class SAPRouterInfoClient(PacketNoPadded): """SAP Router Protocol Information Request Client info This packet is used to return the information of a connected client. """ name = "SAP Router Client Info" fields_desc = [ # 137 bytes length IntField("id", 1), BitField("flag_XXX1", 0, 1), BitField("flag_XXX2", 0, 1), BitField("flag_XXX3", 0, 1), BitField("flag_XXX4", 0, 1), BitField("flag_XXX5", 0, 1), BitField("flag_traced", 0, 1), BitField("flag_connected", 0, 1), BitField("flag_routed", 0, 1), LongField("connected_on", 0), StrNullFixedLenField("address", None, length=45), StrNullFixedLenField("partner", None, length=45), StrNullFixedLenField("service", None, length=27), StrFixedLenField("XXX3", None, length=4), ]
class DNSRRTSIG(_DNSRRdummy): name = "DNS TSIG Resource Record" fields_desc = [ DNSStrField("rrname", ""), ShortEnumField("type", 250, dnstypes), ShortEnumField("rclass", 1, dnsclasses), IntField("ttl", 0), ShortField("rdlen", None), DNSStrField("algo_name", "hmac-sha1"), TimeSignedField("time_signed", 0), ShortField("fudge", 0), FieldLenField("mac_len", 20, fmt="!H", length_of="mac_data"), # noqa: E501 StrLenField("mac_data", "", length_from=lambda pkt: pkt.mac_len), # noqa: E501 ShortField("original_id", 0), ShortField("error", 0), FieldLenField("other_len", 0, fmt="!H", length_of="other_data"), # noqa: E501 StrLenField("other_data", "", length_from=lambda pkt: pkt.other_len) # noqa: E501 ]
class OFPETFlowModFailed(_ofp_header): name = "OFPET_FLOW_MOD_FAILED" fields_desc = [ ByteEnumField("version", 0x01, ofp_version), ByteEnumField("type", 1, ofp_type), ShortField("len", None), IntField("xid", 0), ShortEnumField("errtype", 3, ofp_error_type), ShortEnumField( "errcode", 0, { 0: "OFPFMFC_ALL_TABLES_FULL", 1: "OFPFMFC_OVERLAP", 2: "OFPFMFC_EPERM", 3: "OFPFMFC_BAD_EMERG_TIMEOUT", # noqa: E501 4: "OFPFMFC_BAD_COMMAND", 5: "OFPFMFC_UNSUPPORTED" }), OFPacketField("data", "", Raw) ] overload_fields = {TCP: {"dport": 6653}}
class DNSRRNSEC3(_DNSRRdummy): name = "DNS NSEC3 Resource Record" fields_desc = [ DNSStrField("rrname", ""), ShortEnumField("type", 50, dnstypes), ShortEnumField("rclass", 1, dnsclasses), IntField("ttl", 0), ShortField("rdlen", None), ByteField("hashalg", 0), BitEnumField("flags", 0, 8, {1: "Opt-Out"}), ShortField("iterations", 0), FieldLenField("saltlength", 0, fmt="!B", length_of="salt"), StrLenField("salt", "", length_from=lambda x: x.saltlength), FieldLenField("hashlength", 0, fmt="!B", length_of="nexthashedownername"), # noqa: E501 StrLenField("nexthashedownername", "", length_from=lambda x: x.hashlength), # noqa: E501 RRlistField("typebitmaps", "") ]
class RadiusAttr_Vendor_Specific(RadiusAttribute): """ Implements the "Vendor-Specific" attribute, as described in RFC 2865. """ name = "Vendor-Specific" fields_desc = [ ByteEnumField("type", 26, _radius_attribute_types), FieldLenField("len", None, "value", "B", adjust=lambda pkt, x: len(pkt.value) + 8), IntField("vendor_id", 0), ByteField("vendor_type", 0), FieldLenField("vendor_len", None, "value", "B", adjust=lambda p, x: len(p.value) + 2), StrLenField("value", "", length_from=lambda p: p.vendor_len - 2) ]
class PPTPWANErrorNotify(PPTP): name = "PPTP WAN Error Notify" fields_desc = [ LenField("len", 40), ShortEnumField("type", 1, _PPTP_msg_type), XIntField("magic_cookie", _PPTP_MAGIC_COOKIE), ShortEnumField("ctrl_msg_type", 14, _PPTP_ctrl_msg_type), XShortField("reserved_0", 0x0000), ShortField("peer_call_id", 1), XShortField("reserved_1", 0x0000), IntField("crc_errors", 0), IntField("framing_errors", 0), IntField("hardware_overruns", 0), IntField("buffer_overruns", 0), IntField("time_out_errors", 0), IntField("alignment_errors", 0) ]
class AH(Packet): """ Authentication Header See https://tools.ietf.org/rfc/rfc4302.txt """ name = 'AH' def __get_icv_len(self): """ Compute the size of the ICV based on the payloadlen field. Padding size is included as it can only be known from the authentication # noqa: E501 algorithm provided by the Security Association. """ # payloadlen = length of AH in 32-bit words (4-byte units), minus "2" # payloadlen = 3 32-bit word fixed fields + ICV + padding - 2 # ICV = (payloadlen + 2 - 3 - padding) in 32-bit words return (self.payloadlen - 1) * 4 fields_desc = [ ByteEnumField('nh', None, IP_PROTOS), ByteField('payloadlen', None), ShortField('reserved', None), XIntField('spi', 0x0), IntField('seq', 0), XStrLenField('icv', None, length_from=__get_icv_len), # Padding len can only be known with the SecurityAssociation.auth_algo XStrLenField('padding', None, length_from=lambda x: 0), ] overload_fields = { IP: {'proto': socket.IPPROTO_AH}, IPv6: {'nh': socket.IPPROTO_AH}, IPv6ExtHdrHopByHop: {'nh': socket.IPPROTO_AH}, IPv6ExtHdrDestOpt: {'nh': socket.IPPROTO_AH}, IPv6ExtHdrRouting: {'nh': socket.IPPROTO_AH}, }
class MulticastSubscriberConfigInfo(EntityClass): class_id = 310 attributes = [ ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}), ECA(ByteField("me_type", None), {AA.R, AA.W, AA.SBC}), ECA(ShortField("mcast_operations_profile_pointer", None), {AA.R, AA.W, AA.SBC}), ECA(ShortField("max_simultaneous_groups", None), {AA.R, AA.W, AA.SBC}, optional=True), ECA(IntField("max_multicast_bandwidth", None), {AA.R, AA.W, AA.SBC}, optional=True), ECA(ByteField("bandwidth_enforcement", None), {AA.R, AA.W, AA.SBC}, optional=True), # TODO: need to make table and add column data ECA(StrFixedLenField("multicast_service_package_table", None, 20), {AA.R, AA.W}, optional=True), # TODO: need to make table and add column data ECA(StrFixedLenField("allowed_preview_groups_table", None, 22), {AA.R, AA.W}, optional=True), ] mandatory_operations = {OP.Create, OP.Delete, OP.Set, OP.Get, OP.GetNext}
class OFPETBadAction(_ofp_header): name = "OFPET_BAD_ACTION" fields_desc = [ ByteEnumField("version", 0x01, ofp_version), ByteEnumField("type", 1, ofp_type), ShortField("len", None), IntField("xid", 0), ShortEnumField("errtype", 2, ofp_error_type), ShortEnumField( "errcode", 0, { 0: "OFPBAC_BAD_TYPE", 1: "OFPBAC_BAD_LEN", 2: "OFPBAC_BAD_VENDOR", 3: "OFPBAC_BAD_VENDOR_TYPE", 4: "OFPBAC_BAD_OUT_PORT", 5: "OFPBAC_BAD_ARGUMENT", 6: "OFPBAC_EPERM", 7: "OFPBAC_TOO_MANY", 8: "OFPBAC_BAD_QUEUE" }), OFPacketField("data", "", Raw) ] overload_fields = {TCP: {"dport": 6653}}
class OFPETBadRequest(_ofp_header): name = "OFPET_BAD_REQUEST" fields_desc = [ ByteEnumField("version", 0x01, ofp_version), ByteEnumField("type", 1, ofp_type), ShortField("len", None), IntField("xid", 0), ShortEnumField("errtype", 1, ofp_error_type), ShortEnumField( "errcode", 0, { 0: "OFPBRC_BAD_VERSION", 1: "OFPBRC_BAD_TYPE", 2: "OFPBRC_BAD_STAT", 3: "OFPBRC_BAD_VENDOR", 4: "OFPBRC_BAD_SUBTYPE", 5: "OFPBRC_EPERM", 6: "OFPBRC_BAD_LEN", 7: "OFPBRC_BUFFER_EMPTY", 8: "OFPBRC_BUFFER_UNKNOWN" }), OFPacketField("data", "", Raw) ] overload_fields = {TCP: {"dport": 6653}}
class VQP(Packet): name = "VQP" fields_desc = [ ByteField("const", 1), ByteEnumField( "type", 1, { 1: "requestPort", 2: "responseVLAN", 3: "requestReconfirm", 4: "responseReconfirm" }), ByteEnumField("errorcodeaction", 0, { 0: "none", 3: "accessDenied", 4: "shutdownPort", 5: "wrongDomain" }), ByteEnumField("unknown", 2, { 2: "inGoodResponse", 6: "inRequests" }), IntField("seq", 0), ]
class ISIS_ExtendedIpPrefix(Packet): name = "ISIS Extended IP Prefix" fields_desc = [ IntField("metric", 1), BitField("updown", 0, 1), BitField("subtlvindicator", 0, 1), BitFieldLenField("pfxlen", None, 6, length_of="pfx"), IPPrefixField("pfx", None, wordbytes=1, length_from=lambda x: x.pfxlen), ConditionalField( FieldLenField("subtlvslen", None, length_of=lambda x: x.subtlvs, fmt="B"), lambda pkt: pkt.subtlvindicator == 1), ConditionalField( PacketListField("subtlvs", [], _isis_guess_subtlv_cls, length_from=lambda x: x.subtlvslen), lambda pkt: pkt.subtlvindicator == 1) ] def extract_padding(self, s): return "", s
class BMPHeader(Packet): """ The header of any BMP message. References: https://tools.ietf.org/html/rfc7854, """ name = "BMPHeader" fields_desc = [ ByteField("version", 4), IntField("len", None), ByteEnumField("type", 0, _bmp_message_types), ] def post_build(self, p, pay): if self.len is None: length = len(p) if pay: length = length + len(pay) position_after_length = self.fields_desc[0].sz + self.fields_desc[ 1].sz p = (p[:self.fields_desc[0].sz] + struct.pack("!I", length) + p[position_after_length:]) return p + pay
class NBNSRequest(Packet): name = "NBNS request" fields_desc = [ShortField("NAME_TRN_ID", 0), ShortField("FLAGS", 0x2910), ShortField("QDCOUNT", 1), ShortField("ANCOUNT", 0), ShortField("NSCOUNT", 0), ShortField("ARCOUNT", 1), NetBIOSNameField("QUESTION_NAME", "windows"), ShortEnumField("SUFFIX", 0x4141, _NETBIOS_SUFFIXES), ByteField("NULL", 0), ShortEnumField("QUESTION_TYPE", 0x20, _NETBIOS_QRTYPES), ShortEnumField("QUESTION_CLASS", 1, _NETBIOS_QRCLASS), ShortEnumField("RR_NAME", 0xC00C, _NETBIOS_RNAMES), ShortEnumField("RR_TYPE", 0x20, _NETBIOS_QRTYPES), ShortEnumField("RR_CLASS", 1, _NETBIOS_QRCLASS), IntField("TTL", 0), ShortField("RDLENGTH", 6), BitEnumField("G", 0, 1, _NETBIOS_GNAMES), BitEnumField("OWNER_NODE_TYPE", 00, 2, _NETBIOS_OWNER_MODE_TYPES), BitEnumField("UNUSED", 0, 13, {0: "Unused"}), IPField("NB_ADDRESS", "127.0.0.1")]
class CircuitPack(EntityClass): class_id = 6 attributes = [ ECA(StrFixedLenField("managed_entity_id", None, 22), {AA.R, AA.SBC}), ECA(ByteField("type", None), {AA.R, AA.SBC}), ECA(ByteField("number_of_ports", None), {AA.R}, optional=True), ECA(StrFixedLenField("serial_number", None, 8), {AA.R}), ECA(StrFixedLenField("version", None, 14), {AA.R}), ECA(StrFixedLenField("vendor_id", None, 4), {AA.R}), ECA(ByteField("administrative_state", None), {AA.R, AA.W, AA.SBC}), ECA(ByteField("operational_state", None), {AA.R}, optional=True), ECA(ByteField("bridged_or_ip_ind", None), {AA.R, AA.W}, optional=True), ECA(StrFixedLenField("equipment_id", None, 20), {AA.R}, optional=True), ECA(ByteField("card_configuration", None), {AA.R, AA.W, AA.SBC}), # not really mandatory, see spec ECA(ByteField("total_tcont_buffer_number", None), {AA.R}), ECA(ByteField("total_priority_queue_number", None), {AA.R}), ECA(ByteField("total_traffic_scheduler_number", None), {AA.R}), ECA(IntField("power_sched_override", None), {AA.R, AA.W}, optional=True) ] mandatory_operations = {OP.Get, OP.Set, OP.Reboot} optional_operations = {OP.Create, OP.Delete, OP.Test}
class NetflowRecordV1(Packet): name = "Netflow Record v1" fields_desc = [IPField("ipsrc", "0.0.0.0"), IPField("ipdst", "0.0.0.0"), IPField("nexthop", "0.0.0.0"), ShortField("inputIfIndex", 0), ShortField("outpuIfIndex", 0), IntField("dpkts", 0), IntField("dbytes", 0), IntField("starttime", 0), IntField("endtime", 0), ShortField("srcport", 0), ShortField("dstport", 0), ShortField("padding", 0), ByteField("proto", 0), ByteField("tos", 0), IntField("padding1", 0), IntField("padding2", 0)]
class AVSWLANHeader(Packet): """ iwpriv eth1 set_prismhdr 1 """ name = "AVS WLAN Monitor Header" fields_desc = [IntField("version", 1), IntField("len", 64), LongField("mactime", 0), LongField("hosttime", 0), IntEnumField("phytype", 0, AVSWLANPhyType), IntField("channel", 0), IntField("datarate", 0), IntField("antenna", 0), IntField("priority", 0), IntEnumField("ssi_type", 0, AVSWLANSSIType), SignedIntField("ssi_signal", 0), SignedIntField("ssi_noise", 0), IntEnumField("preamble", 0, AVSWLANPreambleType), IntEnumField("encoding", 0, AVSWLANEncodingType), ]
class OFPTFlowMod(_ofp_header): name = "OFPT_FLOW_MOD" fields_desc = [ByteEnumField("version", 0x01, ofp_version), ByteEnumField("type", 14, ofp_type), ShortField("len", None), IntField("xid", 0), PacketField("match", OFPMatch(), OFPMatch), LongField("cookie", 0), ShortEnumField("cmd", 0, {0: "OFPFC_ADD", 1: "OFPFC_MODIFY", 2: "OFPFC_MODIFY_STRICT", 3: "OFPFC_DELETE", 4: "OFPFC_DELETE_STRICT"}), ShortField("idle_timeout", 0), ShortField("hard_timeout", 0), ShortField("priority", 0), IntEnumField("buffer_id", "NO_BUFFER", ofp_buffer), ShortEnumField("out_port", "NONE", ofp_port_no), FlagsField("flags", 0, 16, ["SEND_FLOW_REM", "CHECK_OVERLAP", "EMERG"]), PacketListField("actions", [], OFPAT, ofp_action_cls, length_from=lambda pkt:pkt.len - 72)]
class SwAds(Packet): fields_desc = [ BitField('fl', 0, 1), BitField('free_ar', 0, 1), BitField('reserved1', 0, 14), ShortField('pkey_index', 0), ByteField('reserved2', 0), BitField('grh', 0, 1), BitField('mlid', 0, 7), ShortField('rlid', 0), BitField('ack_timeout', 0, 5), BitField('reserved3', 0, 3), ByteField('src_addr_index', 0), BitField('log_rtm', 0, 4), BitField('stat_rate', 0, 4), ByteField('hop_limit', 0), BitField('reserved4', 0, 4), BitField('tclass', 0, 8), BitField('flow_label', 0, 20), FieldListField('rgid_rip', [0 for x in range(4)], IntField('', 0), count_from=lambda pkt: 4), BitField('reserved5', 0, 4), BitField('f_dscp', 0, 1), BitField('f_ecn', 0, 1), BitField('reserved6', 0, 1), BitField('f_eth_prio', 0, 1), BitField('ecn', 0, 2), BitField('dscp', 0, 6), ShortField('udp_sport', 0), BitField('dei_cfi_reserved_from_prm_041', 0, 1), BitField('eth_prio', 0, 3), BitField('sl', 0, 4), ByteField('vhca_port_num', 0), MACField('rmac', '00:00:00:00:00:00'), ]
class MACsec(Packet): """representation of one MACsec frame""" name = '802.1AE' fields_desc = [BitField('Ver', 0, 1), BitField('ES', 0, 1), BitField('SC', 0, 1), BitField('SCB', 0, 1), BitField('E', 0, 1), BitField('C', 0, 1), BitField('an', 0, 2), BitField('reserved', 0, 2), BitField('shortlen', 0, 6), IntField("pn", 1), ConditionalField(PacketField("sci", None, MACsecSCI), lambda pkt: pkt.SC), # noqa: E501 ConditionalField(XShortEnumField("type", None, ETHER_TYPES), lambda pkt: pkt.type is not None)] def mysummary(self): summary = self.sprintf("an=%MACsec.an%, pn=%MACsec.pn%") if self.SC: summary += self.sprintf(", sci=%MACsec.sci%") if self.type is not None: summary += self.sprintf(", %MACsec.type%") return summary
class HSFZ(Packet): name = 'HSFZ' fields_desc = [ IntField('length', None), ShortEnumField('type', 1, { 0x01: "message", 0x02: "echo" }), XByteField('src', 0), XByteField('dst', 0), ] def hashret(self): # type: () -> bytes hdr_hash = struct.pack("B", self.src ^ self.dst) pay_hash = self.payload.hashret() return hdr_hash + pay_hash def answers(self, other): # type: (Packet) -> int if other.__class__ == self.__class__: return self.payload.answers(other.payload) return 0 def extract_padding(self, s): # type: (bytes) -> Tuple[bytes, bytes] return s[:self.length - 2], s[self.length - 2:] def post_build(self, pkt, pay): # type: (bytes, bytes) -> bytes """ This will set the LenField 'length' to the correct value. """ if self.length is None: pkt = struct.pack("!I", len(pay) + 2) + pkt[4:] return pkt + pay
class AH(Packet): """ Authentication Header See https://tools.ietf.org/rfc/rfc4302.txt """ name = 'AH' fields_desc = [ ByteEnumField('nh', None, IP_PROTOS), ByteField('payloadlen', None), ShortField('reserved', None), XIntField('spi', 0x0), IntField('seq', 0), StrField('icv', None), StrField('padding', None), ] overload_fields = { IP: { 'proto': socket.IPPROTO_AH }, IPv6: { 'nh': socket.IPPROTO_AH }, IPv6ExtHdrHopByHop: { 'nh': socket.IPPROTO_AH }, IPv6ExtHdrDestOpt: { 'nh': socket.IPPROTO_AH }, IPv6ExtHdrRouting: { 'nh': socket.IPPROTO_AH }, }
class DNSRR(InheritOriginDNSStrPacket): name = "DNS Resource Record" show_indent = 0 fields_desc = [ DNSStrField("rrname", ""), ShortEnumField("type", 1, dnstypes), ShortEnumField("rclass", 1, dnsclasses), IntField("ttl", 0), FieldLenField("rdlen", None, length_of="rdata", fmt="H"), MultipleTypeField( [ # A (IPField("rdata", "0.0.0.0"), lambda pkt: pkt.type == 1), # AAAA (IP6Field("rdata", "::"), lambda pkt: pkt.type == 28), # NS, MD, MF, CNAME, PTR (DNSStrField("rdata", "", length_from=lambda pkt: pkt.rdlen), lambda pkt: pkt.type in [2, 3, 4, 5, 12]), # TEXT (DNSTextField("rdata", [], length_from=lambda pkt: pkt.rdlen), lambda pkt: pkt.type == 16), ], StrLenField("rdata", "", length_from=lambda pkt: pkt.rdlen)) ]
class File_Object(Packet): name = 'File Object' fields_desc = [ IntField('length', 0), StrLenField('fh', b'', length_from=lambda pkt: pkt.length), StrLenField('fill', b'', length_from=lambda pkt: (4 - pkt.length) % 4) ] def set(self, new_filehandle, length=None, fill=None): # convert filehandle to bytes if it was passed as a string if new_filehandle.isalnum(): new_filehandle = unhexlify(new_filehandle) if length is None: length = len(new_filehandle) if fill is None: fill = b'\x00' * ((4 - length) % 4) self.length = length self.fh = new_filehandle self.fill = fill def extract_padding(self, s): return '', s
class OmciFrame(Packet): name = "OmciFrame" fields_desc = [ ShortField("transaction_id", 0), ByteField("message_type", None), ByteField("omci", 0x0a), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciCreate), align=36), lambda pkt: pkt.message_type == OmciCreate.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciCreateResponse), align=36), lambda pkt: pkt.message_type == OmciCreateResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciDelete), align=36), lambda pkt: pkt.message_type == OmciDelete.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciDeleteResponse), align=36), lambda pkt: pkt.message_type == OmciDeleteResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciSet), align=36), lambda pkt: pkt.message_type == OmciSet.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciSetResponse), align=36), lambda pkt: pkt.message_type == OmciSetResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciGet), align=36), lambda pkt: pkt.message_type == OmciGet.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciGetResponse), align=36), lambda pkt: pkt.message_type == OmciGetResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciGetAllAlarms), align=36), lambda pkt: pkt.message_type == OmciGetAllAlarms.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciGetAllAlarmsResponse), align=36), lambda pkt: pkt.message_type == OmciGetAllAlarmsResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciGetAllAlarmsNext), align=36), lambda pkt: pkt.message_type == OmciGetAllAlarmsNext.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciGetAllAlarmsNextResponse), align=36), lambda pkt: pkt.message_type == OmciGetAllAlarmsNextResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciMibUpload), align=36), lambda pkt: pkt.message_type == OmciMibUpload.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciMibUploadResponse), align=36), lambda pkt: pkt.message_type == OmciMibUploadResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciMibUploadNext), align=36), lambda pkt: pkt.message_type == OmciMibUploadNext.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciMibUploadNextResponse), align=36), lambda pkt: pkt.message_type == OmciMibUploadNextResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciMibReset), align=36), lambda pkt: pkt.message_type == OmciMibReset.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciMibResetResponse), align=36), lambda pkt: pkt.message_type == OmciMibResetResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciAlarmNotification), align=36), lambda pkt: pkt.message_type == OmciAlarmNotification.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciAttributeValueChange), align=36), lambda pkt: pkt.message_type == OmciAttributeValueChange.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciTestResult), align=36), lambda pkt: pkt.message_type == OmciTestResult.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciReboot), align=36), lambda pkt: pkt.message_type == OmciReboot.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciRebootResponse), align=36), lambda pkt: pkt.message_type == OmciRebootResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciGetNext), align=36), lambda pkt: pkt.message_type == OmciGetNext.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciGetNextResponse), align=36), lambda pkt: pkt.message_type == OmciGetNextResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciSynchronizeTime), align=36), lambda pkt: pkt.message_type == OmciSynchronizeTime.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciSynchronizeTimeResponse), align=36), lambda pkt: pkt.message_type == OmciSynchronizeTimeResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciGetCurrentData), align=36), lambda pkt: pkt.message_type == OmciGetCurrentData.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciGetCurrentDataResponse), align=36), lambda pkt: pkt.message_type == OmciGetCurrentDataResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciStartSoftwareDownload), align=36), lambda pkt: pkt.message_type == OmciStartSoftwareDownload.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciStartSoftwareDownloadResponse), align=36), lambda pkt: pkt.message_type == OmciStartSoftwareDownloadResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciDownloadSection), align=36), lambda pkt: pkt.message_type == OmciDownloadSection.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciDownloadSectionLast), align=36), lambda pkt: pkt.message_type == OmciDownloadSectionLast.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciDownloadSectionResponse), align=36), lambda pkt: pkt.message_type == OmciDownloadSectionResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciEndSoftwareDownload), align=36), lambda pkt: pkt.message_type == OmciEndSoftwareDownload.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciEndSoftwareDownloadResponse), align=36), lambda pkt: pkt.message_type == OmciEndSoftwareDownloadResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciActivateImage), align=36), lambda pkt: pkt.message_type == OmciActivateImage.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciActivateImageResponse), align=36), lambda pkt: pkt.message_type == OmciActivateImageResponse.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciCommitImage), align=36), lambda pkt: pkt.message_type == OmciCommitImage.message_id), ConditionalField( FixedLenField(PacketField("omci_message", None, OmciCommitImageResponse), align=36), lambda pkt: pkt.message_type == OmciCommitImageResponse.message_id), # TODO add entries for remaining OMCI message types IntField("omci_trailer", 0x00000028) ] # We needed to patch the do_dissect(...) method of Packet, because # it wiped out already dissected conditional fields with None if they # referred to the same field name. We marked the only new line of code # with "Extra condition added". def do_dissect(self, s): raw = s self.raw_packet_cache_fields = {} for f in self.fields_desc: if not s: break s, fval = f.getfield(self, s) # We need to track fields with mutable values to discard # .raw_packet_cache when needed. if f.islist or f.holds_packets: self.raw_packet_cache_fields[f.name] = f.do_copy(fval) # Extra condition added if fval is not None or f.name not in self.fields: self.fields[f.name] = fval assert (raw.endswith(s)) self.raw_packet_cache = raw[:-len(s)] if s else raw self.explicit = 1 return s
class SDESChunk(Packet): name = "SDES chunk" fields_desc = [ IntField('sourcesync', None), PacketListField('items', None, pkt_cls=SDESItem) ]
class PPP_LCP_Magic_Number_Option(PPP_LCP_Option): fields_desc = [ ByteEnumField("type", 5, _PPP_lcp_optiontypes), ByteField("len", 6), IntField("magic_number", None), ]
40: "NIS_domain", 41: IPField("NIS_server", "0.0.0.0"), 42: IPField("NTP_server", "0.0.0.0"), 43: "vendor_specific", 44: IPField("NetBIOS_server", "0.0.0.0"), 45: IPField("NetBIOS_dist_server", "0.0.0.0"), 50: IPField("requested_addr", "0.0.0.0"), 51: IntField("lease_time", 43200), 53: ByteEnumField("message-type", 1, DHCPTypes), 54: IPField("server_id", "0.0.0.0"), 55: _DHCPParamReqFieldListField("param_req_list", [], ByteField("opcode", 0), length_from=lambda x: 1), # noqa: E501 56: "error_message", 57: ShortField("max_dhcp_size", 1500), 58: IntField("renewal_time", 21600), 59:
class SAPDiagStep(Packet): name = "SAP Diag Dialog Step" fields_desc = [IntField("step", 0)]
def __init__(self, name): IntField.__init__(self, name, 0x800E0000)
def i2h(self, pkt, x): return IntField.i2h(self, pkt, x & 0xFFFF)
class SAPEnqueue(PacketNoPadded): """SAP Enqueue Server packet This packet is used for general Enqueue packets. """ name = "SAP Enqueue" fields_desc = [ StrFixedLenField("magic_bytes", "\xab\xcd\xe1\x23", 4), IntField("id", 0), LenField("len", None, fmt="!I"), LenField("len_frag", None, fmt="!I"), ByteEnumKeysField("dest", 0x00, enqueue_dest_values), ByteEnumKeysField("opcode", 0x00, enqueue_conn_admin_opcode_values), ByteField("more_frags", 0), ByteEnumKeysField("type", 0x00, enqueue_type_values), # Server Admin fields ConditionalField(StrNullFixedLenField("adm_eyecatcher1", "ENC", 3), lambda pkt: pkt.dest == 3), ConditionalField(ByteField("adm_version", 1), lambda pkt: pkt.dest == 3), ConditionalField(ByteField("adm_padd1", 0), lambda pkt: pkt.dest == 3), ConditionalField(ByteField("adm_padd2", 0), lambda pkt: pkt.dest == 3), ConditionalField(ByteField("adm_padd3", 0), lambda pkt: pkt.dest == 3), ConditionalField(StrFixedLenField("adm_eyecatcher2", "#EAA", 4), lambda pkt: pkt.dest == 3), ConditionalField(ByteField("adm_1", 1), lambda pkt: pkt.dest == 3), ConditionalField(IntField("adm_len", 0), lambda pkt: pkt.dest == 3), ConditionalField( ByteEnumKeysField("adm_opcode", 0, enqueue_server_admin_opcode_values), lambda pkt: pkt.dest == 3), ConditionalField(ByteField("adm_flags", 0), lambda pkt: pkt.dest == 3), ConditionalField(IntField("adm_rc", 0), lambda pkt: pkt.dest == 3), ConditionalField(StrFixedLenField("adm_eyecatcher3", "#EAE", 4), lambda pkt: pkt.dest == 3), # Server Admin Trace fields ConditionalField( ByteField("adm_trace_protocol_version", 1), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( ByteEnumKeysField("adm_trace_action", 3, enqueue_server_admin_trace_action_values), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( ByteEnumKeysField("adm_trace_limit", 0, enqueue_server_admin_trace_limit_values), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( ByteEnumKeysField("adm_trace_thread", 0, enqueue_server_admin_trace_thread_values), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( IntField("adm_trace_unknown1", 0), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( IntField("adm_trace_level", 1), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( IntField("adm_trace_level1", 1), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( ByteField("adm_trace_logging", 0), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( IntField("adm_trace_max_file_size", 20 * 1024 * 1024), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( FieldLenField("adm_trace_nopatterns", 0, count_of="adm_trace_patterns", fmt="!I"), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( FieldLenField("adm_trace_nopatterns1", 0, count_of="adm_trace_patterns", fmt="!I"), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( IntField("adm_trace_unknown3", 37), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( StrFixedLenField("adm_trace_eyecatcher4", "#EAH", 4), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( PacketListField("adm_trace_patterns", None, SAPEnqueueTracePattern, count_from=lambda pkt: pkt.adm_trace_nopatterns), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), ConditionalField( StrFixedLenField("adm_trace_eyecatcher5", "#EAD", 4), lambda pkt: pkt.dest == 3 and pkt.adm_opcode in [0x06]), # Connection Admin fields ConditionalField( FieldLenField("params_count", None, count_of="params", fmt="!I"), lambda pkt: pkt.dest == 6 and pkt.opcode in [1, 2]), ConditionalField( PacketListField("params", None, SAPEnqueueParam, count_from=lambda pkt: pkt.params_count), lambda pkt: pkt.dest == 6 and pkt.opcode in [1, 2]), ] def post_build(self, pkt, pay): """Adjust the len and len_frags fields after the build of the whole packet. """ l = struct.pack("!I", len(pkt) + len(pay)) pkt = pkt[:8] + l + l + pkt[16:] return pkt + pay
def h2i(self, pkt, x): return IntField.h2i(self, pkt, (x if x is not None else 0) | 0x800E0000) # noqa: E501