* Generate an error packet of type error in response to bad IP6 packet. */
| 256 | * Generate an error packet of type error in response to bad IP6 packet. |
| 257 | */ |
| 258 | void |
| 259 | icmp6_error(struct mbuf *m, int type, int code, int param) |
| 260 | { |
| 261 | struct ip6_hdr *oip6, *nip6; |
| 262 | struct icmp6_hdr *icmp6; |
| 263 | u_int preplen; |
| 264 | int off; |
| 265 | int nxt; |
| 266 | |
| 267 | ICMP6STAT_INC(icp6s_error); |
| 268 | |
| 269 | /* count per-type-code statistics */ |
| 270 | icmp6_errcount(type, code); |
| 271 | |
| 272 | #ifdef M_DECRYPTED /*not openbsd*/ |
| 273 | if (m->m_flags & M_DECRYPTED) { |
| 274 | ICMP6STAT_INC(icp6s_canterror); |
| 275 | goto freeit; |
| 276 | } |
| 277 | #endif |
| 278 | |
| 279 | if (m->m_len < sizeof(struct ip6_hdr)) { |
| 280 | m = m_pullup(m, sizeof(struct ip6_hdr)); |
| 281 | if (m == NULL) { |
| 282 | IP6STAT_INC(ip6s_exthdrtoolong); |
| 283 | return; |
| 284 | } |
| 285 | } |
| 286 | oip6 = mtod(m, struct ip6_hdr *); |
| 287 | |
| 288 | /* |
| 289 | * If the destination address of the erroneous packet is a multicast |
| 290 | * address, or the packet was sent using link-layer multicast, |
| 291 | * we should basically suppress sending an error (RFC 2463, Section |
| 292 | * 2.4). |
| 293 | * We have two exceptions (the item e.2 in that section): |
| 294 | * - the Packet Too Big message can be sent for path MTU discovery. |
| 295 | * - the Parameter Problem Message that can be allowed an icmp6 error |
| 296 | * in the option type field. This check has been done in |
| 297 | * ip6_unknown_opt(), so we can just check the type and code. |
| 298 | */ |
| 299 | if ((m->m_flags & (M_BCAST|M_MCAST) || |
| 300 | IN6_IS_ADDR_MULTICAST(&oip6->ip6_dst)) && |
| 301 | (type != ICMP6_PACKET_TOO_BIG && |
| 302 | (type != ICMP6_PARAM_PROB || |
| 303 | code != ICMP6_PARAMPROB_OPTION))) |
| 304 | goto freeit; |
| 305 | |
| 306 | /* |
| 307 | * RFC 2463, 2.4 (e.5): source address check. |
| 308 | * XXX: the case of anycast source? |
| 309 | */ |
| 310 | if (IN6_IS_ADDR_UNSPECIFIED(&oip6->ip6_src) || |
| 311 | IN6_IS_ADDR_MULTICAST(&oip6->ip6_src)) |
| 312 | goto freeit; |
| 313 | |
| 314 | /* |
| 315 | * If we are about to send ICMPv6 against ICMPv6 error/redirect, |
no test coverage detected