Skip to content

Commit

Permalink
Delete our rule first and add it back, to take care of caclmgrd restart.
Browse files Browse the repository at this point in the history
Another benefit is that we delete only our rules, rather than earlier approach of "iptables -F" which cleans up all rules.
  • Loading branch information
judyjoseph committed Sep 24, 2020
1 parent 02c493a commit db5b102
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions files/image_config/caclmgrd/caclmgrd
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,27 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
"""
fwd_snmp_traffic_from_namespace_to_host_cmds = []

# The action set for iptables where D is DELETE, A is APPEND
rule_action_list = ['D', 'A']

if namespace:
# IPv4 rules
fwd_snmp_traffic_from_namespace_to_host_cmds.append(self.iptables_cmd_ns_prefix[namespace] +
"iptables -t nat -A PREROUTING -p udp --dport {} -j DNAT --to-destination {}".format
(self.ACL_SERVICES['SNMP']['dst_ports'][0], self.namespace_mgmt_ip))
fwd_snmp_traffic_from_namespace_to_host_cmds.append(self.iptables_cmd_ns_prefix[namespace] +
"iptables -t nat -A POSTROUTING -p udp --dport {} -j SNAT --to-source {}".format
(self.ACL_SERVICES['SNMP']['dst_ports'][0], self.namespace_docker_mgmt_ip[namespace]))

# IPv6 rules
fwd_snmp_traffic_from_namespace_to_host_cmds.append(self.iptables_cmd_ns_prefix[namespace] +
"ip6tables -t nat -A PREROUTING -p udp --dport {} -j DNAT --to-destination {}".format
(self.ACL_SERVICES['SNMP']['dst_ports'][0], self.namespace_mgmt_ipv6))
fwd_snmp_traffic_from_namespace_to_host_cmds.append(self.iptables_cmd_ns_prefix[namespace] +
"ip6tables -t nat -A POSTROUTING -p udp --dport {} -j SNAT --to-source {}".format
(self.ACL_SERVICES['SNMP']['dst_ports'][0], self.namespace_docker_mgmt_ipv6[namespace]))
# Delete only the rules we created earlier before addiing them again, useful in case of caclmgrd restart.
for action in rule_action_list:
# IPv4 rules
fwd_snmp_traffic_from_namespace_to_host_cmds.append(self.iptables_cmd_ns_prefix[namespace] +
"iptables -t nat -{} PREROUTING -p udp --dport {} -j DNAT --to-destination {}".format
(action, self.ACL_SERVICES['SNMP']['dst_ports'][0], self.namespace_mgmt_ip))
fwd_snmp_traffic_from_namespace_to_host_cmds.append(self.iptables_cmd_ns_prefix[namespace] +
"iptables -t nat -{} POSTROUTING -p udp --dport {} -j SNAT --to-source {}".format
(action, self.ACL_SERVICES['SNMP']['dst_ports'][0], self.namespace_docker_mgmt_ip[namespace]))

# IPv6 rules
fwd_snmp_traffic_from_namespace_to_host_cmds.append(self.iptables_cmd_ns_prefix[namespace] +
"ip6tables -t nat -{} PREROUTING -p udp --dport {} -j DNAT --to-destination {}".format
(action, self.ACL_SERVICES['SNMP']['dst_ports'][0], self.namespace_mgmt_ipv6))
fwd_snmp_traffic_from_namespace_to_host_cmds.append(self.iptables_cmd_ns_prefix[namespace] +
"ip6tables -t nat -{} POSTROUTING -p udp --dport {} -j SNAT --to-source {}".format
(action, self.ACL_SERVICES['SNMP']['dst_ports'][0], self.namespace_docker_mgmt_ipv6[namespace]))

return fwd_snmp_traffic_from_namespace_to_host_cmds

Expand Down

0 comments on commit db5b102

Please sign in to comment.