confile: improve network vetting

Move all input sanity checks up and add two missing checks for the correct network type when using veth-vlan and vlan network types. Link: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32513Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 0977c023
...@@ -302,12 +302,12 @@ static int set_config_net_type(const char *key, const char *value, ...@@ -302,12 +302,12 @@ static int set_config_net_type(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_type(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_type(key, lxc_conf, data);
if (strequal(value, "veth")) { if (strequal(value, "veth")) {
netdev->type = LXC_NET_VETH; netdev->type = LXC_NET_VETH;
lxc_list_init(&netdev->priv.veth_attr.ipv4_routes); lxc_list_init(&netdev->priv.veth_attr.ipv4_routes);
...@@ -345,12 +345,12 @@ static int set_config_net_flags(const char *key, const char *value, ...@@ -345,12 +345,12 @@ static int set_config_net_flags(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_flags(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_flags(key, lxc_conf, data);
netdev->flags |= IFF_UP; netdev->flags |= IFF_UP;
return 0; return 0;
...@@ -403,12 +403,12 @@ static int set_config_net_link(const char *key, const char *value, ...@@ -403,12 +403,12 @@ static int set_config_net_link(const char *key, const char *value,
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
int ret = 0; int ret = 0;
if (lxc_config_value_empty(value))
return clr_config_net_link(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_link(key, lxc_conf, data);
if (value[strlen(value) - 1] == '+' && netdev->type == LXC_NET_PHYS) if (value[strlen(value) - 1] == '+' && netdev->type == LXC_NET_PHYS)
ret = create_matched_ifnames(value, lxc_conf, netdev); ret = create_matched_ifnames(value, lxc_conf, netdev);
else else
...@@ -424,12 +424,12 @@ static int set_config_net_l2proxy(const char *key, const char *value, ...@@ -424,12 +424,12 @@ static int set_config_net_l2proxy(const char *key, const char *value,
unsigned int val = 0; unsigned int val = 0;
int ret; int ret;
if (lxc_config_value_empty(value))
return clr_config_net_l2proxy(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_l2proxy(key, lxc_conf, data);
ret = lxc_safe_uint(value, &val); ret = lxc_safe_uint(value, &val);
if (ret < 0) if (ret < 0)
return ret_errno(ret); return ret_errno(ret);
...@@ -451,12 +451,12 @@ static int set_config_net_name(const char *key, const char *value, ...@@ -451,12 +451,12 @@ static int set_config_net_name(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_name(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_name(key, lxc_conf, data);
return network_ifname(netdev->name, value, sizeof(netdev->name)); return network_ifname(netdev->name, value, sizeof(netdev->name));
} }
...@@ -466,6 +466,12 @@ static int set_config_net_veth_mode(const char *key, const char *value, ...@@ -466,6 +466,12 @@ static int set_config_net_veth_mode(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_net_veth_mode(key, lxc_conf, data); return clr_config_net_veth_mode(key, lxc_conf, data);
...@@ -480,12 +486,15 @@ static int set_config_net_veth_pair(const char *key, const char *value, ...@@ -480,12 +486,15 @@ static int set_config_net_veth_pair(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_veth_pair(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_veth_pair(key, lxc_conf, data);
return network_ifname(netdev->priv.veth_attr.pair, value, return network_ifname(netdev->priv.veth_attr.pair, value,
sizeof(netdev->priv.veth_attr.pair)); sizeof(netdev->priv.veth_attr.pair));
} }
...@@ -495,49 +504,48 @@ static int set_config_net_macvlan_mode(const char *key, const char *value, ...@@ -495,49 +504,48 @@ static int set_config_net_macvlan_mode(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_macvlan_mode(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_MACVLAN)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_macvlan_mode(key, lxc_conf, data);
return lxc_macvlan_mode_to_flag(&netdev->priv.macvlan_attr.mode, value); return lxc_macvlan_mode_to_flag(&netdev->priv.macvlan_attr.mode, value);
} }
static int set_config_net_ipvlan_mode(const char *key, const char *value, static int set_config_net_ipvlan_mode(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_ipvlan_mode(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_IPVLAN) if (netdev->type != LXC_NET_IPVLAN)
return log_error_errno(-EINVAL, return syserror_set(-EINVAL, "Invalid ipvlan mode \"%s\", can only be used with ipvlan network", value);
EINVAL, "Invalid ipvlan mode \"%s\", can only be used with ipvlan network",
value); if (lxc_config_value_empty(value))
return clr_config_net_ipvlan_mode(key, lxc_conf, data);
return lxc_ipvlan_mode_to_flag(&netdev->priv.ipvlan_attr.mode, value); return lxc_ipvlan_mode_to_flag(&netdev->priv.ipvlan_attr.mode, value);
} }
static int set_config_net_ipvlan_isolation(const char *key, const char *value, static int set_config_net_ipvlan_isolation(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_ipvlan_isolation(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_IPVLAN) if (netdev->type != LXC_NET_IPVLAN)
return log_error_errno(-EINVAL, return syserror_set(-EINVAL, "Invalid ipvlan isolation \"%s\", can only be used with ipvlan network", value);
EINVAL, "Invalid ipvlan isolation \"%s\", can only be used with ipvlan network",
value); if (lxc_config_value_empty(value))
return clr_config_net_ipvlan_isolation(key, lxc_conf, data);
return lxc_ipvlan_isolation_to_flag(&netdev->priv.ipvlan_attr.isolation, value); return lxc_ipvlan_isolation_to_flag(&netdev->priv.ipvlan_attr.isolation, value);
} }
...@@ -548,12 +556,12 @@ static int set_config_net_hwaddr(const char *key, const char *value, ...@@ -548,12 +556,12 @@ static int set_config_net_hwaddr(const char *key, const char *value,
__do_free char *new_value = NULL; __do_free char *new_value = NULL;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_hwaddr(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_hwaddr(key, lxc_conf, data);
new_value = strdup(value); new_value = strdup(value);
if (!new_value) if (!new_value)
return ret_errno(ENOMEM); return ret_errno(ENOMEM);
...@@ -574,12 +582,15 @@ static int set_config_net_vlan_id(const char *key, const char *value, ...@@ -574,12 +582,15 @@ static int set_config_net_vlan_id(const char *key, const char *value,
int ret; int ret;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_vlan_id(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VLAN)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_vlan_id(key, lxc_conf, data);
ret = get_u16(&netdev->priv.vlan_attr.vid, value, 0); ret = get_u16(&netdev->priv.vlan_attr.vid, value, 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -592,12 +603,12 @@ static int set_config_net_mtu(const char *key, const char *value, ...@@ -592,12 +603,12 @@ static int set_config_net_mtu(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_mtu(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_mtu(key, lxc_conf, data);
return set_config_string_item(&netdev->mtu, value); return set_config_string_item(&netdev->mtu, value);
} }
...@@ -612,12 +623,12 @@ static int set_config_net_ipv4_address(const char *key, const char *value, ...@@ -612,12 +623,12 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
char *cursor, *slash; char *cursor, *slash;
char *bcast = NULL, *prefix = NULL; char *bcast = NULL, *prefix = NULL;
if (lxc_config_value_empty(value))
return clr_config_net_ipv4_address(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_ipv4_address(key, lxc_conf, data);
inetdev = zalloc(sizeof(*inetdev)); inetdev = zalloc(sizeof(*inetdev));
if (!inetdev) if (!inetdev)
return ret_errno(ENOMEM); return ret_errno(ENOMEM);
...@@ -683,12 +694,12 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value, ...@@ -683,12 +694,12 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_net_ipv4_gateway(key, lxc_conf, data); return clr_config_net_ipv4_gateway(key, lxc_conf, data);
if (!netdev)
return -1;
free(netdev->ipv4_gateway); free(netdev->ipv4_gateway);
if (strequal(value, "auto")) { if (strequal(value, "auto")) {
...@@ -718,7 +729,7 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value, ...@@ -718,7 +729,7 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
} }
static int set_config_net_veth_ipv4_route(const char *key, const char *value, static int set_config_net_veth_ipv4_route(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
__do_free char *valdup = NULL; __do_free char *valdup = NULL;
__do_free struct lxc_inetdev *inetdev = NULL; __do_free struct lxc_inetdev *inetdev = NULL;
...@@ -727,16 +738,14 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value, ...@@ -727,16 +738,14 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value,
char *netmask, *slash; char *netmask, *slash;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_veth_ipv4_route(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return log_error_errno(-EINVAL, return syserror_set(-EINVAL, "Invalid ipv4 route \"%s\", can only be used with veth network", value);
EINVAL, "Invalid ipv4 route \"%s\", can only be used with veth network",
value); if (lxc_config_value_empty(value))
return clr_config_net_veth_ipv4_route(key, lxc_conf, data);
inetdev = zalloc(sizeof(*inetdev)); inetdev = zalloc(sizeof(*inetdev));
if (!inetdev) if (!inetdev)
...@@ -788,12 +797,12 @@ static int set_config_net_ipv6_address(const char *key, const char *value, ...@@ -788,12 +797,12 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
char *slash, *netmask; char *slash, *netmask;
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_address(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_address(key, lxc_conf, data);
inet6dev = zalloc(sizeof(*inet6dev)); inet6dev = zalloc(sizeof(*inet6dev));
if (!inet6dev) if (!inet6dev)
return ret_errno(ENOMEM); return ret_errno(ENOMEM);
...@@ -834,12 +843,12 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value, ...@@ -834,12 +843,12 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_gateway(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_gateway(key, lxc_conf, data);
free(netdev->ipv6_gateway); free(netdev->ipv6_gateway);
if (strequal(value, "auto")) { if (strequal(value, "auto")) {
...@@ -870,7 +879,7 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value, ...@@ -870,7 +879,7 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
} }
static int set_config_net_veth_ipv6_route(const char *key, const char *value, static int set_config_net_veth_ipv6_route(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
__do_free char *valdup = NULL; __do_free char *valdup = NULL;
__do_free struct lxc_inet6dev *inet6dev = NULL; __do_free struct lxc_inet6dev *inet6dev = NULL;
...@@ -879,16 +888,14 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value, ...@@ -879,16 +888,14 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,
char *netmask, *slash; char *netmask, *slash;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_veth_ipv6_route(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return log_error_errno(-EINVAL, return syserror_set(-EINVAL, "Invalid ipv6 route \"%s\", can only be used with veth network", value);
EINVAL, "Invalid ipv6 route \"%s\", can only be used with veth network",
value); if (lxc_config_value_empty(value))
return clr_config_net_veth_ipv6_route(key, lxc_conf, data);
inet6dev = zalloc(sizeof(*inet6dev)); inet6dev = zalloc(sizeof(*inet6dev));
if (!inet6dev) if (!inet6dev)
...@@ -934,12 +941,12 @@ static int set_config_net_script_up(const char *key, const char *value, ...@@ -934,12 +941,12 @@ static int set_config_net_script_up(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_script_up(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_script_up(key, lxc_conf, data);
return set_config_string_item(&netdev->upscript, value); return set_config_string_item(&netdev->upscript, value);
} }
...@@ -948,12 +955,12 @@ static int set_config_net_script_down(const char *key, const char *value, ...@@ -948,12 +955,12 @@ static int set_config_net_script_down(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_script_down(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_script_down(key, lxc_conf, data);
return set_config_string_item(&netdev->downscript, value); return set_config_string_item(&netdev->downscript, value);
} }
...@@ -4939,7 +4946,7 @@ static int clr_config_net_ipvlan_mode(const char *key, ...@@ -4939,7 +4946,7 @@ static int clr_config_net_ipvlan_mode(const char *key,
} }
static int clr_config_net_ipvlan_isolation(const char *key, static int clr_config_net_ipvlan_isolation(const char *key,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
...@@ -4978,6 +4985,9 @@ static int clr_config_net_veth_pair(const char *key, struct lxc_conf *lxc_conf, ...@@ -4978,6 +4985,9 @@ static int clr_config_net_veth_pair(const char *key, struct lxc_conf *lxc_conf,
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
netdev->priv.veth_attr.pair[0] = '\0'; netdev->priv.veth_attr.pair[0] = '\0';
return 0; return 0;
...@@ -5043,6 +5053,9 @@ static int clr_config_net_vlan_id(const char *key, struct lxc_conf *lxc_conf, ...@@ -5043,6 +5053,9 @@ static int clr_config_net_vlan_id(const char *key, struct lxc_conf *lxc_conf,
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VLAN)
return 0;
netdev->priv.vlan_attr.vid = 0; netdev->priv.vlan_attr.vid = 0;
return 0; return 0;
...@@ -5088,6 +5101,9 @@ static int clr_config_net_veth_ipv4_route(const char *key, ...@@ -5088,6 +5101,9 @@ static int clr_config_net_veth_ipv4_route(const char *key,
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv4_routes, next) { lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv4_routes, next) {
lxc_list_del(cur); lxc_list_del(cur);
free(cur->elem); free(cur->elem);
...@@ -5137,6 +5153,9 @@ static int clr_config_net_veth_ipv6_route(const char *key, ...@@ -5137,6 +5153,9 @@ static int clr_config_net_veth_ipv6_route(const char *key,
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv6_routes, next) { lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv6_routes, next) {
lxc_list_del(cur); lxc_list_del(cur);
free(cur->elem); free(cur->elem);
...@@ -5177,14 +5196,14 @@ static int get_config_net_type(const char *key, char *retv, int inlen, ...@@ -5177,14 +5196,14 @@ static int get_config_net_type(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
strprint(retv, inlen, "%s", lxc_net_type_to_str(netdev->type)); strprint(retv, inlen, "%s", lxc_net_type_to_str(netdev->type));
return fulllen; return fulllen;
...@@ -5197,14 +5216,14 @@ static int get_config_net_flags(const char *key, char *retv, int inlen, ...@@ -5197,14 +5216,14 @@ static int get_config_net_flags(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->flags & IFF_UP) if (netdev->flags & IFF_UP)
strprint(retv, inlen, "up"); strprint(retv, inlen, "up");
...@@ -5218,14 +5237,14 @@ static int get_config_net_link(const char *key, char *retv, int inlen, ...@@ -5218,14 +5237,14 @@ static int get_config_net_link(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->link[0] != '\0') if (netdev->link[0] != '\0')
strprint(retv, inlen, "%s", netdev->link); strprint(retv, inlen, "%s", netdev->link);
...@@ -5236,6 +5255,10 @@ static int get_config_net_l2proxy(const char *key, char *retv, int inlen, ...@@ -5236,6 +5255,10 @@ static int get_config_net_l2proxy(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data) struct lxc_conf *c, void *data)
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
return lxc_get_conf_bool(c, retv, inlen, netdev->l2proxy); return lxc_get_conf_bool(c, retv, inlen, netdev->l2proxy);
} }
...@@ -5246,14 +5269,14 @@ static int get_config_net_name(const char *key, char *retv, int inlen, ...@@ -5246,14 +5269,14 @@ static int get_config_net_name(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->name[0] != '\0') if (netdev->name[0] != '\0')
strprint(retv, inlen, "%s", netdev->name); strprint(retv, inlen, "%s", netdev->name);
...@@ -5268,16 +5291,16 @@ static int get_config_net_macvlan_mode(const char *key, char *retv, int inlen, ...@@ -5268,16 +5291,16 @@ static int get_config_net_macvlan_mode(const char *key, char *retv, int inlen,
const char *mode; const char *mode;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_MACVLAN) if (netdev->type != LXC_NET_MACVLAN)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
switch (netdev->priv.macvlan_attr.mode) { switch (netdev->priv.macvlan_attr.mode) {
case MACVLAN_MODE_PRIVATE: case MACVLAN_MODE_PRIVATE:
...@@ -5310,16 +5333,16 @@ static int get_config_net_ipvlan_mode(const char *key, char *retv, int inlen, ...@@ -5310,16 +5333,16 @@ static int get_config_net_ipvlan_mode(const char *key, char *retv, int inlen,
int len; int len;
const char *mode; const char *mode;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_IPVLAN) if (netdev->type != LXC_NET_IPVLAN)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
switch (netdev->priv.ipvlan_attr.mode) { switch (netdev->priv.ipvlan_attr.mode) {
case IPVLAN_MODE_L3: case IPVLAN_MODE_L3:
...@@ -5349,16 +5372,16 @@ static int get_config_net_ipvlan_isolation(const char *key, char *retv, int inle ...@@ -5349,16 +5372,16 @@ static int get_config_net_ipvlan_isolation(const char *key, char *retv, int inle
int len; int len;
const char *mode; const char *mode;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_IPVLAN) if (netdev->type != LXC_NET_IPVLAN)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
switch (netdev->priv.ipvlan_attr.isolation) { switch (netdev->priv.ipvlan_attr.isolation) {
case IPVLAN_ISOLATION_BRIDGE: case IPVLAN_ISOLATION_BRIDGE:
...@@ -5381,23 +5404,23 @@ static int get_config_net_ipvlan_isolation(const char *key, char *retv, int inle ...@@ -5381,23 +5404,23 @@ static int get_config_net_ipvlan_isolation(const char *key, char *retv, int inle
} }
static int get_config_net_veth_mode(const char *key, char *retv, int inlen, static int get_config_net_veth_mode(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data) struct lxc_conf *c, void *data)
{ {
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
int len; int len;
const char *mode; const char *mode;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
switch (netdev->priv.veth_attr.mode) { switch (netdev->priv.veth_attr.mode) {
case VETH_MODE_BRIDGE: case VETH_MODE_BRIDGE:
...@@ -5423,16 +5446,16 @@ static int get_config_net_veth_pair(const char *key, char *retv, int inlen, ...@@ -5423,16 +5446,16 @@ static int get_config_net_veth_pair(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
strprint(retv, inlen, "%s", strprint(retv, inlen, "%s",
netdev->priv.veth_attr.pair[0] != '\0' netdev->priv.veth_attr.pair[0] != '\0'
...@@ -5449,14 +5472,14 @@ static int get_config_net_script_up(const char *key, char *retv, int inlen, ...@@ -5449,14 +5472,14 @@ static int get_config_net_script_up(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->upscript) if (netdev->upscript)
strprint(retv, inlen, "%s", netdev->upscript); strprint(retv, inlen, "%s", netdev->upscript);
...@@ -5470,14 +5493,14 @@ static int get_config_net_script_down(const char *key, char *retv, int inlen, ...@@ -5470,14 +5493,14 @@ static int get_config_net_script_down(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->downscript) if (netdev->downscript)
strprint(retv, inlen, "%s", netdev->downscript); strprint(retv, inlen, "%s", netdev->downscript);
...@@ -5491,14 +5514,14 @@ static int get_config_net_hwaddr(const char *key, char *retv, int inlen, ...@@ -5491,14 +5514,14 @@ static int get_config_net_hwaddr(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->hwaddr) if (netdev->hwaddr)
strprint(retv, inlen, "%s", netdev->hwaddr); strprint(retv, inlen, "%s", netdev->hwaddr);
...@@ -5512,14 +5535,14 @@ static int get_config_net_mtu(const char *key, char *retv, int inlen, ...@@ -5512,14 +5535,14 @@ static int get_config_net_mtu(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->mtu) if (netdev->mtu)
strprint(retv, inlen, "%s", netdev->mtu); strprint(retv, inlen, "%s", netdev->mtu);
...@@ -5533,16 +5556,16 @@ static int get_config_net_vlan_id(const char *key, char *retv, int inlen, ...@@ -5533,16 +5556,16 @@ static int get_config_net_vlan_id(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VLAN) if (netdev->type != LXC_NET_VLAN)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
strprint(retv, inlen, "%d", netdev->priv.vlan_attr.vid); strprint(retv, inlen, "%d", netdev->priv.vlan_attr.vid);
...@@ -5557,14 +5580,14 @@ static int get_config_net_ipv4_gateway(const char *key, char *retv, int inlen, ...@@ -5557,14 +5580,14 @@ static int get_config_net_ipv4_gateway(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->ipv4_gateway_auto) { if (netdev->ipv4_gateway_auto) {
strprint(retv, inlen, "auto"); strprint(retv, inlen, "auto");
} else if (netdev->ipv4_gateway_dev) { } else if (netdev->ipv4_gateway_dev) {
...@@ -5588,14 +5611,14 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen, ...@@ -5588,14 +5611,14 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
listlen = lxc_list_len(&netdev->ipv4); listlen = lxc_list_len(&netdev->ipv4);
lxc_list_for_each(it, &netdev->ipv4) { lxc_list_for_each(it, &netdev->ipv4) {
...@@ -5610,7 +5633,7 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen, ...@@ -5610,7 +5633,7 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen,
} }
static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen, static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data) struct lxc_conf *c, void *data)
{ {
int len; int len;
size_t listlen; size_t listlen;
...@@ -5619,16 +5642,16 @@ static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen ...@@ -5619,16 +5642,16 @@ static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
listlen = lxc_list_len(&netdev->priv.veth_attr.ipv4_routes); listlen = lxc_list_len(&netdev->priv.veth_attr.ipv4_routes);
...@@ -5651,14 +5674,14 @@ static int get_config_net_ipv6_gateway(const char *key, char *retv, int inlen, ...@@ -5651,14 +5674,14 @@ static int get_config_net_ipv6_gateway(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->ipv6_gateway_auto) { if (netdev->ipv6_gateway_auto) {
strprint(retv, inlen, "auto"); strprint(retv, inlen, "auto");
} else if (netdev->ipv6_gateway_dev) { } else if (netdev->ipv6_gateway_dev) {
...@@ -5682,14 +5705,14 @@ static int get_config_net_ipv6_address(const char *key, char *retv, int inlen, ...@@ -5682,14 +5705,14 @@ static int get_config_net_ipv6_address(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
listlen = lxc_list_len(&netdev->ipv6); listlen = lxc_list_len(&netdev->ipv6);
lxc_list_for_each(it, &netdev->ipv6) { lxc_list_for_each(it, &netdev->ipv6) {
...@@ -5713,16 +5736,16 @@ static int get_config_net_veth_ipv6_route(const char *key, char *retv, int inlen ...@@ -5713,16 +5736,16 @@ static int get_config_net_veth_ipv6_route(const char *key, char *retv, int inlen
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
listlen = lxc_list_len(&netdev->priv.veth_attr.ipv6_routes); listlen = lxc_list_len(&netdev->priv.veth_attr.ipv6_routes);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment