From 75945ad74cf614b3516abd3a50de56cbaab58346 Mon Sep 17 00:00:00 2001 From: Redouane Kachach Date: Thu, 5 May 2022 16:08:12 +0200 Subject: [PATCH] mgr/cephadm: fixing ipv6/128 and ipv4/32 subnets handling Fixes: https://tracker.ceph.com/issues/51257 Fixes: https://tracker.ceph.com/issues/53496 Signed-off-by: Redouane Kachach --- src/cephadm/cephadm | 10 +++++++--- src/cephadm/tests/test_networks.py | 15 +++++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 0de6dc4e523..09260d0ccbd 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -6083,12 +6083,14 @@ def _list_ipv4_networks(ctx: CephadmContext) -> Dict[str, Dict[str, Set[str]]]: def _parse_ipv4_route(out: str) -> Dict[str, Dict[str, Set[str]]]: r = {} # type: Dict[str, Dict[str, Set[str]]] - p = re.compile(r'^(\S+) dev (\S+) (.*)scope link (.*)src (\S+)') + p = re.compile(r'^(\S+) (?:via \S+)? ?dev (\S+) (.*)scope link (.*)src (\S+)') for line in out.splitlines(): m = p.findall(line) if not m: continue net = m[0][0] + if '/' not in net: # aggregate /32 mask for single host sub-networks + net += '/32' iface = m[0][1] ip = m[0][4] if net not in r: @@ -6118,9 +6120,11 @@ def _parse_ipv6_route(routes: str, ips: str) -> Dict[str, Dict[str, Set[str]]]: if not m or m[0][0].lower() == 'default': continue net = m[0][0] - if '/' not in net: # only consider networks with a mask - continue + if '/' not in net: # aggregate /128 mask for single host sub-networks + net += '/128' iface = m[0][1] + if iface == 'lo': # skip loopback devices + continue if net not in r: r[net] = {} if iface not in r[net]: diff --git a/src/cephadm/tests/test_networks.py b/src/cephadm/tests/test_networks.py index ef0f6778a77..6fa47ea2704 100644 --- a/src/cephadm/tests/test_networks.py +++ b/src/cephadm/tests/test_networks.py @@ -24,6 +24,8 @@ class TestCommandListNetworks: 139.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50 140.1.0.0/17 via 10.4.0.1 dev tun0 proto static metric 50 141.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50 + 172.16.100.34 via 172.16.100.34 dev eth1 proto kernel scope link src 172.16.100.34 + 192.168.122.1 dev ens3 proto dhcp scope link src 192.168.122.236 metric 100 169.254.0.0/16 dev docker0 scope link metric 1000 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 192.168.39.0/24 dev virbr1 proto kernel scope link src 192.168.39.1 linkdown @@ -33,7 +35,9 @@ class TestCommandListNetworks: 195.135.221.12 via 192.168.178.1 dev enxd89ef3f34260 proto static metric 100 """), { - '10.4.0.1': {'tun0': {'10.4.0.2'}}, + '172.16.100.34/32': {'eth1': {'172.16.100.34'}}, + '192.168.122.1/32': {'ens3': {'192.168.122.236'}}, + '10.4.0.1/32': {'tun0': {'10.4.0.2'}}, '172.17.0.0/16': {'docker0': {'172.17.0.1'}}, '192.168.39.0/24': {'virbr1': {'192.168.39.1'}}, '192.168.122.0/24': {'virbr0': {'192.168.122.1'}}, @@ -61,7 +65,7 @@ class TestCommandListNetworks: { '10.3.64.0/24': {'eno1': {'10.3.64.23', '10.3.64.27'}}, '10.88.0.0/16': {'cni-podman0': {'10.88.0.1'}}, - '172.21.3.1': {'tun0': {'172.21.3.2'}}, + '172.21.3.1/32': {'tun0': {'172.21.3.2'}}, '192.168.122.0/24': {'virbr0': {'192.168.122.1'}} } ), @@ -175,11 +179,14 @@ class TestCommandListNetworks: valid_lft forever preferred_lft forever """), { - '2001:1458:301:eb::/64': { + '2001:1458:301:eb::100:1a/128': { 'ens20f0': { '2001:1458:301:eb::100:1a' }, }, + '2001:1458:301:eb::/64': { + 'ens20f0': set(), + }, 'fe80::/64': { 'ens20f0': {'fe80::2e60:cff:fef8:da41'}, }, @@ -224,5 +231,5 @@ class TestCommandListNetworks: with with_cephadm_ctx([]) as ctx: cd.command_list_networks(ctx) assert json.loads(capsys.readouterr().out) == { - '10.4.0.1': {'tun0': ['10.4.0.2']} + '10.4.0.1/32': {'tun0': ['10.4.0.2']} } \ No newline at end of file -- 2.39.5