icmp6.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. """Internet Control Message Protocol for IPv6."""
  2. from pypacker import pypacker
  3. import logging
  4. logger = logging.getLogger("pypacker")
  5. ICMP6_DST_UNREACH = 1 # dest unreachable, codes:
  6. ICMP6_PACKET_TOO_BIG = 2 # packet too big
  7. ICMP6_TIME_EXCEEDED = 3 # time exceeded, code:
  8. ICMP6_PARAM_PROB = 4 # ip6 header bad
  9. ICMP6_ECHO_REQUEST = 128 # echo service
  10. ICMP6_ECHO_REPLY = 129 # echo reply
  11. MLD_LISTENER_QUERY = 130 # multicast listener query
  12. MLD_LISTENER_REPORT = 131 # multicast listener report
  13. MLD_LISTENER_DONE = 132 # multicast listener done
  14. # RFC2292 decls
  15. ICMP6_MEMBERSHIP_QUERY = 130 # group membership query
  16. ICMP6_MEMBERSHIP_REPORT = 131 # group membership report
  17. ICMP6_MEMBERSHIP_REDUCTION = 132 # group membership termination
  18. ND_ROUTER_SOLICIT = 133 # router solicitation
  19. ND_ROUTER_ADVERT = 134 # router advertisment
  20. ND_NEIGHBOR_SOLICIT = 135 # neighbor solicitation
  21. ND_NEIGHBOR_ADVERT = 136 # neighbor advertisment
  22. ND_REDIRECT = 137 # redirect
  23. ICMP6_ROUTER_RENUMBERING = 138 # router renumbering
  24. ICMP6_WRUREQUEST = 139 # who are you request
  25. ICMP6_WRUREPLY = 140 # who are you reply
  26. ICMP6_FQDN_QUERY = 139 # FQDN query
  27. ICMP6_FQDN_REPLY = 140 # FQDN reply
  28. ICMP6_NI_QUERY = 139 # node information request
  29. ICMP6_NI_REPLY = 140 # node information reply
  30. ICMP6_MAXTYPE = 201
  31. class ICMP6(pypacker.Packet):
  32. __hdr__ = (
  33. ("type", "B", 0),
  34. ("code", "B", 0),
  35. ("sum", "H", 0)
  36. )
  37. def _dissect(self, buf):
  38. self._init_handler(buf[0], buf[4:])
  39. return 4
  40. class Error(pypacker.Packet):
  41. __hdr__ = (("pad", "I", 0), )
  42. class Unreach(Error):
  43. pass
  44. class TooBig(Error):
  45. __hdr__ = (("mtu", "I", 1232), )
  46. class TimeExceed(Error):
  47. pass
  48. class ParamProb(Error):
  49. __hdr__ = (("ptr", "I", 0), )
  50. class Echo(pypacker.Packet):
  51. __hdr__ = (
  52. ("id", "H", 0),
  53. ("seq", "H", 0)
  54. )
  55. pypacker.Packet.load_handler(ICMP6,
  56. {
  57. 1: ICMP6.Unreach,
  58. 2: ICMP6.TooBig,
  59. 3: ICMP6.TimeExceed,
  60. 4: ICMP6.ParamProb,
  61. 128: ICMP6.Echo,
  62. 129: ICMP6.Echo
  63. }
  64. )