networkd.h revision 1324e3ae515719a93a94a8d8316644af6c780909
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding/***
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding This file is part of systemd.
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding Copyright 2013 Tom Gundersen <teg@jklm.no>
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding systemd is free software; you can redistribute it and/or modify it
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar under the terms of the GNU Lesser General Public License as published by
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd the Free Software Foundation; either version 2.1 of the License, or
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar (at your option) any later version.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd systemd is distributed in the hope that it will be useful, but
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd WITHOUT ANY WARRANTY; without even the implied warranty of
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd Lesser General Public License for more details.
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar You should have received a copy of the GNU Lesser General Public License
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar along with systemd; If not, see <http://www.gnu.org/licenses/>.
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar***/
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#pragma once
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include <arpa/inet.h>
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "sd-event.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "sd-rtnl.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "sd-bus.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "sd-dhcp-client.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "sd-dhcp-server.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "sd-ipv4ll.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "udev.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "rtnl-util.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "hashmap.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "list.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "set.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#include "condition-util.h"
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#define CACHE_INFO_INFINITY_LIFE_TIME 0xFFFFFFFFU
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoartypedef struct NetDev NetDev;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoartypedef struct Network Network;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoartypedef struct Link Link;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoartypedef struct Address Address;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoartypedef struct Route Route;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoartypedef struct Manager Manager;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoartypedef struct netdev_enslave_callback netdev_enslave_callback;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarstruct netdev_enslave_callback {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar sd_rtnl_message_handler_t callback;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Link *link;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LIST_FIELDS(netdev_enslave_callback, callbacks);
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg};
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankgtypedef enum MacVlanMode {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_MACVLAN_MODE_PRIVATE = MACVLAN_MODE_PRIVATE,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_MACVLAN_MODE_VEPA = MACVLAN_MODE_VEPA,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_MACVLAN_MODE_BRIDGE = MACVLAN_MODE_BRIDGE,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_MACVLAN_MODE_PASSTHRU = MACVLAN_MODE_PASSTHRU,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar _NETDEV_MACVLAN_MODE_MAX,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar _NETDEV_MACVLAN_MODE_INVALID = -1
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar} MacVlanMode;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoartypedef enum NetDevKind {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_KIND_BRIDGE,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_KIND_BOND,
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg NETDEV_KIND_VLAN,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_KIND_MACVLAN,
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg NETDEV_KIND_IPIP,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_KIND_GRE,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_KIND_SIT,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_KIND_VETH,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_KIND_VTI,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar _NETDEV_KIND_MAX,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar _NETDEV_KIND_INVALID = -1
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar} NetDevKind;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoartypedef enum NetDevState {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_STATE_FAILED,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_STATE_CREATING,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_STATE_READY,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NETDEV_STATE_LINGER,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar _NETDEV_STATE_MAX,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar _NETDEV_STATE_INVALID = -1,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar} NetDevState;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarstruct NetDev {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Manager *manager;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar int n_ref;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *filename;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Condition *match_host;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Condition *match_virt;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Condition *match_kernel;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Condition *match_arch;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *description;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *ifname;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *ifname_peer;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar size_t mtu;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct ether_addr *mac;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct ether_addr *mac_peer;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NetDevKind kind;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar uint64_t vlanid;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar int32_t macvlan_mode;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar int ifindex;
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg NetDevState state;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar bool tunnel_pmtudisc;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned ttl;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned tos;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct in_addr local;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct in_addr remote;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LIST_HEAD(netdev_enslave_callback, callbacks);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar};
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarstruct Network {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Manager *manager;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg char *filename;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct ether_addr *match_mac;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *match_path;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *match_driver;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *match_type;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *match_name;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Condition *match_host;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Condition *match_virt;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Condition *match_kernel;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Condition *match_arch;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *description;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NetDev *bridge;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NetDev *bond;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar NetDev *tunnel;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Hashmap *vlans;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Hashmap *macvlans;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar bool dhcp;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar bool dhcp_dns;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar bool dhcp_ntp;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar bool dhcp_mtu;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar bool dhcp_hostname;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar bool dhcp_domainname;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar bool dhcp_critical;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar bool ipv4ll;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg bool dhcp_server;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LIST_HEAD(Address, static_addresses);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LIST_HEAD(Route, static_routes);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Hashmap *addresses_by_section;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Hashmap *routes_by_section;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LIST_HEAD(Address, dns);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LIST_HEAD(Address, ntp);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LIST_FIELDS(Network, networks);
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg};
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarstruct Address {
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg Network *network;
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg uint64_t section;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned char family;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned char prefixlen;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned char scope;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *label;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct in_addr broadcast;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct ifa_cacheinfo cinfo;
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar union {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct in_addr in;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct in6_addr in6;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar } in_addr;
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg LIST_FIELDS(Address, addresses);
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg};
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarstruct Route {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Network *network;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar uint64_t section;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned char family;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned char dst_prefixlen;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned char scope;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar uint32_t metrics;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg union {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct in_addr in;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct in6_addr in6;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar } in_addr;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar union {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct in_addr in;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct in6_addr in6;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar } dst_addr;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LIST_FIELDS(Route, routes);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar};
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoartypedef enum LinkState {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LINK_STATE_INITIALIZING,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LINK_STATE_ENSLAVING,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LINK_STATE_SETTING_ADDRESSES,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LINK_STATE_SETTING_ROUTES,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LINK_STATE_CONFIGURED,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LINK_STATE_UNMANAGED,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LINK_STATE_FAILED,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LINK_STATE_LINGER,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar _LINK_STATE_MAX,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar _LINK_STATE_INVALID = -1
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar} LinkState;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoartypedef enum LinkOperationalState {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LINK_OPERSTATE_UNKNOWN,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LINK_OPERSTATE_DORMANT,
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg LINK_OPERSTATE_CARRIER,
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg LINK_OPERSTATE_DEGRADED,
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg LINK_OPERSTATE_ROUTABLE,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar _LINK_OPERSTATE_MAX,
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar _LINK_OPERSTATE_INVALID = -1
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar} LinkOperationalState;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarstruct Link {
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg Manager *manager;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar int n_ref;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar uint64_t ifindex;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *ifname;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *state_file;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct ether_addr mac;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct udev_device *udev_device;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned flags;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar uint8_t kernel_operstate;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Network *network;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LinkState state;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LinkOperationalState operstate;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned addr_messages;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned route_messages;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar unsigned enslaving;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LIST_HEAD(Address, addresses);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar sd_dhcp_client *dhcp_client;
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg sd_dhcp_lease *dhcp_lease;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *lease_file;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar uint16_t original_mtu;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar sd_ipv4ll *ipv4ll;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar sd_dhcp_server *dhcp_server;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar};
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarstruct Manager {
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar sd_rtnl *rtnl;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar sd_event *event;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar sd_bus *bus;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct udev *udev;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar struct udev_monitor *udev_monitor;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar sd_event_source *udev_event_source;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar sd_event_source *sigterm_event_source;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar sd_event_source *sigint_event_source;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar char *state_file;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Hashmap *links;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar Hashmap *netdevs;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar LIST_HEAD(Network, networks);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar usec_t network_dirs_ts_usec;
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar};
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarextern const char* const network_dirs[];
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar/* Manager */
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarint manager_new(Manager **ret);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarvoid manager_free(Manager *m);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarint manager_load_config(Manager *m);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarbool manager_should_reload(Manager *m);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarint manager_rtnl_enumerate_links(Manager *m);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarint manager_rtnl_listen(Manager *m);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarint manager_udev_listen(Manager *m);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarint manager_bus_listen(Manager *m);
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarint manager_save(Manager *m);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarDEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar#define _cleanup_manager_free_ _cleanup_(manager_freep)
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg/* NetDev */
e569ae6ccf9b3a7424969289971fa4481ce6a014fuankg
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarint netdev_load(Manager *manager);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoarvoid netdev_drop(NetDev *netdev);
650b8deadd86f9326c0d4a1bcbbb61cb907722aacoar
NetDev *netdev_unref(NetDev *netdev);
NetDev *netdev_ref(NetDev *netdev);
DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_unref);
#define _cleanup_netdev_unref_ _cleanup_(netdev_unrefp)
int netdev_get(Manager *manager, const char *name, NetDev **ret);
int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *newlink);
int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t cb);
int netdev_create_tunnel(Link *link, sd_rtnl_message_handler_t callback);
int netdev_create_veth(NetDev *netdev, sd_rtnl_message_handler_t callback);
const char *netdev_kind_to_string(NetDevKind d) _const_;
NetDevKind netdev_kind_from_string(const char *d) _pure_;
const char *macvlan_mode_to_string(MacVlanMode d) _const_;
MacVlanMode macvlan_mode_from_string(const char *d) _pure_;
int 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);
int config_parse_macvlan_mode(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);
/* gperf */
const struct ConfigPerfItem* network_netdev_gperf_lookup(const char *key, unsigned length);
/* Network */
int network_load(Manager *manager);
void network_free(Network *network);
DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_free);
#define _cleanup_network_free_ _cleanup_(network_freep)
int network_get(Manager *manager, struct udev_device *device,
const char *ifname, const struct ether_addr *mac,
Network **ret);
int network_apply(Manager *manager, Network *network, Link *link);
int config_parse_netdev(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);
int config_parse_tunnel(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);
int config_parse_tunnel_address(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);
/* gperf */
const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, unsigned length);
/* Route */
int route_new_static(Network *network, unsigned section, Route **ret);
int route_new_dynamic(Route **ret);
void route_free(Route *route);
int route_configure(Route *route, Link *link, sd_rtnl_message_handler_t callback);
int route_drop(Route *route, Link *link, sd_rtnl_message_handler_t callback);
DEFINE_TRIVIAL_CLEANUP_FUNC(Route*, route_free);
#define _cleanup_route_free_ _cleanup_(route_freep)
int config_parse_gateway(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);
int config_parse_destination(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);
/* Address */
int address_new_static(Network *network, unsigned section, Address **ret);
int address_new_dynamic(Address **ret);
void address_free(Address *address);
int address_configure(Address *address, Link *link, sd_rtnl_message_handler_t callback);
int address_update(Address *address, Link *link, sd_rtnl_message_handler_t callback);
int address_drop(Address *address, Link *link, sd_rtnl_message_handler_t callback);
bool address_equal(Address *a1, Address *a2);
DEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free);
#define _cleanup_address_free_ _cleanup_(address_freep)
int config_parse_dns(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);
int config_parse_address(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);
int config_parse_broadcast(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);
int config_parse_label(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);
/* Link */
Link *link_unref(Link *link);
Link *link_ref(Link *link);
int link_get(Manager *m, int ifindex, Link **ret);
int link_add(Manager *manager, sd_rtnl_message *message, Link **ret);
void link_drop(Link *link);
int link_update(Link *link, sd_rtnl_message *message);
int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata);
int link_initialized(Link *link, struct udev_device *device);
int link_save(Link *link);
bool link_has_carrier(unsigned flags, uint8_t operstate);
const char* link_state_to_string(LinkState s) _const_;
LinkState link_state_from_string(const char *s) _pure_;
const char* link_operstate_to_string(LinkOperationalState s) _const_;
LinkOperationalState link_operstate_from_string(const char *s) _pure_;
DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
#define _cleanup_link_unref_ _cleanup_(link_unrefp)
/* Macros which append INTERFACE= to the message */
#define log_full_link(level, link, fmt, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "INTERFACE=", link->ifname, "%-*s: " fmt, IFNAMSIZ, link->ifname, ##__VA_ARGS__)
#define log_debug_link(link, ...) log_full_link(LOG_DEBUG, link, ##__VA_ARGS__)
#define log_info_link(link, ...) log_full_link(LOG_INFO, link, ##__VA_ARGS__)
#define log_notice_link(link, ...) log_full_link(LOG_NOTICE, link, ##__VA_ARGS__)
#define log_warning_link(link, ...) log_full_link(LOG_WARNING, link, ##__VA_ARGS__)
#define log_error_link(link, ...) log_full_link(LOG_ERR, link, ##__VA_ARGS__)
#define log_struct_link(level, link, ...) log_struct(level, "INTERFACE=%s", link->ifname, __VA_ARGS__)
/* More macros which append INTERFACE= to the message */
#define log_full_netdev(level, netdev, fmt, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "INTERFACE=", netdev->ifname, "%-*s: " fmt, IFNAMSIZ, netdev->ifname, ##__VA_ARGS__)
#define log_debug_netdev(netdev, ...) log_full_netdev(LOG_DEBUG, netdev, ##__VA_ARGS__)
#define log_info_netdev(netdev, ...) log_full_netdev(LOG_INFO, netdev, ##__VA_ARGS__)
#define log_notice_netdev(netdev, ...) log_full_netdev(LOG_NOTICE, netdev, ##__VA_ARGS__)
#define log_warning_netdev(netdev, ...) log_full_netdev(LOG_WARNING, netdev,## __VA_ARGS__)
#define log_error_netdev(netdev, ...) log_full_netdev(LOG_ERR, netdev, ##__VA_ARGS__)
#define log_struct_netdev(level, netdev, ...) log_struct(level, "INTERFACE=%s", netdev->ifname, __VA_ARGS__)
#define NETDEV(netdev) "INTERFACE=%s", netdev->ifname
#define ADDRESS_FMT_VAL(address) \
(address).s_addr & 0xFF, \
((address).s_addr >> 8) & 0xFF, \
((address).s_addr >> 16) & 0xFF, \
(address).s_addr >> 24