Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[acl] Add default deny rule for l3 table #734

Merged
merged 2 commits into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/sonic-config-engine/tests/sample_output/rules_for_dataacl.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"ACL_RULE_TABLE:dataacl:Rule_1":{
"ACL_RULE_TABLE:DATAACL:RULE_1":{
"IP_PROTOCOL":17,
"PACKET_ACTION":"FORWARD",
"SRC_IP":"10.0.0.0/8",
Expand All @@ -9,7 +9,7 @@
"OP":"SET"
},
{
"ACL_RULE_TABLE:dataacl:Rule_3":{
"ACL_RULE_TABLE:DATAACL:RULE_3":{
"IP_PROTOCOL":17,
"PACKET_ACTION":"FORWARD",
"SRC_IP":"25.0.0.0/8",
Expand All @@ -18,7 +18,7 @@
"OP":"SET"
},
{
"ACL_RULE_TABLE:dataacl:Rule_2":{
"ACL_RULE_TABLE:DATAACL:RULE_2":{
"IP_PROTOCOL":17,
"PACKET_ACTION":"FORWARD",
"SRC_IP":"100.64.0.0/10",
Expand All @@ -27,12 +27,20 @@
"OP":"SET"
},
{
"ACL_RULE_TABLE:dataacl:Rule_4":{
"ACL_RULE_TABLE:DATAACL:RULE_4":{
"IP_PROTOCOL":6,
"PACKET_ACTION":"FORWARD",
"TCP_FLAGS":"0x10/0x10",
"priority":9996
},
"OP":"SET"
},
{
"ACL_RULE_TABLE:DATAACL:DEFAULT_RULE":{
"ETHER_TYPE":"0x0800",
"PACKET_ACTION":"DROP",
"priority":1
},
"OP":"SET"
}
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"ACL_RULE_TABLE:everflow:Rule_1":{
"ACL_RULE_TABLE:EVERFLOW:RULE_1":{
"DST_IP":"127.0.0.1/32",
"IP_PROTOCOL":6,
"L4_DST_PORT":0,
Expand Down
15 changes: 13 additions & 2 deletions src/sonic-config-engine/translate_acl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ def dump_json(filename, data):
with open(filename, 'w') as outfile:
json.dump(data, outfile, indent=4, sort_keys=True, separators=(',', ':'))

def default_deny_rule(table_name):
rule_props = {}
rule_data = {}
rule_data["ACL_RULE_TABLE:"+table_name.upper()+":DEFAULT_RULE"] = rule_props
rule_data["OP"] = "SET"
rule_props["priority"] = 1
rule_props["ETHER_TYPE"] = "0x0800"
rule_props["PACKET_ACTION"] = "DROP"
return rule_data

def generate_rule_json(table_name, rule, max_priority, mirror):
rule_idx = rule.config.sequence_id
rule_props = {}
rule_data = {}
rule_data["ACL_RULE_TABLE:"+table_name+":Rule_"+str(rule_idx)] = rule_props
rule_data["ACL_RULE_TABLE:"+table_name.upper()+":RULE_"+str(rule_idx)] = rule_props
rule_data["OP"] = "SET"

rule_props["priority"] = max_priority - rule_idx
Expand Down Expand Up @@ -120,7 +130,8 @@ def generate_table_json(aclset, aclname, ports, mirror, max_priority, output_pat
rule_props = generate_rule_json(table_name, aclentry, max_priority, mirror)
if rule_props:
rule_data.append(rule_props)

if not mirror:
rule_data.append(default_deny_rule(table_name))
dump_json(os.path.join(output_path, "rules_for_"+table_name+".json"), rule_data)

def translate_acl_fixed_port(filename, output_path, port, max_priority):
Expand Down