Changeset View
Changeset View
Standalone View
Standalone View
sbin/pfctl/pfctl.c
Show First 20 Lines • Show All 1,231 Lines • ▼ Show 20 Lines | |||||
done: | done: | ||||
free(inbuf); | free(inbuf); | ||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
pfctl_show_states(int dev, const char *iface, int opts) | pfctl_show_states(int dev, const char *iface, int opts) | ||||
{ | { | ||||
struct pfioc_states ps; | struct pfctl_states states; | ||||
struct pfsync_state *p; | struct pfctl_state *s; | ||||
char *inbuf = NULL, *newinbuf = NULL; | int dotitle = (opts & PF_OPT_SHOWALL); | ||||
unsigned int len = 0; | |||||
int i, dotitle = (opts & PF_OPT_SHOWALL); | |||||
memset(&ps, 0, sizeof(ps)); | memset(&states, 0, sizeof(states)); | ||||
for (;;) { | |||||
ps.ps_len = len; | if (pfctl_get_states(dev, &states)) | ||||
if (len) { | |||||
newinbuf = realloc(inbuf, len); | |||||
if (newinbuf == NULL) | |||||
err(1, "realloc"); | |||||
ps.ps_buf = inbuf = newinbuf; | |||||
} | |||||
if (ioctl(dev, DIOCGETSTATES, &ps) < 0) { | |||||
warn("DIOCGETSTATES"); | |||||
free(inbuf); | |||||
return (-1); | return (-1); | ||||
} | |||||
if (ps.ps_len + sizeof(struct pfioc_states) < len) | TAILQ_FOREACH(s, &states.states, entry) { | ||||
break; | if (iface != NULL && strcmp(s->ifname, iface)) | ||||
if (len == 0 && ps.ps_len == 0) | |||||
goto done; | |||||
if (len == 0 && ps.ps_len != 0) | |||||
len = ps.ps_len; | |||||
if (ps.ps_len == 0) | |||||
goto done; /* no states */ | |||||
len *= 2; | |||||
} | |||||
p = ps.ps_states; | |||||
for (i = 0; i < ps.ps_len; i += sizeof(*p), p++) { | |||||
if (iface != NULL && strcmp(p->ifname, iface)) | |||||
continue; | continue; | ||||
if (dotitle) { | if (dotitle) { | ||||
pfctl_print_title("STATES:"); | pfctl_print_title("STATES:"); | ||||
dotitle = 0; | dotitle = 0; | ||||
} | } | ||||
print_state(p, opts); | print_state(s, opts); | ||||
} | } | ||||
done: | |||||
free(inbuf); | pfctl_free_states(&states); | ||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
pfctl_show_status(int dev, int opts) | pfctl_show_status(int dev, int opts) | ||||
{ | { | ||||
struct pf_status status; | struct pf_status status; | ||||
▲ Show 20 Lines • Show All 1,323 Lines • Show Last 20 Lines |