Skip to content

Commit 5f17c7a

Browse files
committed
kamel: [caclmgrd] Use interface IP for IP2ME
Currently the first IP on the VLAN subnet is used, regardless of whatever IP is actually assigned to the control plane. This fix uses the correct IP. See earlier work: - sonic-net/sonic-buildimage#9826 - sonic-net/sonic-buildimage#7178 - sonic-net/sonic-buildimage#7008 Signed-off-by: Christian Svensson <[email protected]>
1 parent cc6eb42 commit 5f17c7a

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

scripts/caclmgrd

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,16 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
282282
for key, _ in iface_table.items():
283283
if not _ip_prefix_in_key(key):
284284
continue
285-
286285
iface_name, iface_cidr = key
287-
ip_ntwrk = ipaddress.ip_network(iface_cidr, strict=False)
286+
ip_iface = ipaddress.ip_interface(iface_cidr)
287+
if isinstance(ip_iface, ipaddress.IPv4Interface):
288+
block_ip2me_cmds.append(self.iptables_cmd_ns_prefix[namespace] + ['iptables', '-A', 'INPUT', '-d', format(ip_iface.ip), '-j', 'DROP'])
289+
elif isinstance(ip_iface, ipaddress.IPv6Interface):
290+
block_ip2me_cmds.append(self.iptables_cmd_ns_prefix[namespace] + ['ip6tables', '-A', 'INPUT', '-d', format(ip_iface.ip), '-j', 'DROP'])
291+
else:
292+
self.log_warning("Unrecognized IP address type on interface '{}': {}".format(iface_name, ip_iface))
288293

289-
# For VLAN interfaces, the IP address we want to block is the default gateway (i.e.,
290-
# the first available host IP address of the VLAN subnet)
291-
ip_addr = next(ip_ntwrk.hosts()) if iface_table_name == "VLAN_INTERFACE" else ip_ntwrk.network_address
292294

293-
if isinstance(ip_ntwrk, ipaddress.IPv4Network):
294-
block_ip2me_cmds.append(self.iptables_cmd_ns_prefix[namespace] + ['iptables', '-A', 'INPUT', '-d', '{}/{}'.format(ip_addr, ip_ntwrk.max_prefixlen), '-j', 'DROP'])
295-
elif isinstance(ip_ntwrk, ipaddress.IPv6Network):
296-
block_ip2me_cmds.append(self.iptables_cmd_ns_prefix[namespace] + ['ip6tables', '-A', 'INPUT', '-d', '{}/{}'.format(ip_addr, ip_ntwrk.max_prefixlen), '-j', 'DROP'])
297-
else:
298-
self.log_warning("Unrecognized IP address type on interface '{}': {}".format(iface_name, ip_ntwrk))
299295

300296
return block_ip2me_cmds
301297

tests/caclmgrd/test_ip2me_vectors.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
"FEATURE": {},
5454
},
5555
"return": [
56-
['iptables', '-A', 'INPUT', '-d', '10.10.10.10/32', '-j', 'DROP'],
57-
['iptables', '-A', 'INPUT', '-d', '10.10.11.10/32', '-j', 'DROP'],
58-
['iptables', '-A', 'INPUT', '-d', '10.10.12.10/32', '-j', 'DROP'],
56+
['iptables', '-A', 'INPUT', '-d', '10.10.10.10', '-j', 'DROP'],
57+
['iptables', '-A', 'INPUT', '-d', '10.10.11.10', '-j', 'DROP'],
58+
['iptables', '-A', 'INPUT', '-d', '10.10.12.10', '-j', 'DROP'],
5959
],
6060
},
6161
],
@@ -81,7 +81,33 @@
8181
"FEATURE": {},
8282
},
8383
"return": [
84-
['iptables', '-A', 'INPUT', '-d', '10.10.11.1/32', '-j', 'DROP'],
84+
['iptables', '-A', 'INPUT', '-d', '10.10.11.1', '-j', 'DROP'],
85+
],
86+
},
87+
],
88+
[
89+
"One VLAN interface, /24, we are .2",
90+
{
91+
"config_db": {
92+
"MGMT_INTERFACE": {
93+
"eth0|172.18.0.100/24": {
94+
"gwaddr": "172.18.0.1"
95+
}
96+
},
97+
"LOOPBACK_INTERFACE": {},
98+
"VLAN_INTERFACE": {
99+
"Vlan110|10.10.11.2/24": {},
100+
},
101+
"PORTCHANNEL_INTERFACE": {},
102+
"INTERFACE": {},
103+
"DEVICE_METADATA": {
104+
"localhost": {
105+
}
106+
},
107+
"FEATURE": {},
108+
},
109+
"return": [
110+
["iptables", "-A", "INPUT", "-d", "10.10.11.2", "-j", "DROP"],
85111
],
86112
},
87113
],
@@ -113,11 +139,11 @@
113139
"FEATURE": {},
114140
},
115141
"return": [
116-
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:10::/128', '-j', 'DROP'],
117-
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:11::1/128', '-j', 'DROP'],
118-
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:12::/128', '-j', 'DROP'],
119-
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:13::/128', '-j', 'DROP']
120-
],
142+
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:10::', '-j', 'DROP'],
143+
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:11::', '-j', 'DROP'],
144+
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:12::', '-j', 'DROP'],
145+
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:13::', '-j', 'DROP']
146+
],
121147
},
122148
]
123149
]

0 commit comments

Comments
 (0)