icmp6.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. #ifndef _NETINET_ICMP6_H
  2. #define _NETINET_ICMP6_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stdint.h>
  7. #include <string.h>
  8. #include <sys/types.h>
  9. #include <netinet/in.h>
  10. #define ICMP6_FILTER 1
  11. #define ICMP6_FILTER_BLOCK 1
  12. #define ICMP6_FILTER_PASS 2
  13. #define ICMP6_FILTER_BLOCKOTHERS 3
  14. #define ICMP6_FILTER_PASSONLY 4
  15. struct icmp6_filter {
  16. uint32_t icmp6_filt[8];
  17. };
  18. struct icmp6_hdr {
  19. uint8_t icmp6_type;
  20. uint8_t icmp6_code;
  21. uint16_t icmp6_cksum;
  22. union {
  23. uint32_t icmp6_un_data32[1];
  24. uint16_t icmp6_un_data16[2];
  25. uint8_t icmp6_un_data8[4];
  26. } icmp6_dataun;
  27. };
  28. #define icmp6_data32 icmp6_dataun.icmp6_un_data32
  29. #define icmp6_data16 icmp6_dataun.icmp6_un_data16
  30. #define icmp6_data8 icmp6_dataun.icmp6_un_data8
  31. #define icmp6_pptr icmp6_data32[0]
  32. #define icmp6_mtu icmp6_data32[0]
  33. #define icmp6_id icmp6_data16[0]
  34. #define icmp6_seq icmp6_data16[1]
  35. #define icmp6_maxdelay icmp6_data16[0]
  36. #define ICMP6_DST_UNREACH 1
  37. #define ICMP6_PACKET_TOO_BIG 2
  38. #define ICMP6_TIME_EXCEEDED 3
  39. #define ICMP6_PARAM_PROB 4
  40. #define ICMP6_INFOMSG_MASK 0x80
  41. #define ICMP6_ECHO_REQUEST 128
  42. #define ICMP6_ECHO_REPLY 129
  43. #define MLD_LISTENER_QUERY 130
  44. #define MLD_LISTENER_REPORT 131
  45. #define MLD_LISTENER_REDUCTION 132
  46. #define ICMP6_DST_UNREACH_NOROUTE 0
  47. #define ICMP6_DST_UNREACH_ADMIN 1
  48. #define ICMP6_DST_UNREACH_BEYONDSCOPE 2
  49. #define ICMP6_DST_UNREACH_ADDR 3
  50. #define ICMP6_DST_UNREACH_NOPORT 4
  51. #define ICMP6_TIME_EXCEED_TRANSIT 0
  52. #define ICMP6_TIME_EXCEED_REASSEMBLY 1
  53. #define ICMP6_PARAMPROB_HEADER 0
  54. #define ICMP6_PARAMPROB_NEXTHEADER 1
  55. #define ICMP6_PARAMPROB_OPTION 2
  56. #define ICMP6_FILTER_WILLPASS(type, filterp) \
  57. ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
  58. #define ICMP6_FILTER_WILLBLOCK(type, filterp) \
  59. ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
  60. #define ICMP6_FILTER_SETPASS(type, filterp) \
  61. ((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))))
  62. #define ICMP6_FILTER_SETBLOCK(type, filterp) \
  63. ((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31))))
  64. #define ICMP6_FILTER_SETPASSALL(filterp) \
  65. memset (filterp, 0, sizeof (struct icmp6_filter));
  66. #define ICMP6_FILTER_SETBLOCKALL(filterp) \
  67. memset (filterp, 0xFF, sizeof (struct icmp6_filter));
  68. #define ND_ROUTER_SOLICIT 133
  69. #define ND_ROUTER_ADVERT 134
  70. #define ND_NEIGHBOR_SOLICIT 135
  71. #define ND_NEIGHBOR_ADVERT 136
  72. #define ND_REDIRECT 137
  73. struct nd_router_solicit {
  74. struct icmp6_hdr nd_rs_hdr;
  75. };
  76. #define nd_rs_type nd_rs_hdr.icmp6_type
  77. #define nd_rs_code nd_rs_hdr.icmp6_code
  78. #define nd_rs_cksum nd_rs_hdr.icmp6_cksum
  79. #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
  80. struct nd_router_advert {
  81. struct icmp6_hdr nd_ra_hdr;
  82. uint32_t nd_ra_reachable;
  83. uint32_t nd_ra_retransmit;
  84. };
  85. #define nd_ra_type nd_ra_hdr.icmp6_type
  86. #define nd_ra_code nd_ra_hdr.icmp6_code
  87. #define nd_ra_cksum nd_ra_hdr.icmp6_cksum
  88. #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
  89. #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
  90. #define ND_RA_FLAG_MANAGED 0x80
  91. #define ND_RA_FLAG_OTHER 0x40
  92. #define ND_RA_FLAG_HOME_AGENT 0x20
  93. #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
  94. struct nd_neighbor_solicit {
  95. struct icmp6_hdr nd_ns_hdr;
  96. struct in6_addr nd_ns_target;
  97. };
  98. #define nd_ns_type nd_ns_hdr.icmp6_type
  99. #define nd_ns_code nd_ns_hdr.icmp6_code
  100. #define nd_ns_cksum nd_ns_hdr.icmp6_cksum
  101. #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
  102. struct nd_neighbor_advert {
  103. struct icmp6_hdr nd_na_hdr;
  104. struct in6_addr nd_na_target;
  105. };
  106. #define nd_na_type nd_na_hdr.icmp6_type
  107. #define nd_na_code nd_na_hdr.icmp6_code
  108. #define nd_na_cksum nd_na_hdr.icmp6_cksum
  109. #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0]
  110. #if __BYTE_ORDER == __BIG_ENDIAN
  111. #define ND_NA_FLAG_ROUTER 0x80000000
  112. #define ND_NA_FLAG_SOLICITED 0x40000000
  113. #define ND_NA_FLAG_OVERRIDE 0x20000000
  114. #else
  115. #define ND_NA_FLAG_ROUTER 0x00000080
  116. #define ND_NA_FLAG_SOLICITED 0x00000040
  117. #define ND_NA_FLAG_OVERRIDE 0x00000020
  118. #endif
  119. struct nd_redirect {
  120. struct icmp6_hdr nd_rd_hdr;
  121. struct in6_addr nd_rd_target;
  122. struct in6_addr nd_rd_dst;
  123. };
  124. #define nd_rd_type nd_rd_hdr.icmp6_type
  125. #define nd_rd_code nd_rd_hdr.icmp6_code
  126. #define nd_rd_cksum nd_rd_hdr.icmp6_cksum
  127. #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
  128. struct nd_opt_hdr {
  129. uint8_t nd_opt_type;
  130. uint8_t nd_opt_len;
  131. };
  132. #define ND_OPT_SOURCE_LINKADDR 1
  133. #define ND_OPT_TARGET_LINKADDR 2
  134. #define ND_OPT_PREFIX_INFORMATION 3
  135. #define ND_OPT_REDIRECTED_HEADER 4
  136. #define ND_OPT_MTU 5
  137. #define ND_OPT_RTR_ADV_INTERVAL 7
  138. #define ND_OPT_HOME_AGENT_INFO 8
  139. struct nd_opt_prefix_info {
  140. uint8_t nd_opt_pi_type;
  141. uint8_t nd_opt_pi_len;
  142. uint8_t nd_opt_pi_prefix_len;
  143. uint8_t nd_opt_pi_flags_reserved;
  144. uint32_t nd_opt_pi_valid_time;
  145. uint32_t nd_opt_pi_preferred_time;
  146. uint32_t nd_opt_pi_reserved2;
  147. struct in6_addr nd_opt_pi_prefix;
  148. };
  149. #define ND_OPT_PI_FLAG_ONLINK 0x80
  150. #define ND_OPT_PI_FLAG_AUTO 0x40
  151. #define ND_OPT_PI_FLAG_RADDR 0x20
  152. struct nd_opt_rd_hdr {
  153. uint8_t nd_opt_rh_type;
  154. uint8_t nd_opt_rh_len;
  155. uint16_t nd_opt_rh_reserved1;
  156. uint32_t nd_opt_rh_reserved2;
  157. };
  158. struct nd_opt_mtu {
  159. uint8_t nd_opt_mtu_type;
  160. uint8_t nd_opt_mtu_len;
  161. uint16_t nd_opt_mtu_reserved;
  162. uint32_t nd_opt_mtu_mtu;
  163. };
  164. struct mld_hdr {
  165. struct icmp6_hdr mld_icmp6_hdr;
  166. struct in6_addr mld_addr;
  167. };
  168. #define mld_type mld_icmp6_hdr.icmp6_type
  169. #define mld_code mld_icmp6_hdr.icmp6_code
  170. #define mld_cksum mld_icmp6_hdr.icmp6_cksum
  171. #define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0]
  172. #define mld_reserved mld_icmp6_hdr.icmp6_data16[1]
  173. #define ICMP6_ROUTER_RENUMBERING 138
  174. struct icmp6_router_renum {
  175. struct icmp6_hdr rr_hdr;
  176. uint8_t rr_segnum;
  177. uint8_t rr_flags;
  178. uint16_t rr_maxdelay;
  179. uint32_t rr_reserved;
  180. };
  181. #define rr_type rr_hdr.icmp6_type
  182. #define rr_code rr_hdr.icmp6_code
  183. #define rr_cksum rr_hdr.icmp6_cksum
  184. #define rr_seqnum rr_hdr.icmp6_data32[0]
  185. #define ICMP6_RR_FLAGS_TEST 0x80
  186. #define ICMP6_RR_FLAGS_REQRESULT 0x40
  187. #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20
  188. #define ICMP6_RR_FLAGS_SPECSITE 0x10
  189. #define ICMP6_RR_FLAGS_PREVDONE 0x08
  190. struct rr_pco_match {
  191. uint8_t rpm_code;
  192. uint8_t rpm_len;
  193. uint8_t rpm_ordinal;
  194. uint8_t rpm_matchlen;
  195. uint8_t rpm_minlen;
  196. uint8_t rpm_maxlen;
  197. uint16_t rpm_reserved;
  198. struct in6_addr rpm_prefix;
  199. };
  200. #define RPM_PCO_ADD 1
  201. #define RPM_PCO_CHANGE 2
  202. #define RPM_PCO_SETGLOBAL 3
  203. struct rr_pco_use {
  204. uint8_t rpu_uselen;
  205. uint8_t rpu_keeplen;
  206. uint8_t rpu_ramask;
  207. uint8_t rpu_raflags;
  208. uint32_t rpu_vltime;
  209. uint32_t rpu_pltime;
  210. uint32_t rpu_flags;
  211. struct in6_addr rpu_prefix;
  212. };
  213. #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x20
  214. #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x10
  215. #if __BYTE_ORDER == __BIG_ENDIAN
  216. #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000
  217. #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000
  218. #else
  219. #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80
  220. #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40
  221. #endif
  222. struct rr_result {
  223. uint16_t rrr_flags;
  224. uint8_t rrr_ordinal;
  225. uint8_t rrr_matchedlen;
  226. uint32_t rrr_ifid;
  227. struct in6_addr rrr_prefix;
  228. };
  229. #if __BYTE_ORDER == __BIG_ENDIAN
  230. #define ICMP6_RR_RESULT_FLAGS_OOB 0x0002
  231. #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001
  232. #else
  233. #define ICMP6_RR_RESULT_FLAGS_OOB 0x0200
  234. #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100
  235. #endif
  236. struct nd_opt_adv_interval {
  237. uint8_t nd_opt_adv_interval_type;
  238. uint8_t nd_opt_adv_interval_len;
  239. uint16_t nd_opt_adv_interval_reserved;
  240. uint32_t nd_opt_adv_interval_ival;
  241. };
  242. struct nd_opt_home_agent_info {
  243. uint8_t nd_opt_home_agent_info_type;
  244. uint8_t nd_opt_home_agent_info_len;
  245. uint16_t nd_opt_home_agent_info_reserved;
  246. uint16_t nd_opt_home_agent_info_preference;
  247. uint16_t nd_opt_home_agent_info_lifetime;
  248. };
  249. #ifdef __cplusplus
  250. }
  251. #endif
  252. #endif