]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: fix order independence of network keys 3408/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 11 May 2020 20:16:59 +0000 (22:16 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 11 May 2020 20:16:59 +0000 (22:16 +0200)
We need to make sure we don't overwrite values when they have already been set.

Closes: #3405.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c
src/lxc/confile_utils.c
src/lxc/confile_utils.h

index 3d7d9be50aadf8192231263e6d978efdd94648d3..13ebdd059a9367371235bbdcd14f056f6c6fe624 100644 (file)
@@ -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) {
index ff4ae768848c069285badd6dd29705c717879575..05dadf9ec62c2bc896726765e37fa563d72ae58c 100644 (file)
@@ -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;
index 1568ccec5d38fd208709c931cdac83fba3a64bdd..7c59deae5a08b62327f19e765a25afc2030373c3 100644 (file)
@@ -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);