Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Aug 2018 20:49:56 +0000 (UTC)
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r338390 - stable/11/sbin/pfctl
Message-ID:  <201808292049.w7TKnu43021942@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kp
Date: Wed Aug 29 20:49:56 2018
New Revision: 338390
URL: https://svnweb.freebsd.org/changeset/base/338390

Log:
  MFC r338183, r338183:
  
  pfctl: Improve set skip handling for groups
  
  Rely on the kernel to appropriately mark group members as skipped.
  Once a group is skipped we can clear the update flag on all the members.
  
  PR:		229241
  Submitted by:	Andreas Longwitz <longwitz AT incore.de>

Modified:
  stable/11/sbin/pfctl/pfctl.c
  stable/11/sbin/pfctl/pfctl_parser.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sbin/pfctl/pfctl.c
==============================================================================
--- stable/11/sbin/pfctl/pfctl.c	Wed Aug 29 17:58:01 2018	(r338389)
+++ stable/11/sbin/pfctl/pfctl.c	Wed Aug 29 20:49:56 2018	(r338390)
@@ -69,7 +69,7 @@ int	 pfctl_disable(int, int);
 int	 pfctl_clear_stats(int, int);
 int	 pfctl_get_skip_ifaces(void);
 int	 pfctl_check_skip_ifaces(char *);
-int	 pfctl_clear_skip_ifaces(struct pfctl *);
+int	 pfctl_adjust_skip_ifaces(struct pfctl *);
 int	 pfctl_clear_interface_flags(int, int);
 int	 pfctl_clear_rules(int, int, char *);
 int	 pfctl_clear_nat(int, int, char *);
@@ -319,21 +319,66 @@ int
 pfctl_check_skip_ifaces(char *ifname)
 {
 	struct pfi_kif		*p;
+	struct node_host	*h = NULL, *n = NULL;
 
-	PFRB_FOREACH(p, &skip_b)
-		if ((p->pfik_flags & PFI_IFLAG_SKIP) && !strcmp(ifname, p->pfik_name))
+	PFRB_FOREACH(p, &skip_b) {
+		if (!strcmp(ifname, p->pfik_name) &&
+		    (p->pfik_flags & PFI_IFLAG_SKIP))
 			p->pfik_flags &= ~PFI_IFLAG_SKIP;
+		if (!strcmp(ifname, p->pfik_name) && p->pfik_group != NULL) {
+			if ((h = ifa_grouplookup(p->pfik_name, 0)) == NULL)
+				continue;
+
+			for (n = h; n != NULL; n = n->next) {
+				if (p->pfik_ifp == NULL)
+					continue;
+				if (strncmp(p->pfik_name, ifname, IFNAMSIZ))
+					continue;
+
+				p->pfik_flags &= ~PFI_IFLAG_SKIP;
+			}
+		}
+	}
 	return (0);
 }
 
 int
-pfctl_clear_skip_ifaces(struct pfctl *pf)
+pfctl_adjust_skip_ifaces(struct pfctl *pf)
 {
-	struct pfi_kif		*p;
+	struct pfi_kif		*p, *pp;
+	struct node_host	*h = NULL, *n = NULL;
 
-	PFRB_FOREACH(p, &skip_b)
-		if (p->pfik_flags & PFI_IFLAG_SKIP)
-			pfctl_set_interface_flags(pf, p->pfik_name, PFI_IFLAG_SKIP, 0);
+	PFRB_FOREACH(p, &skip_b) {
+		if (p->pfik_group == NULL || !(p->pfik_flags & PFI_IFLAG_SKIP))
+			continue;
+
+		pfctl_set_interface_flags(pf, p->pfik_name, PFI_IFLAG_SKIP, 0);
+		if ((h = ifa_grouplookup(p->pfik_name, 0)) == NULL)
+			continue;
+
+		for (n = h; n != NULL; n = n->next)
+			PFRB_FOREACH(pp, &skip_b) {
+				if (pp->pfik_ifp == NULL)
+					continue;
+
+				if (strncmp(pp->pfik_name, n->ifname, IFNAMSIZ))
+					continue;
+
+				if (!(pp->pfik_flags & PFI_IFLAG_SKIP))
+					pfctl_set_interface_flags(pf,
+					    pp->pfik_name, PFI_IFLAG_SKIP, 1);
+				if (pp->pfik_flags & PFI_IFLAG_SKIP)
+					pp->pfik_flags &= ~PFI_IFLAG_SKIP;
+			}
+	}
+
+	PFRB_FOREACH(p, &skip_b) {
+		if (p->pfik_ifp == NULL || ! (p->pfik_flags & PFI_IFLAG_SKIP))
+			continue;
+
+		pfctl_set_interface_flags(pf, p->pfik_name, PFI_IFLAG_SKIP, 0);
+	}
+
 	return (0);
 }
 
@@ -1537,7 +1582,7 @@ pfctl_rules(int dev, char *filename, int opts, int opt
 			goto _error;
 	}
 	if (loadopt & PFCTL_FLAG_OPTION)
-		pfctl_clear_skip_ifaces(&pf);
+		pfctl_adjust_skip_ifaces(&pf);
 
 	if ((pf.loadopt & PFCTL_FLAG_FILTER &&
 	    (pfctl_load_ruleset(&pf, path, rs, PF_RULESET_SCRUB, 0))) ||

Modified: stable/11/sbin/pfctl/pfctl_parser.h
==============================================================================
--- stable/11/sbin/pfctl/pfctl_parser.h	Wed Aug 29 17:58:01 2018	(r338389)
+++ stable/11/sbin/pfctl/pfctl_parser.h	Wed Aug 29 20:49:56 2018	(r338390)
@@ -315,6 +315,7 @@ int			 unmask(struct pf_addr *, sa_family_t);
 void			 ifa_load(void);
 int			 get_socket_domain(void);
 struct node_host	*ifa_exists(const char *);
+struct node_host	*ifa_grouplookup(const char *ifa_name, int flags);
 struct node_host	*ifa_lookup(const char *, int);
 struct node_host	*host(const char *);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808292049.w7TKnu43021942>