From e6cce2132b2de08b5bffdca2aafca24412ee87e1 Mon Sep 17 00:00:00 2001 From: Sumukha Tumkur Vani Date: Thu, 4 Feb 2021 21:55:51 -0800 Subject: [PATCH] Advertise ipv6 link local address (#1402) --- scripts/neighbor_advertiser | 16 ++++++++++++++++ tests/neighbor_advertiser_test.py | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/scripts/neighbor_advertiser b/scripts/neighbor_advertiser index c1545646dd4f..7d38dd435a1c 100644 --- a/scripts/neighbor_advertiser +++ b/scripts/neighbor_advertiser @@ -11,6 +11,7 @@ import argparse import json import os import requests +import subprocess import sys import time import traceback @@ -233,6 +234,21 @@ def get_vlan_addresses(vlan_interface): ipv4_addr, ipv4_prefix = get_vlan_addr_prefix(vlan_interface, 4) ipv6_addr, ipv6_prefix = get_vlan_addr_prefix(vlan_interface, 6) + if len(ipv6_addr): + try: + out = subprocess.check_output(['ip', '-6', 'addr', 'show', vlan_interface]) + out = out.decode('UTF-8') + for line in out.splitlines(): + keys = line.split() + if keys[0] == 'inet6': + ip = IPNetwork(keys[1]) + if str(ip.ip).startswith("fe80") and str(ip.ip) not in ipv6_addr: + # Link local ipv6 address + ipv6_addr.append(str(ip.ip)) + ipv6_prefix.append('128') + except Exception: + log.log_error('failed to get %s addresses from o.s.' % vlan_interface) + metadata = config_db.get_table('DEVICE_METADATA') mac_addr = metadata['localhost']['mac'] if not mac_addr: diff --git a/tests/neighbor_advertiser_test.py b/tests/neighbor_advertiser_test.py index 2310a3bf6598..3ba7b8afd75f 100644 --- a/tests/neighbor_advertiser_test.py +++ b/tests/neighbor_advertiser_test.py @@ -1,6 +1,7 @@ import sys import os import pytest +import subprocess from swsscommon.swsscommon import ConfigDBConnector test_path = os.path.dirname(os.path.abspath(__file__)) @@ -19,6 +20,16 @@ def set_up(self): neighbor_advertiser.connect_app_db() def test_neighbor_advertiser_slice(self, set_up): + cmd = "sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0" + subprocess.check_output(cmd.split()) + cmd = "sudo ip link add Vlan1000 type dummy" + subprocess.check_output(cmd.split()) + cmd = "sudo ip -6 address add dev Vlan1000 scope link fe80::1e34:daff:fe1e:2800/64" + subprocess.check_output(cmd.split()) + cmd = "sudo ip link add Vlan2000 type dummy" + subprocess.check_output(cmd.split()) + cmd = "sudo ip -6 address add dev Vlan2000 scope link fe80::1e43:dfaf:fe2e:1800/64" + subprocess.check_output(cmd.split()) output = neighbor_advertiser.construct_neighbor_advertiser_slice() expected_output = dict( { @@ -29,7 +40,8 @@ def test_neighbor_advertiser_slice(self, set_up): {'macAddr': '1d:34:db:16:a6:00', 'ipAddr': '192.168.0.1', 'ipPrefixLen': '32'} ], 'ipv6AddrMappings': [ - {'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1000::1', 'ipPrefixLen': '128'} + {'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1000::1', 'ipPrefixLen': '128'}, + {'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fe80::1e34:daff:fe1e:2800', 'ipPrefixLen': '128'} ], 'vxlanId': '1000', 'vlanId': '1000', @@ -40,7 +52,8 @@ def test_neighbor_advertiser_slice(self, set_up): {'macAddr': '1d:34:db:16:a6:00', 'ipAddr': '192.168.0.10', 'ipPrefixLen': '21'} ], 'ipv6AddrMappings': [ - {'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1011::1', 'ipPrefixLen': '64'} + {'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1011::1', 'ipPrefixLen': '64'}, + {'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fe80::1e43:dfaf:fe2e:1800', 'ipPrefixLen': '128'} ], 'vxlanId': '2000', 'vlanId': '2000',