@@ -116,12 +116,14 @@ func (c *nftConnmark) ensureBaseChain(table *nftables.Table) *nftables.Chain {
116116 }
117117 if existing == nil {
118118 priority := c .getDesiredPriority ()
119+ policy := nftables .ChainPolicyAccept
119120 chain := c .nft .AddChain (& nftables.Chain {
120121 Name : nftBaseChainName ,
121122 Table : table ,
122123 Type : nftables .ChainTypeNAT ,
123124 Hooknum : nftables .ChainHookPrerouting ,
124125 Priority : & priority ,
126+ Policy : & policy ,
125127 })
126128 return chain
127129 }
@@ -276,7 +278,9 @@ func (c *nftConnmark) ensureConnmarkChainRules(table *nftables.Table, chain *nft
276278
277279 // Delete unknown rules
278280 for _ , r := range unknownRules {
279- c .nft .DelRule (r )
281+ if err := c .nft .DelRule (r ); err != nil {
282+ log .Errorf ("failed to delete unknown rule: %s, id: %d" , err , r .Handle )
283+ }
280284 }
281285
282286 desiredCIDRs := make (map [string ]bool )
@@ -287,13 +291,20 @@ func (c *nftConnmark) ensureConnmarkChainRules(table *nftables.Table, chain *nft
287291 // Delete stale CIDRs
288292 for cidr , rule := range currentCIDRs {
289293 if ! desiredCIDRs [cidr ] {
290- c .nft .DelRule (rule )
294+ if err := c .nft .DelRule (rule ); err != nil {
295+ log .Errorf ("failed to delete stale cidr rule %s in nf table: %s, id: %d" , cidr , err , rule .Handle )
296+ }
291297 }
292298 }
293299
294300 // Insert missing CIDRs (prepends - order doesn't matter for CIDR rules)
295- for cidr := range desiredCIDRs {
296- if _ , exists := currentCIDRs [cidr ]; ! exists {
301+ for cidrStr := range desiredCIDRs {
302+ if _ , exists := currentCIDRs [cidrStr ]; ! exists {
303+ _ , cidr , err := net .ParseCIDR (cidrStr )
304+ if err != nil {
305+ log .Errorf ("failed to insert cidr %s in nf table: %s" , cidrStr , err )
306+ continue
307+ }
297308 c .insertCIDRReturnRule (table , chain , cidr ) // InsertRule
298309 }
299310 }
@@ -489,11 +500,7 @@ func (c *nftConnmark) addSetMarkRule(table *nftables.Table, chain *nftables.Chai
489500 })
490501}
491502
492- func (c * nftConnmark ) insertCIDRReturnRule (table * nftables.Table , chain * nftables.Chain , cidrStr string ) {
493- _ , cidr , err := net .ParseCIDR (cidrStr )
494- if err != nil {
495- return
496- }
503+ func (c * nftConnmark ) insertCIDRReturnRule (table * nftables.Table , chain * nftables.Chain , cidr * net.IPNet ) {
497504 c .nft .InsertRule (& nftables.Rule {
498505 Table : table ,
499506 Chain : chain ,
0 commit comments