Give the BPF the ability to generate signals when a packet is available.

Reviewed by:	pst & wollman
Submitted by:	grossman@cygnus.com
This commit is contained in:
pst 1995-06-15 18:11:00 +00:00
parent af679f9c57
commit 763ad9c0a0
3 changed files with 66 additions and 5 deletions

View File

@ -37,7 +37,7 @@
*
* @(#)bpf.c 8.2 (Berkeley) 3/28/94
*
* $Id: bpf.c,v 1.6 1995/05/09 13:35:38 davidg Exp $
* $Id: bpf.c,v 1.7 1995/05/30 08:07:50 rgrimes Exp $
*/
#include "bpfilter.h"
@ -328,6 +328,7 @@ bpfopen(dev, flag)
/* Mark "free" and do most initialization. */
bzero((char *)d, sizeof(*d));
d->bd_bufsize = bpf_bufsize;
d->bd_sig = SIGIO;
return (0);
}
@ -439,8 +440,11 @@ bpfread(dev, uio)
ROTATE_BUFFERS(d);
break;
}
error = BPF_SLEEP((caddr_t)d, PRINET|PCATCH, "bpf",
d->bd_rtout);
if (d->bd_rtout != -1)
error = BPF_SLEEP((caddr_t)d, PRINET|PCATCH, "bpf",
d->bd_rtout);
else
error = EWOULDBLOCK; /* User requested non-blocking I/O */
if (error == EINTR || error == ERESTART) {
splx(s);
return (error);
@ -496,7 +500,15 @@ static inline void
bpf_wakeup(d)
register struct bpf_d *d;
{
struct proc *p;
wakeup((caddr_t)d);
if (d->bd_async && d->bd_sig)
if (d->bd_pgid > 0)
gsignal (d->bd_pgid, d->bd_sig);
else if (p = pfind (-d->bd_pgid))
psignal (p, d->bd_sig);
#if BSD >= 199103
selwakeup(&d->bd_sel);
/* XXX */
@ -782,6 +794,48 @@ bpfioctl(dev, cmd, addr, flag)
bv->bv_minor = BPF_MINOR_VERSION;
break;
}
case FIONBIO: /* Non-blocking I/O */
if (*(int *)addr)
d->bd_rtout = -1;
else
d->bd_rtout = 0;
break;
case FIOASYNC: /* Send signal on receive packets */
d->bd_async = *(int *)addr;
break;
/* N.B. ioctl (FIOSETOWN) and fcntl (F_SETOWN) both end up doing the
equivalent of a TIOCSPGRP and hence end up here. *However* TIOCSPGRP's arg
is a process group if it's positive and a process id if it's negative. This
is exactly the opposite of what the other two functions want! Therefore
there is code in ioctl and fcntl to negate the arg before calling here. */
case TIOCSPGRP: /* Process or group to send signals to */
d->bd_pgid = *(int *)addr;
break;
case TIOCGPGRP:
*(int *)addr = d->bd_pgid;
break;
case BIOCSRSIG: /* Set receive signal */
{
u_int sig;
sig = *(u_int *)addr;
if (sig >= NSIG)
error = EINVAL;
else
d->bd_sig = sig;
break;
}
case BIOCGRSIG:
*(u_int *)addr = d->bd_sig;
break;
}
return (error);
}

View File

@ -37,7 +37,7 @@
*
* @(#)bpf.h 8.1 (Berkeley) 6/10/93
*
* $Id: bpf.h,v 1.3 1994/08/21 05:11:38 paul Exp $
* $Id: bpf.h,v 1.4 1995/05/30 08:07:52 rgrimes Exp $
*/
#ifndef _NET_BPF_H_
@ -110,6 +110,8 @@ struct bpf_version {
#define BIOCGSTATS _IOR(B,111, struct bpf_stat)
#define BIOCIMMEDIATE _IOW(B,112, u_int)
#define BIOCVERSION _IOR(B,113, struct bpf_version)
#define BIOCGRSIG _IOR(B,114, u_int)
#define BIOCSRSIG _IOW(B,115, u_int)
#else
#define BIOCGBLEN _IOR('B',102, u_int)
#define BIOCSBLEN _IOWR('B',102, u_int)
@ -124,6 +126,8 @@ struct bpf_version {
#define BIOCGSTATS _IOR('B',111, struct bpf_stat)
#define BIOCIMMEDIATE _IOW('B',112, u_int)
#define BIOCVERSION _IOR('B',113, struct bpf_version)
#define BIOCGRSIG _IOR('B',114, u_int)
#define BIOCSRSIG _IOW('B',115, u_int)
#endif
/*

View File

@ -37,7 +37,7 @@
*
* @(#)bpfdesc.h 8.1 (Berkeley) 6/10/93
*
* $Id: bpfdesc.h,v 1.3 1994/08/02 07:46:00 davidg Exp $
* $Id: bpfdesc.h,v 1.4 1994/08/21 05:11:39 paul Exp $
*/
#ifndef _NET_BPFDESC_H_
@ -76,6 +76,9 @@ struct bpf_d {
u_char bd_promisc; /* true if listening promiscuously */
u_char bd_state; /* idle, waiting, or timed out */
u_char bd_immediate; /* true to return on packet arrival */
int bd_async; /* non-zero if packet reception should generate signal */
int bd_sig; /* signal to send upon packet reception */
pid_t bd_pgid; /* process or group id for signal */
#if BSD < 199103
u_char bd_selcoll; /* true if selects collide */
int bd_timedout;