1# $Id: icmp6.py 23 2006-11-08 15:45:33Z dugsong $ 2# -*- coding: utf-8 -*- 3"""Internet Control Message Protocol for IPv6.""" 4from __future__ import absolute_import 5 6from . import dpkt 7 8ICMP6_DST_UNREACH = 1 # dest unreachable, codes: 9ICMP6_PACKET_TOO_BIG = 2 # packet too big 10ICMP6_TIME_EXCEEDED = 3 # time exceeded, code: 11ICMP6_PARAM_PROB = 4 # ip6 header bad 12 13ICMP6_ECHO_REQUEST = 128 # echo service 14ICMP6_ECHO_REPLY = 129 # echo reply 15MLD_LISTENER_QUERY = 130 # multicast listener query 16MLD_LISTENER_REPORT = 131 # multicast listener report 17MLD_LISTENER_DONE = 132 # multicast listener done 18 19# RFC2292 decls 20ICMP6_MEMBERSHIP_QUERY = 130 # group membership query 21ICMP6_MEMBERSHIP_REPORT = 131 # group membership report 22ICMP6_MEMBERSHIP_REDUCTION = 132 # group membership termination 23 24ND_ROUTER_SOLICIT = 133 # router solicitation 25ND_ROUTER_ADVERT = 134 # router advertisment 26ND_NEIGHBOR_SOLICIT = 135 # neighbor solicitation 27ND_NEIGHBOR_ADVERT = 136 # neighbor advertisment 28ND_REDIRECT = 137 # redirect 29 30ICMP6_ROUTER_RENUMBERING = 138 # router renumbering 31 32ICMP6_WRUREQUEST = 139 # who are you request 33ICMP6_WRUREPLY = 140 # who are you reply 34ICMP6_FQDN_QUERY = 139 # FQDN query 35ICMP6_FQDN_REPLY = 140 # FQDN reply 36ICMP6_NI_QUERY = 139 # node information request 37ICMP6_NI_REPLY = 140 # node information reply 38 39ICMP6_MAXTYPE = 201 40 41 42class ICMP6(dpkt.Packet): 43 """Internet Control Message Protocol for IPv6. 44 45 TODO: Longer class information.... 46 47 Attributes: 48 __hdr__: Header fields of ICMPv6. 49 TODO. 50 """ 51 52 __hdr__ = ( 53 ('type', 'B', 0), 54 ('code', 'B', 0), 55 ('sum', 'H', 0) 56 ) 57 58 class Error(dpkt.Packet): 59 __hdr__ = (('pad', 'I', 0), ) 60 61 def unpack(self, buf): 62 dpkt.Packet.unpack(self, buf) 63 from . import ip6 64 self.data = self.ip6 = ip6.IP6(self.data) 65 66 class Unreach(Error): 67 pass 68 69 class TooBig(Error): 70 __hdr__ = (('mtu', 'I', 1232), ) 71 72 class TimeExceed(Error): 73 pass 74 75 class ParamProb(Error): 76 __hdr__ = (('ptr', 'I', 0), ) 77 78 class Echo(dpkt.Packet): 79 __hdr__ = (('id', 'H', 0), ('seq', 'H', 0)) 80 81 _typesw = {1: Unreach, 2: TooBig, 3: TimeExceed, 4: ParamProb, 128: Echo, 129: Echo} 82 83 def unpack(self, buf): 84 dpkt.Packet.unpack(self, buf) 85 try: 86 self.data = self._typesw[self.type](self.data) 87 setattr(self, self.data.__class__.__name__.lower(), self.data) 88 except (KeyError, dpkt.UnpackError): 89 pass 90