@@ -285,20 +285,16 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
285
285
for key , _ in iface_table .items ():
286
286
if not _ip_prefix_in_key (key ):
287
287
continue
288
-
289
288
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 ))
291
296
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
295
297
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 ))
302
298
303
299
return block_ip2me_cmds
304
300
0 commit comments