Skip to content

Commit 29ae71e

Browse files
authored
Use IPFIX postNAT fields (#1181)
1 parent d209b58 commit 29ae71e

File tree

1 file changed

+42
-24
lines changed

1 file changed

+42
-24
lines changed

pkg/pipeline/write/write_ipfix.go

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,25 @@ var (
7070
"packetDeltaCount",
7171
"interfaceName",
7272
"tcpControlBits",
73+
"postNAPTSourceTransportPort",
74+
"postNAPTDestinationTransportPort",
7375
}
7476
IPv4IANAFields = append([]string{
7577
"sourceIPv4Address",
7678
"destinationIPv4Address",
7779
"icmpTypeIPv4",
7880
"icmpCodeIPv4",
81+
"postNATSourceIPv4Address",
82+
"postNATDestinationIPv4Address",
7983
}, IANAFields...)
8084
IPv6IANAFields = append([]string{
8185
"sourceIPv6Address",
8286
"destinationIPv6Address",
8387
"nextHeaderIPv6",
8488
"icmpTypeIPv6",
8589
"icmpCodeIPv6",
90+
"postNATSourceIPv6Address",
91+
"postNATDestinationIPv6Address",
8692
}, IANAFields...)
8793
KubeFields = []entities.InfoElement{
8894
{Name: "sourcePodNamespace", ElementId: 7733, DataType: entities.String, Len: 65535},
@@ -96,17 +102,9 @@ var (
96102
{Name: "timeFlowRttNs", ElementId: 7740, DataType: entities.Unsigned64, Len: 8},
97103
{Name: "interfaces", ElementId: 7741, DataType: entities.String, Len: 65535},
98104
{Name: "directions", ElementId: 7742, DataType: entities.String, Len: 65535},
99-
{Name: "xlatSourcePort", ElementId: 7743, DataType: entities.Unsigned16, Len: 2},
100-
{Name: "xlatDestinationPort", ElementId: 7744, DataType: entities.Unsigned16, Len: 2},
101-
}
102-
CustomNetworkFieldsV4 = []entities.InfoElement{
103-
{Name: "xlatSourceIPv4Address", ElementId: 7745, DataType: entities.Ipv4Address, Len: 4},
104-
{Name: "xlatDestinationIPv4Address", ElementId: 7746, DataType: entities.Ipv4Address, Len: 4},
105-
}
106-
CustomNetworkFieldsV6 = []entities.InfoElement{
107-
{Name: "xlatSourceIPv6Address", ElementId: 7747, DataType: entities.Ipv6Address, Len: 16},
108-
{Name: "xlatDestinationIPv6Address", ElementId: 7748, DataType: entities.Ipv6Address, Len: 16},
109105
}
106+
CustomNetworkFieldsV4 = []entities.InfoElement{}
107+
CustomNetworkFieldsV6 = []entities.InfoElement{}
110108

111109
MapIPFIXKeys = map[string]FieldMap{
112110
"sourceIPv4Address": {
@@ -332,40 +330,60 @@ var (
332330
Getter: func(elt entities.InfoElementWithValue) any { return int64(elt.GetUnsigned64Value()) },
333331
Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned64Value(uint64(rec.(int64))) },
334332
},
335-
"xlatSourcePort": {
333+
"postNAPTSourceTransportPort": {
336334
Key: "XlatSrcPort",
337335
Getter: func(elt entities.InfoElementWithValue) any { return elt.GetUnsigned16Value() },
338336
Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned16Value(rec.(uint16)) },
339337
},
340-
"xlatDestinationPort": {
338+
"postNAPTDestinationTransportPort": {
341339
Key: "XlatDstPort",
342340
Getter: func(elt entities.InfoElementWithValue) any { return elt.GetUnsigned16Value() },
343341
Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned16Value(rec.(uint16)) },
344342
},
345-
"xlatSourceIPv4Address": {
346-
Key: "XlatSrcAddr",
347-
Getter: func(elt entities.InfoElementWithValue) any { return elt.GetIPAddressValue().String() },
343+
"postNATSourceIPv4Address": {
344+
Key: "XlatSrcAddr",
345+
Getter: func(elt entities.InfoElementWithValue) any {
346+
if net.IPv4zero.Equal(elt.GetIPAddressValue()) {
347+
return nil
348+
}
349+
return elt.GetIPAddressValue().String()
350+
},
348351
Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetIPAddressValue(net.ParseIP(rec.(string))) },
349352
// Force zero-IP by default to avoid go-ipfix throwing an error: https://github.com/vmware/go-ipfix/blob/d9256ccb0ed9e3ae38c3a2bf3d6ce1ce01c9ac4f/pkg/entities/ie.go#L596
350353
Default: func(elt entities.InfoElementWithValue) { elt.SetIPAddressValue(net.IPv4zero) },
351354
},
352-
"xlatDestinationIPv4Address": {
353-
Key: "XlatDstAddr",
354-
Getter: func(elt entities.InfoElementWithValue) any { return elt.GetIPAddressValue().String() },
355+
"postNATDestinationIPv4Address": {
356+
Key: "XlatDstAddr",
357+
Getter: func(elt entities.InfoElementWithValue) any {
358+
if net.IPv4zero.Equal(elt.GetIPAddressValue()) {
359+
return nil
360+
}
361+
return elt.GetIPAddressValue().String()
362+
},
355363
Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetIPAddressValue(net.ParseIP(rec.(string))) },
356364
// Force zero-IP by default to avoid go-ipfix throwing an error: https://github.com/vmware/go-ipfix/blob/d9256ccb0ed9e3ae38c3a2bf3d6ce1ce01c9ac4f/pkg/entities/ie.go#L596
357365
Default: func(elt entities.InfoElementWithValue) { elt.SetIPAddressValue(net.IPv4zero) },
358366
},
359-
"xlatSourceIPv6Address": {
360-
Key: "XlatSrcAddr",
361-
Getter: func(elt entities.InfoElementWithValue) any { return elt.GetIPAddressValue().String() },
367+
"postNATSourceIPv6Address": {
368+
Key: "XlatSrcAddr",
369+
Getter: func(elt entities.InfoElementWithValue) any {
370+
if net.IPv6zero.Equal(elt.GetIPAddressValue()) {
371+
return nil
372+
}
373+
return elt.GetIPAddressValue().String()
374+
},
362375
Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetIPAddressValue(net.ParseIP(rec.(string))) },
363376
// Force zero-IP by default to avoid go-ipfix throwing an error: https://github.com/vmware/go-ipfix/blob/d9256ccb0ed9e3ae38c3a2bf3d6ce1ce01c9ac4f/pkg/entities/ie.go#L602
364377
Default: func(elt entities.InfoElementWithValue) { elt.SetIPAddressValue(net.IPv6zero) },
365378
},
366-
"xlatDestinationIPv6Address": {
367-
Key: "XlatDstAddr",
368-
Getter: func(elt entities.InfoElementWithValue) any { return elt.GetIPAddressValue().String() },
379+
"postNATDestinationIPv6Address": {
380+
Key: "XlatDstAddr",
381+
Getter: func(elt entities.InfoElementWithValue) any {
382+
if net.IPv6zero.Equal(elt.GetIPAddressValue()) {
383+
return nil
384+
}
385+
return elt.GetIPAddressValue().String()
386+
},
369387
Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetIPAddressValue(net.ParseIP(rec.(string))) },
370388
// Force zero-IP by default to avoid go-ipfix throwing an error: https://github.com/vmware/go-ipfix/blob/d9256ccb0ed9e3ae38c3a2bf3d6ce1ce01c9ac4f/pkg/entities/ie.go#L602
371389
Default: func(elt entities.InfoElementWithValue) { elt.SetIPAddressValue(net.IPv6zero) },

0 commit comments

Comments
 (0)