Unverified Commit cf52a093 by Christian Brauner Committed by Stéphane Graber

confile: fix order independence of network keys

We need to make sure we don't overwrite values when they have already been set. Closes: #3405. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 7821133a
...@@ -300,14 +300,18 @@ static int set_config_net_type(const char *key, const char *value, ...@@ -300,14 +300,18 @@ static int set_config_net_type(const char *key, const char *value,
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);
lxc_list_init(&netdev->priv.veth_attr.ipv6_routes); lxc_list_init(&netdev->priv.veth_attr.ipv6_routes);
lxc_veth_mode_to_flag(&netdev->priv.veth_attr.mode, "bridge"); if (!lxc_veth_flag_to_mode(netdev->priv.veth_attr.mode))
lxc_veth_mode_to_flag(&netdev->priv.veth_attr.mode, "bridge");
} else if (strcmp(value, "macvlan") == 0) { } else if (strcmp(value, "macvlan") == 0) {
netdev->type = LXC_NET_MACVLAN; netdev->type = LXC_NET_MACVLAN;
lxc_macvlan_mode_to_flag(&netdev->priv.macvlan_attr.mode, "private"); if (!lxc_macvlan_flag_to_mode(netdev->priv.veth_attr.mode))
lxc_macvlan_mode_to_flag(&netdev->priv.macvlan_attr.mode, "private");
} else if (strcmp(value, "ipvlan") == 0) { } else if (strcmp(value, "ipvlan") == 0) {
netdev->type = LXC_NET_IPVLAN; netdev->type = LXC_NET_IPVLAN;
lxc_ipvlan_mode_to_flag(&netdev->priv.ipvlan_attr.mode, "l3"); if (!lxc_ipvlan_flag_to_mode(netdev->priv.ipvlan_attr.mode))
lxc_ipvlan_isolation_to_flag(&netdev->priv.ipvlan_attr.isolation, "bridge"); lxc_ipvlan_mode_to_flag(&netdev->priv.ipvlan_attr.mode, "l3");
if (!lxc_ipvlan_flag_to_isolation(netdev->priv.ipvlan_attr.isolation))
lxc_ipvlan_isolation_to_flag(&netdev->priv.ipvlan_attr.isolation, "bridge");
} else if (strcmp(value, "vlan") == 0) { } else if (strcmp(value, "vlan") == 0) {
netdev->type = LXC_NET_VLAN; netdev->type = LXC_NET_VLAN;
} else if (strcmp(value, "phys") == 0) { } else if (strcmp(value, "phys") == 0) {
......
...@@ -506,6 +506,18 @@ int lxc_veth_mode_to_flag(int *mode, const char *value) ...@@ -506,6 +506,18 @@ int lxc_veth_mode_to_flag(int *mode, const char *value)
return ret_set_errno(-1, EINVAL); return ret_set_errno(-1, EINVAL);
} }
char *lxc_veth_flag_to_mode(int mode)
{
for (size_t i = 0; i < sizeof(veth_mode) / sizeof(veth_mode[0]); i++) {
if (veth_mode[i].mode != mode)
continue;
return veth_mode[i].name;
}
return NULL;
}
static struct lxc_macvlan_mode { static struct lxc_macvlan_mode {
char *name; char *name;
int mode; int mode;
......
...@@ -41,6 +41,7 @@ extern void lxc_log_configured_netdevs(const struct lxc_conf *conf); ...@@ -41,6 +41,7 @@ extern void lxc_log_configured_netdevs(const struct lxc_conf *conf);
extern bool lxc_remove_nic_by_idx(struct lxc_conf *conf, unsigned int idx); extern bool lxc_remove_nic_by_idx(struct lxc_conf *conf, unsigned int idx);
extern void lxc_free_networks(struct lxc_list *networks); extern void lxc_free_networks(struct lxc_list *networks);
extern int lxc_veth_mode_to_flag(int *mode, const char *value); extern int lxc_veth_mode_to_flag(int *mode, const char *value);
extern char *lxc_veth_flag_to_mode(int mode);
extern int lxc_macvlan_mode_to_flag(int *mode, const char *value); extern int lxc_macvlan_mode_to_flag(int *mode, const char *value);
extern char *lxc_macvlan_flag_to_mode(int mode); extern char *lxc_macvlan_flag_to_mode(int mode);
extern int lxc_ipvlan_mode_to_flag(int *mode, const char *value); extern int lxc_ipvlan_mode_to_flag(int *mode, const char *value);
......
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