networkd.h revision eb27aeca247a4cf8816fffc4c0dbcab55ead3864
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/***
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen This file is part of systemd.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Copyright 2013 Tom Gundersen <teg@jklm.no>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is free software; you can redistribute it and/or modify it
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen under the terms of the GNU Lesser General Public License as published by
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen (at your option) any later version.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is distributed in the hope that it will be useful, but
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Lesser General Public License for more details.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen You should have received a copy of the GNU Lesser General Public License
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen***/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#pragma once
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <arpa/inet.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <linux/rtnetlink.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "sd-event.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "sd-rtnl.h"
1346b1f0388f4100bb3c2a2bb23bc881769c020cTom Gundersen#include "sd-bus.h"
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen#include "sd-dhcp-client.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "udev.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "rtnl-util.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "hashmap.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "list.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersentypedef struct Netdev Netdev;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersentypedef struct Network Network;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersentypedef struct Link Link;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersentypedef struct Address Address;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersentypedef struct Route Route;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersentypedef struct Manager Manager;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersentypedef struct netdev_enslave_callback netdev_enslave_callback;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersenstruct netdev_enslave_callback {
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen sd_rtnl_message_handler_t callback;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen Link *link;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen LIST_FIELDS(netdev_enslave_callback, callbacks);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen};
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersentypedef enum NetdevKind {
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen NETDEV_KIND_BRIDGE,
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen NETDEV_KIND_BOND,
54abf461d6b10dc270c4bb2aeac65f240ff1c5cdTom Gundersen NETDEV_KIND_VLAN,
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen _NETDEV_KIND_MAX,
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen _NETDEV_KIND_INVALID = -1
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen} NetdevKind;
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersentypedef enum NetdevState {
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen NETDEV_STATE_FAILED,
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen NETDEV_STATE_CREATING,
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen NETDEV_STATE_READY,
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen _NETDEV_STATE_MAX,
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen _NETDEV_STATE_INVALID = -1,
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen} NetdevState;
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersenstruct Netdev {
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen Manager *manager;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen char *filename;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen char *description;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen char *name;
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen NetdevKind kind;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
54abf461d6b10dc270c4bb2aeac65f240ff1c5cdTom Gundersen int vlanid;
54abf461d6b10dc270c4bb2aeac65f240ff1c5cdTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen Link *link;
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen NetdevState state;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen LIST_HEAD(netdev_enslave_callback, callbacks);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen};
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenstruct Network {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Manager *manager;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen char *filename;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen struct ether_addr *match_mac;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen char *match_path;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen char *match_driver;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen char *match_type;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen char *match_name;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen char *description;
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen Netdev *bridge;
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen Netdev *bond;
54abf461d6b10dc270c4bb2aeac65f240ff1c5cdTom Gundersen Netdev *vlan;
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen bool dhcp;
5be4d38e31281727b6f45ae869136bb01a1f7790Tom Gundersen bool dhcp_dns;
4f882b2a5007e51032459e29d15a86df6b5ea9f4Tom Gundersen bool dhcp_mtu;
1346b1f0388f4100bb3c2a2bb23bc881769c020cTom Gundersen bool dhcp_hostname;
039ebe6aebaebcaa18375b33caf1db5fe2551621Tom Gundersen bool dhcp_domainname;
eb27aeca247a4cf8816fffc4c0dbcab55ead3864Tom Gundersen bool dhcp_critical;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen LIST_HEAD(Address, static_addresses);
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen LIST_HEAD(Route, static_routes);
3bef724f7e7f7eaca69881548b06e221b77d7031Tom Gundersen Address *dns;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen Hashmap *addresses_by_section;
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen Hashmap *routes_by_section;
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen LIST_FIELDS(Network, networks);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen};
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenstruct Address {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Network *network;
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen uint64_t section;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen unsigned char family;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen unsigned char prefixlen;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen char *label;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
8cd11a0f0f4ca05199e1166f6a07472b296f7455Tom Gundersen struct in_addr netmask;
8cd11a0f0f4ca05199e1166f6a07472b296f7455Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen union {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen struct in_addr in;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen struct in6_addr in6;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen } in_addr;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen LIST_FIELDS(Address, static_addresses);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen};
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenstruct Route {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Network *network;
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen uint64_t section;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen unsigned char family;
b3070dc0258831c7e2b13624f75fa3dbd80d9833Tom Gundersen unsigned char dst_family;
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen unsigned char dst_prefixlen;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen union {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen struct in_addr in;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen struct in6_addr in6;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen } in_addr;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen union {
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen struct in_addr in;
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen struct in6_addr in6;
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen } dst_addr;
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen LIST_FIELDS(Route, static_routes);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen};
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersentypedef enum LinkState {
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen LINK_STATE_ENSLAVING,
ef1ba6065c6ccea94d4ee867f36df7bbc53a5224Tom Gundersen LINK_STATE_SETTING_ADDRESSES,
ef1ba6065c6ccea94d4ee867f36df7bbc53a5224Tom Gundersen LINK_STATE_SETTING_ROUTES,
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen LINK_STATE_CONFIGURED,
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen LINK_STATE_FAILED,
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen _LINK_STATE_MAX,
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen _LINK_STATE_INVALID = -1
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen} LinkState;
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenstruct Link {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Manager *manager;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
0617ffabe86a6d366252477eafbe59a888b149d4Tom Gundersen uint64_t ifindex;
c166a070553511e402de5ad216d3fb62b49bdacbTom Gundersen char *ifname;
8cd11a0f0f4ca05199e1166f6a07472b296f7455Tom Gundersen struct ether_addr mac;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen unsigned flags;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Network *network;
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen Route *dhcp_route;
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen Address *dhcp_address;
3bef724f7e7f7eaca69881548b06e221b77d7031Tom Gundersen Address *dns;
4f882b2a5007e51032459e29d15a86df6b5ea9f4Tom Gundersen uint16_t original_mtu;
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen LinkState state;
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen unsigned addr_messages;
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen unsigned route_messages;
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen unsigned enslaving;
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen sd_dhcp_client *dhcp;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen};
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenstruct Manager {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen sd_rtnl *rtnl;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen sd_event *event;
1346b1f0388f4100bb3c2a2bb23bc881769c020cTom Gundersen sd_bus *bus;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen struct udev *udev;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen struct udev_monitor *udev_monitor;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen sd_event_source *udev_event_source;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Hashmap *links;
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen Hashmap *netdevs;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen LIST_HEAD(Network, networks);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen usec_t network_dirs_ts_usec;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen};
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmekextern const char* const network_dirs[];
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/* Manager */
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenint manager_new(Manager **ret);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenvoid manager_free(Manager *m);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersenint manager_load_config(Manager *m);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersenbool manager_should_reload(Manager *m);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenint manager_udev_enumerate_links(Manager *m);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenint manager_udev_listen(Manager *m);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersenint manager_rtnl_listen(Manager *m);
1346b1f0388f4100bb3c2a2bb23bc881769c020cTom Gundersenint manager_bus_listen(Manager *m);
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen
3bef724f7e7f7eaca69881548b06e221b77d7031Tom Gundersenint manager_update_resolv_conf(Manager *m);
3bef724f7e7f7eaca69881548b06e221b77d7031Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom GundersenDEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#define _cleanup_manager_free_ _cleanup_(manager_freep)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen/* Netdev */
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersenint netdev_load(Manager *manager);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersenvoid netdev_free(Netdev *netdev);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom GundersenDEFINE_TRIVIAL_CLEANUP_FUNC(Netdev*, netdev_free);
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen#define _cleanup_netdev_free_ _cleanup_(netdev_freep)
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersenint netdev_get(Manager *manager, const char *name, Netdev **ret);
52433f6b65eccd1c54606dde999610640f3458acTom Gundersenint netdev_set_link(Manager *m, NetdevKind kind, Link *link);
52433f6b65eccd1c54606dde999610640f3458acTom Gundersenint netdev_enslave(Netdev *netdev, Link *link, sd_rtnl_message_handler_t cb);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersenconst char *netdev_kind_to_string(NetdevKind d) _const_;
52433f6b65eccd1c54606dde999610640f3458acTom GundersenNetdevKind netdev_kind_from_string(const char *d) _pure_;
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersenint 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);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/* Network */
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenint network_load(Manager *manager);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenvoid network_free(Network *network);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom GundersenDEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_free);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#define _cleanup_network_free_ _cleanup_(network_freep)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenint network_get(Manager *manager, struct udev_device *device, Network **ret);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenint network_apply(Manager *manager, Network *network, Link *link);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersenint config_parse_bridge(const char *unit, const char *filename, unsigned line,
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen const char *section, unsigned section_line, const char *lvalue,
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen int ltype, const char *rvalue, void *data, void *userdata);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
52433f6b65eccd1c54606dde999610640f3458acTom Gundersenint config_parse_bond(const char *unit, const char *filename, unsigned line,
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen const char *section, unsigned section_line, const char *lvalue,
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen int ltype, const char *rvalue, void *data, void *userdata);
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen
54abf461d6b10dc270c4bb2aeac65f240ff1c5cdTom Gundersenint config_parse_vlan(const char *unit, const char *filename, unsigned line,
54abf461d6b10dc270c4bb2aeac65f240ff1c5cdTom Gundersen const char *section, unsigned section_line, const char *lvalue,
54abf461d6b10dc270c4bb2aeac65f240ff1c5cdTom Gundersen int ltype, const char *rvalue, void *data, void *userdata);
54abf461d6b10dc270c4bb2aeac65f240ff1c5cdTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen/* gperf */
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenconst struct ConfigPerfItem* network_gperf_lookup(const char *key, unsigned length);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/* Route */
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersenint route_new_static(Network *network, unsigned section, Route **ret);
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersenint route_new_dynamic(Route **ret);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenvoid route_free(Route *route);
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersenint route_configure(Route *route, Link *link, sd_rtnl_message_handler_t callback);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom GundersenDEFINE_TRIVIAL_CLEANUP_FUNC(Route*, route_free);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#define _cleanup_route_free_ _cleanup_(route_freep)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenint config_parse_gateway(const char *unit, const char *filename, unsigned line,
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen const char *section, unsigned section_line, const char *lvalue,
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen int ltype, const char *rvalue, void *data, void *userdata);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersenint config_parse_destination(const char *unit, const char *filename, unsigned line,
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen const char *section, unsigned section_line, const char *lvalue,
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen int ltype, const char *rvalue, void *data, void *userdata);
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/* Address */
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersenint address_new_static(Network *network, unsigned section, Address **ret);
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersenint address_new_dynamic(Address **ret);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenvoid address_free(Address *address);
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersenint address_configure(Address *address, Link *link, sd_rtnl_message_handler_t callback);
407fe036a24834203aca6c1eec7d74d9ad3e9ee0Tom Gundersenint address_drop(Address *address, Link *link, sd_rtnl_message_handler_t callback);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom GundersenDEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#define _cleanup_address_free_ _cleanup_(address_freep)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
3bef724f7e7f7eaca69881548b06e221b77d7031Tom Gundersenint config_parse_dns(const char *unit, const char *filename, unsigned line,
3bef724f7e7f7eaca69881548b06e221b77d7031Tom Gundersen const char *section, unsigned section_line, const char *lvalue,
3bef724f7e7f7eaca69881548b06e221b77d7031Tom Gundersen int ltype, const char *rvalue, void *data, void *userdata);
3bef724f7e7f7eaca69881548b06e221b77d7031Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenint config_parse_address(const char *unit, const char *filename, unsigned line,
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen const char *section, unsigned section_line, const char *lvalue,
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen int ltype, const char *rvalue, void *data, void *userdata);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersenint config_parse_label(const char *unit, const char *filename, unsigned line,
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen const char *section, unsigned section_line, const char *lvalue,
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen int ltype, const char *rvalue, void *data, void *userdata);
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/* Link */
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenint link_new(Manager *manager, struct udev_device *device, Link **ret);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenvoid link_free(Link *link);
aa3437a573ed2a2b2a03c9649fe11d27b40a772bTom Gundersenint link_add(Manager *manager, struct udev_device *device, Link **ret);
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersenint link_configure(Link *link);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
22936833e177d9e477e059ec2b4f4fa9213b4e19Tom Gundersenint link_update(Link *link, sd_rtnl_message *message);
dd3efc0993b6e95ff04775e9125e2fc9d30fe261Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom GundersenDEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#define _cleanup_link_free_ _cleanup_(link_freep)
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmek
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmek/* Macros which append INTERFACE= to the message */
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmek
39032b87779323a244dd89f4832949d462b2ac68Zbigniew Jędrzejewski-Szmek#define log_full_link(level, link, fmt, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "INTERFACE=", link->ifname, "%s: " fmt, link->ifname, ##__VA_ARGS__)
39032b87779323a244dd89f4832949d462b2ac68Zbigniew Jędrzejewski-Szmek#define log_debug_link(link, ...) log_full_link(LOG_DEBUG, link, ##__VA_ARGS__)
39032b87779323a244dd89f4832949d462b2ac68Zbigniew Jędrzejewski-Szmek#define log_info_link(link, ...) log_full_link(LOG_INFO, link, ##__VA_ARGS__)
39032b87779323a244dd89f4832949d462b2ac68Zbigniew Jędrzejewski-Szmek#define log_notice_link(link, ...) log_full_link(LOG_NOTICE, link, ##__VA_ARGS__)
39032b87779323a244dd89f4832949d462b2ac68Zbigniew Jędrzejewski-Szmek#define log_warning_link(link, ...) log_full_link(LOG_WARNING, link, ##__VA_ARGS__)
39032b87779323a244dd89f4832949d462b2ac68Zbigniew Jędrzejewski-Szmek#define log_error_link(link, ...) log_full_link(LOG_ERR, link, ##__VA_ARGS__)
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmek
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmek#define log_struct_link(level, link, ...) log_struct(level, "INTERFACE=%s", link->ifname, __VA_ARGS__)
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmek
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmek/* More macros which append INTERFACE= to the message */
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmek
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen#define log_full_netdev(level, netdev, fmt, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "INTERFACE=", netdev->name, "%s: " fmt, netdev->name, ##__VA_ARGS__)
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen#define log_debug_netdev(netdev, ...) log_full_netdev(LOG_DEBUG, netdev, ##__VA_ARGS__)
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen#define log_info_netdev(netdev, ...) log_full_netdev(LOG_INFO, netdev, ##__VA_ARGS__)
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen#define log_notice_netdev(netdev, ...) log_full_netdev(LOG_NOTICE, netdev, ##__VA_ARGS__)
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen#define log_warning_netdev(netdev, ...) log_full_netdev(LOG_WARNING, netdev,## __VA_ARGS__)
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen#define log_error_netdev(netdev, ...) log_full_netdev(LOG_ERR, netdev, ##__VA_ARGS__)
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmek
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen#define log_struct_netdev(level, netdev, ...) log_struct(level, "INTERFACE=%s", netdev->name, __VA_ARGS__)
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmek
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen#define NETDEV(netdev) "INTERFACE=%s", netdev->name
628706137efbca8aaf753ccd063e5abf7e31aed5Zbigniew Jędrzejewski-Szmek#define ADDRESS_FMT_VAL(address) \
628706137efbca8aaf753ccd063e5abf7e31aed5Zbigniew Jędrzejewski-Szmek (address).s_addr & 0xFF, \
628706137efbca8aaf753ccd063e5abf7e31aed5Zbigniew Jędrzejewski-Szmek ((address).s_addr >> 8) & 0xFF, \
628706137efbca8aaf753ccd063e5abf7e31aed5Zbigniew Jędrzejewski-Szmek ((address).s_addr >> 16) & 0xFF, \
628706137efbca8aaf753ccd063e5abf7e31aed5Zbigniew Jędrzejewski-Szmek (address).s_addr >> 24