From nobody Thu Oct 22 03:31:27 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4j9BWz62MNz6x45X for ; Thu, 22 Oct 2026 03:31:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4j9BWz3G6Bz4N0T for ; Thu, 22 Oct 2026 03:31:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792639887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=d678NF9/ykRueK7cuBxAfE/VKeTidiH465Wqn5cttxg=; b=Z2KGZHnLKUli5pGbQVqkwZJI6L4v5K8NCThY7mkpLEa7azoofzUZN5uSx0PjGNvlBGeHoq zJQtEVivKUZBN0bbicCWpnpT8tK1Jviak2bgeC4b0y9PxTFphbIRezvKDBbM/QjKW3bxWi BXBkrUmfobNLG3xRn5T3eIbejgeN7ji+Eh2DD+/rzGMvD1fVivjZf8ALyKCGYXPDGybNnt Pl7SA9OFpUF6VhmZKM/hzJcZTw6Mi/WEnoeAgz1ehbeV+OdbW1OrseAwX506R25R884aK1 GskG3jOWH6W2L7A/MIVsS1jOPOr75VqsunLtHuZgYlH0uR+rKbRO00qELVhAew== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1792639887; b=TnpiycbzhgVAdnu2UCxP+l03xZLVthZeqbUd3ppmc9gTRI6jFYnTohHMub5TL12XB6/Ux+ C4ok9fcLzXM2TZQYyNgEAe4eBaHpNjk0MRSl5+GjqvQJyMCViN+grd7faKa9W2VYLpbyYh uHxn8C823BlXit1MyzhwlW/9TUOGkizQsgji056eKQg7IsWJdkPL29TwP6B2b2myqfsATg sjo1GzRFcKx3dk27rP6xt8WaJ6ZhCUr+Z30wYpXajlJgim65OHionOCsfDdRCuMWKFsm2A q3x0SRTqwQC1RXmiNTLvo7yAdBiHsdSUi9DfU0lpqFhkXAhcvJWNG7MVnQP0BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792639887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=d678NF9/ykRueK7cuBxAfE/VKeTidiH465Wqn5cttxg=; b=ruSCAWa9X5Ppyk4VIuw+j3nm49ACQB6V78LKuqqC9vvylSiAbZG7PDtqgCBt8TViaPDWeB pQNpUCqBsnaM9ZvU6cYpALhUpgmEb/2cmTvChTrVnDpcYDLI/nzLRl+HicwOpmnP07q5JD XtO8w5LiKLnb7BqV+Qu7taW8+EhRtVrauST8/4u4cQL7vLUnHcEb2cce3rZy41WnNpWf6s LwWscHynPxm3CTsSkFpZf7QP7grvZdBJDgEHDKb6NP42s7102cLh6+qB6HhJfZZZO5ySXf 26w1jqSQ4SV+c5fCHBKdTHRBRnJP0OApYZQ3hlFE3u/xbWlfT9JEuiOFb6D3lQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4j9BWz2v9wzNT9 for ; Thu, 22 Oct 2026 03:31:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 224c6 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 22 Oct 2026 03:31:27 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: abb8b02550c3 - main - icmp6: make icmp6_notify_error() more readable List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: Commit messages for the main branch of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: abb8b02550c3313d846c15167755f699388a4731 Auto-Submitted: auto-generated Date: Thu, 22 Oct 2026 03:31:27 +0000 Message-Id: <6ad9838f.224c6.739e0918@gitrepo.freebsd.org> The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=abb8b02550c3313d846c15167755f699388a4731 commit abb8b02550c3313d846c15167755f699388a4731 Author: Gleb Smirnoff AuthorDate: 2026-10-21 20:49:17 +0000 Commit: Gleb Smirnoff CommitDate: 2026-10-22 03:29:37 +0000 icmp6: make icmp6_notify_error() more readable Remove a level of indentation, improve line breaks, remove single use variables. No functional change. --- sys/netinet6/icmp6.c | 291 ++++++++++++++++++++++++--------------------------- 1 file changed, 139 insertions(+), 152 deletions(-) diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index f171af3fa5ef..0958b21de404 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -891,11 +891,17 @@ icmp6_input(struct mbuf **mp, int *offp, int proto) static int icmp6_notify_error(struct mbuf **mp, int off, int icmp6len) { + struct sockaddr_in6 icmp6src, icmp6dst; + struct ip6ctlparam ip6cp; struct mbuf *m; struct icmp6_hdr *icmp6; struct ip6_hdr *eip6; - u_int32_t notifymtu; - struct sockaddr_in6 icmp6src, icmp6dst; + struct ip6_frag *fh; + struct ip6_rthdr *rth; + struct ip6_rthdr0 *rth0; + uint32_t notifymtu; + int eoff, rthlen; + uint8_t nxt; m = *mp; *mp = NULL; /* Consumed in most cases. */ @@ -915,171 +921,152 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len) bzero(&icmp6dst, sizeof(icmp6dst)); /* Detect the upper level protocol */ - { - u_int8_t nxt = eip6->ip6_nxt; - int eoff = off + sizeof(struct icmp6_hdr) + - sizeof(struct ip6_hdr); - struct ip6ctlparam ip6cp; - int icmp6type = icmp6->icmp6_type; - struct ip6_frag *fh; - struct ip6_rthdr *rth; - struct ip6_rthdr0 *rth0; - int rthlen; - - while (1) { /* XXX: should avoid infinite loop explicitly? */ - struct ip6_ext *eh; - - switch (nxt) { - case IPPROTO_HOPOPTS: - case IPPROTO_DSTOPTS: - case IPPROTO_AH: - if ((m = m_pullup(m, eoff + - sizeof(struct ip6_ext))) == NULL) { - IP6STAT_INC(ip6s_exthdrtoolong); - return (-1); - } - eh = (struct ip6_ext *) - (mtod(m, char *) + eoff); - if (nxt == IPPROTO_AH) - eoff += (eh->ip6e_len + 2) << 2; - else - eoff += (eh->ip6e_len + 1) << 3; - nxt = eh->ip6e_nxt; - break; - case IPPROTO_ROUTING: - /* - * When the erroneous packet contains a - * routing header, we should examine the - * header to determine the final destination. - * Otherwise, we can't properly update - * information that depends on the final - * destination (e.g. path MTU). - */ - if ((m = m_pullup(m, eoff + sizeof(*rth))) == - NULL) { + nxt = eip6->ip6_nxt; + eoff = off + sizeof(struct icmp6_hdr) + sizeof(struct ip6_hdr); + + while (1) { /* XXX: should avoid infinite loop explicitly? */ + struct ip6_ext *eh; + + switch (nxt) { + case IPPROTO_HOPOPTS: + case IPPROTO_DSTOPTS: + case IPPROTO_AH: + if ((m = m_pullup(m, eoff + + sizeof(struct ip6_ext))) == NULL) { + IP6STAT_INC(ip6s_exthdrtoolong); + return (-1); + } + eh = (struct ip6_ext *)(mtod(m, char *) + eoff); + if (nxt == IPPROTO_AH) + eoff += (eh->ip6e_len + 2) << 2; + else + eoff += (eh->ip6e_len + 1) << 3; + nxt = eh->ip6e_nxt; + break; + case IPPROTO_ROUTING: + /* + * When the erroneous packet contains a routing header, + * we should examine the header to determine the final + * destination. Otherwise, we can't properly update + * information that depends on the final destination + * (e.g. path MTU). + */ + if ((m = m_pullup(m, eoff + sizeof(*rth))) == NULL) { + IP6STAT_INC(ip6s_exthdrtoolong); + return (-1); + } + rth = (struct ip6_rthdr *)(mtod(m, char *) + eoff); + rthlen = (rth->ip6r_len + 1) << 3; + /* + * XXX: currently there is no officially defined type + * other than type-0. Note that if the segment left + * field is 0, all intermediate hops must have been + * passed. + */ + if (rth->ip6r_segleft && + rth->ip6r_type == IPV6_RTHDR_TYPE_0) { + int hops; + + if ((m = m_pullup(m, eoff + rthlen)) == NULL) { IP6STAT_INC(ip6s_exthdrtoolong); return (-1); } - rth = (struct ip6_rthdr *) + rth0 = (struct ip6_rthdr0 *) (mtod(m, char *) + eoff); - rthlen = (rth->ip6r_len + 1) << 3; - /* - * XXX: currently there is no - * officially defined type other - * than type-0. - * Note that if the segment left field - * is 0, all intermediate hops must - * have been passed. - */ - if (rth->ip6r_segleft && - rth->ip6r_type == IPV6_RTHDR_TYPE_0) { - int hops; - - if ((m = m_pullup(m, eoff + rthlen)) == - NULL) { - IP6STAT_INC(ip6s_exthdrtoolong); - return (-1); - } - rth0 = (struct ip6_rthdr0 *) - (mtod(m, char *) + eoff); - - /* just ignore a bogus header */ - if ((rth0->ip6r0_len % 2) == 0 && - (hops = rth0->ip6r0_len/2)) - icmp6dst.sin6_addr = *((struct in6_addr *)(rth0 + 1) + (hops - 1)); - } - eoff += rthlen; - nxt = rth->ip6r_nxt; - break; - case IPPROTO_FRAGMENT: - if ((m = m_pullup(m, eoff + - sizeof(struct ip6_frag))) == NULL) { - IP6STAT_INC(ip6s_exthdrtoolong); - return (-1); - } - fh = (struct ip6_frag *)(mtod(m, char *) + - eoff); - /* - * Data after a fragment header is meaningless - * unless it is the first fragment, but - * we'll go to the notify label for path MTU - * discovery. - */ - if (fh->ip6f_offlg & IP6F_OFF_MASK) - goto notify; - eoff += sizeof(struct ip6_frag); - nxt = fh->ip6f_nxt; - break; - default: - /* - * This case includes ESP and the No Next - * Header. In such cases going to the notify - * label does not have any meaning - * (i.e. ctlfunc will be NULL), but we go - * anyway since we might have to update - * path MTU information. - */ - goto notify; + /* just ignore a bogus header */ + if ((rth0->ip6r0_len % 2) == 0 && + (hops = rth0->ip6r0_len/2)) + icmp6dst.sin6_addr = *((struct in6_addr *)(rth0 + 1) + (hops - 1)); + } + eoff += rthlen; + nxt = rth->ip6r_nxt; + break; + case IPPROTO_FRAGMENT: + if ((m = m_pullup(m, eoff + + sizeof(struct ip6_frag))) == NULL) { + IP6STAT_INC(ip6s_exthdrtoolong); + return (-1); } + fh = (struct ip6_frag *)(mtod(m, char *) + eoff); + /* + * Data after a fragment header is meaningless unless + * it is the first fragment, but we'll go to the notify + * label for path MTU discovery. + */ + if (fh->ip6f_offlg & IP6F_OFF_MASK) + goto notify; + + eoff += sizeof(struct ip6_frag); + nxt = fh->ip6f_nxt; + break; + default: + /* + * This case includes ESP and the No Next Header. In + * such cases going to the notify label does not have + * any meaning (i.e. ctlfunc will be NULL), but we go + * anyway since we might have to update path MTU + * information. + */ + goto notify; } - notify: - icmp6 = (struct icmp6_hdr *)(mtod(m, char *) + off); + } - /* - * retrieve parameters from the inner IPv6 header, and convert - * them into sockaddr structures. - * XXX: there is no guarantee that the source or destination - * addresses of the inner packet are in the same scope as - * the addresses of the icmp packet. But there is no other - * way to determine the zone. - */ - eip6 = (struct ip6_hdr *)(icmp6 + 1); +notify: + icmp6 = (struct icmp6_hdr *)(mtod(m, char *) + off); - /* - * Protocol layers can't do anything useful with unspecified - * addresses. - */ - if (IN6_IS_ADDR_UNSPECIFIED(&eip6->ip6_src) || - IN6_IS_ADDR_UNSPECIFIED(&eip6->ip6_dst)) - goto freeit; + /* + * Retrieve parameters from the inner IPv6 header, and convert them + * into sockaddr structures. + * XXX: there is no guarantee that the source or destination addresses + * of the inner packet are in the same scope as the addresses of the + * icmp packet. But there is no other way to determine the zone. + */ + eip6 = (struct ip6_hdr *)(icmp6 + 1); - icmp6dst.sin6_len = sizeof(struct sockaddr_in6); - icmp6dst.sin6_family = AF_INET6; - if (IN6_IS_ADDR_UNSPECIFIED(&icmp6dst.sin6_addr)) - icmp6dst.sin6_addr = eip6->ip6_dst; - if (in6_setscope(&icmp6dst.sin6_addr, m->m_pkthdr.rcvif, NULL)) - goto freeit; - bzero(&icmp6src, sizeof(icmp6src)); - icmp6src.sin6_len = sizeof(struct sockaddr_in6); - icmp6src.sin6_family = AF_INET6; - icmp6src.sin6_addr = eip6->ip6_src; - if (in6_setscope(&icmp6src.sin6_addr, m->m_pkthdr.rcvif, NULL)) - goto freeit; - icmp6src.sin6_flowinfo = - (eip6->ip6_flow & IPV6_FLOWLABEL_MASK); - - ip6cp.ip6c_m = m; - ip6cp.ip6c_icmp6 = icmp6; - ip6cp.ip6c_ip6 = (struct ip6_hdr *)(icmp6 + 1); - ip6cp.ip6c_off = eoff; - ip6cp.ip6c_finaldst = &icmp6dst; - ip6cp.ip6c_src = &icmp6src; - ip6cp.ip6c_nxt = nxt; - - if (icmp6type == ICMP6_PACKET_TOO_BIG) { - notifymtu = ntohl(icmp6->icmp6_mtu); - ip6cp.ip6c_cmdarg = (void *)¬ifymtu; - icmp6_mtudisc_update(&ip6cp); - } + /* + * Protocol layers can't do anything useful with unspecified addresses. + */ + if (IN6_IS_ADDR_UNSPECIFIED(&eip6->ip6_src) || + IN6_IS_ADDR_UNSPECIFIED(&eip6->ip6_dst)) + goto freeit; - if (ip6_ctlprotox[nxt] != NULL) - ip6_ctlprotox[nxt](&ip6cp); + icmp6dst.sin6_len = sizeof(struct sockaddr_in6); + icmp6dst.sin6_family = AF_INET6; + if (IN6_IS_ADDR_UNSPECIFIED(&icmp6dst.sin6_addr)) + icmp6dst.sin6_addr = eip6->ip6_dst; + if (in6_setscope(&icmp6dst.sin6_addr, m->m_pkthdr.rcvif, NULL)) + goto freeit; + bzero(&icmp6src, sizeof(icmp6src)); + icmp6src.sin6_len = sizeof(struct sockaddr_in6); + icmp6src.sin6_family = AF_INET6; + icmp6src.sin6_addr = eip6->ip6_src; + if (in6_setscope(&icmp6src.sin6_addr, m->m_pkthdr.rcvif, NULL)) + goto freeit; + icmp6src.sin6_flowinfo = + (eip6->ip6_flow & IPV6_FLOWLABEL_MASK); + + ip6cp.ip6c_m = m; + ip6cp.ip6c_icmp6 = icmp6; + ip6cp.ip6c_ip6 = (struct ip6_hdr *)(icmp6 + 1); + ip6cp.ip6c_off = eoff; + ip6cp.ip6c_finaldst = &icmp6dst; + ip6cp.ip6c_src = &icmp6src; + ip6cp.ip6c_nxt = nxt; + + if (icmp6->icmp6_type == ICMP6_PACKET_TOO_BIG) { + notifymtu = ntohl(icmp6->icmp6_mtu); + ip6cp.ip6c_cmdarg = (void *)¬ifymtu; + icmp6_mtudisc_update(&ip6cp); } + + if (ip6_ctlprotox[nxt] != NULL) + ip6_ctlprotox[nxt](&ip6cp); + *mp = m; return (0); - freeit: +freeit: m_freem(m); return (-1); }