diff options
author | Tom Gundersen <teg@jklm.no> | 2015-10-25 14:35:40 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-10-25 14:35:40 +0100 |
commit | 1e23792147b675cf6d3d7e85d02ba3d4dcc886c1 (patch) | |
tree | ce05af47b9489f6516c8ad7baa079d73d11575e6 | |
parent | 7c8871d31510865e40c8628ef765996202a3cc00 (diff) | |
parent | c2353b2f2f03b131d99491f458f439e4c65825c9 (diff) |
Merge pull request #1668 from ssahani/net1
networkd: fix asserts
-rw-r--r-- | src/network/networkd-netdev-bond.c | 17 | ||||
-rw-r--r-- | src/network/networkd-netdev-ipvlan.c | 12 | ||||
-rw-r--r-- | src/network/networkd-netdev-veth.c | 19 | ||||
-rw-r--r-- | src/network/networkd-netdev-vlan.c | 14 | ||||
-rw-r--r-- | src/network/networkd-netdev-vxlan.c | 11 |
5 files changed, 54 insertions, 19 deletions
diff --git a/src/network/networkd-netdev-bond.c b/src/network/networkd-netdev-bond.c index f66c88c35e..afc1efdcf7 100644 --- a/src/network/networkd-netdev-bond.c +++ b/src/network/networkd-netdev-bond.c @@ -180,15 +180,18 @@ static uint8_t bond_xmit_hash_policy_to_kernel(BondXmitHashPolicy policy) { } static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { - Bond *b = BOND(netdev); + Bond *b; ArpIpTarget *target = NULL; int r, i = 0; assert(netdev); assert(!link); - assert(b); assert(m); + b = BOND(netdev); + + assert(b); + if (b->mode != _NETDEV_BOND_MODE_INVALID) { r = sd_netlink_message_append_u8(m, IFLA_BOND_MODE, bond_mode_to_kernel(b->mode)); @@ -382,9 +385,12 @@ int config_parse_arp_ip_target_address(const char *unit, static void bond_done(NetDev *netdev) { ArpIpTarget *t = NULL, *n = NULL; - Bond *b = BOND(netdev); + Bond *b; assert(netdev); + + b = BOND(netdev); + assert(b); LIST_FOREACH_SAFE(arp_ip_target, t, n, b->arp_ip_targets) @@ -394,9 +400,12 @@ static void bond_done(NetDev *netdev) { } static void bond_init(NetDev *netdev) { - Bond *b = BOND(netdev); + Bond *b; assert(netdev); + + b = BOND(netdev); + assert(b); b->mode = _NETDEV_BOND_MODE_INVALID; diff --git a/src/network/networkd-netdev-ipvlan.c b/src/network/networkd-netdev-ipvlan.c index 5eb4a1eb36..fb0aed0dcb 100644 --- a/src/network/networkd-netdev-ipvlan.c +++ b/src/network/networkd-netdev-ipvlan.c @@ -33,14 +33,17 @@ DEFINE_STRING_TABLE_LOOKUP(ipvlan_mode, IPVlanMode); DEFINE_CONFIG_PARSE_ENUM(config_parse_ipvlan_mode, ipvlan_mode, IPVlanMode, "Failed to parse ipvlan mode"); static int netdev_ipvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) { - IPVlan *m = IPVLAN(netdev); + IPVlan *m; int r; assert(netdev); - assert(m); assert(link); assert(netdev->ifname); + m = IPVLAN(netdev); + + assert(m); + if (m->mode != _NETDEV_IPVLAN_MODE_INVALID) { r = sd_netlink_message_append_u16(req, IFLA_IPVLAN_MODE, m->mode); if (r < 0) @@ -51,9 +54,12 @@ static int netdev_ipvlan_fill_message_create(NetDev *netdev, Link *link, sd_netl } static void ipvlan_init(NetDev *n) { - IPVlan *m = IPVLAN(n); + IPVlan *m; assert(n); + + m = IPVLAN(n); + assert(m); m->mode = _NETDEV_IPVLAN_MODE_INVALID; diff --git a/src/network/networkd-netdev-veth.c b/src/network/networkd-netdev-veth.c index e20f9f74e2..bee1a16726 100644 --- a/src/network/networkd-netdev-veth.c +++ b/src/network/networkd-netdev-veth.c @@ -26,14 +26,17 @@ #include "networkd-netdev-veth.h" static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { - Veth *v = VETH(netdev); + Veth *v; int r; assert(netdev); assert(!link); - assert(v); assert(m); + v = VETH(netdev); + + assert(v); + r = sd_netlink_message_open_container(m, VETH_INFO_PEER); if (r < 0) return log_netdev_error_errno(netdev, r, "Could not append VETH_INFO_PEER attribute: %m"); @@ -58,13 +61,16 @@ static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlin } static int netdev_veth_verify(NetDev *netdev, const char *filename) { - Veth *v = VETH(netdev); + Veth *v; int r; assert(netdev); - assert(v); assert(filename); + v = VETH(netdev); + + assert(v); + if (!v->ifname_peer) { log_warning("Veth NetDev without peer name configured in %s. Ignoring", filename); @@ -84,9 +90,12 @@ static int netdev_veth_verify(NetDev *netdev, const char *filename) { } static void veth_done(NetDev *n) { - Veth *v = VETH(n); + Veth *v; assert(n); + + v = VETH(n); + assert(v); free(v->ifname_peer); diff --git a/src/network/networkd-netdev-vlan.c b/src/network/networkd-netdev-vlan.c index 195d1a944e..75fbdd355e 100644 --- a/src/network/networkd-netdev-vlan.c +++ b/src/network/networkd-netdev-vlan.c @@ -24,14 +24,17 @@ #include "networkd-netdev-vlan.h" static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) { - VLan *v = VLAN(netdev); + VLan *v; int r; assert(netdev); - assert(v); assert(link); assert(req); + v = VLAN(netdev); + + assert(v); + if (v->id <= VLANID_MAX) { r = sd_netlink_message_append_u16(req, IFLA_VLAN_ID, v->id); if (r < 0) @@ -42,12 +45,15 @@ static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlin } static int netdev_vlan_verify(NetDev *netdev, const char *filename) { - VLan *v = VLAN(netdev); + VLan *v; assert(netdev); - assert(v); assert(filename); + v = VLAN(netdev); + + assert(v); + if (v->id > VLANID_MAX) { log_warning("VLAN without valid Id (%"PRIu64") configured in %s. Ignoring", v->id, filename); return -EINVAL; diff --git a/src/network/networkd-netdev-vxlan.c b/src/network/networkd-netdev-vxlan.c index 03a599c0d4..baf6dd6623 100644 --- a/src/network/networkd-netdev-vxlan.c +++ b/src/network/networkd-netdev-vxlan.c @@ -28,14 +28,16 @@ #include "missing.h" static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { - VxLan *v = VXLAN(netdev); + VxLan *v; int r; assert(netdev); - assert(v); assert(link); assert(m); + v = VXLAN(netdev); + + assert(v); if (v->id <= VXLAN_VID_MAX) { r = sd_netlink_message_append_u32(m, IFLA_VXLAN_ID, v->id); @@ -162,9 +164,12 @@ static int netdev_vxlan_verify(NetDev *netdev, const char *filename) { } static void vxlan_init(NetDev *netdev) { - VxLan *v = VXLAN(netdev); + VxLan *v; assert(netdev); + + v = VXLAN(netdev); + assert(v); v->id = VXLAN_VID_MAX + 1; |