Skip to content

Commit ba29dc9

Browse files
author
Capirca Team
committed
DSMO invalid netmask fix
PiperOrigin-RevId: 827987592
1 parent 350b346 commit ba29dc9

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

capirca/lib/summarizer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,14 @@ def _SummarizeSameMask(nets):
261261
# or they are "a pair".
262262
if (current_net.netmask == pair_net.netmask and
263263
(xored_address & (xored_address - 1) == 0) and xored_address > 0):
264+
new_netmask = current_net.netmask ^ xored_address
265+
if new_netmask.bit_length() not in (0, 32):
266+
singletons.append(current_net)
267+
break
264268
# if pair was found, remove both, add paired up network
265269
# to combinetons for next run and move along
266270
# otherwise this network can never be paired
267271
current_nets.pop(pair_net_index)
268-
new_netmask = current_net.netmask ^ xored_address
269272
# summarize supplied networks into one using discontinuous
270273
# subnet mask.
271274
combinetons.append(DSMNet(min(current_net.address, pair_net.address),

tests/lib/summarizer_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ def testSummarizeNoNetworks(self):
8585
result = summarizer.Summarize(nets)
8686
self.assertEqual(len(result), 256)
8787

88+
def testDontSummarizeWeirdMasks(self):
89+
nets = [
90+
# combining these results in a weird netmask, dont do it
91+
nacaddr.IPv4('34.144.128.0/19'),
92+
nacaddr.IPv4('162.144.128.0/19'),
93+
]
94+
result = summarizer.Summarize(nets)
95+
self.assertEqual(result, [summarizer.DSMNet(579895296, 4294959104),
96+
summarizer.DSMNet(2727378944, 4294959104)])
97+
8898
def testSummarizeSomeNetworks(self):
8999
nets = [
90100
# continiously summarizable to one /25

0 commit comments

Comments
 (0)