Skip to content

Commit 3daac6f

Browse files
authored
Merge pull request ceph#46202 from rkachach/fix_issue_51257
mgr/cephadm: fixing ipv6/128 and ipv4/32 subnets handling Reviewed-by: Adam King <adking@redhat.com> Reviewed-by: John Mulligan <jmulligan@redhat.com>
2 parents e01758e + 75945ad commit 3daac6f

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/cephadm/cephadm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6098,12 +6098,14 @@ def _list_ipv4_networks(ctx: CephadmContext) -> Dict[str, Dict[str, Set[str]]]:
60986098

60996099
def _parse_ipv4_route(out: str) -> Dict[str, Dict[str, Set[str]]]:
61006100
r = {} # type: Dict[str, Dict[str, Set[str]]]
6101-
p = re.compile(r'^(\S+) dev (\S+) (.*)scope link (.*)src (\S+)')
6101+
p = re.compile(r'^(\S+) (?:via \S+)? ?dev (\S+) (.*)scope link (.*)src (\S+)')
61026102
for line in out.splitlines():
61036103
m = p.findall(line)
61046104
if not m:
61056105
continue
61066106
net = m[0][0]
6107+
if '/' not in net: # aggregate /32 mask for single host sub-networks
6108+
net += '/32'
61076109
iface = m[0][1]
61086110
ip = m[0][4]
61096111
if net not in r:
@@ -6133,9 +6135,11 @@ def _parse_ipv6_route(routes: str, ips: str) -> Dict[str, Dict[str, Set[str]]]:
61336135
if not m or m[0][0].lower() == 'default':
61346136
continue
61356137
net = m[0][0]
6136-
if '/' not in net: # only consider networks with a mask
6137-
continue
6138+
if '/' not in net: # aggregate /128 mask for single host sub-networks
6139+
net += '/128'
61386140
iface = m[0][1]
6141+
if iface == 'lo': # skip loopback devices
6142+
continue
61396143
if net not in r:
61406144
r[net] = {}
61416145
if iface not in r[net]:

src/cephadm/tests/test_networks.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class TestCommandListNetworks:
2424
139.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50
2525
140.1.0.0/17 via 10.4.0.1 dev tun0 proto static metric 50
2626
141.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50
27+
172.16.100.34 via 172.16.100.34 dev eth1 proto kernel scope link src 172.16.100.34
28+
192.168.122.1 dev ens3 proto dhcp scope link src 192.168.122.236 metric 100
2729
169.254.0.0/16 dev docker0 scope link metric 1000
2830
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
2931
192.168.39.0/24 dev virbr1 proto kernel scope link src 192.168.39.1 linkdown
@@ -33,7 +35,9 @@ class TestCommandListNetworks:
3335
195.135.221.12 via 192.168.178.1 dev enxd89ef3f34260 proto static metric 100
3436
"""),
3537
{
36-
'10.4.0.1': {'tun0': {'10.4.0.2'}},
38+
'172.16.100.34/32': {'eth1': {'172.16.100.34'}},
39+
'192.168.122.1/32': {'ens3': {'192.168.122.236'}},
40+
'10.4.0.1/32': {'tun0': {'10.4.0.2'}},
3741
'172.17.0.0/16': {'docker0': {'172.17.0.1'}},
3842
'192.168.39.0/24': {'virbr1': {'192.168.39.1'}},
3943
'192.168.122.0/24': {'virbr0': {'192.168.122.1'}},
@@ -61,7 +65,7 @@ class TestCommandListNetworks:
6165
{
6266
'10.3.64.0/24': {'eno1': {'10.3.64.23', '10.3.64.27'}},
6367
'10.88.0.0/16': {'cni-podman0': {'10.88.0.1'}},
64-
'172.21.3.1': {'tun0': {'172.21.3.2'}},
68+
'172.21.3.1/32': {'tun0': {'172.21.3.2'}},
6569
'192.168.122.0/24': {'virbr0': {'192.168.122.1'}}
6670
}
6771
),
@@ -175,11 +179,14 @@ def test_parse_ipv4_route(self, test_input, expected):
175179
valid_lft forever preferred_lft forever
176180
"""),
177181
{
178-
'2001:1458:301:eb::/64': {
182+
'2001:1458:301:eb::100:1a/128': {
179183
'ens20f0': {
180184
'2001:1458:301:eb::100:1a'
181185
},
182186
},
187+
'2001:1458:301:eb::/64': {
188+
'ens20f0': set(),
189+
},
183190
'fe80::/64': {
184191
'ens20f0': {'fe80::2e60:cff:fef8:da41'},
185192
},
@@ -224,5 +231,5 @@ def test_command_list_networks(self, cephadm_fs, capsys):
224231
with with_cephadm_ctx([]) as ctx:
225232
cd.command_list_networks(ctx)
226233
assert json.loads(capsys.readouterr().out) == {
227-
'10.4.0.1': {'tun0': ['10.4.0.2']}
234+
'10.4.0.1/32': {'tun0': ['10.4.0.2']}
228235
}

0 commit comments

Comments
 (0)