]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: tighten parsing of Tunnel addresses
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 2 Dec 2016 18:28:01 +0000 (13:28 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 9 Dec 2016 18:55:14 +0000 (13:55 -0500)
When assigning addresses, we'd set the family, and later
verify that the address on the other end has the same family.
But when the address was specified as "any", we'd simply unset
the family. Instead, only unset the family if both addresses
are wiped.

Also, don't bother setting family = AF_UNSPEC, since it's the default (0).

src/network/netdev/tunnel.c

index b1f1b5a425ea5a307482f58f280448d82a77e350..2ce55a84b68e3c0eab8bc92fd6adc880e02b0cbd 100644 (file)
@@ -432,26 +432,40 @@ int config_parse_tunnel_address(const char *unit,
         assert(rvalue);
         assert(data);
 
+        /* This is used to parse addresses on both local and remote ends of the tunnel.
+         * Address families must match.
+         *
+         * "any" is a special value which means that the address is unspecified.
+         */
+
         if (streq(rvalue, "any")) {
-                t->family = 0;
+                *addr = IN_ADDR_NULL;
+
+                /* As a special case, if both the local and remote addresses are
+                 * unspecified, also clear the address family.
+                 */
+                if (t->family != AF_UNSPEC &&
+                    in_addr_is_null(t->family, &t->local) &&
+                    in_addr_is_null(t->family, &t->remote))
+                        t->family = AF_UNSPEC;
                 return 0;
-        } else {
+        }
 
-                r = in_addr_from_string_auto(rvalue, &f, &buffer);
-                if (r < 0) {
-                        log_syntax(unit, LOG_ERR, filename, line, r, "Tunnel address is invalid, ignoring assignment: %s", rvalue);
-                        return 0;
-                }
+        r = in_addr_from_string_auto(rvalue, &f, &buffer);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, r,
+                           "Tunnel address \"%s\" invalid, ignoring assignment: %m", rvalue);
+                return 0;
+        }
 
-                if (t->family != AF_UNSPEC && t->family != f) {
-                        log_syntax(unit, LOG_ERR, filename, line, 0, "Tunnel addresses incompatible, ignoring assignment: %s", rvalue);
-                        return 0;
-                }
+        if (t->family != AF_UNSPEC && t->family != f) {
+                log_syntax(unit, LOG_ERR, filename, line, 0,
+                           "Tunnel addresses incompatible, ignoring assignment: %s", rvalue);
+                return 0;
         }
 
         t->family = f;
         *addr = buffer;
-
         return 0;
 }
 
@@ -579,7 +593,6 @@ static void ipip_init(NetDev *n) {
         assert(t);
 
         t->pmtudisc = true;
-        t->family = AF_UNSPEC;
 }
 
 static void sit_init(NetDev *n) {
@@ -589,7 +602,6 @@ static void sit_init(NetDev *n) {
         assert(t);
 
         t->pmtudisc = true;
-        t->family = AF_UNSPEC;
 }
 
 static void vti_init(NetDev *n) {
@@ -620,7 +632,6 @@ static void gre_init(NetDev *n) {
         assert(t);
 
         t->pmtudisc = true;
-        t->family = AF_UNSPEC;
 }
 
 static void ip6gre_init(NetDev *n) {