From: Christian Brauner Date: Mon, 11 May 2020 20:16:59 +0000 (+0200) Subject: confile: fix order independence of network keys X-Git-Tag: lxc-5.0.0~438^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3408%2Fhead;p=thirdparty%2Flxc.git 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: Christian Brauner --- diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 3d7d9be50..13ebdd059 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -306,14 +306,18 @@ static int set_config_net_type(const char *key, const char *value, netdev->type = LXC_NET_VETH; lxc_list_init(&netdev->priv.veth_attr.ipv4_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) { 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) { netdev->type = LXC_NET_IPVLAN; - lxc_ipvlan_mode_to_flag(&netdev->priv.ipvlan_attr.mode, "l3"); - lxc_ipvlan_isolation_to_flag(&netdev->priv.ipvlan_attr.isolation, "bridge"); + if (!lxc_ipvlan_flag_to_mode(netdev->priv.ipvlan_attr.mode)) + 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) { netdev->type = LXC_NET_VLAN; } else if (strcmp(value, "phys") == 0) { diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index ff4ae7688..05dadf9ec 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -506,6 +506,18 @@ int lxc_veth_mode_to_flag(int *mode, const char *value) 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 { char *name; int mode; diff --git a/src/lxc/confile_utils.h b/src/lxc/confile_utils.h index 1568ccec5..7c59deae5 100644 --- a/src/lxc/confile_utils.h +++ b/src/lxc/confile_utils.h @@ -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 void lxc_free_networks(struct lxc_list *networks); 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 char *lxc_macvlan_flag_to_mode(int mode); extern int lxc_ipvlan_mode_to_flag(int *mode, const char *value);