Skip to content

Commit 0c0ea58

Browse files
committed
add conntrack zone serialization
this allows to use the zone for conntrack delete Signed-off-by: Antonio Ojea <aojea@google.com>
1 parent 036dfc3 commit 0c0ea58

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

conntrack_linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ func (s *ConntrackFlow) toNlData() ([]*nl.RtAttr, error) {
391391
// <BEuint64>
392392
// <len, CTA_LABELS>
393393
// <binary data>
394+
// <len, CTA_ZONE>
395+
// <BEuint16>
394396
// <len, NLA_F_NESTED|CTA_PROTOINFO>
395397

396398
// CTA_TUPLE_ORIG
@@ -439,6 +441,11 @@ func (s *ConntrackFlow) toNlData() ([]*nl.RtAttr, error) {
439441
}
440442
}
441443

444+
if s.Zone != 0 {
445+
ctZone := nl.NewRtAttr(nl.CTA_ZONE, nl.BEUint16Attr(s.Zone))
446+
payload = append(payload, ctZone)
447+
}
448+
442449
return payload, nil
443450
}
444451

conntrack_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,8 @@ func TestConntrackDeleteV4(t *testing.T) {
15411541
t.Fatalf("failed to create netlink handle: %s", err)
15421542
}
15431543

1544+
ctZone := uint16(123)
1545+
15441546
flow := ConntrackFlow{
15451547
FamilyType: FAMILY_V4,
15461548
Forward: IPTuple{
@@ -1562,6 +1564,7 @@ func TestConntrackDeleteV4(t *testing.T) {
15621564
ProtoInfo: &ProtoInfoTCP{
15631565
State: nl.TCP_CONNTRACK_ESTABLISHED,
15641566
},
1567+
Zone: ctZone,
15651568
}
15661569

15671570
// Create the entry using the handle
@@ -1586,6 +1589,7 @@ func TestConntrackDeleteV4(t *testing.T) {
15861589
ConntrackOrigDstPort: flow.Forward.DstPort,
15871590
},
15881591
protoFilter: unix.IPPROTO_TCP,
1592+
zoneFilter: &ctZone,
15891593
}
15901594
var match *ConntrackFlow
15911595
for _, f := range flows {
@@ -1645,6 +1649,8 @@ func TestConntrackDeleteV6(t *testing.T) {
16451649
t.Fatalf("failed to create netlink handle: %s", err)
16461650
}
16471651

1652+
ctZone := uint16(123)
1653+
16481654
flow := ConntrackFlow{
16491655
FamilyType: FAMILY_V6,
16501656
Forward: IPTuple{
@@ -1666,6 +1672,7 @@ func TestConntrackDeleteV6(t *testing.T) {
16661672
ProtoInfo: &ProtoInfoTCP{
16671673
State: nl.TCP_CONNTRACK_ESTABLISHED,
16681674
},
1675+
Zone: ctZone,
16691676
}
16701677

16711678
// Create the entry using the handle
@@ -1690,6 +1697,7 @@ func TestConntrackDeleteV6(t *testing.T) {
16901697
ConntrackOrigDstPort: flow.Forward.DstPort,
16911698
},
16921699
protoFilter: unix.IPPROTO_TCP,
1700+
zoneFilter: &ctZone,
16931701
}
16941702
var match *ConntrackFlow
16951703
for _, f := range flows {

0 commit comments

Comments
 (0)