chiark / gitweb /
networkd: tie links to rtnl rather than udev
[elogind.git] / src / network / networkd-network.c
index 14fa92aeaf62d6cce055ef23439696f5a3927c1c..048017e22968f000882c7716cccb31cbcc1bf123 100644 (file)
@@ -20,7 +20,7 @@
 ***/
 
 #include "networkd.h"
-#include "net-util.h"
+#include "network-internal.h"
 #include "path-util.h"
 #include "conf-files.h"
 #include "conf-parser.h"
@@ -41,7 +41,7 @@ static int network_load_one(Manager *manager, const char *filename) {
                 if (errno == ENOENT)
                         return 0;
                 else
-                        return errno;
+                        return -errno;
         }
 
         network = new0(Network, 1);
@@ -53,10 +53,14 @@ static int network_load_one(Manager *manager, const char *filename) {
         LIST_HEAD_INIT(network->static_addresses);
         LIST_HEAD_INIT(network->static_routes);
 
-        network->vlans = hashmap_new(uint64_hash_func, uint64_compare_func);
+        network->vlans = hashmap_new(string_hash_func, string_compare_func);
         if (!network->vlans)
                 return log_oom();
 
+        network->macvlans = hashmap_new(uint64_hash_func, uint64_compare_func);
+        if (!network->macvlans)
+                return log_oom();
+
         network->addresses_by_section = hashmap_new(uint64_hash_func, uint64_compare_func);
         if (!network->addresses_by_section)
                 return log_oom();
@@ -65,6 +69,10 @@ static int network_load_one(Manager *manager, const char *filename) {
         if (!network->routes_by_section)
                 return log_oom();
 
+        network->dns = set_new(NULL, NULL);
+        if (!network->dns)
+                return log_oom();
+
         network->filename = strdup(filename);
         if (!network->filename)
                 return log_oom();
@@ -132,6 +140,7 @@ int network_load(Manager *manager) {
 void network_free(Network *network) {
         Route *route;
         Address *address;
+        Iterator i;
 
         if (!network)
                 return;
@@ -146,10 +155,15 @@ void network_free(Network *network) {
 
         free(network->description);
 
-        address_free(network->dns);
+        SET_FOREACH(address, network->dns, i)
+                address_free(address);
+
+        set_free(network->dns);
 
         hashmap_free(network->vlans);
 
+        hashmap_free(network->macvlans);
+
         while ((route = network->static_routes))
                 route_free(route);
 
@@ -162,31 +176,36 @@ void network_free(Network *network) {
         if (network->manager && network->manager->networks)
                 LIST_REMOVE(networks, network->manager->networks, network);
 
+        condition_free_list(network->match_host);
+        condition_free_list(network->match_virt);
+        condition_free_list(network->match_kernel);
+        condition_free_list(network->match_arch);
+
         free(network);
 }
 
-int network_get(Manager *manager, struct udev_device *device, Network **ret) {
+int network_get(Manager *manager, struct udev_device *device,
+                const char *ifname, const struct ether_addr *address,
+                Network **ret) {
         Network *network;
 
         assert(manager);
-        assert(device);
         assert(ret);
 
         LIST_FOREACH(networks, network, manager->networks) {
                 if (net_match_config(network->match_mac, network->match_path,
-                                        network->match_driver, network->match_type,
-                                        network->match_name, network->match_host,
-                                        network->match_virt, network->match_kernel,
-                                        network->match_arch,
-                                        udev_device_get_sysattr_value(device, "address"),
-                                        udev_device_get_property_value(device, "ID_PATH"),
-                                        udev_device_get_driver(udev_device_get_parent(device)),
-                                        udev_device_get_property_value(device, "ID_NET_DRIVER"),
-                                        udev_device_get_devtype(device),
-                                        udev_device_get_sysname(device))) {
-                        log_debug("%s: found matching network '%s'",
-                                        udev_device_get_sysname(device),
-                                        network->filename);
+                                     network->match_driver, network->match_type,
+                                     network->match_name, network->match_host,
+                                     network->match_virt, network->match_kernel,
+                                     network->match_arch,
+                                     address,
+                                     udev_device_get_property_value(device, "ID_PATH"),
+                                     udev_device_get_driver(udev_device_get_parent(device)),
+                                     udev_device_get_property_value(device, "ID_NET_DRIVER"),
+                                     udev_device_get_devtype(device),
+                                     ifname)) {
+                        log_debug("%s: found matching network '%s'", ifname,
+                                  network->filename);
                         *ret = network;
                         return 0;
                 }
@@ -202,10 +221,6 @@ int network_apply(Manager *manager, Network *network, Link *link) {
 
         link->network = network;
 
-        r = link_configure(link);
-        if (r < 0)
-                return r;
-
         if (network->dns) {
                 r = manager_update_resolv_conf(manager);
                 if (r < 0)
@@ -330,3 +345,45 @@ int config_parse_vlan(const char *unit,
 
         return 0;
 }
+
+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) {
+        Network *network = userdata;
+        NetDev *netdev;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = netdev_get(network->manager, rvalue, &netdev);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "MACVLAN is invalid, ignoring assignment: %s", rvalue);
+                return 0;
+        }
+
+        if (netdev->kind != NETDEV_KIND_MACVLAN) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "NetDev is not a MACVLAN, ignoring assignment: %s", rvalue);
+                return 0;
+        }
+
+        r = hashmap_put(network->macvlans, netdev->name, netdev);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Can not add MACVLAN to network: %s", rvalue);
+                return 0;
+        }
+
+        return 0;
+}