summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2022-04-17 21:24:38 +0200
committerGitHub <noreply@github.com>2022-04-17 21:24:38 +0200
commitee5b175b8c223b4db2d21a41c502b782ad0febad (patch)
treeb1f3c2bef1647d62b9dd37ac35c45a5c6ba355ae /src
parentbf93f24ad8743e1dae7d8629946df7325af2bef7 (diff)
parent5984b92726e3b3051e404febbf15615fa38d3a61 (diff)
downloadsystemd-ee5b175b8c223b4db2d21a41c502b782ad0febad.tar.gz
Merge pull request #23100 from yuwata/network-fix-tunnel-address-parser
network: fix tunnel address parser
Diffstat (limited to 'src')
-rw-r--r--src/network/netdev/l2tp-tunnel.c48
-rw-r--r--src/network/netdev/tunnel.c59
2 files changed, 75 insertions, 32 deletions
diff --git a/src/network/netdev/l2tp-tunnel.c b/src/network/netdev/l2tp-tunnel.c
index 9724e7760e..05af5dbf89 100644
--- a/src/network/netdev/l2tp-tunnel.c
+++ b/src/network/netdev/l2tp-tunnel.c
@@ -486,7 +486,8 @@ int config_parse_l2tp_tunnel_local_address(
L2tpLocalAddressType type;
L2tpTunnel *t = userdata;
const char *p = rvalue;
- int r;
+ union in_addr_union a;
+ int r, f;
assert(filename);
assert(lvalue);
@@ -539,16 +540,27 @@ int config_parse_l2tp_tunnel_local_address(
return 0;
}
- if (t->family == AF_UNSPEC)
- r = in_addr_from_string_auto(rvalue, &t->family, &t->local);
- else
- r = in_addr_from_string(t->family, rvalue, &t->local);
+ r = in_addr_from_string_auto(rvalue, &f, &a);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
- "Invalid L2TP Tunnel address specified in %s=, ignoring assignment: %s", lvalue, rvalue);
+ "Invalid L2TP Tunnel local address specified, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+
+ if (in_addr_is_null(f, &a)) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "L2TP Tunnel local address cannot be null, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+
+ if (t->family != AF_UNSPEC && t->family != f) {
+ log_syntax(unit, LOG_WARNING, filename, line, 0,
+ "Address family does not match the previous assignment, ignoring assignment: %s", rvalue);
return 0;
}
+ t->family = f;
+ t->local = a;
free_and_replace(t->local_ifname, ifname);
t->local_address_type = _NETDEV_L2TP_LOCAL_ADDRESS_INVALID;
return 0;
@@ -567,7 +579,8 @@ int config_parse_l2tp_tunnel_remote_address(
void *userdata) {
L2tpTunnel *t = userdata;
- int r;
+ union in_addr_union a;
+ int r, f;
assert(filename);
assert(lvalue);
@@ -584,16 +597,27 @@ int config_parse_l2tp_tunnel_remote_address(
return 0;
}
- if (t->family == AF_UNSPEC)
- r = in_addr_from_string_auto(rvalue, &t->family, &t->remote);
- else
- r = in_addr_from_string(t->family, rvalue, &t->remote);
+ r = in_addr_from_string_auto(rvalue, &f, &a);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
- "Invalid L2TP Tunnel address specified in %s=, ignoring assignment: %s", lvalue, rvalue);
+ "Invalid L2TP Tunnel remote address specified, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+
+ if (in_addr_is_null(f, &a)) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "L2TP Tunnel remote address cannot be null, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+
+ if (t->family != AF_UNSPEC && t->family != f) {
+ log_syntax(unit, LOG_WARNING, filename, line, 0,
+ "Address family does not match the previous assignment, ignoring assignment: %s", rvalue);
return 0;
}
+ t->family = f;
+ t->remote = a;
return 0;
}
diff --git a/src/network/netdev/tunnel.c b/src/network/netdev/tunnel.c
index 3ba4484b6b..747acb1e80 100644
--- a/src/network/netdev/tunnel.c
+++ b/src/network/netdev/tunnel.c
@@ -7,6 +7,7 @@
#include <linux/ip.h>
#include <linux/ip6_tunnel.h>
+#include "af-list.h"
#include "conf-parser.h"
#include "hexdecoct.h"
#include "missing_network.h"
@@ -737,6 +738,20 @@ static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
return 0;
}
+static int unset_local(Tunnel *t) {
+ assert(t);
+
+ /* Unset the previous assignment. */
+ t->local = IN_ADDR_NULL;
+ t->local_type = _NETDEV_LOCAL_ADDRESS_TYPE_INVALID;
+
+ /* If the remote address is not specified, also clear the address family. */
+ if (!in_addr_is_set(t->family, &t->remote))
+ t->family = AF_UNSPEC;
+
+ return 0;
+}
+
int config_parse_tunnel_local_address(
const char *unit,
const char *filename,
@@ -759,16 +774,8 @@ int config_parse_tunnel_local_address(
assert(rvalue);
assert(userdata);
- if (isempty(rvalue) || streq(rvalue, "any")) {
- /* Unset the previous assignment. */
- t->local = IN_ADDR_NULL;
- t->local_type = _NETDEV_LOCAL_ADDRESS_TYPE_INVALID;
-
- /* If the remote address is not specified, also clear the address family. */
- if (!in_addr_is_set(t->family, &t->remote))
- t->family = AF_UNSPEC;
- return 0;
- }
+ if (isempty(rvalue) || streq(rvalue, "any"))
+ return unset_local(t);
type = netdev_local_address_type_from_string(rvalue);
if (IN_SET(type, NETDEV_LOCAL_ADDRESS_IPV4LL, NETDEV_LOCAL_ADDRESS_DHCP4))
@@ -783,6 +790,9 @@ int config_parse_tunnel_local_address(
"Tunnel address \"%s\" invalid, ignoring assignment: %m", rvalue);
return 0;
}
+
+ if (in_addr_is_null(f, &buffer))
+ return unset_local(t);
}
if (t->family != AF_UNSPEC && t->family != f) {
@@ -797,6 +807,20 @@ int config_parse_tunnel_local_address(
return 0;
}
+static int unset_remote(Tunnel *t) {
+ assert(t);
+
+ /* Unset the previous assignment. */
+ t->remote = IN_ADDR_NULL;
+
+ /* If the local address is not specified, also clear the address family. */
+ if (t->local_type == _NETDEV_LOCAL_ADDRESS_TYPE_INVALID &&
+ !in_addr_is_set(t->family, &t->local))
+ t->family = AF_UNSPEC;
+
+ return 0;
+}
+
int config_parse_tunnel_remote_address(
const char *unit,
const char *filename,
@@ -818,16 +842,8 @@ int config_parse_tunnel_remote_address(
assert(rvalue);
assert(userdata);
- if (isempty(rvalue) || streq(rvalue, "any")) {
- /* Unset the previous assignment. */
- t->remote = IN_ADDR_NULL;
-
- /* If the local address is not specified, also clear the address family. */
- if (t->local_type == _NETDEV_LOCAL_ADDRESS_TYPE_INVALID &&
- !in_addr_is_set(t->family, &t->local))
- t->family = AF_UNSPEC;
- return 0;
- }
+ if (isempty(rvalue) || streq(rvalue, "any"))
+ return unset_remote(t);
r = in_addr_from_string_auto(rvalue, &f, &buffer);
if (r < 0) {
@@ -836,6 +852,9 @@ int config_parse_tunnel_remote_address(
return 0;
}
+ if (in_addr_is_null(f, &buffer))
+ return unset_remote(t);
+
if (t->family != AF_UNSPEC && t->family != f) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Address family does not match the previous assignment, ignoring assignment: %s", rvalue);