@@ -314,27 +314,28 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
314314 nat_source_ipv6_set = acl_source_ip_map [acl_service ]["ipv6" ] if acl_source_ip_map and acl_source_ip_map [acl_service ]["ipv6" ] else { "::/0" }
315315
316316 for ip_protocol in self .ACL_SERVICES [acl_service ]["ip_protocols" ]:
317- for dst_port in self .ACL_SERVICES [acl_service ]["dst_ports" ]:
318- for ipv4_src_ip in nat_source_ipv4_set :
319- # IPv4 rules
320- fwd_traffic_from_namespace_to_host_cmds .append (self .iptables_cmd_ns_prefix [namespace ] +
321- "iptables -t nat -A PREROUTING -p {} -s {} --dport {} -j DNAT --to-destination {}" .format
322- (ip_protocol , ipv4_src_ip , dst_port ,
323- self .namespace_mgmt_ip ))
324- fwd_traffic_from_namespace_to_host_cmds .append (self .iptables_cmd_ns_prefix [namespace ] +
325- "iptables -t nat -A POSTROUTING -p {} -s {} --dport {} -j SNAT --to-source {}" .format
326- (ip_protocol , ipv4_src_ip , dst_port ,
327- self .namespace_docker_mgmt_ip [namespace ]))
328- for ipv6_src_ip in nat_source_ipv6_set :
329- # IPv6 rules
330- fwd_traffic_from_namespace_to_host_cmds .append (self .iptables_cmd_ns_prefix [namespace ] +
331- "ip6tables -t nat -A PREROUTING -p {} -s {} --dport {} -j DNAT --to-destination {}" .format
332- (ip_protocol , ipv6_src_ip , dst_port ,
333- self .namespace_mgmt_ipv6 ))
334- fwd_traffic_from_namespace_to_host_cmds .append (self .iptables_cmd_ns_prefix [namespace ] +
335- "ip6tables -t nat -A POSTROUTING -p {} -s {} --dport {} -j SNAT --to-source {}" .format
336- (ip_protocol ,ipv6_src_ip , dst_port ,
337- self .namespace_docker_mgmt_ipv6 [namespace ]))
317+ if "dst_ports" in self .ACL_SERVICES [acl_service ]:
318+ for dst_port in self .ACL_SERVICES [acl_service ]["dst_ports" ]:
319+ for ipv4_src_ip in nat_source_ipv4_set :
320+ # IPv4 rules
321+ fwd_traffic_from_namespace_to_host_cmds .append (self .iptables_cmd_ns_prefix [namespace ] +
322+ "iptables -t nat -A PREROUTING -p {} -s {} --dport {} -j DNAT --to-destination {}" .format
323+ (ip_protocol , ipv4_src_ip , dst_port ,
324+ self .namespace_mgmt_ip ))
325+ fwd_traffic_from_namespace_to_host_cmds .append (self .iptables_cmd_ns_prefix [namespace ] +
326+ "iptables -t nat -A POSTROUTING -p {} -s {} --dport {} -j SNAT --to-source {}" .format
327+ (ip_protocol , ipv4_src_ip , dst_port ,
328+ self .namespace_docker_mgmt_ip [namespace ]))
329+ for ipv6_src_ip in nat_source_ipv6_set :
330+ # IPv6 rules
331+ fwd_traffic_from_namespace_to_host_cmds .append (self .iptables_cmd_ns_prefix [namespace ] +
332+ "ip6tables -t nat -A PREROUTING -p {} -s {} --dport {} -j DNAT --to-destination {}" .format
333+ (ip_protocol , ipv6_src_ip , dst_port ,
334+ self .namespace_mgmt_ipv6 ))
335+ fwd_traffic_from_namespace_to_host_cmds .append (self .iptables_cmd_ns_prefix [namespace ] +
336+ "ip6tables -t nat -A POSTROUTING -p {} -s {} --dport {} -j SNAT --to-source {}" .format
337+ (ip_protocol ,ipv6_src_ip , dst_port ,
338+ self .namespace_docker_mgmt_ipv6 [namespace ]))
338339
339340 return fwd_traffic_from_namespace_to_host_cmds
340341
0 commit comments