Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
name = "DHCP6 Interface-Id Option"
fields_desc = [ShortEnumField("optcode", 18, dhcp6opts),
FieldLenField("optlen", None, fmt="!H",
length_of="ifaceid"),
StrLenField("ifaceid", "",
length_from=lambda pkt: pkt.optlen)]
# DHCPv6 Reconfigure Message Option #
# A server includes a Reconfigure Message option in a Reconfigure
# message to indicate to the client whether the client responds with a
# renew message or an Information-request message.
class DHCP6OptReconfMsg(_DHCP6OptGuessPayload): # RFC sect 22.19
name = "DHCP6 Reconfigure Message Option"
fields_desc = [ShortEnumField("optcode", 19, dhcp6opts),
ShortField("optlen", 1),
ByteEnumField("msgtype", 11, {5: "Renew Message",
11: "Information Request"})]
# DHCPv6 Reconfigure Accept Option #
# A client uses the Reconfigure Accept option to announce to the
# server whether the client is willing to accept Recoonfigure
# messages, and a server uses this option to tell the client whether
# or not to accept Reconfigure messages. The default behavior in the
# absence of this option, means unwillingness to accept reconfigure
# messages, or instruction not to accept Reconfigure messages, for the
# client and server messages, respectively.
class DHCP6OptReconfAccept(_DHCP6OptGuessPayload): # RFC sect 22.20
name = "DHCP6 Reconfigure Accept Option"
99: "SPF", 100: "UINFO", 101: "UID", 102: "GID", 103: "UNSPEC", 104: "NID",
105: "L32", 106: "L64", 107: "LP", 108: "EUI48", 109: "EUI64",
249: "TKEY", 250: "TSIG", 256: "URI", 257: "CAA", 258: "AVC",
32768: "TA", 32769: "DLV", 65535: "RESERVED"
}
dnsqtypes = {251: "IXFR", 252: "AXFR", 253: "MAILB", 254: "MAILA", 255: "ALL"}
dnsqtypes.update(dnstypes)
dnsclasses = {1: 'IN', 2: 'CS', 3: 'CH', 4: 'HS', 255: 'ANY'}
class DNSQR(InheritOriginDNSStrPacket):
name = "DNS Question Record"
show_indent = 0
fields_desc = [DNSStrField("qname", "www.example.com"),
ShortEnumField("qtype", 1, dnsqtypes),
ShortEnumField("qclass", 1, dnsclasses)]
# RFC 2671 - Extension Mechanisms for DNS (EDNS0)
class EDNS0TLV(Packet):
name = "DNS EDNS0 TLV"
fields_desc = [ShortEnumField("optcode", 0, {0: "Reserved", 1: "LLQ", 2: "UL", 3: "NSID", 4: "Reserved", 5: "PING"}), # noqa: E501
FieldLenField("optlen", None, "optdata", fmt="H"),
StrLenField("optdata", "", length_from=lambda pkt: pkt.optlen)] # noqa: E501
def extract_padding(self, p):
return "", p
class DNSRROPT(InheritOriginDNSStrPacket):
ofp_queue_property_types = {0: "OFPQT_NONE",
1: "OFPQT_MIN_RATE"}
class OFPQTNone(_ofp_header):
name = "OFPQT_NONE"
fields_desc = [ShortEnumField("type", 0, ofp_queue_property_types),
ShortField("len", 8),
XIntField("pad", 0)]
class OFPQTMinRate(_ofp_header):
name = "OFPQT_MIN_RATE"
fields_desc = [ShortEnumField("type", 1, ofp_queue_property_types),
ShortField("len", 16),
XIntField("pad", 0),
ShortField("rate", 0),
XBitField("pad2", 0, 48)]
ofp_queue_property_cls = {0: OFPQTNone,
1: OFPQTMinRate}
class OFPQT(Packet):
@classmethod
def dispatch_hook(cls, _pkt=None, *args, **kargs):
if _pkt and len(_pkt) >= 2:
t = struct.unpack("!H", _pkt[:2])[0]
return ofp_queue_property_cls.get(t, Raw)
ByteEnumField("proto", None, {0: "Reserved", 1: "IKE", 2: "AH", 3: "ESP"}), # noqa: E501
FieldLenField("SPIsize", None, "SPI", "B"),
ShortEnumField("type", 0, IKEv2NotifyMessageTypes),
StrLenField("SPI", "", length_from=lambda x: x.SPIsize),
StrLenField("load", "", length_from=lambda x: x.length - 8),
]
class IKEv2_payload_KE(IKEv2_class):
name = "IKEv2 Key Exchange"
overload_fields = {IKEv2: {"next_payload": 34}}
fields_desc = [
ByteEnumField("next_payload", None, IKEv2_payload_type),
ByteField("res", 0),
FieldLenField("length", None, "load", "H", adjust=lambda pkt, x:x + 8),
ShortEnumField("group", 0, IKEv2TransformTypes['GroupDesc'][1]),
ShortField("res2", 0),
StrLenField("load", "", length_from=lambda x:x.length - 8),
]
class IKEv2_payload_IDi(IKEv2_class):
name = "IKEv2 Identification - Initiator"
overload_fields = {IKEv2: {"next_payload": 35}}
fields_desc = [
ByteEnumField("next_payload", None, IKEv2_payload_type),
ByteField("res", 0),
FieldLenField("length", None, "load", "H", adjust=lambda pkt, x:x + 8),
ByteEnumField("IDtype", 1, {1: "IPv4_addr", 2: "FQDN", 3: "Email_addr", 5: "IPv6_addr", 11: "Key"}), # noqa: E501
ByteEnumField("ProtoID", 0, {0: "Unused"}),
ShortEnumField("Port", 0, {0: "Unused"}),
# IPField("IdentData","127.0.0.1"),
10: "OFPBAC_MATCH_INCONSISTENT", # noqa: E501
11: "OFPBAC_UNSUPPORTED_ORDER", # noqa: E501
12: "OFPBAC_BAD_TAG",
13: "OFPBAC_BAD_SET_TYPE",
14: "OFPBAC_BAD_SET_LEN",
15: "OFPBAC_BAD_SET_ARGUMENT"}), # noqa: E501
OFPacketField("data", "", Raw)]
class OFPETBadInstruction(_ofp_header):
name = "OFPET_BAD_INSTRUCTION"
fields_desc = [ByteEnumField("version", 0x04, ofp_version),
ByteEnumField("type", 1, ofp_type),
ShortField("len", None),
IntField("xid", 0),
ShortEnumField("errtype", 3, ofp_error_type),
ShortEnumField("errcode", 0, {0: "OFPBIC_UNKNOWN_INST",
1: "OFPBIC_UNSUP_INST",
2: "OFPBIC_BAD_TABLE_ID",
3: "OFPBIC_UNSUP_METADATA",
4: "OFPBIC_UNSUP_METADATA_MASK", # noqa: E501
5: "OFPBIC_BAD_EXPERIMENTER",
6: "OFPBIC_BAD_EXP_TYPE",
7: "OFPBIC_BAD_LEN",
8: "OFPBIC_EPERM"}),
OFPacketField("data", "", Raw)]
class OFPETBadMatch(_ofp_header):
name = "OFPET_BAD_MATCH"
fields_desc = [ByteEnumField("version", 0x04, ofp_version),
ByteEnumField("type", 1, ofp_type),
"""
Specific version that selects the right Trusted Authority (previous TA*)
class to be used for dissection based on idtype.
"""
def m2i(self, pkt, m):
idtype = ord(m[0])
cls = self.cls
if idtype in _tls_trusted_authority_cls:
cls = _tls_trusted_authority_cls[idtype]
return cls(m)
class TLS_Ext_TrustedCAInd(TLS_Ext_Unknown): # RFC 4366
name = "TLS Extension - Trusted CA Indication"
fields_desc = [ShortEnumField("type", 3, _tls_ext),
ShortField("len", None),
FieldLenField("talen", None, length_of="ta"),
_TAListField("ta", [], Raw,
length_from=lambda pkt: pkt.talen)]
class TLS_Ext_TruncatedHMAC(TLS_Ext_Unknown): # RFC 4366
name = "TLS Extension - Truncated HMAC"
fields_desc = [ShortEnumField("type", 4, _tls_ext),
ShortField("len", None)]
class ResponderID(Packet):
name = "Responder ID structure"
fields_desc = [FieldLenField("respidlen", None, length_of="respid"),
StrLenField("respid", "",
dnsclasses = {1: 'IN', 2: 'CS', 3: 'CH', 4: 'HS', 255: 'ANY'}
class DNSQR(InheritOriginDNSStrPacket):
name = "DNS Question Record"
show_indent = 0
fields_desc = [DNSStrField("qname", "www.example.com"),
ShortEnumField("qtype", 1, dnsqtypes),
ShortEnumField("qclass", 1, dnsclasses)]
# RFC 2671 - Extension Mechanisms for DNS (EDNS0)
class EDNS0TLV(Packet):
name = "DNS EDNS0 TLV"
fields_desc = [ShortEnumField("optcode", 0, {0: "Reserved", 1: "LLQ", 2: "UL", 3: "NSID", 4: "Reserved", 5: "PING"}), # noqa: E501
FieldLenField("optlen", None, "optdata", fmt="H"),
StrLenField("optdata", "", length_from=lambda pkt: pkt.optlen)] # noqa: E501
def extract_padding(self, p):
return "", p
class DNSRROPT(InheritOriginDNSStrPacket):
name = "DNS OPT Resource Record"
fields_desc = [DNSStrField("rrname", ""),
ShortEnumField("type", 41, dnstypes),
ShortField("rclass", 4096),
ByteField("extrcode", 0),
ByteField("version", 0),
# version 0 means EDNS0
BitEnumField("z", 32768, 16, {32768: "D0"}),
class OFPMatch(Packet):
name = "OFP_MATCH"
fields_desc = [FlagsField("wildcards1", None, 12, ["DL_VLAN_PCP",
"NW_TOS"]),
BitField("nw_dst_mask", None, 6),
BitField("nw_src_mask", None, 6),
FlagsField("wildcards2", None, 8, ["IN_PORT",
"DL_VLAN",
"DL_SRC",
"DL_DST",
"DL_TYPE",
"NW_PROTO",
"TP_SRC",
"TP_DST"]),
ShortEnumField("in_port", None, ofp_port_no),
MACField("dl_src", None),
MACField("dl_dst", None),
ShortField("dl_vlan", None),
ByteField("dl_vlan_pcp", None),
XByteField("pad1", None),
ShortField("dl_type", None),
ByteField("nw_tos", None),
ByteField("nw_proto", None),
XShortField("pad2", None),
IPField("nw_src", "0"),
IPField("nw_dst", "0"),
ShortField("tp_src", None),
ShortField("tp_dst", None)]
def extract_padding(self, s):
return b"", s
FieldLenField("optlen", None, length_of="sipservers"),
IP6ListField("sipservers", [],
length_from=lambda pkt: pkt.optlen)]
class DHCP6OptDNSServers(_DHCP6OptGuessPayload): # RFC3646
name = "DHCP6 Option - DNS Recursive Name Server"
fields_desc = [ShortEnumField("optcode", 23, dhcp6opts),
FieldLenField("optlen", None, length_of="dnsservers"),
IP6ListField("dnsservers", [],
length_from=lambda pkt: pkt.optlen)]
class DHCP6OptDNSDomains(_DHCP6OptGuessPayload): # RFC3646
name = "DHCP6 Option - Domain Search List option"
fields_desc = [ShortEnumField("optcode", 24, dhcp6opts),
FieldLenField("optlen", None, length_of="dnsdomains"),
DomainNameListField("dnsdomains", [],
length_from=lambda pkt: pkt.optlen)]
# TODO: Implement iaprefopts correctly when provided with more
# information about it.
class DHCP6OptIAPrefix(_DHCP6OptGuessPayload): # RFC3633
name = "DHCP6 Option - IA_PD Prefix option"
fields_desc = [ShortEnumField("optcode", 26, dhcp6opts),
FieldLenField("optlen", None, length_of="iaprefopts",
adjust=lambda pkt, x: x + 25),
IntField("preflft", 0),
IntField("validlft", 0),
ByteField("plen", 48), # TODO: Challenge that default value
ShortEnumField("stats_type", 2, ofp_stats_types),
FlagsField("flags", 0, 16, []),
LongField("packet_count", 0),
LongField("byte_count", 0),
IntField("flow_count", 0),
XIntField("pad", 0)]
overload_fields = {TCP: {"dport": 6653}}
class OFPTStatsRequestTable(_ofp_header):
name = "OFPST_STATS_REQUEST_TABLE"
fields_desc = [ByteEnumField("version", 0x01, ofp_version),
ByteEnumField("type", 16, ofp_type),
ShortField("len", None),
IntField("xid", 0),
ShortEnumField("stats_type", 3, ofp_stats_types),
FlagsField("flags", 0, 16, [])]
overload_fields = {TCP: {"sport": 6653}}
class OFPTableStats(Packet):
def extract_padding(self, s):
return b"", s
name = "OFP_TABLE_STATS"
fields_desc = [ByteField("table_id", 0),
X3BytesField("pad", 0),
StrFixedLenField("name", "", 32),
FlagsField("wildcards1", 0x003, 12, ["DL_VLAN_PCP",
"NW_TOS"]),
BitField("nw_dst_mask", 63, 6), # 32 would be enough