summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjell Wooding <kjell@cvs.openbsd.org>2001-06-27 10:31:52 +0000
committerKjell Wooding <kjell@cvs.openbsd.org>2001-06-27 10:31:52 +0000
commit1af4743896368d72b37729fb509c340856465816 (patch)
tree135ce5b80dfc7230b98001235cbc2e4c11bded46
parent448bece5da7e46a44180845c85ee979221134c31 (diff)
add -z flag for zeroing statistics. -s status no longer resets anything
-rw-r--r--sbin/pfctl/pfctl.c26
-rw-r--r--sys/net/pf.c14
-rw-r--r--sys/net/pfvar.h3
3 files changed, 31 insertions, 12 deletions
diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c
index 2b7d72a0633..9db439e019f 100644
--- a/sbin/pfctl/pfctl.c
+++ b/sbin/pfctl/pfctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl.c,v 1.18 2001/06/26 23:24:06 kjell Exp $ */
+/* $OpenBSD: pfctl.c,v 1.19 2001/06/27 10:31:49 kjell Exp $ */
/*
* Copyright (c) 2001, Daniel Hartmeier
@@ -51,6 +51,7 @@ void usage(void);
char *load_file(char *, size_t *);
int pfctl_enable(int);
int pfctl_disable(int);
+int pfctl_clear_stats(int);
int pfctl_clear_rules(int);
int pfctl_clear_nat(int);
int pfctl_clear_states(int);
@@ -66,6 +67,7 @@ int dflag = 0;
int eflag = 0;
int vflag = 0;
int Nflag = 0;
+int zflag = 0;
char *clearopt;
char *logopt;
char *natopt;
@@ -78,7 +80,7 @@ usage()
extern char *__progname;
fprintf(stderr, "usage: %s [-de] [-c set] [-l interface]", __progname);
- fprintf(stderr, " [-n file] [-r file] [-s set]\n");
+ fprintf(stderr, " [-N] [-n file] [-r file] [-s set] [-v] [-z]\n");
exit(1);
}
@@ -136,6 +138,17 @@ pfctl_disable(int dev)
}
int
+pfctl_clear_stats(int dev)
+{
+ if (ioctl(dev, DIOCCLRSTATUS)) {
+ errx(1, "DIOCCLRSTATUS");
+ return (1);
+ }
+ printf("pf: statistics cleared\n");
+ return (0);
+}
+
+int
pfctl_clear_rules(int dev)
{
struct pfioc_rule pr;
@@ -428,7 +441,7 @@ main(int argc, char *argv[])
if (argc < 2)
usage();
- while ((ch = getopt(argc, argv, "c:del:Nn:r:s:v")) != -1) {
+ while ((ch = getopt(argc, argv, "c:del:Nn:r:s:vz")) != -1) {
switch (ch) {
case 'c':
clearopt = optarg;
@@ -457,6 +470,9 @@ main(int argc, char *argv[])
case 'v':
vflag++;
break;
+ case 'z':
+ zflag++;
+ break;
default:
usage();
/* NOTREACHED */
@@ -473,6 +489,10 @@ main(int argc, char *argv[])
if (pfctl_disable(dev))
error = 1;
+ if (zflag)
+ if (pfctl_clear_stats(dev))
+ error = 1;
+
if (clearopt != NULL) {
if (!strcmp(clearopt, "rules")) {
if (pfctl_clear_rules(dev))
diff --git a/sys/net/pf.c b/sys/net/pf.c
index 811f4467aa0..8b62c34a703 100644
--- a/sys/net/pf.c
+++ b/sys/net/pf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf.c,v 1.76 2001/06/27 10:27:43 kjell Exp $ */
+/* $OpenBSD: pf.c,v 1.77 2001/06/27 10:31:51 kjell Exp $ */
/*
* Copyright (c) 2001, Daniel Hartmeier
@@ -962,18 +962,16 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
case DIOCGETSTATUS: {
struct pf_status *s = (struct pf_status *)addr;
+ bcopy(&pf_status, s, sizeof(struct pf_status));
+ break;
+ }
+
+ case DIOCCLRSTATUS: {
u_int8_t running = pf_status.running;
u_int32_t states = pf_status.states;
-
- bcopy(&pf_status, s, sizeof(struct pf_status));
- if (s->since)
- s->since = pftv.tv_sec - s->since;
- else
- s->since = 0;
bzero(&pf_status, sizeof(struct pf_status));
pf_status.running = running;
pf_status.states = states;
- pf_status.since = pftv.tv_sec;
break;
}
diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h
index 72087015201..3f86ed947b3 100644
--- a/sys/net/pfvar.h
+++ b/sys/net/pfvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfvar.h,v 1.22 2001/06/27 04:29:21 deraadt Exp $ */
+/* $OpenBSD: pfvar.h,v 1.23 2001/06/27 10:31:51 kjell Exp $ */
/*
* Copyright (c) 2001, Daniel Hartmeier
@@ -217,6 +217,7 @@ struct pfioc_if {
#define DIOCGETSTATE _IOWR('D', 19, struct pfioc_state)
#define DIOCSETSTATUSIF _IOWR('D', 20, struct pfioc_if)
#define DIOCGETSTATUS _IOWR('D', 21, struct pf_status)
+#define DIOCCLRSTATUS _IO ('D', 22)
#ifdef _KERNEL