summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-address.c60
-rw-r--r--src/network/networkd-link.c6
-rw-r--r--src/network/networkd-netdev-tunnel.c17
-rw-r--r--src/network/networkd-route.c38
4 files changed, 65 insertions, 56 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 1b2d7d52ff..ae87b83524 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -394,7 +394,8 @@ int address_configure(Address *address, Link *link,
return 0;
}
-int config_parse_broadcast(const char *unit,
+int config_parse_broadcast(
+ const char *unit,
const char *filename,
unsigned line,
const char *section,
@@ -404,9 +405,9 @@ int config_parse_broadcast(const char *unit,
const char *rvalue,
void *data,
void *userdata) {
+
Network *network = userdata;
_cleanup_address_free_ Address *n = NULL;
- _cleanup_free_ char *address = NULL;
int r;
assert(filename);
@@ -421,18 +422,18 @@ int config_parse_broadcast(const char *unit,
if (n->family == AF_INET6) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Broadcast is not valid for IPv6 addresses, "
- "ignoring assignment: %s", address);
+ "Broadcast is not valid for IPv6 addresses, ignoring assignment: %s", rvalue);
return 0;
}
- r = net_parse_inaddr(address, &n->family, &n->broadcast);
+ r = in_addr_from_string(AF_INET, rvalue, (union in_addr_union*) &n->broadcast);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Broadcast is invalid, ignoring assignment: %s", address);
+ "Broadcast is invalid, ignoring assignment: %s", rvalue);
return 0;
}
+ n->family = AF_INET;
n = NULL;
return 0;
@@ -448,12 +449,12 @@ int config_parse_address(const char *unit,
const char *rvalue,
void *data,
void *userdata) {
+
Network *network = userdata;
_cleanup_address_free_ Address *n = NULL;
- _cleanup_free_ char *address = NULL;
- union in_addr_union *addr;
- const char *e;
- int r;
+ const char *address, *e;
+ union in_addr_union buffer;
+ int r, f;
assert(filename);
assert(section);
@@ -471,11 +472,6 @@ int config_parse_address(const char *unit,
if (r < 0)
return r;
- if (streq(lvalue, "Address"))
- addr = &n->in_addr;
- else
- addr = &n->in_addr_peer;
-
/* Address=address/prefixlen */
/* prefixlen */
@@ -485,32 +481,38 @@ int config_parse_address(const char *unit,
r = safe_atou(e + 1, &i);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Interface prefix length is invalid, "
- "ignoring assignment: %s", e + 1);
+ "Interface prefix length is invalid, ignoring assignment: %s", e + 1);
return 0;
}
n->prefixlen = (unsigned char) i;
- address = strndup(rvalue, e - rvalue);
- if (!address)
- return log_oom();
- } else {
- address = strdup(rvalue);
- if (!address)
- return log_oom();
- }
+ address = strndupa(rvalue, e - rvalue);
+ } else
+ address = rvalue;
- r = net_parse_inaddr(address, &n->family, addr);
+ r = in_addr_from_string_auto(address, &f, &buffer);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
"Address is invalid, ignoring assignment: %s", address);
return 0;
}
- if (n->family == AF_INET && !n->broadcast.s_addr)
- n->broadcast.s_addr = n->in_addr.in.s_addr |
- htonl(0xfffffffflu >> n->prefixlen);
+ if (n->family != AF_UNSPEC && f != n->family) {
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+ "Address is incompatible, ignoring assignment: %s", address);
+ return 0;
+ }
+
+ n->family = f;
+
+ if (streq(lvalue, "Address"))
+ n->in_addr = buffer;
+ else
+ n->in_addr_peer = buffer;
+
+ if (n->family == AF_INET && n->broadcast.s_addr == 0)
+ n->broadcast.s_addr = n->in_addr.in.s_addr | htonl(0xfffffffflu >> n->prefixlen);
n = NULL;
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index accb42bf37..d13a47bb2e 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -750,7 +750,7 @@ static int link_enter_set_addresses(Link *link) {
return r;
}
- prefixlen = net_netmask_to_prefixlen(&netmask);
+ prefixlen = in_addr_netmask_to_prefixlen(&netmask);
r = address_new_dynamic(&address);
if (r < 0) {
@@ -983,7 +983,7 @@ static int dhcp_lease_lost(Link *link) {
sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
- prefixlen = net_netmask_to_prefixlen(&netmask);
+ prefixlen = in_addr_netmask_to_prefixlen(&netmask);
address->family = AF_INET;
address->in_addr.in = addr;
@@ -1073,7 +1073,7 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
return r;
}
- prefixlen = net_netmask_to_prefixlen(&netmask);
+ prefixlen = in_addr_netmask_to_prefixlen(&netmask);
r = sd_dhcp_lease_get_router(lease, &gateway);
if (r < 0 && r != -ENOENT) {
diff --git a/src/network/networkd-netdev-tunnel.c b/src/network/networkd-netdev-tunnel.c
index 4561f8d0a9..56eeb99e4b 100644
--- a/src/network/networkd-netdev-tunnel.c
+++ b/src/network/networkd-netdev-tunnel.c
@@ -266,21 +266,28 @@ int config_parse_tunnel_address(const char *unit,
void *data,
void *userdata) {
Tunnel *t = userdata;
- union in_addr_union *addr = data;
- int r;
+ union in_addr_union *addr = data, buffer;
+ int r, f;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
- r = net_parse_inaddr(rvalue, &t->family, addr);
+ r = in_addr_from_string_auto(rvalue, &f, &buffer);
if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Tunnel address is invalid, ignoring assignment: %s", rvalue);
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Tunnel address is invalid, ignoring assignment: %s", rvalue);
return 0;
}
+ if (t->family != AF_UNSPEC && t->family != f) {
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Tunnel addresses incompatible, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+
+ t->family = f;
+ *addr = buffer;
+
return 0;
}
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index f451b975a7..77c2daddc5 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -256,10 +256,11 @@ int config_parse_gateway(const char *unit,
const char *rvalue,
void *data,
void *userdata) {
+
Network *network = userdata;
_cleanup_route_free_ Route *n = NULL;
- _cleanup_free_ char *route = NULL;
- int r;
+ union in_addr_union buffer;
+ int r, f;
assert(filename);
assert(section);
@@ -277,13 +278,15 @@ int config_parse_gateway(const char *unit,
if (r < 0)
return r;
- r = net_parse_inaddr(rvalue, &n->family, &n->in_addr);
+ r = in_addr_from_string_auto(rvalue, &f, &buffer);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Route is invalid, ignoring assignment: %s", route);
+ "Route is invalid, ignoring assignment: %s", rvalue);
return 0;
}
+ n->family = f;
+ n->in_addr = buffer;
n = NULL;
return 0;
@@ -299,11 +302,12 @@ int config_parse_destination(const char *unit,
const char *rvalue,
void *data,
void *userdata) {
+
Network *network = userdata;
_cleanup_route_free_ Route *n = NULL;
- _cleanup_free_ char *address = NULL;
- const char *e;
- int r;
+ const char *address, *e;
+ union in_addr_union buffer;
+ int r, f;
assert(filename);
assert(section);
@@ -319,17 +323,12 @@ int config_parse_destination(const char *unit,
/* address */
e = strchr(rvalue, '/');
- if (e) {
- address = strndup(rvalue, e - rvalue);
- if (!address)
- return log_oom();
- } else {
- address = strdup(rvalue);
- if (!address)
- return log_oom();
- }
+ if (e)
+ address = strndupa(rvalue, e - rvalue);
+ else
+ address = rvalue;
- r = net_parse_inaddr(address, &n->family, &n->dst_addr);
+ r = in_addr_from_string_auto(address, &f, &buffer);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
"Destination is invalid, ignoring assignment: %s", address);
@@ -343,8 +342,7 @@ int config_parse_destination(const char *unit,
r = safe_atou(e + 1, &i);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Route destination prefix length is invalid, "
- "ignoring assignment: %s", e + 1);
+ "Route destination prefix length is invalid, ignoring assignment: %s", e + 1);
return 0;
}
@@ -360,6 +358,8 @@ int config_parse_destination(const char *unit,
}
}
+ n->family = f;
+ n->dst_addr = buffer;
n = NULL;
return 0;