The branch main has been updated by glebius:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=d0f4c558f920309647029a082af2e87706d33eff

commit d0f4c558f920309647029a082af2e87706d33eff
Author:     Gleb Smirnoff <gleb...@freebsd.org>
AuthorDate: 2025-09-01 16:33:34 +0000
Commit:     Gleb Smirnoff <gleb...@freebsd.org>
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);
 

Reply via email to