1 /* Copyright (C) 1991-1997,2000,2006 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 4 The GNU C Library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 The GNU C Library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with the GNU C Library; if not, write to the Free 16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 17 02111-1307 USA. */ 18 19 #ifndef _NETINET_ICMP6_H 20 #define _NETINET_ICMP6_H 1 21 22 #include <inttypes.h> 23 #include <string.h> 24 #include <sys/types.h> 25 #include <netinet/in.h> 26 27 #define ICMP6_FILTER 1 28 29 #define ICMP6_FILTER_BLOCK 1 30 #define ICMP6_FILTER_PASS 2 31 #define ICMP6_FILTER_BLOCKOTHERS 3 32 #define ICMP6_FILTER_PASSONLY 4 33 34 struct icmp6_filter 35 { 36 uint32_t icmp6_filt[8]; 37 }; 38 39 struct icmp6_hdr 40 { 41 uint8_t icmp6_type; /* type field */ 42 uint8_t icmp6_code; /* code field */ 43 uint16_t icmp6_cksum; /* checksum field */ 44 union 45 { 46 uint32_t icmp6_un_data32[1]; /* type-specific field */ 47 uint16_t icmp6_un_data16[2]; /* type-specific field */ 48 uint8_t icmp6_un_data8[4]; /* type-specific field */ 49 } icmp6_dataun; 50 }; 51 52 #define icmp6_data32 icmp6_dataun.icmp6_un_data32 53 #define icmp6_data16 icmp6_dataun.icmp6_un_data16 54 #define icmp6_data8 icmp6_dataun.icmp6_un_data8 55 #define icmp6_pptr icmp6_data32[0] /* parameter prob */ 56 #define icmp6_mtu icmp6_data32[0] /* packet too big */ 57 #define icmp6_id icmp6_data16[0] /* echo request/reply */ 58 #define icmp6_seq icmp6_data16[1] /* echo request/reply */ 59 #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */ 60 61 #define ICMP6_DST_UNREACH 1 62 #define ICMP6_PACKET_TOO_BIG 2 63 #define ICMP6_TIME_EXCEEDED 3 64 #define ICMP6_PARAM_PROB 4 65 66 #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */ 67 68 #define ICMP6_ECHO_REQUEST 128 69 #define ICMP6_ECHO_REPLY 129 70 #define MLD_LISTENER_QUERY 130 71 #define MLD_LISTENER_REPORT 131 72 #define MLD_LISTENER_REDUCTION 132 73 74 #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */ 75 #define ICMP6_DST_UNREACH_ADMIN 1 /* communication with destination */ 76 /* administratively prohibited */ 77 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */ 78 #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */ 79 #define ICMP6_DST_UNREACH_NOPORT 4 /* bad port */ 80 81 #define ICMP6_TIME_EXCEED_TRANSIT 0 /* Hop Limit == 0 in transit */ 82 #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* Reassembly time out */ 83 84 #define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */ 85 #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized Next Header */ 86 #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized IPv6 option */ 87 88 #define ICMP6_FILTER_WILLPASS(type, filterp) \ 89 ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0) 90 91 #define ICMP6_FILTER_WILLBLOCK(type, filterp) \ 92 ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0) 93 94 #define ICMP6_FILTER_SETPASS(type, filterp) \ 95 ((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))) 96 97 #define ICMP6_FILTER_SETBLOCK(type, filterp) \ 98 ((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))) 99 100 #define ICMP6_FILTER_SETPASSALL(filterp) \ 101 memset (filterp, 0, sizeof (struct icmp6_filter)); 102 103 #define ICMP6_FILTER_SETBLOCKALL(filterp) \ 104 memset (filterp, 0xFF, sizeof (struct icmp6_filter)); 105 106 #define ND_ROUTER_SOLICIT 133 107 #define ND_ROUTER_ADVERT 134 108 #define ND_NEIGHBOR_SOLICIT 135 109 #define ND_NEIGHBOR_ADVERT 136 110 #define ND_REDIRECT 137 111 112 struct nd_router_solicit /* router solicitation */ 113 { 114 struct icmp6_hdr nd_rs_hdr; 115 /* could be followed by options */ 116 }; 117 118 #define nd_rs_type nd_rs_hdr.icmp6_type 119 #define nd_rs_code nd_rs_hdr.icmp6_code 120 #define nd_rs_cksum nd_rs_hdr.icmp6_cksum 121 #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0] 122 123 struct nd_router_advert /* router advertisement */ 124 { 125 struct icmp6_hdr nd_ra_hdr; 126 uint32_t nd_ra_reachable; /* reachable time */ 127 uint32_t nd_ra_retransmit; /* retransmit timer */ 128 /* could be followed by options */ 129 }; 130 131 #define nd_ra_type nd_ra_hdr.icmp6_type 132 #define nd_ra_code nd_ra_hdr.icmp6_code 133 #define nd_ra_cksum nd_ra_hdr.icmp6_cksum 134 #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0] 135 #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1] 136 #define ND_RA_FLAG_MANAGED 0x80 137 #define ND_RA_FLAG_OTHER 0x40 138 #define ND_RA_FLAG_HOME_AGENT 0x20 139 #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1] 140 141 struct nd_neighbor_solicit /* neighbor solicitation */ 142 { 143 struct icmp6_hdr nd_ns_hdr; 144 struct in6_addr nd_ns_target; /* target address */ 145 /* could be followed by options */ 146 }; 147 148 #define nd_ns_type nd_ns_hdr.icmp6_type 149 #define nd_ns_code nd_ns_hdr.icmp6_code 150 #define nd_ns_cksum nd_ns_hdr.icmp6_cksum 151 #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0] 152 153 struct nd_neighbor_advert /* neighbor advertisement */ 154 { 155 struct icmp6_hdr nd_na_hdr; 156 struct in6_addr nd_na_target; /* target address */ 157 /* could be followed by options */ 158 }; 159 160 #define nd_na_type nd_na_hdr.icmp6_type 161 #define nd_na_code nd_na_hdr.icmp6_code 162 #define nd_na_cksum nd_na_hdr.icmp6_cksum 163 #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0] 164 #if BYTE_ORDER == BIG_ENDIAN 165 #define ND_NA_FLAG_ROUTER 0x80000000 166 #define ND_NA_FLAG_SOLICITED 0x40000000 167 #define ND_NA_FLAG_OVERRIDE 0x20000000 168 #else /* BYTE_ORDER == LITTLE_ENDIAN */ 169 #define ND_NA_FLAG_ROUTER 0x00000080 170 #define ND_NA_FLAG_SOLICITED 0x00000040 171 #define ND_NA_FLAG_OVERRIDE 0x00000020 172 #endif 173 174 struct nd_redirect /* redirect */ 175 { 176 struct icmp6_hdr nd_rd_hdr; 177 struct in6_addr nd_rd_target; /* target address */ 178 struct in6_addr nd_rd_dst; /* destination address */ 179 /* could be followed by options */ 180 }; 181 182 #define nd_rd_type nd_rd_hdr.icmp6_type 183 #define nd_rd_code nd_rd_hdr.icmp6_code 184 #define nd_rd_cksum nd_rd_hdr.icmp6_cksum 185 #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0] 186 187 struct nd_opt_hdr /* Neighbor discovery option header */ 188 { 189 uint8_t nd_opt_type; 190 uint8_t nd_opt_len; /* in units of 8 octets */ 191 /* followed by option specific data */ 192 }; 193 194 #define ND_OPT_SOURCE_LINKADDR 1 195 #define ND_OPT_TARGET_LINKADDR 2 196 #define ND_OPT_PREFIX_INFORMATION 3 197 #define ND_OPT_REDIRECTED_HEADER 4 198 #define ND_OPT_MTU 5 199 #define ND_OPT_RTR_ADV_INTERVAL 7 200 #define ND_OPT_HOME_AGENT_INFO 8 201 202 struct nd_opt_prefix_info /* prefix information */ 203 { 204 uint8_t nd_opt_pi_type; 205 uint8_t nd_opt_pi_len; 206 uint8_t nd_opt_pi_prefix_len; 207 uint8_t nd_opt_pi_flags_reserved; 208 uint32_t nd_opt_pi_valid_time; 209 uint32_t nd_opt_pi_preferred_time; 210 uint32_t nd_opt_pi_reserved2; 211 struct in6_addr nd_opt_pi_prefix; 212 }; 213 214 #define ND_OPT_PI_FLAG_ONLINK 0x80 215 #define ND_OPT_PI_FLAG_AUTO 0x40 216 #define ND_OPT_PI_FLAG_RADDR 0x20 217 218 struct nd_opt_rd_hdr /* redirected header */ 219 { 220 uint8_t nd_opt_rh_type; 221 uint8_t nd_opt_rh_len; 222 uint16_t nd_opt_rh_reserved1; 223 uint32_t nd_opt_rh_reserved2; 224 /* followed by IP header and data */ 225 }; 226 227 struct nd_opt_mtu /* MTU option */ 228 { 229 uint8_t nd_opt_mtu_type; 230 uint8_t nd_opt_mtu_len; 231 uint16_t nd_opt_mtu_reserved; 232 uint32_t nd_opt_mtu_mtu; 233 }; 234 235 struct mld_hdr 236 { 237 struct icmp6_hdr mld_icmp6_hdr; 238 struct in6_addr mld_addr; /* multicast address */ 239 }; 240 241 #define mld_type mld_icmp6_hdr.icmp6_type 242 #define mld_code mld_icmp6_hdr.icmp6_code 243 #define mld_cksum mld_icmp6_hdr.icmp6_cksum 244 #define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0] 245 #define mld_reserved mld_icmp6_hdr.icmp6_data16[1] 246 247 #define ICMP6_ROUTER_RENUMBERING 138 248 249 struct icmp6_router_renum /* router renumbering header */ 250 { 251 struct icmp6_hdr rr_hdr; 252 uint8_t rr_segnum; 253 uint8_t rr_flags; 254 uint16_t rr_maxdelay; 255 uint32_t rr_reserved; 256 }; 257 258 #define rr_type rr_hdr.icmp6_type 259 #define rr_code rr_hdr.icmp6_code 260 #define rr_cksum rr_hdr.icmp6_cksum 261 #define rr_seqnum rr_hdr.icmp6_data32[0] 262 263 /* Router renumbering flags */ 264 #define ICMP6_RR_FLAGS_TEST 0x80 265 #define ICMP6_RR_FLAGS_REQRESULT 0x40 266 #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20 267 #define ICMP6_RR_FLAGS_SPECSITE 0x10 268 #define ICMP6_RR_FLAGS_PREVDONE 0x08 269 270 struct rr_pco_match /* match prefix part */ 271 { 272 uint8_t rpm_code; 273 uint8_t rpm_len; 274 uint8_t rpm_ordinal; 275 uint8_t rpm_matchlen; 276 uint8_t rpm_minlen; 277 uint8_t rpm_maxlen; 278 uint16_t rpm_reserved; 279 struct in6_addr rpm_prefix; 280 }; 281 282 /* PCO code values */ 283 #define RPM_PCO_ADD 1 284 #define RPM_PCO_CHANGE 2 285 #define RPM_PCO_SETGLOBAL 3 286 287 struct rr_pco_use /* use prefix part */ 288 { 289 uint8_t rpu_uselen; 290 uint8_t rpu_keeplen; 291 uint8_t rpu_ramask; 292 uint8_t rpu_raflags; 293 uint32_t rpu_vltime; 294 uint32_t rpu_pltime; 295 uint32_t rpu_flags; 296 struct in6_addr rpu_prefix; 297 }; 298 299 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x20 300 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x10 301 302 #if BYTE_ORDER == BIG_ENDIAN 303 # define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000 304 # define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000 305 #elif BYTE_ORDER == LITTLE_ENDIAN 306 # define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80 307 # define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40 308 #endif 309 310 struct rr_result /* router renumbering result message */ 311 { 312 uint16_t rrr_flags; 313 uint8_t rrr_ordinal; 314 uint8_t rrr_matchedlen; 315 uint32_t rrr_ifid; 316 struct in6_addr rrr_prefix; 317 }; 318 319 #if BYTE_ORDER == BIG_ENDIAN 320 # define ICMP6_RR_RESULT_FLAGS_OOB 0x0002 321 # define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001 322 #elif BYTE_ORDER == LITTLE_ENDIAN 323 # define ICMP6_RR_RESULT_FLAGS_OOB 0x0200 324 # define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100 325 #endif 326 327 /* Mobile IPv6 extension: Advertisement Interval. */ 328 struct nd_opt_adv_interval 329 { 330 uint8_t nd_opt_adv_interval_type; 331 uint8_t nd_opt_adv_interval_len; 332 uint16_t nd_opt_adv_interval_reserved; 333 uint32_t nd_opt_adv_interval_ival; 334 }; 335 336 /* Mobile IPv6 extension: Home Agent Info. */ 337 struct nd_opt_home_agent_info 338 { 339 uint8_t nd_opt_home_agent_info_type; 340 uint8_t nd_opt_home_agent_info_len; 341 uint16_t nd_opt_home_agent_info_reserved; 342 int16_t nd_opt_home_agent_info_preference; 343 uint16_t nd_opt_home_agent_info_lifetime; 344 }; 345 346 #endif /* netinet/icmpv6.h */ 347