From bf088e2b2bca3601996da0e7183cb5627772de3b Mon Sep 17 00:00:00 2001 From: bluhm Date: Tue, 22 Mar 2022 18:27:21 +0000 Subject: [PATCH] Extract the type from the ICMP6 header before looping over Raw IPv6 PCBs. This make mutex and error handling easier. OK claudio@ --- sys/netinet6/raw_ip6.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index b5bb3bf6907..6d882f6dcc5 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.145 2022/03/21 09:12:34 bluhm Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.146 2022/03/22 18:27:21 bluhm Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -125,10 +125,19 @@ rip6_input(struct mbuf **mp, int *offp, int proto, int af) struct in6_addr *key; struct sockaddr_in6 rip6src; struct mbuf *opts = NULL; + uint8_t type; KASSERT(af == AF_INET6); - if (proto != IPPROTO_ICMPV6) + if (proto == IPPROTO_ICMPV6) { + struct icmp6_hdr *icmp6; + + IP6_EXTHDR_GET(icmp6, struct icmp6_hdr *, m, *offp, + sizeof(*icmp6)); + if (icmp6 == NULL) + return IPPROTO_DONE; + type = icmp6->icmp6_type; + } else rip6stat_inc(rip6s_ipackets); bzero(&rip6src, sizeof(rip6src)); @@ -177,16 +186,7 @@ rip6_input(struct mbuf **mp, int *offp, int proto, int af) !IN6_ARE_ADDR_EQUAL(&in6p->inp_faddr6, &ip6->ip6_src)) continue; if (proto == IPPROTO_ICMPV6 && in6p->inp_icmp6filt) { - struct icmp6_hdr *icmp6; - - IP6_EXTHDR_GET(icmp6, struct icmp6_hdr *, m, *offp, - sizeof(*icmp6)); - if (icmp6 == NULL) { - mtx_leave(&rawin6pcbtable.inpt_mtx); - return IPPROTO_DONE; - } - if (ICMP6_FILTER_WILLBLOCK(icmp6->icmp6_type, - in6p->inp_icmp6filt)) + if (ICMP6_FILTER_WILLBLOCK(type, in6p->inp_icmp6filt)) continue; } if (proto != IPPROTO_ICMPV6 && in6p->inp_cksum6 != -1) { -- 2.20.1