Skip to content

Commit 1c6c9d1

Browse files
Merge branch 'master' into pm_cli_adv
2 parents 994427a + c57bf81 commit 1c6c9d1

File tree

170 files changed

+1599659
-2706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+1599659
-2706
lines changed

.github/workflows/semgrep.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
- uses: actions/checkout@v3
1919
- run: semgrep ci
2020
env:
21-
SEMGREP_RULES: p/default
21+
SEMGREP_RULES: "p/default r/python.lang.security.audit.dangerous-system-call-audit.dangerous-system-call-audit"

acl_loader/main.py

+50-12
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,31 @@ def read_tables_info(self):
173173
Read ACL_TABLE table from configuration database
174174
:return:
175175
"""
176-
self.tables_db_info = self.configdb.get_table(self.ACL_TABLE)
176+
# get the acl table info from host config_db
177+
host_acl_table = self.configdb.get_table(self.ACL_TABLE)
178+
# For multi asic get only the control plane acls from the host config_db
179+
if self.per_npu_configdb:
180+
for table, entry in host_acl_table.items():
181+
if entry.get('type', None) != self.ACL_TABLE_TYPE_CTRLPLANE:
182+
continue
183+
184+
self.tables_db_info[table] = entry
185+
else:
186+
self.tables_db_info.update(host_acl_table)
187+
188+
# for DATAACL, EVERFLOW acls.
189+
# update the ports from all the namespaces
190+
if self.per_npu_configdb:
191+
for ns, config_db in self.per_npu_configdb.items():
192+
acl_table = config_db.get_table(self.ACL_TABLE)
193+
for table, entry in acl_table.items():
194+
if entry.get('type', None) == self.ACL_TABLE_TYPE_CTRLPLANE:
195+
continue
196+
if table not in self.tables_db_info:
197+
self.tables_db_info[table] = entry
198+
else:
199+
self.tables_db_info[table]['ports'] += entry.get(
200+
'ports', [])
177201

178202
def get_tables_db_info(self):
179203
return self.tables_db_info
@@ -389,17 +413,17 @@ def parse_acl_json(filename):
389413
raise AclLoaderException("Invalid input file %s" % filename)
390414
return yang_acl
391415

392-
def load_rules_from_file(self, filename):
416+
def load_rules_from_file(self, filename, skip_action_validation=False):
393417
"""
394418
Load file with ACL rules configuration in openconfig ACL format. Convert rules
395419
to Config DB schema.
396420
:param filename: File in openconfig ACL format
397421
:return:
398422
"""
399423
self.yang_acl = AclLoader.parse_acl_json(filename)
400-
self.convert_rules()
424+
self.convert_rules(skip_action_validation)
401425

402-
def convert_action(self, table_name, rule_idx, rule):
426+
def convert_action(self, table_name, rule_idx, rule, skip_validation=False):
403427
rule_props = {}
404428

405429
if rule.actions.config.forwarding_action == "ACCEPT":
@@ -428,13 +452,13 @@ def convert_action(self, table_name, rule_idx, rule):
428452
raise AclLoaderException("Unknown rule action {} in table {}, rule {}".format(
429453
rule.actions.config.forwarding_action, table_name, rule_idx))
430454

431-
if not self.validate_actions(table_name, rule_props):
455+
if not self.validate_actions(table_name, rule_props, skip_validation):
432456
raise AclLoaderException("Rule action {} is not supported in table {}, rule {}".format(
433457
rule.actions.config.forwarding_action, table_name, rule_idx))
434458

435459
return rule_props
436460

437-
def validate_actions(self, table_name, action_props):
461+
def validate_actions(self, table_name, action_props, skip_validation=False):
438462
if self.is_table_control_plane(table_name):
439463
return True
440464

@@ -457,6 +481,11 @@ def validate_actions(self, table_name, action_props):
457481
else:
458482
aclcapability = self.statedb.get_all(self.statedb.STATE_DB, "{}|{}".format(self.ACL_STAGE_CAPABILITY_TABLE, stage.upper()))
459483
switchcapability = self.statedb.get_all(self.statedb.STATE_DB, "{}|switch".format(self.SWITCH_CAPABILITY_TABLE))
484+
# In the load_minigraph path, it's possible that the STATE_DB entry haven't pop up because orchagent is stopped
485+
# before loading acl.json. So we skip the validation if any table is empty
486+
if skip_validation and (not aclcapability or not switchcapability):
487+
warning("Skipped action validation as capability table is not present in STATE_DB")
488+
return True
460489
for action_key in dict(action_props):
461490
action_list_key = self.ACL_ACTIONS_CAPABILITY_FIELD
462491
if action_list_key not in aclcapability:
@@ -574,6 +603,14 @@ def convert_icmp(self, table_name, rule_idx, rule):
574603
is_rule_v6 = True
575604
except Exception as e:
576605
pass
606+
else:
607+
# get the IP version type using IP_PROTOCOL.
608+
try:
609+
ip_protocol = rule.ip.config.protocol
610+
if ip_protocol == "IP_ICMPV6" or int(ip_protocol) == self.ip_protocol_map["IP_ICMPV6"]:
611+
is_rule_v6 = True
612+
except Exception as e:
613+
pass
577614

578615
type_key = "ICMPV6_TYPE" if is_rule_v6 else "ICMP_TYPE"
579616
code_key = "ICMPV6_CODE" if is_rule_v6 else "ICMP_CODE"
@@ -667,7 +704,7 @@ def validate_rule_fields(self, rule_props):
667704
if ("ICMPV6_TYPE" in rule_props or "ICMPV6_CODE" in rule_props) and protocol != 58:
668705
raise AclLoaderException("IP_PROTOCOL={} is not ICMPV6, but ICMPV6 fields were provided".format(protocol))
669706

670-
def convert_rule_to_db_schema(self, table_name, rule):
707+
def convert_rule_to_db_schema(self, table_name, rule, skip_action_validation=False):
671708
"""
672709
Convert rules format from openconfig ACL to Config DB schema
673710
:param table_name: ACL table name to which rule belong
@@ -697,7 +734,7 @@ def convert_rule_to_db_schema(self, table_name, rule):
697734
elif self.is_table_l3(table_name):
698735
rule_props["ETHER_TYPE"] = str(self.ethertype_map["ETHERTYPE_IPV4"])
699736

700-
deep_update(rule_props, self.convert_action(table_name, rule_idx, rule))
737+
deep_update(rule_props, self.convert_action(table_name, rule_idx, rule, skip_action_validation))
701738
deep_update(rule_props, self.convert_l2(table_name, rule_idx, rule))
702739
deep_update(rule_props, self.convert_ip(table_name, rule_idx, rule))
703740
deep_update(rule_props, self.convert_icmp(table_name, rule_idx, rule))
@@ -729,7 +766,7 @@ def deny_rule(self, table_name):
729766
return {} # Don't add default deny rule if table is not [L3, L3V6]
730767
return rule_data
731768

732-
def convert_rules(self):
769+
def convert_rules(self, skip_aciton_validation=False):
733770
"""
734771
Convert rules in openconfig ACL format to Config DB schema
735772
:return:
@@ -748,7 +785,7 @@ def convert_rules(self):
748785
for acl_entry_name in acl_set.acl_entries.acl_entry:
749786
acl_entry = acl_set.acl_entries.acl_entry[acl_entry_name]
750787
try:
751-
rule = self.convert_rule_to_db_schema(table_name, acl_entry)
788+
rule = self.convert_rule_to_db_schema(table_name, acl_entry, skip_aciton_validation)
752789
deep_update(self.rules_info, rule)
753790
except AclLoaderException as ex:
754791
error("Error processing rule %s: %s. Skipped." % (acl_entry_name, ex))
@@ -1117,8 +1154,9 @@ def update(ctx):
11171154
@click.option('--session_name', type=click.STRING, required=False)
11181155
@click.option('--mirror_stage', type=click.Choice(["ingress", "egress"]), default="ingress")
11191156
@click.option('--max_priority', type=click.INT, required=False)
1157+
@click.option('--skip_action_validation', is_flag=True, default=False, help="Skip action validation")
11201158
@click.pass_context
1121-
def full(ctx, filename, table_name, session_name, mirror_stage, max_priority):
1159+
def full(ctx, filename, table_name, session_name, mirror_stage, max_priority, skip_action_validation):
11221160
"""
11231161
Full update of ACL rules configuration.
11241162
If a table_name is provided, the operation will be restricted in the specified table.
@@ -1136,7 +1174,7 @@ def full(ctx, filename, table_name, session_name, mirror_stage, max_priority):
11361174
if max_priority:
11371175
acl_loader.set_max_priority(max_priority)
11381176

1139-
acl_loader.load_rules_from_file(filename)
1177+
acl_loader.load_rules_from_file(filename, skip_action_validation)
11401178
acl_loader.full_update()
11411179

11421180

azure-pipelines.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ resources:
1313
name: sonic-net/sonic-swss
1414
endpoint: sonic-net
1515

16+
variables:
17+
- name: BUILD_BRANCH
18+
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
19+
value: $(System.PullRequest.TargetBranch)
20+
${{ else }}:
21+
value: $(Build.SourceBranchName)
22+
1623
stages:
1724
- stage: Build
1825

@@ -26,7 +33,7 @@ stages:
2633
vmImage: ubuntu-20.04
2734

2835
container:
29-
image: sonicdev-microsoft.azurecr.io:443/sonic-slave-bullseye:latest
36+
image: sonicdev-microsoft.azurecr.io:443/sonic-slave-bullseye:$(BUILD_BRANCH)
3037

3138
steps:
3239
- script: |
@@ -52,12 +59,11 @@ stages:
5259

5360
- script: |
5461
set -xe
55-
sudo apt-get -y purge libhiredis-dev libnl-3-dev libnl-route-3-dev || true
62+
sudo apt-get -y purge libnl-3-dev libnl-route-3-dev || true
5663
sudo dpkg -i libnl-3-200_*.deb
5764
sudo dpkg -i libnl-genl-3-200_*.deb
5865
sudo dpkg -i libnl-route-3-200_*.deb
5966
sudo dpkg -i libnl-nf-3-200_*.deb
60-
sudo dpkg -i libhiredis0.14_*.deb
6167
sudo dpkg -i libyang_1.0.73_amd64.deb
6268
sudo dpkg -i libyang-cpp_1.0.73_amd64.deb
6369
sudo dpkg -i python3-yang_1.0.73_amd64.deb

clear/main.py

+15
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,21 @@ def queuecounters():
181181
command = ["queuestat", "-c"]
182182
run_command(command)
183183

184+
command = ["queuestat", "-c", "--voq"]
185+
run_command(command)
186+
187+
@cli.command()
188+
def fabriccountersqueue():
189+
"""Clear fabric queue counters"""
190+
command = ["fabricstat", "-C", "-q"]
191+
run_command(command)
192+
193+
@cli.command()
194+
def fabriccountersport():
195+
"""Clear fabric port counters"""
196+
command = ["fabricstat", "-C"]
197+
run_command(command)
198+
184199
@cli.command()
185200
def pfccounters():
186201
"""Clear pfc counters"""

config/fabric.py

+33
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,39 @@ def error_threshold(crccells, rxcells, namespace):
157157
config_db.mod_entry("FABRIC_MONITOR", "FABRIC_MONITOR_DATA",
158158
{'monErrThreshCrcCells': crccells, 'monErrThreshRxCells': rxcells})
159159

160+
def setFabricPortMonitorState(state, namespace, ctx):
161+
""" set the fabric port monitor state"""
162+
# Connect to config database
163+
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
164+
config_db.connect()
165+
166+
# Make sure configuration data exists
167+
monitorData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_MONITOR|FABRIC_MONITOR_DATA")
168+
if not bool(monitorData):
169+
ctx.fail("Fabric monitor configuration data not present")
170+
171+
# Update entry
172+
config_db.mod_entry("FABRIC_MONITOR", "FABRIC_MONITOR_DATA",
173+
{'monState': state})
174+
175+
#
176+
# 'config fabric port montior state <enable/disable>'
177+
#
178+
@monitor.command()
179+
@click.argument('state', metavar='<state>', required=True)
180+
@multi_asic_util.multi_asic_click_option_namespace
181+
def state(state, namespace):
182+
"""FABRIC PORT MONITOR STATE configuration tasks"""
183+
ctx = click.get_current_context()
184+
185+
n_asics = multi_asic.get_num_asics()
186+
if n_asics > 1 and namespace is None:
187+
ns_list = multi_asic.get_namespace_list()
188+
for namespace in ns_list:
189+
setFabricPortMonitorState(state, namespace, ctx)
190+
else:
191+
setFabricPortMonitorState(state, namespace, ctx)
192+
160193
#
161194
# 'config fabric port monitor poll ...'
162195
#

0 commit comments

Comments
 (0)