icmp6.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. #ifndef _NETINET_ICMP6_H
  16. #define _NETINET_ICMP6_H 1
  17. #include <inttypes.h>
  18. #include <string.h>
  19. #include <sys/types.h>
  20. #include <netinet/in.h>
  21. #define ICMP6_FILTER 1
  22. #define ICMP6_FILTER_BLOCK 1
  23. #define ICMP6_FILTER_PASS 2
  24. #define ICMP6_FILTER_BLOCKOTHERS 3
  25. #define ICMP6_FILTER_PASSONLY 4
  26. struct icmp6_filter
  27. {
  28. uint32_t data[8];
  29. };
  30. struct icmp6_hdr
  31. {
  32. uint8_t icmp6_type; /* type field */
  33. uint8_t icmp6_code; /* code field */
  34. uint16_t icmp6_cksum; /* checksum field */
  35. union
  36. {
  37. uint32_t icmp6_un_data32[1]; /* type-specific field */
  38. uint16_t icmp6_un_data16[2]; /* type-specific field */
  39. uint8_t icmp6_un_data8[4]; /* type-specific field */
  40. } icmp6_dataun;
  41. };
  42. #define icmp6_data32 icmp6_dataun.icmp6_un_data32
  43. #define icmp6_data16 icmp6_dataun.icmp6_un_data16
  44. #define icmp6_data8 icmp6_dataun.icmp6_un_data8
  45. #define icmp6_pptr icmp6_data32[0] /* parameter prob */
  46. #define icmp6_mtu icmp6_data32[0] /* packet too big */
  47. #define icmp6_id icmp6_data16[0] /* echo request/reply */
  48. #define icmp6_seq icmp6_data16[1] /* echo request/reply */
  49. #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
  50. #define ICMP6_DST_UNREACH 1
  51. #define ICMP6_PACKET_TOO_BIG 2
  52. #define ICMP6_TIME_EXCEEDED 3
  53. #define ICMP6_PARAM_PROB 4
  54. #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */
  55. #define ICMP6_ECHO_REQUEST 128
  56. #define ICMP6_ECHO_REPLY 129
  57. #define ICMP6_MEMBERSHIP_QUERY 130
  58. #define ICMP6_MEMBERSHIP_REPORT 131
  59. #define ICMP6_MEMBERSHIP_REDUCTION 132
  60. #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */
  61. #define ICMP6_DST_UNREACH_ADMIN 1 /* communication with destination */
  62. /* administratively prohibited */
  63. #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor */
  64. #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */
  65. #define ICMP6_DST_UNREACH_NOPORT 4 /* bad port */
  66. #define ICMP6_TIME_EXCEED_TRANSIT 0 /* Hop Limit == 0 in transit */
  67. #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* Reassembly time out */
  68. #define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */
  69. #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized Next Header */
  70. #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized IPv6 option */
  71. #define ICMP6_FILTER_WILLPASS(type, filterp) \
  72. ((((filterp)->data[(type) >> 5]) & (1 << ((type) & 31))) == 0)
  73. #define ICMP6_FILTER_WILLBLOCK(type, filterp) \
  74. ((((filterp)->data[(type) >> 5]) & (1 << ((type) & 31))) != 0)
  75. #define ICMP6_FILTER_SETPASS(type, filterp) \
  76. ((((filterp)->data[(type) >> 5]) &= ~(1 << ((type) & 31))))
  77. #define ICMP6_FILTER_SETBLOCK(type, filterp) \
  78. ((((filterp)->data[(type) >> 5]) |= (1 << ((type) & 31))))
  79. #define ICMP6_FILTER_SETPASSALL(filterp) \
  80. memset (filterp, 0, sizeof (struct icmp6_filter));
  81. #define ICMP6_FILTER_SETBLOCKALL(filterp) \
  82. memset (filterp, 0xFF, sizeof (struct icmp6_filter));
  83. #define ND_ROUTER_SOLICIT 133
  84. #define ND_ROUTER_ADVERT 134
  85. #define ND_NEIGHBOR_SOLICIT 135
  86. #define ND_NEIGHBOR_ADVERT 136
  87. #define ND_REDIRECT 137
  88. struct nd_router_solicit /* router solicitation */
  89. {
  90. struct icmp6_hdr nd_rs_hdr;
  91. /* could be followed by options */
  92. };
  93. #define nd_rs_type nd_rs_hdr.icmp6_type
  94. #define nd_rs_code nd_rs_hdr.icmp6_code
  95. #define nd_rs_cksum nd_rs_hdr.icmp6_cksum
  96. #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
  97. struct nd_router_advert /* router advertisement */
  98. {
  99. struct icmp6_hdr nd_ra_hdr;
  100. uint32_t nd_ra_reachable; /* reachable time */
  101. uint32_t nd_ra_retransmit; /* retransmit timer */
  102. /* could be followed by options */
  103. };
  104. #define nd_ra_type nd_ra_hdr.icmp6_type
  105. #define nd_ra_code nd_ra_hdr.icmp6_code
  106. #define nd_ra_cksum nd_ra_hdr.icmp6_cksum
  107. #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
  108. #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
  109. #define ND_RA_FLAG_MANAGED 0x80
  110. #define ND_RA_FLAG_OTHER 0x40
  111. #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
  112. struct nd_neighbor_solicit /* neighbor solicitation */
  113. {
  114. struct icmp6_hdr nd_ns_hdr;
  115. struct in6_addr nd_ns_target; /* target address */
  116. /* could be followed by options */
  117. };
  118. #define nd_ns_type nd_ns_hdr.icmp6_type
  119. #define nd_ns_code nd_ns_hdr.icmp6_code
  120. #define nd_ns_cksum nd_ns_hdr.icmp6_cksum
  121. #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
  122. struct nd_neighbor_advert /* neighbor advertisement */
  123. {
  124. struct icmp6_hdr nd_na_hdr;
  125. struct in6_addr nd_na_target; /* target address */
  126. /* could be followed by options */
  127. };
  128. #define nd_na_type nd_na_hdr.icmp6_type
  129. #define nd_na_code nd_na_hdr.icmp6_code
  130. #define nd_na_cksum nd_na_hdr.icmp6_cksum
  131. #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0]
  132. #if BYTE_ORDER == BIG_ENDIAN
  133. #define ND_NA_FLAG_ROUTER 0x80000000
  134. #define ND_NA_FLAG_SOLICITED 0x40000000
  135. #define ND_NA_FLAG_OVERRIDE 0x20000000
  136. #else /* BYTE_ORDER == LITTLE_ENDIAN */
  137. #define ND_NA_FLAG_ROUTER 0x00000080
  138. #define ND_NA_FLAG_SOLICITED 0x00000040
  139. #define ND_NA_FLAG_OVERRIDE 0x00000020
  140. #endif
  141. struct nd_redirect /* redirect */
  142. {
  143. struct icmp6_hdr nd_rd_hdr;
  144. struct in6_addr nd_rd_target; /* target address */
  145. struct in6_addr nd_rd_dst; /* destination address */
  146. /* could be followed by options */
  147. };
  148. #define nd_rd_type nd_rd_hdr.icmp6_type
  149. #define nd_rd_code nd_rd_hdr.icmp6_code
  150. #define nd_rd_cksum nd_rd_hdr.icmp6_cksum
  151. #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
  152. struct nd_opt_hdr /* Neighbor discovery option header */
  153. {
  154. uint8_t nd_opt_type;
  155. uint8_t nd_opt_len; /* in units of 8 octets */
  156. /* followed by option specific data */
  157. };
  158. #define ND_OPT_SOURCE_LINKADDR 1
  159. #define ND_OPT_TARGET_LINKADDR 2
  160. #define ND_OPT_PREFIX_INFORMATION 3
  161. #define ND_OPT_REDIRECTED_HEADER 4
  162. #define ND_OPT_MTU 5
  163. struct nd_opt_prefix_info /* prefix information */
  164. {
  165. uint8_t nd_opt_pi_type;
  166. uint8_t nd_opt_pi_len;
  167. uint8_t nd_opt_pi_prefix_len;
  168. uint8_t nd_opt_pi_flags_reserved;
  169. uint32_t nd_opt_pi_valid_time;
  170. uint32_t nd_opt_pi_preferred_time;
  171. uint32_t nd_opt_pi_reserved2;
  172. struct in6_addr nd_opt_pi_prefix;
  173. };
  174. #define ND_OPT_PI_FLAG_ONLINK 0x80
  175. #define ND_OPT_PI_FLAG_AUTO 0x40
  176. struct nd_opt_rd_hdr /* redirected header */
  177. {
  178. uint8_t nd_opt_rh_type;
  179. uint8_t nd_opt_rh_len;
  180. uint16_t nd_opt_rh_reserved1;
  181. uint32_t nd_opt_rh_reserved2;
  182. /* followed by IP header and data */
  183. };
  184. struct nd_opt_mtu /* MTU option */
  185. {
  186. uint8_t nd_opt_mtu_type;
  187. uint8_t nd_opt_mtu_len;
  188. uint16_t nd_opt_mtu_reserved;
  189. uint32_t nd_opt_mtu_mtu;
  190. };
  191. #endif /* netinet/icmpv6.h */