Skip to content

Commit 4a64ef8

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 bd88ec2 commit 4a64ef8

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

scripts/caclmgrd

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

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

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

303299
return block_ip2me_cmds
304300

tests/caclmgrd/test_ip2me_vectors.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,32 @@
8585
],
8686
},
8787
],
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/32", "-j", "DROP"],
111+
],
112+
},
113+
],
88114
[
89115
"One interface of each type, IPv6, /64 - block all interfaces but MGMT",
90116
{
@@ -114,10 +140,10 @@
114140
},
115141
"return": [
116142
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:10::/128', '-j', 'DROP'],
117-
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:11::1/128', '-j', 'DROP'],
143+
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:11::/128', '-j', 'DROP'],
118144
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:12::/128', '-j', 'DROP'],
119145
['ip6tables', '-A', 'INPUT', '-d', '2001:db8:13::/128', '-j', 'DROP']
120-
],
146+
],
121147
},
122148
]
123149
]

0 commit comments

Comments
 (0)