{
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);
{
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;
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
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);
{
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));
}
{
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);
{
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;
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);
}
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;
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);
{
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);
}
__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);
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;
{
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);
}
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);
{
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")) {
}
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;
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)
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);
{
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")) {
}
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;
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)
{
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);
}
{
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);
}
}
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;
if (!netdev)
return ret_errno(EINVAL);
+ if (netdev->type != LXC_NET_VETH)
+ return 0;
+
netdev->priv.veth_attr.pair[0] = '\0';
return 0;
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;
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);
if (!netdev)
return ret_errno(EINVAL);
+ if (netdev->type != LXC_NET_VLAN)
+ return 0;
+
netdev->priv.vlan_attr.vid = 0;
return 0;
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);
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);
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;
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");
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);
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);
}
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);
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:
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:
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:
}
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:
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'
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
- return 0;
+ return ret_errno(EINVAL);
if (!retv)
inlen = 0;
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;
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
- return 0;
+ return ret_errno(EINVAL);
if (!retv)
inlen = 0;
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;
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);
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);
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);
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);
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);
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) {
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) {
}
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;
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);
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) {
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) {
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);