summaryrefslogtreecommitdiff
path: root/sbin/pfctl/pfctl.c
diff options
context:
space:
mode:
authorRyan Thomas McBride <mcbride@cvs.openbsd.org>2010-06-28 23:21:42 +0000
committerRyan Thomas McBride <mcbride@cvs.openbsd.org>2010-06-28 23:21:42 +0000
commitc246d91cf4c801e05376eac44bd49d0016e34d9f (patch)
treea09bcc996a97bf629e74a883e6abb18fa5787f99 /sbin/pfctl/pfctl.c
parente780a94e3f212f0eddee803af28afa52558c1489 (diff)
Clean up iterface stats handling:
- 'make -Fi' reset ALL the interface statistics can be restricted with -i ifname - 'make -Fa -i ifname' fail (it's meaningless) - get rid of a silly little struct that's only used for one thing ok henning
Diffstat (limited to 'sbin/pfctl/pfctl.c')
-rw-r--r--sbin/pfctl/pfctl.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c
index 1f0deda6ef1..1bc461d5dcc 100644
--- a/sbin/pfctl/pfctl.c
+++ b/sbin/pfctl/pfctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl.c,v 1.297 2010/06/25 23:27:47 henning Exp $ */
+/* $OpenBSD: pfctl.c,v 1.298 2010/06/28 23:21:41 mcbride Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -61,7 +61,7 @@
void usage(void);
int pfctl_enable(int, int);
int pfctl_disable(int, int);
-int pfctl_clear_stats(int, int);
+int pfctl_clear_stats(int, const char *, int);
int pfctl_clear_interface_flags(int, int);
int pfctl_clear_rules(int, int, char *);
int pfctl_clear_altq(int, int);
@@ -281,12 +281,23 @@ pfctl_disable(int dev, int opts)
}
int
-pfctl_clear_stats(int dev, int opts)
+pfctl_clear_stats(int dev, const char *iface, int opts)
{
- if (ioctl(dev, DIOCCLRSTATUS))
+ struct pfioc_iface pi;
+
+ memset(&pi, 0, sizeof(pi));
+ if (iface != NULL && strlcpy(pi.pfiio_name, iface,
+ sizeof(pi.pfiio_name)) >= sizeof(pi.pfiio_name))
+ errx(1, "invalid interface: %s", iface);
+
+ if (ioctl(dev, DIOCCLRSTATUS, &pi))
err(1, "DIOCCLRSTATUS");
- if ((opts & PF_OPT_QUIET) == 0)
- fprintf(stderr, "pf: statistics cleared\n");
+ if ((opts & PF_OPT_QUIET) == 0) {
+ fprintf(stderr, "pf: statistics cleared");
+ if (iface != NULL)
+ fprintf(stderr, " for interface %s", iface);
+ fprintf(stderr, "\n");
+ }
return (0);
}
@@ -1582,11 +1593,11 @@ pfctl_set_logif(struct pfctl *pf, char *ifname)
int
pfctl_load_logif(struct pfctl *pf, char *ifname)
{
- struct pfioc_if pi;
+ struct pfioc_iface pi;
memset(&pi, 0, sizeof(pi));
- if (ifname && strlcpy(pi.ifname, ifname,
- sizeof(pi.ifname)) >= sizeof(pi.ifname)) {
+ if (ifname && strlcpy(pi.pfiio_name, ifname,
+ sizeof(pi.pfiio_name)) >= sizeof(pi.pfiio_name)) {
warnx("pfctl_load_logif: strlcpy");
return (1);
}
@@ -2131,16 +2142,21 @@ main(int argc, char *argv[])
pfctl_clear_src_nodes(dev, opts);
break;
case 'i':
- pfctl_clear_stats(dev, opts);
+ pfctl_clear_stats(dev, ifaceopt, opts);
break;
case 'a':
pfctl_clear_rules(dev, opts, anchorname);
pfctl_clear_tables(anchorname, opts);
+ if (*ifaceopt) {
+ warnx("don't specify an interface with -Fall");
+ usage();
+ /* NOTREACHED */
+ }
if (!*anchorname) {
pfctl_clear_altq(dev, opts);
pfctl_clear_states(dev, ifaceopt, opts);
pfctl_clear_src_nodes(dev, opts);
- pfctl_clear_stats(dev, opts);
+ pfctl_clear_stats(dev, ifaceopt, opts);
pfctl_clear_fingerprints(dev, opts);
pfctl_clear_interface_flags(dev, opts);
}