@@ -586,6 +586,14 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
586586 iptables_cmds .append (self .iptables_cmd_ns_prefix [namespace ] + ['iptables' , '-A' , 'INPUT' , '-s' , '127.0.0.1' , '-i' , 'lo' , '-j' , 'ACCEPT' ])
587587 iptables_cmds .append (self .iptables_cmd_ns_prefix [namespace ] + ['ip6tables' , '-A' , 'INPUT' , '-s' , '::1' , '-i' , 'lo' , '-j' , 'ACCEPT' ])
588588
589+
590+ if self .bfdAllowed :
591+ iptables_cmds += self .get_bfd_iptable_commands (namespace )
592+
593+ if self .VxlanAllowed :
594+ fvs = swsscommon .FieldValuePairs ([("src_ip" , self .VxlanSrcIP )])
595+ iptables_cmds += self .get_vxlan_port_iptable_commands (namespace , fvs )
596+
589597 # Add iptables commands to allow internal docker traffic
590598 iptables_cmds += self .generate_allow_internal_docker_ip_traffic_commands (namespace )
591599
@@ -813,12 +821,6 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
813821 self .log_info (" " + ' ' .join (cmd ))
814822
815823 self .run_commands (iptables_cmds )
816- if self .bfdAllowed :
817- self .allow_bfd_protocol (namespace )
818- if self .VxlanAllowed :
819- fvs = swsscommon .FieldValuePairs ([("src_ip" , self .VxlanSrcIP )])
820- self .allow_vxlan_port (namespace , fvs )
821-
822824
823825 self .update_control_plane_nat_acls (namespace , service_to_source_ip_map , config_db_connector )
824826
@@ -886,24 +888,29 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
886888 finally :
887889 new_config_db_connector .close ("CONFIG_DB" )
888890
889- def allow_bfd_protocol (self , namespace ):
891+ def get_bfd_iptable_commands (self , namespace ):
890892 iptables_cmds = []
891893 # Add iptables/ip6tables commands to allow all BFD singlehop and multihop sessions
892894 iptables_cmds .append (self .iptables_cmd_ns_prefix [namespace ] + ['iptables' , '-I' , 'INPUT' , '2' , '-p' , 'udp' , '-m' , 'multiport' , '--dports' , '3784,4784' , '-j' , 'ACCEPT' ])
893895 iptables_cmds .append (self .iptables_cmd_ns_prefix [namespace ] + ['ip6tables' , '-I' , 'INPUT' , '2' , '-p' , 'udp' , '-m' , 'multiport' , '--dports' , '3784,4784' , '-j' , 'ACCEPT' ])
894- self . run_commands ( iptables_cmds )
896+ return iptables_cmds
895897
896- def allow_vxlan_port (self , namespace , data ):
898+ def allow_bfd_protocol (self , namespace ):
899+ iptables_cmds = self .get_bfd_iptable_commands (namespace )
900+ if iptables_cmds :
901+ self .run_commands (iptables_cmds )
902+
903+
904+ def get_vxlan_port_iptable_commands (self , namespace , data ):
905+ iptables_cmds = []
897906 for fv in data :
898907 if (fv [0 ] == "src_ip" ):
899908 self .VxlanSrcIP = fv [1 ]
900909 break
901910
902911 if not self .VxlanSrcIP :
903912 self .log_info ("Received vxlan tunnel configuration without source ip" )
904- return False
905-
906- iptables_cmds = []
913+ return iptables_cmds
907914
908915 # Add iptables/ip6tables commands to allow VxLAN packets
909916 ip_addr = ipaddress .ip_address (self .VxlanSrcIP )
@@ -914,10 +921,15 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
914921 iptables_cmds .append (self .iptables_cmd_ns_prefix [namespace ] +
915922 ['iptables' , '-I' , 'INPUT' , '2' , '-p' , 'udp' , '-d' , self .VxlanSrcIP , '--dport' , '4789' , '-j' , 'ACCEPT' ])
916923
924+ return iptables_cmds
925+
926+ def allow_vxlan_port (self , namespace , data ):
927+ iptables_cmds = self .get_vxlan_port_iptable_commands (namespace , data )
928+ if not iptables_cmds :
929+ return False
917930 self .run_commands (iptables_cmds )
918931 self .log_info ("Enabled vxlan port for source ip " + self .VxlanSrcIP )
919932 self .VxlanAllowed = True
920- return True
921933
922934 def block_vxlan_port (self , namespace ):
923935 if not self .VxlanSrcIP :
0 commit comments