1
0

icmp6.h 8.4 KB

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