ip6.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* NetBSD: ip6.h,v 1.9 2000/07/13 05:34:21 itojun Exp */
  2. /* $KAME: ip6.h,v 1.9 2000/07/02 21:01:32 itojun Exp $ */
  3. /*
  4. * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the project nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. */
  31. /*
  32. * Copyright (c) 1982, 1986, 1993
  33. * The Regents of the University of California. All rights reserved.
  34. *
  35. * Redistribution and use in source and binary forms, with or without
  36. * modification, are permitted provided that the following conditions
  37. * are met:
  38. * 1. Redistributions of source code must retain the above copyright
  39. * notice, this list of conditions and the following disclaimer.
  40. * 2. Redistributions in binary form must reproduce the above copyright
  41. * notice, this list of conditions and the following disclaimer in the
  42. * documentation and/or other materials provided with the distribution.
  43. * 3. All advertising materials mentioning features or use of this software
  44. * must display the following acknowledgement:
  45. * This product includes software developed by the University of
  46. * California, Berkeley and its contributors.
  47. * 4. Neither the name of the University nor the names of its contributors
  48. * may be used to endorse or promote products derived from this software
  49. * without specific prior written permission.
  50. *
  51. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  52. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  54. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  55. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  56. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  57. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  58. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  59. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  60. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  61. * SUCH DAMAGE.
  62. *
  63. * @(#)ip.h 8.1 (Berkeley) 6/10/93
  64. */
  65. #ifndef _NETINET_IP6_H_
  66. #define _NETINET_IP6_H_
  67. /*
  68. * Definition for internet protocol version 6.
  69. * RFC 2460
  70. */
  71. struct ip6_hdr {
  72. union {
  73. struct ip6_hdrctl {
  74. uint32_t ip6_un1_flow; /* 20 bits of flow-ID */
  75. uint16_t ip6_un1_plen; /* payload length */
  76. uint8_t ip6_un1_nxt; /* next header */
  77. uint8_t ip6_un1_hlim; /* hop limit */
  78. } ip6_un1;
  79. uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
  80. } ip6_ctlun;
  81. struct in6_addr ip6_src; /* source address */
  82. struct in6_addr ip6_dst; /* destination address */
  83. } UNALIGNED;
  84. #define ip6_vfc ip6_ctlun.ip6_un2_vfc
  85. #define IP6_VERSION(ip6_hdr) (((ip6_hdr)->ip6_vfc & 0xf0) >> 4)
  86. #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
  87. #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
  88. #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
  89. #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
  90. #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
  91. /* in network endian */
  92. #define IPV6_FLOWINFO_MASK ((uint32_t)htonl(0x0fffffff)) /* flow info (28 bits) */
  93. #define IPV6_FLOWLABEL_MASK ((uint32_t)htonl(0x000fffff)) /* flow label (20 bits) */
  94. #if 1
  95. /* ECN bits proposed by Sally Floyd */
  96. #define IP6TOS_CE 0x01 /* congestion experienced */
  97. #define IP6TOS_ECT 0x02 /* ECN-capable transport */
  98. #endif
  99. /*
  100. * Extension Headers
  101. */
  102. struct ip6_ext {
  103. uint8_t ip6e_nxt;
  104. uint8_t ip6e_len;
  105. } UNALIGNED;
  106. /* Hop-by-Hop options header */
  107. struct ip6_hbh {
  108. uint8_t ip6h_nxt; /* next header */
  109. uint8_t ip6h_len; /* length in units of 8 octets */
  110. /* followed by options */
  111. } UNALIGNED;
  112. /* Destination options header */
  113. struct ip6_dest {
  114. uint8_t ip6d_nxt; /* next header */
  115. uint8_t ip6d_len; /* length in units of 8 octets */
  116. /* followed by options */
  117. } UNALIGNED;
  118. /* http://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml */
  119. /* Option types and related macros */
  120. #define IP6OPT_PAD1 0x00 /* 00 0 00000 */
  121. #define IP6OPT_PADN 0x01 /* 00 0 00001 */
  122. #define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
  123. #define IP6OPT_JUMBO_LEN 6
  124. #define IP6OPT_RPL 0x63 /* 01 1 00011 */
  125. #define IP6OPT_TUN_ENC_LIMIT 0x04 /* 00 0 00100 */
  126. #define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 */
  127. #define IP6OPT_RTALERT_LEN 4
  128. #define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */
  129. #define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */
  130. #define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
  131. #define IP6OPT_MINLEN 2
  132. #define IP6OPT_QUICK_START 0x26 /* 00 1 00110 */
  133. #define IP6OPT_CALIPSO 0x07 /* 00 0 00111 */
  134. #define IP6OPT_SMF_DPD 0x08 /* 00 0 01000 */
  135. #define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */
  136. #define IP6OPT_HOMEADDR_MINLEN 18
  137. #define IP6OPT_EID 0x8a /* 10 0 01010 */
  138. #define IP6OPT_ILNP_NOTICE 0x8b /* 10 0 01011 */
  139. #define IP6OPT_LINE_ID 0x8c /* 10 0 01100 */
  140. #define IP6OPT_MPL 0x6d /* 01 1 01101 */
  141. #define IP6OPT_IP_DFF 0xee /* 11 1 01110 */
  142. #define IP6OPT_TYPE(o) ((o) & 0xC0)
  143. #define IP6OPT_TYPE_SKIP 0x00
  144. #define IP6OPT_TYPE_DISCARD 0x40
  145. #define IP6OPT_TYPE_FORCEICMP 0x80
  146. #define IP6OPT_TYPE_ICMP 0xC0
  147. #define IP6OPT_MUTABLE 0x20
  148. /* Routing header */
  149. struct ip6_rthdr {
  150. uint8_t ip6r_nxt; /* next header */
  151. uint8_t ip6r_len; /* length in units of 8 octets */
  152. uint8_t ip6r_type; /* routing type */
  153. uint8_t ip6r_segleft; /* segments left */
  154. /* followed by routing type specific data */
  155. } UNALIGNED;
  156. #define IPV6_RTHDR_TYPE_0 0
  157. #define IPV6_RTHDR_TYPE_2 2
  158. /* Type 0 Routing header */
  159. /* Also used for Type 2 */
  160. struct ip6_rthdr0 {
  161. nd_uint8_t ip6r0_nxt; /* next header */
  162. nd_uint8_t ip6r0_len; /* length in units of 8 octets */
  163. nd_uint8_t ip6r0_type; /* always zero */
  164. nd_uint8_t ip6r0_segleft; /* segments left */
  165. nd_uint32_t ip6r0_reserved; /* reserved field */
  166. struct in6_addr ip6r0_addr[1]; /* up to 23 addresses */
  167. };
  168. /* Fragment header */
  169. struct ip6_frag {
  170. uint8_t ip6f_nxt; /* next header */
  171. uint8_t ip6f_reserved; /* reserved field */
  172. uint16_t ip6f_offlg; /* offset, reserved, and flag */
  173. uint32_t ip6f_ident; /* identification */
  174. } UNALIGNED;
  175. #define IP6F_OFF_MASK 0xfff8 /* mask out offset from ip6f_offlg */
  176. #define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */
  177. #define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */
  178. #endif /* not _NETINET_IP6_H_ */