Skip to content

Commit b1ce50c

Browse files
aroradamanaboch
authored andcommitted
capture and return errors in ConntrackDeleteFilters
Signed-off-by: Daman Arora <[email protected]>
1 parent e194da5 commit b1ce50c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

conntrack_linux.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"net"
9+
"strings"
910
"time"
1011

1112
"github.com/vishvananda/netlink/nl"
@@ -158,21 +159,26 @@ func (h *Handle) ConntrackDeleteFilters(table ConntrackTableType, family InetFam
158159
}
159160

160161
var matched uint
162+
var errMsgs []string
161163
for _, dataRaw := range res {
162164
flow := parseRawData(dataRaw)
163165
for _, filter := range filters {
164166
if match := filter.MatchConntrackFlow(flow); match {
165167
req2 := h.newConntrackRequest(table, family, nl.IPCTNL_MSG_CT_DELETE, unix.NLM_F_ACK)
166168
// skip the first 4 byte that are the netfilter header, the newConntrackRequest is adding it already
167169
req2.AddRawData(dataRaw[4:])
168-
req2.Execute(unix.NETLINK_NETFILTER, 0)
169-
matched++
170-
// flow is already deleted, no need to match on other filters and continue to the next flow.
171-
break
170+
if _, err = req2.Execute(unix.NETLINK_NETFILTER, 0); err == nil {
171+
matched++
172+
// flow is already deleted, no need to match on other filters and continue to the next flow.
173+
break
174+
}
175+
errMsgs = append(errMsgs, fmt.Sprintf("failed to delete conntrack flow '%s': %s", flow.String(), err.Error()))
172176
}
173177
}
174178
}
175-
179+
if len(errMsgs) > 0 {
180+
return matched, fmt.Errorf(strings.Join(errMsgs, "; "))
181+
}
176182
return matched, nil
177183
}
178184

0 commit comments

Comments
 (0)