ip6.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* Copyright (C) 1991-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #ifndef _NETINET_IP6_H
  15. #define _NETINET_IP6_H 1
  16. #include <inttypes.h>
  17. #include <netinet/in.h>
  18. struct ip6_hdr
  19. {
  20. union
  21. {
  22. struct ip6_hdrctl
  23. {
  24. uint32_t ip6_un1_flow; /* 4 bits version, 8 bits TC,
  25. 20 bits flow-ID */
  26. uint16_t ip6_un1_plen; /* payload length */
  27. uint8_t ip6_un1_nxt; /* next header */
  28. uint8_t ip6_un1_hlim; /* hop limit */
  29. } ip6_un1;
  30. uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits tclass */
  31. } ip6_ctlun;
  32. struct in6_addr ip6_src; /* source address */
  33. struct in6_addr ip6_dst; /* destination address */
  34. };
  35. #define ip6_vfc ip6_ctlun.ip6_un2_vfc
  36. #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
  37. #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
  38. #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
  39. #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
  40. #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
  41. #define IPV6_VERSION 0x60
  42. #define IPV6_VERSION_MASK 0xf0
  43. #if __BYTE_ORDER == __BIG_ENDIAN
  44. #define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */
  45. #define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */
  46. #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
  47. #define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */
  48. #define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */
  49. #endif
  50. /* Generic extension header. */
  51. struct ip6_ext
  52. {
  53. uint8_t ip6e_nxt; /* next header. */
  54. uint8_t ip6e_len; /* length in units of 8 octets. */
  55. };
  56. /* Hop-by-Hop options header. */
  57. struct ip6_hbh
  58. {
  59. uint8_t ip6h_nxt; /* next header. */
  60. uint8_t ip6h_len; /* length in units of 8 octets. */
  61. /* followed by options */
  62. };
  63. /* Destination options header */
  64. struct ip6_dest
  65. {
  66. uint8_t ip6d_nxt; /* next header */
  67. uint8_t ip6d_len; /* length in units of 8 octets */
  68. /* followed by options */
  69. };
  70. /* Routing header */
  71. struct ip6_rthdr
  72. {
  73. uint8_t ip6r_nxt; /* next header */
  74. uint8_t ip6r_len; /* length in units of 8 octets */
  75. uint8_t ip6r_type; /* routing type */
  76. uint8_t ip6r_segleft; /* segments left */
  77. /* followed by routing type specific data */
  78. };
  79. /* Type 0 Routing header */
  80. struct ip6_rthdr0
  81. {
  82. uint8_t ip6r0_nxt; /* next header */
  83. uint8_t ip6r0_len; /* length in units of 8 octets */
  84. uint8_t ip6r0_type; /* always zero */
  85. uint8_t ip6r0_segleft; /* segments left */
  86. uint8_t ip6r0_reserved; /* reserved field */
  87. uint8_t ip6r0_slmap[3]; /* strict/loose bit map */
  88. /* followed by up to 127 struct in6_addr */
  89. struct in6_addr ip6r0_addr[0];
  90. };
  91. /* Fragment header */
  92. struct ip6_frag
  93. {
  94. uint8_t ip6f_nxt; /* next header */
  95. uint8_t ip6f_reserved; /* reserved field */
  96. uint16_t ip6f_offlg; /* offset, reserved, and flag */
  97. uint32_t ip6f_ident; /* identification */
  98. };
  99. #if __BYTE_ORDER == __BIG_ENDIAN
  100. # define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */
  101. # define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */
  102. # define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */
  103. #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
  104. # define IP6F_OFF_MASK 0xf8ff /* mask out offset from _offlg */
  105. # define IP6F_RESERVED_MASK 0x0600 /* reserved bits in ip6f_offlg */
  106. # define IP6F_MORE_FRAG 0x0100 /* more-fragments flag */
  107. #endif
  108. /* IPv6 options */
  109. struct ip6_opt
  110. {
  111. uint8_t ip6o_type;
  112. uint8_t ip6o_len;
  113. };
  114. /* The high-order 3 bits of the option type define the behavior
  115. * when processing an unknown option and whether or not the option
  116. * content changes in flight.
  117. */
  118. #define IP6OPT_TYPE(o) ((o) & 0xc0)
  119. #define IP6OPT_TYPE_SKIP 0x00
  120. #define IP6OPT_TYPE_DISCARD 0x40
  121. #define IP6OPT_TYPE_FORCEICMP 0x80
  122. #define IP6OPT_TYPE_ICMP 0xc0
  123. #define IP6OPT_TYPE_MUTABLE 0x20
  124. /* Special option types for padding. */
  125. #define IP6OPT_PAD1 0
  126. #define IP6OPT_PADN 1
  127. #define IP6OPT_JUMBO 0xc2
  128. #define IP6OPT_NSAP_ADDR 0xc3
  129. #define IP6OPT_TUNNEL_LIMIT 0x04
  130. #define IP6OPT_ROUTER_ALERT 0x05
  131. /* Jumbo Payload Option */
  132. struct ip6_opt_jumbo
  133. {
  134. uint8_t ip6oj_type;
  135. uint8_t ip6oj_len;
  136. uint8_t ip6oj_jumbo_len[4];
  137. };
  138. #define IP6OPT_JUMBO_LEN 6
  139. /* NSAP Address Option */
  140. struct ip6_opt_nsap
  141. {
  142. uint8_t ip6on_type;
  143. uint8_t ip6on_len;
  144. uint8_t ip6on_src_nsap_len;
  145. uint8_t ip6on_dst_nsap_len;
  146. /* followed by source NSAP */
  147. /* followed by destination NSAP */
  148. };
  149. /* Tunnel Limit Option */
  150. struct ip6_opt_tunnel
  151. {
  152. uint8_t ip6ot_type;
  153. uint8_t ip6ot_len;
  154. uint8_t ip6ot_encap_limit;
  155. };
  156. /* Router Alert Option */
  157. struct ip6_opt_router
  158. {
  159. uint8_t ip6or_type;
  160. uint8_t ip6or_len;
  161. uint8_t ip6or_value[2];
  162. };
  163. /* Router alert values (in network byte order) */
  164. #if __BYTE_ORDER == __BIG_ENDIAN
  165. # define IP6_ALERT_MLD 0x0000
  166. # define IP6_ALERT_RSVP 0x0001
  167. # define IP6_ALERT_AN 0x0002
  168. #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
  169. # define IP6_ALERT_MLD 0x0000
  170. # define IP6_ALERT_RSVP 0x0100
  171. # define IP6_ALERT_AN 0x0200
  172. #endif
  173. #endif /* netinet/ip6.h */