icmp6.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /* Copyright (C) 1991-1997,2000,2006,2009 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 icmp6_filt[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 MLD_LISTENER_QUERY 130
  58. #define MLD_LISTENER_REPORT 131
  59. #define MLD_LISTENER_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_BEYONDSCOPE 2 /* beyond scope of source address */
  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)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
  73. #define ICMP6_FILTER_WILLBLOCK(type, filterp) \
  74. ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
  75. #define ICMP6_FILTER_SETPASS(type, filterp) \
  76. ((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))))
  77. #define ICMP6_FILTER_SETBLOCK(type, filterp) \
  78. ((((filterp)->icmp6_filt[(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. struct mld_hdr
  196. {
  197. struct icmp6_hdr mld_icmp6_hdr;
  198. struct in6_addr mld_addr; /* multicast address */
  199. };
  200. #define mld_type mld_icmp6_hdr.icmp6_type
  201. #define mld_code mld_icmp6_hdr.icmp6_code
  202. #define mld_cksum mld_icmp6_hdr.icmp6_cksum
  203. #define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0]
  204. #define mld_reserved mld_icmp6_hdr.icmp6_data16[1]
  205. #define ICMP6_ROUTER_RENUMBERING 138
  206. struct icmp6_router_renum /* router renumbering header */
  207. {
  208. struct icmp6_hdr rr_hdr;
  209. uint8_t rr_segnum;
  210. uint8_t rr_flags;
  211. uint16_t rr_maxdelay;
  212. uint32_t rr_reserved;
  213. };
  214. #define rr_type rr_hdr.icmp6_type
  215. #define rr_code rr_hdr.icmp6_code
  216. #define rr_cksum rr_hdr.icmp6_cksum
  217. #define rr_seqnum rr_hdr.icmp6_data32[0]
  218. /* Router renumbering flags */
  219. #define ICMP6_RR_FLAGS_TEST 0x80
  220. #define ICMP6_RR_FLAGS_REQRESULT 0x40
  221. #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20
  222. #define ICMP6_RR_FLAGS_SPECSITE 0x10
  223. #define ICMP6_RR_FLAGS_PREVDONE 0x08
  224. struct rr_pco_match /* match prefix part */
  225. {
  226. uint8_t rpm_code;
  227. uint8_t rpm_len;
  228. uint8_t rpm_ordinal;
  229. uint8_t rpm_matchlen;
  230. uint8_t rpm_minlen;
  231. uint8_t rpm_maxlen;
  232. uint16_t rpm_reserved;
  233. struct in6_addr rpm_prefix;
  234. };
  235. /* PCO code values */
  236. #define RPM_PCO_ADD 1
  237. #define RPM_PCO_CHANGE 2
  238. #define RPM_PCO_SETGLOBAL 3
  239. struct rr_pco_use /* use prefix part */
  240. {
  241. uint8_t rpu_uselen;
  242. uint8_t rpu_keeplen;
  243. uint8_t rpu_ramask;
  244. uint8_t rpu_raflags;
  245. uint32_t rpu_vltime;
  246. uint32_t rpu_pltime;
  247. uint32_t rpu_flags;
  248. struct in6_addr rpu_prefix;
  249. };
  250. #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x20
  251. #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x10
  252. #if __BYTE_ORDER == __BIG_ENDIAN
  253. # define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000
  254. # define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000
  255. #elif __BYTE_ORDER == __LITTLE_ENDIAN
  256. # define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80
  257. # define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40
  258. #endif
  259. struct rr_result /* router renumbering result message */
  260. {
  261. uint16_t rrr_flags;
  262. uint8_t rrr_ordinal;
  263. uint8_t rrr_matchedlen;
  264. uint32_t rrr_ifid;
  265. struct in6_addr rrr_prefix;
  266. };
  267. #if __BYTE_ORDER == __BIG_ENDIAN
  268. # define ICMP6_RR_RESULT_FLAGS_OOB 0x0002
  269. # define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001
  270. #elif __BYTE_ORDER == __LITTLE_ENDIAN
  271. # define ICMP6_RR_RESULT_FLAGS_OOB 0x0200
  272. # define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100
  273. #endif
  274. /* Mobile IPv6 extension: Advertisement Interval. */
  275. struct nd_opt_adv_interval
  276. {
  277. uint8_t nd_opt_adv_interval_type;
  278. uint8_t nd_opt_adv_interval_len;
  279. uint16_t nd_opt_adv_interval_reserved;
  280. uint32_t nd_opt_adv_interval_ival;
  281. };
  282. /* Mobile IPv6 extension: Home Agent Info. */
  283. struct nd_opt_home_agent_info
  284. {
  285. uint8_t nd_opt_home_agent_info_type;
  286. uint8_t nd_opt_home_agent_info_len;
  287. uint16_t nd_opt_home_agent_info_reserved;
  288. uint16_t nd_opt_home_agent_info_preference;
  289. uint16_t nd_opt_home_agent_info_lifetime;
  290. };
  291. #endif /* netinet/icmpv6.h */