[posix] bind the resolver's UDP socket to the infra network interface (#10864)

This commit fixes an issue in DNS recursive resolver that it didn't
bind its socket to the infra network interface. This may cause the DNS
message to be sent on an unexpected network interface, depending on
the routing table of the platform.

This commit also updates the test case `test_upstream_dns.py` to make
the upstream DNS server run on a different node. Previously the
upstream DNS server ran on the same node as the BR which is a
limitation of this test case.
This commit is contained in:
Handa Wang
2024-10-29 07:54:55 -07:00
committed by GitHub
parent 005c5cefc2
commit d88b63d192
5 changed files with 72 additions and 27 deletions
+16 -8
View File
@@ -3818,19 +3818,27 @@ class LinuxHost():
self.bash(f'ip link set {self.ETH_DEV} down')
def get_ether_addrs(self):
output = self.bash(f'ip -6 addr list dev {self.ETH_DEV}')
def get_ether_addrs(self, ipv4=False, ipv6=True):
output = self.bash(f'ip addr list dev {self.ETH_DEV}')
addrs = []
for line in output:
# line example: "inet6 fe80::42:c0ff:fea8:903/64 scope link"
# line examples:
# "inet6 fe80::42:c0ff:fea8:903/64 scope link"
# "inet 192.168.9.1/24 brd 192.168.9.255 scope global eth0"
line = line.strip().split()
if line and line[0] == 'inet6':
addr = line[1]
if '/' in addr:
addr = addr.split('/')[0]
addrs.append(addr)
if not line or not line[0].startswith('inet'):
continue
if line[0] == 'inet' and not ipv4:
continue
if line[0] == 'inet6' and not ipv6:
continue
addr = line[1]
if '/' in addr:
addr = addr.split('/')[0]
addrs.append(addr)
logging.debug('%s: get_ether_addrs: %r', self, addrs)
return addrs