Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
Show First 20 Lines • Show All 1,509 Lines • ▼ Show 20 Lines | err2: | ||||
free(pt); | free(pt); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
static int | static int | ||||
pfl_scan_ruleset(const char *path) | pfl_scan_ruleset(const char *path) | ||||
{ | { | ||||
struct pfioc_rule pr; | struct pfioc_rule pr; | ||||
struct pfctl_rule rule; | |||||
glebius: Do you plan to eventually hide struct pfioc_rule into libpfctl? | |||||
kpAuthorUnsubmitted Not Done Inline ActionsI'm hoping to eventually delete it entirely. kp: I'm hoping to eventually delete it entirely.
One of the things I want to add to libpfctl is a… | |||||
struct pfl_entry *e; | struct pfl_entry *e; | ||||
u_int32_t nr, i; | u_int32_t nr, i; | ||||
bzero(&pr, sizeof(pr)); | bzero(&pr, sizeof(pr)); | ||||
strlcpy(pr.anchor, path, sizeof(pr.anchor)); | strlcpy(pr.anchor, path, sizeof(pr.anchor)); | ||||
pr.rule.action = PF_PASS; | pr.rule.action = PF_PASS; | ||||
if (ioctl(dev, DIOCGETRULES, &pr)) { | if (ioctl(dev, DIOCGETRULES, &pr)) { | ||||
syslog(LOG_ERR, "pfl_scan_ruleset: ioctl(DIOCGETRULES): %s", | syslog(LOG_ERR, "pfl_scan_ruleset: ioctl(DIOCGETRULES): %s", | ||||
strerror(errno)); | strerror(errno)); | ||||
goto err; | goto err; | ||||
} | } | ||||
for (nr = pr.nr, i = 0; i < nr; i++) { | for (nr = pr.nr, i = 0; i < nr; i++) { | ||||
pr.nr = i; | pr.nr = i; | ||||
if (libpfctl_add_rule(dev, &pr.rule, pr.anchor, pr.anchor_call, | if (libpfctl_add_rule(dev, &rule, pr.anchor, pr.anchor_call, | ||||
pr.ticket, pr.pool_ticket)) { | pr.ticket, pr.pool_ticket)) { | ||||
syslog(LOG_ERR, "pfl_scan_ruleset: ioctl(DIOCGETRULE):" | syslog(LOG_ERR, "pfl_scan_ruleset: ioctl(DIOCGETRULE):" | ||||
" %s", strerror(errno)); | " %s", strerror(errno)); | ||||
goto err; | goto err; | ||||
} | } | ||||
if (pr.rule.label[0]) { | if (rule.label[0]) { | ||||
e = (struct pfl_entry *)malloc(sizeof(*e)); | e = (struct pfl_entry *)malloc(sizeof(*e)); | ||||
if (e == NULL) | if (e == NULL) | ||||
goto err; | goto err; | ||||
strlcpy(e->name, path, sizeof(e->name)); | strlcpy(e->name, path, sizeof(e->name)); | ||||
if (path[0]) | if (path[0]) | ||||
strlcat(e->name, "/", sizeof(e->name)); | strlcat(e->name, "/", sizeof(e->name)); | ||||
strlcat(e->name, pr.rule.label, sizeof(e->name)); | strlcat(e->name, rule.label, sizeof(e->name)); | ||||
e->evals = pr.rule.evaluations; | e->evals = rule.evaluations; | ||||
e->bytes[IN] = pr.rule.bytes[IN]; | e->bytes[IN] = rule.bytes[IN]; | ||||
e->bytes[OUT] = pr.rule.bytes[OUT]; | e->bytes[OUT] = rule.bytes[OUT]; | ||||
e->pkts[IN] = pr.rule.packets[IN]; | e->pkts[IN] = rule.packets[IN]; | ||||
e->pkts[OUT] = pr.rule.packets[OUT]; | e->pkts[OUT] = rule.packets[OUT]; | ||||
e->index = ++pfl_table_count; | e->index = ++pfl_table_count; | ||||
TAILQ_INSERT_TAIL(&pfl_table, e, link); | TAILQ_INSERT_TAIL(&pfl_table, e, link); | ||||
} | } | ||||
} | } | ||||
return (0); | return (0); | ||||
▲ Show 20 Lines • Show All 246 Lines • Show Last 20 Lines |
Do you plan to eventually hide struct pfioc_rule into libpfctl?