Skip to content

Commit

Permalink
Fix #12 and cleanup naming - breaks API calls!
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed May 6, 2024
1 parent 4bad58d commit 386f5de
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 126 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,25 @@ func main() {
fmt.Printf("DstIP: %v\n", ipAddr.DstIP)
}

if flowRecord.hasXlateIP {
fmt.Sprintf(" SrcXlateIP : %v\n", flowRecord.srcXlateIP)
fmt.Sprintf(" DstXlateIP : %v\n", flowRecord.dstXlateIP)
// get NAT xlate IP adresses
if natXlateIP = flowRecord.NatXlateIP(); natXlateIP != nil {
fmt.Sprintf(" SrcXlateIP : %v\n", natXlateIP.SrcXIP)
fmt.Sprintf(" DstXlateIP : %v\n", natXlateIP.DstXIP)
}

// get xlate ports and print
if xlatePort := flowRecord.XlatePort(); xlatePort == nil {
fmt.Printf(" Src X-Port : %d\n", xlatePort.XlateSrcPort)
fmt.Printf(" Dst X-Port : %d\n", xlatePort.XlateDstPort)
// get NAT xlate ports
if natXlatePort := flowRecord.NatXlatePort(); natXlatePort == nil {
fmt.Printf(" Src X-Port : %d\n", natXlatePort.XlateSrcPort)
fmt.Printf(" Dst X-Port : %d\n", natXlatePort.XlateDstPort)
}

// get nat port block and print
if natPortBlock := flowRecord.NatPortBlock(); natPortBlock == nil {
fmt.Printf(" NAT pstart : %d\n", natPortBlock.BlockStart)
fmt.Printf(" NAT pend : %d\n", natPortBlock.BlockEnd)
fmt.Printf(" NAT pstep : %d\n", natPortBlock.BlockStep)
fmt.Printf(" NAT psize : %d\n", natPortBlock.BlockSize)
}

/*
// other extension
Expand Down
49 changes: 29 additions & 20 deletions defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,27 @@ import (
)

const (
EXnull = uint(C.EXnull)
EXgenericFlowID = uint16(C.EXgenericFlowID)
EXipv4FlowID = uint16(C.EXipv4FlowID)
EXipv6FlowID = uint16(C.EXipv6FlowID)
EXflowMiscID = uint16(C.EXflowMiscID)
EXcntFlowID = uint16(C.EXcntFlowID)
EXvLanID = uint16(C.EXvLanID)
EXasRoutingID = uint16(C.EXasRoutingID)
EXbgpNextHopV4ID = uint16(C.EXbgpNextHopV4ID)
EXbgpNextHopV6ID = uint16(C.EXbgpNextHopV6ID)
EXipNextHopV4ID = uint16(C.EXipNextHopV4ID)
EXipNextHopV6ID = uint16(C.EXipNextHopV6ID)
EXipReceivedV4ID = uint16(C.EXipReceivedV4ID)
EXipReceivedV6ID = uint16(C.EXipReceivedV6ID)
EXsamplerInfoID = uint16(C.EXsamplerInfoID)
EXinPayloadID = uint16(C.EXinPayloadID)
EXnselXlateIPv4ID = uint16(C.EXnselXlateIPv4ID)
EXnselXlateIPv6ID = uint16(C.EXnselXlateIPv6ID)
EXnselXlatePortID = uint16(C.EXnselXlatePortID)
EXnull = uint(C.EXnull)
EXgenericFlowID = uint16(C.EXgenericFlowID)
EXipv4FlowID = uint16(C.EXipv4FlowID)
EXipv6FlowID = uint16(C.EXipv6FlowID)
EXflowMiscID = uint16(C.EXflowMiscID)
EXcntFlowID = uint16(C.EXcntFlowID)
EXvLanID = uint16(C.EXvLanID)
EXasRoutingID = uint16(C.EXasRoutingID)
EXbgpNextHopV4ID = uint16(C.EXbgpNextHopV4ID)
EXbgpNextHopV6ID = uint16(C.EXbgpNextHopV6ID)
EXipNextHopV4ID = uint16(C.EXipNextHopV4ID)
EXipNextHopV6ID = uint16(C.EXipNextHopV6ID)
EXipReceivedV4ID = uint16(C.EXipReceivedV4ID)
EXipReceivedV6ID = uint16(C.EXipReceivedV6ID)
EXsamplerInfoID = uint16(C.EXsamplerInfoID)
EXinPayloadID = uint16(C.EXinPayloadID)
EXnatXlateIPv4ID = uint16(C.EXnatXlateIPv4ID)
EXnatXlateIPv6ID = uint16(C.EXnatXlateIPv6ID)
EXnatXlatePortID = uint16(C.EXnatXlatePortID)
EXnatCommonID = uint16(C.EXnelCommonID)
EXnatPortBlockID = uint16(C.EXnatPortBlockID)
)

const (
Expand All @@ -66,7 +68,9 @@ type EXcntFlow C.struct_EXcntFlow_s
type EXvLan C.struct_EXvLan_s
type EXasRouting C.struct_EXasRouting_s
type EXsamplerInfo C.struct_EXsamplerInfo_s
type EXnselXlatePort C.struct_EXnselXlatePort_s
type EXnatXlatePort C.struct_EXnatXlatePort_s
type EXnatCommon C.struct_EXnelCommon_s
type EXnatPortBlock C.struct_EXnatPortBlock_s

type EXbgpNextHop struct {
IP net.IP
Expand All @@ -80,6 +84,11 @@ type EXipReceived struct {
IP net.IP
}

type EXnatXlateIP struct {
SrcXIP net.IP
DstXIP net.IP
}

type EXinPayload []byte

type ExporterInfoRecord C.struct_exporter_info_record_s
Expand Down
19 changes: 1 addition & 18 deletions example/reader/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Peter Haag peter@people.ops-trust.net
// Copyright © 2024 Peter Haag peter@people.ops-trust.net
// All rights reserved.
//
// Use of this source code is governed by the license that can be
Expand Down Expand Up @@ -84,23 +84,6 @@ func main() {
fmt.Printf("DstIP: %v\n", ipAddr.DstIP)
}

// get xlate ports
if xlatePort := record.XlatePort(); xlatePort != nil {
fmt.Printf("SrcXlatePort: %d\n", xlatePort.XlateSrcPort)
fmt.Printf("DstXlatePort: %d\n", xlatePort.XlateDstPort)
}

// xlateIPs
// can contain IPv4 or IPv6
xlateIP := record.XlateIP()
if xlateIP != nil {
// when printing as %v, Golang takes care about proper formating
// as IPv4 or IPv6
// see Golang standard library net.IP for more details to process IPs
fmt.Printf("SrcXlateIP: %v\n", xlateIP.SrcXIP)
fmt.Printf("DstXlateIP: %v\n", xlateIP.DstXIP)
}

// get payload extension
if payload := record.Payload(); payload != nil {
fmt.Printf("Payload length: %d\n", len(payload))
Expand Down
2 changes: 1 addition & 1 deletion nffile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Peter Haag peter@people.ops-trust.net
// Copyright © 2024 Peter Haag peter@people.ops-trust.net
// All rights reserved.
//
// Use of this source code is governed by the license that can be
Expand Down
28 changes: 24 additions & 4 deletions nfxV3.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 46 additions & 46 deletions nfxV3.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,38 +428,38 @@ typedef struct EXnselCommon_s {
} EXnselCommon_t;
#define EXnselCommonSize (sizeof(EXnselCommon_t) + sizeof(elementHeader_t))

typedef struct EXnselXlateIPv4_s {
#define EXnselXlateIPv4ID 20
typedef struct EXnatXlateIPv4_s {
#define EXnatXlateIPv4ID 20
uint32_t xlateSrcAddr; // NF_F_XLATE_SRC_ADDR_IPV4(225), NF_F_XLATE_SRC_ADDR_84(40001)
uint32_t xlateDstAddr; // NF_F_XLATE_DST_ADDR_IPV4(226), NF_F_XLATE_DST_ADDR_84(40002)
#define OFFxlateSrc4Addr offsetof(EXnselXlateIPv4_t, xlateSrcAddr)
#define SIZExlateSrc4Addr MemberSize(EXnselXlateIPv4_t, xlateSrcAddr)
#define OFFxlateDst4Addr offsetof(EXnselXlateIPv4_t, xlateDstAddr)
#define SIZExlateDst4Addr MemberSize(EXnselXlateIPv4_t, xlateDstAddr)
} EXnselXlateIPv4_t;
#define EXnselXlateIPv4Size (sizeof(EXnselXlateIPv4_t) + sizeof(elementHeader_t))

typedef struct EXnselXlateIPv6_s {
#define EXnselXlateIPv6ID 21
#define OFFxlateSrc4Addr offsetof(EXnatXlateIPv4_t, xlateSrcAddr)
#define SIZExlateSrc4Addr MemberSize(EXnatXlateIPv4_t, xlateSrcAddr)
#define OFFxlateDst4Addr offsetof(EXnatXlateIPv4_t, xlateDstAddr)
#define SIZExlateDst4Addr MemberSize(EXnatXlateIPv4_t, xlateDstAddr)
} EXnatXlateIPv4_t;
#define EXnatXlateIPv4Size (sizeof(EXnatXlateIPv4_t) + sizeof(elementHeader_t))

typedef struct EXnatXlateIPv6_s {
#define EXnatXlateIPv6ID 21
uint64_t xlateSrcAddr[2]; // NF_F_XLATE_SRC_ADDR_IPV6(281),
uint64_t xlateDstAddr[2]; // NF_F_XLATE_DST_ADDR_IPV6(282),
#define OFFxlateSrc6Addr offsetof(EXnselXlateIPv6_t, xlateSrcAddr)
#define SIZExlateSrc6Addr MemberSize(EXnselXlateIPv6_t, xlateSrcAddr)
#define OFFxlateDst6Addr offsetof(EXnselXlateIPv6_t, xlateDstAddr)
#define SIZExlateDst6Addr MemberSize(EXnselXlateIPv6_t, xlateDstAddr)
} EXnselXlateIPv6_t;
#define EXnselXlateIPv6Size (sizeof(EXnselXlateIPv6_t) + sizeof(elementHeader_t))

typedef struct EXnselXlatePort_s {
#define EXnselXlatePortID 22
#define OFFxlateSrc6Addr offsetof(EXnatXlateIPv6_t, xlateSrcAddr)
#define SIZExlateSrc6Addr MemberSize(EXnatXlateIPv6_t, xlateSrcAddr)
#define OFFxlateDst6Addr offsetof(EXnatXlateIPv6_t, xlateDstAddr)
#define SIZExlateDst6Addr MemberSize(EXnatXlateIPv6_t, xlateDstAddr)
} EXnatXlateIPv6_t;
#define EXnatXlateIPv6Size (sizeof(EXnatXlateIPv6_t) + sizeof(elementHeader_t))

typedef struct EXnatXlatePort_s {
#define EXnatXlatePortID 22
uint16_t xlateSrcPort; // NF_F_XLATE_SRC_PORT(227), NF_F_XLATE_SRC_PORT_84(40003)
uint16_t xlateDstPort; // NF_F_XLATE_DST_PORT(228), NF_F_XLATE_DST_PORT_84(40004)
#define OFFxlateSrcPort offsetof(EXnselXlatePort_t, xlateSrcPort)
#define SIZExlateSrcPort MemberSize(EXnselXlatePort_t, xlateSrcPort)
#define OFFxlateDstPort offsetof(EXnselXlatePort_t, xlateDstPort)
#define SIZExlateDstPort MemberSize(EXnselXlatePort_t, xlateDstPort)
} EXnselXlatePort_t;
#define EXnselXlatePortSize (sizeof(EXnselXlatePort_t) + sizeof(elementHeader_t))
#define OFFxlateSrcPort offsetof(EXnatXlatePort_t, xlateSrcPort)
#define SIZExlateSrcPort MemberSize(EXnatXlatePort_t, xlateSrcPort)
#define OFFxlateDstPort offsetof(EXnatXlatePort_t, xlateDstPort)
#define SIZExlateDstPort MemberSize(EXnatXlatePort_t, xlateDstPort)
} EXnatXlatePort_t;
#define EXnatXlatePortSize (sizeof(EXnatXlatePort_t) + sizeof(elementHeader_t))

typedef struct EXnselAcl_s {
#define EXnselAclID 23
Expand Down Expand Up @@ -511,22 +511,22 @@ typedef struct EXnelCommonCompat_s {
} EXnelCommonCompat_t;
#define EXnelCommonCompatSize (sizeof(EXnelCommonCompat_t) + sizeof(elementHeader_t))

typedef struct EXnelXlatePort_s {
#define EXnelXlatePortID 26
typedef struct EXnatPortBlock_s {
#define EXnatPortBlockID 26
uint16_t blockStart; // NF_F_XLATE_PORT_BLOCK_START(361)
uint16_t blockEnd; // NF_F_XLATE_PORT_BLOCK_END(362)
uint16_t blockStep; // NF_F_XLATE_PORT_BLOCK_STEP(363)
uint16_t blockSize; // NF_F_XLATE_PORT_BLOCK_SIZE(364)
#define OFFnelblockStart offsetof(EXnelXlatePort_t, blockStart)
#define SIZEnelblockStart MemberSize(EXnelXlatePort_t, blockStart)
#define OFFnelblockEnd offsetof(EXnelXlatePort_t, blockEnd)
#define SIZEnelblockEnd MemberSize(EXnelXlatePort_t, blockEnd)
#define OFFnelblockStep offsetof(EXnelXlatePort_t, blockStep)
#define SIZEnelblockStep MemberSize(EXnelXlatePort_t, blockStep)
#define OFFnelblockSize offsetof(EXnelXlatePort_t, blockSize)
#define SIZEnelblockSize MemberSize(EXnelXlatePort_t, blockSize)
} EXnelXlatePort_t;
#define EXnelXlatePortSize (sizeof(EXnelXlatePort_t) + sizeof(elementHeader_t))
#define OFFnelblockStart offsetof(EXnatPortBlock_t, blockStart)
#define SIZEnelblockStart MemberSize(EXnatPortBlock_t, blockStart)
#define OFFnelblockEnd offsetof(EXnatPortBlock_t, blockEnd)
#define SIZEnelblockEnd MemberSize(EXnatPortBlock_t, blockEnd)
#define OFFnelblockStep offsetof(EXnatPortBlock_t, blockStep)
#define SIZEnelblockStep MemberSize(EXnatPortBlock_t, blockStep)
#define OFFnelblockSize offsetof(EXnatPortBlock_t, blockSize)
#define SIZEnelblockSize MemberSize(EXnatPortBlock_t, blockSize)
} EXnatPortBlock_t;
#define EXnatPortBlockSize (sizeof(EXnatPortBlock_t) + sizeof(elementHeader_t))

typedef struct EXnbarApp_s {
#define EXnbarAppID 27
Expand Down Expand Up @@ -734,14 +734,14 @@ static const struct extensionTable_s {
uint32_t size; // number of bytes incl. header, 0xFFFF for dyn length
char *name; // name of extension
} extensionTable[] = {
{0, 0, "ExNull"}, EXTENSION(EXgenericFlow), EXTENSION(EXipv4Flow), EXTENSION(EXipv6Flow), EXTENSION(EXflowMisc),
EXTENSION(EXcntFlow), EXTENSION(EXvLan), EXTENSION(EXasRouting), EXTENSION(EXbgpNextHopV4), EXTENSION(EXbgpNextHopV6),
EXTENSION(EXipNextHopV4), EXTENSION(EXipNextHopV6), EXTENSION(EXipReceivedV4), EXTENSION(EXipReceivedV6), EXTENSION(EXmplsLabel),
EXTENSION(EXmacAddr), EXTENSION(EXasAdjacent), EXTENSION(EXlatency), EXTENSION(EXsamplerInfo), EXTENSION(EXnselCommon),
EXTENSION(EXnselXlateIPv4), EXTENSION(EXnselXlateIPv6), EXTENSION(EXnselXlatePort), EXTENSION(EXnselAcl), EXTENSION(EXnselUser),
EXTENSION(EXnelCommon), EXTENSION(EXnelXlatePort), EXTENSION(EXnbarApp), EXTENSION(EXlabel), EXTENSION(EXinPayload),
EXTENSION(EXoutPayload), EXTENSION(EXtunIPv4), EXTENSION(EXtunIPv6), EXTENSION(EXobservation), EXTENSION(EXinmonMeta),
EXTENSION(EXinmonFrame), EXTENSION(EXvrf), EXTENSION(EXpfinfo), EXTENSION(EXlayer2)};
{0, 0, "ExNull"}, EXTENSION(EXgenericFlow), EXTENSION(EXipv4Flow), EXTENSION(EXipv6Flow), EXTENSION(EXflowMisc),
EXTENSION(EXcntFlow), EXTENSION(EXvLan), EXTENSION(EXasRouting), EXTENSION(EXbgpNextHopV4), EXTENSION(EXbgpNextHopV6),
EXTENSION(EXipNextHopV4), EXTENSION(EXipNextHopV6), EXTENSION(EXipReceivedV4), EXTENSION(EXipReceivedV6), EXTENSION(EXmplsLabel),
EXTENSION(EXmacAddr), EXTENSION(EXasAdjacent), EXTENSION(EXlatency), EXTENSION(EXsamplerInfo), EXTENSION(EXnselCommon),
EXTENSION(EXnatXlateIPv4), EXTENSION(EXnatXlateIPv6), EXTENSION(EXnatXlatePort), EXTENSION(EXnselAcl), EXTENSION(EXnselUser),
EXTENSION(EXnelCommon), EXTENSION(EXnatPortBlock), EXTENSION(EXnbarApp), EXTENSION(EXlabel), EXTENSION(EXinPayload),
EXTENSION(EXoutPayload), EXTENSION(EXtunIPv4), EXTENSION(EXtunIPv6), EXTENSION(EXobservation), EXTENSION(EXinmonMeta),
EXTENSION(EXinmonFrame), EXTENSION(EXvrf), EXTENSION(EXpfinfo), EXTENSION(EXlayer2)};

typedef struct record_map_s {
recordHeaderV3_t *recordHeader;
Expand Down
Loading

0 comments on commit 386f5de

Please sign in to comment.