From nobody Mon Sep 1 16:33:54 2025 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 4cFvZp6fCSz66p3q; Mon, 01 Sep 2025 16:33:54 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cFvZp62ygz43wQ; Mon, 01 Sep 2025 16:33:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756744434; 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=InC1LMgYAnj0LN33/tExbVwbcFKPWz3W0aOQnkr/3mA=; b=qjRCKiUCKcHw1ADvKhtYxJWnUMwRnvlcG5Ag8HQxPoJ2RsNv4fMjGMHkAtC2x4yRYxGowO kdcnyELEft9xKCDczx6gm/AMmUw2YuB5+jAHAtX0NClKA6zG9zHv8E9UAnEPM2S31ZnH5Z RBt+mgZoCmG5J3Z4P3ovT8+3088Uh2sdqk17QQeIQcVXDkmaNx8OwUexoKOCQh4sssaFvF YJlTAHhA4RW7TbWgrfhzBxtwucq2yvMr/fpOjnAHNcyTzEflPuTg3CEMSl2XsNyFHnC4li Tq4cV2x/D9cqsD/Rj7JPOpHNkN8iBarXlsdFyzWWCSkwGzyn0i/NLnMkrXGA6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756744434; 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=InC1LMgYAnj0LN33/tExbVwbcFKPWz3W0aOQnkr/3mA=; b=o2M4LB0EIT322NMgL3n9bMZFxjxrPkbcF85X/EIyIenlFrGrnE1l8fk3PvCgNFG7pz/o8/ GQtM5JY96daSmyw8t4jEmdImpZKRfRDdjZb7OBx2UaAJfceqV2794GKnNPHP7otvRSoE/V VoQfFXU3cjnRTmiiCLewM/2amis1ZKvTg71qCZaxc2iNP3MqaehhtcqTflCRcrLVFUxqp2 r3/el8mU2wdfoHI0uKeUQfG+0l+SWbIJYPV+VeZH8IjZmr/b0/yNadNf2y8DbBzHOFebZs GPsE6WuwmQBIKPetstM0k3070G4ReWPK+Qokez31ojDDpPwdZtopLeDIemiG1g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1756744434; a=rsa-sha256; cv=none; b=mk+gkzmhemOk/49qZE8yQf8TtiHy6p7CovvnVTBKm7Nja9N0VyrgGjim6f5AdhHx7ay3ih 07pzLXoVn4xV5JRsja6uX1QQVa4W9B6R9juWVRXH0XQpvdydK1UuwwZxRJCAM1F6Pfn8lv fUI+XOh7yF8BI6yz/8vYPLy/mSDxF5jG15tOOy1k7gwZ2ikfGAn5Tqv7Lym2ttECFsRNtT QE/iS8G0I1zGvMmr4r2VdcErdizhJMkuwB1mOA1tM+StmLeoAxP18YKyilB7HTOLVGVqM0 T0LXX0sr4Sxot5mDfa80qXbXY8cBAFAq3A4oAgqy+IwAJWM7vtK4iJuywU01IQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cFvZp5ZyFz16lY; Mon, 01 Sep 2025 16:33:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 581GXsU4089789; Mon, 1 Sep 2025 16:33:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 581GXsaP089786; Mon, 1 Sep 2025 16:33:54 GMT (envelope-from git) Date: Mon, 1 Sep 2025 16:33:54 GMT Message-Id: <202509011633.581GXsaP089786@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: d0f4c558f920 - main - udp: slightly refactor udp_append() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org 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: d0f4c558f920309647029a082af2e87706d33eff Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=d0f4c558f920309647029a082af2e87706d33eff commit d0f4c558f920309647029a082af2e87706d33eff Author: Gleb Smirnoff AuthorDate: 2025-09-01 16:33:34 +0000 Commit: Gleb Smirnoff CommitDate: 2025-09-01 16:33:34 +0000 udp: slightly refactor udp_append() Make it bool. Reword the comment, add note that mbuf is always consumed. In case tunnel consumed the mbuf, don't INP_RUNLOCK(), behave just like all the other normal exits from the function. Reviewed by: tuexen, kp, markj Differential Revision: https://reviews.freebsd.org/D52171 --- sys/netinet/udp_usrreq.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 4547699b6df5..cea8a916679b 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -223,16 +223,18 @@ VNET_SYSUNINIT(udp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, udp_destroy, NULL); * udp_append() will convert to a sockaddr_in6 before passing the address * into the socket code. * - * In the normal case udp_append() will return 0, indicating that you - * must unlock the inp. However if a tunneling protocol is in place we increment - * the inpcb refcnt and unlock the inp, on return from the tunneling protocol we - * then decrement the reference count. If the inp_rele returns 1, indicating the - * inp is gone, we return that to the caller to tell them *not* to unlock - * the inp. In the case of multi-cast this will cause the distribution - * to stop (though most tunneling protocols known currently do *not* use - * multicast). + * In the normal case udp_append() will return 'false', indicating that you + * must unlock the inpcb. However if a tunneling protocol is in place we + * increment the inpcb refcnt and unlock the inpcb, on return from the tunneling + * protocol we then decrement the reference count. If in_pcbrele_rlocked() + * returns 'true', indicating the inpcb is gone, we return that to the caller + * to tell them *not* to unlock the inpcb. In the case of multicast this will + * cause the distribution to stop (though most tunneling protocols known + * currently do *not* use multicast). + * + * The mbuf is always consumed. */ -static int +static bool udp_append(struct inpcb *inp, struct ip *ip, struct mbuf *n, int off, struct sockaddr_in *udp_in) { @@ -255,18 +257,16 @@ udp_append(struct inpcb *inp, struct ip *ip, struct mbuf *n, int off, in_pcbref(inp); INP_RUNLOCK(inp); - filtered = (*up->u_tun_func)(n, off, inp, (struct sockaddr *)&udp_in[0], - up->u_tun_ctx); + filtered = (*up->u_tun_func)(n, off, inp, + (struct sockaddr *)&udp_in[0], up->u_tun_ctx); INP_RLOCK(inp); if (in_pcbrele_rlocked(inp)) { if (!filtered) m_freem(n); - return (1); - } - if (filtered) { - INP_RUNLOCK(inp); - return (1); + return (true); } + if (filtered) + return (false); } off += sizeof(struct udphdr); @@ -276,18 +276,18 @@ udp_append(struct inpcb *inp, struct ip *ip, struct mbuf *n, int off, if (IPSEC_ENABLED(ipv4) && IPSEC_CHECK_POLICY(ipv4, n, inp) != 0) { m_freem(n); - return (0); + return (false); } if (up->u_flags & UF_ESPINUDP) {/* IPSec UDP encaps. */ if (IPSEC_ENABLED(ipv4) && UDPENCAP_INPUT(ipv4, n, off, AF_INET) != 0) - return (0); /* Consumed. */ + return (false); } #endif /* IPSEC */ #ifdef MAC if (mac_inpcb_check_deliver(inp, n) != 0) { m_freem(n); - return (0); + return (false); } #endif /* MAC */ if (inp->inp_flags & INP_CONTROLOPTS || @@ -333,7 +333,7 @@ udp_append(struct inpcb *inp, struct ip *ip, struct mbuf *n, int off, UDPSTAT_INC(udps_fullsock); } else sorwakeup_locked(so); - return (0); + return (false); } static bool @@ -702,7 +702,7 @@ udp_input(struct mbuf **mp, int *offp, int proto) UDPLITE_PROBE(receive, NULL, inp, ip, inp, uh); else UDP_PROBE(receive, NULL, inp, ip, inp, uh); - if (udp_append(inp, ip, m, iphlen, udp_in) == 0) + if (!udp_append(inp, ip, m, iphlen, udp_in)) INP_RUNLOCK(inp); return (IPPROTO_DONE);