chiark / gitweb /
treewide: correct typos and use consistent "MAC" spelling
[elogind.git] / src / network / networkd-network.c
index 2b555ef..3ebd4d7 100644 (file)
@@ -34,6 +34,7 @@
 static int network_load_one(Manager *manager, const char *filename) {
         _cleanup_network_free_ Network *network = NULL;
         _cleanup_fclose_ FILE *file = NULL;
+        char *d;
         Route *route;
         Address *address;
         int r;
@@ -84,6 +85,18 @@ static int network_load_one(Manager *manager, const char *filename) {
         if (!network->filename)
                 return log_oom();
 
+        network->name = strdup(basename(filename));
+        if (!network->name)
+                return log_oom();
+
+        d = strrchr(network->name, '.');
+        if (!d)
+                return -EINVAL;
+
+        assert(streq(d, ".network"));
+
+        *d = '\0';
+
         network->dhcp = ADDRESS_FAMILY_NO;
         network->dhcp_ntp = true;
         network->dhcp_dns = true;
@@ -94,6 +107,8 @@ static int network_load_one(Manager *manager, const char *filename) {
 
         network->llmnr = LLMNR_SUPPORT_YES;
 
+        network->link_local = ADDRESS_FAMILY_IPV6;
+
         r = config_parse(NULL, filename, file,
                          "Match\0"
                          "Link\0"
@@ -115,6 +130,14 @@ static int network_load_one(Manager *manager, const char *filename) {
 
         LIST_PREPEND(networks, manager->networks, network);
 
+        r = hashmap_ensure_allocated(&manager->networks_by_name, &string_hash_ops);
+        if (r < 0)
+                return r;
+
+        r = hashmap_put(manager->networks_by_name, network->name, network);
+        if (r < 0)
+                return r;
+
         LIST_FOREACH(routes, route, network->static_routes) {
                 if (!route->family) {
                         log_warning("Route section without Gateway field configured in %s. "
@@ -210,8 +233,15 @@ void network_free(Network *network) {
         hashmap_free(network->routes_by_section);
         hashmap_free(network->fdb_entries_by_section);
 
-        if (network->manager && network->manager->networks)
-                LIST_REMOVE(networks, network->manager->networks, network);
+        if (network->manager) {
+                if (network->manager->networks)
+                        LIST_REMOVE(networks, network->manager->networks, network);
+
+                if (network->manager->networks_by_name)
+                        hashmap_remove(network->manager->networks_by_name, network->name);
+        }
+
+        free(network->name);
 
         condition_free_list(network->match_host);
         condition_free_list(network->match_virt);
@@ -221,6 +251,22 @@ void network_free(Network *network) {
         free(network);
 }
 
+int network_get_by_name(Manager *manager, const char *name, Network **ret) {
+        Network *network;
+
+        assert(manager);
+        assert(name);
+        assert(ret);
+
+        network = hashmap_get(manager->networks_by_name, name);
+        if (!network)
+                return -ENOENT;
+
+        *ret = network;
+
+        return 0;
+}
+
 int network_get(Manager *manager, struct udev_device *device,
                 const char *ifname, const struct ether_addr *address,
                 Network **ret) {
@@ -453,7 +499,11 @@ int config_parse_tunnel(const char *unit,
             netdev->kind != NETDEV_KIND_SIT &&
             netdev->kind != NETDEV_KIND_GRE &&
             netdev->kind != NETDEV_KIND_GRETAP &&
-            netdev->kind != NETDEV_KIND_VTI) {
+            netdev->kind != NETDEV_KIND_IP6GRE &&
+            netdev->kind != NETDEV_KIND_IP6GRETAP &&
+            netdev->kind != NETDEV_KIND_VTI &&
+            netdev->kind != NETDEV_KIND_IP6TNL
+            ) {
                 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
                            "NetDev is not a tunnel, ignoring assignment: %s", rvalue);
                 return 0;
@@ -472,6 +522,37 @@ int config_parse_tunnel(const char *unit,
         return 0;
 }
 
+int config_parse_ipv4ll(
+                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) {
+
+        AddressFamilyBoolean *link_local = data;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        /* Note that this is mostly like
+         * config_parse_address_family_boolean(), except that it
+         * applies only to IPv4 */
+
+        if (parse_boolean(rvalue))
+                *link_local |= ADDRESS_FAMILY_IPV4;
+        else
+                *link_local &= ~ADDRESS_FAMILY_IPV4;
+
+        return 0;
+}
+
 int config_parse_dhcp(
                 const char* unit,
                 const char *filename,
@@ -545,7 +626,7 @@ int config_parse_llmnr(
         assert(filename);
         assert(lvalue);
         assert(rvalue);
-        assert(data);
+        assert(llmnr);
 
         /* Our enum shall be a superset of booleans, hence first try
          * to parse as boolean, and then as enum */
@@ -569,3 +650,46 @@ int config_parse_llmnr(
 
         return 0;
 }
+
+int config_parse_token(
+                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) {
+
+        union in_addr_union buffer;
+        struct in6_addr *token = data;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(token);
+
+        r = in_addr_from_string(AF_INET6, rvalue, &buffer);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, -r, "Failed to parse IPv6 token, ignoring: %s", rvalue);
+                return 0;
+        }
+
+        r = in_addr_is_null(AF_INET6, &buffer);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, -r, "IPv6 token can not be the ANY address, ignoring: %s", rvalue);
+                return 0;
+        }
+
+        if ((buffer.in6.s6_addr32[0] | buffer.in6.s6_addr32[1]) != 0) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL, "IPv6 token can not be longer than 64 bits, ignoring: %s", rvalue);
+                return 0;
+        }
+
+        *token = buffer.in6;
+
+        return 0;
+}