icmp6.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* Copyright (C) 1991,92,93,94,95,96,97,2000 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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 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_FLAG_HOME_AGENT 0x20
  112. #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
  113. struct nd_neighbor_solicit /* neighbor solicitation */
  114. {
  115. struct icmp6_hdr nd_ns_hdr;
  116. struct in6_addr nd_ns_target; /* target address */
  117. /* could be followed by options */
  118. };
  119. #define nd_ns_type nd_ns_hdr.icmp6_type
  120. #define nd_ns_code nd_ns_hdr.icmp6_code
  121. #define nd_ns_cksum nd_ns_hdr.icmp6_cksum
  122. #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
  123. struct nd_neighbor_advert /* neighbor advertisement */
  124. {
  125. struct icmp6_hdr nd_na_hdr;
  126. struct in6_addr nd_na_target; /* target address */
  127. /* could be followed by options */
  128. };
  129. #define nd_na_type nd_na_hdr.icmp6_type
  130. #define nd_na_code nd_na_hdr.icmp6_code
  131. #define nd_na_cksum nd_na_hdr.icmp6_cksum
  132. #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0]
  133. #if BYTE_ORDER == BIG_ENDIAN
  134. #define ND_NA_FLAG_ROUTER 0x80000000
  135. #define ND_NA_FLAG_SOLICITED 0x40000000
  136. #define ND_NA_FLAG_OVERRIDE 0x20000000
  137. #else /* BYTE_ORDER == LITTLE_ENDIAN */
  138. #define ND_NA_FLAG_ROUTER 0x00000080
  139. #define ND_NA_FLAG_SOLICITED 0x00000040
  140. #define ND_NA_FLAG_OVERRIDE 0x00000020
  141. #endif
  142. struct nd_redirect /* redirect */
  143. {
  144. struct icmp6_hdr nd_rd_hdr;
  145. struct in6_addr nd_rd_target; /* target address */
  146. struct in6_addr nd_rd_dst; /* destination address */
  147. /* could be followed by options */
  148. };
  149. #define nd_rd_type nd_rd_hdr.icmp6_type
  150. #define nd_rd_code nd_rd_hdr.icmp6_code
  151. #define nd_rd_cksum nd_rd_hdr.icmp6_cksum
  152. #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
  153. struct nd_opt_hdr /* Neighbor discovery option header */
  154. {
  155. uint8_t nd_opt_type;
  156. uint8_t nd_opt_len; /* in units of 8 octets */
  157. /* followed by option specific data */
  158. };
  159. #define ND_OPT_SOURCE_LINKADDR 1
  160. #define ND_OPT_TARGET_LINKADDR 2
  161. #define ND_OPT_PREFIX_INFORMATION 3
  162. #define ND_OPT_REDIRECTED_HEADER 4
  163. #define ND_OPT_MTU 5
  164. #define ND_OPT_RTR_ADV_INTERVAL 7
  165. #define ND_OPT_HOME_AGENT_INFO 8
  166. struct nd_opt_prefix_info /* prefix information */
  167. {
  168. uint8_t nd_opt_pi_type;
  169. uint8_t nd_opt_pi_len;
  170. uint8_t nd_opt_pi_prefix_len;
  171. uint8_t nd_opt_pi_flags_reserved;
  172. uint32_t nd_opt_pi_valid_time;
  173. uint32_t nd_opt_pi_preferred_time;
  174. uint32_t nd_opt_pi_reserved2;
  175. struct in6_addr nd_opt_pi_prefix;
  176. };
  177. #define ND_OPT_PI_FLAG_ONLINK 0x80
  178. #define ND_OPT_PI_FLAG_AUTO 0x40
  179. #define ND_OPT_PI_FLAG_RADDR 0x20
  180. struct nd_opt_rd_hdr /* redirected header */
  181. {
  182. uint8_t nd_opt_rh_type;
  183. uint8_t nd_opt_rh_len;
  184. uint16_t nd_opt_rh_reserved1;
  185. uint32_t nd_opt_rh_reserved2;
  186. /* followed by IP header and data */
  187. };
  188. struct nd_opt_mtu /* MTU option */
  189. {
  190. uint8_t nd_opt_mtu_type;
  191. uint8_t nd_opt_mtu_len;
  192. uint16_t nd_opt_mtu_reserved;
  193. uint32_t nd_opt_mtu_mtu;
  194. };
  195. /* Mobile IPv6 extension: Advertisement Interval. */
  196. struct nd_opt_adv_interval
  197. {
  198. uint8_t nd_opt_adv_interval_type;
  199. uint8_t nd_opt_adv_interval_len;
  200. uint16_t nd_opt_adv_interval_reserved;
  201. uint32_t nd_opt_adv_interval_ival;
  202. };
  203. /* Mobile IPv6 extension: Home Agent Info. */
  204. struct nd_opt_home_agent_info
  205. {
  206. uint8_t nd_opt_home_agent_info_type;
  207. uint8_t nd_opt_home_agent_info_len;
  208. uint16_t nd_opt_home_agent_info_reserved;
  209. int16_t nd_opt_home_agent_info_preference;
  210. uint16_t nd_opt_home_agent_info_lifetime;
  211. };
  212. #endif /* netinet/icmpv6.h */