svn commit: r343678 - head/sys/netpfil/pf

Gleb Smirnoff glebius at FreeBSD.org
Sat Feb 2 05:49:06 UTC 2019


Author: glebius
Date: Sat Feb  2 05:49:05 2019
New Revision: 343678
URL: https://svnweb.freebsd.org/changeset/base/343678

Log:
  Return PFIL_CONSUMED if packet was consumed.  While here gather all
  the identical endings of pf_check_*() into single function.
  
  PR:		235411

Modified:
  head/sys/netpfil/pf/pf_ioctl.c

Modified: head/sys/netpfil/pf/pf_ioctl.c
==============================================================================
--- head/sys/netpfil/pf/pf_ioctl.c	Sat Feb  2 04:27:47 2019	(r343677)
+++ head/sys/netpfil/pf/pf_ioctl.c	Sat Feb  2 05:49:05 2019	(r343678)
@@ -4002,6 +4002,26 @@ shutdown_pf(void)
 	return (error);
 }
 
+static pfil_return_t
+pf_check_return(int chk, struct mbuf **m)
+{
+
+	switch (chk) {
+	case PF_PASS:
+		if (*m == NULL)
+			return (PFIL_CONSUMED);
+		else
+			return (PFIL_PASS);
+		break;
+	default:
+		if (*m != NULL) {
+			m_freem(*m);
+			*m = NULL;
+		}
+		return (PFIL_DROPPED);
+	}
+}
+
 #ifdef INET
 static pfil_return_t
 pf_check_in(struct mbuf **m, struct ifnet *ifp, int flags,
@@ -4010,12 +4030,8 @@ pf_check_in(struct mbuf **m, struct ifnet *ifp, int fl
 	int chk;
 
 	chk = pf_test(PF_IN, flags, ifp, m, inp);
-	if (chk && *m) {
-		m_freem(*m);
-		*m = NULL;
-	}
 
-	return (chk == PF_PASS ? PFIL_PASS : PFIL_DROPPED);
+	return (pf_check_return(chk, m));
 }
 
 static pfil_return_t
@@ -4025,12 +4041,8 @@ pf_check_out(struct mbuf **m, struct ifnet *ifp, int f
 	int chk;
 
 	chk = pf_test(PF_OUT, flags, ifp, m, inp);
-	if (chk && *m) {
-		m_freem(*m);
-		*m = NULL;
-	}
 
-	return (chk == PF_PASS ? PFIL_PASS : PFIL_DROPPED);
+	return (pf_check_return(chk, m));
 }
 #endif
 
@@ -4049,12 +4061,8 @@ pf_check6_in(struct mbuf **m, struct ifnet *ifp, int f
 	CURVNET_SET(ifp->if_vnet);
 	chk = pf_test6(PF_IN, flags, (*m)->m_flags & M_LOOP ? V_loif : ifp, m, inp);
 	CURVNET_RESTORE();
-	if (chk && *m) {
-		m_freem(*m);
-		*m = NULL;
-	}
 
-	return (chk == PF_PASS ? PFIL_PASS : PFIL_DROPPED);
+	return (pf_check_return(chk, m));
 }
 
 static pfil_return_t
@@ -4066,12 +4074,8 @@ pf_check6_out(struct mbuf **m, struct ifnet *ifp, int 
 	CURVNET_SET(ifp->if_vnet);
 	chk = pf_test6(PF_OUT, flags, ifp, m, inp);
 	CURVNET_RESTORE();
-	if (chk && *m) {
-		m_freem(*m);
-		*m = NULL;
-	}
 
-	return (chk == PF_PASS ? PFIL_PASS : PFIL_DROPPED);
+	return (pf_check_return(chk, m));
 }
 #endif /* INET6 */
 


More information about the svn-src-all mailing list