11#!/usr/bin/env python
22
33import click
4+ import ipaddr
45import json
56import syslog
67import tabulate
@@ -253,7 +254,7 @@ def convert_l2(self, table_name, rule_idx, rule):
253254
254255 return rule_props
255256
256- def convert_ipv4 (self , table_name , rule_idx , rule ):
257+ def convert_ip (self , table_name , rule_idx , rule ):
257258 rule_props = {}
258259
259260 if rule .ip .config .protocol :
@@ -269,10 +270,18 @@ def convert_ipv4(self, table_name, rule_idx, rule):
269270 rule_props ["IP_PROTOCOL" ] = rule .ip .config .protocol
270271
271272 if rule .ip .config .source_ip_address :
272- rule_props ["SRC_IP" ] = rule .ip .config .source_ip_address .encode ("ascii" )
273+ source_ip_address = rule .ip .config .source_ip_address .encode ("ascii" )
274+ if ipaddr .IPNetwork (source_ip_address ) == 4 :
275+ rule_props ["SRC_IP" ] = source_ip_address
276+ else :
277+ rule_props ["SRC_IPV6" ] = source_ip_address
273278
274279 if rule .ip .config .destination_ip_address :
275- rule_props ["DST_IP" ] = rule .ip .config .destination_ip_address .encode ("ascii" )
280+ destination_ip_address = rule .ip .config .destination_ip_address .encode ("ascii" )
281+ if ipaddr .IPNetwork (destination_ip_address ) == 4 :
282+ rule_props ["DST_IP" ] = destination_ip_address
283+ else :
284+ rule_props ["DST_IPV6" ] = destination_ip_address
276285
277286 # NOTE: DSCP is available only for MIRROR table
278287 if self .is_table_mirror (table_name ):
@@ -346,7 +355,7 @@ def convert_rule_to_db_schema(self, table_name, rule):
346355
347356 deep_update (rule_props , self .convert_action (table_name , rule_idx , rule ))
348357 deep_update (rule_props , self .convert_l2 (table_name , rule_idx , rule ))
349- deep_update (rule_props , self .convert_ipv4 (table_name , rule_idx , rule ))
358+ deep_update (rule_props , self .convert_ip (table_name , rule_idx , rule ))
350359 deep_update (rule_props , self .convert_transport (table_name , rule_idx , rule ))
351360
352361 return rule_data
0 commit comments