Skip to content

Commit

Permalink
[acl_loader]: Add support for IPv6 field match (sonic-net#377)
Browse files Browse the repository at this point in the history
import ipaddr package and check if the ip address is ipv4 or ipv6
and set the corresponding rule properties

Signed-off-by: Shu0T1an ChenG <shuche@microsoft.com>
  • Loading branch information
Shuotian Cheng authored and lguohan committed Nov 11, 2018
1 parent f3bb9bd commit c25fd0a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import click
import ipaddr
import json
import syslog
import tabulate
Expand Down Expand Up @@ -253,7 +254,7 @@ def convert_l2(self, table_name, rule_idx, rule):

return rule_props

def convert_ipv4(self, table_name, rule_idx, rule):
def convert_ip(self, table_name, rule_idx, rule):
rule_props = {}

if rule.ip.config.protocol:
Expand All @@ -269,10 +270,18 @@ def convert_ipv4(self, table_name, rule_idx, rule):
rule_props["IP_PROTOCOL"] = rule.ip.config.protocol

if rule.ip.config.source_ip_address:
rule_props["SRC_IP"] = rule.ip.config.source_ip_address.encode("ascii")
source_ip_address = rule.ip.config.source_ip_address.encode("ascii")
if ipaddr.IPNetwork(source_ip_address) == 4:
rule_props["SRC_IP"] = source_ip_address
else:
rule_props["SRC_IPV6"] = source_ip_address

if rule.ip.config.destination_ip_address:
rule_props["DST_IP"] = rule.ip.config.destination_ip_address.encode("ascii")
destination_ip_address = rule.ip.config.destination_ip_address.encode("ascii")
if ipaddr.IPNetwork(destination_ip_address) == 4:
rule_props["DST_IP"] = destination_ip_address
else:
rule_props["DST_IPV6"] = destination_ip_address

# NOTE: DSCP is available only for MIRROR table
if self.is_table_mirror(table_name):
Expand Down Expand Up @@ -346,7 +355,7 @@ def convert_rule_to_db_schema(self, table_name, rule):

deep_update(rule_props, self.convert_action(table_name, rule_idx, rule))
deep_update(rule_props, self.convert_l2(table_name, rule_idx, rule))
deep_update(rule_props, self.convert_ipv4(table_name, rule_idx, rule))
deep_update(rule_props, self.convert_ip(table_name, rule_idx, rule))
deep_update(rule_props, self.convert_transport(table_name, rule_idx, rule))

return rule_data
Expand Down

0 comments on commit c25fd0a

Please sign in to comment.