ipv6.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * Internet Protocol Version 6
  11. *
  12. * rfc2460 defines the protocol, rfc2461 neighbour discovery, and
  13. * rfc2462 address autoconfiguration. rfc4443 defines ICMP; was rfc2463.
  14. * rfc4291 defines the address architecture (including prefices), was rfc3513.
  15. * rfc4007 defines the scoped address architecture.
  16. *
  17. * global unicast is anything but unspecified (::), loopback (::1),
  18. * multicast (ff00::/8), and link-local unicast (fe80::/10).
  19. *
  20. * site-local (fec0::/10) is now deprecated, originally by rfc3879.
  21. *
  22. * Unique Local IPv6 Unicast Addresses are defined by rfc4193.
  23. * prefix is fc00::/7, scope is global, routing is limited to roughly a site.
  24. */
  25. #define isv6mcast(addr) ((addr)[0] == 0xff)
  26. #define islinklocal(addr) ((addr)[0] == 0xfe && ((addr)[1] & 0xc0) == 0x80)
  27. #define optexsts(np) (nhgets((np)->ploadlen) > 24)
  28. #define issmcast(addr) (memcmp((addr), v6solicitednode, 13) == 0)
  29. enum { /* Header Types */
  30. HBH = 0, /* hop-by-hop multicast routing protocol */
  31. ICMP = 1,
  32. IGMP = 2,
  33. GGP = 3,
  34. IPINIP = 4,
  35. ST = 5,
  36. TCP = 6,
  37. UDP = 17,
  38. ISO_TP4 = 29,
  39. RH = 43,
  40. FH = 44,
  41. IDRP = 45,
  42. RSVP = 46,
  43. AH = 51,
  44. ESP = 52,
  45. ICMPv6 = 58,
  46. NNH = 59,
  47. DOH = 60,
  48. ISO_IP = 80,
  49. IGRP = 88,
  50. OSPF = 89,
  51. Maxhdrtype = 256,
  52. };
  53. enum {
  54. /* multicast flags and scopes */
  55. // Well_known_flg = 0,
  56. // Transient_flg = 1,
  57. // Interface_local_scop = 1,
  58. Link_local_scop = 2,
  59. // Site_local_scop = 5,
  60. // Org_local_scop = 8,
  61. Global_scop = 14,
  62. /* various prefix lengths */
  63. SOLN_PREF_LEN = 13,
  64. /* icmpv6 unreachability codes */
  65. Icmp6_no_route = 0,
  66. Icmp6_ad_prohib = 1,
  67. Icmp6_out_src_scope = 2,
  68. Icmp6_adr_unreach = 3,
  69. Icmp6_port_unreach = 4,
  70. Icmp6_gress_src_fail = 5,
  71. Icmp6_rej_route = 6,
  72. Icmp6_unknown = 7, /* our own invention for internal use */
  73. /* various flags & constants */
  74. v6MINTU = 1280,
  75. HOP_LIMIT = 255,
  76. IP6HDR = 40, /* sizeof(Ip6hdr) = 8 + 2*16 */
  77. /* option types */
  78. /* neighbour discovery */
  79. SRC_LLADDR = 1,
  80. TARGET_LLADDR = 2,
  81. PREFIX_INFO = 3,
  82. REDIR_HEADER = 4,
  83. MTU_OPTION = 5,
  84. /* new since rfc2461; see iana.org/assignments/icmpv6-parameters */
  85. V6nd_home = 8,
  86. V6nd_srcaddrs = 9, /* rfc3122 */
  87. V6nd_ip = 17,
  88. /* /lib/rfc/drafts/draft-jeong-dnsop-ipv6-dns-discovery-12.txt */
  89. V6nd_rdns = 25,
  90. /* plan 9 extensions */
  91. V6nd_9fs = 250,
  92. V6nd_9auth = 251,
  93. SRC_UNSPEC = 0,
  94. SRC_UNI = 1,
  95. TARG_UNI = 2,
  96. TARG_MULTI = 3,
  97. Tunitent = 1,
  98. Tuniproxy = 2,
  99. Tunirany = 3,
  100. /* Node constants */
  101. MAX_MULTICAST_SOLICIT = 3,
  102. RETRANS_TIMER = 1000,
  103. };
  104. typedef struct Ip6hdr Ip6hdr;
  105. typedef struct Opthdr Opthdr;
  106. typedef struct Routinghdr Routinghdr;
  107. typedef struct Fraghdr6 Fraghdr6;
  108. /* we do this in case there's padding at the end of Ip6hdr */
  109. #define IPV6HDR \
  110. uint8_t vcf[4]; /* version:4, traffic class:8, flow label:20 */\
  111. uint8_t ploadlen[2]; /* payload length: packet length - 40 */ \
  112. uint8_t proto; /* next header type */ \
  113. uint8_t ttl; /* hop limit */ \
  114. uint8_t src[IPaddrlen]; \
  115. uint8_t dst[IPaddrlen]
  116. struct Ip6hdr {
  117. IPV6HDR;
  118. uint8_t payload[];
  119. };
  120. struct Opthdr { /* unused */
  121. uint8_t nexthdr;
  122. uint8_t len;
  123. };
  124. /*
  125. * Beware routing header type 0 (loose source routing); see
  126. * http://www.secdev.org/conf/IPv6_RH_security-csw07.pdf.
  127. * Type 1 is unused. Type 2 is for MIPv6 (mobile IPv6) filtering
  128. * against type 0 header.
  129. */
  130. struct Routinghdr { /* unused */
  131. uint8_t nexthdr;
  132. uint8_t len;
  133. uint8_t rtetype;
  134. uint8_t segrem;
  135. };
  136. struct Fraghdr6 {
  137. uint8_t nexthdr;
  138. uint8_t res;
  139. uint8_t offsetRM[2]; /* Offset, Res, M flag */
  140. uint8_t id[4];
  141. };
  142. extern uint8_t v6allnodesN[IPaddrlen];
  143. extern uint8_t v6allnodesL[IPaddrlen];
  144. extern uint8_t v6allroutersN[IPaddrlen];
  145. extern uint8_t v6allroutersL[IPaddrlen];
  146. extern uint8_t v6allnodesNmask[IPaddrlen];
  147. extern uint8_t v6allnodesLmask[IPaddrlen];
  148. extern uint8_t v6solicitednode[IPaddrlen];
  149. extern uint8_t v6solicitednodemask[IPaddrlen];
  150. extern uint8_t v6Unspecified[IPaddrlen];
  151. extern uint8_t v6loopback[IPaddrlen];
  152. extern uint8_t v6loopbackmask[IPaddrlen];
  153. extern uint8_t v6linklocal[IPaddrlen];
  154. extern uint8_t v6linklocalmask[IPaddrlen];
  155. extern uint8_t v6multicast[IPaddrlen];
  156. extern uint8_t v6multicastmask[IPaddrlen];
  157. extern int v6llpreflen;
  158. extern int v6mcpreflen;
  159. extern int v6snpreflen;
  160. extern int v6aNpreflen;
  161. extern int v6aLpreflen;
  162. extern int ReTransTimer;
  163. void ipv62smcast(uint8_t *, uint8_t *);
  164. void icmpns(Fs *f, uint8_t* src, int suni, uint8_t* targ, int tuni, uint8_t* mac);
  165. void icmpna(Fs *f, uint8_t* src, uint8_t* dst, uint8_t* targ, uint8_t* mac, uint8_t flags);
  166. void icmpttlexceeded6(Fs *f, Ipifc *ifc, Block *bp);
  167. void icmppkttoobig6(Fs *f, Ipifc *ifc, Block *bp);
  168. void icmphostunr(Fs *f, Ipifc *ifc, Block *bp, int code, int free);