Skip to content

Commit 693621f

Browse files
committed
added CustomOption schema/data
1 parent 3e4b3e8 commit 693621f

File tree

6 files changed

+44
-15
lines changed

6 files changed

+44
-15
lines changed

pcapkit/protocols/data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# PCAP-NG file format
3535
'PCAPNG',
3636
'PCAPNG_Option', 'PCAPNG_UnknownOption',
37-
'PCAPNG_EndOfOption', 'PCAPNG_CommentOption',
37+
'PCAPNG_EndOfOption', 'PCAPNG_CommentOption', 'PCAPNG_CustomOption',
3838
'PCAPNG_IF_NameOption', 'PCAPNG_IF_DescriptionOption', 'PCAPNG_IF_IPv4AddrOption', 'PCAPNG_IF_IPv6AddrOption',
3939
'PCAPNG_IF_MACAddrOption', 'PCAPNG_IF_EUIAddrOption', 'PCAPNG_IF_SpeedOption', 'PCAPNG_IF_TSResolOption',
4040
'PCAPNG_IF_TZoneOption', 'PCAPNG_IF_FilterOption', 'PCAPNG_IF_OSOption', 'PCAPNG_IF_FCSLenOption',

pcapkit/protocols/data/misc/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pcapkit.protocols.data.misc.pcapng import PCAPNG
1010
from pcapkit.protocols.data.misc.pcapng import CommentOption as PCAPNG_CommentOption
1111
from pcapkit.protocols.data.misc.pcapng import CustomBlock as PCAPNG_CustomBlock
12+
from pcapkit.protocols.data.misc.pcapng import CustomOption as PCAPNG_CustomOption
1213
from pcapkit.protocols.data.misc.pcapng import \
1314
DecryptionSecretsBlock as PCAPNG_DecryptionSecretsBlock
1415
from pcapkit.protocols.data.misc.pcapng import DSBSecrets as PCAPNG_DSBSecrets
@@ -83,7 +84,7 @@
8384
# PCAP-NG file format
8485
'PCAPNG',
8586
'PCAPNG_Option', 'PCAPNG_UnknownOption',
86-
'PCAPNG_EndOfOption', 'PCAPNG_CommentOption',
87+
'PCAPNG_EndOfOption', 'PCAPNG_CommentOption', 'PCAPNG_CustomOption',
8788
'PCAPNG_IF_NameOption', 'PCAPNG_IF_DescriptionOption', 'PCAPNG_IF_IPv4AddrOption', 'PCAPNG_IF_IPv6AddrOption',
8889
'PCAPNG_IF_MACAddrOption', 'PCAPNG_IF_EUIAddrOption', 'PCAPNG_IF_SpeedOption', 'PCAPNG_IF_TSResolOption',
8990
'PCAPNG_IF_TZoneOption', 'PCAPNG_IF_FilterOption', 'PCAPNG_IF_OSOption', 'PCAPNG_IF_FCSLenOption',

pcapkit/protocols/data/misc/pcapng.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'PCAPNG',
1111

1212
'Option', 'UnknownOption',
13-
'EndOfOption', 'CommentOption',
13+
'EndOfOption', 'CommentOption', 'CustomOption',
1414
'IF_NameOption', 'IF_DescriptionOption', 'IF_IPv4AddrOption', 'IF_IPv6AddrOption',
1515
'IF_MACAddrOption', 'IF_EUIAddrOption', 'IF_SpeedOption', 'IF_TSResolOption',
1616
'IF_TZoneOption', 'IF_FilterOption', 'IF_OSOption', 'IF_FCSLenOption',
@@ -107,6 +107,18 @@ class CommentOption(Option):
107107
comment: 'str'
108108

109109

110+
class CustomOption(Option):
111+
"""Data model for PCAP-NG file ``opt_custom`` options."""
112+
113+
#: Private enterprise number (PEN).
114+
pen: 'int'
115+
#: Custom data.
116+
data: 'bytes'
117+
118+
if TYPE_CHECKING:
119+
def __init__(self, type: 'Enum_OptionType', length: 'int', pen: 'int', data: 'bytes') -> None: ...
120+
121+
110122
class SectionHeaderBlock(PCAPNG):
111123
"""Data model for PCAP-NG Section Header Block (SHB)."""
112124

pcapkit/protocols/schema/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
# PCAP-NG file format
103103
'PCAPNG',
104104
'PCAPNG_Option', 'PCAPNG_UnknownOption',
105-
'PCAPNG_EndOfOption', 'PCAPNG_CommentOption',
105+
'PCAPNG_EndOfOption', 'PCAPNG_CommentOption', 'PCAPNG_CustomOption',
106106
'PCAPNG_IF_NameOption', 'PCAPNG_IF_DescriptionOption', 'PCAPNG_IF_IPv4AddrOption', 'PCAPNG_IF_IPv6AddrOption',
107107
'PCAPNG_IF_MACAddrOption', 'PCAPNG_IF_EUIAddrOption', 'PCAPNG_IF_SpeedOption', 'PCAPNG_IF_TSResolOption',
108108
'PCAPNG_IF_TZoneOption', 'PCAPNG_IF_FilterOption', 'PCAPNG_IF_OSOption', 'PCAPNG_IF_FCSLenOption',

pcapkit/protocols/schema/misc/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pcapkit.protocols.schema.misc.pcapng import PCAPNG
1111
from pcapkit.protocols.schema.misc.pcapng import CommentOption as PCAPNG_CommentOption
1212
from pcapkit.protocols.schema.misc.pcapng import CustomBlock as PCAPNG_CustomBlock
13+
from pcapkit.protocols.schema.misc.pcapng import CustomOption as PCAPNG_CustomOption
1314
from pcapkit.protocols.schema.misc.pcapng import \
1415
DecryptionSecretsBlock as PCAPNG_DecryptionSecretsBlock
1516
from pcapkit.protocols.schema.misc.pcapng import DSBSecrets as PCAPNG_DSBSecrets
@@ -83,7 +84,7 @@
8384
# PCAP-NG file format
8485
'PCAPNG',
8586
'PCAPNG_Option', 'PCAPNG_UnknownOption',
86-
'PCAPNG_EndOfOption', 'PCAPNG_CommentOption',
87+
'PCAPNG_EndOfOption', 'PCAPNG_CommentOption', 'PCAPNG_CustomOption',
8788
'PCAPNG_IF_NameOption', 'PCAPNG_IF_DescriptionOption', 'PCAPNG_IF_IPv4AddrOption', 'PCAPNG_IF_IPv6AddrOption',
8889
'PCAPNG_IF_MACAddrOption', 'PCAPNG_IF_EUIAddrOption', 'PCAPNG_IF_SpeedOption', 'PCAPNG_IF_TSResolOption',
8990
'PCAPNG_IF_TZoneOption', 'PCAPNG_IF_FilterOption', 'PCAPNG_IF_OSOption', 'PCAPNG_IF_FCSLenOption',

pcapkit/protocols/schema/misc/pcapng.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
'PCAPNG',
3434

3535
'Option', 'UnknownOption',
36-
'EndOfOption', 'CommentOption',
36+
'EndOfOption', 'CommentOption', 'CustomOption',
3737
'IF_NameOption', 'IF_DescriptionOption', 'IF_IPv4AddrOption', 'IF_IPv6AddrOption',
3838
'IF_MACAddrOption', 'IF_EUIAddrOption', 'IF_SpeedOption', 'IF_TSResolOption',
3939
'IF_TZoneOption', 'IF_FilterOption', 'IF_OSOption', 'IF_FCSLenOption',
@@ -283,7 +283,7 @@ class UnknownOption(Option):
283283
padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
284284

285285
if TYPE_CHECKING:
286-
def __init__(self, type: 'int', length: 'int', data: 'bytes', padding: 'bytes') -> 'None': ...
286+
def __init__(self, type: 'int', length: 'int', data: 'bytes') -> 'None': ...
287287

288288

289289
class EndOfOption(Option):
@@ -302,7 +302,21 @@ class CommentOption(Option):
302302
padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
303303

304304
if TYPE_CHECKING:
305-
def __init__(self, type: 'int', length: 'int', comment: 'str', padding: 'bytes') -> 'None': ...
305+
def __init__(self, type: 'int', length: 'int', comment: 'str') -> 'None': ...
306+
307+
308+
class CustomOption(Option):
309+
"""Header schema for PCAP-NG file ``opt_custom`` options."""
310+
311+
#: Private enterprise number (PEN).
312+
pen: 'int' = UInt32Field(callback=byteorder_callback)
313+
#: Custom data.
314+
data: 'bytes' = BytesField(length=lambda pkt: pkt['length'] - 4)
315+
#: Padding.
316+
padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
317+
318+
if TYPE_CHECKING:
319+
def __init__(self, type: 'int', length: 'int', pen: 'int', data: 'bytes') -> 'None': ...
306320

307321

308322
class SectionHeaderBlock(BlockType):
@@ -315,7 +329,7 @@ class SectionHeaderBlock(BlockType):
315329
#: Block total length.
316330
length: 'int' = UInt32Field(callback=shb_byteorder_callback)
317331
#: Byte order magic number.
318-
magic: 'int' = UInt32Field(callback=shb_byteorder_callback)
332+
magic: 'Literal[0x1A2B3C4D]' = UInt32Field(callback=shb_byteorder_callback)
319333
#: Major version number.
320334
major: 'int' = UInt16Field(callback=shb_byteorder_callback, default=1)
321335
#: Minor version number.
@@ -382,8 +396,9 @@ def post_process(self, packet: 'dict[str, Any]') -> 'SectionHeaderBlock':
382396
#: Byteorder.
383397
byteorder: Literal['big', 'little']
384398

385-
def __init__(self, length: 'int', magic: 'int', major: 'int',
386-
minor: 'int', section_length: 'int', options: 'list[Option | bytes] | bytes', length2: 'int') -> 'None': ...
399+
def __init__(self, length: 'int', magic: 'Literal[0x1A2B3C4D]', major: 'int',
400+
minor: 'int', section_length: 'int', options: 'list[Option | bytes] | bytes',
401+
length2: 'int') -> 'None': ...
387402

388403

389404
class IF_NameOption(Option):
@@ -395,7 +410,7 @@ class IF_NameOption(Option):
395410
padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
396411

397412
if TYPE_CHECKING:
398-
def __init__(self, type: 'int', length: 'int', name: 'str', padding: 'bytes') -> 'None': ...
413+
def __init__(self, type: 'int', length: 'int', name: 'str') -> 'None': ...
399414

400415

401416
class IF_DescriptionOption(Option):
@@ -407,7 +422,7 @@ class IF_DescriptionOption(Option):
407422
padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
408423

409424
if TYPE_CHECKING:
410-
def __init__(self, type: 'int', length: 'int', description: 'str', padding: 'bytes') -> 'None': ...
425+
def __init__(self, type: 'int', length: 'int', description: 'str') -> 'None': ...
411426

412427

413428
class IF_IPv4AddrOption(Option):
@@ -860,7 +875,7 @@ def post_process(self, packet: 'dict[str, Any]') -> 'Schema':
860875
#: Name resolution records.
861876
names: 'list[str]'
862877

863-
def __init__(self, type: 'Enum_RecordType', length: 'int', ip: 'IPv4Address', resol: 'str', padding: 'bytes') -> 'None': ...
878+
def __init__(self, type: 'Enum_RecordType', length: 'int', ip: 'IPv4Address', resol: 'str') -> 'None': ...
864879

865880

866881
class IPv6Record(NameResolutionRecord):
@@ -890,7 +905,7 @@ def post_process(self, packet: 'dict[str, Any]') -> 'Schema':
890905
#: Name resolution records.
891906
names: 'list[str]'
892907

893-
def __init__(self, type: 'Enum_RecordType', length: 'int', ip: 'IPv4Address', resol: 'str', padding: 'bytes') -> 'None': ...
908+
def __init__(self, type: 'Enum_RecordType', length: 'int', ip: 'IPv4Address', resol: 'str') -> 'None': ...
894909

895910

896911
class NS_DNSNameOption(Option):

0 commit comments

Comments
 (0)