@@ -318,6 +318,7 @@ class Term:
318
318
dscp-except: VarType.DSCP_EXCEPT
319
319
comments: VarType.COMMENT
320
320
encapsulate: VarType.ENCAPSULATE
321
+ filter-term: VarType.FILTER_TERM
321
322
flexible-match-range: VarType.FLEXIBLE_MATCH_RANGE
322
323
forwarding-class: VarType.FORWARDING_CLASS
323
324
forwarding-class-except: VarType.FORWARDING_CLASS_EXCEPT
@@ -411,6 +412,7 @@ def __init__(self, obj):
411
412
self .destination_address_exclude = []
412
413
self .destination_port = []
413
414
self .destination_prefix = []
415
+ self .filter_term = None
414
416
self .forwarding_class = []
415
417
self .forwarding_class_except = []
416
418
self .logging = []
@@ -709,6 +711,8 @@ def __str__(self):
709
711
if self .destination_prefix_except :
710
712
ret_str .append (' destination_prefix_except: %s' %
711
713
self .destination_prefix_except )
714
+ if self .filter_term :
715
+ ret_str .append (' filter_term: %s' % self .filter_term )
712
716
if self .forwarding_class :
713
717
ret_str .append (' forwarding_class: %s' % self .forwarding_class )
714
718
if self .forwarding_class_except :
@@ -896,6 +900,10 @@ def __eq__(self, other):
896
900
if self .precedence != other .precedence :
897
901
return False
898
902
903
+ # filter
904
+ if self .filter_term != other .filter_term :
905
+ return False
906
+
899
907
# forwarding-class
900
908
if sorted (self .forwarding_class ) != sorted (other .forwarding_class ):
901
909
return False
@@ -1193,6 +1201,8 @@ def AddObject(self, obj):
1193
1201
self .target_resources .append (obj .value )
1194
1202
elif obj .var_type is VarType .TARGET_SERVICE_ACCOUNTS :
1195
1203
self .target_service_accounts .append (obj .value )
1204
+ elif obj .var_type is VarType .FILTER_TERM :
1205
+ self .filter_term = obj .value
1196
1206
else :
1197
1207
raise TermObjectTypeError (
1198
1208
'%s isn\' t a type I know how to deal with' % (type (obj )))
@@ -1226,8 +1236,11 @@ def SanityCheck(self):
1226
1236
raise ParseError (
1227
1237
'term "%s" has both verbatim and non-verbatim tokens.' % self .name )
1228
1238
else :
1229
- if not self .action and not self .routing_instance and not self .next_ip and not self .encapsulate :
1239
+ if (not self .action and not self .routing_instance and not self .next_ip and
1240
+ not self .encapsulate and not self .filter_term ):
1230
1241
raise TermNoActionError ('no action specified for term %s' % self .name )
1242
+ if self .filter_term and self .action :
1243
+ raise InvalidTermActionError ('term "%s" has both filter and action tokens.' % self .name )
1231
1244
# have we specified a port with a protocol that doesn't support ports?
1232
1245
if self .source_port or self .destination_port or self .port :
1233
1246
if not any (proto in self .protocol for proto in ['tcp' , 'udp' , 'sctp' ]):
@@ -1497,8 +1510,10 @@ class VarType:
1497
1510
TARGET_RESOURCES = 59
1498
1511
TARGET_SERVICE_ACCOUNTS = 60
1499
1512
ENCAPSULATE = 61
1513
+ FILTER_TERM = 62
1500
1514
RESTRICT_ADDRESS_FAMILY = 63
1501
1515
1516
+
1502
1517
def __init__ (self , var_type , value ):
1503
1518
self .var_type = var_type
1504
1519
if self .var_type == self .COMMENT or self .var_type == self .LOG_NAME :
@@ -1675,6 +1690,7 @@ def __ne__(self, other):
1675
1690
'ESCAPEDSTRING' ,
1676
1691
'ETHER_TYPE' ,
1677
1692
'EXPIRATION' ,
1693
+ 'FILTER_TERM' ,
1678
1694
'FLEXIBLE_MATCH_RANGE' ,
1679
1695
'FORWARDING_CLASS' ,
1680
1696
'FORWARDING_CLASS_EXCEPT' ,
@@ -1757,6 +1773,7 @@ def __ne__(self, other):
1757
1773
'encapsulate' : 'ENCAPSULATE' ,
1758
1774
'ether-type' : 'ETHER_TYPE' ,
1759
1775
'expiration' : 'EXPIRATION' ,
1776
+ 'filter-term' : 'FILTER_TERM' ,
1760
1777
'flexible-match-range' : 'FLEXIBLE_MATCH_RANGE' ,
1761
1778
'forwarding-class' : 'FORWARDING_CLASS' ,
1762
1779
'forwarding-class-except' : 'FORWARDING_CLASS_EXCEPT' ,
@@ -1939,6 +1956,7 @@ def p_term_spec(p):
1939
1956
| term_spec ether_type_spec
1940
1957
| term_spec exclude_spec
1941
1958
| term_spec expiration_spec
1959
+ | term_spec filter_term_spec
1942
1960
| term_spec flexible_match_range_spec
1943
1961
| term_spec forwarding_class_spec
1944
1962
| term_spec forwarding_class_except_spec
@@ -2380,6 +2398,9 @@ def p_ttl_spec(p):
2380
2398
""" ttl_spec : TTL ':' ':' INTEGER """
2381
2399
p [0 ] = VarType (VarType .TTL , p [4 ])
2382
2400
2401
+ def p_filter_term_spec (p ):
2402
+ """ filter_term_spec : FILTER_TERM ':' ':' STRING """
2403
+ p [0 ] = VarType (VarType .FILTER_TERM , p [4 ])
2383
2404
2384
2405
def p_one_or_more_strings (p ):
2385
2406
""" one_or_more_strings : one_or_more_strings STRING
0 commit comments