ipv6.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #define MIN(a, b) ((a) <= (b) ? (a) : (b))
  2. /* rfc 3513 defines the address prefices */
  3. #define isv6mcast(addr) ((addr)[0] == 0xff)
  4. #define islinklocal(addr) ((addr)[0] == 0xfe && ((addr)[1] & 0xc0) == 0x80)
  5. #define issitelocal(addr) ((addr)[0] == 0xfe && ((addr)[1] & 0xc0) == 0xc0)
  6. #define isv6global(addr) (((addr)[0] & 0xe0) == 0x20)
  7. #define optexsts(np) (nhgets((np)->ploadlen) > 24)
  8. #define issmcast(addr) (memcmp((addr), v6solicitednode, 13) == 0)
  9. /* from RFC 2460 */
  10. typedef struct Ip6hdr Ip6hdr;
  11. typedef struct Opthdr Opthdr;
  12. typedef struct Routinghdr Routinghdr;
  13. typedef struct Fraghdr6 Fraghdr6;
  14. struct Ip6hdr {
  15. uchar vcf[4]; // version:4, traffic class:8, flow label:20
  16. uchar ploadlen[2]; // payload length: packet length - 40
  17. uchar proto; // next header type
  18. uchar ttl; // hop limit
  19. uchar src[IPaddrlen];
  20. uchar dst[IPaddrlen];
  21. };
  22. struct Opthdr {
  23. uchar nexthdr;
  24. uchar len;
  25. };
  26. struct Routinghdr {
  27. uchar nexthdr;
  28. uchar len;
  29. uchar rtetype;
  30. uchar segrem;
  31. };
  32. struct Fraghdr6 {
  33. uchar nexthdr;
  34. uchar res;
  35. uchar offsetRM[2]; // Offset, Res, M flag
  36. uchar id[4];
  37. };
  38. enum { /* Header Types */
  39. HBH = 0, //?
  40. ICMP = 1,
  41. IGMP = 2,
  42. GGP = 3,
  43. IPINIP = 4,
  44. ST = 5,
  45. TCP = 6,
  46. UDP = 17,
  47. ISO_TP4 = 29,
  48. RH = 43,
  49. FH = 44,
  50. IDRP = 45,
  51. RSVP = 46,
  52. AH = 51,
  53. ESP = 52,
  54. ICMPv6 = 58,
  55. NNH = 59,
  56. DOH = 60,
  57. ISO_IP = 80,
  58. IGRP = 88,
  59. OSPF = 89,
  60. Maxhdrtype = 256,
  61. };
  62. enum {
  63. // multicast flgs and scop
  64. well_known_flg = 0,
  65. transient_flg = 1,
  66. node_local_scop = 1,
  67. link_local_scop = 2,
  68. site_local_scop = 5,
  69. org_local_scop = 8,
  70. global_scop = 14,
  71. // various prefix lengths
  72. SOLN_PREF_LEN = 13,
  73. // icmpv6 unreach codes
  74. icmp6_no_route = 0,
  75. icmp6_ad_prohib = 1,
  76. icmp6_unassigned = 2,
  77. icmp6_adr_unreach = 3,
  78. icmp6_port_unreach = 4,
  79. icmp6_unkn_code = 5,
  80. // various flags & constants
  81. v6MINTU = 1280,
  82. HOP_LIMIT = 255,
  83. ETHERHDR_LEN = 14,
  84. IPV6HDR_LEN = 40,
  85. IPV4HDR_LEN = 20,
  86. // option types
  87. SRC_LLADDRESS = 1,
  88. TARGET_LLADDRESS = 2,
  89. PREFIX_INFO = 3,
  90. REDIR_HEADER = 4,
  91. MTU_OPTION = 5,
  92. SRC_UNSPEC = 0,
  93. SRC_UNI = 1,
  94. TARG_UNI = 2,
  95. TARG_MULTI = 3,
  96. t_unitent = 1,
  97. t_uniproxy = 2,
  98. t_unirany = 3,
  99. // Router constants (all times in milliseconds)
  100. MAX_INITIAL_RTR_ADVERT_INTERVAL = 16000,
  101. MAX_INITIAL_RTR_ADVERTISEMENTS = 3,
  102. MAX_FINAL_RTR_ADVERTISEMENTS = 3,
  103. MIN_DELAY_BETWEEN_RAS = 3000,
  104. MAX_RA_DELAY_TIME = 500,
  105. // Host constants
  106. MAX_RTR_SOLICITATION_DELAY = 1000,
  107. RTR_SOLICITATION_INTERVAL = 4000,
  108. MAX_RTR_SOLICITATIONS = 3,
  109. // Node constants
  110. MAX_MULTICAST_SOLICIT = 3,
  111. MAX_UNICAST_SOLICIT = 3,
  112. MAX_ANYCAST_DELAY_TIME = 1000,
  113. MAX_NEIGHBOR_ADVERTISEMENT = 3,
  114. REACHABLE_TIME = 30000,
  115. RETRANS_TIMER = 1000,
  116. DELAY_FIRST_PROBE_TIME = 5000,
  117. };
  118. extern void ipv62smcast(uchar *, uchar *);
  119. extern void icmpns(Fs *f, uchar* src, int suni, uchar* targ, int tuni, uchar* mac);
  120. extern void icmpna(Fs *f, uchar* src, uchar* dst, uchar* targ, uchar* mac, uchar flags);
  121. extern void icmpttlexceeded6(Fs *f, Ipifc *ifc, Block *bp);
  122. extern void icmppkttoobig6(Fs *f, Ipifc *ifc, Block *bp);
  123. extern void icmphostunr(Fs *f, Ipifc *ifc, Block *bp, int code, int free);
  124. extern uchar v6allnodesN[IPaddrlen];
  125. extern uchar v6allnodesL[IPaddrlen];
  126. extern uchar v6allroutersN[IPaddrlen];
  127. extern uchar v6allroutersL[IPaddrlen];
  128. extern uchar v6allnodesNmask[IPaddrlen];
  129. extern uchar v6allnodesLmask[IPaddrlen];
  130. extern uchar v6allroutersS[IPaddrlen];
  131. extern uchar v6solicitednode[IPaddrlen];
  132. extern uchar v6solicitednodemask[IPaddrlen];
  133. extern uchar v6Unspecified[IPaddrlen];
  134. extern uchar v6loopback[IPaddrlen];
  135. extern uchar v6loopbackmask[IPaddrlen];
  136. extern uchar v6linklocal[IPaddrlen];
  137. extern uchar v6linklocalmask[IPaddrlen];
  138. extern uchar v6sitelocal[IPaddrlen];
  139. extern uchar v6sitelocalmask[IPaddrlen];
  140. extern uchar v6glunicast[IPaddrlen];
  141. extern uchar v6multicast[IPaddrlen];
  142. extern uchar v6multicastmask[IPaddrlen];
  143. extern int v6llpreflen;
  144. extern int v6slpreflen;
  145. extern int v6lbpreflen;
  146. extern int v6mcpreflen;
  147. extern int v6snpreflen;
  148. extern int v6aNpreflen;
  149. extern int v6aLpreflen;
  150. extern int ReTransTimer;