2
0
mirror of git://github.com/lxc/lxc synced 2025-08-30 23:19:34 +00:00

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=32513
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner
2021-03-27 11:37:26 +01:00
parent bbc9892535
commit 299ddd1663

View File

@@ -321,12 +321,12 @@ static int set_config_net_type(const char *key, const char *value,
{
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_type(key, lxc_conf, data);
if (!netdev)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_type(key, lxc_conf, data);
if (strequal(value, "veth")) {
netdev->type = LXC_NET_VETH;
lxc_list_init(&netdev->priv.veth_attr.ipv4_routes);
@@ -364,12 +364,12 @@ static int set_config_net_flags(const char *key, const char *value,
{
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_flags(key, lxc_conf, data);
if (!netdev)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_flags(key, lxc_conf, data);
netdev->flags |= IFF_UP;
return 0;
@@ -422,12 +422,12 @@ static int set_config_net_link(const char *key, const char *value,
struct lxc_netdev *netdev = data;
int ret = 0;
if (lxc_config_value_empty(value))
return clr_config_net_link(key, lxc_conf, data);
if (!netdev)
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)
ret = create_matched_ifnames(value, lxc_conf, netdev);
else
@@ -443,12 +443,12 @@ static int set_config_net_l2proxy(const char *key, const char *value,
unsigned int val = 0;
int ret;
if (lxc_config_value_empty(value))
return clr_config_net_l2proxy(key, lxc_conf, data);
if (!netdev)
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);
if (ret < 0)
return ret_errno(ret);
@@ -470,12 +470,12 @@ static int set_config_net_name(const char *key, const char *value,
{
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_name(key, lxc_conf, data);
if (!netdev)
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));
}
@@ -485,6 +485,12 @@ static int set_config_net_veth_mode(const char *key, const char *value,
{
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))
return clr_config_net_veth_mode(key, lxc_conf, data);
@@ -499,18 +505,21 @@ static int set_config_net_veth_pair(const char *key, const char *value,
{
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_veth_pair(key, lxc_conf, data);
if (!netdev)
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,
sizeof(netdev->priv.veth_attr.pair));
}
static int set_config_net_veth_vlan_id(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
struct lxc_conf *lxc_conf, void *data)
{
int ret;
struct lxc_netdev *netdev = data;
@@ -518,6 +527,9 @@ static int set_config_net_veth_vlan_id(const char *key, const char *value,
if (!netdev)
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_vlan_id(key, lxc_conf, data);
@@ -541,7 +553,8 @@ static int set_config_net_veth_vlan_id(const char *key, const char *value,
}
static int set_config_net_veth_vlan_tagged_id(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
struct lxc_conf *lxc_conf,
void *data)
{
__do_free struct lxc_list *list = NULL;
int ret;
@@ -551,6 +564,9 @@ static int set_config_net_veth_vlan_tagged_id(const char *key, const char *value
if (!netdev)
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_vlan_tagged_id(key, lxc_conf, data);
@@ -577,49 +593,48 @@ static int set_config_net_macvlan_mode(const char *key, const char *value,
{
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_macvlan_mode(key, lxc_conf, data);
if (!netdev)
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);
}
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;
if (lxc_config_value_empty(value))
return clr_config_net_ipvlan_mode(key, lxc_conf, data);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_IPVLAN)
return log_error_errno(-EINVAL,
EINVAL, "Invalid ipvlan mode \"%s\", can only be used with ipvlan network",
value);
return syserror_set(-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);
}
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;
if (lxc_config_value_empty(value))
return clr_config_net_ipvlan_isolation(key, lxc_conf, data);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_IPVLAN)
return log_error_errno(-EINVAL,
EINVAL, "Invalid ipvlan isolation \"%s\", can only be used with ipvlan network",
value);
return syserror_set(-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);
}
@@ -630,12 +645,12 @@ static int set_config_net_hwaddr(const char *key, const char *value,
__do_free char *new_value = NULL;
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_hwaddr(key, lxc_conf, data);
if (!netdev)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_hwaddr(key, lxc_conf, data);
new_value = strdup(value);
if (!new_value)
return ret_errno(ENOMEM);
@@ -656,12 +671,15 @@ static int set_config_net_vlan_id(const char *key, const char *value,
int ret;
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_vlan_id(key, lxc_conf, data);
if (!netdev)
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);
if (ret < 0)
return ret;
@@ -674,12 +692,12 @@ static int set_config_net_mtu(const char *key, const char *value,
{
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_mtu(key, lxc_conf, data);
if (!netdev)
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);
}
@@ -694,12 +712,12 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
char *cursor, *slash;
char *bcast = NULL, *prefix = NULL;
if (lxc_config_value_empty(value))
return clr_config_net_ipv4_address(key, lxc_conf, data);
if (!netdev)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_ipv4_address(key, lxc_conf, data);
inetdev = zalloc(sizeof(*inetdev));
if (!inetdev)
return ret_errno(ENOMEM);
@@ -765,12 +783,12 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
{
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_ipv4_gateway(key, lxc_conf, data);
if (!netdev)
return -1;
free(netdev->ipv4_gateway);
if (strequal(value, "auto")) {
@@ -800,7 +818,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,
struct lxc_conf *lxc_conf, void *data)
struct lxc_conf *lxc_conf, void *data)
{
__do_free char *valdup = NULL;
__do_free struct lxc_inetdev *inetdev = NULL;
@@ -809,16 +827,14 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value,
char *netmask, *slash;
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_veth_ipv4_route(key, lxc_conf, data);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return log_error_errno(-EINVAL,
EINVAL, "Invalid ipv4 route \"%s\", can only be used with veth network",
value);
return syserror_set(-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));
if (!inetdev)
@@ -870,12 +886,12 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
struct lxc_netdev *netdev = data;
char *slash, *netmask;
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_address(key, lxc_conf, data);
if (!netdev)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_address(key, lxc_conf, data);
inet6dev = zalloc(sizeof(*inet6dev));
if (!inet6dev)
return ret_errno(ENOMEM);
@@ -916,12 +932,12 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
{
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_gateway(key, lxc_conf, data);
if (!netdev)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_gateway(key, lxc_conf, data);
free(netdev->ipv6_gateway);
if (strequal(value, "auto")) {
@@ -952,7 +968,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,
struct lxc_conf *lxc_conf, void *data)
struct lxc_conf *lxc_conf, void *data)
{
__do_free char *valdup = NULL;
__do_free struct lxc_inet6dev *inet6dev = NULL;
@@ -961,16 +977,14 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,
char *netmask, *slash;
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_veth_ipv6_route(key, lxc_conf, data);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return log_error_errno(-EINVAL,
EINVAL, "Invalid ipv6 route \"%s\", can only be used with veth network",
value);
return syserror_set(-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));
if (!inet6dev)
@@ -1016,12 +1030,12 @@ static int set_config_net_script_up(const char *key, const char *value,
{
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_script_up(key, lxc_conf, data);
if (!netdev)
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);
}
@@ -1030,12 +1044,12 @@ static int set_config_net_script_down(const char *key, const char *value,
{
struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_script_down(key, lxc_conf, data);
if (!netdev)
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);
}
@@ -5402,7 +5416,7 @@ static int clr_config_net_ipvlan_mode(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;
@@ -5441,6 +5455,9 @@ static int clr_config_net_veth_pair(const char *key, struct lxc_conf *lxc_conf,
if (!netdev)
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
netdev->priv.veth_attr.pair[0] = '\0';
return 0;
@@ -5454,6 +5471,9 @@ static int clr_config_net_veth_vlan_id(const char *key, struct lxc_conf *lxc_con
if (!netdev)
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
netdev->priv.veth_attr.vlan_id = 0;
netdev->priv.veth_attr.vlan_id_set = false;
@@ -5469,6 +5489,9 @@ static int clr_config_net_veth_vlan_tagged_id(const char *key,
if (!netdev)
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.vlan_tagged_ids, next) {
lxc_list_del(cur);
free(cur);
@@ -5538,6 +5561,9 @@ static int clr_config_net_vlan_id(const char *key, struct lxc_conf *lxc_conf,
if (!netdev)
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VLAN)
return 0;
netdev->priv.vlan_attr.vid = 0;
return 0;
@@ -5583,6 +5609,9 @@ static int clr_config_net_veth_ipv4_route(const char *key,
if (!netdev)
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_del(cur);
free(cur->elem);
@@ -5632,6 +5661,9 @@ static int clr_config_net_veth_ipv6_route(const char *key,
if (!netdev)
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_del(cur);
free(cur->elem);
@@ -5672,14 +5704,14 @@ static int get_config_net_type(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
strprint(retv, inlen, "%s", lxc_net_type_to_str(netdev->type));
return fulllen;
@@ -5692,14 +5724,14 @@ static int get_config_net_flags(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->flags & IFF_UP)
strprint(retv, inlen, "up");
@@ -5713,14 +5745,14 @@ static int get_config_net_link(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->link[0] != '\0')
strprint(retv, inlen, "%s", netdev->link);
@@ -5731,6 +5763,10 @@ static int get_config_net_l2proxy(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data)
{
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
return lxc_get_conf_bool(c, retv, inlen, netdev->l2proxy);
}
@@ -5741,14 +5777,14 @@ static int get_config_net_name(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->name[0] != '\0')
strprint(retv, inlen, "%s", netdev->name);
@@ -5763,16 +5799,16 @@ static int get_config_net_macvlan_mode(const char *key, char *retv, int inlen,
const char *mode;
struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
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) {
case MACVLAN_MODE_PRIVATE:
@@ -5805,16 +5841,16 @@ static int get_config_net_ipvlan_mode(const char *key, char *retv, int inlen,
int len;
const char *mode;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
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) {
case IPVLAN_MODE_L3:
@@ -5844,16 +5880,16 @@ static int get_config_net_ipvlan_isolation(const char *key, char *retv, int inle
int len;
const char *mode;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
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) {
case IPVLAN_ISOLATION_BRIDGE:
@@ -5876,23 +5912,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,
struct lxc_conf *c, void *data)
struct lxc_conf *c, void *data)
{
int fulllen = 0;
struct lxc_netdev *netdev = data;
int len;
const char *mode;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
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) {
case VETH_MODE_BRIDGE:
@@ -5918,16 +5954,16 @@ static int get_config_net_veth_pair(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
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",
netdev->priv.veth_attr.pair[0] != '\0'
@@ -5948,7 +5984,7 @@ static int get_config_net_veth_vlan_id(const char *key, char *retv, int inlen,
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
@@ -5960,8 +5996,9 @@ static int get_config_net_veth_vlan_id(const char *key, char *retv, int inlen,
return fulllen;
}
static int get_config_net_veth_vlan_tagged_id(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data)
static int get_config_net_veth_vlan_tagged_id(const char *key, char *retv,
int inlen, struct lxc_conf *c,
void *data)
{
int len;
size_t listlen;
@@ -5973,7 +6010,7 @@ static int get_config_net_veth_vlan_tagged_id(const char *key, char *retv, int i
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
@@ -5984,8 +6021,7 @@ static int get_config_net_veth_vlan_tagged_id(const char *key, char *retv, int i
lxc_list_for_each(it, &netdev->priv.veth_attr.vlan_tagged_ids) {
unsigned short i = PTR_TO_USHORT(it->elem);
strprint(retv, inlen, "%u%s", i,
(listlen-- > 1) ? "\n" : "");
strprint(retv, inlen, "%u%s", i, (listlen-- > 1) ? "\n" : "");
}
return fulllen;
@@ -5998,14 +6034,14 @@ static int get_config_net_script_up(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->upscript)
strprint(retv, inlen, "%s", netdev->upscript);
@@ -6019,14 +6055,14 @@ static int get_config_net_script_down(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->downscript)
strprint(retv, inlen, "%s", netdev->downscript);
@@ -6040,14 +6076,14 @@ static int get_config_net_hwaddr(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->hwaddr)
strprint(retv, inlen, "%s", netdev->hwaddr);
@@ -6061,14 +6097,14 @@ static int get_config_net_mtu(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->mtu)
strprint(retv, inlen, "%s", netdev->mtu);
@@ -6082,16 +6118,16 @@ static int get_config_net_vlan_id(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
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);
@@ -6106,14 +6142,14 @@ static int get_config_net_ipv4_gateway(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->ipv4_gateway_auto) {
strprint(retv, inlen, "auto");
} else if (netdev->ipv4_gateway_dev) {
@@ -6137,14 +6173,14 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
listlen = lxc_list_len(&netdev->ipv4);
lxc_list_for_each(it, &netdev->ipv4) {
@@ -6159,7 +6195,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,
struct lxc_conf *c, void *data)
struct lxc_conf *c, void *data)
{
int len;
size_t listlen;
@@ -6168,16 +6204,16 @@ static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
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);
@@ -6200,14 +6236,14 @@ static int get_config_net_ipv6_gateway(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->ipv6_gateway_auto) {
strprint(retv, inlen, "auto");
} else if (netdev->ipv6_gateway_dev) {
@@ -6231,14 +6267,14 @@ static int get_config_net_ipv6_address(const char *key, char *retv, int inlen,
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
listlen = lxc_list_len(&netdev->ipv6);
lxc_list_for_each(it, &netdev->ipv6) {
@@ -6262,16 +6298,16 @@ static int get_config_net_veth_ipv6_route(const char *key, char *retv, int inlen
int fulllen = 0;
struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
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);