svn commit: r338183 - head/sbin/pfctl
Kristof Provost
kp at FreeBSD.org
Wed Aug 22 08:14:30 UTC 2018
Author: kp
Date: Wed Aug 22 08:14:29 2018
New Revision: 338183
URL: https://svnweb.freebsd.org/changeset/base/338183
Log:
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>
MFC after: 1 week
Modified:
head/sbin/pfctl/pfctl.c
head/sbin/pfctl/pfctl_parser.h
Modified: head/sbin/pfctl/pfctl.c
==============================================================================
--- head/sbin/pfctl/pfctl.c Wed Aug 22 04:29:24 2018 (r338182)
+++ head/sbin/pfctl/pfctl.c Wed Aug 22 08:14:29 2018 (r338183)
@@ -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,86 @@ 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)
+static void
+pfctl_adjust_skip_ifaces_group_member(struct pfctl *pf, char *ifname)
{
- struct pfi_kif *p;
+ struct pfi_kif *p;
- PFRB_FOREACH(p, &skip_b)
+ PFRB_FOREACH(p, &skip_b) {
+ if (p->pfik_ifp == NULL)
+ continue;
+
+ if (strncmp(p->pfik_name, ifname, IFNAMSIZ))
+ continue;
+
+ if (!(p->pfik_flags & PFI_IFLAG_SKIP))
+ pfctl_set_interface_flags(pf, p->pfik_name,
+ PFI_IFLAG_SKIP, 1);
if (p->pfik_flags & PFI_IFLAG_SKIP)
- pfctl_set_interface_flags(pf, p->pfik_name, PFI_IFLAG_SKIP, 0);
+ p->pfik_flags &= ~PFI_IFLAG_SKIP;
+ }
+}
+
+int
+pfctl_adjust_skip_ifaces(struct pfctl *pf)
+{
+ struct pfi_kif *p, *pp;
+ struct node_host *h = NULL, *n = NULL;
+
+ 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 +1602,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: head/sbin/pfctl/pfctl_parser.h
==============================================================================
--- head/sbin/pfctl/pfctl_parser.h Wed Aug 22 04:29:24 2018 (r338182)
+++ head/sbin/pfctl/pfctl_parser.h Wed Aug 22 08:14:29 2018 (r338183)
@@ -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 *);
More information about the svn-src-all
mailing list