Skip to content

Commit cb619e5

Browse files
GabrielGannegpotter2
authored andcommitted
netflow - add IP_DSCP support
DSCP is a one-byte field just like TOS, and is already listed in the list of possible values in the template (NetflowV910TemplateFieldTypes), this just adds it to the list of possible values. Signed-off-by: Gabriel Ganne <[email protected]>
1 parent 4aaed1d commit cb619e5

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

scapy/layers/netflow.py

+2
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,7 @@ class NetflowRecordV5(Packet):
10921092
77: 3,
10931093
78: 3,
10941094
79: 3,
1095+
195: 1,
10951096
}
10961097

10971098
# NetflowV9 Ready-made fields
@@ -1202,6 +1203,7 @@ def __init__(self, name, default, *args, **kargs):
12021203
160: (N9UTCTimeField, [True]), # systemInitTimeMilliseconds
12031204
161: (N9SecondsIntField, [True]), # flowDurationMilliseconds
12041205
162: (N9SecondsIntField, [False, True]), # flowDurationMicroseconds
1206+
195: XByteField, # IP_DSCP
12051207
211: IPField, # collectorIPv4Address
12061208
212: IP6Field, # collectorIPv6Address
12071209
225: IPField, # postNATSourceIPv4Address

test/scapy/layers/netflow.uts

+27
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,30 @@ records = dissected_packets[3][NetflowDataflowsetV9].records
456456
assert len(records) == 24
457457
assert records[0].IPV4_SRC_ADDR == '20.0.1.174'
458458
assert records[0].IPV4_NEXT_HOP == '10.100.103.1'
459+
460+
# test for netflow IP_DSCP (id=195)
461+
dscp_flowset = NetflowFlowsetV9(
462+
templates=[
463+
NetflowTemplateV9(
464+
template_fields=[
465+
NetflowTemplateFieldV9(fieldType=195),
466+
],
467+
templateID=273,
468+
)
469+
],
470+
flowSetID=2,
471+
)
472+
473+
recordClass = GetNetflowRecordV9(dscp_flowset, templateID=273)
474+
475+
dscp_dataset = NetflowDataflowsetV9(
476+
templateID=273,
477+
records=[
478+
recordClass(
479+
IP_DSCP=42,
480+
),
481+
],
482+
)
483+
484+
# record is generated with 2 zero bytes of padding
485+
assert(raw(dscp_dataset) == b'\x01\x11\x00\x08\x2a\x00\x00\x00')

0 commit comments

Comments
 (0)