pf.loadopt = loadopt;
pfctl_rules(int dev, char *filename, int opts){	FILE *fin;	struct pfioc_rule	pr[PF_RULESET_MAX];	struct pfioc_altq	pa;	struct pfctl		pf;	int			i;	memset(&pa, 0, sizeof(pa));	memset(&pf, 0, sizeof(pf));	for (i = 0; i < PF_RULESET_MAX; i++) {		memset(&pr[i], 0, sizeof(pr[i]));		memcpy(pr[i].anchor, anchorname, sizeof(pr[i].anchor));		memcpy(pr[i].ruleset, rulesetname, sizeof(pr[i].ruleset));	}	if (strcmp(filename, "-") == 0) {		fin = stdin;		infile = "stdin";	} else {		fin = fopen(filename, "r");		infile = filename;	}	if (fin == NULL) {		warn("%s", filename);		return (1);	}	if ((opts & PF_OPT_NOACTION) == 0) {		if ((loadopt & (PFCTL_FLAG_NAT | PFCTL_FLAG_ALL)) != 0) {			pr[PF_RULESET_NAT].rule.action = PF_NAT;			if (ioctl(dev, DIOCBEGINRULES, &pr[PF_RULESET_NAT]))				err(1, "DIOCBEGINRULES");			pr[PF_RULESET_RDR].rule.action = PF_RDR;			if (ioctl(dev, DIOCBEGINRULES, &pr[PF_RULESET_RDR]))				err(1, "DIOCBEGINRULES");			pr[PF_RULESET_BINAT].rule.action = PF_BINAT;			if (ioctl(dev, DIOCBEGINRULES, &pr[PF_RULESET_BINAT]))				err(1, "DIOCBEGINRULES");		}		if (((altqsupport && (loadopt &		    (PFCTL_FLAG_ALTQ | PFCTL_FLAG_ALL)) != 0)) &&		    ioctl(dev, DIOCBEGINALTQS, &pa.ticket)) {			err(1, "DIOCBEGINALTQS");		}		if ((loadopt & (PFCTL_FLAG_FILTER | PFCTL_FLAG_ALL)) != 0) {			pr[PF_RULESET_SCRUB].rule.action = PF_SCRUB;			if (ioctl(dev, DIOCBEGINRULES, &pr[PF_RULESET_SCRUB]))				err(1, "DIOCBEGINRULES");			pr[PF_RULESET_FILTER].rule.action = PF_PASS;			if (ioctl(dev, DIOCBEGINRULES, &pr[PF_RULESET_FILTER]))				err(1, "DIOCBEGINRULES");		}		pfctl_begin_table();	}	/* fill in callback data */	pf.dev = dev;	pf.opts = opts;	pf.paltq = &pa;	for (i = 0; i < PF_RULESET_MAX; i++) {		pf.prule[i] = &pr[i];	}	pf.rule_nr = 0;	if (parse_rules(fin, &pf) < 0)		errx(1, "Syntax error in file: pf rules not loaded");	if ((altqsupport && (loadopt & (PFCTL_FLAG_ALTQ | PFCTL_FLAG_ALL)) != 0))		if (check_commit_altq(dev, opts) != 0)			errx(1, "errors in altq config");	if ((opts & PF_OPT_NOACTION) == 0) {		if ((loadopt & (PFCTL_FLAG_NAT | PFCTL_FLAG_ALL)) != 0) {			pr[PF_RULESET_NAT].rule.action = PF_NAT;			if (ioctl(dev, DIOCCOMMITRULES, &pr[PF_RULESET_NAT]))				err(1, "DIOCCOMMITRULES");			pr[PF_RULESET_RDR].rule.action = PF_RDR;			if (ioctl(dev, DIOCCOMMITRULES, &pr[PF_RULESET_RDR]))				err(1, "DIOCCOMMITRULES");			pr[PF_RULESET_BINAT].rule.action = PF_BINAT;			if (ioctl(dev, DIOCCOMMITRULES, &pr[PF_RULESET_BINAT]))				err(1, "DIOCCOMMITRULES");		}		if (((altqsupport && (loadopt &		    (PFCTL_FLAG_ALTQ | PFCTL_FLAG_ALL)) != 0)) &&		    ioctl(dev, DIOCCOMMITALTQS, &pa.ticket))			err(1, "DIOCCOMMITALTQS");		if ((loadopt & (PFCTL_FLAG_FILTER | PFCTL_FLAG_ALL)) != 0) {			pr[PF_RULESET_SCRUB].rule.action = PF_SCRUB;			if (ioctl(dev, DIOCCOMMITRULES, &pr[PF_RULESET_SCRUB]))				err(1, "DIOCCOMMITRULES");			pr[PF_RULESET_FILTER].rule.action = PF_PASS;			if (ioctl(dev, DIOCCOMMITRULES, &pr[PF_RULESET_FILTER]))				err(1, "DIOCCOMMITRULES");		}		pfctl_commit_table();#if 0		if ((opts & PF_OPT_QUIET) == 0) {			fprintf(stderr, "%u nat entries loaded\n", n);			fprintf(stderr, "%u rdr entries loaded\n", r);			fprintf(stderr, "%u binat entries loaded\n", b);			fprintf(stderr, "%u rules loaded\n", n);		}#endif	}	if (fin != stdin)		fclose(fin);	return (0);}