⬢ DragonFlyBSD Kernel Audit
DF-3420 / setstatif.c
← back to finding ↓ download raw
/*
 * DF-3420 helper: set pf status-if to the group name "tap" so that
 * pfctl -si (DIOCGETSTATUS -> pfi_update_status) takes the GROUP branch
 * and does the unlocked bcopy of ifg_members (pf_if.c:722-724).
 */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define IFNAMSIZ 16
struct pfioc_if { char ifname[IFNAMSIZ]; };
#define PFIOC_SETSTATUSIF _IOWR('D', 20, struct pfioc_if)

int
main(int argc, char **argv)
{
	struct pfioc_if pi;
	int fd;

	if (argc != 2) {
		fprintf(stderr, "usage: %s <ifname-or-group>\n", argv[0]);
		return 2;
	}
	fd = open("/dev/pf", O_RDWR);
	if (fd < 0) { perror("open /dev/pf"); return 2; }
	bzero(&pi, sizeof(pi));
	strlcpy(pi.ifname, argv[1], sizeof(pi.ifname));
	if (ioctl(fd, PFIOC_SETSTATUSIF, &pi) != 0) {
		perror("DIOCSETSTATUSIF"); return 2;
	}
	printf("status-if set to %s\n", pi.ifname);
	return 0;
}