From f11c35082bae13e97081cbdd18b70d9a9d822c96 Mon Sep 17 00:00:00 2001 From: David Malone Date: Mon, 7 Jul 2008 09:25:49 +0000 Subject: [PATCH] Add a new ioctl for changing the read filter (BIOCSETFNR). This is just like BIOCSETF but it doesn't drop all the packets buffered on the discriptor and reset the statistics. Also, when setting the write filter, don't drop packets waiting to be read or reset the statistics. PR: 118486 Submitted by: Matthew Luckie MFC after: 1 month --- sys/net/bpf.c | 12 ++++++++---- sys/net/bpf.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sys/net/bpf.c b/sys/net/bpf.c index e03f30e1f84d..ffaa762e58dc 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -927,8 +927,9 @@ reset_d(struct bpf_d *d) * FIONREAD Check for read packet available. * SIOCGIFADDR Get interface address - convenient hook to driver. * BIOCGBLEN Get buffer len [for read()]. - * BIOCSETF Set ethernet read filter. - * BIOCSETWF Set ethernet write filter. + * BIOCSETF Set read filter. + * BIOCSETFNR Set read filter without resetting descriptor. + * BIOCSETWF Set write filter. * BIOCFLUSH Flush read packet buffer. * BIOCPROMISC Put interface into promiscuous mode. * BIOCGDLT Get link layer type. @@ -1047,6 +1048,7 @@ bpfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, * Set link layer read filter. */ case BIOCSETF: + case BIOCSETFNR: case BIOCSETWF: error = bpf_setf(d, (struct bpf_program *)addr, cmd); break; @@ -1361,8 +1363,9 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd) #ifdef BPF_JITTER d->bd_bfilter = NULL; #endif + if (cmd == BIOCSETF) + reset_d(d); } - reset_d(d); BPFD_UNLOCK(d); if (old != NULL) free((caddr_t)old, M_BPF); @@ -1388,8 +1391,9 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd) #ifdef BPF_JITTER d->bd_bfilter = bpf_jitter(fcode, flen); #endif + if (cmd == BIOCSETF) + reset_d(d); } - reset_d(d); BPFD_UNLOCK(d); if (old != NULL) free((caddr_t)old, M_BPF); diff --git a/sys/net/bpf.h b/sys/net/bpf.h index 1d6f9db7415d..3d3d079907a6 100644 --- a/sys/net/bpf.h +++ b/sys/net/bpf.h @@ -142,6 +142,7 @@ struct bpf_zbuf { #define BIOCGETZMAX _IOR('B',127, size_t) #define BIOCROTZBUF _IOR('B',128, struct bpf_zbuf) #define BIOCSETZBUF _IOW('B',129, struct bpf_zbuf) +#define BIOCSETFNR _IOW('B',130, struct bpf_program) /* Obsolete */ #define BIOCGSEESENT BIOCGDIRECTION