KVM test: Add support for ipv6 addresses
PATCH 1/1 KVM test: Add support for ipv6 addresses
This patch enables ipv6 address support in kvm-autotest.
The patch adds a new dictionary called "address6_cache" for ip6 address. Tcpdump is used to create this cache of link-local ipv6 address.
Link-local ipv6 address is used because it eliminates to need to create complex configuration on both the host and the guest.
The ipv6 address for a guest can be obtained by using the new function get_address6 in kvm_vm.py
--- client/tests/kvm/kvm_preprocessing.py | 29 ++++++++++++++++++- client/tests/kvm/kvm_utils.py | 28 +++++++++++++++++++ client/tests/kvm/kvm_vm.py | 49 +++++++++++++++++++++++++++++++-- 3 files changed, 101 insertions(+), 5 deletions(-)
client/tests/kvm/kvm_preprocessing.py +27 -2
@@ -51,7 +51,8 @@ def preprocess_vm(test, params, env, name): logging.debug("VM object found in environment") else: logging.debug("VM object does not exist; creating it") - vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache")) + vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache"), + env.get("address6_cache")) kvm_utils.env_register_vm(env, name, vm) start_vm = False
@@ -199,6 +200,14 @@ def preprocess(test, params, env): command=command, output_func=_update_address_cache, output_params=(env["address_cache"],)) + + env["address6_cache"] = {} + command6 = "/usr/sbin/tcpdump -npv ip6 -i any 'dst net ff02::2'" + env["tcpdump6"] = kvm_subprocess.kvm_tail( + command=command6, + output_func=_update_address6_cache, + output_params=(env["address6_cache"],)) + if kvm_utils.wait_for(lambda: not env["tcpdump"].is_alive(), 0.1, 0.1, 1.0): logging.warn("Could not start tcpdump")
@@ -321,6 +330,8 @@ def postprocess(test, params, env): if not living_vms and env.has_key("tcpdump"): env["tcpdump"].close() del env["tcpdump"] + env["tcpdump6"].close() + del env["tcpdump6"] def postprocess_on_error(test, params, env):
@@ -343,7 +354,21 @@ def _update_address_cache(address_cache, line): matches = re.findall(r"\w*:\w*:\w*:\w*:\w*:\w*", line) if matches and address_cache.get("last_seen"): mac_address = matches[0].lower() - logging.debug("(address cache) Adding cache entry: %s ---> %s", + logging.debug("(address cache ipv4) Adding cache entry: %s ---> %s", mac_address, address_cache.get("last_seen")) address_cache[mac_address] = address_cache.get("last_seen") del address_cache["last_seen"] + +def _update_address6_cache(address6_cache, line): + if re.search("ff02::2:", line, re.IGNORECASE): + matches = re.findall(r"(fe80.+) >", line) + if matches: + address6_cache["last_seen"] = matches[0] + if re.search("source link-address option", line, re.IGNORECASE): + matches = re.findall(r"\w*:\w*:\w*:\w*:\w*:\w*", line) + if matches and address6_cache.get("last_seen"): + mac_address = matches[0].lower() + logging.debug("(address cache ipv6) Adding cache entry: %s ---> %s", + mac_address, address6_cache.get("last_seen")) + address6_cache[mac_address] = address6_cache.get("last_seen") + del address6_cache["last_seen"]
client/tests/kvm/kvm_utils.py +28 -0
@@ -208,6 +208,34 @@ def verify_ip_address_ownership(ip, macs, timeout=10.0): o = commands.getoutput("/sbin/arping -f -c 3 -I %s %s" % (dev, ip)) return bool(regex.search(o)) +def verify_ip6_address_ownership(ip, macs, timeout=10.0): + """ + Use ping6 and the ND cache to make sure a given IP address belongs to one + of the given MAC addresses. + + @param ip: An IP6 address. + @param macs: A list or tuple of MAC addresses. + @return: True iff ip is assigned to a MAC address in macs. + """ + # Compile a regex that matches the given IP6 address and any of the given + # MAC addresses + mac_regex = "|".join("(%s)" % mac for mac in macs) + regex = re.compile(r"\b%s\b.*\b(%s)\b" % (ip, mac_regex), re.IGNORECASE) + + # Get the name of the bridge device for ping6 + o = commands.getoutput("/sbin/ip route get ff02::1" ) + dev = re.findall("dev\s+\S+", o, re.IGNORECASE) + if not dev: + return False + dev = dev[0].split()[-1] + + if bool(commands.getstatusoutput("/bin/ping6 -c 11 -I %s %s"% (dev, ip)[0])): + return False + + # Check the ND cache + o = commands.getoutput("/sbin/ip -6 neigh show") + if regex.search(o): + return True # Functions for working with the environment (a dict-like object)
client/tests/kvm/kvm_vm.py +46 -3
91 lines not on this page · raw message
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
H i Yogi, I have read and rebased your patch against current trunk. I have one doubt: I noticed that the tcpdump command you use to monitor traffic is basically all traffic that goes to network routers
/usr/sbin/tcpdump -npv ip6 -i any 'dst net ff02::2'
However, the IPv4 implementation filters the traffic to the dhcp/bootp port, 68. Therefore the ipv6 mapper captures more (non necessarily useful) mappings than the ipv4 version. I made some brief research and couldn't figure out how to do it. Do you think it's possible to refine the tcpdump command to make it look only on the dhp request port (68)?
Quoted 25 lines · Lucas Meneghel Rodrigues
This patch enables ipv6 address support in kvm-autotest.
The patch adds a new dictionary called "address6_cache" for ip6 address. Tcpdump is used to create this cache of link-local ipv6 address.Link-local ipv6 address is used because it eliminates to need to create complex configuration on both the host and the guest.
The ipv6 address for a guest can be obtained by using the new function
get_address6inkvm_vm.pySigned-off-by Yogananth Subramanian <[email protected]>---
client/tests/kvm/kvm_preprocessing.py | 29 ++++++++++++++++++-client/tests/kvm/kvm_utils.py| 28 +++++++++++++++++++client/tests/kvm/kvm_vm.py| 49 +++++++++++++++++++++++++++++++--3 files changed, 101 insertions(+), 5 deletions(-)_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
Signature · 1 line
Lucas
Quoted 4 lines · Lucas Meneghel Rodrigues
H i Yogi, I have read and rebased your patch against current trunk. I have one doubt: I noticed that the tcpdump command you use to monitor traffic is basically all traffic that goes to network routers
Quoted 8 lines
/usr/sbin/tcpdump-npv ip6 -i any 'dst net ff02::2'However, the IPv4 implementation filters the traffic to the dhcp/bootp port, 68. Therefore the ipv6 mapper captures more (non necessarily useful) mappings than the ipv4 version. I made some brief research and couldn't figure out how to do it. Do you think it's possible to refine the tcpdump command to make it look only on the dhp request port (68)?
Hello Lucas, thanks for reviewing my patches for ipv6. Following tcpdump command will capture only the icmp6 packets and not all the ipv6 packets
tcpdump -npv -i any icmp6 and 'dst net ff02::2'
Since the patch uses ip6 link local address, we are looking for router solicitation messages.
Thanks
Yogi
Quoted 30 lines
Quoted 25 lines · Lucas Meneghel Rodrigues
This patch enables ipv6 address support in kvm-autotest.
The patch adds a new dictionary called "address6_cache" for ip6 address. Tcpdump is used to create this cache of link-local ipv6 address.Link-local ipv6 address is used because it eliminates to need to create complex configuration on both the host and the guest.
The ipv6 address for a guest can be obtained by using the new function
get_address6inkvm_vm.pySigned-off-by Yogananth Subramanian <[email protected]>--- client/tests/kvm/kvm_preprocessing.py | 29 ++++++++++++++++++- client/tests/kvm/kvm_utils.py | 28 +++++++++++++++++++ client/tests/kvm/kvm_vm.py | 49 +++++++++++++++++++++++++++++++-- 3 files changed, 101 insertions(+), 5 deletions(-)_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
Quoted 14 lines · yogi
Quoted 4 lines · Lucas Meneghel Rodrigues
H i Yogi, I have read and rebased your patch against current trunk. I have one doubt: I noticed that the tcpdump command you use to monitor traffic is basically all traffic that goes to network routers
Quoted 8 lines
/usr/sbin/tcpdump-npv ip6 -i any 'dst net ff02::2'However, the IPv4 implementation filters the traffic to the dhcp/bootp port, 68. Therefore the ipv6 mapper captures more (non necessarily useful) mappings than the ipv4 version. I made some brief research and couldn't figure out how to do it. Do you think it's possible to refine the tcpdump command to make it look only on the dhp request port (68)?
Quoted 7 lines
Hello Lucas, thanks for reviewing my patches for ipv6. Following tcpdump command will capture only the icmp6 packets and not all the ipv6 packets
tcpdump -npv -i any icmp6 and 'dst net ff02::2'Since the patch uses ip6 link local address, we are looking for router solicitation messages.
Ok, so you think it'd be better to change the tcpdump command used in the patch to be "tcpdump -npv -i any icmp6 and 'dst net ff02::2'"?
That said, I don't fully understand all gory ipv6 details, so please bear with me on this question: how would we be benefit from having an ipv6 address cache? I mean, it's not like we're going to use the mappings for any of the communications...
This patch will stay in the queue so Michael can take a look at it and give opinions.
Cheers,
Lucas
Quoted 20 lines · Lucas Meneghel Rodrigues
Quoted 19 lines · yogi
Quoted 4 lines · Lucas Meneghel Rodrigues
H i Yogi, I have read and rebased your patch against current trunk. I have one doubt: I noticed that the tcpdump command you use to monitor traffic is basically all traffic that goes to network routers
Quoted 8 lines
/usr/sbin/tcpdump-npv ip6 -i any 'dst net ff02::2'However, the IPv4 implementation filters the traffic to the dhcp/bootp port, 68. Therefore the ipv6 mapper captures more (non necessarily useful) mappings than the ipv4 version. I made some brief research and couldn't figure out how to do it. Do you think it's possible to refine the tcpdump command to make it look only on the dhp request port (68)?
Hello Lucas, thanks for reviewing my patches for ipv6. Following tcpdump command will capture only the icmp6 packets and not all the ipv6 packets
tcpdump -npv -i any icmp6 and 'dst net ff02::2'
Quoted 6 lines
Quoted 2 lines
Since the patch uses ip6 link local address, we are looking for router solicitation messages.
Ok, so you think it'd be better to change the tcpdump command used in the patch to be "tcpdump -npv -i any icmp6 and 'dst net ff02::2'"?
Yes, its better to change the tcdump in the patch, so that it captures only the icmp6 packets.
Quoted 4 lines
That said, I don't fully understand all gory ipv6 details, so please bear with me on this question: how would we be benefit from having an ipv6 address cache? I mean, it's not like we're going to use the mappings for any of the communications...
Ipv6 address cache would add support to test the ipv6 stack in the guest, while doing network tests.
Quoted 3 lines
This patch will stay in the queue so Michael can take a look at it and give opinions.
Sure no problem at all. I would be happy to resubmit the Ipv6 patch, when there is support to do network tests in kvm-autotest becomes available.
Quoted 5 lines
Cheers,
Lucas
Thanks and Regards
Yogi