Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class PPP_ECP_Option_OUI(PPP_ECP_Option):
fields_desc = [
ByteEnumField("type", 0, _PPP_ecpopttypes),
FieldLenField("len", None, length_of="data", fmt="B",
adjust=lambda _, val: val + 6),
StrFixedLenField("oui", "", 3),
ByteField("subtype", 0),
StrLenField("data", "", length_from=lambda pkt: pkt.len - 6),
]
class PPP_ECP(Packet):
fields_desc = [
ByteEnumField("code", 1, _PPP_conftypes),
XByteField("id", 0),
FieldLenField("len", None, fmt="H", length_of="options",
adjust=lambda _, val: val + 4),
PacketListField("options", [], PPP_ECP_Option,
length_from=lambda pkt: pkt.len - 4),
]
# Link Control Protocol (RFC 1661)
_PPP_lcptypes = {1: "Configure-Request",
2: "Configure-Ack",
3: "Configure-Nak",
4: "Configure-Reject",
5: "Terminate-Request",
6: "Terminate-Ack",
1: "OFPCR_ROLE_EQUAL",
2: "OFPCR_ROLE_MASTER",
3: "OFPCR_ROLE_SLAVE"}),
XIntField("pad", 0),
LongField("generation_id", 0)]
class OFPTRoleReply(OFPTRoleRequest):
name = "OFPT_ROLE_REPLY"
type = 25
class OFPTGetAsyncRequest(_ofp_header):
name = "OFPT_GET_ASYNC_REQUEST"
fields_desc = [ByteEnumField("version", 0x04, ofp_version),
ByteEnumField("type", 26, ofp_type),
ShortField("len", 8),
IntField("xid", 0)]
ofp_packet_in_reason = ["NO_MATCH",
"ACTION",
"INVALID_TTL"]
ofp_port_reason = ["ADD",
"DELETE",
"MODIFY"]
ofp_flow_removed_reason = ["IDLE_TIMEOUT",
"HARD_TIMEOUT",
"DELETE",
"GROUP_DELETE"]
]
ALLOWED_RETURN_CODE = {
0: 'Success',
1: 'Success',
2: 'Success',
128: 'Failure'
}
class MQTTSuback(Packet):
name = "MQTT suback"
fields_desc = [
ShortField("msgid", None),
ByteEnumField("retcode", None, ALLOWED_RETURN_CODE)
]
class MQTTTopic(Packet):
name = "MQTT topic"
fields_desc = [
FieldLenField("len", None, length_of="topic"),
StrLenField("topic", "", length_from=lambda pkt:pkt.len)
]
def guess_payload_class(self, payload):
return conf.padding_layer
def cb_topic(pkt, lst, cur, remain):
"""
class Dot15d4Cmd(Packet):
name = "802.15.4 Command"
fields_desc = [
XLEShortField("dest_panid", 0xFFFF),
# Users should correctly set the dest_addr field. By default is 0x0 for construction to work. # noqa: E501
dot15d4AddressField("dest_addr", 0x0, length_of="fcf_destaddrmode"),
ConditionalField(XLEShortField("src_panid", 0x0), \
lambda pkt:util_srcpanid_present(pkt)),
ConditionalField(dot15d4AddressField("src_addr", None,
length_of="fcf_srcaddrmode"),
lambda pkt:pkt.underlayer.getfieldval("fcf_srcaddrmode") != 0), # noqa: E501
# Security field present if fcf_security == True
ConditionalField(PacketField("aux_sec_header", Dot15d4AuxSecurityHeader(), Dot15d4AuxSecurityHeader), # noqa: E501
lambda pkt:pkt.underlayer.getfieldval("fcf_security") is True), # noqa: E501
ByteEnumField("cmd_id", 0, {
1: "AssocReq", # Association request
2: "AssocResp", # Association response
3: "DisassocNotify", # Disassociation notification
4: "DataReq", # Data request
5: "PANIDConflictNotify", # PAN ID conflict notification
6: "OrphanNotify", # Orphan notification
7: "BeaconReq", # Beacon request
8: "CoordRealign", # coordinator realignment
9: "GTSReq" # GTS request
# 0x0a - 0xff reserved
}),
# TODO command payload
]
def mysummary(self):
return self.sprintf("802.15.4 Command %Dot15d4Cmd.cmd_id% ( %Dot15dCmd.src_panid%:%Dot15d4Cmd.src_addr% -> %Dot15d4Cmd.dest_panid%:%Dot15d4Cmd.dest_addr% )") # noqa: E501
TACACSACNTSTATUS = {1: 'Success',
2: 'Error',
33: 'Follow'}
class TacacsAccountingRequest(Packet):
'''
Tacacs accounting request body from section 6.1
https://tools.ietf.org/html/draft-ietf-opsawg-tacacs-06#section-6.1
'''
name = 'Tacacs Accounting Request Body'
fields_desc = [ByteEnumField('flags', 0, TACACSACNTFLAGS),
ByteEnumField('authen_method', 0, TACACSAUTHORTYPE),
ByteEnumField('priv_lvl', 1, TACACSPRIVLEVEL),
ByteEnumField('authen_type', 1, TACACSAUTHENTYPE),
ByteEnumField('authen_service', 1, TACACSAUTHENSERVICE),
FieldLenField('user_len', None, fmt='!B', length_of='user'),
FieldLenField('port_len', None, fmt='!B', length_of='port'),
FieldLenField('rem_addr_len', None, fmt='!B', length_of='rem_addr'), # noqa: E501
FieldLenField('arg_cnt', None, fmt='!B', count_of='arg_len_list'), # noqa: E501
FieldListField('arg_len_list', [], ByteField('', 0),
length_from=lambda pkt: pkt.arg_cnt),
StrLenField('user', '', length_from=lambda x: x.user_len),
StrLenField('port', '', length_from=lambda x: x.port_len),
StrLenField('rem_addr', '', length_from=lambda x: x.rem_addr_len)] # noqa: E501
def guess_payload_class(self, pay):
if self.arg_cnt > 0:
]
def mysummary(self):
return self.sprintf("802.15.4 Association Response Payload ( Association Status: %Dot15d4CmdAssocResp.association_status% Assigned Address: %Dot15d4CmdAssocResp.short_address% )") # noqa: E501
class Dot15d4CmdDisassociation(Packet):
name = "802.15.4 Disassociation Notification Payload"
fields_desc = [
# Disassociation Reason
# 0x00 == Reserved
# 0x01 == The coordinator wishes the device to leave the PAN
# 0x02 == The device wishes to leave the PAN
# 0x03 - 0x7f == Reserved
# 0x80 - 0xff == Reserved for MAC primitive enumeration values
ByteEnumField("disassociation_reason", 0x02, {1: 'coord_wishes_device_to_leave', 2: 'device_wishes_to_leave'}), # noqa: E501
]
def mysummary(self):
return self.sprintf("802.15.4 Disassociation Notification Payload ( Disassociation Reason %Dot15d4CmdDisassociation.disassociation_reason% )") # noqa: E501
class Dot15d4CmdGTSReq(Packet):
name = "802.15.4 GTS request command"
fields_desc = [
# GTS Characteristics field (1 octet)
# Reserved (bits 6-7)
BitField("reserved", 0, 2),
# Characteristics Type (bit 5)
BitField("charact_type", 0, 1),
# GTS Direction (bit 4)
BitField("gts_dir", 0, 1),
)
class PPP_LCP_Code_Reject(PPP_LCP):
fields_desc = [
ByteEnumField("code", 7, _PPP_lcptypes),
XByteField("id", 0),
FieldLenField("len", None, fmt="H", length_of="rejected_packet",
adjust=lambda _, val: val + 4),
PacketField("rejected_packet", None, PPP_LCP),
]
class PPP_LCP_Protocol_Reject(PPP_LCP):
fields_desc = [
ByteEnumField("code", 8, _PPP_lcptypes),
XByteField("id", 0),
FieldLenField("len", None, fmt="H", length_of="rejected_information",
adjust=lambda _, val: val + 6),
ShortEnumField("rejected_protocol", None, _PPP_PROTOCOLS),
PacketField("rejected_information", None, Packet),
]
class PPP_LCP_Discard_Request(PPP_LCP):
fields_desc = [
ByteEnumField("code", 11, _PPP_lcptypes),
XByteField("id", 0),
FieldLenField("len", None, fmt="H", length_of="data",
adjust=lambda _, val: val + 8),
IntField("magic_number", None),
StrLenField("data", "", length_from=lambda pkt: pkt.len - 8),
BitField("instance", 0, 4),
ShortField("PortNumber", RandShort())]
class IE_APN_Restriction(gtp.IE_Base):
name = "IE APN Restriction"
fields_desc = [ByteEnumField("ietype", 127, IEType),
ShortField("length", None),
BitField("CR_flag", 0, 4),
BitField("instance", 0, 4),
ByteField("APN_Restriction", 0)]
class IE_SelectionMode(gtp.IE_Base):
name = "IE Selection Mode"
fields_desc = [ByteEnumField("ietype", 128, IEType),
ShortField("length", None),
BitField("CR_flag", 0, 4),
BitField("instance", 0, 4),
BitField("SPARE", 0, 6),
BitField("SelectionMode", 0, 2)]
class IE_MMBR(gtp.IE_Base):
name = "IE Max MBR/APN-AMBR (MMBR)"
fields_desc = [ByteEnumField("ietype", 72, IEType),
ShortField("length", None),
BitField("CR_flag", 0, 4),
BitField("instance", 0, 4),
IntField("uplink_rate", 0),
IntField("downlink_rate", 0)]
"INFO_FLAG_PPS_SYNC",
"INFO_FLAG_MONITOR",
"INFO_FLAG_FILEGEN",
]
class NTPInfoPeerList(Packet):
"""
Used to return raw lists of peers.
"""
name = "info_peer_list"
fields_desc = [
IPField("addr", "0.0.0.0"),
ShortField("port", 0),
ByteEnumField("hmode", 0, _ntp_modes),
FlagsField("flags", 0, 8, _peer_flags),
IntField("v6_flag", 0),
IntField("unused1", 0),
IP6Field("addr6", "::")
]
class NTPInfoPeerSummary(Packet):
"""
Sort of the info that ntpdc returns by default.
"""
name = "info_peer_summary"
fields_desc = [
IPField("dstaddr", "0.0.0.0"),
IPField("srcaddr", "0.0.0.0"),
ShortField("srcport", 0),
15: "L1 LAN Hello",
16: "L2 LAN Hello",
17: "P2P Hello",
18: "L1 LSP",
20: "L2 LSP",
24: "L1 CSNP",
25: "L2 CSNP",
26: "L1 PSNP",
27: "L2 PSNP"
}
class ISIS_CommonHdr(Packet):
name = "ISIS Common Header"
fields_desc = [
ByteEnumField("nlpid", 0x83, network_layer_protocol_ids),
ByteField("hdrlen", None),
ByteField("version", 1),
ByteField("idlen", 0),
ByteEnumField("pdutype", None, _isis_pdu_names),
ByteField("pduversion", 1),
ByteField("hdrreserved", 0),
ByteField("maxareaaddr", 0)
]
def post_build(self, pkt, pay):
# calculating checksum if requested
pdu = pkt + pay
checksumInfo = self[1].checksum_info(self.hdrlen)
if checksumInfo is not None:
(cbegin, cpos) = checksumInfo