@@ -70,7 +70,13 @@ func ConntrackUpdate(table ConntrackTableType, family InetFamily, flow *Conntrac
7070// ConntrackDeleteFilter deletes entries on the specified table on the base of the filter
7171// conntrack -D [table] parameters Delete conntrack or expectation
7272func ConntrackDeleteFilter (table ConntrackTableType , family InetFamily , filter CustomConntrackFilter ) (uint , error ) {
73- return pkgHandle .ConntrackDeleteFilter (table , family , filter )
73+ return pkgHandle .ConntrackDeleteFilters (table , family , filter )
74+ }
75+
76+ // ConntrackDeleteFilters deletes entries on the specified table matching any of the specified filters
77+ // conntrack -D [table] parameters Delete conntrack or expectation
78+ func ConntrackDeleteFilters (table ConntrackTableType , family InetFamily , filters ... CustomConntrackFilter ) (uint , error ) {
79+ return pkgHandle .ConntrackDeleteFilters (table , family , filters ... )
7480}
7581
7682// ConntrackTableList returns the flow list of a table of a specific family using the netlink handle passed
@@ -133,9 +139,9 @@ func (h *Handle) ConntrackUpdate(table ConntrackTableType, family InetFamily, fl
133139 return err
134140}
135141
136- // ConntrackDeleteFilter deletes entries on the specified table on the base of the filter using the netlink handle passed
142+ // ConntrackDeleteFilters deletes entries on the specified table matching any of the specified filters using the netlink handle passed
137143// conntrack -D [table] parameters Delete conntrack or expectation
138- func (h * Handle ) ConntrackDeleteFilter (table ConntrackTableType , family InetFamily , filter CustomConntrackFilter ) (uint , error ) {
144+ func (h * Handle ) ConntrackDeleteFilters (table ConntrackTableType , family InetFamily , filters ... CustomConntrackFilter ) (uint , error ) {
139145 res , err := h .dumpConntrackTable (table , family )
140146 if err != nil {
141147 return 0 , err
@@ -144,12 +150,16 @@ func (h *Handle) ConntrackDeleteFilter(table ConntrackTableType, family InetFami
144150 var matched uint
145151 for _ , dataRaw := range res {
146152 flow := parseRawData (dataRaw )
147- if match := filter .MatchConntrackFlow (flow ); match {
148- req2 := h .newConntrackRequest (table , family , nl .IPCTNL_MSG_CT_DELETE , unix .NLM_F_ACK )
149- // skip the first 4 byte that are the netfilter header, the newConntrackRequest is adding it already
150- req2 .AddRawData (dataRaw [4 :])
151- req2 .Execute (unix .NETLINK_NETFILTER , 0 )
152- matched ++
153+ for _ , filter := range filters {
154+ if match := filter .MatchConntrackFlow (flow ); match {
155+ req2 := h .newConntrackRequest (table , family , nl .IPCTNL_MSG_CT_DELETE , unix .NLM_F_ACK )
156+ // skip the first 4 byte that are the netfilter header, the newConntrackRequest is adding it already
157+ req2 .AddRawData (dataRaw [4 :])
158+ req2 .Execute (unix .NETLINK_NETFILTER , 0 )
159+ matched ++
160+ // flow is already deleted, no need to match on other filters and continue to the next flow.
161+ break
162+ }
153163 }
154164 }
155165
0 commit comments