Fix style(9) nits, reduce unnecessary type castings, etc., for bpf_setf().
This commit is contained in:
parent
9a4c9bf04c
commit
f2bf1d383e
@ -159,7 +159,7 @@ static void catchpacket(struct bpf_d *, u_char *, u_int, u_int,
|
|||||||
void (*)(struct bpf_d *, caddr_t, u_int, void *, u_int),
|
void (*)(struct bpf_d *, caddr_t, u_int, void *, u_int),
|
||||||
struct bintime *);
|
struct bintime *);
|
||||||
static void reset_d(struct bpf_d *);
|
static void reset_d(struct bpf_d *);
|
||||||
static int bpf_setf(struct bpf_d *, struct bpf_program *, u_long cmd);
|
static int bpf_setf(struct bpf_d *, struct bpf_program *, u_long cmd);
|
||||||
static int bpf_getdltlist(struct bpf_d *, struct bpf_dltlist *);
|
static int bpf_getdltlist(struct bpf_d *, struct bpf_dltlist *);
|
||||||
static int bpf_setdlt(struct bpf_d *, u_int);
|
static int bpf_setdlt(struct bpf_d *, u_int);
|
||||||
static void filt_bpfdetach(struct knote *);
|
static void filt_bpfdetach(struct knote *);
|
||||||
@ -1708,6 +1708,10 @@ bpfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags,
|
|||||||
static int
|
static int
|
||||||
bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd)
|
bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd)
|
||||||
{
|
{
|
||||||
|
#ifdef COMPAT_FREEBSD32
|
||||||
|
struct bpf_program fp_swab;
|
||||||
|
struct bpf_program32 *fp32;
|
||||||
|
#endif
|
||||||
struct bpf_insn *fcode, *old;
|
struct bpf_insn *fcode, *old;
|
||||||
#ifdef BPF_JITTER
|
#ifdef BPF_JITTER
|
||||||
bpf_jit_filter *jfunc, *ofunc;
|
bpf_jit_filter *jfunc, *ofunc;
|
||||||
@ -1715,10 +1719,8 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd)
|
|||||||
size_t size;
|
size_t size;
|
||||||
u_int flen;
|
u_int flen;
|
||||||
int need_upgrade;
|
int need_upgrade;
|
||||||
#ifdef COMPAT_FREEBSD32
|
|
||||||
struct bpf_program32 *fp32;
|
|
||||||
struct bpf_program fp_swab;
|
|
||||||
|
|
||||||
|
#ifdef COMPAT_FREEBSD32
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case BIOCSETF32:
|
case BIOCSETF32:
|
||||||
case BIOCSETWF32:
|
case BIOCSETWF32:
|
||||||
@ -1743,36 +1745,35 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd)
|
|||||||
#ifdef BPF_JITTER
|
#ifdef BPF_JITTER
|
||||||
jfunc = ofunc = NULL;
|
jfunc = ofunc = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
need_upgrade = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check new filter validness before acquiring any locks.
|
* Check new filter validness before acquiring any locks.
|
||||||
* Allocate memory for new filter, if needed.
|
* Allocate memory for new filter, if needed.
|
||||||
*/
|
*/
|
||||||
flen = fp->bf_len;
|
flen = fp->bf_len;
|
||||||
if ((flen > bpf_maxinsns) || ((fp->bf_insns == NULL) && (flen != 0)))
|
if (flen > bpf_maxinsns || (fp->bf_insns == NULL && flen != 0))
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
|
|
||||||
need_upgrade = 0;
|
|
||||||
size = flen * sizeof(*fp->bf_insns);
|
size = flen * sizeof(*fp->bf_insns);
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
/* We're setting up new filter. Copy and check actual data */
|
/* We're setting up new filter. Copy and check actual data. */
|
||||||
fcode = (struct bpf_insn *)malloc(size, M_BPF, M_WAITOK);
|
fcode = malloc(size, M_BPF, M_WAITOK);
|
||||||
if (copyin((caddr_t)fp->bf_insns, (caddr_t)fcode, size) != 0 ||
|
if (copyin(fp->bf_insns, fcode, size) != 0 ||
|
||||||
bpf_validate(fcode, (int)flen) == 0) {
|
!bpf_validate(fcode, flen)) {
|
||||||
free(fcode, M_BPF);
|
free(fcode, M_BPF);
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
}
|
}
|
||||||
#ifdef BPF_JITTER
|
#ifdef BPF_JITTER
|
||||||
/* Filter is copied inside fcode and is perfectly valid */
|
/* Filter is copied inside fcode and is perfectly valid. */
|
||||||
jfunc = bpf_jitter(fcode, flen);
|
jfunc = bpf_jitter(fcode, flen);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
BPF_LOCK();
|
BPF_LOCK();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up new filter.
|
* Set up new filter.
|
||||||
* Protect filter change by interface lock
|
* Protect filter change by interface lock.
|
||||||
* Additionally, we are protected by global lock here.
|
* Additionally, we are protected by global lock here.
|
||||||
*/
|
*/
|
||||||
if (d->bd_bif != NULL)
|
if (d->bd_bif != NULL)
|
||||||
@ -1794,9 +1795,9 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd)
|
|||||||
if (fcode != NULL) {
|
if (fcode != NULL) {
|
||||||
/*
|
/*
|
||||||
* Do not require upgrade by first BIOCSETF
|
* Do not require upgrade by first BIOCSETF
|
||||||
* (used to set snaplen) by pcap_open_live()
|
* (used to set snaplen) by pcap_open_live().
|
||||||
*/
|
*/
|
||||||
if ((d->bd_writer != 0) && (--d->bd_writer == 0))
|
if (d->bd_writer != 0 && --d->bd_writer == 0)
|
||||||
need_upgrade = 1;
|
need_upgrade = 1;
|
||||||
CTR4(KTR_NET, "%s: filter function set by pid %d, "
|
CTR4(KTR_NET, "%s: filter function set by pid %d, "
|
||||||
"bd_writer counter %d, need_upgrade %d",
|
"bd_writer counter %d, need_upgrade %d",
|
||||||
@ -1807,14 +1808,14 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd)
|
|||||||
if (d->bd_bif != NULL)
|
if (d->bd_bif != NULL)
|
||||||
BPFIF_WUNLOCK(d->bd_bif);
|
BPFIF_WUNLOCK(d->bd_bif);
|
||||||
if (old != NULL)
|
if (old != NULL)
|
||||||
free((caddr_t)old, M_BPF);
|
free(old, M_BPF);
|
||||||
#ifdef BPF_JITTER
|
#ifdef BPF_JITTER
|
||||||
if (ofunc != NULL)
|
if (ofunc != NULL)
|
||||||
bpf_destroy_jit_filter(ofunc);
|
bpf_destroy_jit_filter(ofunc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Move d to active readers list */
|
/* Move d to active readers list. */
|
||||||
if (need_upgrade != 0)
|
if (need_upgrade)
|
||||||
bpf_upgraded(d);
|
bpf_upgraded(d);
|
||||||
|
|
||||||
BPF_UNLOCK();
|
BPF_UNLOCK();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user