summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/network/networkd-netdev.c53
-rw-r--r--src/network/networkd-tunnel.c24
-rw-r--r--src/network/networkd.h7
3 files changed, 58 insertions, 26 deletions
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index cc85e5348b..a810be04b9 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -254,8 +254,8 @@ int config_parse_tunnel_address(const char *unit,
const char *rvalue,
void *data,
void *userdata) {
- NetDev *n = data;
- unsigned char family = AF_INET;
+ NetDev *n = userdata;
+ union in_addr_union *addr = data;
int r;
assert(filename);
@@ -263,13 +263,14 @@ int config_parse_tunnel_address(const char *unit,
assert(rvalue);
assert(data);
- r = net_parse_inaddr(rvalue, &family, n);
+ r = net_parse_inaddr(rvalue, &n->family, addr);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
"Tunnel address is invalid, ignoring assignment: %s", rvalue);
return 0;
}
- return 0;
+
+ return 0;
}
static int netdev_create(NetDev *netdev) {
@@ -607,9 +608,41 @@ static int netdev_load_one(Manager *manager, const char *filename) {
return r;
}
- if (netdev->kind == _NETDEV_KIND_INVALID) {
+ switch (netdev->kind) {
+ case _NETDEV_KIND_INVALID:
log_warning("NetDev without Kind configured in %s. Ignoring", filename);
return 0;
+ case NETDEV_KIND_VLAN:
+ if (netdev->vlanid > VLANID_MAX) {
+ log_warning("VLAN without valid Id configured in %s. Ignoring", filename);
+ return 0;
+ }
+ break;
+ case NETDEV_KIND_VXLAN:
+ if (netdev->vxlanid > VXLAN_VID_MAX) {
+ log_warning("VXLAN without valid Id configured in %s. Ignoring", filename);
+ return 0;
+ }
+ break;
+ case NETDEV_KIND_IPIP:
+ case NETDEV_KIND_GRE:
+ case NETDEV_KIND_SIT:
+ case NETDEV_KIND_VTI:
+ if (netdev->local.in.s_addr == INADDR_ANY) {
+ log_warning("Tunnel without local address configured in %s. Ignoring", filename);
+ return 0;
+ }
+ if (netdev->remote.in.s_addr == INADDR_ANY) {
+ log_warning("Tunnel without remote address configured in %s. Ignoring", filename);
+ return 0;
+ }
+ if (netdev->family != AF_INET) {
+ log_warning("Tunnel with invalid address family configured in %s. Ignoring", filename);
+ return 0;
+ }
+ break;
+ default:
+ break;
}
if (!netdev->ifname) {
@@ -617,16 +650,6 @@ static int netdev_load_one(Manager *manager, const char *filename) {
return 0;
}
- if (netdev->kind == NETDEV_KIND_VLAN && netdev->vlanid > VLANID_MAX) {
- log_warning("VLAN without valid Id configured in %s. Ignoring", filename);
- return 0;
- }
-
- if (netdev->kind == NETDEV_KIND_VXLAN && netdev->vxlanid > VXLAN_VID_MAX) {
- log_warning("VXLAN without valid Id configured in %s. Ignoring", filename);
- return 0;
- }
-
if (netdev->kind != NETDEV_KIND_VLAN && netdev->vlanid <= VLANID_MAX) {
log_warning("VLAN Id configured for a %s in %s. Ignoring",
netdev_kind_to_string(netdev->kind), filename);
diff --git a/src/network/networkd-tunnel.c b/src/network/networkd-tunnel.c
index cffa5644ca..bd12259420 100644
--- a/src/network/networkd-tunnel.c
+++ b/src/network/networkd-tunnel.c
@@ -43,6 +43,8 @@ static int netdev_fill_ipip_rtnl_message(Link *link, sd_rtnl_message *m) {
netdev = link->network->tunnel;
+ assert(netdev->family == AF_INET);
+
r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
if (r < 0) {
log_error_netdev(netdev,
@@ -96,7 +98,7 @@ static int netdev_fill_ipip_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &netdev->local);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &netdev->local.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_LOCAL attribute: %s",
@@ -104,7 +106,7 @@ static int netdev_fill_ipip_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &netdev->remote);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &netdev->remote.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_REMOTE attribute: %s",
@@ -150,6 +152,8 @@ static int netdev_fill_sit_rtnl_message(Link *link, sd_rtnl_message *m) {
netdev = link->network->tunnel;
+ assert(netdev->family == AF_INET);
+
r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
if (r < 0) {
log_error_netdev(netdev,
@@ -203,7 +207,7 @@ static int netdev_fill_sit_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &netdev->local);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &netdev->local.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_LOCAL attribute: %s",
@@ -211,7 +215,7 @@ static int netdev_fill_sit_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &netdev->remote);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &netdev->remote.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_REMOTE attribute: %s",
@@ -265,6 +269,8 @@ static int netdev_fill_ipgre_rtnl_message(Link *link, sd_rtnl_message *m) {
netdev = link->network->tunnel;
+ assert(netdev->family == AF_INET);
+
r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
if (r < 0) {
log_error_netdev(netdev,
@@ -318,7 +324,7 @@ static int netdev_fill_ipgre_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_LOCAL, &netdev->local);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_LOCAL, &netdev->local.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_GRE_LOCAL attribute: %s",
@@ -326,7 +332,7 @@ static int netdev_fill_ipgre_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_REMOTE, &netdev->remote);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_REMOTE, &netdev->remote.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_GRE_REMOTE attribute: %s",
@@ -380,6 +386,8 @@ static int netdev_fill_vti_rtnl_message(Link *link, sd_rtnl_message *m) {
netdev = link->network->tunnel;
+ assert(netdev->family == AF_INET);
+
r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
if (r < 0) {
log_error_netdev(netdev,
@@ -433,7 +441,7 @@ static int netdev_fill_vti_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_LOCAL, &netdev->local);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_LOCAL, &netdev->local.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_LOCAL attribute: %s",
@@ -441,7 +449,7 @@ static int netdev_fill_vti_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_REMOTE, &netdev->remote);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_REMOTE, &netdev->remote.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_REMOTE attribute: %s",
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 67ca41b8a4..6a00175157 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -134,9 +134,10 @@ struct NetDev {
unsigned ttl;
unsigned tos;
- struct in_addr local;
- struct in_addr remote;
- struct in_addr group;
+ unsigned char family;
+ union in_addr_union local;
+ union in_addr_union remote;
+ union in_addr_union group;
LIST_HEAD(netdev_enslave_callback, callbacks);
};