MCPcopy Create free account
hub / github.com/F-Stack/f-stack / icmp6_error

Function icmp6_error

freebsd/netinet6/icmp6.c:258–391  ·  view source on GitHub ↗

* Generate an error packet of type error in response to bad IP6 packet. */

Source from the content-addressed store, hash-verified

256 * Generate an error packet of type error in response to bad IP6 packet.
257 */
258void
259icmp6_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,

Callers 15

pf_intrFunction · 0.85
pf_route6Function · 0.85
send_reject6Function · 0.85
tcp6_inputFunction · 0.85
ip6_forwardFunction · 0.85
frag6_freefFunction · 0.85
frag6_inputFunction · 0.85
ip6_input_hbhFunction · 0.85
ip6_process_hopoptsFunction · 0.85
ip6_unknown_optFunction · 0.85
ip6_findrouteFunction · 0.85
ip6_tryforwardFunction · 0.85

Calls 8

icmp6_errcountFunction · 0.85
m_pullupFunction · 0.85
ip6_lasthdrFunction · 0.85
icmp6_ratelimitFunction · 0.85
m_adjFunction · 0.85
in6_clearscopeFunction · 0.85
icmp6_reflectFunction · 0.85
m_freemFunction · 0.50

Tested by

no test coverage detected