networkd-netdev.h revision 0dd25fb9f005d8ab7ac4bc10a609d00569f8c56a
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering/***
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering This file is part of systemd.
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering Copyright 2013 Tom Gundersen <teg@jklm.no>
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering systemd is free software; you can redistribute it and/or modify it
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering under the terms of the GNU Lesser General Public License as published by
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering (at your option) any later version.
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering systemd is distributed in the hope that it will be useful, but
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering Lesser General Public License for more details.
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering You should have received a copy of the GNU Lesser General Public License
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering***/
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#pragma once
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "networkd.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "hashmap.h"
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering#include "list.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "set.h"
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering#include "condition-util.h"
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering#include "in-addr-util.h"
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
b1d4f8e154bf61b5de1b27461ef8e9c8c5e838a1Lennart Poetteringtypedef struct NetDevVTable NetDevVTable;
b1d4f8e154bf61b5de1b27461ef8e9c8c5e838a1Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poetteringtypedef struct netdev_join_callback netdev_join_callback;
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poetteringstruct netdev_join_callback {
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering sd_rtnl_message_handler_t callback;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering Link *link;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering LIST_FIELDS(netdev_join_callback, callbacks);
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering};
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poetteringtypedef enum NetDevKind {
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering NETDEV_KIND_BRIDGE,
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering NETDEV_KIND_BOND,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering NETDEV_KIND_VLAN,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering NETDEV_KIND_MACVLAN,
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering NETDEV_KIND_VXLAN,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering NETDEV_KIND_IPIP,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering NETDEV_KIND_GRE,
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering NETDEV_KIND_SIT,
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering NETDEV_KIND_VETH,
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering NETDEV_KIND_VTI,
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering NETDEV_KIND_DUMMY,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering NETDEV_KIND_TUN,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering NETDEV_KIND_TAP,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering _NETDEV_KIND_MAX,
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering _NETDEV_KIND_INVALID = -1
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering} NetDevKind;
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poetteringtypedef enum NetDevState {
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering NETDEV_STATE_FAILED,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering NETDEV_STATE_CREATING,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering NETDEV_STATE_READY,
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering NETDEV_STATE_LINGER,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering _NETDEV_STATE_MAX,
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering _NETDEV_STATE_INVALID = -1,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering} NetDevState;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
115cbf7e209a86cf5317fa12d44566247b4af332Evgeny Vereshchaginstruct NetDev {
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering Manager *manager;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering int n_ref;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering char *filename;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering Condition *match_host;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering Condition *match_virt;
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering Condition *match_kernel;
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering Condition *match_arch;
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering char *description;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering char *ifname;
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering char *ifname_peer;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering char *user_name;
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering char *group_name;
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering size_t mtu;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering struct ether_addr *mac;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering struct ether_addr *mac_peer;
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering NetDevKind kind;
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering uint64_t vlanid;
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering uint64_t vxlanid;
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering int32_t macvlan_mode;
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering int32_t bond_mode;
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering int ifindex;
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering NetDevState state;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering bool tunnel_pmtudisc;
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering bool learning;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering bool one_queue;
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering bool multi_queue;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering bool packet_info;
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering unsigned ttl;
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering unsigned tos;
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering int family;
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering union in_addr_union local;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering union in_addr_union remote;
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering union in_addr_union group;
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering LIST_HEAD(netdev_join_callback, callbacks);
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering};
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poetteringstruct NetDevVTable {
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering /* fill in message to create netdev */
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering int (*fill_message_create)(NetDev *netdev, sd_rtnl_message *message);
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering /* fill in message to create netdev on top of a given link */
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering int (*fill_message_create_on_link)(NetDev *netdev, Link *link, sd_rtnl_message *message);
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering /* fill in message to enslave link by netdev */
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering int (*enslave)(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback);
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering /* create netdev, if not done via rtnl */
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering int (*create)(NetDev *netdev);
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering /* verify that compulsory configuration options were specified */
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering int (*config_verify)(NetDev *netdev, const char *filename);
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering};
115cbf7e209a86cf5317fa12d44566247b4af332Evgeny Vereshchagin
115cbf7e209a86cf5317fa12d44566247b4af332Evgeny Vereshchaginextern const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX];
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering#define NETDEV_VTABLE(n) netdev_vtable[(n)->kind]
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poetteringint netdev_load(Manager *manager);
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poetteringvoid netdev_drop(NetDev *netdev);
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart PoetteringNetDev *netdev_unref(NetDev *netdev);
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart PoetteringNetDev *netdev_ref(NetDev *netdev);
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering
19f6d710772305610b928bc2678b9d77fe11e770Lennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_unref);
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering#define _cleanup_netdev_unref_ _cleanup_(netdev_unrefp)
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
b2c23da8cea1987a1a329f5a964d3299b7ca7890Lennart Poetteringint netdev_get(Manager *manager, const char *name, NetDev **ret);
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poetteringint netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *newlink);
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poetteringint netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback);
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poetteringint netdev_get_mac(const char *ifname, struct ether_addr **ret);
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poetteringint netdev_join(NetDev *netdev, Link *link, sd_rtnl_message_handler_t cb);
15411c0cb1192799b37ec8f25d6f30e8d7292fc6David Herrmann
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poetteringconst char *netdev_kind_to_string(NetDevKind d) _const_;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart PoetteringNetDevKind netdev_kind_from_string(const char *d) _pure_;
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poetteringint config_parse_netdev_kind(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering/* gperf */
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poetteringconst struct ConfigPerfItem* network_netdev_gperf_lookup(const char *key, unsigned length);
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering/* Macros which append INTERFACE= to the message */
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering#define log_full_netdev(level, netdev, fmt, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "INTERFACE=", netdev->ifname, "%-*s: " fmt, IFNAMSIZ, netdev->ifname, ##__VA_ARGS__)
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering#define log_debug_netdev(netdev, ...) log_full_netdev(LOG_DEBUG, netdev, ##__VA_ARGS__)
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering#define log_info_netdev(netdev, ...) log_full_netdev(LOG_INFO, netdev, ##__VA_ARGS__)
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering#define log_notice_netdev(netdev, ...) log_full_netdev(LOG_NOTICE, netdev, ##__VA_ARGS__)
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering#define log_warning_netdev(netdev, ...) log_full_netdev(LOG_WARNING, netdev,## __VA_ARGS__)
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering#define log_error_netdev(netdev, ...) log_full_netdev(LOG_ERR, netdev, ##__VA_ARGS__)
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering
067d851d30386c553e3a84f59d81d003ff638b91Daniel Wallace#define log_struct_netdev(level, netdev, ...) log_struct(level, "INTERFACE=%s", netdev->ifname, __VA_ARGS__)
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering#define NETDEV(netdev) "INTERFACE=%s", netdev->ifname
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering