chiark / gitweb /
net-util: verify the address family
authorTom Gundersen <teg@jklm.no>
Tue, 28 Jan 2014 19:00:47 +0000 (20:00 +0100)
committerTom Gundersen <teg@jklm.no>
Thu, 30 Jan 2014 13:30:39 +0000 (14:30 +0100)
Error out if the address family is already set to something incompatible with the
address being parsed.

src/network/networkd-address.c
src/network/networkd-network.c
src/network/networkd-route.c
src/network/networkd.h
src/shared/net-util.c

index 3f787948f92dfcccb5afe703e99986773b6dfcd4..de5566dfdb44b96b50bf749fc2a4667a4f68de07 100644 (file)
@@ -46,6 +46,8 @@ int address_new_static(Network *network, unsigned section, Address **ret) {
         if (!address)
                 return -ENOMEM;
 
+        address->family = AF_UNSPEC;
+
         address->network = network;
 
         LIST_PREPEND(static_addresses, network->static_addresses, address);
@@ -68,6 +70,8 @@ int address_new_dynamic(Address **ret) {
         if (!address)
                 return -ENOMEM;
 
+        address->family = AF_UNSPEC;
+
         *ret = address;
         address = NULL;
 
index 2a720349a07fd5395fa2c491ca52df251c69fe43..94138cd55814cbdc826ae185dcd402d9f26ea5fa 100644 (file)
@@ -84,12 +84,6 @@ static int network_load_one(Manager *manager, const char *filename) {
                                     "Ignoring", filename);
                         return 0;
                 }
-
-                if (route->dst_family && route->family != route->dst_family) {
-                        log_warning("Route section with conflicting Gateway and Destination address "
-                                    "family configured in %s. Ignoring", filename);
-                        return 0;
-                }
         }
 
         LIST_FOREACH(static_addresses, address, network->static_addresses) {
index 83dad655db19658d5434c4191881afae439c21bd..29ee1045da55ed7c6b067b180c980faf960a53eb 100644 (file)
@@ -47,6 +47,8 @@ int route_new_static(Network *network, unsigned section, Route **ret) {
         if (!route)
                 return -ENOMEM;
 
+        route->family = AF_UNSPEC;
+
         route->network = network;
 
         LIST_PREPEND(static_routes, network->static_routes, route);
@@ -69,6 +71,8 @@ int route_new_dynamic(Route **ret) {
         if (!route)
                 return -ENOMEM;
 
+        route->family = AF_UNSPEC;
+
         *ret = route;
         route = NULL;
 
@@ -231,7 +235,7 @@ int config_parse_destination(const char *unit,
                         return log_oom();
         }
 
-        r = net_parse_inaddr(address, &n->dst_family, &n->dst_addr);
+        r = net_parse_inaddr(address, &n->family, &n->dst_addr);
         if (r < 0) {
                 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
                            "Destination is invalid, ignoring assignment: %s", address);
@@ -252,7 +256,7 @@ int config_parse_destination(const char *unit,
 
                 n->dst_prefixlen = (unsigned char) i;
         } else {
-                switch (n->dst_family) {
+                switch (n->family) {
                         case AF_INET:
                                 n->dst_prefixlen = 32;
                                 break;
index 968edf6a70d5b925808e5dfd89329e430105e904..f174abbf5937ba85cb546818c7951068cb5ac39e 100644 (file)
@@ -138,7 +138,6 @@ struct Route {
         uint64_t section;
 
         unsigned char family;
-        unsigned char dst_family;
         unsigned char dst_prefixlen;
 
         union {
index 8f8cfc9fdb6d7fe6ece6b9ede732c13a85ec4d95..887dae51251647a16a2e6d1115b7a9c69302fa94 100644 (file)
@@ -192,16 +192,24 @@ int net_parse_inaddr(const char *address, unsigned char *family, void *dst) {
 
         /* IPv4 */
         r = inet_pton(AF_INET, address, dst);
-        if (r > 0)
-                *family = AF_INET; /* successfully parsed IPv4 address */
-        else  if (r < 0)
+        if (r > 0) {
+                /* succsefully parsed IPv4 address */
+                if (*family == AF_UNSPEC)
+                        *family = AF_INET;
+                else if (*family != AF_INET)
+                        return -EINVAL;
+        } else  if (r < 0)
                 return -errno;
         else {
                 /* not an IPv4 address, so let's try IPv6 */
                 r = inet_pton(AF_INET6, address, dst);
-                if (r > 0)
-                        *family = AF_INET6; /* successfully parsed IPv6 address */
-                else if (r < 0)
+                if (r > 0) {
+                        /* successfully parsed IPv6 address */
+                        if (*family == AF_UNSPEC)
+                                *family = AF_INET6;
+                        else if (*family != AF_INET6)
+                                return -EINVAL;
+                } else if (r < 0)
                         return -errno;
                 else
                         return -EINVAL;