From owner-svn-src-stable@freebsd.org Wed Aug 29 20:49:57 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9EA811095FD1; Wed, 29 Aug 2018 20:49:57 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5F456814DE; Wed, 29 Aug 2018 20:49:57 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 405F0224AC; Wed, 29 Aug 2018 20:49:57 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7TKnvaj021944; Wed, 29 Aug 2018 20:49:57 GMT (envelope-from kp@FreeBSD.org) Received: (from kp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7TKnu43021942; Wed, 29 Aug 2018 20:49:56 GMT (envelope-from kp@FreeBSD.org) Message-Id: <201808292049.w7TKnu43021942@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kp set sender to kp@FreeBSD.org using -f From: Kristof Provost Date: Wed, 29 Aug 2018 20:49:56 +0000 (UTC) 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 X-SVN-Group: stable-11 X-SVN-Commit-Author: kp X-SVN-Commit-Paths: stable/11/sbin/pfctl X-SVN-Commit-Revision: 338390 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Aug 2018 20:49:57 -0000 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 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 *);