@@ -707,7 +707,8 @@ def _TranslatePolicy(self, pol, exp_info):
707
707
filter_policy_default_action ,
708
708
verbose ,
709
709
base_chain_name ,
710
- table_name
710
+ table_name ,
711
+ as_regular_chain ,
711
712
) = self ._ProcessHeader (filter_options )
712
713
713
714
# Base chain determine name based on iteration of header.
@@ -767,7 +768,8 @@ def _TranslatePolicy(self, pol, exp_info):
767
768
pol_counter += 1
768
769
self .nftables_policies .append (
769
770
(header , base_chain_name , nf_af , nf_hook , nf_priority ,
770
- filter_policy_default_action , verbose , child_chains , table_name ))
771
+ filter_policy_default_action , verbose ,
772
+ child_chains , table_name , as_regular_chain ))
771
773
772
774
def _ProcessHeader (self , header_options ):
773
775
"""Capirca policy header processing.
@@ -824,6 +826,7 @@ def _ProcessHeader(self, header_options):
824
826
base_chain_name = option .split ('=' )[1 ].strip ()
825
827
if option .startswith ('table_name=' ):
826
828
table_name = option .split ('=' )[1 ].strip ()
829
+ as_regular_chain = True if 'as_regular_chain' in header_options else False
827
830
return (
828
831
netfilter_family ,
829
832
netfilter_hook ,
@@ -832,6 +835,7 @@ def _ProcessHeader(self, header_options):
832
835
verbose ,
833
836
base_chain_name ,
834
837
table_name ,
838
+ as_regular_chain ,
835
839
)
836
840
837
841
def _ConfigurationDictionary (self , nft_pol ):
@@ -857,6 +861,7 @@ def _ConfigurationDictionary(self, nft_pol):
857
861
verbose ,
858
862
child_chains ,
859
863
table_name ,
864
+ as_regular_chain ,
860
865
) in nft_pol :
861
866
base_chain_comment = ''
862
867
# TODO: If child_chain ruleset is empty don't store term.
@@ -870,6 +875,7 @@ def _ConfigurationDictionary(self, nft_pol):
870
875
'priority' : nf_priority ,
871
876
'policy' : filter_policy_default_action ,
872
877
'rules' : child_chains ,
878
+ 'as_regular_chain' : as_regular_chain ,
873
879
}
874
880
return nftables
875
881
@@ -898,12 +904,13 @@ def __str__(self):
898
904
# First time we comment it out so .nft file is human-readable.
899
905
nft_config .append (
900
906
TabSpacer (8 , '#' + ' ' .join (base_chain_dict [item ]['comment' ])))
901
- nft_config .append (
902
- TabSpacer (
903
- 8 , 'type filter hook %s priority %s; policy %s;' %
904
- (base_chain_dict [item ]['hook' ],
905
- base_chain_dict [item ]['priority' ],
906
- base_chain_dict [item ]['policy' ])))
907
+ if not base_chain_dict [item ]['as_regular_chain' ]:
908
+ nft_config .append (
909
+ TabSpacer (
910
+ 8 , 'type filter hook %s priority %s; policy %s;' %
911
+ (base_chain_dict [item ]['hook' ],
912
+ base_chain_dict [item ]['priority' ],
913
+ base_chain_dict [item ]['policy' ])))
907
914
# Add policy header comment after stateful firewall rule.
908
915
if base_chain_dict [item ]['comment' ]:
909
916
nft_config .append (TabSpacer (8 , 'ct state established,related accept'
0 commit comments