Skip to content

Commit c0d46dc

Browse files
milan-zededati-mo
authored andcommitted
Fix Conn.Get to correctly set IP family for partial IPv6 filters
Conn.Get supports filters with only one of TupleOrig or TupleReply defined. However, when using such a partial filter with IPv6 addresses, the function failed to set the correct IP family (ProtoIPv6) in the netfilter header, resulting in the error: netfilter query: netlink receive: invalid argument This change updates the condition to set the protocol family to IPv6 if either TupleOrig or TupleReply uses an IPv6 address. Signed-off-by: Milan Lenco <milan@zededa.com>
1 parent 9deed04 commit c0d46dc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func (c *Conn) Get(f Flow) (Flow, error) {
382382
}
383383

384384
pf := netfilter.ProtoIPv4
385-
if f.TupleOrig.IP.IsIPv6() && f.TupleReply.IP.IsIPv6() {
385+
if f.TupleOrig.IP.IsIPv6() || f.TupleReply.IP.IsIPv6() {
386386
pf = netfilter.ProtoIPv6
387387
}
388388

flow_integration_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,22 @@ func TestConnCreateGetFlow(t *testing.T) {
298298

299299
assert.Equal(t, qflow.TupleOrig.IP.SourceAddress, f.TupleOrig.IP.SourceAddress)
300300
assert.Equal(t, qflow.TupleOrig.IP.DestinationAddress, f.TupleOrig.IP.DestinationAddress)
301+
302+
fOrig := f
303+
fOrig.TupleReply = Tuple{}
304+
qflow, err = c.Get(fOrig)
305+
require.NoError(t, err, "get flow by TupleOrig", n)
306+
307+
assert.Equal(t, qflow.TupleReply.IP.SourceAddress, f.TupleReply.IP.SourceAddress)
308+
assert.Equal(t, qflow.TupleReply.IP.DestinationAddress, f.TupleReply.IP.DestinationAddress)
309+
310+
fReply := f
311+
fReply.TupleOrig = Tuple{}
312+
qflow, err = c.Get(fReply)
313+
require.NoError(t, err, "get flow by TupleReply", n)
314+
315+
assert.Equal(t, qflow.TupleOrig.IP.SourceAddress, f.TupleOrig.IP.SourceAddress)
316+
assert.Equal(t, qflow.TupleOrig.IP.DestinationAddress, f.TupleOrig.IP.DestinationAddress)
301317
}
302318
}
303319

0 commit comments

Comments
 (0)