Skip to content

Commit d2ff604

Browse files
committed
Implement #15
1 parent 87bca98 commit d2ff604

File tree

6 files changed

+82
-21
lines changed

6 files changed

+82
-21
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,25 @@ func main() {
101101
}
102102

103103
// get NAT xlate ports
104-
if natXlatePort := flowRecord.NatXlatePort(); natXlatePort == nil {
104+
if natXlatePort := flowRecord.NatXlatePort(); natXlatePort != nil {
105105
fmt.Printf(" Src X-Port : %d\n", natXlatePort.XlateSrcPort)
106106
fmt.Printf(" Dst X-Port : %d\n", natXlatePort.XlateDstPort)
107107
}
108108

109109
// get nat port block and print
110-
if natPortBlock := flowRecord.NatPortBlock(); natPortBlock == nil {
110+
if natPortBlock := flowRecord.NatPortBlock(); natPortBlock != nil {
111111
fmt.Printf(" NAT pstart : %d\n", natPortBlock.BlockStart)
112112
fmt.Printf(" NAT pend : %d\n", natPortBlock.BlockEnd)
113113
fmt.Printf(" NAT pstep : %d\n", natPortBlock.BlockStep)
114114
fmt.Printf(" NAT psize : %d\n", natPortBlock.BlockSize)
115115
}
116-
116+
117+
// get IP info extension
118+
if ipInfo := flowRecord.IpInfo(); ipInfo != nil {
119+
fmt.Pprintf(" IP ttl : %d\n", ipInfo.Ttl)
120+
fmt.Pprintf(" IP fragment : %s%s\n", ipInfo.FragmentFlags)
121+
}
122+
117123
/*
118124
// other extension
119125
// see nfxV3.go for all fields in the respectiv records

defs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ const (
4545
EXflowIdID = uint16(C.EXflowIdID)
4646
EXnokiaNatID = uint16(C.EXnokiaNatID)
4747
EXnokiaNatStringID = uint16(C.EXnokiaNatStringID)
48+
EXipInfoID = uint16(C.EXipInfoID)
4849
)
4950

5051
const (
5152
V3_FLAG_EVENT = uint(C.V3_FLAG_EVENT)
5253
V3_FLAG_SAMPLED = uint(C.V3_FLAG_SAMPLED)
5354
V3_FLAG_ANON = uint(C.V3_FLAG_ANON)
55+
FlagMF = uint8(C.flagMF)
56+
FlagDF = uint8(C.flagDF)
5457
)
5558

5659
const (
@@ -77,6 +80,7 @@ type EXnatPortBlock C.struct_EXnatPortBlock_s
7780
type EXflowId C.struct_EXflowId_s
7881
type EXnokiaNat C.struct_EXnokiaNat_s
7982
type EXnokiaNatString string
83+
type EXipInfo C.struct_EXipInfo_s
8084

8185
type EXbgpNextHop struct {
8286
IP net.IP

nfxV3.go

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nfxV3.h

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,7 @@ typedef struct EXflowMisc_s {
239239
uint8_t flowEndReason;
240240
#define OFFflowEndReason offsetof(EXflowMisc_t, flowEndReason)
241241
#define SIZEflowEndReason MemberSize(EXflowMisc_t, flowEndReason)
242-
uint8_t revTcpFlags;
243-
uint8_t fragmentFlags;
244-
#define OFFfragmentFlags offsetof(EXflowMisc_t, fragmentFlags)
245-
#define SIZEfragmentFlags MemberSize(EXflowMisc_t, fragmentFlags)
242+
uint16_t align;
246243
} EXflowMisc_t;
247244
#define EXflowMiscSize (sizeof(EXflowMisc_t) + sizeof(elementHeader_t))
248245

@@ -686,8 +683,22 @@ typedef struct EXnokiaNatString_s {
686683
} EXnokiaNatString_t;
687684
#define EXnokiaNatStringSize (sizeof(EXnokiaNatString_t) + sizeof(elementHeader_t))
688685

686+
#define EXipInfoID 42
687+
typedef struct EXipInfo_s {
688+
uint8_t ttl;
689+
#define OFFipTTL offsetof(EXipInfo_t, ttl)
690+
#define SIZEipTTL MemberSize(EXipInfo_t, ttl)
691+
#define flagMF 0x20
692+
#define flagDF 0x40
693+
uint8_t fragmentFlags;
694+
#define OFFfragmentFlags offsetof(EXipInfo_t, fragmentFlags)
695+
#define SIZEfragmentFlags MemberSize(EXipInfo_t, fragmentFlags)
696+
uint16_t align; // unused for nfpcapd
697+
} EXipInfo_t;
698+
#define EXipInfoSize (sizeof(EXipInfo_t) + sizeof(elementHeader_t))
699+
689700
// max possible elements
690-
#define MAXEXTENSIONS 42
701+
#define MAXEXTENSIONS 43
691702

692703
// push a fixed length extension to the v3 record
693704
// h v3 record header
@@ -747,16 +758,17 @@ static const struct extensionTable_s {
747758
uint32_t id; // id number
748759
uint32_t size; // number of bytes incl. header, 0xFFFF for dyn length
749760
char *name; // name of extension
750-
} extensionTable[] = {
751-
{0, 0, "EXnull"}, EXTENSION(EXgenericFlow), EXTENSION(EXipv4Flow), EXTENSION(EXipv6Flow), EXTENSION(EXflowMisc),
752-
EXTENSION(EXcntFlow), EXTENSION(EXvLan), EXTENSION(EXasRouting), EXTENSION(EXbgpNextHopV4), EXTENSION(EXbgpNextHopV6),
753-
EXTENSION(EXipNextHopV4), EXTENSION(EXipNextHopV6), EXTENSION(EXipReceivedV4), EXTENSION(EXipReceivedV6), EXTENSION(EXmplsLabel),
754-
EXTENSION(EXmacAddr), EXTENSION(EXasAdjacent), EXTENSION(EXlatency), EXTENSION(EXsamplerInfo), EXTENSION(EXnselCommon),
755-
EXTENSION(EXnatXlateIPv4), EXTENSION(EXnatXlateIPv6), EXTENSION(EXnatXlatePort), EXTENSION(EXnselAcl), EXTENSION(EXnselUser),
756-
EXTENSION(EXnatCommon), EXTENSION(EXnatPortBlock), EXTENSION(EXnbarApp), EXTENSION(EXlabel), EXTENSION(EXinPayload),
757-
EXTENSION(EXoutPayload), EXTENSION(EXtunIPv4), EXTENSION(EXtunIPv6), EXTENSION(EXobservation), EXTENSION(EXinmonMeta),
758-
EXTENSION(EXinmonFrame), EXTENSION(EXvrf), EXTENSION(EXpfinfo), EXTENSION(EXlayer2), EXTENSION(EXflowId),
759-
EXTENSION(EXnokiaNat), EXTENSION(EXnokiaNatString)};
761+
} extensionTable[] = {{0, 0, "EXnull"}, EXTENSION(EXgenericFlow), EXTENSION(EXipv4Flow), EXTENSION(EXipv6Flow),
762+
EXTENSION(EXflowMisc), EXTENSION(EXcntFlow), EXTENSION(EXvLan), EXTENSION(EXasRouting),
763+
EXTENSION(EXbgpNextHopV4), EXTENSION(EXbgpNextHopV6), EXTENSION(EXipNextHopV4), EXTENSION(EXipNextHopV6),
764+
EXTENSION(EXipReceivedV4), EXTENSION(EXipReceivedV6), EXTENSION(EXmplsLabel), EXTENSION(EXmacAddr),
765+
EXTENSION(EXasAdjacent), EXTENSION(EXlatency), EXTENSION(EXsamplerInfo), EXTENSION(EXnselCommon),
766+
EXTENSION(EXnatXlateIPv4), EXTENSION(EXnatXlateIPv6), EXTENSION(EXnatXlatePort), EXTENSION(EXnselAcl),
767+
EXTENSION(EXnselUser), EXTENSION(EXnatCommon), EXTENSION(EXnatPortBlock), EXTENSION(EXnbarApp),
768+
EXTENSION(EXlabel), EXTENSION(EXinPayload), EXTENSION(EXoutPayload), EXTENSION(EXtunIPv4),
769+
EXTENSION(EXtunIPv6), EXTENSION(EXobservation), EXTENSION(EXinmonMeta), EXTENSION(EXinmonFrame),
770+
EXTENSION(EXvrf), EXTENSION(EXpfinfo), EXTENSION(EXlayer2), EXTENSION(EXflowId),
771+
EXTENSION(EXnokiaNat), EXTENSION(EXnokiaNatString), EXTENSION(EXipInfo)};
760772

761773
typedef struct record_map_s {
762774
recordHeaderV3_t *recordHeader;

record.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,13 @@ func (flowRecord *FlowRecordV3) NokiaNatString() EXnokiaNatString {
383383
bytes := flowRecord.rawRecord[offset : offset+size]
384384
return (EXnokiaNatString)(string(bytes[:]))
385385
}
386+
387+
// Returns the ipInfo extension from the *FlowRecordV3 object
388+
func (flowRecord *FlowRecordV3) IpInfo() *EXipInfo {
389+
offset := flowRecord.extOffset[EXipInfoID].offset
390+
if offset == 0 {
391+
return nil
392+
}
393+
ipInfo := (*EXipInfo)(unsafe.Pointer(&flowRecord.rawRecord[offset]))
394+
return ipInfo
395+
}

string.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func (flowRecord *FlowRecordV3) String() string {
104104
s += flowRecord.dumpEXflowId()
105105
s += flowRecord.dumpEXnokiaNAT()
106106
s += flowRecord.dumpEXnokiaNatString()
107+
s += flowRecord.dumpEXipInfoString()
107108

108109
return s
109110
}
@@ -321,3 +322,24 @@ func (flowRecord *FlowRecordV3) dumpEXnokiaNatString() string {
321322
}
322323
return fmt.Sprintf(" Flow ID : %v\n", natString)
323324
}
325+
326+
func (flowRecord *FlowRecordV3) dumpEXipInfoString() string {
327+
var ipInfo *EXipInfo
328+
if ipInfo = flowRecord.IpInfo(); ipInfo == nil {
329+
return ""
330+
}
331+
332+
var DF string = "--"
333+
var MF string = "--"
334+
if ipInfo.FragmentFlags&FlagMF != 0 {
335+
MF = "MF"
336+
}
337+
if ipInfo.FragmentFlags&FlagDF != 0 {
338+
DF = "DF"
339+
}
340+
var s string = "" +
341+
fmt.Sprintf(" IP ttl : %d\n", ipInfo.Ttl) +
342+
fmt.Sprintf(" IP fragment : %s%s\n", DF, MF)
343+
344+
return s
345+
}

0 commit comments

Comments
 (0)