[libvirt] [PATCH v3 0/2] lxc: Fix a bug related to IPv{4, 6} gateway persistent setting.

This serie fixes a bug related to IPv{4,6} gateway settings when it is defined and used with multiple network definitions. Basically, this data is being carried on to the next network settings because the pointer is not being cleaned up/initialized properly. The idea behind the fix was create a new way to initialize the data without knowing the structure attributes. The old way has a high probability to cause new bugs. This serie add a new test case to cover this scenario too. It will be so important to network index implemented on LXC 3.X. v1-v2: Fixing tabs inside the code. Julio Faracco (2): lxc: Initializing IPv6 and IPv4 gateway to overwrite old settings. tests: Adding test case to include multiple network definitions. src/lxc/lxc_native.c | 27 ++++++----- .../lxcconf2xml-miscnetwork-v3.config | 23 ++++++++++ .../lxcconf2xml-miscnetwork.config | 23 ++++++++++ .../lxcconf2xml-miscnetwork.xml | 45 +++++++++++++++++++ tests/lxcconf2xmltest.c | 2 + 5 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.config create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.xml -- 2.19.1

This commit fixes a bug when you have multiple network settings defined. Basically, if you set an IPv6 or IPv4 gateway, it carries on next network settings. It is happening because the data is not being initialized when a new network type is defined. So, the old data still persists into the pointer. Another way to initialized the data was introduced using memset() to avoid missing attributes from the struct. Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- src/lxc/lxc_native.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 9f6d4b3de8..0d21d9fb2b 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -561,27 +561,26 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data) int status; if (STREQ(name, "lxc.network.type")) { + virDomainDefPtr def = parseData->def; + size_t networks = parseData->networks; + bool privnet = parseData->privnet; + /* Store the previous NIC */ status = lxcAddNetworkDefinition(parseData); if (status < 0) return -1; else if (status > 0) - parseData->networks++; + networks++; else if (parseData->type != NULL && STREQ(parseData->type, "none")) - parseData->privnet = false; - - /* Start a new network interface config */ - parseData->type = NULL; - parseData->link = NULL; - parseData->mac = NULL; - parseData->flag = NULL; - parseData->macvlanmode = NULL; - parseData->vlanid = NULL; - parseData->name = NULL; - - parseData->ips = NULL; - parseData->nips = 0; + privnet = false; + + /* clean NIC to store a new one */ + memset(parseData, 0, sizeof(*parseData)); + + parseData->def = def; + parseData->networks = networks; + parseData->privnet = privnet; /* Keep the new value */ parseData->type = value->str; -- 2.19.1

This commit includes a test case for multiple network definitions. It is useful right now, but it will be more useful when the index used by LXC version 3.X is implemented to support this new settings. The version 3.X is using indexes to specify each network settings. Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- .../lxcconf2xml-miscnetwork-v3.config | 23 ++++++++++ .../lxcconf2xml-miscnetwork.config | 23 ++++++++++ .../lxcconf2xml-miscnetwork.xml | 45 +++++++++++++++++++ tests/lxcconf2xmltest.c | 2 + 4 files changed, 93 insertions(+) create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.config create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.xml diff --git a/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config new file mode 100644 index 0000000000..b46cb3ee7d --- /dev/null +++ b/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config @@ -0,0 +1,23 @@ +lxc.network.type = phys +lxc.network.link = eth0 +lxc.network.name = eth1 +lxc.network.ipv4 = 192.168.122.2/24 +lxc.network.ipv4.gateway = 192.168.122.1 +lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 + +lxc.network.type = vlan +lxc.network.flags = up +lxc.network.link = eth0 +lxc.network.hwaddr = 02:00:15:8f:05:c1 +lxc.network.vlan.id = 2 + +lxc.network.type = macvlan +lxc.network.flags = up +lxc.network.link = eth0 +lxc.network.hwaddr = 02:00:15:8f:05:c1 +lxc.network.macvlan.mode = vepa + +lxc.rootfs = /var/lib/lxc/migrate_test/rootfs +lxc.utsname = migrate_test +lxc.autodev=1 diff --git a/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.config b/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.config new file mode 100644 index 0000000000..b46cb3ee7d --- /dev/null +++ b/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.config @@ -0,0 +1,23 @@ +lxc.network.type = phys +lxc.network.link = eth0 +lxc.network.name = eth1 +lxc.network.ipv4 = 192.168.122.2/24 +lxc.network.ipv4.gateway = 192.168.122.1 +lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 + +lxc.network.type = vlan +lxc.network.flags = up +lxc.network.link = eth0 +lxc.network.hwaddr = 02:00:15:8f:05:c1 +lxc.network.vlan.id = 2 + +lxc.network.type = macvlan +lxc.network.flags = up +lxc.network.link = eth0 +lxc.network.hwaddr = 02:00:15:8f:05:c1 +lxc.network.macvlan.mode = vepa + +lxc.rootfs = /var/lib/lxc/migrate_test/rootfs +lxc.utsname = migrate_test +lxc.autodev=1 diff --git a/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.xml b/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.xml new file mode 100644 index 0000000000..63189cfaec --- /dev/null +++ b/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.xml @@ -0,0 +1,45 @@ +<domain type='lxc'> + <name>migrate_test</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>65536</memory> + <currentMemory unit='KiB'>65536</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>exe</type> + <init>/sbin/init</init> + </os> + <features> + <capabilities policy='allow'> + </capabilities> + </features> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/libexec/libvirt_lxc</emulator> + <filesystem type='mount' accessmode='passthrough'> + <source dir='/var/lib/lxc/migrate_test/rootfs'/> + <target dir='/'/> + </filesystem> + <interface type='direct'> + <mac address='02:00:15:8f:05:c1'/> + <source dev='eth0' mode='vepa'/> + <link state='up'/> + </interface> + <hostdev mode='capabilities' type='net'> + <source> + <interface>eth0</interface> + </source> + <ip address='192.168.122.2' family='ipv4' prefix='24'/> + <ip address='2003:db8:1:0:214:1234:fe0b:3596' family='ipv6' prefix='64'/> + <route family='ipv4' address='0.0.0.0' gateway='192.168.122.1'/> + <route family='ipv6' address='::' gateway='2003:db8:1:0:214:1234:fe0b:3595'/> + </hostdev> + <hostdev mode='capabilities' type='net'> + <source> + <interface>eth0.2</interface> + </source> + </hostdev> + </devices> +</domain> diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index 0766239ec4..2a277042ce 100644 --- a/tests/lxcconf2xmltest.c +++ b/tests/lxcconf2xmltest.c @@ -137,6 +137,7 @@ mymain(void) DO_TEST("physnetwork", false); DO_TEST("macvlannetwork", false); DO_TEST("vlannetwork", false); + DO_TEST("miscnetwork", false); DO_TEST("idmap", false); DO_TEST("memtune", false); DO_TEST("cputune", false); @@ -161,6 +162,7 @@ mymain(void) DO_TEST3("physnetwork", false); DO_TEST3("macvlannetwork", false); DO_TEST3("vlannetwork", false); + DO_TEST3("miscnetwork", false); DO_TEST3("idmap", false); DO_TEST3("memtune", false); DO_TEST3("cputune", false); -- 2.19.1

On 11/30/18 7:43 AM, Julio Faracco wrote:
This serie fixes a bug related to IPv{4,6} gateway settings when it is defined and used with multiple network definitions. Basically, this data is being carried on to the next network settings because the pointer is not being cleaned up/initialized properly. The idea behind the fix was create a new way to initialize the data without knowing the structure attributes. The old way has a high probability to cause new bugs.
This serie add a new test case to cover this scenario too. It will be so important to network index implemented on LXC 3.X.
v1-v2: Fixing tabs inside the code.
Julio Faracco (2): lxc: Initializing IPv6 and IPv4 gateway to overwrite old settings. tests: Adding test case to include multiple network definitions.
src/lxc/lxc_native.c | 27 ++++++----- .../lxcconf2xml-miscnetwork-v3.config | 23 ++++++++++ .../lxcconf2xml-miscnetwork.config | 23 ++++++++++ .../lxcconf2xml-miscnetwork.xml | 45 +++++++++++++++++++ tests/lxcconf2xmltest.c | 2 + 5 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.config create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.xml
Reviewed-by: John Ferlan <jferlan@redhat.com> (and pushed), John
participants (2)
-
John Ferlan
-
Julio Faracco