pypcapkit 1.6.2__pp312-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pcapkit/__init__.py +107 -0
- pcapkit/__main__.py +158 -0
- pcapkit/all.py +168 -0
- pcapkit/const/__init__.py +143 -0
- pcapkit/const/arp/__init__.py +35 -0
- pcapkit/const/arp/hardware.py +195 -0
- pcapkit/const/arp/operation.py +145 -0
- pcapkit/const/dccp/__init__.py +58 -0
- pcapkit/const/dccp/ack_vector_state.py +73 -0
- pcapkit/const/dccp/drop_code.py +79 -0
- pcapkit/const/dccp/feature.py +106 -0
- pcapkit/const/dccp/option.py +133 -0
- pcapkit/const/dccp/packet_type.py +103 -0
- pcapkit/const/dccp/reset_code.py +115 -0
- pcapkit/const/esp/__init__.py +49 -0
- pcapkit/const/esp/cipher.py +265 -0
- pcapkit/const/esp/integrity.py +154 -0
- pcapkit/const/ftp/__init__.py +35 -0
- pcapkit/const/ftp/command.py +659 -0
- pcapkit/const/ftp/return_code.py +409 -0
- pcapkit/const/hip/__init__.py +121 -0
- pcapkit/const/hip/certificate.py +91 -0
- pcapkit/const/hip/cipher.py +79 -0
- pcapkit/const/hip/di.py +73 -0
- pcapkit/const/hip/ecdsa_curve.py +73 -0
- pcapkit/const/hip/ecdsa_low_curve.py +70 -0
- pcapkit/const/hip/eddsa_curve.py +79 -0
- pcapkit/const/hip/esp_transform_suite.py +112 -0
- pcapkit/const/hip/group.py +100 -0
- pcapkit/const/hip/hi_algorithm.py +100 -0
- pcapkit/const/hip/hit_suite.py +82 -0
- pcapkit/const/hip/nat_traversal.py +76 -0
- pcapkit/const/hip/notify_message.py +214 -0
- pcapkit/const/hip/packet.py +103 -0
- pcapkit/const/hip/parameter.py +391 -0
- pcapkit/const/hip/registration.py +82 -0
- pcapkit/const/hip/registration_failure.py +98 -0
- pcapkit/const/hip/suite.py +85 -0
- pcapkit/const/hip/transport.py +73 -0
- pcapkit/const/http/__init__.py +52 -0
- pcapkit/const/http/error_code.py +108 -0
- pcapkit/const/http/frame.py +109 -0
- pcapkit/const/http/method.py +329 -0
- pcapkit/const/http/setting.py +110 -0
- pcapkit/const/http/status_code.py +347 -0
- pcapkit/const/icmp/__init__.py +52 -0
- pcapkit/const/icmp/destination_unreachable_code.py +111 -0
- pcapkit/const/icmp/parameter_problem_code.py +70 -0
- pcapkit/const/icmp/time_exceeded_code.py +67 -0
- pcapkit/const/icmp/type.py +179 -0
- pcapkit/const/icmpv6/__init__.py +52 -0
- pcapkit/const/icmpv6/destination_unreachable_code.py +91 -0
- pcapkit/const/icmpv6/parameter_problem_code.py +94 -0
- pcapkit/const/icmpv6/time_exceeded_code.py +67 -0
- pcapkit/const/icmpv6/type.py +209 -0
- pcapkit/const/ieee802_11/__init__.py +52 -0
- pcapkit/const/ieee802_11/control_subtype.py +106 -0
- pcapkit/const/ieee802_11/data_subtype.py +97 -0
- pcapkit/const/ieee802_11/extension_subtype.py +70 -0
- pcapkit/const/ieee802_11/management_subtype.py +109 -0
- pcapkit/const/ieee802_11/type.py +73 -0
- pcapkit/const/igmp/__init__.py +37 -0
- pcapkit/const/igmp/record_type.py +73 -0
- pcapkit/const/igmp/type.py +112 -0
- pcapkit/const/ipv4/__init__.py +79 -0
- pcapkit/const/ipv4/classification_level.py +77 -0
- pcapkit/const/ipv4/option_class.py +69 -0
- pcapkit/const/ipv4/option_number.py +151 -0
- pcapkit/const/ipv4/protection_authority.py +77 -0
- pcapkit/const/ipv4/qs_function.py +65 -0
- pcapkit/const/ipv4/router_alert.py +268 -0
- pcapkit/const/ipv4/tos_del.py +65 -0
- pcapkit/const/ipv4/tos_ecn.py +69 -0
- pcapkit/const/ipv4/tos_pre.py +77 -0
- pcapkit/const/ipv4/tos_rel.py +65 -0
- pcapkit/const/ipv4/tos_thr.py +65 -0
- pcapkit/const/ipv4/ts_flag.py +67 -0
- pcapkit/const/ipv6/__init__.py +70 -0
- pcapkit/const/ipv6/extension_header.py +86 -0
- pcapkit/const/ipv6/option.py +151 -0
- pcapkit/const/ipv6/option_action.py +69 -0
- pcapkit/const/ipv6/qs_function.py +65 -0
- pcapkit/const/ipv6/router_alert.py +280 -0
- pcapkit/const/ipv6/routing.py +94 -0
- pcapkit/const/ipv6/seed_id.py +69 -0
- pcapkit/const/ipv6/smf_dpd_mode.py +65 -0
- pcapkit/const/ipv6/tagger_id.py +76 -0
- pcapkit/const/ipx/__init__.py +37 -0
- pcapkit/const/ipx/packet.py +86 -0
- pcapkit/const/ipx/socket.py +121 -0
- pcapkit/const/l2tp/__init__.py +30 -0
- pcapkit/const/l2tp/type.py +65 -0
- pcapkit/const/linux/__init__.py +28 -0
- pcapkit/const/linux/arphrd.py +91 -0
- pcapkit/const/mh/__init__.py +259 -0
- pcapkit/const/mh/access_type.py +106 -0
- pcapkit/const/mh/ack_status_code.py +85 -0
- pcapkit/const/mh/ani_suboption.py +88 -0
- pcapkit/const/mh/auth_subtype.py +67 -0
- pcapkit/const/mh/binding_ack_flag.py +82 -0
- pcapkit/const/mh/binding_error.py +65 -0
- pcapkit/const/mh/binding_revocation.py +73 -0
- pcapkit/const/mh/binding_update_flag.py +97 -0
- pcapkit/const/mh/cga_extension.py +80 -0
- pcapkit/const/mh/cga_sec.py +71 -0
- pcapkit/const/mh/cga_type.py +82 -0
- pcapkit/const/mh/dhcp_support_mode.py +67 -0
- pcapkit/const/mh/dns_status_code.py +79 -0
- pcapkit/const/mh/dsmip6_tls_packet.py +76 -0
- pcapkit/const/mh/dsmipv6_home_address.py +88 -0
- pcapkit/const/mh/enumerating_algorithm.py +70 -0
- pcapkit/const/mh/fb_ack_status.py +76 -0
- pcapkit/const/mh/fb_action.py +85 -0
- pcapkit/const/mh/fb_indication_trigger.py +79 -0
- pcapkit/const/mh/fb_type.py +73 -0
- pcapkit/const/mh/flow_id_status.py +91 -0
- pcapkit/const/mh/flow_id_suboption.py +85 -0
- pcapkit/const/mh/handoff_type.py +85 -0
- pcapkit/const/mh/handover_ack_flag.py +70 -0
- pcapkit/const/mh/handover_ack_status.py +106 -0
- pcapkit/const/mh/handover_initiate_flag.py +73 -0
- pcapkit/const/mh/handover_initiate_status.py +76 -0
- pcapkit/const/mh/home_address_reply.py +85 -0
- pcapkit/const/mh/lla_code.py +77 -0
- pcapkit/const/mh/lma_mag_suboption.py +73 -0
- pcapkit/const/mh/mn_group_id.py +73 -0
- pcapkit/const/mh/mn_id_subtype.py +91 -0
- pcapkit/const/mh/operator_id.py +77 -0
- pcapkit/const/mh/option.py +274 -0
- pcapkit/const/mh/packet.py +133 -0
- pcapkit/const/mh/qos_attribute.py +103 -0
- pcapkit/const/mh/revocation_status_code.py +97 -0
- pcapkit/const/mh/revocation_trigger.py +100 -0
- pcapkit/const/mh/status_code.py +246 -0
- pcapkit/const/mh/traffic_selector.py +76 -0
- pcapkit/const/mh/upa_status.py +85 -0
- pcapkit/const/mh/upn_reason.py +94 -0
- pcapkit/const/ngap/__init__.py +44 -0
- pcapkit/const/ngap/procedure_code.py +223 -0
- pcapkit/const/ngap/protocol_ie.py +937 -0
- pcapkit/const/ospf/__init__.py +37 -0
- pcapkit/const/ospf/authentication.py +79 -0
- pcapkit/const/ospf/packet.py +85 -0
- pcapkit/const/pcapng/__init__.py +71 -0
- pcapkit/const/pcapng/block_type.py +166 -0
- pcapkit/const/pcapng/filter_type.py +62 -0
- pcapkit/const/pcapng/hash_algorithm.py +73 -0
- pcapkit/const/pcapng/option_type.py +422 -0
- pcapkit/const/pcapng/record_type.py +70 -0
- pcapkit/const/pcapng/secrets_type.py +69 -0
- pcapkit/const/pcapng/tls_key_label.py +89 -0
- pcapkit/const/pcapng/verdict_type.py +67 -0
- pcapkit/const/radiotap/__init__.py +116 -0
- pcapkit/const/radiotap/ampdu_flags.py +85 -0
- pcapkit/const/radiotap/channel_flags.py +94 -0
- pcapkit/const/radiotap/eht_known.py +124 -0
- pcapkit/const/radiotap/field_type.py +165 -0
- pcapkit/const/radiotap/flags.py +85 -0
- pcapkit/const/radiotap/he_data1_known.py +103 -0
- pcapkit/const/radiotap/he_data2_known.py +88 -0
- pcapkit/const/radiotap/he_mu_flags1_known.py +85 -0
- pcapkit/const/radiotap/he_mu_flags2_known.py +67 -0
- pcapkit/const/radiotap/he_mu_other_user_known.py +85 -0
- pcapkit/const/radiotap/lsig_data1.py +67 -0
- pcapkit/const/radiotap/mcs_known.py +85 -0
- pcapkit/const/radiotap/rx_flags.py +64 -0
- pcapkit/const/radiotap/s1g_known.py +85 -0
- pcapkit/const/radiotap/timestamp_flags.py +67 -0
- pcapkit/const/radiotap/tx_flags.py +82 -0
- pcapkit/const/radiotap/usig_common_known.py +85 -0
- pcapkit/const/radiotap/vht_coding.py +73 -0
- pcapkit/const/radiotap/vht_flags.py +84 -0
- pcapkit/const/radiotap/vht_known.py +90 -0
- pcapkit/const/reg/__init__.py +54 -0
- pcapkit/const/reg/apptype/__init__.py +164 -0
- pcapkit/const/reg/apptype/apptype.py +5233 -0
- pcapkit/const/reg/apptype/dccp.py +112 -0
- pcapkit/const/reg/apptype/sctp.py +432 -0
- pcapkit/const/reg/apptype/tcp.py +25154 -0
- pcapkit/const/reg/apptype/udp.py +24563 -0
- pcapkit/const/reg/ethertype.py +740 -0
- pcapkit/const/reg/linktype.py +811 -0
- pcapkit/const/reg/transtype.py +552 -0
- pcapkit/const/sctp/__init__.py +49 -0
- pcapkit/const/sctp/cause_code.py +146 -0
- pcapkit/const/sctp/chunk.py +164 -0
- pcapkit/const/sctp/parameter.py +170 -0
- pcapkit/const/sctp/payload_protocol_identifier.py +325 -0
- pcapkit/const/sslv2/__init__.py +37 -0
- pcapkit/const/sslv2/handshake_type.py +88 -0
- pcapkit/const/sslv2/version.py +64 -0
- pcapkit/const/tcp/__init__.py +47 -0
- pcapkit/const/tcp/checksum.py +69 -0
- pcapkit/const/tcp/flags.py +96 -0
- pcapkit/const/tcp/mp_tcp_option.py +95 -0
- pcapkit/const/tcp/option.py +210 -0
- pcapkit/const/tls/__init__.py +44 -0
- pcapkit/const/tls/content_type.py +99 -0
- pcapkit/const/tls/extension_type.py +382 -0
- pcapkit/const/tls/handshake_type.py +154 -0
- pcapkit/const/vlan/__init__.py +32 -0
- pcapkit/const/vlan/priority_level.py +85 -0
- pcapkit/corekit/__init__.py +64 -0
- pcapkit/corekit/checksum/__init__.py +24 -0
- pcapkit/corekit/checksum/internet.py +253 -0
- pcapkit/corekit/context.py +248 -0
- pcapkit/corekit/decorators.py +328 -0
- pcapkit/corekit/enum.py +742 -0
- pcapkit/corekit/fields/__init__.py +46 -0
- pcapkit/corekit/fields/collections.py +646 -0
- pcapkit/corekit/fields/field.py +643 -0
- pcapkit/corekit/fields/ipaddress.py +582 -0
- pcapkit/corekit/fields/misc.py +843 -0
- pcapkit/corekit/fields/numbers.py +1279 -0
- pcapkit/corekit/fields/strings.py +445 -0
- pcapkit/corekit/infoclass.py +1231 -0
- pcapkit/corekit/io.py +980 -0
- pcapkit/corekit/module.py +133 -0
- pcapkit/corekit/multidict.py +676 -0
- pcapkit/corekit/packet.py +179 -0
- pcapkit/corekit/protochain.py +266 -0
- pcapkit/corekit/schema/__init__.py +20 -0
- pcapkit/corekit/schema/byteorder.py +89 -0
- pcapkit/corekit/schema/ipaddress.py +210 -0
- pcapkit/corekit/schema/jumbogram.py +66 -0
- pcapkit/corekit/schema/padding.py +50 -0
- pcapkit/corekit/schema/shortread.py +150 -0
- pcapkit/corekit/sentinels.py +597 -0
- pcapkit/corekit/version.py +40 -0
- pcapkit/dumpkit/__init__.py +14 -0
- pcapkit/dumpkit/common.py +778 -0
- pcapkit/dumpkit/null.py +72 -0
- pcapkit/dumpkit/pcap.py +292 -0
- pcapkit/foundation/__init__.py +63 -0
- pcapkit/foundation/analysis/__init__.py +27 -0
- pcapkit/foundation/analysis/dtls.py +61 -0
- pcapkit/foundation/analysis/ip.py +88 -0
- pcapkit/foundation/analysis/tcp.py +87 -0
- pcapkit/foundation/engines/__init__.py +35 -0
- pcapkit/foundation/engines/_pcap_backend.py +358 -0
- pcapkit/foundation/engines/dpkt.py +680 -0
- pcapkit/foundation/engines/engine.py +318 -0
- pcapkit/foundation/engines/pcap.py +259 -0
- pcapkit/foundation/engines/pcap_ct.py +469 -0
- pcapkit/foundation/engines/pcapng.py +513 -0
- pcapkit/foundation/engines/pypcap.py +386 -0
- pcapkit/foundation/engines/pypcapfile.py +477 -0
- pcapkit/foundation/engines/pyshark.py +374 -0
- pcapkit/foundation/engines/scapy.py +451 -0
- pcapkit/foundation/extraction.py +1833 -0
- pcapkit/foundation/reassembly/__init__.py +55 -0
- pcapkit/foundation/reassembly/data/__init__.py +43 -0
- pcapkit/foundation/reassembly/data/data.py +300 -0
- pcapkit/foundation/reassembly/data/dtls.py +186 -0
- pcapkit/foundation/reassembly/data/ip.py +203 -0
- pcapkit/foundation/reassembly/data/tcp.py +296 -0
- pcapkit/foundation/reassembly/dtls.py +340 -0
- pcapkit/foundation/reassembly/ip.py +639 -0
- pcapkit/foundation/reassembly/ipv4.py +80 -0
- pcapkit/foundation/reassembly/ipv6.py +206 -0
- pcapkit/foundation/reassembly/reassembly.py +605 -0
- pcapkit/foundation/reassembly/tcp.py +870 -0
- pcapkit/foundation/registry/__init__.py +56 -0
- pcapkit/foundation/registry/foundation.py +362 -0
- pcapkit/foundation/registry/protocols/__init__.py +67 -0
- pcapkit/foundation/registry/protocols/application.py +119 -0
- pcapkit/foundation/registry/protocols/internet.py +506 -0
- pcapkit/foundation/registry/protocols/link.py +378 -0
- pcapkit/foundation/registry/protocols/misc.py +352 -0
- pcapkit/foundation/registry/protocols/protocol.py +519 -0
- pcapkit/foundation/registry/protocols/transport.py +647 -0
- pcapkit/foundation/traceflow/__init__.py +45 -0
- pcapkit/foundation/traceflow/data/__init__.py +17 -0
- pcapkit/foundation/traceflow/data/data.py +193 -0
- pcapkit/foundation/traceflow/data/tcp.py +212 -0
- pcapkit/foundation/traceflow/tcp.py +581 -0
- pcapkit/foundation/traceflow/traceflow.py +593 -0
- pcapkit/interface/__init__.py +23 -0
- pcapkit/interface/core.py +265 -0
- pcapkit/interface/misc.py +186 -0
- pcapkit/interface/registry.py +116 -0
- pcapkit/protocols/__init__.py +95 -0
- pcapkit/protocols/application/NotImplemented/bgp.py +0 -0
- pcapkit/protocols/application/NotImplemented/dhcp.py +0 -0
- pcapkit/protocols/application/NotImplemented/dhcpv6.py +0 -0
- pcapkit/protocols/application/NotImplemented/dns.py +0 -0
- pcapkit/protocols/application/NotImplemented/imap.py +0 -0
- pcapkit/protocols/application/NotImplemented/ldap.py +0 -0
- pcapkit/protocols/application/NotImplemented/mqtt.py +0 -0
- pcapkit/protocols/application/NotImplemented/nntp.py +0 -0
- pcapkit/protocols/application/NotImplemented/ntp.py +0 -0
- pcapkit/protocols/application/NotImplemented/onc_rpc.py +0 -0
- pcapkit/protocols/application/NotImplemented/pop.py +0 -0
- pcapkit/protocols/application/NotImplemented/rip.py +0 -0
- pcapkit/protocols/application/NotImplemented/rtp.py +0 -0
- pcapkit/protocols/application/NotImplemented/sip.py +0 -0
- pcapkit/protocols/application/NotImplemented/smtp.py +0 -0
- pcapkit/protocols/application/NotImplemented/snmp.py +0 -0
- pcapkit/protocols/application/NotImplemented/ssh.py +0 -0
- pcapkit/protocols/application/NotImplemented/telnet.py +0 -0
- pcapkit/protocols/application/NotImplemented/xmpp.py +0 -0
- pcapkit/protocols/application/__init__.py +79 -0
- pcapkit/protocols/application/application.py +189 -0
- pcapkit/protocols/application/drarp/__init__.py +14 -0
- pcapkit/protocols/application/drarp/protocol.py +53 -0
- pcapkit/protocols/application/dtls/__init__.py +30 -0
- pcapkit/protocols/application/dtls/data.py +150 -0
- pcapkit/protocols/application/dtls/protocol.py +1137 -0
- pcapkit/protocols/application/dtls/schema.py +157 -0
- pcapkit/protocols/application/ftp/__init__.py +27 -0
- pcapkit/protocols/application/ftp/data.py +72 -0
- pcapkit/protocols/application/ftp/protocol.py +410 -0
- pcapkit/protocols/application/ftp/schema.py +21 -0
- pcapkit/protocols/application/ftp_data/__init__.py +14 -0
- pcapkit/protocols/application/ftp_data/protocol.py +97 -0
- pcapkit/protocols/application/http/__init__.py +14 -0
- pcapkit/protocols/application/http/protocol.py +773 -0
- pcapkit/protocols/application/httpv1/__init__.py +28 -0
- pcapkit/protocols/application/httpv1/data.py +98 -0
- pcapkit/protocols/application/httpv1/protocol.py +610 -0
- pcapkit/protocols/application/httpv1/schema.py +29 -0
- pcapkit/protocols/application/httpv2/__init__.py +61 -0
- pcapkit/protocols/application/httpv2/data.py +347 -0
- pcapkit/protocols/application/httpv2/protocol.py +1724 -0
- pcapkit/protocols/application/httpv2/schema.py +430 -0
- pcapkit/protocols/application/ngap/__init__.py +29 -0
- pcapkit/protocols/application/ngap/data.py +124 -0
- pcapkit/protocols/application/ngap/protocol.py +578 -0
- pcapkit/protocols/application/ngap/schema.py +29 -0
- pcapkit/protocols/application/ospf/__init__.py +29 -0
- pcapkit/protocols/application/ospf/data.py +79 -0
- pcapkit/protocols/application/ospf/protocol.py +544 -0
- pcapkit/protocols/application/ospf/schema.py +109 -0
- pcapkit/protocols/application/rarp/__init__.py +14 -0
- pcapkit/protocols/application/rarp/protocol.py +111 -0
- pcapkit/protocols/application/ssl/__init__.py +43 -0
- pcapkit/protocols/application/ssl/data.py +322 -0
- pcapkit/protocols/application/ssl/protocol.py +1522 -0
- pcapkit/protocols/application/sslv2/__init__.py +32 -0
- pcapkit/protocols/application/sslv2/data.py +93 -0
- pcapkit/protocols/application/sslv2/protocol.py +543 -0
- pcapkit/protocols/application/sslv2/schema.py +304 -0
- pcapkit/protocols/application/sslv3/__init__.py +14 -0
- pcapkit/protocols/application/sslv3/protocol.py +51 -0
- pcapkit/protocols/application/tls/__init__.py +25 -0
- pcapkit/protocols/application/tls/data.py +40 -0
- pcapkit/protocols/application/tls/protocol.py +561 -0
- pcapkit/protocols/application/tls/schema.py +44 -0
- pcapkit/protocols/data.py +76 -0
- pcapkit/protocols/internet/NotImplemented/ecn.py +0 -0
- pcapkit/protocols/internet/NotImplemented/shim6.py +0 -0
- pcapkit/protocols/internet/__init__.py +87 -0
- pcapkit/protocols/internet/ah/__init__.py +25 -0
- pcapkit/protocols/internet/ah/data.py +39 -0
- pcapkit/protocols/internet/ah/protocol.py +343 -0
- pcapkit/protocols/internet/ah/schema.py +57 -0
- pcapkit/protocols/internet/esp/__init__.py +25 -0
- pcapkit/protocols/internet/esp/data.py +71 -0
- pcapkit/protocols/internet/esp/protocol.py +1509 -0
- pcapkit/protocols/internet/esp/schema.py +46 -0
- pcapkit/protocols/internet/hip/__init__.py +169 -0
- pcapkit/protocols/internet/hip/data.py +1109 -0
- pcapkit/protocols/internet/hip/protocol.py +5697 -0
- pcapkit/protocols/internet/hip/schema.py +1654 -0
- pcapkit/protocols/internet/hopopt/__init__.py +80 -0
- pcapkit/protocols/internet/hopopt/data.py +445 -0
- pcapkit/protocols/internet/hopopt/protocol.py +2346 -0
- pcapkit/protocols/internet/hopopt/schema.py +686 -0
- pcapkit/protocols/internet/icmp/__init__.py +14 -0
- pcapkit/protocols/internet/icmp/protocol.py +201 -0
- pcapkit/protocols/internet/icmpv4/__init__.py +38 -0
- pcapkit/protocols/internet/icmpv4/data.py +153 -0
- pcapkit/protocols/internet/icmpv4/protocol.py +652 -0
- pcapkit/protocols/internet/icmpv4/schema.py +135 -0
- pcapkit/protocols/internet/icmpv6/__init__.py +40 -0
- pcapkit/protocols/internet/icmpv6/data.py +174 -0
- pcapkit/protocols/internet/icmpv6/protocol.py +735 -0
- pcapkit/protocols/internet/icmpv6/schema.py +144 -0
- pcapkit/protocols/internet/igmp/__init__.py +25 -0
- pcapkit/protocols/internet/igmp/data.py +59 -0
- pcapkit/protocols/internet/igmp/protocol.py +491 -0
- pcapkit/protocols/internet/igmp/schema.py +54 -0
- pcapkit/protocols/internet/igmpv1/__init__.py +14 -0
- pcapkit/protocols/internet/igmpv1/protocol.py +63 -0
- pcapkit/protocols/internet/igmpv2/__init__.py +14 -0
- pcapkit/protocols/internet/igmpv2/protocol.py +65 -0
- pcapkit/protocols/internet/igmpv3/__init__.py +32 -0
- pcapkit/protocols/internet/igmpv3/data.py +150 -0
- pcapkit/protocols/internet/igmpv3/protocol.py +587 -0
- pcapkit/protocols/internet/igmpv3/schema.py +373 -0
- pcapkit/protocols/internet/internet.py +566 -0
- pcapkit/protocols/internet/ip/__init__.py +14 -0
- pcapkit/protocols/internet/ip/protocol.py +205 -0
- pcapkit/protocols/internet/ipsec/__init__.py +14 -0
- pcapkit/protocols/internet/ipsec/protocol.py +48 -0
- pcapkit/protocols/internet/ipv4/__init__.py +68 -0
- pcapkit/protocols/internet/ipv4/data.py +470 -0
- pcapkit/protocols/internet/ipv4/protocol.py +2293 -0
- pcapkit/protocols/internet/ipv4/schema.py +747 -0
- pcapkit/protocols/internet/ipv6/__init__.py +25 -0
- pcapkit/protocols/internet/ipv6/data.py +83 -0
- pcapkit/protocols/internet/ipv6/protocol.py +731 -0
- pcapkit/protocols/internet/ipv6/schema.py +176 -0
- pcapkit/protocols/internet/ipv6_ext/__init__.py +25 -0
- pcapkit/protocols/internet/ipv6_ext/data.py +52 -0
- pcapkit/protocols/internet/ipv6_ext/protocol.py +718 -0
- pcapkit/protocols/internet/ipv6_ext/schema.py +397 -0
- pcapkit/protocols/internet/ipv6_frag/__init__.py +25 -0
- pcapkit/protocols/internet/ipv6_frag/data.py +41 -0
- pcapkit/protocols/internet/ipv6_frag/protocol.py +320 -0
- pcapkit/protocols/internet/ipv6_frag/schema.py +51 -0
- pcapkit/protocols/internet/ipv6_opts/__init__.py +83 -0
- pcapkit/protocols/internet/ipv6_opts/data.py +462 -0
- pcapkit/protocols/internet/ipv6_opts/protocol.py +2335 -0
- pcapkit/protocols/internet/ipv6_opts/schema.py +695 -0
- pcapkit/protocols/internet/ipv6_route/__init__.py +34 -0
- pcapkit/protocols/internet/ipv6_route/data.py +113 -0
- pcapkit/protocols/internet/ipv6_route/protocol.py +936 -0
- pcapkit/protocols/internet/ipv6_route/schema.py +299 -0
- pcapkit/protocols/internet/ipx/__init__.py +26 -0
- pcapkit/protocols/internet/ipx/data.py +59 -0
- pcapkit/protocols/internet/ipx/protocol.py +387 -0
- pcapkit/protocols/internet/ipx/schema.py +53 -0
- pcapkit/protocols/internet/mh/__init__.py +433 -0
- pcapkit/protocols/internet/mh/data.py +2464 -0
- pcapkit/protocols/internet/mh/protocol.py +11753 -0
- pcapkit/protocols/internet/mh/schema.py +3367 -0
- pcapkit/protocols/link/NotImplemented/dsl.py +0 -0
- pcapkit/protocols/link/NotImplemented/eapol.py +1 -0
- pcapkit/protocols/link/NotImplemented/fddi.py +0 -0
- pcapkit/protocols/link/NotImplemented/isdn.py +0 -0
- pcapkit/protocols/link/NotImplemented/ndp.py +0 -0
- pcapkit/protocols/link/NotImplemented/ppp.py +0 -0
- pcapkit/protocols/link/__init__.py +80 -0
- pcapkit/protocols/link/arp/__init__.py +27 -0
- pcapkit/protocols/link/arp/data.py +73 -0
- pcapkit/protocols/link/arp/protocol.py +513 -0
- pcapkit/protocols/link/arp/schema.py +49 -0
- pcapkit/protocols/link/c_tag/__init__.py +14 -0
- pcapkit/protocols/link/c_tag/protocol.py +99 -0
- pcapkit/protocols/link/ethernet/__init__.py +25 -0
- pcapkit/protocols/link/ethernet/data.py +27 -0
- pcapkit/protocols/link/ethernet/protocol.py +221 -0
- pcapkit/protocols/link/ethernet/schema.py +72 -0
- pcapkit/protocols/link/frad/__init__.py +25 -0
- pcapkit/protocols/link/frad/data.py +47 -0
- pcapkit/protocols/link/frad/protocol.py +470 -0
- pcapkit/protocols/link/frad/schema.py +112 -0
- pcapkit/protocols/link/gre/__init__.py +25 -0
- pcapkit/protocols/link/gre/data.py +64 -0
- pcapkit/protocols/link/gre/protocol.py +396 -0
- pcapkit/protocols/link/gre/schema.py +91 -0
- pcapkit/protocols/link/ieee802_11/__init__.py +30 -0
- pcapkit/protocols/link/ieee802_11/data.py +171 -0
- pcapkit/protocols/link/ieee802_11/protocol.py +612 -0
- pcapkit/protocols/link/ieee802_11/schema.py +163 -0
- pcapkit/protocols/link/inarp/__init__.py +14 -0
- pcapkit/protocols/link/inarp/protocol.py +55 -0
- pcapkit/protocols/link/l2tp/__init__.py +26 -0
- pcapkit/protocols/link/l2tp/data.py +72 -0
- pcapkit/protocols/link/l2tp/protocol.py +285 -0
- pcapkit/protocols/link/l2tp/schema.py +122 -0
- pcapkit/protocols/link/l2tpv2/__init__.py +14 -0
- pcapkit/protocols/link/l2tpv2/protocol.py +440 -0
- pcapkit/protocols/link/link.py +226 -0
- pcapkit/protocols/link/linux_sll/__init__.py +14 -0
- pcapkit/protocols/link/linux_sll/protocol.py +421 -0
- pcapkit/protocols/link/linux_sll1/__init__.py +25 -0
- pcapkit/protocols/link/linux_sll1/data.py +41 -0
- pcapkit/protocols/link/linux_sll1/protocol.py +247 -0
- pcapkit/protocols/link/linux_sll1/schema.py +46 -0
- pcapkit/protocols/link/linux_sll2/__init__.py +25 -0
- pcapkit/protocols/link/linux_sll2/data.py +47 -0
- pcapkit/protocols/link/linux_sll2/protocol.py +257 -0
- pcapkit/protocols/link/linux_sll2/schema.py +52 -0
- pcapkit/protocols/link/loopback/__init__.py +25 -0
- pcapkit/protocols/link/loopback/data.py +25 -0
- pcapkit/protocols/link/loopback/protocol.py +334 -0
- pcapkit/protocols/link/loopback/schema.py +33 -0
- pcapkit/protocols/link/netlink/__init__.py +25 -0
- pcapkit/protocols/link/netlink/data.py +40 -0
- pcapkit/protocols/link/netlink/protocol.py +390 -0
- pcapkit/protocols/link/netlink/schema.py +44 -0
- pcapkit/protocols/link/radiotap/__init__.py +103 -0
- pcapkit/protocols/link/radiotap/data.py +768 -0
- pcapkit/protocols/link/radiotap/protocol.py +2264 -0
- pcapkit/protocols/link/radiotap/schema.py +662 -0
- pcapkit/protocols/link/s_tag/__init__.py +14 -0
- pcapkit/protocols/link/s_tag/protocol.py +102 -0
- pcapkit/protocols/link/vlan/__init__.py +27 -0
- pcapkit/protocols/link/vlan/data.py +47 -0
- pcapkit/protocols/link/vlan/protocol.py +269 -0
- pcapkit/protocols/link/vlan/schema.py +77 -0
- pcapkit/protocols/misc/__init__.py +60 -0
- pcapkit/protocols/misc/checksum/__init__.py +28 -0
- pcapkit/protocols/misc/checksum/ip_pseudo/__init__.py +25 -0
- pcapkit/protocols/misc/checksum/ip_pseudo/data.py +41 -0
- pcapkit/protocols/misc/checksum/ip_pseudo/protocol.py +692 -0
- pcapkit/protocols/misc/checksum/ip_pseudo/schema.py +118 -0
- pcapkit/protocols/misc/no_payload/__init__.py +25 -0
- pcapkit/protocols/misc/no_payload/data.py +17 -0
- pcapkit/protocols/misc/no_payload/protocol.py +164 -0
- pcapkit/protocols/misc/no_payload/schema.py +17 -0
- pcapkit/protocols/misc/pcap/__init__.py +30 -0
- pcapkit/protocols/misc/pcap/frame/__init__.py +26 -0
- pcapkit/protocols/misc/pcap/frame/data.py +62 -0
- pcapkit/protocols/misc/pcap/frame/protocol.py +673 -0
- pcapkit/protocols/misc/pcap/frame/schema.py +47 -0
- pcapkit/protocols/misc/pcap/header/__init__.py +26 -0
- pcapkit/protocols/misc/pcap/header/data.py +52 -0
- pcapkit/protocols/misc/pcap/header/protocol.py +391 -0
- pcapkit/protocols/misc/pcap/header/schema.py +103 -0
- pcapkit/protocols/misc/pcapng/__init__.py +160 -0
- pcapkit/protocols/misc/pcapng/data.py +1102 -0
- pcapkit/protocols/misc/pcapng/protocol.py +6960 -0
- pcapkit/protocols/misc/pcapng/schema.py +2825 -0
- pcapkit/protocols/misc/raw/__init__.py +25 -0
- pcapkit/protocols/misc/raw/data.py +35 -0
- pcapkit/protocols/misc/raw/protocol.py +188 -0
- pcapkit/protocols/misc/raw/schema.py +24 -0
- pcapkit/protocols/protocol.py +3145 -0
- pcapkit/protocols/schema.py +1295 -0
- pcapkit/protocols/transport/NotImplemented/rsvp.py +0 -0
- pcapkit/protocols/transport/__init__.py +47 -0
- pcapkit/protocols/transport/dccp/__init__.py +57 -0
- pcapkit/protocols/transport/dccp/data.py +275 -0
- pcapkit/protocols/transport/dccp/protocol.py +1525 -0
- pcapkit/protocols/transport/dccp/schema.py +381 -0
- pcapkit/protocols/transport/sctp/__init__.py +147 -0
- pcapkit/protocols/transport/sctp/data.py +633 -0
- pcapkit/protocols/transport/sctp/protocol.py +3937 -0
- pcapkit/protocols/transport/sctp/schema.py +1007 -0
- pcapkit/protocols/transport/tcp/__init__.py +108 -0
- pcapkit/protocols/transport/tcp/data.py +637 -0
- pcapkit/protocols/transport/tcp/protocol.py +3640 -0
- pcapkit/protocols/transport/tcp/schema.py +1131 -0
- pcapkit/protocols/transport/transport.py +371 -0
- pcapkit/protocols/transport/udp/__init__.py +25 -0
- pcapkit/protocols/transport/udp/data.py +38 -0
- pcapkit/protocols/transport/udp/protocol.py +384 -0
- pcapkit/protocols/transport/udp/schema.py +44 -0
- pcapkit/py.typed +0 -0
- pcapkit/toolkit/__init__.py +88 -0
- pcapkit/toolkit/dpkt.py +909 -0
- pcapkit/toolkit/pcap.py +510 -0
- pcapkit/toolkit/pcap_ct.py +160 -0
- pcapkit/toolkit/pcapng.py +287 -0
- pcapkit/toolkit/pypcap.py +158 -0
- pcapkit/toolkit/pypcapfile.py +917 -0
- pcapkit/toolkit/pyshark.py +628 -0
- pcapkit/toolkit/scapy.py +761 -0
- pcapkit/utilities/__init__.py +41 -0
- pcapkit/utilities/chardet.py +64 -0
- pcapkit/utilities/compat.py +173 -0
- pcapkit/utilities/config.py +446 -0
- pcapkit/utilities/contextvars.py +57 -0
- pcapkit/utilities/datetime.py +117 -0
- pcapkit/utilities/exceptions.py +845 -0
- pcapkit/utilities/importlib.py +123 -0
- pcapkit/utilities/inspect.py +55 -0
- pcapkit/utilities/logging.py +395 -0
- pcapkit/utilities/pickle.py +181 -0
- pcapkit/utilities/warnings.py +538 -0
- pcapkit/vendor/__init__.py +220 -0
- pcapkit/vendor/__main__.py +253 -0
- pcapkit/vendor/arp/__init__.py +27 -0
- pcapkit/vendor/arp/hardware.py +29 -0
- pcapkit/vendor/arp/operation.py +29 -0
- pcapkit/vendor/dccp/__init__.py +44 -0
- pcapkit/vendor/dccp/ack_vector_state.py +29 -0
- pcapkit/vendor/dccp/drop_code.py +29 -0
- pcapkit/vendor/dccp/feature.py +29 -0
- pcapkit/vendor/dccp/option.py +29 -0
- pcapkit/vendor/dccp/packet_type.py +29 -0
- pcapkit/vendor/dccp/reset_code.py +29 -0
- pcapkit/vendor/default.py +823 -0
- pcapkit/vendor/esp/__init__.py +32 -0
- pcapkit/vendor/esp/cipher.py +114 -0
- pcapkit/vendor/esp/integrity.py +111 -0
- pcapkit/vendor/ftp/__init__.py +27 -0
- pcapkit/vendor/ftp/command.py +577 -0
- pcapkit/vendor/ftp/return_code.py +363 -0
- pcapkit/vendor/hip/__init__.py +94 -0
- pcapkit/vendor/hip/certificate.py +29 -0
- pcapkit/vendor/hip/cipher.py +29 -0
- pcapkit/vendor/hip/di.py +29 -0
- pcapkit/vendor/hip/ecdsa_curve.py +29 -0
- pcapkit/vendor/hip/ecdsa_low_curve.py +29 -0
- pcapkit/vendor/hip/eddsa_curve.py +85 -0
- pcapkit/vendor/hip/esp_transform_suite.py +29 -0
- pcapkit/vendor/hip/group.py +87 -0
- pcapkit/vendor/hip/hi_algorithm.py +29 -0
- pcapkit/vendor/hip/hit_suite.py +29 -0
- pcapkit/vendor/hip/nat_traversal.py +29 -0
- pcapkit/vendor/hip/notify_message.py +29 -0
- pcapkit/vendor/hip/packet.py +88 -0
- pcapkit/vendor/hip/parameter.py +88 -0
- pcapkit/vendor/hip/registration.py +29 -0
- pcapkit/vendor/hip/registration_failure.py +29 -0
- pcapkit/vendor/hip/suite.py +29 -0
- pcapkit/vendor/hip/transport.py +29 -0
- pcapkit/vendor/http/__init__.py +39 -0
- pcapkit/vendor/http/error_code.py +94 -0
- pcapkit/vendor/http/frame.py +91 -0
- pcapkit/vendor/http/method.py +309 -0
- pcapkit/vendor/http/setting.py +93 -0
- pcapkit/vendor/http/status_code.py +233 -0
- pcapkit/vendor/icmp/__init__.py +40 -0
- pcapkit/vendor/icmp/destination_unreachable_code.py +80 -0
- pcapkit/vendor/icmp/parameter_problem_code.py +80 -0
- pcapkit/vendor/icmp/time_exceeded_code.py +80 -0
- pcapkit/vendor/icmp/type.py +78 -0
- pcapkit/vendor/icmpv6/__init__.py +40 -0
- pcapkit/vendor/icmpv6/destination_unreachable_code.py +80 -0
- pcapkit/vendor/icmpv6/parameter_problem_code.py +80 -0
- pcapkit/vendor/icmpv6/time_exceeded_code.py +73 -0
- pcapkit/vendor/icmpv6/type.py +78 -0
- pcapkit/vendor/ieee802_11/__init__.py +54 -0
- pcapkit/vendor/ieee802_11/control_subtype.py +107 -0
- pcapkit/vendor/ieee802_11/data_subtype.py +106 -0
- pcapkit/vendor/ieee802_11/extension_subtype.py +95 -0
- pcapkit/vendor/ieee802_11/management_subtype.py +102 -0
- pcapkit/vendor/ieee802_11/type.py +90 -0
- pcapkit/vendor/igmp/__init__.py +27 -0
- pcapkit/vendor/igmp/record_type.py +88 -0
- pcapkit/vendor/igmp/type.py +77 -0
- pcapkit/vendor/ipv4/__init__.py +59 -0
- pcapkit/vendor/ipv4/classification_level.py +90 -0
- pcapkit/vendor/ipv4/option_class.py +80 -0
- pcapkit/vendor/ipv4/option_number.py +105 -0
- pcapkit/vendor/ipv4/protection_authority.py +84 -0
- pcapkit/vendor/ipv4/qs_function.py +78 -0
- pcapkit/vendor/ipv4/router_alert.py +94 -0
- pcapkit/vendor/ipv4/tos_del.py +78 -0
- pcapkit/vendor/ipv4/tos_ecn.py +95 -0
- pcapkit/vendor/ipv4/tos_pre.py +84 -0
- pcapkit/vendor/ipv4/tos_rel.py +78 -0
- pcapkit/vendor/ipv4/tos_thr.py +78 -0
- pcapkit/vendor/ipv4/ts_flag.py +79 -0
- pcapkit/vendor/ipv6/__init__.py +53 -0
- pcapkit/vendor/ipv6/extension_header.py +220 -0
- pcapkit/vendor/ipv6/option.py +104 -0
- pcapkit/vendor/ipv6/option_action.py +90 -0
- pcapkit/vendor/ipv6/qs_function.py +78 -0
- pcapkit/vendor/ipv6/router_alert.py +93 -0
- pcapkit/vendor/ipv6/routing.py +87 -0
- pcapkit/vendor/ipv6/seed_id.py +81 -0
- pcapkit/vendor/ipv6/smf_dpd_mode.py +78 -0
- pcapkit/vendor/ipv6/tagger_id.py +81 -0
- pcapkit/vendor/ipx/__init__.py +39 -0
- pcapkit/vendor/ipx/packet.py +149 -0
- pcapkit/vendor/ipx/socket.py +240 -0
- pcapkit/vendor/l2tp/__init__.py +21 -0
- pcapkit/vendor/l2tp/type.py +79 -0
- pcapkit/vendor/linux/__init__.py +21 -0
- pcapkit/vendor/linux/arphrd.py +100 -0
- pcapkit/vendor/mh/__init__.py +206 -0
- pcapkit/vendor/mh/access_type.py +87 -0
- pcapkit/vendor/mh/ack_status_code.py +88 -0
- pcapkit/vendor/mh/ani_suboption.py +88 -0
- pcapkit/vendor/mh/auth_subtype.py +83 -0
- pcapkit/vendor/mh/binding_ack_flag.py +164 -0
- pcapkit/vendor/mh/binding_error.py +78 -0
- pcapkit/vendor/mh/binding_revocation.py +87 -0
- pcapkit/vendor/mh/binding_update_flag.py +163 -0
- pcapkit/vendor/mh/cga_extension.py +91 -0
- pcapkit/vendor/mh/cga_sec.py +91 -0
- pcapkit/vendor/mh/cga_type.py +74 -0
- pcapkit/vendor/mh/dhcp_support_mode.py +77 -0
- pcapkit/vendor/mh/dns_status_code.py +87 -0
- pcapkit/vendor/mh/dsmip6_tls_packet.py +87 -0
- pcapkit/vendor/mh/dsmipv6_home_address.py +87 -0
- pcapkit/vendor/mh/enumerating_algorithm.py +82 -0
- pcapkit/vendor/mh/fb_ack_status.py +87 -0
- pcapkit/vendor/mh/fb_action.py +88 -0
- pcapkit/vendor/mh/fb_indication_trigger.py +87 -0
- pcapkit/vendor/mh/fb_type.py +88 -0
- pcapkit/vendor/mh/flow_id_status.py +87 -0
- pcapkit/vendor/mh/flow_id_suboption.py +87 -0
- pcapkit/vendor/mh/handoff_type.py +87 -0
- pcapkit/vendor/mh/handover_ack_flag.py +159 -0
- pcapkit/vendor/mh/handover_ack_status.py +87 -0
- pcapkit/vendor/mh/handover_initiate_flag.py +159 -0
- pcapkit/vendor/mh/handover_initiate_status.py +87 -0
- pcapkit/vendor/mh/home_address_reply.py +87 -0
- pcapkit/vendor/mh/lla_code.py +97 -0
- pcapkit/vendor/mh/lma_mag_suboption.py +88 -0
- pcapkit/vendor/mh/mn_group_id.py +87 -0
- pcapkit/vendor/mh/mn_id_subtype.py +87 -0
- pcapkit/vendor/mh/operator_id.py +87 -0
- pcapkit/vendor/mh/option.py +83 -0
- pcapkit/vendor/mh/packet.py +82 -0
- pcapkit/vendor/mh/qos_attribute.py +87 -0
- pcapkit/vendor/mh/revocation_status_code.py +87 -0
- pcapkit/vendor/mh/revocation_trigger.py +87 -0
- pcapkit/vendor/mh/status_code.py +91 -0
- pcapkit/vendor/mh/traffic_selector.py +87 -0
- pcapkit/vendor/mh/upa_status.py +87 -0
- pcapkit/vendor/mh/upn_reason.py +87 -0
- pcapkit/vendor/ngap/__init__.py +31 -0
- pcapkit/vendor/ngap/procedure_code.py +233 -0
- pcapkit/vendor/ngap/protocol_ie.py +201 -0
- pcapkit/vendor/ospf/__init__.py +27 -0
- pcapkit/vendor/ospf/authentication.py +29 -0
- pcapkit/vendor/ospf/packet.py +29 -0
- pcapkit/vendor/pcapng/__init__.py +55 -0
- pcapkit/vendor/pcapng/block_type.py +102 -0
- pcapkit/vendor/pcapng/filter_type.py +77 -0
- pcapkit/vendor/pcapng/hash_algorithm.py +82 -0
- pcapkit/vendor/pcapng/option_type.py +477 -0
- pcapkit/vendor/pcapng/record_type.py +81 -0
- pcapkit/vendor/pcapng/secrets_type.py +80 -0
- pcapkit/vendor/pcapng/tls_key_label.py +180 -0
- pcapkit/vendor/pcapng/verdict_type.py +79 -0
- pcapkit/vendor/radiotap/__init__.py +86 -0
- pcapkit/vendor/radiotap/ampdu_flags.py +46 -0
- pcapkit/vendor/radiotap/channel_flags.py +51 -0
- pcapkit/vendor/radiotap/eht_known.py +59 -0
- pcapkit/vendor/radiotap/field_type.py +151 -0
- pcapkit/vendor/radiotap/flags.py +307 -0
- pcapkit/vendor/radiotap/he_data1_known.py +54 -0
- pcapkit/vendor/radiotap/he_data2_known.py +49 -0
- pcapkit/vendor/radiotap/he_mu_flags1_known.py +48 -0
- pcapkit/vendor/radiotap/he_mu_flags2_known.py +42 -0
- pcapkit/vendor/radiotap/he_mu_other_user_known.py +38 -0
- pcapkit/vendor/radiotap/lsig_data1.py +40 -0
- pcapkit/vendor/radiotap/mcs_known.py +48 -0
- pcapkit/vendor/radiotap/rx_flags.py +39 -0
- pcapkit/vendor/radiotap/s1g_known.py +46 -0
- pcapkit/vendor/radiotap/timestamp_flags.py +40 -0
- pcapkit/vendor/radiotap/tx_flags.py +44 -0
- pcapkit/vendor/radiotap/usig_common_known.py +48 -0
- pcapkit/vendor/radiotap/vht_coding.py +42 -0
- pcapkit/vendor/radiotap/vht_flags.py +44 -0
- pcapkit/vendor/radiotap/vht_known.py +47 -0
- pcapkit/vendor/reg/__init__.py +47 -0
- pcapkit/vendor/reg/apptype/__init__.py +36 -0
- pcapkit/vendor/reg/apptype/apptype.py +1320 -0
- pcapkit/vendor/reg/apptype/dccp.py +27 -0
- pcapkit/vendor/reg/apptype/sctp.py +27 -0
- pcapkit/vendor/reg/apptype/tcp.py +27 -0
- pcapkit/vendor/reg/apptype/udp.py +27 -0
- pcapkit/vendor/reg/ethertype.py +175 -0
- pcapkit/vendor/reg/linktype.py +210 -0
- pcapkit/vendor/reg/transtype.py +116 -0
- pcapkit/vendor/sctp/__init__.py +37 -0
- pcapkit/vendor/sctp/cause_code.py +29 -0
- pcapkit/vendor/sctp/chunk.py +29 -0
- pcapkit/vendor/sctp/parameter.py +29 -0
- pcapkit/vendor/sctp/payload_protocol_identifier.py +34 -0
- pcapkit/vendor/sslv2/__init__.py +24 -0
- pcapkit/vendor/sslv2/handshake_type.py +100 -0
- pcapkit/vendor/sslv2/version.py +95 -0
- pcapkit/vendor/tcp/__init__.py +35 -0
- pcapkit/vendor/tcp/checksum.py +80 -0
- pcapkit/vendor/tcp/flags.py +180 -0
- pcapkit/vendor/tcp/mp_tcp_option.py +90 -0
- pcapkit/vendor/tcp/option.py +103 -0
- pcapkit/vendor/tls/__init__.py +30 -0
- pcapkit/vendor/tls/content_type.py +142 -0
- pcapkit/vendor/tls/extension_type.py +151 -0
- pcapkit/vendor/tls/handshake_type.py +154 -0
- pcapkit/vendor/vlan/__init__.py +23 -0
- pcapkit/vendor/vlan/priority_level.py +97 -0
- pypcapkit-1.6.2.dist-info/METADATA +199 -0
- pypcapkit-1.6.2.dist-info/RECORD +770 -0
- pypcapkit-1.6.2.dist-info/WHEEL +5 -0
- pypcapkit-1.6.2.dist-info/entry_points.txt +3 -0
- pypcapkit-1.6.2.dist-info/licenses/LICENSE +29 -0
- pypcapkit-1.6.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,2335 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""IPv6-Opts - Destination Options for IPv6
|
|
3
|
+
==============================================
|
|
4
|
+
|
|
5
|
+
.. module:: pcapkit.protocols.internet.ipv6_opts.protocol
|
|
6
|
+
|
|
7
|
+
:mod:`pcapkit.protocols.internet.ipv6_opts.protocol` contains
|
|
8
|
+
:class:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts`
|
|
9
|
+
only, which implements the extractor for Destination Options
|
|
10
|
+
for IPv6 (IPv6-Opts) [*]_, whose structure is described
|
|
11
|
+
as below:
|
|
12
|
+
|
|
13
|
+
======= ========= =================== =================================
|
|
14
|
+
Octets Bits Name Description
|
|
15
|
+
======= ========= =================== =================================
|
|
16
|
+
0 0 ``opts.next`` Next Header
|
|
17
|
+
1 8 ``opts.length`` Header Extension Length
|
|
18
|
+
2 16 ``opts.options`` Options
|
|
19
|
+
======= ========= =================== =================================
|
|
20
|
+
|
|
21
|
+
.. [*] https://en.wikipedia.org/wiki/IPv6_packet#Hop-by-hop_options_and_destination_options
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
import collections
|
|
25
|
+
import datetime
|
|
26
|
+
import ipaddress
|
|
27
|
+
import math
|
|
28
|
+
from typing import TYPE_CHECKING, cast, overload
|
|
29
|
+
|
|
30
|
+
from pcapkit.const.ipv6.option import Option as Enum_Option
|
|
31
|
+
from pcapkit.const.ipv6.option_action import OptionAction as Enum_OptionAction
|
|
32
|
+
from pcapkit.const.ipv6.qs_function import QSFunction as Enum_QSFunction
|
|
33
|
+
from pcapkit.const.ipv6.router_alert import RouterAlert as Enum_RouterAlert
|
|
34
|
+
from pcapkit.const.ipv6.seed_id import SeedID as Enum_SeedID
|
|
35
|
+
from pcapkit.const.ipv6.smf_dpd_mode import SMFDPDMode as Enum_SMFDPDMode
|
|
36
|
+
from pcapkit.const.ipv6.tagger_id import TaggerID as Enum_TaggerID
|
|
37
|
+
from pcapkit.const.reg.transtype import TransType as Enum_TransType
|
|
38
|
+
from pcapkit.corekit.multidict import OrderedMultiDict
|
|
39
|
+
from pcapkit.corekit.schema.padding import pad_length
|
|
40
|
+
from pcapkit.corekit.sentinels import NO_VALUE
|
|
41
|
+
from pcapkit.protocols.internet.ipv6_ext.protocol import IPv6_Ext
|
|
42
|
+
from pcapkit.protocols.internet.ipv6_opts.data import CALIPSOOption as Data_CALIPSOOption
|
|
43
|
+
from pcapkit.protocols.internet.ipv6_opts.data import DFFFlags as Data_DFFFlags
|
|
44
|
+
from pcapkit.protocols.internet.ipv6_opts.data import HomeAddressOption as Data_HomeAddressOption
|
|
45
|
+
from pcapkit.protocols.internet.ipv6_opts.data import ILNPOption as Data_ILNPOption
|
|
46
|
+
from pcapkit.protocols.internet.ipv6_opts.data import IPDFFOption as Data_IPDFFOption
|
|
47
|
+
from pcapkit.protocols.internet.ipv6_opts.data import IPv6_Opts as Data_IPv6_Opts
|
|
48
|
+
from pcapkit.protocols.internet.ipv6_opts.data import JumboPayloadOption as Data_JumboPayloadOption
|
|
49
|
+
from pcapkit.protocols.internet.ipv6_opts.data import \
|
|
50
|
+
LineIdentificationOption as Data_LineIdentificationOption
|
|
51
|
+
from pcapkit.protocols.internet.ipv6_opts.data import MPLFlags as Data_MPLFlags
|
|
52
|
+
from pcapkit.protocols.internet.ipv6_opts.data import MPLOption as Data_MPLOption
|
|
53
|
+
from pcapkit.protocols.internet.ipv6_opts.data import PadOption as Data_PadOption
|
|
54
|
+
from pcapkit.protocols.internet.ipv6_opts.data import PDMOption as Data_PDMOption
|
|
55
|
+
from pcapkit.protocols.internet.ipv6_opts.data import \
|
|
56
|
+
QuickStartReportOption as Data_QuickStartReportOption
|
|
57
|
+
from pcapkit.protocols.internet.ipv6_opts.data import \
|
|
58
|
+
QuickStartRequestOption as Data_QuickStartRequestOption
|
|
59
|
+
from pcapkit.protocols.internet.ipv6_opts.data import RouterAlertOption as Data_RouterAlertOption
|
|
60
|
+
from pcapkit.protocols.internet.ipv6_opts.data import RPLFlags as Data_RPLFlags
|
|
61
|
+
from pcapkit.protocols.internet.ipv6_opts.data import RPLOption as Data_RPLOption
|
|
62
|
+
from pcapkit.protocols.internet.ipv6_opts.data import \
|
|
63
|
+
SMFHashBasedDPDOption as Data_SMFHashBasedDPDOption
|
|
64
|
+
from pcapkit.protocols.internet.ipv6_opts.data import \
|
|
65
|
+
SMFIdentificationBasedDPDOption as Data_SMFIdentificationBasedDPDOption
|
|
66
|
+
from pcapkit.protocols.internet.ipv6_opts.data import \
|
|
67
|
+
TunnelEncapsulationLimitOption as Data_TunnelEncapsulationLimitOption
|
|
68
|
+
from pcapkit.protocols.internet.ipv6_opts.data import UnassignedOption as Data_UnassignedOption
|
|
69
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import CALIPSOOption as Schema_CALIPSOOption
|
|
70
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import \
|
|
71
|
+
HomeAddressOption as Schema_HomeAddressOption
|
|
72
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import ILNPOption as Schema_ILNPOption
|
|
73
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import IPDFFOption as Schema_IPDFFOption
|
|
74
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import IPv6_Opts as Schema_IPv6_Opts
|
|
75
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import \
|
|
76
|
+
JumboPayloadOption as Schema_JumboPayloadOption
|
|
77
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import \
|
|
78
|
+
LineIdentificationOption as Schema_LineIdentificationOption
|
|
79
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import MPLOption as Schema_MPLOption
|
|
80
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import PadOption as Schema_PadOption
|
|
81
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import PDMOption as Schema_PDMOption
|
|
82
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import \
|
|
83
|
+
QuickStartReportOption as Schema_QuickStartReportOption
|
|
84
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import \
|
|
85
|
+
QuickStartRequestOption as Schema_QuickStartRequestOption
|
|
86
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import \
|
|
87
|
+
RouterAlertOption as Schema_RouterAlertOption
|
|
88
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import RPLOption as Schema_RPLOption
|
|
89
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import \
|
|
90
|
+
SMFHashBasedDPDOption as Schema_SMFHashBasedDPDOption
|
|
91
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import \
|
|
92
|
+
SMFIdentificationBasedDPDOption as Schema_SMFIdentificationBasedDPDOption
|
|
93
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import \
|
|
94
|
+
TunnelEncapsulationLimitOption as Schema_TunnelEncapsulationLimitOption
|
|
95
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import UnassignedOption as Schema_UnassignedOption
|
|
96
|
+
from pcapkit.protocols.misc.no_payload.protocol import NoPayload
|
|
97
|
+
from pcapkit.protocols.schema import Schema
|
|
98
|
+
from pcapkit.utilities.exceptions import BaseError, CaughtByCaller, ProtocolError, UnsupportedCall
|
|
99
|
+
from pcapkit.utilities.warnings import ProtocolWarning, RegistryWarning, warn
|
|
100
|
+
|
|
101
|
+
if TYPE_CHECKING:
|
|
102
|
+
from datetime import timedelta
|
|
103
|
+
from ipaddress import IPv4Address, IPv6Address
|
|
104
|
+
from typing import IO, Any, Callable, DefaultDict, NoReturn, Optional
|
|
105
|
+
|
|
106
|
+
from mypy_extensions import DefaultArg, KwArg, NamedArg
|
|
107
|
+
from typing_extensions import Literal
|
|
108
|
+
|
|
109
|
+
from pcapkit.corekit.protochain import ProtoChain
|
|
110
|
+
from pcapkit.protocols.internet.ipv6_opts.data import Option as Data_Option
|
|
111
|
+
from pcapkit.protocols.internet.ipv6_opts.data import QuickStartOption as Data_QuickStartOption
|
|
112
|
+
from pcapkit.protocols.internet.ipv6_opts.data import SMFDPDOption as Data_SMFDPDOption
|
|
113
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import Option as Schema_Option
|
|
114
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import \
|
|
115
|
+
QuickStartOption as Schema_QuickStartOption
|
|
116
|
+
from pcapkit.protocols.internet.ipv6_opts.schema import SMFDPDOption as Schema_SMFDPDOption
|
|
117
|
+
from pcapkit.protocols.protocol import ProtocolBase
|
|
118
|
+
|
|
119
|
+
Option = OrderedMultiDict[Enum_Option, Data_Option]
|
|
120
|
+
OptionParser = Callable[[Schema_Option, NamedArg(Option, 'options')], Data_Option]
|
|
121
|
+
OptionConstructor = Callable[[Enum_Option,
|
|
122
|
+
DefaultArg(Optional[Data_Option]), KwArg(Any)], Schema_Option]
|
|
123
|
+
|
|
124
|
+
__all__ = ['IPv6_Opts']
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class IPv6_Opts(IPv6_Ext[Data_IPv6_Opts, Schema_IPv6_Opts],
|
|
128
|
+
schema=Schema_IPv6_Opts, data=Data_IPv6_Opts):
|
|
129
|
+
"""This class implements Destination Options for IPv6.
|
|
130
|
+
|
|
131
|
+
This class parses the following IPv6 destination options, which are
|
|
132
|
+
registered in the
|
|
133
|
+
:attr:`self.__option__ <pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts.__option__>`
|
|
134
|
+
attribute:
|
|
135
|
+
|
|
136
|
+
.. list-table::
|
|
137
|
+
:header-rows: 1
|
|
138
|
+
|
|
139
|
+
* - Option Code
|
|
140
|
+
- Option Parser
|
|
141
|
+
- Option Constructor
|
|
142
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.Pad1`
|
|
143
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_pad`
|
|
144
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_pad`
|
|
145
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.PadN`
|
|
146
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_pad`
|
|
147
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_pad`
|
|
148
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.Tunnel_Encapsulation_Limit`
|
|
149
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_tun`
|
|
150
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_tun`
|
|
151
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.Router_Alert`
|
|
152
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_ra`
|
|
153
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_ra`
|
|
154
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.CALIPSO`
|
|
155
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_calipso`
|
|
156
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_calipso`
|
|
157
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.SMF_DPD`
|
|
158
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_smf_dpd`
|
|
159
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_smf_dpd`
|
|
160
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.PDM`
|
|
161
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_pdm`
|
|
162
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_pdm`
|
|
163
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.Quick_Start`
|
|
164
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_qs`
|
|
165
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_qs`
|
|
166
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.RPL_Option_0x23`
|
|
167
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_rpl`
|
|
168
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_rpl`
|
|
169
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.RPL_Option_0x63`
|
|
170
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_rpl`
|
|
171
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_rpl`
|
|
172
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.MPL_Option`
|
|
173
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_mpl`
|
|
174
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_mpl`
|
|
175
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.ILNP_Nonce`
|
|
176
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_ilnp`
|
|
177
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_ilnp`
|
|
178
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.Line_Identification_Option`
|
|
179
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_lio`
|
|
180
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_lio`
|
|
181
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.Jumbo_Payload`
|
|
182
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_jumbo`
|
|
183
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_jumbo`
|
|
184
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.Home_Address`
|
|
185
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_home`
|
|
186
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_home`
|
|
187
|
+
* - :attr:`~pcapkit.const.ipv6.option.Option.IP_DFF`
|
|
188
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._read_opt_ip_dff`
|
|
189
|
+
- :meth:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts._make_opt_ip_dff`
|
|
190
|
+
|
|
191
|
+
.. versionchanged:: 1.5.0
|
|
192
|
+
|
|
193
|
+
* The ILNP nonce is sized with a ceiling rather than a floor
|
|
194
|
+
(:issue:`601`).
|
|
195
|
+
* The RPL option keeps its reserved flag bits on rebuild and accepts
|
|
196
|
+
:rfc:`6553` sub-TLVs (:issue:`1199`).
|
|
197
|
+
* A rebuild reproduces the option area byte for byte: its padding, a
|
|
198
|
+
PadN with no data, the SMF_DPD, CALIPSO, PDM and ILNP Nonce options,
|
|
199
|
+
and unassigned Quick-Start function codes (:issue:`1200`,
|
|
200
|
+
:issue:`1228`, :issue:`1229`, :issue:`1232` to :issue:`1234`,
|
|
201
|
+
:issue:`1237`); a CALIPSO option keeps its trailing pad and its
|
|
202
|
+
length (:issue:`1403`).
|
|
203
|
+
* The MPL, ``IP_DFF`` and Quick-Start options keep their reserved bits
|
|
204
|
+
on rebuild, and ``IP_DFF`` takes the ``Opt Data Len`` of ``3`` that
|
|
205
|
+
:rfc:`6971` Errata ID 3937 gives, where it took ``2`` (:issue:`1235`).
|
|
206
|
+
* A PadN option's data and the "Not Used" octet of a Quick-Start report
|
|
207
|
+
are kept as captured rather than zeroed (:issue:`1223`).
|
|
208
|
+
|
|
209
|
+
.. versionchanged:: 1.6.0
|
|
210
|
+
|
|
211
|
+
* A Quick-Start rate the four-bit rate code cannot carry, or a TTL,
|
|
212
|
+
nonce or reserved value outside its field, raises
|
|
213
|
+
:exc:`~pcapkit.utilities.exceptions.ProtocolError`, rather than a bare
|
|
214
|
+
:exc:`ValueError`, an :exc:`OverflowError` or a
|
|
215
|
+
:exc:`~pcapkit.utilities.exceptions.FieldValueError`, or a different
|
|
216
|
+
value written in its place (:issue:`2617`).
|
|
217
|
+
* The Quick-Start maker builds an unassigned function code as an
|
|
218
|
+
unassigned option, the form the reader keeps one in (:issue:`2617`).
|
|
219
|
+
* An option maker given a value its fixed-width field cannot carry --
|
|
220
|
+
negative, too wide, or a :obj:`bool` for a field wider than one bit
|
|
221
|
+
-- raises :exc:`~pcapkit.utilities.exceptions.ProtocolError`, rather
|
|
222
|
+
than writing a different value or raising another exception; so
|
|
223
|
+
does :meth:`make` for options too long for the ``Hdr Ext Len``
|
|
224
|
+
(:issue:`2614`).
|
|
225
|
+
* A PDM scale, given or derived from its delta, that does not fit its
|
|
226
|
+
octet raises :exc:`~pcapkit.utilities.exceptions.ProtocolError`,
|
|
227
|
+
where it warned and was written wrapped (:issue:`2614`).
|
|
228
|
+
* Each enumeration field of :meth:`make` and of the option makers,
|
|
229
|
+
including the type of each option given to :meth:`make`, takes a
|
|
230
|
+
member or an :class:`int` code, resolved with the enumeration's
|
|
231
|
+
``get``; a name, a :obj:`bool` for a field wider than one bit, or a
|
|
232
|
+
code the field cannot carry raises
|
|
233
|
+
:exc:`~pcapkit.utilities.exceptions.ProtocolError`, rather than
|
|
234
|
+
resolving against an enumeration inferred from the caller's frame,
|
|
235
|
+
writing a different value or raising another exception
|
|
236
|
+
(:issue:`2594`).
|
|
237
|
+
* The CALIPSO option's checksum and the "Not Used" octet of a
|
|
238
|
+
Quick-Start report, given the wrong number of octets, raise
|
|
239
|
+
:exc:`~pcapkit.utilities.exceptions.ProtocolError`, rather than being
|
|
240
|
+
padded or cut to their field (:issue:`2676`).
|
|
241
|
+
* An option given to :meth:`make` as empty raw octets, which hold no
|
|
242
|
+
type octet, raises :exc:`~pcapkit.utilities.exceptions.ProtocolError`
|
|
243
|
+
rather than an :exc:`IndexError` (:issue:`2723`).
|
|
244
|
+
|
|
245
|
+
.. versionremoved:: 1.6.0
|
|
246
|
+
|
|
247
|
+
The ``*_default``, ``*_namespace`` and ``*_reversed`` arguments that
|
|
248
|
+
went with each enumeration field of :meth:`make` and of the option
|
|
249
|
+
makers -- ``next``, ``alert``, ``mode``, ``tid_type``, ``func`` and
|
|
250
|
+
``seed_type``; resolve a name with
|
|
251
|
+
:meth:`~pcapkit.protocols.protocol.Protocol.resolve_index` first
|
|
252
|
+
(:issue:`2594`).
|
|
253
|
+
|
|
254
|
+
"""
|
|
255
|
+
|
|
256
|
+
##########################################################################
|
|
257
|
+
# Defaults.
|
|
258
|
+
##########################################################################
|
|
259
|
+
|
|
260
|
+
#: Option code to method mapping, see :meth:`_read_ipv6_opts` and/or
|
|
261
|
+
#: :meth:`_make_ipv6_opts`. A :obj:`str` value names the methods
|
|
262
|
+
#: ``_read_opt_${name}`` and ``_make_opt_${name}``, falling back to
|
|
263
|
+
#: ``_read_opt_none`` / ``_make_opt_none`` when they do not exist; any other
|
|
264
|
+
#: value is a ``(parser, constructor)`` pair of callables.
|
|
265
|
+
__option__ = collections.defaultdict(
|
|
266
|
+
lambda: 'none',
|
|
267
|
+
{
|
|
268
|
+
Enum_Option.Pad1: 'pad', # [RFC 8200] 0
|
|
269
|
+
Enum_Option.PadN: 'pad', # [RFC 8200]
|
|
270
|
+
Enum_Option.Tunnel_Encapsulation_Limit: 'tun', # [RFC 2473] 1
|
|
271
|
+
Enum_Option.Router_Alert: 'ra', # [RFC 2711] 2
|
|
272
|
+
Enum_Option.CALIPSO: 'calipso', # [RFC 5570]
|
|
273
|
+
Enum_Option.SMF_DPD: 'smf_dpd', # [RFC 6621]
|
|
274
|
+
Enum_Option.PDM: 'pdm', # [RFC 8250] 10
|
|
275
|
+
Enum_Option.RPL_Option_0x23: 'rpl', # [RFC 9008]
|
|
276
|
+
Enum_Option.Quick_Start: 'qs', # [RFC 4782][RFC Errata 2034] 6
|
|
277
|
+
Enum_Option.RPL_Option_0x63: 'rpl', # [RFC 6553]
|
|
278
|
+
Enum_Option.MPL_Option: 'mpl', # [RFC 7731]
|
|
279
|
+
Enum_Option.ILNP_Nonce: 'ilnp', # [RFC 6744]
|
|
280
|
+
Enum_Option.Line_Identification_Option: 'lio', # [RFC 6788]
|
|
281
|
+
Enum_Option.Jumbo_Payload: 'jumbo', # [RFC 2675]
|
|
282
|
+
Enum_Option.Home_Address: 'home', # [RFC 6275]
|
|
283
|
+
Enum_Option.IP_DFF: 'ip_dff', # [RFC 6971]
|
|
284
|
+
},
|
|
285
|
+
) # type: DefaultDict[Enum_Option | int, str | tuple[OptionParser, OptionConstructor]]
|
|
286
|
+
|
|
287
|
+
##########################################################################
|
|
288
|
+
# Properties.
|
|
289
|
+
##########################################################################
|
|
290
|
+
|
|
291
|
+
@property
|
|
292
|
+
def name(self) -> 'Literal["Destination Options for IPv6"]':
|
|
293
|
+
"""Name of current protocol."""
|
|
294
|
+
return 'Destination Options for IPv6'
|
|
295
|
+
|
|
296
|
+
@property
|
|
297
|
+
def alias(self) -> 'Literal["IPv6-Opts"]':
|
|
298
|
+
"""Acronym of corresponding protocol."""
|
|
299
|
+
return 'IPv6-Opts'
|
|
300
|
+
|
|
301
|
+
@property
|
|
302
|
+
def length(self) -> 'int':
|
|
303
|
+
"""Header length of current protocol."""
|
|
304
|
+
return self._info.length
|
|
305
|
+
|
|
306
|
+
@property
|
|
307
|
+
def payload(self) -> 'ProtocolBase | NoReturn':
|
|
308
|
+
"""Payload of current instance.
|
|
309
|
+
|
|
310
|
+
Raises:
|
|
311
|
+
UnsupportedCall: if the protocol is used as an IPv6 extension header
|
|
312
|
+
|
|
313
|
+
"""
|
|
314
|
+
if self._extf:
|
|
315
|
+
raise UnsupportedCall(f"'{self.__class__.__name__}' object has no attribute 'payload'")
|
|
316
|
+
return self._next
|
|
317
|
+
|
|
318
|
+
@property
|
|
319
|
+
def protocol(self) -> 'Optional[str] | NoReturn':
|
|
320
|
+
"""Name of next layer protocol (if any).
|
|
321
|
+
|
|
322
|
+
Raises:
|
|
323
|
+
UnsupportedCall: if the protocol is used as an IPv6 extension header
|
|
324
|
+
|
|
325
|
+
"""
|
|
326
|
+
if self._extf:
|
|
327
|
+
raise UnsupportedCall(f"'{self.__class__.__name__}' object has no attribute 'protocol'")
|
|
328
|
+
return super().protocol
|
|
329
|
+
|
|
330
|
+
@property
|
|
331
|
+
def protochain(self) -> 'ProtoChain | NoReturn':
|
|
332
|
+
"""Protocol chain of current instance.
|
|
333
|
+
|
|
334
|
+
Raises:
|
|
335
|
+
UnsupportedCall: if the protocol is used as an IPv6 extension header
|
|
336
|
+
|
|
337
|
+
"""
|
|
338
|
+
if self._extf:
|
|
339
|
+
raise UnsupportedCall(f"'{self.__class__.__name__}' object has no attribute 'protochain'")
|
|
340
|
+
return super().protochain
|
|
341
|
+
|
|
342
|
+
##########################################################################
|
|
343
|
+
# Methods.
|
|
344
|
+
##########################################################################
|
|
345
|
+
|
|
346
|
+
def read(self, length: 'Optional[int]' = None, *, extension: 'bool' = False, # pylint: disable=arguments-differ
|
|
347
|
+
**kwargs: 'Any') -> 'Data_IPv6_Opts': # pylint: disable=unused-argument
|
|
348
|
+
"""Read Destination Options for IPv6.
|
|
349
|
+
|
|
350
|
+
Structure of IPv6-Opts header [:rfc:`8200`]:
|
|
351
|
+
|
|
352
|
+
.. code-block:: text
|
|
353
|
+
|
|
354
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
355
|
+
| Next Header | Hdr Ext Len | |
|
|
356
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
|
|
357
|
+
| |
|
|
358
|
+
. .
|
|
359
|
+
. Options .
|
|
360
|
+
. .
|
|
361
|
+
| |
|
|
362
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
363
|
+
|
|
364
|
+
Args:
|
|
365
|
+
length: Length of packet data.
|
|
366
|
+
extension: If the packet is used as an IPv6 extension header.
|
|
367
|
+
**kwargs: Arbitrary keyword arguments.
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
Parsed packet data.
|
|
371
|
+
|
|
372
|
+
"""
|
|
373
|
+
if length is None:
|
|
374
|
+
length = len(self)
|
|
375
|
+
schema = self.__header__
|
|
376
|
+
|
|
377
|
+
ipv6_opts = Data_IPv6_Opts(
|
|
378
|
+
next=schema.next,
|
|
379
|
+
length=(schema.len + 1) * 8,
|
|
380
|
+
options=self._read_ipv6_opts(schema.len * 8 + 6),
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
if extension:
|
|
384
|
+
# NOTE: As an IPv6 extension header the upper layer belongs to the enclosing
|
|
385
|
+
# IPv6 header, so hold NoPayload here so that membership does not raise (#2487).
|
|
386
|
+
self._next = NoPayload() # pylint: disable=attribute-defined-outside-init
|
|
387
|
+
return ipv6_opts
|
|
388
|
+
return self._decode_next_layer(ipv6_opts, schema.next, length - ipv6_opts.length)
|
|
389
|
+
|
|
390
|
+
def make(self,
|
|
391
|
+
next: 'Enum_TransType | int' = Enum_TransType.UDP,
|
|
392
|
+
options: 'Optional[list[Schema_Option | tuple[Enum_Option | int, dict[str, Any]] | bytes] | Option]' = None, # pylint: disable=line-too-long
|
|
393
|
+
payload: 'bytes | ProtocolBase | Schema' = b'', *,
|
|
394
|
+
len: 'Optional[int]' = None, # pylint: disable=redefined-builtin
|
|
395
|
+
**kwargs: 'Any') -> 'Schema_IPv6_Opts':
|
|
396
|
+
"""Make (construct) packet data.
|
|
397
|
+
|
|
398
|
+
Args:
|
|
399
|
+
next: Next header type.
|
|
400
|
+
options: Destination Options.
|
|
401
|
+
payload: Payload of current protocol.
|
|
402
|
+
len: ``Hdr Ext Len`` to declare, rather than the one the options
|
|
403
|
+
fill. A header the capture cut short declares one its parsed
|
|
404
|
+
options do not fill, which :meth:`from_data` passes on, so that
|
|
405
|
+
the rebuild declares it too (:issue:`2694`). Options that fill
|
|
406
|
+
less than it declares are not padded out to it, so the header
|
|
407
|
+
then declares more octets than it packs, as a cut one does.
|
|
408
|
+
**kwargs: Arbitrary keyword arguments.
|
|
409
|
+
|
|
410
|
+
Returns:
|
|
411
|
+
Constructed packet data.
|
|
412
|
+
|
|
413
|
+
Raises:
|
|
414
|
+
ProtocolError: If ``next``, or the type of an option, is a name, a
|
|
415
|
+
:obj:`bool`, or a member or code that does not fit in one
|
|
416
|
+
octet; or if the options make a header too long for its
|
|
417
|
+
one-octet ``Hdr Ext Len``, or longer than ``len`` declares.
|
|
418
|
+
|
|
419
|
+
.. versionchanged:: 1.6.0
|
|
420
|
+
|
|
421
|
+
Takes ``len``, the ``Hdr Ext Len`` of a header the capture cut short
|
|
422
|
+
(:issue:`2694`).
|
|
423
|
+
|
|
424
|
+
"""
|
|
425
|
+
next_value = self._make_index(next, Enum_TransType, bits=8, name='next header')
|
|
426
|
+
|
|
427
|
+
# NOTE: No options still means six octets of padding options; returning ``[], 0``
|
|
428
|
+
# would emit the fixed two octets alone under a ``Hdr Ext Len`` of ``-1``.
|
|
429
|
+
options_value, total_length = self._make_ipv6_opts(
|
|
430
|
+
options if options is not None else [])
|
|
431
|
+
|
|
432
|
+
# NOTE: ``_make_ipv6_opts`` has aligned the header, so this division is
|
|
433
|
+
# exact and rounding up is unnecessary.
|
|
434
|
+
length = self._make_uint((total_length - 6) // 8, bits=8, name='Hdr Ext Len')
|
|
435
|
+
if len is not None:
|
|
436
|
+
length = self._make_uint(len, bits=8, name='Hdr Ext Len')
|
|
437
|
+
if length * 8 + 6 < total_length:
|
|
438
|
+
raise ProtocolError(f'{self.alias}: Hdr Ext Len {length} declares fewer octets '
|
|
439
|
+
f'than the options take ({total_length})')
|
|
440
|
+
|
|
441
|
+
return Schema_IPv6_Opts(
|
|
442
|
+
next=next_value,
|
|
443
|
+
len=length,
|
|
444
|
+
options=options_value,
|
|
445
|
+
payload=payload,
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
@classmethod
|
|
449
|
+
def register_option(cls, code: 'Enum_Option', meth: 'str | tuple[OptionParser, OptionConstructor]') -> 'None':
|
|
450
|
+
"""Register an option parser.
|
|
451
|
+
|
|
452
|
+
Args:
|
|
453
|
+
code: IPv6-Opts option code.
|
|
454
|
+
meth: Name ``X`` of the ``_read_opt_X`` and ``_make_opt_X``
|
|
455
|
+
methods, or a ``(parser, constructor)`` pair of callables, see
|
|
456
|
+
:attr:`__option__`.
|
|
457
|
+
|
|
458
|
+
Warns:
|
|
459
|
+
RegistryWarning: If a different entry is already registered for
|
|
460
|
+
``code``; it is overwritten. Handing back the entry already
|
|
461
|
+
stored, or one equal to it, is a silent no-op. The entry
|
|
462
|
+
``code`` shipped with is accepted like any other, so an
|
|
463
|
+
override can be undone (:issue:`1362`, :issue:`1363`).
|
|
464
|
+
|
|
465
|
+
"""
|
|
466
|
+
incumbent = cls.__option__.get(code)
|
|
467
|
+
if incumbent is not None and incumbent == meth:
|
|
468
|
+
return
|
|
469
|
+
if incumbent is not None:
|
|
470
|
+
warn(f'option {code} already registered, overwriting', RegistryWarning)
|
|
471
|
+
cls.__option__[code] = meth
|
|
472
|
+
|
|
473
|
+
@classmethod
|
|
474
|
+
def id(cls) -> 'tuple[Literal["IPv6_Opts"]]': # type: ignore[override]
|
|
475
|
+
"""Index ID of the protocol.
|
|
476
|
+
|
|
477
|
+
Returns:
|
|
478
|
+
Index ID of the protocol.
|
|
479
|
+
|
|
480
|
+
"""
|
|
481
|
+
return ('IPv6_Opts',)
|
|
482
|
+
|
|
483
|
+
##########################################################################
|
|
484
|
+
# Data models.
|
|
485
|
+
##########################################################################
|
|
486
|
+
|
|
487
|
+
@overload
|
|
488
|
+
def __post_init__(self, file: 'IO[bytes] | bytes', length: 'Optional[int]' = ..., *, # pylint: disable=arguments-differ
|
|
489
|
+
extension: 'bool' = ..., **kwargs: 'Any') -> 'None': ...
|
|
490
|
+
|
|
491
|
+
@overload
|
|
492
|
+
def __post_init__(self, **kwargs: 'Any') -> 'None': ... # pylint: disable=arguments-differ
|
|
493
|
+
|
|
494
|
+
def __post_init__(self, file: 'Optional[IO[bytes] | bytes]' = None, length: 'Optional[int]' = None, *, # pylint: disable=arguments-differ
|
|
495
|
+
extension: 'bool' = False, **kwargs: 'Any') -> 'None':
|
|
496
|
+
"""Post initialisation hook.
|
|
497
|
+
|
|
498
|
+
Args:
|
|
499
|
+
file: Source packet stream.
|
|
500
|
+
length: Length of packet data.
|
|
501
|
+
extension: If the protocol is used as an IPv6 extension header.
|
|
502
|
+
**kwargs: Arbitrary keyword arguments.
|
|
503
|
+
|
|
504
|
+
See Also:
|
|
505
|
+
For construction arguments, please refer to :meth:`self.make <IPv6_Opts.make>`.
|
|
506
|
+
|
|
507
|
+
"""
|
|
508
|
+
#: bool: If the protocol is used as an IPv6 extension header.
|
|
509
|
+
self._extf = extension
|
|
510
|
+
|
|
511
|
+
# call super __post_init__
|
|
512
|
+
super().__post_init__(file, length, extension=extension, **kwargs) # type: ignore[arg-type]
|
|
513
|
+
|
|
514
|
+
def __length_hint__(self) -> 'Literal[8]':
|
|
515
|
+
"""Return an estimated length for the object.
|
|
516
|
+
|
|
517
|
+
Eight octets: the two fixed ones and the options that
|
|
518
|
+
:rfc:`8200#section-4.6` counts in the first 8-octet unit.
|
|
519
|
+
|
|
520
|
+
"""
|
|
521
|
+
return 8
|
|
522
|
+
|
|
523
|
+
@classmethod
|
|
524
|
+
def __index__(cls) -> 'Enum_TransType': # pylint: disable=invalid-index-returned
|
|
525
|
+
"""Numeral registry index of the protocol.
|
|
526
|
+
|
|
527
|
+
Returns:
|
|
528
|
+
Numeral registry index of the protocol in `IANA`_.
|
|
529
|
+
|
|
530
|
+
.. _IANA: https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
|
|
531
|
+
|
|
532
|
+
"""
|
|
533
|
+
return Enum_TransType.IPv6_Opts # type: ignore[return-value]
|
|
534
|
+
|
|
535
|
+
##########################################################################
|
|
536
|
+
# Utilities.
|
|
537
|
+
##########################################################################
|
|
538
|
+
|
|
539
|
+
@classmethod
|
|
540
|
+
def _make_data(cls, data: 'Data_IPv6_Opts') -> 'dict[str, Any]': # type: ignore[override]
|
|
541
|
+
"""Create key-value pairs from ``data`` for protocol construction.
|
|
542
|
+
|
|
543
|
+
Args:
|
|
544
|
+
data: protocol data
|
|
545
|
+
|
|
546
|
+
Returns:
|
|
547
|
+
Key-value pairs for protocol construction.
|
|
548
|
+
|
|
549
|
+
"""
|
|
550
|
+
# NOTE: A header the capture cut short declares an area its parsed options
|
|
551
|
+
# do not fill, and is rebuilt with the Hdr Ext Len it declared (#2694).
|
|
552
|
+
return {
|
|
553
|
+
'next': data.next,
|
|
554
|
+
'options': data.options,
|
|
555
|
+
'payload': cls._make_payload(data),
|
|
556
|
+
'len': data.length // 8 - 1 if data.get('__short_read__') is not None else None,
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
def _read_ipv6_opts(self, length: 'int') -> 'Option':
|
|
560
|
+
"""Read IPv6-Opts options.
|
|
561
|
+
|
|
562
|
+
Args:
|
|
563
|
+
length: Length of the options area, in octets.
|
|
564
|
+
|
|
565
|
+
Returns:
|
|
566
|
+
Extracted IPv6-Opts options
|
|
567
|
+
|
|
568
|
+
Raises:
|
|
569
|
+
ProtocolError: If the parsed options do not total exactly ``length``
|
|
570
|
+
octets, unless the capture cut the header short, as its short
|
|
571
|
+
read records. Or if the capture cut an option short and its
|
|
572
|
+
parser refuses the zeros it lacks, or its maker does not write
|
|
573
|
+
the octets captured back.
|
|
574
|
+
|
|
575
|
+
.. versionchanged:: 1.6.0
|
|
576
|
+
|
|
577
|
+
A header the capture cut short reads as the short read it is, and an
|
|
578
|
+
option it cuts as its parser reads the zeros it lacks, rather than
|
|
579
|
+
being refused (:issue:`2694`).
|
|
580
|
+
|
|
581
|
+
"""
|
|
582
|
+
counter = 0 # length of read options
|
|
583
|
+
options = OrderedMultiDict() # type: Option
|
|
584
|
+
|
|
585
|
+
for schema in self.__header__.options:
|
|
586
|
+
dscp = schema.type
|
|
587
|
+
name = self._lookup_registry(self.__option__, dscp)
|
|
588
|
+
|
|
589
|
+
if isinstance(name, str):
|
|
590
|
+
meth_name = f'_read_opt_{name}'
|
|
591
|
+
meth = cast('OptionParser',
|
|
592
|
+
getattr(self, meth_name, self._read_opt_none))
|
|
593
|
+
maker = cast('OptionConstructor',
|
|
594
|
+
getattr(self, f'_make_opt_{name}', self._make_opt_none))
|
|
595
|
+
else:
|
|
596
|
+
meth, maker = name
|
|
597
|
+
|
|
598
|
+
# NOTE: A capture-cut option reads its missing octets as zeros; it stands if its parser
|
|
599
|
+
# takes them and its maker writes the captured ones back (#2694), or is refused (#1325).
|
|
600
|
+
if '__short_read__' in schema.__dict__:
|
|
601
|
+
try:
|
|
602
|
+
with CaughtByCaller(BaseError):
|
|
603
|
+
data = meth(schema, options=options)
|
|
604
|
+
made = maker(dscp, data).pack()[:len(schema)]
|
|
605
|
+
except BaseError as error:
|
|
606
|
+
raise ProtocolError(f'{self.alias}: [OptNo {dscp}] option cut short: {error}') from error
|
|
607
|
+
if made != bytes(schema):
|
|
608
|
+
raise ProtocolError(f'{self.alias}: [OptNo {dscp}] option cut short does not '
|
|
609
|
+
'rebuild as captured')
|
|
610
|
+
else:
|
|
611
|
+
data = meth(schema, options=options)
|
|
612
|
+
|
|
613
|
+
# record option data
|
|
614
|
+
options.add(dscp, data)
|
|
615
|
+
counter += len(schema)
|
|
616
|
+
|
|
617
|
+
# check threshold, which a header the capture cut short falls short of (#2694)
|
|
618
|
+
if counter != length and '__short_read__' not in self.__header__.__dict__:
|
|
619
|
+
raise ProtocolError('IPv6-Opts: invalid format')
|
|
620
|
+
return options
|
|
621
|
+
|
|
622
|
+
def _make_ipv6_opts(self, options: 'list[Schema_Option | tuple[Enum_Option | int, dict[str, Any]] | bytes] | Option') -> 'tuple[list[Schema_Option | bytes], int]': # pylint: disable=line-too-long
|
|
623
|
+
"""Make options for IPv6-Opts.
|
|
624
|
+
|
|
625
|
+
Args:
|
|
626
|
+
options: IPv6-Opts options
|
|
627
|
+
|
|
628
|
+
Returns:
|
|
629
|
+
Tuple of options and total length of options.
|
|
630
|
+
|
|
631
|
+
Raises:
|
|
632
|
+
ProtocolError: If the type of an option, given in a ``(type,
|
|
633
|
+
kwargs)`` pair or as the key of a container, is a name, a
|
|
634
|
+
:obj:`bool` or a code its field cannot carry, or if an option
|
|
635
|
+
given as raw octets is empty (:issue:`2723`).
|
|
636
|
+
|
|
637
|
+
Note:
|
|
638
|
+
Options given as a :obj:`list` are fresh input: padding options in
|
|
639
|
+
it are dropped, and padding is inserted after each option to align
|
|
640
|
+
the header. Options given as a mapping, such as the
|
|
641
|
+
:class:`~pcapkit.corekit.infoclass.OrderedMultiInfo` of parsed
|
|
642
|
+
data, are emitted in order with their own padding options kept, and
|
|
643
|
+
padding is added only at the end if the header is not aligned.
|
|
644
|
+
|
|
645
|
+
The returned length is that of the options area alone, the value
|
|
646
|
+
:meth:`make` derives the ``Hdr Ext Len`` field from. Since the two
|
|
647
|
+
octets of the fixed header precede it, an options area is well
|
|
648
|
+
formed only when it is 2 octets short of a multiple of 8 --
|
|
649
|
+
including when it holds no real options at all, in which case it is
|
|
650
|
+
6 octets of pure padding rather than empty.
|
|
651
|
+
|
|
652
|
+
"""
|
|
653
|
+
total_length = 0
|
|
654
|
+
if isinstance(options, list):
|
|
655
|
+
options_list = [] # type: list[Schema_Option | bytes]
|
|
656
|
+
for schema in options:
|
|
657
|
+
if isinstance(schema, bytes):
|
|
658
|
+
if not schema:
|
|
659
|
+
raise ProtocolError(f'{self.alias}: invalid option: {schema!r} holds no type octet')
|
|
660
|
+
code = Enum_Option.get(schema[0])
|
|
661
|
+
if code in (Enum_Option.Pad1, Enum_Option.PadN): # ignore padding options by default
|
|
662
|
+
continue
|
|
663
|
+
|
|
664
|
+
opt = schema # type: bytes | Schema_Option
|
|
665
|
+
opt_len = len(schema)
|
|
666
|
+
elif isinstance(schema, Schema):
|
|
667
|
+
code = schema.type
|
|
668
|
+
if code in (Enum_Option.Pad1, Enum_Option.PadN): # ignore padding options by default
|
|
669
|
+
continue
|
|
670
|
+
|
|
671
|
+
opt = schema
|
|
672
|
+
opt_len = len(schema.pack())
|
|
673
|
+
else:
|
|
674
|
+
kind, args = cast('tuple[Enum_Option | int, dict[str, Any]]', schema)
|
|
675
|
+
code = self._make_index(kind, Enum_Option, bits=8, name='option type')
|
|
676
|
+
if code in (Enum_Option.Pad1, Enum_Option.PadN): # ignore padding options by default
|
|
677
|
+
continue
|
|
678
|
+
|
|
679
|
+
name = self._lookup_registry(self.__option__, code)
|
|
680
|
+
if isinstance(name, str):
|
|
681
|
+
meth_name = f'_make_opt_{name}'
|
|
682
|
+
meth = cast('OptionConstructor',
|
|
683
|
+
getattr(self, meth_name, self._make_opt_none))
|
|
684
|
+
else:
|
|
685
|
+
meth = name[1]
|
|
686
|
+
|
|
687
|
+
opt = meth(code, **args)
|
|
688
|
+
opt_len = len(opt.pack())
|
|
689
|
+
|
|
690
|
+
options_list.append(opt)
|
|
691
|
+
total_length += opt_len
|
|
692
|
+
|
|
693
|
+
# force alignment of the header (fixed part included) to 8 octets
|
|
694
|
+
pad_opts, pad_len = self._make_pad_options(total_length + 2)
|
|
695
|
+
options_list.extend(pad_opts)
|
|
696
|
+
total_length += pad_len
|
|
697
|
+
|
|
698
|
+
# an options area holding nothing at all is still 6 octets long
|
|
699
|
+
pad_opts, pad_len = self._make_pad_options(total_length + 2)
|
|
700
|
+
options_list.extend(pad_opts)
|
|
701
|
+
total_length += pad_len
|
|
702
|
+
return options_list, total_length
|
|
703
|
+
|
|
704
|
+
# NOTE: Parsed options are emitted as they are, padding in place, so a parsed header
|
|
705
|
+
# rebuilds byte for byte; only a header short of alignment gets trailing padding.
|
|
706
|
+
options_list = []
|
|
707
|
+
for key, option in options.items(multi=True):
|
|
708
|
+
code = self._make_index(key, Enum_Option, bits=8, name='option type')
|
|
709
|
+
name = self._lookup_registry(self.__option__, code)
|
|
710
|
+
if isinstance(name, str):
|
|
711
|
+
meth_name = f'_make_opt_{name}'
|
|
712
|
+
meth = cast('OptionConstructor',
|
|
713
|
+
getattr(self, meth_name, self._make_opt_none))
|
|
714
|
+
else:
|
|
715
|
+
meth = name[1]
|
|
716
|
+
|
|
717
|
+
opt = meth(code, option)
|
|
718
|
+
opt_len = len(opt.pack())
|
|
719
|
+
|
|
720
|
+
options_list.append(opt)
|
|
721
|
+
total_length += opt_len
|
|
722
|
+
|
|
723
|
+
# an options area holding nothing at all is still 6 octets long
|
|
724
|
+
pad_opts, pad_len = self._make_pad_options(total_length + 2)
|
|
725
|
+
options_list.extend(pad_opts)
|
|
726
|
+
total_length += pad_len
|
|
727
|
+
return options_list, total_length
|
|
728
|
+
|
|
729
|
+
def _read_opt_none(self, schema: 'Schema_UnassignedOption', *, options: 'Option') -> 'Data_UnassignedOption': # pylint: disable=unused-argument
|
|
730
|
+
"""Read IPv6-Opts unassigned options.
|
|
731
|
+
|
|
732
|
+
Structure of IPv6-Opts unassigned options [:rfc:`8200`]:
|
|
733
|
+
|
|
734
|
+
.. code-block:: text
|
|
735
|
+
|
|
736
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
|
|
737
|
+
| Option Type | Opt Data Len | Option Data
|
|
738
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
|
|
739
|
+
|
|
740
|
+
Args:
|
|
741
|
+
schema: parsed parameter schema
|
|
742
|
+
options: extracted IPv6-Opts options
|
|
743
|
+
|
|
744
|
+
Returns:
|
|
745
|
+
Parsed option data.
|
|
746
|
+
|
|
747
|
+
"""
|
|
748
|
+
opt = Data_UnassignedOption(
|
|
749
|
+
type=schema.type,
|
|
750
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
751
|
+
change=bool(schema.type & 0b00100000),
|
|
752
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
753
|
+
data=schema.data,
|
|
754
|
+
)
|
|
755
|
+
return opt
|
|
756
|
+
|
|
757
|
+
def _read_opt_pad(self, schema: 'Schema_PadOption', *, options: 'Option') -> 'Data_PadOption': # pylint: disable=unused-argument
|
|
758
|
+
"""Read IPv6-Opts padding options.
|
|
759
|
+
|
|
760
|
+
Structure of IPv6-Opts padding options [:rfc:`8200`]:
|
|
761
|
+
|
|
762
|
+
* ``Pad1`` option:
|
|
763
|
+
|
|
764
|
+
.. code-block:: text
|
|
765
|
+
|
|
766
|
+
+-+-+-+-+-+-+-+-+
|
|
767
|
+
| 0 |
|
|
768
|
+
+-+-+-+-+-+-+-+-+
|
|
769
|
+
|
|
770
|
+
* ``PadN`` option:
|
|
771
|
+
|
|
772
|
+
.. code-block:: text
|
|
773
|
+
|
|
774
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
|
|
775
|
+
| 1 | Opt Data Len | Option Data
|
|
776
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
|
|
777
|
+
|
|
778
|
+
Args:
|
|
779
|
+
schema: parsed parameter schema
|
|
780
|
+
options: extracted IPv6-Opts options
|
|
781
|
+
|
|
782
|
+
Returns:
|
|
783
|
+
Parsed option data.
|
|
784
|
+
|
|
785
|
+
Raises:
|
|
786
|
+
ProtocolError: If ``code`` is **NOT** ``0`` or ``1``.
|
|
787
|
+
|
|
788
|
+
Note:
|
|
789
|
+
A ``Pad1`` option occupies a single octet and carries no
|
|
790
|
+
``Opt Data Len`` field, so its
|
|
791
|
+
:attr:`~pcapkit.protocols.internet.ipv6_opts.data.Option.length` is
|
|
792
|
+
``1`` rather than ``len + 2``. That one-octet wire shape is enforced
|
|
793
|
+
by :class:`~pcapkit.protocols.internet.ipv6_opts.schema.PadOption`
|
|
794
|
+
itself, which sizes both the length octet and the padding data from
|
|
795
|
+
the option type; ``clen`` is therefore always ``0`` here for a
|
|
796
|
+
parsed ``Pad1``, and the length check this method makes only guards
|
|
797
|
+
a schema built by hand. A ``PadN`` whose ``Opt Data Len`` is ``0``
|
|
798
|
+
is a valid two-octet padding option [:rfc:`8200#section-4.2`].
|
|
799
|
+
|
|
800
|
+
"""
|
|
801
|
+
code, clen = schema.type, schema.len
|
|
802
|
+
|
|
803
|
+
if code not in (Enum_Option.Pad1, Enum_Option.PadN):
|
|
804
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] invalid format')
|
|
805
|
+
if code == Enum_Option.Pad1 and clen != 0:
|
|
806
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] invalid format')
|
|
807
|
+
|
|
808
|
+
if code == Enum_Option.Pad1:
|
|
809
|
+
_size = 1
|
|
810
|
+
else:
|
|
811
|
+
_size = self._ipv6_opts_option_length(schema.len)
|
|
812
|
+
|
|
813
|
+
opt = Data_PadOption(
|
|
814
|
+
type=schema.type,
|
|
815
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
816
|
+
change=bool(schema.type & 0b00100000),
|
|
817
|
+
length=_size,
|
|
818
|
+
pad=schema.pad,
|
|
819
|
+
)
|
|
820
|
+
return opt
|
|
821
|
+
|
|
822
|
+
def _read_opt_tun(self, schema: 'Schema_TunnelEncapsulationLimitOption', *, options: 'Option') -> 'Data_TunnelEncapsulationLimitOption': # pylint: disable=unused-argument
|
|
823
|
+
"""Read IPv6-Opts Tunnel Encapsulation Limit option.
|
|
824
|
+
|
|
825
|
+
Structure of IPv6-Opts Tunnel Encapsulation Limit option [:rfc:`2473`]:
|
|
826
|
+
|
|
827
|
+
.. code-block:: text
|
|
828
|
+
|
|
829
|
+
Option Type Opt Data Len Opt Data Len
|
|
830
|
+
0 1 2 3 4 5 6 7
|
|
831
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
832
|
+
|0 0 0 0 0 1 0 0| 1 | Tun Encap Lim |
|
|
833
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
834
|
+
|
|
835
|
+
Args:
|
|
836
|
+
schema: parsed parameter schema
|
|
837
|
+
options: extracted IPv6-Opts options
|
|
838
|
+
|
|
839
|
+
Returns:
|
|
840
|
+
Parsed option data.
|
|
841
|
+
|
|
842
|
+
Raises:
|
|
843
|
+
ProtocolError: If ``schema.len`` is **NOT** ``1``.
|
|
844
|
+
|
|
845
|
+
"""
|
|
846
|
+
if schema.len != 1:
|
|
847
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid format')
|
|
848
|
+
|
|
849
|
+
opt = Data_TunnelEncapsulationLimitOption(
|
|
850
|
+
type=schema.type,
|
|
851
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
852
|
+
change=bool(schema.type & 0b00100000),
|
|
853
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
854
|
+
limit=schema.limit,
|
|
855
|
+
)
|
|
856
|
+
return opt
|
|
857
|
+
|
|
858
|
+
def _read_opt_ra(self, schema: 'Schema_RouterAlertOption', *, options: 'Option') -> 'Data_RouterAlertOption': # pylint: disable=unused-argument
|
|
859
|
+
"""Read IPv6-Opts Router Alert option.
|
|
860
|
+
|
|
861
|
+
Structure of IPv6-Opts Router Alert option [:rfc:`2711`]:
|
|
862
|
+
|
|
863
|
+
.. code-block:: text
|
|
864
|
+
|
|
865
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
866
|
+
|0 0 0|0 0 1 0 1|0 0 0 0 0 0 1 0| Value (2 octets) |
|
|
867
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
868
|
+
|
|
869
|
+
Args:
|
|
870
|
+
schema: parsed parameter schema
|
|
871
|
+
options: extracted IPv6-Opts options
|
|
872
|
+
|
|
873
|
+
Returns:
|
|
874
|
+
Parsed option data.
|
|
875
|
+
|
|
876
|
+
Raises:
|
|
877
|
+
ProtocolError: If ``schema.len`` is **NOT** ``2``.
|
|
878
|
+
|
|
879
|
+
"""
|
|
880
|
+
if schema.len != 2:
|
|
881
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid format')
|
|
882
|
+
|
|
883
|
+
opt = Data_RouterAlertOption(
|
|
884
|
+
type=schema.type,
|
|
885
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
886
|
+
change=bool(schema.type & 0b00100000),
|
|
887
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
888
|
+
value=schema.alert,
|
|
889
|
+
)
|
|
890
|
+
return opt
|
|
891
|
+
|
|
892
|
+
def _read_opt_calipso(self, schema: 'Schema_CALIPSOOption', *, options: 'Option') -> 'Data_CALIPSOOption': # pylint: disable=unused-argument
|
|
893
|
+
"""Read IPv6-Opts Common Architecture Label IPv6 Security Option (CALIPSO) option.
|
|
894
|
+
|
|
895
|
+
Structure of IPv6-Opts CALIPSO option [:rfc:`5570`]:
|
|
896
|
+
|
|
897
|
+
.. code-block:: text
|
|
898
|
+
|
|
899
|
+
------------------------------------------------------------
|
|
900
|
+
| Next Header | Hdr Ext Len | Option Type | Option Length|
|
|
901
|
+
+-------------+---------------+-------------+--------------+
|
|
902
|
+
| CALIPSO Domain of Interpretation |
|
|
903
|
+
+-------------+---------------+-------------+--------------+
|
|
904
|
+
| Cmpt Length | Sens Level | Checksum (CRC-16) |
|
|
905
|
+
+-------------+---------------+-------------+--------------+
|
|
906
|
+
| Compartment Bitmap (Optional; variable length) |
|
|
907
|
+
+-------------+---------------+-------------+--------------+
|
|
908
|
+
|
|
909
|
+
Args:
|
|
910
|
+
schema: parsed parameter schema
|
|
911
|
+
options: extracted IPv6-Opts options
|
|
912
|
+
|
|
913
|
+
Returns:
|
|
914
|
+
Parsed option data.
|
|
915
|
+
|
|
916
|
+
Note:
|
|
917
|
+
``Cmpt Length`` counts 32-bit words and may be odd
|
|
918
|
+
[:rfc:`5570#section-5.2`]; it only has to fit inside ``Opt Data
|
|
919
|
+
Len``, which
|
|
920
|
+
:func:`~pcapkit.protocols.internet.ipv6_ext.schema.calipso_pad_len`
|
|
921
|
+
has already checked while the option was unpacked.
|
|
922
|
+
|
|
923
|
+
"""
|
|
924
|
+
opt = Data_CALIPSOOption(
|
|
925
|
+
type=schema.type,
|
|
926
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
927
|
+
change=bool(schema.type & 0b00100000),
|
|
928
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
929
|
+
domain=schema.domain,
|
|
930
|
+
cmpt_len=schema.cmpt_len * 4,
|
|
931
|
+
level=schema.level,
|
|
932
|
+
checksum=schema.checksum,
|
|
933
|
+
pad=schema.pad,
|
|
934
|
+
)
|
|
935
|
+
|
|
936
|
+
if schema.cmpt_len > 0:
|
|
937
|
+
opt.__update__([
|
|
938
|
+
('cmpt_bitmap', tuple(schema.bitmap)),
|
|
939
|
+
])
|
|
940
|
+
return opt
|
|
941
|
+
|
|
942
|
+
def _read_opt_smf_dpd(self, schema: 'Schema_SMFDPDOption', *, options: 'Option') -> 'Data_SMFDPDOption': # pylint: disable=unused-argument,line-too-long
|
|
943
|
+
"""Read IPv6-Opts Simplified Multicast Forwarding Duplicate Packet Detection (``SMF_DPD``) option.
|
|
944
|
+
|
|
945
|
+
Structure of IPv6-Opts ``SMF_DPD`` option [:rfc:`6621`]:
|
|
946
|
+
|
|
947
|
+
* IPv6 ``SMF_DPD`` option header in **I-DPD** (Identification-Based DPD) mode
|
|
948
|
+
|
|
949
|
+
.. code-block:: text
|
|
950
|
+
|
|
951
|
+
0 1 2 3
|
|
952
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
953
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
954
|
+
... |0|0|0| 01000 | Opt. Data Len |
|
|
955
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
956
|
+
|0|TidTy| TidLen| TaggerID (optional) ... |
|
|
957
|
+
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
958
|
+
| | Identifier ...
|
|
959
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
960
|
+
|
|
961
|
+
* IPv6 ``SMF_DPD`` option header in **H-DPD** (Hash-Based) mode
|
|
962
|
+
|
|
963
|
+
.. code-block:: text
|
|
964
|
+
|
|
965
|
+
0 1 2 3
|
|
966
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
967
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
968
|
+
... |0|0|0| OptType | Opt. Data Len |
|
|
969
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
970
|
+
|1| Hash Assist Value (HAV) ...
|
|
971
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
972
|
+
|
|
973
|
+
Args:
|
|
974
|
+
schema: parsed parameter schema
|
|
975
|
+
options: extracted IPv6-Opts options
|
|
976
|
+
|
|
977
|
+
Returns:
|
|
978
|
+
Parsed option data.
|
|
979
|
+
|
|
980
|
+
Raises:
|
|
981
|
+
ProtocolError: If the option is malformed.
|
|
982
|
+
|
|
983
|
+
"""
|
|
984
|
+
mode = schema.mode
|
|
985
|
+
if mode == Enum_SMFDPDMode.I_DPD: # I-DPD mode
|
|
986
|
+
if TYPE_CHECKING:
|
|
987
|
+
schema = cast('Schema_SMFIdentificationBasedDPDOption', schema)
|
|
988
|
+
|
|
989
|
+
# NOTE: An unresolvable *string* key raises KeyError and an unassigned *wire* value
|
|
990
|
+
# mints via _missing_, so only a hand-constructed schema reaches this guard.
|
|
991
|
+
tid_key = None
|
|
992
|
+
try:
|
|
993
|
+
tid_key = schema.info['type']
|
|
994
|
+
tid_type = Enum_TaggerID.get(tid_key)
|
|
995
|
+
except KeyError:
|
|
996
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] '
|
|
997
|
+
f'unknown tagger-id type: {tid_key!r}') from None
|
|
998
|
+
tid_len = schema.info['len']
|
|
999
|
+
|
|
1000
|
+
opt = Data_SMFIdentificationBasedDPDOption(
|
|
1001
|
+
type=schema.type,
|
|
1002
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1003
|
+
change=bool(schema.type & 0b00100000),
|
|
1004
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
1005
|
+
dpd_type=mode,
|
|
1006
|
+
tid_type=tid_type,
|
|
1007
|
+
tid_len=tid_len,
|
|
1008
|
+
tid=schema.tid,
|
|
1009
|
+
id=schema.id,
|
|
1010
|
+
) # type: Data_SMFDPDOption
|
|
1011
|
+
elif mode == Enum_SMFDPDMode.H_DPD: # H-DPD mode
|
|
1012
|
+
if TYPE_CHECKING:
|
|
1013
|
+
schema = cast('Schema_SMFHashBasedDPDOption', schema)
|
|
1014
|
+
|
|
1015
|
+
opt = Data_SMFHashBasedDPDOption(
|
|
1016
|
+
type=schema.type,
|
|
1017
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1018
|
+
change=bool(schema.type & 0b00100000),
|
|
1019
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
1020
|
+
dpd_type=mode,
|
|
1021
|
+
hav=schema.hav,
|
|
1022
|
+
)
|
|
1023
|
+
else:
|
|
1024
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid DPD mode: {mode}')
|
|
1025
|
+
return opt
|
|
1026
|
+
|
|
1027
|
+
def _read_opt_pdm(self, schema: 'Schema_PDMOption', *, options: 'Option') -> 'Data_PDMOption': # pylint: disable=unused-argument
|
|
1028
|
+
"""Read IPv6-Opts Performance and Diagnostic Metrics (PDM) option.
|
|
1029
|
+
|
|
1030
|
+
Structure of IPv6-Opts PDM option [:rfc:`8250`]:
|
|
1031
|
+
|
|
1032
|
+
.. code-block:: text
|
|
1033
|
+
|
|
1034
|
+
0 1 2 3
|
|
1035
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
1036
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1037
|
+
| Option Type | Option Length | ScaleDTLR | ScaleDTLS |
|
|
1038
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1039
|
+
| PSN This Packet | PSN Last Received |
|
|
1040
|
+
|-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1041
|
+
| Delta Time Last Received | Delta Time Last Sent |
|
|
1042
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1043
|
+
|
|
1044
|
+
Args:
|
|
1045
|
+
schema: parsed parameter schema
|
|
1046
|
+
options: extracted IPv6-Opts options
|
|
1047
|
+
|
|
1048
|
+
Returns:
|
|
1049
|
+
Parsed option data.
|
|
1050
|
+
|
|
1051
|
+
Raises:
|
|
1052
|
+
ProtocolError: If ``schema.len`` is **NOT** ``10``.
|
|
1053
|
+
|
|
1054
|
+
"""
|
|
1055
|
+
if schema.len != 10:
|
|
1056
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid format')
|
|
1057
|
+
|
|
1058
|
+
opt = Data_PDMOption(
|
|
1059
|
+
type=schema.type,
|
|
1060
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1061
|
+
change=bool(schema.type & 0b00100000),
|
|
1062
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
1063
|
+
scaledtlr=schema.scaledtlr,
|
|
1064
|
+
scaledtls=schema.scaledtls,
|
|
1065
|
+
psntp=schema.psntp,
|
|
1066
|
+
psnlr=schema.psnlr,
|
|
1067
|
+
deltatlr=schema.deltatlr << schema.scaledtlr,
|
|
1068
|
+
deltatls=schema.deltatls << schema.scaledtls,
|
|
1069
|
+
)
|
|
1070
|
+
return opt
|
|
1071
|
+
|
|
1072
|
+
def _read_opt_rpl(self, schema: 'Schema_RPLOption', *, options: 'Option') -> 'Data_RPLOption': # pylint: disable=unused-argument
|
|
1073
|
+
"""Read IPv6-Opts Routing Protocol for Low-Power and Lossy Networks (RPL) option.
|
|
1074
|
+
|
|
1075
|
+
Structure of IPv6-Opts RPL option [:rfc:`6553`]:
|
|
1076
|
+
|
|
1077
|
+
.. code-block:: text
|
|
1078
|
+
|
|
1079
|
+
0 1 2 3
|
|
1080
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
1081
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1082
|
+
| Option Type | Opt Data Len |
|
|
1083
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1084
|
+
|O|R|F|0|0|0|0|0| RPLInstanceID | SenderRank |
|
|
1085
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1086
|
+
| (sub-TLVs) |
|
|
1087
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1088
|
+
|
|
1089
|
+
The sub-TLVs, which :rfc:`6553#section-3` says MUST be skipped when
|
|
1090
|
+
unrecognised, are kept as raw octets in ``sub_tlvs``.
|
|
1091
|
+
|
|
1092
|
+
Args:
|
|
1093
|
+
schema: parsed parameter schema
|
|
1094
|
+
options: extracted IPv6-Opts options
|
|
1095
|
+
|
|
1096
|
+
Returns:
|
|
1097
|
+
Parsed option data.
|
|
1098
|
+
|
|
1099
|
+
Raises:
|
|
1100
|
+
ProtocolError: If ``schema.len`` is less than ``4``.
|
|
1101
|
+
|
|
1102
|
+
"""
|
|
1103
|
+
if schema.len < 4:
|
|
1104
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid format')
|
|
1105
|
+
|
|
1106
|
+
opt = Data_RPLOption(
|
|
1107
|
+
type=schema.type,
|
|
1108
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1109
|
+
change=bool(schema.type & 0b00100000),
|
|
1110
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
1111
|
+
flags=Data_RPLFlags(
|
|
1112
|
+
down=bool(schema.flags['down']),
|
|
1113
|
+
rank_err=bool(schema.flags['rank_err']),
|
|
1114
|
+
fwd_err=bool(schema.flags['fwd_err']),
|
|
1115
|
+
reserved=schema.flags['reserved'],
|
|
1116
|
+
),
|
|
1117
|
+
id=schema.id,
|
|
1118
|
+
rank=schema.rank,
|
|
1119
|
+
sub_tlvs=schema.sub_tlvs,
|
|
1120
|
+
)
|
|
1121
|
+
return opt
|
|
1122
|
+
|
|
1123
|
+
def _read_opt_qs(self, schema: 'Schema_QuickStartOption', *, options: 'Option') -> 'Data_QuickStartOption': # pylint: disable=unused-argument
|
|
1124
|
+
"""Read IPv6-Opts Quick Start option.
|
|
1125
|
+
|
|
1126
|
+
Structure of IPv6-Opts Quick-Start option [:rfc:`4782`]:
|
|
1127
|
+
|
|
1128
|
+
* A Quick-Start Request:
|
|
1129
|
+
|
|
1130
|
+
.. code-block:: text
|
|
1131
|
+
|
|
1132
|
+
0 1 2 3
|
|
1133
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
1134
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1135
|
+
| Option | Length=6 | Func. | Rate | QS TTL |
|
|
1136
|
+
| | | 0000 |Request| |
|
|
1137
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1138
|
+
| QS Nonce | R |
|
|
1139
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1140
|
+
|
|
1141
|
+
* Report of Approved Rate:
|
|
1142
|
+
|
|
1143
|
+
.. code-block:: text
|
|
1144
|
+
|
|
1145
|
+
0 1 2 3
|
|
1146
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
1147
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1148
|
+
| Option | Length=6 | Func. | Rate | Not Used |
|
|
1149
|
+
| | | 1000 | Report| |
|
|
1150
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1151
|
+
| QS Nonce | R |
|
|
1152
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1153
|
+
|
|
1154
|
+
Args:
|
|
1155
|
+
schema: parsed parameter schema
|
|
1156
|
+
options: extracted IPv6-Opts options
|
|
1157
|
+
|
|
1158
|
+
Returns:
|
|
1159
|
+
Parsed option data.
|
|
1160
|
+
|
|
1161
|
+
Raises:
|
|
1162
|
+
ProtocolError: If the option is malformed.
|
|
1163
|
+
|
|
1164
|
+
Note:
|
|
1165
|
+
An option whose QS function is neither of the two above has no
|
|
1166
|
+
defined layout, so the schema keeps it as an unassigned option and
|
|
1167
|
+
it is parsed as one, see :meth:`_read_opt_none`. That dispatch is
|
|
1168
|
+
by the schema's own class, decided from the octets a file read
|
|
1169
|
+
hands it; a :class:`~pcapkit.protocols.internet.ipv6_opts.schema.QuickStartRequestOption`
|
|
1170
|
+
or :class:`~pcapkit.protocols.internet.ipv6_opts.schema.QuickStartReportOption`
|
|
1171
|
+
built directly with an unassigned ``func`` reaches this method
|
|
1172
|
+
regardless, which is why it still raises below rather than
|
|
1173
|
+
returning early.
|
|
1174
|
+
|
|
1175
|
+
"""
|
|
1176
|
+
if isinstance(schema, Schema_UnassignedOption):
|
|
1177
|
+
return self._read_opt_none(schema, options=options) # type: ignore[return-value]
|
|
1178
|
+
if schema.len != 6:
|
|
1179
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid format')
|
|
1180
|
+
|
|
1181
|
+
func = Enum_QSFunction.get(schema.flags['func'])
|
|
1182
|
+
if func == Enum_QSFunction.Quick_Start_Request:
|
|
1183
|
+
schema_req = cast('Schema_QuickStartRequestOption', schema)
|
|
1184
|
+
|
|
1185
|
+
opt = Data_QuickStartRequestOption(
|
|
1186
|
+
type=schema.type,
|
|
1187
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1188
|
+
change=bool(schema.type & 0b00100000),
|
|
1189
|
+
length=self._ipv6_opts_option_length(schema_req.len),
|
|
1190
|
+
func=func,
|
|
1191
|
+
rate=self._read_qs_rate(schema_req.flags['rate']),
|
|
1192
|
+
ttl=datetime.timedelta(seconds=schema_req.ttl),
|
|
1193
|
+
nonce=schema_req.nonce['nonce'],
|
|
1194
|
+
reserved=schema_req.nonce['reserved'],
|
|
1195
|
+
) # type: Data_QuickStartOption
|
|
1196
|
+
elif func == Enum_QSFunction.Report_of_Approved_Rate:
|
|
1197
|
+
schema_rep = cast('Schema_QuickStartReportOption', schema)
|
|
1198
|
+
|
|
1199
|
+
opt = Data_QuickStartReportOption(
|
|
1200
|
+
type=schema.type,
|
|
1201
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1202
|
+
change=bool(schema.type & 0b00100000),
|
|
1203
|
+
length=self._ipv6_opts_option_length(schema_rep.len),
|
|
1204
|
+
func=func,
|
|
1205
|
+
rate=self._read_qs_rate(schema_rep.flags['rate']),
|
|
1206
|
+
nonce=schema_rep.nonce['nonce'],
|
|
1207
|
+
reserved=schema_rep.nonce['reserved'],
|
|
1208
|
+
unused=schema_rep.reserved,
|
|
1209
|
+
)
|
|
1210
|
+
else:
|
|
1211
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] unknown QS function: {func}')
|
|
1212
|
+
return opt
|
|
1213
|
+
|
|
1214
|
+
def _read_opt_mpl(self, schema: 'Schema_MPLOption', *, options: 'Option') -> 'Data_MPLOption': # pylint: disable=unused-argument
|
|
1215
|
+
"""Read IPv6-Opts Multicast Protocol for Low-Power and Lossy Networks (MPL) option.
|
|
1216
|
+
|
|
1217
|
+
Structure of IPv6-Opts MPL option [:rfc:`7731`]:
|
|
1218
|
+
|
|
1219
|
+
.. code-block:: text
|
|
1220
|
+
|
|
1221
|
+
0 1 2 3
|
|
1222
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
1223
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1224
|
+
| Option Type | Opt Data Len |
|
|
1225
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1226
|
+
| S |M|V| rsv | sequence | seed-id (optional) |
|
|
1227
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1228
|
+
|
|
1229
|
+
Args:
|
|
1230
|
+
schema: parsed parameter schema
|
|
1231
|
+
options: extracted IPv6-Opts options
|
|
1232
|
+
|
|
1233
|
+
Returns:
|
|
1234
|
+
Parsed option data.
|
|
1235
|
+
|
|
1236
|
+
Raises:
|
|
1237
|
+
ProtocolError: If the option is malformed.
|
|
1238
|
+
|
|
1239
|
+
"""
|
|
1240
|
+
# NOTE: An unresolvable *string* key raises KeyError and an unassigned *wire* value
|
|
1241
|
+
# mints via _missing_, so only a hand-constructed schema reaches this guard.
|
|
1242
|
+
seed_key = None
|
|
1243
|
+
try:
|
|
1244
|
+
seed_key = schema.flags['type']
|
|
1245
|
+
kind = Enum_SeedID.get(seed_key)
|
|
1246
|
+
except KeyError:
|
|
1247
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] '
|
|
1248
|
+
f'unknown seed-id type: {seed_key!r}') from None
|
|
1249
|
+
clen = schema.len
|
|
1250
|
+
|
|
1251
|
+
if schema.len < 2:
|
|
1252
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid format')
|
|
1253
|
+
if kind == kind.IPV6_SOURCE_ADDRESS:
|
|
1254
|
+
if clen != 2:
|
|
1255
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid seed-id length: {clen - 2}')
|
|
1256
|
+
elif kind == kind.SEEDID_16_BIT_UNSIGNED_INTEGER:
|
|
1257
|
+
if clen != 4:
|
|
1258
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid seed-id length: {clen - 2}')
|
|
1259
|
+
elif kind == kind.SEEDID_64_BIT_UNSIGNED_INTEGER:
|
|
1260
|
+
if clen != 10:
|
|
1261
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid seed-id length: {clen - 2}')
|
|
1262
|
+
elif kind == kind.SEEDID_128_BIT_UNSIGNED_INTEGER:
|
|
1263
|
+
if clen != 18:
|
|
1264
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid seed-id length: {clen - 2}')
|
|
1265
|
+
else:
|
|
1266
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid seed-id type: {kind}')
|
|
1267
|
+
|
|
1268
|
+
opt = Data_MPLOption(
|
|
1269
|
+
type=schema.type,
|
|
1270
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1271
|
+
change=bool(schema.type & 0b00100000),
|
|
1272
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
1273
|
+
seed_type=kind,
|
|
1274
|
+
flags=Data_MPLFlags(
|
|
1275
|
+
max=bool(schema.flags['max']),
|
|
1276
|
+
drop=bool(schema.flags['drop']),
|
|
1277
|
+
reserved=schema.flags['reserved'],
|
|
1278
|
+
),
|
|
1279
|
+
seq=schema.seq,
|
|
1280
|
+
seed_id=schema.seed if schema.seed is not NO_VALUE else None, # type: ignore[comparison-overlap]
|
|
1281
|
+
)
|
|
1282
|
+
return opt
|
|
1283
|
+
|
|
1284
|
+
def _read_opt_ilnp(self, schema: 'Schema_ILNPOption', *, options: 'Option') -> 'Data_ILNPOption': # pylint: disable=unused-argument
|
|
1285
|
+
"""Read IPv6-Opts Identifier-Locator Network Protocol (ILNP) Nonce option.
|
|
1286
|
+
|
|
1287
|
+
Structure of IPv6-Opts ILNP Nonce option [:rfc:`6744`]:
|
|
1288
|
+
|
|
1289
|
+
.. code-block:: text
|
|
1290
|
+
|
|
1291
|
+
0 1 2 3
|
|
1292
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
1293
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1294
|
+
| Next Header | Hdr Ext Len | Option Type | Option Length |
|
|
1295
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1296
|
+
/ Nonce Value /
|
|
1297
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1298
|
+
|
|
1299
|
+
Args:
|
|
1300
|
+
schema: parsed parameter schema
|
|
1301
|
+
options: extracted IPv6-Opts options
|
|
1302
|
+
|
|
1303
|
+
Returns:
|
|
1304
|
+
Parsed option data.
|
|
1305
|
+
|
|
1306
|
+
"""
|
|
1307
|
+
opt = Data_ILNPOption(
|
|
1308
|
+
type=schema.type,
|
|
1309
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1310
|
+
change=bool(schema.type & 0b00100000),
|
|
1311
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
1312
|
+
nonce=schema.nonce,
|
|
1313
|
+
)
|
|
1314
|
+
return opt
|
|
1315
|
+
|
|
1316
|
+
def _read_opt_lio(self, schema: 'Schema_LineIdentificationOption', *, options: 'Option') -> 'Data_LineIdentificationOption': # pylint: disable=unused-argument
|
|
1317
|
+
"""Read IPv6-Opts Line-Identification option.
|
|
1318
|
+
|
|
1319
|
+
Structure of IPv6-Opts Line-Identification option [:rfc:`6788`]:
|
|
1320
|
+
|
|
1321
|
+
.. code-block:: text
|
|
1322
|
+
|
|
1323
|
+
0 1 2 3
|
|
1324
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
1325
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1326
|
+
| Option Type | Option Length |
|
|
1327
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1328
|
+
| LineIDLen | Line ID...
|
|
1329
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1330
|
+
|
|
1331
|
+
Args:
|
|
1332
|
+
schema: parsed parameter schema
|
|
1333
|
+
options: extracted IPv6-Opts options
|
|
1334
|
+
|
|
1335
|
+
Returns:
|
|
1336
|
+
Parsed option data.
|
|
1337
|
+
|
|
1338
|
+
"""
|
|
1339
|
+
opt = Data_LineIdentificationOption(
|
|
1340
|
+
type=schema.type,
|
|
1341
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1342
|
+
change=bool(schema.type & 0b00100000),
|
|
1343
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
1344
|
+
line_id_len=schema.id_len,
|
|
1345
|
+
line_id=schema.id,
|
|
1346
|
+
)
|
|
1347
|
+
return opt
|
|
1348
|
+
|
|
1349
|
+
def _read_opt_jumbo(self, schema: 'Schema_JumboPayloadOption', *, options: 'Option') -> 'Data_JumboPayloadOption': # pylint: disable=unused-argument
|
|
1350
|
+
"""Read IPv6-Opts Jumbo Payload option.
|
|
1351
|
+
|
|
1352
|
+
Structure of IPv6-Opts Jumbo Payload option [:rfc:`2675`]:
|
|
1353
|
+
|
|
1354
|
+
.. code-block:: text
|
|
1355
|
+
|
|
1356
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1357
|
+
| Option Type | Opt Data Len |
|
|
1358
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1359
|
+
| Jumbo Payload Length |
|
|
1360
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1361
|
+
|
|
1362
|
+
Args:
|
|
1363
|
+
schema: parsed parameter schema
|
|
1364
|
+
options: extracted IPv6-Opts options
|
|
1365
|
+
|
|
1366
|
+
Returns:
|
|
1367
|
+
Parsed option data.
|
|
1368
|
+
|
|
1369
|
+
Raises:
|
|
1370
|
+
ProtocolError: If ``schema.len`` is **NOT** ``4``.
|
|
1371
|
+
|
|
1372
|
+
"""
|
|
1373
|
+
if schema.len != 4:
|
|
1374
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid format')
|
|
1375
|
+
|
|
1376
|
+
opt = Data_JumboPayloadOption(
|
|
1377
|
+
type=schema.type,
|
|
1378
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1379
|
+
change=bool(schema.type & 0b00100000),
|
|
1380
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
1381
|
+
jumbo_len=schema.jumbo_len,
|
|
1382
|
+
)
|
|
1383
|
+
return opt
|
|
1384
|
+
|
|
1385
|
+
def _read_opt_home(self, schema: 'Schema_HomeAddressOption', *, options: 'Option') -> 'Data_HomeAddressOption': # pylint: disable=unused-argument
|
|
1386
|
+
"""Read IPv6-Opts Home Address option.
|
|
1387
|
+
|
|
1388
|
+
Structure of IPv6-Opts Home Address option [:rfc:`6275`]:
|
|
1389
|
+
|
|
1390
|
+
.. code-block:: text
|
|
1391
|
+
|
|
1392
|
+
0 1 2 3
|
|
1393
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
1394
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1395
|
+
| Option Type | Option Length |
|
|
1396
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1397
|
+
| |
|
|
1398
|
+
+ +
|
|
1399
|
+
| |
|
|
1400
|
+
+ Home Address +
|
|
1401
|
+
| |
|
|
1402
|
+
+ +
|
|
1403
|
+
| |
|
|
1404
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1405
|
+
|
|
1406
|
+
Args:
|
|
1407
|
+
schema: parsed parameter schema
|
|
1408
|
+
options: extracted IPv6-Opts options
|
|
1409
|
+
|
|
1410
|
+
Returns:
|
|
1411
|
+
Parsed option data.
|
|
1412
|
+
|
|
1413
|
+
Raises:
|
|
1414
|
+
ProtocolError: If ``schema.len`` is **NOT** ``16``.
|
|
1415
|
+
|
|
1416
|
+
"""
|
|
1417
|
+
if schema.len != 16:
|
|
1418
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid format')
|
|
1419
|
+
|
|
1420
|
+
opt = Data_HomeAddressOption(
|
|
1421
|
+
type=schema.type,
|
|
1422
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1423
|
+
change=bool(schema.type & 0b00100000),
|
|
1424
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
1425
|
+
address=schema.addr,
|
|
1426
|
+
)
|
|
1427
|
+
return opt
|
|
1428
|
+
|
|
1429
|
+
def _read_opt_ip_dff(self, schema: 'Schema_IPDFFOption', *, options: 'Option') -> 'Data_IPDFFOption': # pylint: disable=unused-argument
|
|
1430
|
+
"""Read IPv6-Opts Depth-First Forwarding (``IP_DFF``) option.
|
|
1431
|
+
|
|
1432
|
+
Structure of IPv6-Opts ``IP_DFF`` option [:rfc:`6971`]:
|
|
1433
|
+
|
|
1434
|
+
.. code-block:: text
|
|
1435
|
+
|
|
1436
|
+
1 2 3
|
|
1437
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
1438
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1439
|
+
| Next Header | Hdr Ext Len | OptTypeDFF | OptDataLenDFF |
|
|
1440
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1441
|
+
|VER|D|R|0|0|0|0| Sequence Number | Pad1 |
|
|
1442
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
1443
|
+
|
|
1444
|
+
``OptDataLenDFF`` is ``3``, the flags octet and the sequence number,
|
|
1445
|
+
as corrected by :rfc:`6971` Errata ID 3937; the RFC text says ``2``.
|
|
1446
|
+
|
|
1447
|
+
Args:
|
|
1448
|
+
schema: parsed parameter schema
|
|
1449
|
+
options: extracted IPv6-Opts options
|
|
1450
|
+
|
|
1451
|
+
Returns:
|
|
1452
|
+
Parsed option data.
|
|
1453
|
+
|
|
1454
|
+
Raises:
|
|
1455
|
+
ProtocolError: If ``schema.len`` is **NOT** ``3``.
|
|
1456
|
+
|
|
1457
|
+
"""
|
|
1458
|
+
if schema.len != 3:
|
|
1459
|
+
raise ProtocolError(f'{self.alias}: [OptNo {schema.type}] invalid format')
|
|
1460
|
+
|
|
1461
|
+
opt = Data_IPDFFOption(
|
|
1462
|
+
type=schema.type,
|
|
1463
|
+
action=Enum_OptionAction.get(schema.type >> 6),
|
|
1464
|
+
change=bool(schema.type & 0b00100000),
|
|
1465
|
+
length=self._ipv6_opts_option_length(schema.len),
|
|
1466
|
+
version=schema.flags['ver'],
|
|
1467
|
+
flags=Data_DFFFlags(
|
|
1468
|
+
dup=bool(schema.flags['dup']),
|
|
1469
|
+
ret=bool(schema.flags['ret']),
|
|
1470
|
+
reserved=schema.flags['reserved'],
|
|
1471
|
+
),
|
|
1472
|
+
seq=schema.seq,
|
|
1473
|
+
)
|
|
1474
|
+
return opt
|
|
1475
|
+
|
|
1476
|
+
def _make_opt_none(self, code: 'Enum_Option', opt: 'Optional[Data_UnassignedOption]' = None, *,
|
|
1477
|
+
data: 'bytes' = b'',
|
|
1478
|
+
**kwargs: 'Any') -> 'Schema_UnassignedOption':
|
|
1479
|
+
"""Make IPv6-Opts unassigned option.
|
|
1480
|
+
|
|
1481
|
+
Args:
|
|
1482
|
+
code: option type value
|
|
1483
|
+
opt: option data
|
|
1484
|
+
data: option payload in :obj:`bytes`
|
|
1485
|
+
**kwargs: arbitrary keyword arguments
|
|
1486
|
+
|
|
1487
|
+
Returns:
|
|
1488
|
+
Constructed option schema.
|
|
1489
|
+
|
|
1490
|
+
Raises:
|
|
1491
|
+
ProtocolError: If ``data`` is too long for the one-octet
|
|
1492
|
+
``Opt Data Len``.
|
|
1493
|
+
|
|
1494
|
+
"""
|
|
1495
|
+
if opt is not None:
|
|
1496
|
+
data = opt.data
|
|
1497
|
+
|
|
1498
|
+
return Schema_UnassignedOption(
|
|
1499
|
+
type=code,
|
|
1500
|
+
len=self._make_uint(len(data), bits=8, name='Opt Data Len'),
|
|
1501
|
+
data=data,
|
|
1502
|
+
)
|
|
1503
|
+
|
|
1504
|
+
def _make_opt_pad(self, code: 'Enum_Option', opt: 'Optional[Data_PadOption]' = None, *,
|
|
1505
|
+
length: 'int' = 0,
|
|
1506
|
+
pad: 'bytes' = b'',
|
|
1507
|
+
**kwargs: 'Any') -> 'Schema_PadOption':
|
|
1508
|
+
"""Make IPv6-Opts pad option.
|
|
1509
|
+
|
|
1510
|
+
Args:
|
|
1511
|
+
code: option type value
|
|
1512
|
+
opt: option data
|
|
1513
|
+
length: value of the ``Opt Data Len`` field, i.e. the number of
|
|
1514
|
+
padding octets *after* the two octets of the option header
|
|
1515
|
+
pad: the ``PadN`` option data, truncated or zero-filled to
|
|
1516
|
+
``length`` octets
|
|
1517
|
+
**kwargs: arbitrary keyword arguments
|
|
1518
|
+
|
|
1519
|
+
Returns:
|
|
1520
|
+
Constructed option schema.
|
|
1521
|
+
|
|
1522
|
+
Raises:
|
|
1523
|
+
ProtocolError: If ``length`` does not fit the one-octet
|
|
1524
|
+
``Opt Data Len``.
|
|
1525
|
+
|
|
1526
|
+
Warns:
|
|
1527
|
+
ProtocolWarning: If ``code`` is ``Pad1`` but ``length`` is not
|
|
1528
|
+
``0``; a ``PadN`` option is made instead.
|
|
1529
|
+
|
|
1530
|
+
Note:
|
|
1531
|
+
:attr:`Data_PadOption.length
|
|
1532
|
+
<pcapkit.protocols.internet.ipv6_opts.data.Option.length>` counts
|
|
1533
|
+
the *whole* option, whereas :attr:`Schema_PadOption.len
|
|
1534
|
+
<pcapkit.protocols.internet.ipv6_opts.schema.Option.len>` is the
|
|
1535
|
+
``Opt Data Len`` field: two octets fewer, and absent altogether for a
|
|
1536
|
+
``Pad1``. ``opt`` is honoured so that re-making a parsed padding
|
|
1537
|
+
option keeps its type and size. A ``PadN`` with ``length`` ``0`` is
|
|
1538
|
+
a valid two-octet option [:rfc:`8200#section-4.2`] and is kept.
|
|
1539
|
+
|
|
1540
|
+
"""
|
|
1541
|
+
if opt is not None:
|
|
1542
|
+
code = opt.type
|
|
1543
|
+
length = 0 if opt.type == Enum_Option.Pad1 else opt.length - 2
|
|
1544
|
+
pad = getattr(opt, 'pad', b'')
|
|
1545
|
+
|
|
1546
|
+
if code == Enum_Option.Pad1 and length != 0:
|
|
1547
|
+
warn(f'{self.alias}: [OptNo {code}] invalid length: must be 0 for a Pad1 option, '
|
|
1548
|
+
f'not {length!r}; making a PadN', ProtocolWarning)
|
|
1549
|
+
code = Enum_Option.PadN # type: ignore[assignment]
|
|
1550
|
+
|
|
1551
|
+
return Schema_PadOption(
|
|
1552
|
+
type=code,
|
|
1553
|
+
len=self._make_uint(length, bits=8, name='Opt Data Len'),
|
|
1554
|
+
pad=pad,
|
|
1555
|
+
)
|
|
1556
|
+
|
|
1557
|
+
def _make_opt_tun(self, code: 'Enum_Option', opt: 'Optional[Data_TunnelEncapsulationLimitOption]' = None, *,
|
|
1558
|
+
limit: 'int' = 0,
|
|
1559
|
+
**kwargs: 'Any') -> 'Schema_TunnelEncapsulationLimitOption':
|
|
1560
|
+
"""Make IPv6-Opts tunnel encapsulation limit option.
|
|
1561
|
+
|
|
1562
|
+
Args:
|
|
1563
|
+
code: option type value
|
|
1564
|
+
opt: option data
|
|
1565
|
+
limit: tunnel encapsulation limit
|
|
1566
|
+
**kwargs: arbitrary keyword arguments
|
|
1567
|
+
|
|
1568
|
+
Returns:
|
|
1569
|
+
Constructed option schema.
|
|
1570
|
+
|
|
1571
|
+
Raises:
|
|
1572
|
+
ProtocolError: If ``limit`` does not fit in one octet.
|
|
1573
|
+
|
|
1574
|
+
"""
|
|
1575
|
+
if opt is not None:
|
|
1576
|
+
limit = opt.limit
|
|
1577
|
+
|
|
1578
|
+
return Schema_TunnelEncapsulationLimitOption(
|
|
1579
|
+
type=code,
|
|
1580
|
+
len=1,
|
|
1581
|
+
limit=self._make_uint(limit, bits=8, name='tunnel encapsulation limit'),
|
|
1582
|
+
)
|
|
1583
|
+
|
|
1584
|
+
def _make_opt_ra(self, code: 'Enum_Option', opt: 'Optional[Data_RouterAlertOption]' = None, *,
|
|
1585
|
+
alert: 'Enum_RouterAlert | int' = Enum_RouterAlert.Datagram_contains_a_Multicast_Listener_Discovery_message, # pylint: disable=line-too-long
|
|
1586
|
+
**kwargs: 'Any') -> 'Schema_RouterAlertOption':
|
|
1587
|
+
"""Make IPv6-Opts router alert option.
|
|
1588
|
+
|
|
1589
|
+
Args:
|
|
1590
|
+
code: option type value
|
|
1591
|
+
opt: option data
|
|
1592
|
+
alert: router alert value
|
|
1593
|
+
**kwargs: arbitrary keyword arguments
|
|
1594
|
+
|
|
1595
|
+
Returns:
|
|
1596
|
+
Constructed option schema.
|
|
1597
|
+
|
|
1598
|
+
Raises:
|
|
1599
|
+
ProtocolError: If the router alert value is a name, a :obj:`bool`,
|
|
1600
|
+
or a member or code that does not fit in two octets.
|
|
1601
|
+
|
|
1602
|
+
"""
|
|
1603
|
+
value = self._make_index(opt.value if opt is not None else alert, Enum_RouterAlert,
|
|
1604
|
+
bits=16, name='router alert value')
|
|
1605
|
+
return Schema_RouterAlertOption(
|
|
1606
|
+
type=code,
|
|
1607
|
+
len=2,
|
|
1608
|
+
alert=value,
|
|
1609
|
+
)
|
|
1610
|
+
|
|
1611
|
+
def _make_opt_calipso(self, code: 'Enum_Option', opt: 'Optional[Data_CALIPSOOption]' = None, *,
|
|
1612
|
+
domain: 'int' = 0,
|
|
1613
|
+
level: 'int' = 0,
|
|
1614
|
+
checksum: 'bytes' = b'\x00\x00',
|
|
1615
|
+
bitmap: 'Optional[bytes | tuple[int, ...]]' = None,
|
|
1616
|
+
pad: 'bytes' = b'',
|
|
1617
|
+
**kwargs: 'Any') -> 'Schema_CALIPSOOption':
|
|
1618
|
+
"""Make IPv6-Opts calipso option.
|
|
1619
|
+
|
|
1620
|
+
Args:
|
|
1621
|
+
code: option type value
|
|
1622
|
+
opt: option data
|
|
1623
|
+
domain: CALIPSO domain of interpretation
|
|
1624
|
+
level: sensitivity level
|
|
1625
|
+
checksum: checksum of the option
|
|
1626
|
+
bitmap: compartment bitmap, as a bytes-like object or as an
|
|
1627
|
+
iterable of octets, such as the :obj:`tuple` the reader stores;
|
|
1628
|
+
its length must be a multiple of 4 octets
|
|
1629
|
+
pad: octets after the compartment bitmap, counted in ``Opt Data Len``
|
|
1630
|
+
**kwargs: arbitrary keyword arguments
|
|
1631
|
+
|
|
1632
|
+
Returns:
|
|
1633
|
+
Constructed option schema.
|
|
1634
|
+
|
|
1635
|
+
Raises:
|
|
1636
|
+
ProtocolError: If ``domain`` or ``level`` does not fit its field,
|
|
1637
|
+
if ``checksum`` is not two octets, if the bitmap is not
|
|
1638
|
+
bytes-like or an iterable of octets, or is
|
|
1639
|
+
not a whole number of 32-bit words, if ``pad`` is not
|
|
1640
|
+
:obj:`bytes`, or if the option data would exceed the 255 octets
|
|
1641
|
+
``Opt Data Len`` can count.
|
|
1642
|
+
|
|
1643
|
+
Note:
|
|
1644
|
+
``Cmpt Length`` on the wire counts 32-bit words [:rfc:`5570#section-5.1`],
|
|
1645
|
+
whereas the bitmap here is sized in octets.
|
|
1646
|
+
|
|
1647
|
+
"""
|
|
1648
|
+
if opt is not None:
|
|
1649
|
+
domain = opt.domain
|
|
1650
|
+
level = opt.level
|
|
1651
|
+
checksum = opt.checksum
|
|
1652
|
+
bitmap = opt.cmpt_bitmap if hasattr(opt, 'cmpt_bitmap') else None
|
|
1653
|
+
pad = opt.pad
|
|
1654
|
+
domain = self._make_uint(domain, bits=32, name='CALIPSO domain of interpretation')
|
|
1655
|
+
level = self._make_uint(level, bits=8, name='CALIPSO sensitivity level')
|
|
1656
|
+
if bitmap is None:
|
|
1657
|
+
bitmap_bytes = b''
|
|
1658
|
+
elif isinstance(bitmap, (int, str)):
|
|
1659
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] invalid CALIPSO bitmap type: '
|
|
1660
|
+
f'{type(bitmap).__name__}')
|
|
1661
|
+
else:
|
|
1662
|
+
try: # bytes-like object
|
|
1663
|
+
bitmap_bytes = bytes(memoryview(bitmap))
|
|
1664
|
+
except TypeError: # iterable of octets
|
|
1665
|
+
try:
|
|
1666
|
+
octets = tuple(bitmap)
|
|
1667
|
+
except TypeError as exc:
|
|
1668
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] invalid CALIPSO bitmap type: '
|
|
1669
|
+
f'{type(bitmap).__name__}') from exc
|
|
1670
|
+
bitmap_bytes = bytes(self._make_uint(octet, bits=8, name='CALIPSO bitmap octet')
|
|
1671
|
+
for octet in octets)
|
|
1672
|
+
if len(bitmap_bytes) % 4 != 0:
|
|
1673
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] invalid CALIPSO bitmap length: '
|
|
1674
|
+
f'{len(bitmap_bytes)}')
|
|
1675
|
+
if not isinstance(pad, (bytes, bytearray)):
|
|
1676
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] invalid CALIPSO pad type: '
|
|
1677
|
+
f'{type(pad).__name__}')
|
|
1678
|
+
if 8 + len(bitmap_bytes) + len(pad) > 255:
|
|
1679
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] too long CALIPSO option data: '
|
|
1680
|
+
f'{8 + len(bitmap_bytes) + len(pad)}')
|
|
1681
|
+
|
|
1682
|
+
return Schema_CALIPSOOption(
|
|
1683
|
+
type=code,
|
|
1684
|
+
len=8 + len(bitmap_bytes) + len(pad),
|
|
1685
|
+
domain=domain,
|
|
1686
|
+
cmpt_len=len(bitmap_bytes) // 4,
|
|
1687
|
+
level=level,
|
|
1688
|
+
checksum=self._make_octets(checksum, size=2, name='CALIPSO checksum'),
|
|
1689
|
+
bitmap=bitmap_bytes if bitmap_bytes else None,
|
|
1690
|
+
pad=pad,
|
|
1691
|
+
)
|
|
1692
|
+
|
|
1693
|
+
def _make_opt_smf_dpd(self, code: 'Enum_Option', opt: 'Optional[Data_SMFIdentificationBasedDPDOption | Data_SMFHashBasedDPDOption]' = None, *,
|
|
1694
|
+
mode: 'Enum_SMFDPDMode | int' = Enum_SMFDPDMode.I_DPD,
|
|
1695
|
+
tid_type: 'Optional[Enum_TaggerID | int]' = None,
|
|
1696
|
+
tid: 'Optional[bytes | IPv4Address | IPv6Address]' = None,
|
|
1697
|
+
id: 'bytes' = b'',
|
|
1698
|
+
hav: 'bytes' = b'',
|
|
1699
|
+
**kwargs: 'Any') -> 'Schema_SMFDPDOption':
|
|
1700
|
+
"""Make IPv6-Opts SMF DPD option.
|
|
1701
|
+
|
|
1702
|
+
Args:
|
|
1703
|
+
code: option type value
|
|
1704
|
+
opt: option data
|
|
1705
|
+
mode: DPD mode
|
|
1706
|
+
tid_type: TaggerID type (``TidTy`` field); inferred from the
|
|
1707
|
+
length of ``tid`` if not given
|
|
1708
|
+
tid: Tagger ID
|
|
1709
|
+
id: identifier
|
|
1710
|
+
hav: hash assist value (HAV)
|
|
1711
|
+
**kwargs: arbitrary keyword arguments
|
|
1712
|
+
|
|
1713
|
+
Returns:
|
|
1714
|
+
Constructed option schema.
|
|
1715
|
+
|
|
1716
|
+
Raises:
|
|
1717
|
+
ProtocolError: If the DPD mode is a name, or a member or code
|
|
1718
|
+
that does not fit in one bit; if the TaggerID type is a name,
|
|
1719
|
+
a :obj:`bool`, or a member or code that does not fit in three
|
|
1720
|
+
bits; if the Tagger ID does not fit the TaggerID type, the
|
|
1721
|
+
H-DPD Hash Assist Value is empty, or the option data is too
|
|
1722
|
+
long for its one-octet ``Opt Data Len``.
|
|
1723
|
+
|
|
1724
|
+
"""
|
|
1725
|
+
if opt is not None:
|
|
1726
|
+
mode = opt.dpd_type
|
|
1727
|
+
tid_type = getattr(opt, 'tid_type', None)
|
|
1728
|
+
tid = getattr(opt, 'tid', None)
|
|
1729
|
+
id = getattr(opt, 'id', b'')
|
|
1730
|
+
hav = getattr(opt, 'hav', b'')
|
|
1731
|
+
|
|
1732
|
+
dpd_type = self._make_index(mode, Enum_SMFDPDMode, bits=1, name='DPD mode')
|
|
1733
|
+
|
|
1734
|
+
if dpd_type == Enum_SMFDPDMode.I_DPD:
|
|
1735
|
+
if tid is None:
|
|
1736
|
+
tid_bytes = b''
|
|
1737
|
+
elif isinstance(tid, bytes):
|
|
1738
|
+
tid_bytes = tid
|
|
1739
|
+
elif tid.version in (4, 6):
|
|
1740
|
+
tid_bytes = tid.packed
|
|
1741
|
+
else:
|
|
1742
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] invalid TaggerID version: {tid.version}')
|
|
1743
|
+
tid_len = len(tid_bytes)
|
|
1744
|
+
|
|
1745
|
+
if tid_type is not None:
|
|
1746
|
+
tid_kind = self._make_index(tid_type, Enum_TaggerID, bits=3,
|
|
1747
|
+
name='TaggerID type') # type: Enum_TaggerID | int
|
|
1748
|
+
elif tid_len == 0:
|
|
1749
|
+
tid_kind = Enum_TaggerID.NULL
|
|
1750
|
+
elif tid_len == 4:
|
|
1751
|
+
tid_kind = Enum_TaggerID.IPv4
|
|
1752
|
+
elif tid_len == 16:
|
|
1753
|
+
tid_kind = Enum_TaggerID.IPv6
|
|
1754
|
+
else:
|
|
1755
|
+
tid_kind = Enum_TaggerID.DEFAULT
|
|
1756
|
+
|
|
1757
|
+
if tid_kind == Enum_TaggerID.NULL:
|
|
1758
|
+
tid_ok = tid_len == 0
|
|
1759
|
+
elif tid_kind == Enum_TaggerID.IPv4:
|
|
1760
|
+
tid_ok = tid_len == 4
|
|
1761
|
+
elif tid_kind == Enum_TaggerID.IPv6:
|
|
1762
|
+
tid_ok = tid_len == 16
|
|
1763
|
+
else:
|
|
1764
|
+
# TidLen is 4 bits and holds the length minus one.
|
|
1765
|
+
tid_ok = 1 <= tid_len <= 16
|
|
1766
|
+
if not tid_ok:
|
|
1767
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] invalid TaggerID length {tid_len} '
|
|
1768
|
+
f'for type {tid_kind}')
|
|
1769
|
+
|
|
1770
|
+
schema = Schema_SMFIdentificationBasedDPDOption(
|
|
1771
|
+
type=code,
|
|
1772
|
+
len=self._make_uint(1 + tid_len + len(id), bits=8, name='Opt Data Len'),
|
|
1773
|
+
info={
|
|
1774
|
+
'mode': 0,
|
|
1775
|
+
'type': tid_kind,
|
|
1776
|
+
'len': max(tid_len - 1, 0),
|
|
1777
|
+
},
|
|
1778
|
+
tid=tid_bytes if tid_len else None,
|
|
1779
|
+
id=id,
|
|
1780
|
+
) # type: Schema_SMFDPDOption
|
|
1781
|
+
else:
|
|
1782
|
+
# H-DPD, the other value of the one-bit mode. The first octet of
|
|
1783
|
+
# the HAV carries the H-DPD mode bit.
|
|
1784
|
+
if not hav:
|
|
1785
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] empty Hash Assist Value (HAV)')
|
|
1786
|
+
hav_ba = bytearray(hav)
|
|
1787
|
+
hav_ba[0] = hav[0] | 0x80
|
|
1788
|
+
|
|
1789
|
+
schema = Schema_SMFHashBasedDPDOption(
|
|
1790
|
+
type=code,
|
|
1791
|
+
len=self._make_uint(len(hav), bits=8, name='Opt Data Len'),
|
|
1792
|
+
hav=bytes(hav_ba),
|
|
1793
|
+
)
|
|
1794
|
+
return schema
|
|
1795
|
+
|
|
1796
|
+
def _make_opt_pdm(self, code: 'Enum_Option', opt: 'Optional[Data_PDMOption]' = None, *,
|
|
1797
|
+
psntp: 'int' = 0,
|
|
1798
|
+
psnlr: 'int' = 0,
|
|
1799
|
+
deltatlr: 'int' = 0,
|
|
1800
|
+
deltatls: 'int' = 0,
|
|
1801
|
+
scaledtlr: 'Optional[int]' = None,
|
|
1802
|
+
scaledtls: 'Optional[int]' = None,
|
|
1803
|
+
**kwargs: 'Any') -> 'Schema_PDMOption':
|
|
1804
|
+
"""Make IPv6-Opts PDM option.
|
|
1805
|
+
|
|
1806
|
+
Args:
|
|
1807
|
+
code: option type value
|
|
1808
|
+
opt: option data
|
|
1809
|
+
psntp: packet sequence number (PSN) this packet
|
|
1810
|
+
psnlr: packet sequence number (PSN) last received
|
|
1811
|
+
deltatlr: delta time last received (in attoseconds)
|
|
1812
|
+
deltatls: delta time last sent (in attoseconds)
|
|
1813
|
+
scaledtlr: scale of delta time last received; derived from
|
|
1814
|
+
``deltatlr`` if not given
|
|
1815
|
+
scaledtls: scale of delta time last sent; derived from
|
|
1816
|
+
``deltatls`` if not given
|
|
1817
|
+
**kwargs: arbitrary keyword arguments
|
|
1818
|
+
|
|
1819
|
+
Returns:
|
|
1820
|
+
Constructed option schema.
|
|
1821
|
+
|
|
1822
|
+
Raises:
|
|
1823
|
+
ProtocolError: If ``psntp`` or ``psnlr`` does not fit in two octets,
|
|
1824
|
+
a scale does not fit in one octet, or a delta is negative or,
|
|
1825
|
+
at the scale given for it, does not fit two octets.
|
|
1826
|
+
|
|
1827
|
+
"""
|
|
1828
|
+
if opt is not None:
|
|
1829
|
+
psntp = opt.psntp
|
|
1830
|
+
psnlr = opt.psnlr
|
|
1831
|
+
deltatlr = opt.deltatlr
|
|
1832
|
+
deltatls = opt.deltatls
|
|
1833
|
+
# NOTE: The parsed scales are kept so long as they still describe
|
|
1834
|
+
# the deltas, which they always do for a parsed option.
|
|
1835
|
+
if (deltatlr >> opt.scaledtlr).bit_length() <= 16:
|
|
1836
|
+
scaledtlr = opt.scaledtlr
|
|
1837
|
+
if (deltatls >> opt.scaledtls).bit_length() <= 16:
|
|
1838
|
+
scaledtls = opt.scaledtls
|
|
1839
|
+
|
|
1840
|
+
# NOTE: A delta fits two octets at the widest scale, 255, or at none.
|
|
1841
|
+
deltatlr = self._make_uint(deltatlr, bits=16 + 0xFF, name='PDM delta time last received')
|
|
1842
|
+
deltatls = self._make_uint(deltatls, bits=16 + 0xFF, name='PDM delta time last sent')
|
|
1843
|
+
if scaledtlr is None:
|
|
1844
|
+
scaledtlr = max(0, deltatlr.bit_length() - 16)
|
|
1845
|
+
if scaledtls is None:
|
|
1846
|
+
scaledtls = max(0, deltatls.bit_length() - 16)
|
|
1847
|
+
scale_dtlr = self._make_uint(scaledtlr, bits=8, name='PDM scale of delta time last received')
|
|
1848
|
+
scale_dtls = self._make_uint(scaledtls, bits=8, name='PDM scale of delta time last sent')
|
|
1849
|
+
|
|
1850
|
+
return Schema_PDMOption(
|
|
1851
|
+
type=code,
|
|
1852
|
+
len=10,
|
|
1853
|
+
scaledtlr=scale_dtlr,
|
|
1854
|
+
scaledtls=scale_dtls,
|
|
1855
|
+
psntp=self._make_uint(psntp, bits=16, name='PDM PSN this packet'),
|
|
1856
|
+
psnlr=self._make_uint(psnlr, bits=16, name='PDM PSN last received'),
|
|
1857
|
+
deltatlr=self._make_uint(deltatlr >> scale_dtlr, bits=16,
|
|
1858
|
+
name='PDM delta time last received'),
|
|
1859
|
+
deltatls=self._make_uint(deltatls >> scale_dtls, bits=16,
|
|
1860
|
+
name='PDM delta time last sent'),
|
|
1861
|
+
)
|
|
1862
|
+
|
|
1863
|
+
def _make_opt_rpl(self, code: 'Enum_Option', opt: 'Optional[Data_RPLOption]' = None, *,
|
|
1864
|
+
down: 'bool' = False,
|
|
1865
|
+
rank_err: 'bool' = False,
|
|
1866
|
+
fwd_err: 'bool' = False,
|
|
1867
|
+
id: 'int' = 0,
|
|
1868
|
+
rank: 'int' = 0,
|
|
1869
|
+
reserved: 'int' = 0,
|
|
1870
|
+
sub_tlvs: 'bytes' = b'',
|
|
1871
|
+
**kwargs: 'Any') -> 'Schema_RPLOption':
|
|
1872
|
+
"""Make IPv6-Opts RPL option.
|
|
1873
|
+
|
|
1874
|
+
Args:
|
|
1875
|
+
code: option type value
|
|
1876
|
+
opt: option data
|
|
1877
|
+
down: down flag
|
|
1878
|
+
rank_err: rank error flag
|
|
1879
|
+
fwd_err: forwarding error flag
|
|
1880
|
+
id: RPL instance ID
|
|
1881
|
+
rank: sender rank
|
|
1882
|
+
reserved: reserved flag bits, i.e. the low five bits of the flags octet
|
|
1883
|
+
sub_tlvs: sub-TLVs, as raw octets
|
|
1884
|
+
**kwargs: arbitrary keyword arguments
|
|
1885
|
+
|
|
1886
|
+
Returns:
|
|
1887
|
+
Constructed option schema.
|
|
1888
|
+
|
|
1889
|
+
Raises:
|
|
1890
|
+
ProtocolError: If ``reserved``, ``id`` or ``rank`` does not fit its
|
|
1891
|
+
field, or ``sub_tlvs`` does not fit in the option.
|
|
1892
|
+
|
|
1893
|
+
"""
|
|
1894
|
+
if opt is not None:
|
|
1895
|
+
down = opt.flags.down
|
|
1896
|
+
rank_err = opt.flags.rank_err
|
|
1897
|
+
fwd_err = opt.flags.fwd_err
|
|
1898
|
+
reserved = opt.flags.reserved
|
|
1899
|
+
id = opt.id
|
|
1900
|
+
rank = opt.rank
|
|
1901
|
+
sub_tlvs = opt.sub_tlvs
|
|
1902
|
+
|
|
1903
|
+
reserved = self._make_uint(reserved, bits=5, name='RPL reserved flags')
|
|
1904
|
+
id = self._make_uint(id, bits=8, name='RPL instance ID')
|
|
1905
|
+
rank = self._make_uint(rank, bits=16, name='RPL sender rank')
|
|
1906
|
+
if len(sub_tlvs) > 251:
|
|
1907
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] too long RPL sub-TLVs: {len(sub_tlvs)}')
|
|
1908
|
+
|
|
1909
|
+
return Schema_RPLOption(
|
|
1910
|
+
type=code,
|
|
1911
|
+
len=4 + len(sub_tlvs),
|
|
1912
|
+
flags={
|
|
1913
|
+
'down': down,
|
|
1914
|
+
'rank_err': rank_err,
|
|
1915
|
+
'fwd_err': fwd_err,
|
|
1916
|
+
'reserved': reserved,
|
|
1917
|
+
},
|
|
1918
|
+
id=id,
|
|
1919
|
+
rank=rank,
|
|
1920
|
+
sub_tlvs=sub_tlvs,
|
|
1921
|
+
)
|
|
1922
|
+
|
|
1923
|
+
def _make_opt_qs(self, code: 'Enum_Option', opt: 'Optional[Data_QuickStartOption | Data_UnassignedOption]' = None, *, # pylint: disable=line-too-long
|
|
1924
|
+
func: 'Enum_QSFunction | int' = Enum_QSFunction.Quick_Start_Request,
|
|
1925
|
+
rate: 'int' = 0,
|
|
1926
|
+
ttl: 'timedelta | int' = 0,
|
|
1927
|
+
nonce: 'int' = 0,
|
|
1928
|
+
reserved: 'int' = 0,
|
|
1929
|
+
unused: 'bytes' = b'\x00',
|
|
1930
|
+
**kwargs: 'Any') -> 'Schema_QuickStartOption | Schema_UnassignedOption':
|
|
1931
|
+
"""Make IPv6-Opts QS option.
|
|
1932
|
+
|
|
1933
|
+
Args:
|
|
1934
|
+
code: option type value
|
|
1935
|
+
opt: option data
|
|
1936
|
+
func: QS function type
|
|
1937
|
+
rate: rate (in kbps), rounded down to the nearest rate the
|
|
1938
|
+
four-bit rate code carries (:rfc:`4782#section-3.1`)
|
|
1939
|
+
ttl: time to live (in seconds)
|
|
1940
|
+
nonce: nonce value
|
|
1941
|
+
reserved: reserved bits (``R``) after the nonce
|
|
1942
|
+
unused: the "Not Used" octet of a report of approved rate
|
|
1943
|
+
**kwargs: arbitrary keyword arguments
|
|
1944
|
+
|
|
1945
|
+
Returns:
|
|
1946
|
+
Constructed option schema. An unassigned option schema if ``opt``
|
|
1947
|
+
is a Quick-Start option parsed as unassigned, see :meth:`_read_opt_qs`,
|
|
1948
|
+
or if ``func`` is neither of the assigned functions, in which case
|
|
1949
|
+
the option data takes the layout of a Quick-Start Request.
|
|
1950
|
+
|
|
1951
|
+
Raises:
|
|
1952
|
+
ProtocolError: If ``func`` is a name, a :obj:`bool`, or a member or
|
|
1953
|
+
code that does not fit in four bits, the rate code cannot carry
|
|
1954
|
+
``rate``, ``ttl``, ``nonce`` or ``reserved`` does not fit its
|
|
1955
|
+
field, or ``unused`` is not one octet.
|
|
1956
|
+
|
|
1957
|
+
"""
|
|
1958
|
+
if isinstance(opt, Data_UnassignedOption):
|
|
1959
|
+
return self._make_opt_none(code, opt)
|
|
1960
|
+
if opt is not None:
|
|
1961
|
+
func_enum = opt.func
|
|
1962
|
+
rate = opt.rate
|
|
1963
|
+
ttl = getattr(opt, 'ttl', 0)
|
|
1964
|
+
nonce = getattr(opt, 'nonce', 0)
|
|
1965
|
+
reserved = getattr(opt, 'reserved', 0)
|
|
1966
|
+
unused = getattr(opt, 'unused', b'\x00')
|
|
1967
|
+
else:
|
|
1968
|
+
func_enum = self._make_index(func, Enum_QSFunction, bits=4, name='QS function')
|
|
1969
|
+
rate_val = self._make_qs_rate(rate)
|
|
1970
|
+
ttl_value = ttl if isinstance(ttl, int) else math.floor(ttl.total_seconds())
|
|
1971
|
+
nonce = self._make_uint(nonce, bits=30, name='Quick-Start nonce')
|
|
1972
|
+
reserved = self._make_uint(reserved, bits=2, name='Quick-Start reserved')
|
|
1973
|
+
|
|
1974
|
+
if func_enum == Enum_QSFunction.Quick_Start_Request:
|
|
1975
|
+
return Schema_QuickStartRequestOption(
|
|
1976
|
+
type=code,
|
|
1977
|
+
len=6,
|
|
1978
|
+
flags={
|
|
1979
|
+
'func': func_enum,
|
|
1980
|
+
'rate': rate_val,
|
|
1981
|
+
},
|
|
1982
|
+
ttl=self._make_uint(ttl_value, bits=8, name='Quick-Start TTL'),
|
|
1983
|
+
nonce={
|
|
1984
|
+
'nonce': nonce,
|
|
1985
|
+
'reserved': reserved,
|
|
1986
|
+
},
|
|
1987
|
+
)
|
|
1988
|
+
if func_enum == Enum_QSFunction.Report_of_Approved_Rate:
|
|
1989
|
+
return Schema_QuickStartReportOption(
|
|
1990
|
+
type=code,
|
|
1991
|
+
len=6,
|
|
1992
|
+
flags={
|
|
1993
|
+
'func': func_enum,
|
|
1994
|
+
'rate': rate_val,
|
|
1995
|
+
},
|
|
1996
|
+
reserved=self._make_octets(unused, size=1, name='Quick-Start not-used octet'),
|
|
1997
|
+
nonce={
|
|
1998
|
+
'nonce': nonce,
|
|
1999
|
+
'reserved': reserved,
|
|
2000
|
+
},
|
|
2001
|
+
)
|
|
2002
|
+
func_val = self._make_uint(func_enum, bits=4, name='QS function')
|
|
2003
|
+
ttl_value = self._make_uint(ttl_value, bits=8, name='Quick-Start TTL')
|
|
2004
|
+
data = bytes([(func_val << 4) | rate_val, ttl_value]) + ((nonce << 2) | reserved).to_bytes(4, 'big')
|
|
2005
|
+
return self._make_opt_none(code, data=data)
|
|
2006
|
+
|
|
2007
|
+
def _make_opt_mpl(self, code: 'Enum_Option', opt: 'Optional[Data_MPLOption]' = None, *,
|
|
2008
|
+
seed_type: 'Optional[Enum_SeedID | int]' = None,
|
|
2009
|
+
max: 'bool' = False,
|
|
2010
|
+
drop: 'bool' = False,
|
|
2011
|
+
reserved: 'int' = 0,
|
|
2012
|
+
seq: 'int' = 0,
|
|
2013
|
+
seed: 'Optional[int | IPv6Address]' = None,
|
|
2014
|
+
**kwargs: 'Any') -> 'Schema_MPLOption':
|
|
2015
|
+
"""Make IPv6-Opts MPL option.
|
|
2016
|
+
|
|
2017
|
+
Args:
|
|
2018
|
+
code: option type value
|
|
2019
|
+
opt: option data
|
|
2020
|
+
seed_type: seed-id type (``S`` field); inferred from ``seed`` if not given
|
|
2021
|
+
max: maximum sequence number flag
|
|
2022
|
+
drop: drop packet flag
|
|
2023
|
+
reserved: reserved bits (``rsv``), i.e. the low four bits of the
|
|
2024
|
+
flags octet
|
|
2025
|
+
seq: MPL sequence number
|
|
2026
|
+
seed: MPL seed ID, ignored when the seed-id type is
|
|
2027
|
+
:attr:`~pcapkit.const.ipv6.seed_id.SeedID.IPV6_SOURCE_ADDRESS`,
|
|
2028
|
+
as the seed is then the IPv6 source address
|
|
2029
|
+
**kwargs: arbitrary keyword arguments
|
|
2030
|
+
|
|
2031
|
+
Returns:
|
|
2032
|
+
Constructed option schema.
|
|
2033
|
+
|
|
2034
|
+
Raises:
|
|
2035
|
+
ProtocolError: If the seed-id type is a name, a :obj:`bool`, or a
|
|
2036
|
+
member or code that does not fit in two bits; if the seed ID is
|
|
2037
|
+
missing or does not fit the seed-id type, or ``reserved`` or
|
|
2038
|
+
``seq`` does not fit its field.
|
|
2039
|
+
|
|
2040
|
+
"""
|
|
2041
|
+
if opt is not None:
|
|
2042
|
+
seed_type = opt.seed_type
|
|
2043
|
+
max = opt.flags.max
|
|
2044
|
+
drop = opt.flags.drop
|
|
2045
|
+
reserved = opt.flags.reserved
|
|
2046
|
+
seq = opt.seq
|
|
2047
|
+
seed = opt.seed_id
|
|
2048
|
+
|
|
2049
|
+
reserved = self._make_uint(reserved, bits=4, name='MPL reserved bits')
|
|
2050
|
+
seq = self._make_uint(seq, bits=8, name='MPL sequence number')
|
|
2051
|
+
|
|
2052
|
+
if seed_type is not None:
|
|
2053
|
+
kind = self._make_index(seed_type, Enum_SeedID, bits=2,
|
|
2054
|
+
name='MPL seed-id type') # type: Enum_SeedID | int
|
|
2055
|
+
elif seed is None or isinstance(seed, ipaddress.IPv6Address):
|
|
2056
|
+
kind = Enum_SeedID.IPV6_SOURCE_ADDRESS
|
|
2057
|
+
else:
|
|
2058
|
+
seed_bl = seed.bit_length()
|
|
2059
|
+
if seed_bl <= 16:
|
|
2060
|
+
kind = Enum_SeedID.SEEDID_16_BIT_UNSIGNED_INTEGER
|
|
2061
|
+
elif seed_bl <= 64:
|
|
2062
|
+
kind = Enum_SeedID.SEEDID_64_BIT_UNSIGNED_INTEGER
|
|
2063
|
+
else:
|
|
2064
|
+
kind = Enum_SeedID.SEEDID_128_BIT_UNSIGNED_INTEGER
|
|
2065
|
+
|
|
2066
|
+
if kind == Enum_SeedID.IPV6_SOURCE_ADDRESS:
|
|
2067
|
+
# The seed is the IPv6 source address, which is not on the wire.
|
|
2068
|
+
seed_id = None # type: Optional[int]
|
|
2069
|
+
clen = 2
|
|
2070
|
+
else:
|
|
2071
|
+
if kind == Enum_SeedID.SEEDID_16_BIT_UNSIGNED_INTEGER:
|
|
2072
|
+
clen = 4
|
|
2073
|
+
elif kind == Enum_SeedID.SEEDID_64_BIT_UNSIGNED_INTEGER:
|
|
2074
|
+
clen = 10
|
|
2075
|
+
else: # the 128-bit seed, the last value of the two-bit type
|
|
2076
|
+
clen = 18
|
|
2077
|
+
|
|
2078
|
+
if seed is None:
|
|
2079
|
+
raise ProtocolError(f'{self.alias}: [OptNo {code}] missing MPL seed ID for type {kind}')
|
|
2080
|
+
seed_id = self._make_uint(int(seed) if isinstance(seed, ipaddress.IPv6Address) else seed,
|
|
2081
|
+
bits=(clen - 2) * 8, name='MPL seed ID')
|
|
2082
|
+
|
|
2083
|
+
return Schema_MPLOption(
|
|
2084
|
+
type=code,
|
|
2085
|
+
len=clen,
|
|
2086
|
+
flags={
|
|
2087
|
+
'type': kind,
|
|
2088
|
+
'max': max,
|
|
2089
|
+
'drop': drop,
|
|
2090
|
+
'reserved': reserved,
|
|
2091
|
+
},
|
|
2092
|
+
seq=seq,
|
|
2093
|
+
seed=seed_id,
|
|
2094
|
+
)
|
|
2095
|
+
|
|
2096
|
+
def _make_opt_ilnp(self, code: 'Enum_Option', opt: 'Optional[Data_ILNPOption]' = None, *,
|
|
2097
|
+
nonce: 'int' = 0,
|
|
2098
|
+
**kwargs: 'Any') -> 'Schema_ILNPOption':
|
|
2099
|
+
"""Make IPv6-Opts ILNP option.
|
|
2100
|
+
|
|
2101
|
+
Args:
|
|
2102
|
+
code: option type value
|
|
2103
|
+
opt: option data
|
|
2104
|
+
nonce: ILNP nonce value
|
|
2105
|
+
**kwargs: arbitrary keyword arguments
|
|
2106
|
+
|
|
2107
|
+
Returns:
|
|
2108
|
+
Constructed option schema.
|
|
2109
|
+
|
|
2110
|
+
Raises:
|
|
2111
|
+
ProtocolError: If ``nonce`` is negative, or needs more octets than
|
|
2112
|
+
``Opt Data Len`` can count.
|
|
2113
|
+
|
|
2114
|
+
"""
|
|
2115
|
+
# NOTE: A parsed nonce keeps the width it had on the wire, leading zero
|
|
2116
|
+
# octets and a zero-octet nonce included.
|
|
2117
|
+
if opt is not None:
|
|
2118
|
+
return Schema_ILNPOption(
|
|
2119
|
+
type=code,
|
|
2120
|
+
len=opt.length - 2,
|
|
2121
|
+
nonce=opt.nonce,
|
|
2122
|
+
)
|
|
2123
|
+
|
|
2124
|
+
# NOTE: At least one octet, as RFC 6744 gives the option a Nonce Value
|
|
2125
|
+
# field that a nonce of 0 still fills.
|
|
2126
|
+
nonce = self._make_uint(nonce, bits=0xFF * 8, name='ILNP nonce')
|
|
2127
|
+
return Schema_ILNPOption(
|
|
2128
|
+
type=code,
|
|
2129
|
+
len=self._uint_size(nonce, minimum=1),
|
|
2130
|
+
nonce=nonce,
|
|
2131
|
+
)
|
|
2132
|
+
|
|
2133
|
+
def _make_opt_lio(self, code: 'Enum_Option', opt: 'Optional[Data_LineIdentificationOption]' = None, *,
|
|
2134
|
+
id: 'bytes' = b'',
|
|
2135
|
+
**kwargs: 'Any') -> 'Schema_LineIdentificationOption':
|
|
2136
|
+
"""Make IPv6-Opts LIO option.
|
|
2137
|
+
|
|
2138
|
+
Args:
|
|
2139
|
+
code: option type value
|
|
2140
|
+
opt: option data
|
|
2141
|
+
id: line ID value
|
|
2142
|
+
**kwargs: arbitrary keyword arguments
|
|
2143
|
+
|
|
2144
|
+
Returns:
|
|
2145
|
+
Constructed option schema.
|
|
2146
|
+
|
|
2147
|
+
Raises:
|
|
2148
|
+
ProtocolError: If ``id`` is too long for the one-octet
|
|
2149
|
+
``Opt Data Len``.
|
|
2150
|
+
|
|
2151
|
+
"""
|
|
2152
|
+
if opt is not None:
|
|
2153
|
+
id = opt.line_id
|
|
2154
|
+
|
|
2155
|
+
return Schema_LineIdentificationOption(
|
|
2156
|
+
type=code,
|
|
2157
|
+
len=self._make_uint(len(id) + 1, bits=8, name='Opt Data Len'),
|
|
2158
|
+
id_len=len(id),
|
|
2159
|
+
id=id,
|
|
2160
|
+
)
|
|
2161
|
+
|
|
2162
|
+
def _make_opt_jumbo(self, code: 'Enum_Option', opt: 'Optional[Data_JumboPayloadOption]' = None, *,
|
|
2163
|
+
len: 'int' = 0,
|
|
2164
|
+
**kwargs: 'Any') -> 'Schema_JumboPayloadOption':
|
|
2165
|
+
"""Make IPv6-Opts Jumbo Payload option.
|
|
2166
|
+
|
|
2167
|
+
Args:
|
|
2168
|
+
code: option type value
|
|
2169
|
+
opt: option data
|
|
2170
|
+
len: jumbo payload length
|
|
2171
|
+
**kwargs: arbitrary keyword arguments
|
|
2172
|
+
|
|
2173
|
+
Returns:
|
|
2174
|
+
Constructed option schema.
|
|
2175
|
+
|
|
2176
|
+
Raises:
|
|
2177
|
+
ProtocolError: If ``len`` does not fit in four octets.
|
|
2178
|
+
|
|
2179
|
+
"""
|
|
2180
|
+
if opt is not None:
|
|
2181
|
+
len = opt.jumbo_len
|
|
2182
|
+
|
|
2183
|
+
return Schema_JumboPayloadOption(
|
|
2184
|
+
type=code,
|
|
2185
|
+
len=4,
|
|
2186
|
+
jumbo_len=self._make_uint(len, bits=32, name='jumbo payload length'),
|
|
2187
|
+
)
|
|
2188
|
+
|
|
2189
|
+
def _make_opt_home(self, code: 'Enum_Option', opt: 'Optional[Data_HomeAddressOption]' = None, *,
|
|
2190
|
+
addr: 'IPv6Address | str | bytes | int' = '::',
|
|
2191
|
+
**kwargs: 'Any') -> 'Schema_HomeAddressOption':
|
|
2192
|
+
"""Make IPv6-Opts Home Address option.
|
|
2193
|
+
|
|
2194
|
+
Args:
|
|
2195
|
+
code: option type value
|
|
2196
|
+
opt: option data
|
|
2197
|
+
addr: home address value
|
|
2198
|
+
**kwargs: arbitrary keyword arguments
|
|
2199
|
+
|
|
2200
|
+
Returns:
|
|
2201
|
+
Constructed option schema.
|
|
2202
|
+
|
|
2203
|
+
"""
|
|
2204
|
+
if opt is not None:
|
|
2205
|
+
addr = opt.address
|
|
2206
|
+
|
|
2207
|
+
return Schema_HomeAddressOption(
|
|
2208
|
+
type=code,
|
|
2209
|
+
len=16,
|
|
2210
|
+
addr=addr,
|
|
2211
|
+
)
|
|
2212
|
+
|
|
2213
|
+
def _make_opt_ip_dff(self, code: 'Enum_Option', opt: 'Optional[Data_IPDFFOption]' = None, *,
|
|
2214
|
+
version: 'int' = 0,
|
|
2215
|
+
dup: 'bool' = False,
|
|
2216
|
+
ret: 'bool' = False,
|
|
2217
|
+
reserved: 'int' = 0,
|
|
2218
|
+
seq: 'int' = 0,
|
|
2219
|
+
**kwargs: 'Any') -> 'Schema_IPDFFOption':
|
|
2220
|
+
"""Make IPv6-Opts IP DFF option.
|
|
2221
|
+
|
|
2222
|
+
Args:
|
|
2223
|
+
code: option type value
|
|
2224
|
+
opt: option data
|
|
2225
|
+
version: DFF version
|
|
2226
|
+
dup: duplicate packet flag
|
|
2227
|
+
ret: return packet flag
|
|
2228
|
+
reserved: reserved bits, i.e. the low four bits of the flags octet
|
|
2229
|
+
seq: DFF sequence number
|
|
2230
|
+
**kwargs: arbitrary keyword arguments
|
|
2231
|
+
|
|
2232
|
+
Returns:
|
|
2233
|
+
Constructed option schema.
|
|
2234
|
+
|
|
2235
|
+
Raises:
|
|
2236
|
+
ProtocolError: If ``version``, ``reserved`` or ``seq`` does not fit
|
|
2237
|
+
its field.
|
|
2238
|
+
|
|
2239
|
+
"""
|
|
2240
|
+
if opt is not None:
|
|
2241
|
+
version = opt.version
|
|
2242
|
+
dup = opt.flags.dup
|
|
2243
|
+
ret = opt.flags.ret
|
|
2244
|
+
reserved = opt.flags.reserved
|
|
2245
|
+
seq = opt.seq
|
|
2246
|
+
|
|
2247
|
+
# ``OptDataLenDFF`` is 3 per RFC 6971 Errata ID 3937, see _read_opt_ip_dff.
|
|
2248
|
+
return Schema_IPDFFOption(
|
|
2249
|
+
type=code,
|
|
2250
|
+
len=3,
|
|
2251
|
+
flags={
|
|
2252
|
+
'ver': self._make_uint(version, bits=2, name='DFF version'),
|
|
2253
|
+
'dup': dup,
|
|
2254
|
+
'ret': ret,
|
|
2255
|
+
'reserved': self._make_uint(reserved, bits=4, name='DFF reserved bits'),
|
|
2256
|
+
},
|
|
2257
|
+
seq=self._make_uint(seq, bits=16, name='DFF sequence number'),
|
|
2258
|
+
)
|
|
2259
|
+
|
|
2260
|
+
def _read_opt_type(self, kind: 'int') -> 'tuple[int, bool]':
|
|
2261
|
+
"""Read option type field.
|
|
2262
|
+
|
|
2263
|
+
Arguments:
|
|
2264
|
+
kind (int): option kind value
|
|
2265
|
+
|
|
2266
|
+
Returns:
|
|
2267
|
+
Extracted IPv6-Opts option type field information (unknown option
|
|
2268
|
+
action and change flag), see [:rfc:`8200#section-4.2`].
|
|
2269
|
+
|
|
2270
|
+
"""
|
|
2271
|
+
bin_ = bin(kind)[2:].zfill(8)
|
|
2272
|
+
return int(bin_[:2], base=2), bool(int(bin_[2], base=2))
|
|
2273
|
+
|
|
2274
|
+
@staticmethod
|
|
2275
|
+
def _ipv6_opts_option_length(schema_len: 'int') -> 'int':
|
|
2276
|
+
"""Compute an IPv6-Opts option's whole-option length from its on-the-wire ``Opt Data Len``.
|
|
2277
|
+
|
|
2278
|
+
Per :rfc:`8200#section-4.2`, ``Opt Data Len`` (each ``Schema_*Option.len``)
|
|
2279
|
+
counts *"the length of the Option Data field of this option, in octets"*,
|
|
2280
|
+
so the whole option, which each ``_read_opt_*`` reports as ``.length``,
|
|
2281
|
+
is two octets more. Do NOT drop the ``+ 2``.
|
|
2282
|
+
|
|
2283
|
+
Section 4.2 is cited because the Destination Options header of
|
|
2284
|
+
:rfc:`8200#section-4.6` carries those options without defining their length.
|
|
2285
|
+
|
|
2286
|
+
Only the read side's stored lengths go through it; most ``_make_opt_*``
|
|
2287
|
+
methods recompute ``Opt Data Len`` from the value instead.
|
|
2288
|
+
|
|
2289
|
+
Args:
|
|
2290
|
+
schema_len: raw ``Opt Data Len`` field value, as read off the wire.
|
|
2291
|
+
|
|
2292
|
+
Returns:
|
|
2293
|
+
Whole-option length, in octets, including the Type and Opt Data Len fields.
|
|
2294
|
+
|
|
2295
|
+
"""
|
|
2296
|
+
return schema_len + 2
|
|
2297
|
+
|
|
2298
|
+
def _make_pad_options(self, offset: 'int') -> 'tuple[list[Schema_PadOption], int]':
|
|
2299
|
+
"""Make the padding options needed to align the header to 8 octets.
|
|
2300
|
+
|
|
2301
|
+
Args:
|
|
2302
|
+
offset: Number of octets emitted so far, **counting the two octets
|
|
2303
|
+
of the fixed header** (``Next Header`` and ``Hdr Ext Len``) as
|
|
2304
|
+
well as every option already in the list.
|
|
2305
|
+
|
|
2306
|
+
Returns:
|
|
2307
|
+
Tuple of the padding option schemas and the number of octets they
|
|
2308
|
+
occupy.
|
|
2309
|
+
|
|
2310
|
+
Note:
|
|
2311
|
+
It is the *whole* extension header, fixed part included, that has to
|
|
2312
|
+
be a multiple of 8 octets [:rfc:`8200#section-4.6`] -- which is why
|
|
2313
|
+
the alignment is computed from ``offset`` rather than from the
|
|
2314
|
+
length of the option that has just been emitted. Aligning each
|
|
2315
|
+
option to 8 octets on its own leaves the options area a multiple of
|
|
2316
|
+
8 octets long, whereas :meth:`read` sizes it as
|
|
2317
|
+
``hdr_ext_len * 8 + 6`` -- two short of a multiple of 8 -- so the
|
|
2318
|
+
header would declare 2 octets fewer than it carried.
|
|
2319
|
+
|
|
2320
|
+
A ``PadN`` option spends two octets on its own type and
|
|
2321
|
+
``Opt Data Len`` fields before any padding data, so occupying
|
|
2322
|
+
``pad_len`` octets means an ``Opt Data Len`` of ``pad_len - 2``.
|
|
2323
|
+
One octet is padded with a ``Pad1`` option instead, that being the
|
|
2324
|
+
only form which can occupy a single octet. Two octets are one
|
|
2325
|
+
``PadN`` with an ``Opt Data Len`` of ``0``, not two ``Pad1``:
|
|
2326
|
+
:rfc:`8200#section-4.2` says a ``PadN`` should be used rather than
|
|
2327
|
+
multiple ``Pad1`` options.
|
|
2328
|
+
|
|
2329
|
+
"""
|
|
2330
|
+
pad_len = pad_length(offset, 8)
|
|
2331
|
+
if pad_len == 0:
|
|
2332
|
+
return [], 0
|
|
2333
|
+
if pad_len == 1:
|
|
2334
|
+
return [self._make_opt_pad(Enum_Option.Pad1, length=0)], pad_len # type: ignore[arg-type]
|
|
2335
|
+
return [self._make_opt_pad(Enum_Option.PadN, length=pad_len - 2)], pad_len # type: ignore[arg-type]
|