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
This commit is contained in:
Kristof Provost 2018-08-22 08:14:29 +00:00
parent 9544e6dcf1
commit 7a831fecc8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=338183
2 changed files with 75 additions and 9 deletions

View File

@ -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 optimize,
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))) ||

View File

@ -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 *);