Enhancements to the bpf from Stu Grossman <grossman@cygnus.com>:

* grok FIONBIO, FIOASYNC, and TIOC{G,S}PGRP
	* add BIOC{G,S}RSIG; get/set the signal to be delivered
	  to the process or process group upon packet reception.
	  Defaults to SIGIO.
This commit is contained in:
thorpej 1995-09-27 18:30:37 +00:00
parent e29cdeba95
commit e1f1a3a9a7
3 changed files with 68 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: bpf.c,v 1.22 1995/08/13 04:15:38 mycroft Exp $ */
/* $NetBSD: bpf.c,v 1.23 1995/09/27 18:30:37 thorpej Exp $ */
/*
* Copyright (c) 1990, 1991, 1993
@ -336,6 +336,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);
}
@ -447,8 +448,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);
@ -504,7 +508,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 */
@ -767,6 +779,50 @@ 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

@ -1,4 +1,4 @@
/* $NetBSD: bpf.h,v 1.11 1995/04/22 13:26:32 cgd Exp $ */
/* $NetBSD: bpf.h,v 1.12 1995/09/27 18:30:40 thorpej Exp $ */
/*
* Copyright (c) 1990, 1991, 1993
@ -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 BIOCSRSIG _IOW(B,114, u_int)
#define BIOCGRSIG _IOR(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 BIOCSRSIG _IOW('B',114, u_int)
#define BIOCGRSIG _IOR('B',115, u_int)
#endif
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: bpfdesc.h,v 1.10 1995/03/26 20:30:09 jtc Exp $ */
/* $NetBSD: bpfdesc.h,v 1.11 1995/09/27 18:30:42 thorpej Exp $ */
/*
* Copyright (c) 1990, 1991, 1993
@ -73,6 +73,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;