diff options
author | Ryan Thomas McBride <mcbride@cvs.openbsd.org> | 2010-06-28 23:21:42 +0000 |
---|---|---|
committer | Ryan Thomas McBride <mcbride@cvs.openbsd.org> | 2010-06-28 23:21:42 +0000 |
commit | c246d91cf4c801e05376eac44bd49d0016e34d9f (patch) | |
tree | a09bcc996a97bf629e74a883e6abb18fa5787f99 | |
parent | e780a94e3f212f0eddee803af28afa52558c1489 (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
-rw-r--r-- | sbin/pfctl/pfctl.c | 38 | ||||
-rw-r--r-- | sys/net/pf_if.c | 13 | ||||
-rw-r--r-- | sys/net/pf_ioctl.c | 19 | ||||
-rw-r--r-- | sys/net/pfvar.h | 10 |
4 files changed, 54 insertions, 26 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); } diff --git a/sys/net/pf_if.c b/sys/net/pf_if.c index 0816e3fbf20..b96ba8d1150 100644 --- a/sys/net/pf_if.c +++ b/sys/net/pf_if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf_if.c,v 1.60 2010/01/18 23:52:46 mcbride Exp $ */ +/* $OpenBSD: pf_if.c,v 1.61 2010/06/28 23:21:41 mcbride Exp $ */ /* * Copyright 2005 Henning Brauer <henning@openbsd.org> @@ -628,8 +628,17 @@ pfi_update_status(const char *name, struct pf_status *pfs) TAILQ_HEAD(, ifg_member) ifg_members; int i, j, k, s; - strlcpy(key.pfik_name, name, sizeof(key.pfik_name)); s = splsoftnet(); + if (*name == '\0' && pfs == NULL) { + RB_FOREACH(p, pfi_ifhead, &pfi_ifs) { + bzero(p->pfik_packets, sizeof(p->pfik_packets)); + bzero(p->pfik_bytes, sizeof(p->pfik_bytes)); + p->pfik_tzero = time_second; + } + return; + } + + strlcpy(key.pfik_name, name, sizeof(key.pfik_name)); p = RB_FIND(pfi_ifhead, &pfi_ifs, (struct pfi_kif *)&key); if (p == NULL) { splx(s); diff --git a/sys/net/pf_ioctl.c b/sys/net/pf_ioctl.c index 497ba402125..fd6c047eab6 100644 --- a/sys/net/pf_ioctl.c +++ b/sys/net/pf_ioctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf_ioctl.c,v 1.233 2010/06/27 01:28:44 mcbride Exp $ */ +/* $OpenBSD: pf_ioctl.c,v 1.234 2010/06/28 23:21:41 mcbride Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -1560,24 +1560,31 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p) } case DIOCSETSTATUSIF: { - struct pfioc_if *pi = (struct pfioc_if *)addr; + struct pfioc_iface *pi = (struct pfioc_iface *)addr; - if (pi->ifname[0] == 0) { + if (pi->pfiio_name[0] == 0) { bzero(pf_status.ifname, IFNAMSIZ); break; } - strlcpy(pf_trans_set.statusif, pi->ifname, IFNAMSIZ); + strlcpy(pf_trans_set.statusif, pi->pfiio_name, IFNAMSIZ); pf_trans_set.mask |= PF_TSET_STATUSIF; break; } case DIOCCLRSTATUS: { + struct pfioc_iface *pi = (struct pfioc_iface *)addr; + + /* if ifname is specified, clear counters there only */ + if (pi->pfiio_name[0]) { + pfi_update_status(pi->pfiio_name, NULL); + break; + } + bzero(pf_status.counters, sizeof(pf_status.counters)); bzero(pf_status.fcounters, sizeof(pf_status.fcounters)); bzero(pf_status.scounters, sizeof(pf_status.scounters)); pf_status.since = time_second; - if (*pf_status.ifname) - pfi_update_status(pf_status.ifname, NULL); + break; } diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 8c91ce7ca46..80c563c742f 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pfvar.h,v 1.310 2010/06/27 01:39:43 henning Exp $ */ +/* $OpenBSD: pfvar.h,v 1.311 2010/06/28 23:21:41 mcbride Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -1518,10 +1518,6 @@ struct pfioc_src_nodes { #define psn_src_nodes psn_u.psu_src_nodes }; -struct pfioc_if { - char ifname[IFNAMSIZ]; -}; - struct pfioc_tm { int timeout; int seconds; @@ -1616,9 +1612,9 @@ struct pfioc_iface { /* XXX cut 8 - 17 */ #define DIOCCLRSTATES _IOWR('D', 18, struct pfioc_state_kill) #define DIOCGETSTATE _IOWR('D', 19, struct pfioc_state) -#define DIOCSETSTATUSIF _IOWR('D', 20, struct pfioc_if) +#define DIOCSETSTATUSIF _IOWR('D', 20, struct pfioc_iface) #define DIOCGETSTATUS _IOWR('D', 21, struct pf_status) -#define DIOCCLRSTATUS _IO ('D', 22) +#define DIOCCLRSTATUS _IOWR('D', 22, struct pfioc_iface) #define DIOCNATLOOK _IOWR('D', 23, struct pfioc_natlook) #define DIOCSETDEBUG _IOWR('D', 24, u_int32_t) #define DIOCGETSTATES _IOWR('D', 25, struct pfioc_states) |