Skip to content

Commit e94450b

Browse files
committed
[caclmgrd]Added logic to allow BFD port numbers
1 parent 243d0c7 commit e94450b

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/sonic-host-services/scripts/caclmgrd

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
5959

6060
ACL_TABLE_TYPE_CTRLPLANE = "CTRLPLANE"
6161

62+
BFD_SESSION_TABLE = "BFD_SESSION_TABLE"
63+
6264
# To specify a port range instead of a single port, use iptables format:
6365
# separate start and end ports with a colon, e.g., "1000:2000"
6466
ACL_SERVICES = {
@@ -87,6 +89,7 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
8789
UPDATE_DELAY_SECS = 0.5
8890

8991
DualToR = False
92+
bfdAllowed = False
9093

9194
def __init__(self, log_identifier):
9295
super(ControlPlaneAclManager, self).__init__(log_identifier)
@@ -170,6 +173,7 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
170173
self.log_error("Error running command '{}'".format(cmd))
171174
elif stdout:
172175
return stdout.rstrip('\n')
176+
return ""
173177

174178
def parse_int_to_tcp_flags(self, hex_value):
175179
tcp_flags_str = ""
@@ -705,6 +709,13 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
705709
self.update_thread[namespace] = None
706710
return
707711

712+
def allow_bfd_protocol(self, namespace):
713+
iptables_cmds = []
714+
# Add iptables/ip6tables commands to allow all BFD singlehop and multihop sessions
715+
iptables_cmds.append(self.iptables_cmd_ns_prefix[namespace] + "iptables -I INPUT 2 -p udp -m multiport --dports 3784,4784 -j ACCEPT")
716+
iptables_cmds.append(self.iptables_cmd_ns_prefix[namespace] + "ip6tables -I INPUT 2 -p udp -m multiport --dports 3784,4784 -j ACCEPT")
717+
self.run_commands(iptables_cmds)
718+
708719
def run(self):
709720
# Set select timeout to 1 second
710721
SELECT_TIMEOUT_MS = 1000
@@ -730,12 +741,12 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
730741
state_db_id = swsscommon.SonicDBConfig.getDbId("STATE_DB")
731742
dhcp_packet_mark_tbl = {}
732743

744+
# set up state_db connector
745+
state_db_connector = swsscommon.DBConnector("STATE_DB", 0)
746+
733747
if self.DualToR:
734748
self.log_info("Dual ToR mode")
735749

736-
# set up state_db connector
737-
state_db_connector = swsscommon.DBConnector("STATE_DB", 0)
738-
739750
subscribe_mux_cable = swsscommon.SubscriberStateTable(state_db_connector, self.MUX_CABLE_TABLE)
740751
sel.addSelectable(subscribe_mux_cable)
741752

@@ -746,6 +757,10 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
746757
for namespace in list(self.config_db_map.keys()):
747758
self.setup_dhcp_chain(namespace)
748759

760+
# This should be migrated from state_db BFD session table to feature_table in the future when feature table support gets added for BFD
761+
subscribe_bfd_session = swsscommon.SubscriberStateTable(state_db_connector, self.BFD_SESSION_TABLE)
762+
sel.addSelectable(subscribe_bfd_session)
763+
749764
# Map of Namespace <--> susbcriber table's object
750765
config_db_subscriber_table_map = {}
751766

@@ -785,6 +800,17 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
785800
db_id = redisSelectObj.getDbConnector().getDbId()
786801

787802
if db_id == state_db_id:
803+
while True:
804+
key, op, fvs = subscribe_bfd_session.pop()
805+
if not key:
806+
break
807+
808+
print(key)
809+
if op == 'SET' and not self.bfdAllowed:
810+
self.allow_bfd_protocol(namespace)
811+
self.bfdAllowed = True
812+
sel.removeSelectable(subscribe_bfd_session)
813+
788814
if self.DualToR:
789815
'''dhcp packet mark update'''
790816
while True:

0 commit comments

Comments
 (0)