chiark / gitweb /
networkd: netdev - verify that newlink messages has the expected kind
[elogind.git] / src / network / networkd.h
index 22dcbd098716beab25fdb156cdd0895a6da1d241..8144031a99d286987181a190ca5dcf21993528c8 100644 (file)
 #pragma once
 
 #include <arpa/inet.h>
-#include <linux/rtnetlink.h>
 
 #include "sd-event.h"
 #include "sd-rtnl.h"
 #include "sd-bus.h"
 #include "sd-dhcp-client.h"
+#include "sd-ipv4ll.h"
 #include "udev.h"
 
 #include "rtnl-util.h"
 #include "hashmap.h"
 #include "list.h"
+#include "set.h"
+#include "condition-util.h"
 
-typedef struct Netdev Netdev;
+typedef struct NetDev NetDev;
 typedef struct Network Network;
 typedef struct Link Link;
 typedef struct Address Address;
@@ -50,35 +52,51 @@ struct netdev_enslave_callback {
         LIST_FIELDS(netdev_enslave_callback, callbacks);
 };
 
-typedef enum NetdevKind {
+typedef enum MacVlanMode {
+        NETDEV_MACVLAN_MODE_PRIVATE = MACVLAN_MODE_PRIVATE,
+        NETDEV_MACVLAN_MODE_VEPA = MACVLAN_MODE_VEPA,
+        NETDEV_MACVLAN_MODE_BRIDGE = MACVLAN_MODE_BRIDGE,
+        NETDEV_MACVLAN_MODE_PASSTHRU = MACVLAN_MODE_PASSTHRU,
+        _NETDEV_MACVLAN_MODE_MAX,
+        _NETDEV_MACVLAN_MODE_INVALID = -1
+} MacVlanMode;
+
+typedef enum NetDevKind {
         NETDEV_KIND_BRIDGE,
         NETDEV_KIND_BOND,
         NETDEV_KIND_VLAN,
+        NETDEV_KIND_MACVLAN,
         _NETDEV_KIND_MAX,
         _NETDEV_KIND_INVALID = -1
-} NetdevKind;
+} NetDevKind;
 
-typedef enum NetdevState {
+typedef enum NetDevState {
         NETDEV_STATE_FAILED,
         NETDEV_STATE_CREATING,
         NETDEV_STATE_READY,
         _NETDEV_STATE_MAX,
         _NETDEV_STATE_INVALID = -1,
-} NetdevState;
+} NetDevState;
 
-struct Netdev {
+struct NetDev {
         Manager *manager;
 
         char *filename;
 
+        Condition *match_host;
+        Condition *match_virt;
+        Condition *match_kernel;
+        Condition *match_arch;
+
         char *description;
         char *name;
-        NetdevKind kind;
+        NetDevKind kind;
 
-        int vlanid;
+        uint64_t vlanid;
+        int32_t macvlan_mode;
 
-        Link *link;
-        NetdevState state;
+        int ifindex;
+        NetDevState state;
 
         LIST_HEAD(netdev_enslave_callback, callbacks);
 };
@@ -93,24 +111,32 @@ struct Network {
         char *match_driver;
         char *match_type;
         char *match_name;
+        Condition *match_host;
+        Condition *match_virt;
+        Condition *match_kernel;
+        Condition *match_arch;
 
         char *description;
-        Netdev *bridge;
-        Netdev *bond;
-        Netdev *vlan;
+        NetDev *bridge;
+        NetDev *bond;
+        Hashmap *vlans;
+        Hashmap *macvlans;
         bool dhcp;
         bool dhcp_dns;
         bool dhcp_mtu;
         bool dhcp_hostname;
         bool dhcp_domainname;
+        bool dhcp_critical;
+        bool ipv4ll;
 
         LIST_HEAD(Address, static_addresses);
         LIST_HEAD(Route, static_routes);
-        Address *dns;
 
         Hashmap *addresses_by_section;
         Hashmap *routes_by_section;
 
+        Set *dns;
+
         LIST_FIELDS(Network, networks);
 };
 
@@ -120,9 +146,10 @@ struct Address {
 
         unsigned char family;
         unsigned char prefixlen;
+        unsigned char scope;
         char *label;
 
-        struct in_addr netmask;
+        struct in_addr broadcast;
 
         union {
                 struct in_addr in;
@@ -137,8 +164,9 @@ struct Route {
         uint64_t section;
 
         unsigned char family;
-        unsigned char dst_family;
         unsigned char dst_prefixlen;
+        unsigned char scope;
+        uint32_t metrics;
 
         union {
                 struct in_addr in;
@@ -168,24 +196,24 @@ struct Link {
 
         uint64_t ifindex;
         char *ifname;
+        char *state_file;
         struct ether_addr mac;
+        struct udev_device *udev_device;
 
         unsigned flags;
 
         Network *network;
 
-        Route *dhcp_route;
-        Address *dhcp_address;
-        Address *dns;
-        uint16_t original_mtu;
-
         LinkState state;
 
         unsigned addr_messages;
         unsigned route_messages;
         unsigned enslaving;
 
-        sd_dhcp_client *dhcp;
+        sd_dhcp_client *dhcp_client;
+        sd_dhcp_lease *dhcp_lease;
+        uint16_t original_mtu;
+        sd_ipv4ll *ipv4ll;
 };
 
 struct Manager {
@@ -195,6 +223,8 @@ struct Manager {
         struct udev *udev;
         struct udev_monitor *udev_monitor;
         sd_event_source *udev_event_source;
+        sd_event_source *sigterm_event_source;
+        sd_event_source *sigint_event_source;
 
         Hashmap *links;
         Hashmap *netdevs;
@@ -224,24 +254,32 @@ int manager_update_resolv_conf(Manager *m);
 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
 #define _cleanup_manager_free_ _cleanup_(manager_freep)
 
-/* Netdev */
+/* NetDev */
 
 int netdev_load(Manager *manager);
 
-void netdev_free(Netdev *netdev);
+void netdev_free(NetDev *netdev);
 
-DEFINE_TRIVIAL_CLEANUP_FUNC(Netdev*, netdev_free);
+DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_free);
 #define _cleanup_netdev_free_ _cleanup_(netdev_freep)
 
-int netdev_get(Manager *manager, const char *name, Netdev **ret);
-int netdev_set_link(Manager *m, NetdevKind kind, Link *link);
-int netdev_enslave(Netdev *netdev, Link *link, sd_rtnl_message_handler_t cb);
+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);
+
+const char *netdev_kind_to_string(NetDevKind d) _const_;
+NetDevKind netdev_kind_from_string(const char *d) _pure_;
 
-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);
@@ -266,15 +304,20 @@ int config_parse_vlan(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 */
+int config_parse_macvlan(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);
 
-const struct ConfigPerfItem* network_gperf_lookup(const char *key, unsigned length);
+/* 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)
@@ -305,6 +348,10 @@ 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);
@@ -313,11 +360,16 @@ int config_parse_label(const char *unit, const char *filename, unsigned line,
 
 int link_new(Manager *manager, struct udev_device *device, Link **ret);
 void link_free(Link *link);
+int link_get(Manager *m, int ifindex, Link **ret);
 int link_add(Manager *manager, struct udev_device *device, Link **ret);
-int link_configure(Link *link);
 
 int link_update(Link *link, sd_rtnl_message *message);
 
+int link_save(Link *link);
+
+const char* link_state_to_string(LinkState s) _const_;
+LinkState link_state_from_string(const char *s) _pure_;
+
 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
 #define _cleanup_link_free_ _cleanup_(link_freep)