Skip to content
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
8 changes: 8 additions & 0 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,14 @@ def convert_icmp(self, table_name, rule_idx, rule):
is_rule_v6 = True
except Exception as e:
pass
else:
# get the IP version type using IP_PROTOCOL.
try:
ip_protocol = rule.ip.config.protocol
if ip_protocol == "IP_ICMPV6" or int(ip_protocol) == self.ip_protocol_map["IP_ICMPV6"]:
is_rule_v6 = True
except Exception as e:
pass

type_key = "ICMPV6_TYPE" if is_rule_v6 else "ICMP_TYPE"
code_key = "ICMPV6_CODE" if is_rule_v6 else "ICMP_CODE"
Expand Down
44 changes: 43 additions & 1 deletion tests/acl_input/acl1.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
}
}
},
"2": {
"100": {
"config": {
"sequence-id": 100
},
Expand Down Expand Up @@ -285,6 +285,27 @@
}
}
}
},
"2": {
"actions": {
"config": {
"forwarding-action": "ACCEPT"
}
},
"config": {
"sequence-id": 2
},
"ip": {
"config": {
"protocol": "1"
}
},
"icmp": {
"config": {
"type": "136",
"code": "0"
}
}
}
}
},
Expand All @@ -310,6 +331,27 @@
"destination-ip-address": "fc02::/64"
}
}
},
"2": {
"actions": {
"config": {
"forwarding-action": "ACCEPT"
}
},
"config": {
"sequence-id": 2
},
"ip": {
"config": {
"protocol": "58"
}
},
"icmp": {
"config": {
"type": "136",
"code": "0"
}
}
}
}
},
Expand Down
27 changes: 25 additions & 2 deletions tests/acl_loader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def test_icmp_translation(self, acl_loader):
def test_icmpv6_translation(self, acl_loader):
acl_loader.rules_info = {}
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/acl1.json'))
print(acl_loader.rules_info)
assert acl_loader.rules_info[("DATAACL_2", "RULE_1")] == {
"ICMPV6_TYPE": 1,
"ICMPV6_CODE": 0,
Expand All @@ -171,6 +170,30 @@ def test_icmpv6_translation(self, acl_loader):
"PRIORITY": "9900"
}

def test_icmp_translation_in_custom_acl_table_type(self, acl_loader):
acl_loader.rules_info = {}
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/acl1.json'))
assert acl_loader.rules_info[("BMC_ACL_NORTHBOUND", "RULE_2")]
assert acl_loader.rules_info[("BMC_ACL_NORTHBOUND", "RULE_2")] == {
"ICMP_TYPE": 136,
"ICMP_CODE": 0,
"IP_PROTOCOL": 1,
"PACKET_ACTION": "FORWARD",
"PRIORITY": "9998"
}

def test_icmpv6_translation_in_custom_acl_table_type(self, acl_loader):
acl_loader.rules_info = {}
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/acl1.json'))
assert acl_loader.rules_info[("BMC_ACL_NORTHBOUND_V6", "RULE_2")]
assert acl_loader.rules_info[("BMC_ACL_NORTHBOUND_V6", "RULE_2")] == {
"ICMPV6_TYPE": 136,
"ICMPV6_CODE": 0,
"IP_PROTOCOL": 58,
"PACKET_ACTION": "FORWARD",
"PRIORITY": "9998"
}

def test_ingress_default_deny_rule(self, acl_loader):
acl_loader.set_mirror_stage("ingress")
acl_loader.get_session_name = mock.MagicMock(return_value="everflow_session_mock")
Expand Down Expand Up @@ -250,7 +273,7 @@ def ttest_icmp_fields_with_non_icmpv6_protocol(self, acl_loader):
assert not acl_loader.rules_info.get("RULE_1")


def test_icmp_fields_with_non_tcp_protocol(self, acl_loader):
def test_tcp_fields_with_non_tcp_protocol(self, acl_loader):
acl_loader.rules_info = {}
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/tcp_bad_protocol_number.json'))
assert not acl_loader.rules_info.get("RULE_1")
Expand Down