Merge pull request #1668 from ssahani/net1

networkd: fix asserts
This commit is contained in:
Tom Gundersen 2015-10-25 14:35:40 +01:00
commit 1e23792147
5 changed files with 54 additions and 19 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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;