diff --git a/files/image_config/caclmgrd/caclmgrd b/files/image_config/caclmgrd/caclmgrd index adf4431b3f75..b0963e3db0d7 100755 --- a/files/image_config/caclmgrd/caclmgrd +++ b/files/image_config/caclmgrd/caclmgrd @@ -16,6 +16,7 @@ try: import subprocess import sys import syslog + import sonic_device_util from swsscommon import swsscommon from swsssdk import SonicDBConfig, ConfigDBConnector @@ -448,28 +449,41 @@ class ControlPlaneAclManager(object): def run(self): # Select Time-out for 10 Seconds SELECT_TIMEOUT_MS = 1000 * 10 + # Initlaize Global config that loads all database*.json swsscommon.SonicDBConfig.initializeGlobalConfig() + # Create the Select object sel = swsscommon.Select() + # Map of Namespace <--> susbcriber table's object config_db_subscriber_table_map = {} + # Loop through all asic namespaces (if present) and host (namespace='') for namespace in self.config_db_map.keys(): - # Unconditionally update control plane ACLs once at start + # Unconditionally update control plane ACLs once at start on given namespace self.update_control_plane_acls(namespace) - + # Connect to Config DB of given namespace acl_db_connector = swsscommon.DBConnector("CONFIG_DB", 0, False, namespace) + # Subscribe to notifications when ACL tables changes subscribe_acl_table = swsscommon.SubscriberStateTable(acl_db_connector, swsscommon.CFG_ACL_TABLE_TABLE_NAME) + # Subscribe to notifications when ACL rule tables changes subscribe_acl_rule_table = swsscommon.SubscriberStateTable(acl_db_connector, swsscommon.CFG_ACL_RULE_TABLE_NAME) + # Add both tables to the selectable object sel.addSelectable(subscribe_acl_table) sel.addSelectable(subscribe_acl_rule_table) + # Update the map config_db_subscriber_table_map[namespace] = [] config_db_subscriber_table_map[namespace].append(subscribe_acl_table) config_db_subscriber_table_map[namespace].append(subscribe_acl_rule_table) + #Loop on select to see if any event happen on config db of any namespace while True: (state, c) = sel.select(SELECT_TIMEOUT_MS) + # Continue if select is timeout or selectable object is not return if state != swsscommon.Select.OBJECT: continue + # Get the corresponding namespace from selectable object namespace = c.getDbNamespace() + # Pop data of both Subscriber Table object of namespace that got config db acl table event for table in config_db_subscriber_table_map[namespace]: table.pop() + # Update the Control Plane ACL of the namespace that got config db acl table event self.update_control_plane_acls(namespace) # ============================= Functions =============================