mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-27 05:21:08 +01:00
Tunnel driver is nmow capable of installing its own cdevsw[] entry,
with a little help from conf.c. While e're at it, actually declare the tunnel entry points to have the correct types. This fixes PR #306.
This commit is contained in:
parent
8d89e37c73
commit
1f3d84e82a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=7747
@ -33,6 +33,7 @@
|
|||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
#include <sys/kernel.h>
|
#include <sys/kernel.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <sys/conf.h>
|
||||||
|
|
||||||
#include <machine/cpu.h>
|
#include <machine/cpu.h>
|
||||||
|
|
||||||
@ -67,26 +68,37 @@ int tundebug = 0;
|
|||||||
struct tun_softc tunctl[NTUN];
|
struct tun_softc tunctl[NTUN];
|
||||||
extern int ifqmaxlen;
|
extern int ifqmaxlen;
|
||||||
|
|
||||||
int tunopen __P((dev_t, int, int, struct proc *));
|
d_open_t tunopen;
|
||||||
int tunclose __P((dev_t, int));
|
d_close_t tunclose;
|
||||||
int tunoutput __P((struct ifnet *, struct mbuf *, struct sockaddr *,
|
int tunoutput __P((struct ifnet *, struct mbuf *, struct sockaddr *,
|
||||||
struct rtentry *rt));
|
struct rtentry *rt));
|
||||||
int tunread __P((dev_t, struct uio *));
|
d_rdwr_t tunread;
|
||||||
int tunwrite __P((dev_t, struct uio *));
|
d_rdwr_t tunwrite;
|
||||||
int tunioctl __P((dev_t, int, caddr_t, int, struct proc *));
|
d_ioctl_t tunioctl;
|
||||||
int tunifioctl __P((struct ifnet *, int, caddr_t));
|
int tunifioctl __P((struct ifnet *, int, caddr_t));
|
||||||
int tunselect __P((dev_t, int));
|
d_select_t tunselect;
|
||||||
void tunattach __P((void));
|
void tunattach __P((void));
|
||||||
|
|
||||||
|
static struct cdevsw tuncdevsw =
|
||||||
|
{ tunopen, tunclose, tunread, tunwrite,
|
||||||
|
tunioctl, (d_stop_t *)enodev, (d_reset_t *)nullop, (d_ttycv_t *)enodev,
|
||||||
|
tunselect, (d_mmap_t *)enodev, NULL };
|
||||||
|
extern dev_t tuncdev;
|
||||||
|
|
||||||
static int tuninit __P((int));
|
static int tuninit __P((int));
|
||||||
|
|
||||||
void
|
void
|
||||||
tunattach()
|
tunattach(void)
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
struct ifnet *ifp;
|
struct ifnet *ifp;
|
||||||
struct sockaddr_in *sin;
|
struct sockaddr_in *sin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In case we are an LKM, set up device switch.
|
||||||
|
*/
|
||||||
|
cdevsw[major(tuncdev)] = tuncdevsw;
|
||||||
|
|
||||||
for (i = 0; i < NTUN; i++) {
|
for (i = 0; i < NTUN; i++) {
|
||||||
tunctl[i].tun_flags = TUN_INITED;
|
tunctl[i].tun_flags = TUN_INITED;
|
||||||
|
|
||||||
@ -147,9 +159,7 @@ tunopen(dev, flag, mode, p)
|
|||||||
* routing info
|
* routing info
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
tunclose(dev, flag)
|
tunclose(dev_t dev, int foo, int bar, struct proc *p)
|
||||||
dev_t dev;
|
|
||||||
int flag;
|
|
||||||
{
|
{
|
||||||
register int unit = minor(dev), s;
|
register int unit = minor(dev), s;
|
||||||
struct tun_softc *tp = &tunctl[unit];
|
struct tun_softc *tp = &tunctl[unit];
|
||||||
@ -399,9 +409,7 @@ tunioctl(dev, cmd, data, flag, p)
|
|||||||
* least as much of a packet as can be read.
|
* least as much of a packet as can be read.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
tunread(dev, uio)
|
tunread(dev_t dev, struct uio *uio, int flag)
|
||||||
dev_t dev;
|
|
||||||
struct uio *uio;
|
|
||||||
{
|
{
|
||||||
int unit = minor(dev);
|
int unit = minor(dev);
|
||||||
struct tun_softc *tp = &tunctl[unit];
|
struct tun_softc *tp = &tunctl[unit];
|
||||||
@ -452,9 +460,7 @@ tunread(dev, uio)
|
|||||||
* the cdevsw write interface - an atomic write is a packet - or else!
|
* the cdevsw write interface - an atomic write is a packet - or else!
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
tunwrite(dev, uio)
|
tunwrite(dev_t dev, struct uio *uio, int flag)
|
||||||
dev_t dev;
|
|
||||||
struct uio *uio;
|
|
||||||
{
|
{
|
||||||
int unit = minor (dev);
|
int unit = minor (dev);
|
||||||
struct ifnet *ifp = &tunctl[unit].tun_if;
|
struct ifnet *ifp = &tunctl[unit].tun_if;
|
||||||
@ -542,9 +548,7 @@ tunwrite(dev, uio)
|
|||||||
* anyway, it either accepts the packet or drops it.
|
* anyway, it either accepts the packet or drops it.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
tunselect(dev, rw)
|
tunselect(dev_t dev, int rw, struct proc *p)
|
||||||
dev_t dev;
|
|
||||||
int rw;
|
|
||||||
{
|
{
|
||||||
int unit = minor(dev), s;
|
int unit = minor(dev), s;
|
||||||
struct tun_softc *tp = &tunctl[unit];
|
struct tun_softc *tp = &tunctl[unit];
|
||||||
@ -561,7 +565,7 @@ tunselect(dev, rw)
|
|||||||
ifp->if_unit, ifp->if_snd.ifq_len);
|
ifp->if_unit, ifp->if_snd.ifq_len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
selrecord(curproc, &tp->tun_rsel);
|
selrecord(p, &tp->tun_rsel);
|
||||||
break;
|
break;
|
||||||
case FWRITE:
|
case FWRITE:
|
||||||
splx(s);
|
splx(s);
|
||||||
|
Loading…
Reference in New Issue
Block a user