icmp6.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /* Copyright (C) 1991-2020 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_ICMP6_H
  15. #define _NETINET_ICMP6_H 1
  16. #include <inttypes.h>
  17. #include <string.h>
  18. #include <sys/types.h>
  19. #include <netinet/in.h>
  20. #define ICMP6_FILTER 1
  21. #define ICMP6_FILTER_BLOCK 1
  22. #define ICMP6_FILTER_PASS 2
  23. #define ICMP6_FILTER_BLOCKOTHERS 3
  24. #define ICMP6_FILTER_PASSONLY 4
  25. struct icmp6_filter
  26. {
  27. uint32_t icmp6_filt[8];
  28. };
  29. struct icmp6_hdr
  30. {
  31. uint8_t icmp6_type; /* type field */
  32. uint8_t icmp6_code; /* code field */
  33. uint16_t icmp6_cksum; /* checksum field */
  34. union
  35. {
  36. uint32_t icmp6_un_data32[1]; /* type-specific field */
  37. uint16_t icmp6_un_data16[2]; /* type-specific field */
  38. uint8_t icmp6_un_data8[4]; /* type-specific field */
  39. } icmp6_dataun;
  40. };
  41. #define icmp6_data32 icmp6_dataun.icmp6_un_data32
  42. #define icmp6_data16 icmp6_dataun.icmp6_un_data16
  43. #define icmp6_data8 icmp6_dataun.icmp6_un_data8
  44. #define icmp6_pptr icmp6_data32[0] /* parameter prob */
  45. #define icmp6_mtu icmp6_data32[0] /* packet too big */
  46. #define icmp6_id icmp6_data16[0] /* echo request/reply */
  47. #define icmp6_seq icmp6_data16[1] /* echo request/reply */
  48. #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
  49. #define ICMP6_DST_UNREACH 1
  50. #define ICMP6_PACKET_TOO_BIG 2
  51. #define ICMP6_TIME_EXCEEDED 3
  52. #define ICMP6_PARAM_PROB 4
  53. #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */
  54. #define ICMP6_ECHO_REQUEST 128
  55. #define ICMP6_ECHO_REPLY 129
  56. #define MLD_LISTENER_QUERY 130
  57. #define MLD_LISTENER_REPORT 131
  58. #define MLD_LISTENER_REDUCTION 132
  59. #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */
  60. #define ICMP6_DST_UNREACH_ADMIN 1 /* communication with destination */
  61. /* administratively prohibited */
  62. #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */
  63. #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */
  64. #define ICMP6_DST_UNREACH_NOPORT 4 /* bad port */
  65. #define ICMP6_TIME_EXCEED_TRANSIT 0 /* Hop Limit == 0 in transit */
  66. #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* Reassembly time out */
  67. #define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */
  68. #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized Next Header */
  69. #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized IPv6 option */
  70. #define ICMP6_FILTER_WILLPASS(type, filterp) \
  71. ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
  72. #define ICMP6_FILTER_WILLBLOCK(type, filterp) \
  73. ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
  74. #define ICMP6_FILTER_SETPASS(type, filterp) \
  75. ((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))))
  76. #define ICMP6_FILTER_SETBLOCK(type, filterp) \
  77. ((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31))))
  78. #define ICMP6_FILTER_SETPASSALL(filterp) \
  79. memset (filterp, 0, sizeof (struct icmp6_filter));
  80. #define ICMP6_FILTER_SETBLOCKALL(filterp) \
  81. memset (filterp, 0xFF, sizeof (struct icmp6_filter));
  82. #define ND_ROUTER_SOLICIT 133
  83. #define ND_ROUTER_ADVERT 134
  84. #define ND_NEIGHBOR_SOLICIT 135
  85. #define ND_NEIGHBOR_ADVERT 136
  86. #define ND_REDIRECT 137
  87. struct nd_router_solicit /* router solicitation */
  88. {
  89. struct icmp6_hdr nd_rs_hdr;
  90. /* could be followed by options */
  91. };
  92. #define nd_rs_type nd_rs_hdr.icmp6_type
  93. #define nd_rs_code nd_rs_hdr.icmp6_code
  94. #define nd_rs_cksum nd_rs_hdr.icmp6_cksum
  95. #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
  96. struct nd_router_advert /* router advertisement */
  97. {
  98. struct icmp6_hdr nd_ra_hdr;
  99. uint32_t nd_ra_reachable; /* reachable time */
  100. uint32_t nd_ra_retransmit; /* retransmit timer */
  101. /* could be followed by options */
  102. };
  103. #define nd_ra_type nd_ra_hdr.icmp6_type
  104. #define nd_ra_code nd_ra_hdr.icmp6_code
  105. #define nd_ra_cksum nd_ra_hdr.icmp6_cksum
  106. #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
  107. #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
  108. #define ND_RA_FLAG_MANAGED 0x80
  109. #define ND_RA_FLAG_OTHER 0x40
  110. #define ND_RA_FLAG_HOME_AGENT 0x20
  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. #define ND_OPT_RTR_ADV_INTERVAL 7
  164. #define ND_OPT_HOME_AGENT_INFO 8
  165. struct nd_opt_prefix_info /* prefix information */
  166. {
  167. uint8_t nd_opt_pi_type;
  168. uint8_t nd_opt_pi_len;
  169. uint8_t nd_opt_pi_prefix_len;
  170. uint8_t nd_opt_pi_flags_reserved;
  171. uint32_t nd_opt_pi_valid_time;
  172. uint32_t nd_opt_pi_preferred_time;
  173. uint32_t nd_opt_pi_reserved2;
  174. struct in6_addr nd_opt_pi_prefix;
  175. };
  176. #define ND_OPT_PI_FLAG_ONLINK 0x80
  177. #define ND_OPT_PI_FLAG_AUTO 0x40
  178. #define ND_OPT_PI_FLAG_RADDR 0x20
  179. struct nd_opt_rd_hdr /* redirected header */
  180. {
  181. uint8_t nd_opt_rh_type;
  182. uint8_t nd_opt_rh_len;
  183. uint16_t nd_opt_rh_reserved1;
  184. uint32_t nd_opt_rh_reserved2;
  185. /* followed by IP header and data */
  186. };
  187. struct nd_opt_mtu /* MTU option */
  188. {
  189. uint8_t nd_opt_mtu_type;
  190. uint8_t nd_opt_mtu_len;
  191. uint16_t nd_opt_mtu_reserved;
  192. uint32_t nd_opt_mtu_mtu;
  193. };
  194. struct mld_hdr
  195. {
  196. struct icmp6_hdr mld_icmp6_hdr;
  197. struct in6_addr mld_addr; /* multicast address */
  198. };
  199. #define mld_type mld_icmp6_hdr.icmp6_type
  200. #define mld_code mld_icmp6_hdr.icmp6_code
  201. #define mld_cksum mld_icmp6_hdr.icmp6_cksum
  202. #define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0]
  203. #define mld_reserved mld_icmp6_hdr.icmp6_data16[1]
  204. #define ICMP6_ROUTER_RENUMBERING 138
  205. struct icmp6_router_renum /* router renumbering header */
  206. {
  207. struct icmp6_hdr rr_hdr;
  208. uint8_t rr_segnum;
  209. uint8_t rr_flags;
  210. uint16_t rr_maxdelay;
  211. uint32_t rr_reserved;
  212. };
  213. #define rr_type rr_hdr.icmp6_type
  214. #define rr_code rr_hdr.icmp6_code
  215. #define rr_cksum rr_hdr.icmp6_cksum
  216. #define rr_seqnum rr_hdr.icmp6_data32[0]
  217. /* Router renumbering flags */
  218. #define ICMP6_RR_FLAGS_TEST 0x80
  219. #define ICMP6_RR_FLAGS_REQRESULT 0x40
  220. #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20
  221. #define ICMP6_RR_FLAGS_SPECSITE 0x10
  222. #define ICMP6_RR_FLAGS_PREVDONE 0x08
  223. struct rr_pco_match /* match prefix part */
  224. {
  225. uint8_t rpm_code;
  226. uint8_t rpm_len;
  227. uint8_t rpm_ordinal;
  228. uint8_t rpm_matchlen;
  229. uint8_t rpm_minlen;
  230. uint8_t rpm_maxlen;
  231. uint16_t rpm_reserved;
  232. struct in6_addr rpm_prefix;
  233. };
  234. /* PCO code values */
  235. #define RPM_PCO_ADD 1
  236. #define RPM_PCO_CHANGE 2
  237. #define RPM_PCO_SETGLOBAL 3
  238. struct rr_pco_use /* use prefix part */
  239. {
  240. uint8_t rpu_uselen;
  241. uint8_t rpu_keeplen;
  242. uint8_t rpu_ramask;
  243. uint8_t rpu_raflags;
  244. uint32_t rpu_vltime;
  245. uint32_t rpu_pltime;
  246. uint32_t rpu_flags;
  247. struct in6_addr rpu_prefix;
  248. };
  249. #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x20
  250. #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x10
  251. #if __BYTE_ORDER == __BIG_ENDIAN
  252. # define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000
  253. # define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000
  254. #elif __BYTE_ORDER == __LITTLE_ENDIAN
  255. # define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80
  256. # define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40
  257. #endif
  258. struct rr_result /* router renumbering result message */
  259. {
  260. uint16_t rrr_flags;
  261. uint8_t rrr_ordinal;
  262. uint8_t rrr_matchedlen;
  263. uint32_t rrr_ifid;
  264. struct in6_addr rrr_prefix;
  265. };
  266. #if __BYTE_ORDER == __BIG_ENDIAN
  267. # define ICMP6_RR_RESULT_FLAGS_OOB 0x0002
  268. # define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001
  269. #elif __BYTE_ORDER == __LITTLE_ENDIAN
  270. # define ICMP6_RR_RESULT_FLAGS_OOB 0x0200
  271. # define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100
  272. #endif
  273. /* Mobile IPv6 extension: Advertisement Interval. */
  274. struct nd_opt_adv_interval
  275. {
  276. uint8_t nd_opt_adv_interval_type;
  277. uint8_t nd_opt_adv_interval_len;
  278. uint16_t nd_opt_adv_interval_reserved;
  279. uint32_t nd_opt_adv_interval_ival;
  280. };
  281. /* Mobile IPv6 extension: Home Agent Info. */
  282. struct nd_opt_home_agent_info
  283. {
  284. uint8_t nd_opt_home_agent_info_type;
  285. uint8_t nd_opt_home_agent_info_len;
  286. uint16_t nd_opt_home_agent_info_reserved;
  287. uint16_t nd_opt_home_agent_info_preference;
  288. uint16_t nd_opt_home_agent_info_lifetime;
  289. };
  290. #endif /* netinet/icmpv6.h */