Skip to content

Commit e6cce21

Browse files
authored
Advertise ipv6 link local address (sonic-net#1402)
1 parent a6e322a commit e6cce21

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

scripts/neighbor_advertiser

+16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import argparse
1111
import json
1212
import os
1313
import requests
14+
import subprocess
1415
import sys
1516
import time
1617
import traceback
@@ -233,6 +234,21 @@ def get_vlan_addresses(vlan_interface):
233234
ipv4_addr, ipv4_prefix = get_vlan_addr_prefix(vlan_interface, 4)
234235
ipv6_addr, ipv6_prefix = get_vlan_addr_prefix(vlan_interface, 6)
235236

237+
if len(ipv6_addr):
238+
try:
239+
out = subprocess.check_output(['ip', '-6', 'addr', 'show', vlan_interface])
240+
out = out.decode('UTF-8')
241+
for line in out.splitlines():
242+
keys = line.split()
243+
if keys[0] == 'inet6':
244+
ip = IPNetwork(keys[1])
245+
if str(ip.ip).startswith("fe80") and str(ip.ip) not in ipv6_addr:
246+
# Link local ipv6 address
247+
ipv6_addr.append(str(ip.ip))
248+
ipv6_prefix.append('128')
249+
except Exception:
250+
log.log_error('failed to get %s addresses from o.s.' % vlan_interface)
251+
236252
metadata = config_db.get_table('DEVICE_METADATA')
237253
mac_addr = metadata['localhost']['mac']
238254
if not mac_addr:

tests/neighbor_advertiser_test.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import os
33
import pytest
4+
import subprocess
45
from swsscommon.swsscommon import ConfigDBConnector
56

67
test_path = os.path.dirname(os.path.abspath(__file__))
@@ -19,6 +20,16 @@ def set_up(self):
1920
neighbor_advertiser.connect_app_db()
2021

2122
def test_neighbor_advertiser_slice(self, set_up):
23+
cmd = "sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0"
24+
subprocess.check_output(cmd.split())
25+
cmd = "sudo ip link add Vlan1000 type dummy"
26+
subprocess.check_output(cmd.split())
27+
cmd = "sudo ip -6 address add dev Vlan1000 scope link fe80::1e34:daff:fe1e:2800/64"
28+
subprocess.check_output(cmd.split())
29+
cmd = "sudo ip link add Vlan2000 type dummy"
30+
subprocess.check_output(cmd.split())
31+
cmd = "sudo ip -6 address add dev Vlan2000 scope link fe80::1e43:dfaf:fe2e:1800/64"
32+
subprocess.check_output(cmd.split())
2233
output = neighbor_advertiser.construct_neighbor_advertiser_slice()
2334
expected_output = dict(
2435
{
@@ -29,7 +40,8 @@ def test_neighbor_advertiser_slice(self, set_up):
2940
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': '192.168.0.1', 'ipPrefixLen': '32'}
3041
],
3142
'ipv6AddrMappings': [
32-
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1000::1', 'ipPrefixLen': '128'}
43+
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1000::1', 'ipPrefixLen': '128'},
44+
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fe80::1e34:daff:fe1e:2800', 'ipPrefixLen': '128'}
3345
],
3446
'vxlanId': '1000',
3547
'vlanId': '1000',
@@ -40,7 +52,8 @@ def test_neighbor_advertiser_slice(self, set_up):
4052
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': '192.168.0.10', 'ipPrefixLen': '21'}
4153
],
4254
'ipv6AddrMappings': [
43-
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1011::1', 'ipPrefixLen': '64'}
55+
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1011::1', 'ipPrefixLen': '64'},
56+
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fe80::1e43:dfaf:fe2e:1800', 'ipPrefixLen': '128'}
4457
],
4558
'vxlanId': '2000',
4659
'vlanId': '2000',

0 commit comments

Comments
 (0)