Skip to content

Commit 90c0a49

Browse files
committed
varlen fields. exclude nat stuff
1 parent 3a4d0a5 commit 90c0a49

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

lib/ipflow/field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Field:
1010
)
1111

1212
def __init__(self, field_id: int, length: int):
13-
self._fmt = FIELD_TYPE_FMT.get(field_id, f'{length}s')
13+
self._fmt = FIELD_TYPE_FMT.get((field_id, length), f'{length}x')
1414
self.id = field_id
1515
self.length = length
1616

lib/ipflow/field_type.py

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,51 @@ class FieldType(Enum):
2626
IPV6_DST_MASK = 30
2727
IPV6_NEXT_HOP = 62
2828

29+
# NAT
30+
# postNATSourceIPv4Address = 225
31+
# postNATDestinationIPv4Address = 226
32+
# postNAPTSourceTransportPort = 227
33+
# postNAPTDestinationTransportPort = 228
34+
# natOriginatingAddressRealm = 229
35+
# natEvent = 230
36+
2937

3038
FIELD_TYPE_FMT = {
31-
1: 'L',
32-
2: 'L',
33-
4: 'B',
34-
5: 'B',
35-
6: 'B',
36-
7: 'H',
37-
10: 'H',
38-
11: 'H',
39-
14: 'H',
40-
21: 'L',
41-
22: 'L',
42-
# 27: 'LLLL',
43-
# 28: 'LLLL',
44-
# 62: 'LLLL',
45-
# 63: 'LLLL',
46-
227: 'H', # postNAPTSourceTransportPort
47-
228: 'H', # postNAPTDestinationTransportPort
48-
230: 'B', # natEvent
49-
323: 'Q',
39+
(1, 4): 'L',
40+
(1, 8): 'Q', # also uint64
41+
(2, 4): 'L',
42+
(2, 8): 'Q', # also uint64
43+
(3, 4): 'L',
44+
(3, 8): 'Q', # also uint64
45+
(4, 1): 'B',
46+
(5, 1): 'B',
47+
(6, 1): 'B',
48+
(7, 2): 'H',
49+
(8, 4): '4s',
50+
(9, 1): 'B',
51+
(10, 2): 'H',
52+
(11, 2): 'H',
53+
(12, 4): '4s',
54+
(13, 1): 'B',
55+
(14, 2): 'H',
56+
(15, 4): '4s',
57+
(21, 4): 'L',
58+
(21, 8): 'Q', # also uint64
59+
(22, 4): 'L',
60+
(22, 8): 'Q', # also uint64
61+
(27, 16): '16s',
62+
(28, 16): '16s',
63+
(29, 1): 'B',
64+
(30, 1): 'B',
65+
(62, 16): '16s',
66+
67+
# NAT
68+
# (225, 4): '4s',
69+
# (226, 4): '4s',
70+
# (227, 2): 'H',
71+
# (228, 2): 'H',
72+
# (229, 1): 'B',
73+
# (230, 1): 'B',
5074
}
5175

5276
FIELD_TYPE_FUNC = {
@@ -56,8 +80,8 @@ class FieldType(Enum):
5680
27: lambda a: str(ipaddress.IPv6Address(a)), # IPV6_SRC_ADDR
5781
28: lambda a: str(ipaddress.IPv6Address(a)), # IPV6_DST_ADDR
5882
62: lambda a: str(ipaddress.IPv6Address(a)), # IPV6_NEXT_HOP
59-
63: lambda a: str(ipaddress.IPv6Address(a)), # BGP_IPV6_NEXT_HOP
6083

61-
225: lambda a: str(ipaddress.IPv4Address(a)),
62-
226: lambda a: str(ipaddress.IPv4Address(a)),
84+
# NAT
85+
# 225: lambda a: str(ipaddress.IPv4Address(a)),
86+
# 226: lambda a: str(ipaddress.IPv4Address(a)),
6387
}

0 commit comments

Comments
 (0)