git: e0bf7bc3b2ba - main - pf: reduce indentation level in pf_dummynet_route()

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Fri, 22 Nov 2024 23:33:47 UTC
The branch main has been updated by kp:

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

commit e0bf7bc3b2ba1b2d8a746311471611210ba6fc89
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2024-11-22 12:35:02 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2024-11-22 23:32:04 +0000

    pf: reduce indentation level in pf_dummynet_route()
    
    Reverse the first if() in pf_dummynet_route() to avoid an unneeded level of
    indendation.
    
    No functional change.
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sys/netpfil/pf/pf.c | 98 +++++++++++++++++++++++++++--------------------------
 1 file changed, 50 insertions(+), 48 deletions(-)

diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index 99d30c1acf72..5a0cad132340 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -8383,66 +8383,68 @@ pf_dummynet_route(struct pf_pdesc *pd, struct pf_kstate *s,
     struct pf_krule *r, struct ifnet *ifp, struct sockaddr *sa,
     struct mbuf **m0)
 {
+	struct ip_fw_args dnflow;
+
 	NET_EPOCH_ASSERT();
 
-	if (pd->act.dnpipe || pd->act.dnrpipe) {
-		struct ip_fw_args dnflow;
-		if (ip_dn_io_ptr == NULL) {
-			m_freem(*m0);
-			*m0 = NULL;
-			return (ENOMEM);
-		}
+	if (pd->act.dnpipe == 0 && pd->act.dnrpipe == 0)
+		return (0);
 
-		if (pd->pf_mtag == NULL &&
-		    ((pd->pf_mtag = pf_get_mtag(*m0)) == NULL)) {
-			m_freem(*m0);
-			*m0 = NULL;
-			return (ENOMEM);
-		}
+	if (ip_dn_io_ptr == NULL) {
+		m_freem(*m0);
+		*m0 = NULL;
+		return (ENOMEM);
+	}
 
-		if (ifp != NULL) {
-			pd->pf_mtag->flags |= PF_MTAG_FLAG_ROUTE_TO;
+	if (pd->pf_mtag == NULL &&
+	    ((pd->pf_mtag = pf_get_mtag(*m0)) == NULL)) {
+		m_freem(*m0);
+		*m0 = NULL;
+		return (ENOMEM);
+	}
 
-			pd->pf_mtag->if_index = ifp->if_index;
-			pd->pf_mtag->if_idxgen = ifp->if_idxgen;
+	if (ifp != NULL) {
+		pd->pf_mtag->flags |= PF_MTAG_FLAG_ROUTE_TO;
 
-			MPASS(sa != NULL);
+		pd->pf_mtag->if_index = ifp->if_index;
+		pd->pf_mtag->if_idxgen = ifp->if_idxgen;
 
-			switch (pd->af) {
-			case AF_INET:
-				memcpy(&pd->pf_mtag->dst, sa,
-				    sizeof(struct sockaddr_in));
-				break;
-			case AF_INET6:
-				memcpy(&pd->pf_mtag->dst, sa,
-				    sizeof(struct sockaddr_in6));
-				break;
-			}
+		MPASS(sa != NULL);
+
+		switch (pd->af) {
+		case AF_INET:
+			memcpy(&pd->pf_mtag->dst, sa,
+			    sizeof(struct sockaddr_in));
+			break;
+		case AF_INET6:
+			memcpy(&pd->pf_mtag->dst, sa,
+			    sizeof(struct sockaddr_in6));
+			break;
 		}
+	}
 
-		if (s != NULL && s->nat_rule != NULL &&
-		    s->nat_rule->action == PF_RDR &&
-		    (
+	if (s != NULL && s->nat_rule != NULL &&
+	    s->nat_rule->action == PF_RDR &&
+	    (
 #ifdef INET
-		    (pd->af == AF_INET && IN_LOOPBACK(ntohl(pd->dst->v4.s_addr))) ||
+	    (pd->af == AF_INET && IN_LOOPBACK(ntohl(pd->dst->v4.s_addr))) ||
 #endif
-		    (pd->af == AF_INET6 && IN6_IS_ADDR_LOOPBACK(&pd->dst->v6)))) {
-			/*
-			 * If we're redirecting to loopback mark this packet
-			 * as being local. Otherwise it might get dropped
-			 * if dummynet re-injects.
-			 */
-			(*m0)->m_pkthdr.rcvif = V_loif;
-		}
+	    (pd->af == AF_INET6 && IN6_IS_ADDR_LOOPBACK(&pd->dst->v6)))) {
+		/*
+		 * If we're redirecting to loopback mark this packet
+		 * as being local. Otherwise it might get dropped
+		 * if dummynet re-injects.
+		 */
+		(*m0)->m_pkthdr.rcvif = V_loif;
+	}
 
-		if (pf_pdesc_to_dnflow(pd, r, s, &dnflow)) {
-			pd->pf_mtag->flags |= PF_MTAG_FLAG_DUMMYNET;
-			pd->pf_mtag->flags |= PF_MTAG_FLAG_DUMMYNETED;
-			ip_dn_io_ptr(m0, &dnflow);
-			if (*m0 != NULL) {
-				pd->pf_mtag->flags &= ~PF_MTAG_FLAG_ROUTE_TO;
-				pf_dummynet_flag_remove(*m0, pd->pf_mtag);
-			}
+	if (pf_pdesc_to_dnflow(pd, r, s, &dnflow)) {
+		pd->pf_mtag->flags |= PF_MTAG_FLAG_DUMMYNET;
+		pd->pf_mtag->flags |= PF_MTAG_FLAG_DUMMYNETED;
+		ip_dn_io_ptr(m0, &dnflow);
+		if (*m0 != NULL) {
+			pd->pf_mtag->flags &= ~PF_MTAG_FLAG_ROUTE_TO;
+			pf_dummynet_flag_remove(*m0, pd->pf_mtag);
 		}
 	}