clonify strip and sl.

This commit is contained in:
christos 2004-12-05 05:43:04 +00:00
parent 7a05522334
commit f08ea58021
5 changed files with 119 additions and 77 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files,v 1.701 2004/12/04 16:10:25 peter Exp $
# $NetBSD: files,v 1.702 2004/12/05 05:43:04 christos Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@ -1298,11 +1298,11 @@ file net/if_hippisubr.c hippi needs-flag
file net/if_ieee1394subr.c ieee1394
file net/if_loop.c loop needs-flag
file net/if_media.c
file net/if_ppp.c ppp needs-count
file net/if_ppp.c ppp needs-flag
file net/if_stf.c stf & inet & inet6 needs-flag
file net/if_sl.c sl needs-count
file net/if_sl.c sl needs-flag
file net/if_spppsubr.c sppp
file net/if_strip.c strip needs-count
file net/if_strip.c strip needs-flag
file net/if_tokensubr.c token needs-flag
file net/if_tun.c tun needs-flag
file net/if_vlan.c vlan needs-flag

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_sl.c,v 1.86 2004/08/19 20:58:24 christos Exp $ */
/* $NetBSD: if_sl.c,v 1.87 2004/12/05 05:43:04 christos Exp $ */
/*
* Copyright (c) 1987, 1989, 1992, 1993
@ -60,10 +60,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.86 2004/08/19 20:58:24 christos Exp $");
#include "sl.h"
#if NSL > 0
__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.87 2004/12/05 05:43:04 christos Exp $");
#include "opt_inet.h"
#include "bpfilter.h"
@ -176,7 +173,13 @@ __KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.86 2004/08/19 20:58:24 christos Exp $");
#define ABT_COUNT 3 /* count of escapes for abort */
#define ABT_WINDOW (ABT_COUNT*2+2) /* in seconds - time to count */
struct sl_softc sl_softc[NSL];
static int sl_clone_create(struct if_clone *, int);
static int sl_clone_destroy(struct ifnet *);
static LIST_HEAD(, sl_softc) sl_softc_list;
struct if_clone sl_cloner =
IF_CLONE_INITIALIZER("sl", sl_clone_create, sl_clone_destroy);
#define FRAME_END 0xc0 /* Frame End */
#define FRAME_ESCAPE 0xdb /* Frame Esc */
@ -191,35 +194,55 @@ void slintr(void *);
static int slinit __P((struct sl_softc *));
static struct mbuf *sl_btom __P((struct sl_softc *, int));
/*
* Called from boot code to establish sl interfaces.
*/
void
slattach()
slattach(void)
{
LIST_INIT(&sl_softc_list);
if_clone_attach(&sl_cloner);
}
int
sl_clone_create(struct if_clone *ifc, int unit)
{
struct sl_softc *sc;
int i = 0;
for (sc = sl_softc; i < NSL; sc++) {
sc->sc_unit = i; /* XXX */
snprintf(sc->sc_if.if_xname, sizeof(sc->sc_if.if_xname),
"sl%d", i++);
sc->sc_if.if_softc = sc;
sc->sc_if.if_mtu = SLMTU;
sc->sc_if.if_flags =
IFF_POINTOPOINT | SC_AUTOCOMP | IFF_MULTICAST;
sc->sc_if.if_type = IFT_SLIP;
sc->sc_if.if_ioctl = slioctl;
sc->sc_if.if_output = sloutput;
sc->sc_if.if_dlt = DLT_SLIP;
sc->sc_fastq.ifq_maxlen = 32;
IFQ_SET_READY(&sc->sc_if.if_snd);
if_attach(&sc->sc_if);
if_alloc_sadl(&sc->sc_if);
MALLOC(sc, struct sl_softc *, sizeof(*sc), M_DEVBUF, M_WAIT|M_ZERO);
sc->sc_unit = unit;
(void)snprintf(sc->sc_if.if_xname, sizeof(sc->sc_if.if_xname),
"%s%d", ifc->ifc_name, unit);
sc->sc_if.if_softc = sc;
sc->sc_if.if_mtu = SLMTU;
sc->sc_if.if_flags =
IFF_POINTOPOINT | SC_AUTOCOMP | IFF_MULTICAST;
sc->sc_if.if_type = IFT_SLIP;
sc->sc_if.if_ioctl = slioctl;
sc->sc_if.if_output = sloutput;
sc->sc_if.if_dlt = DLT_SLIP;
sc->sc_fastq.ifq_maxlen = 32;
IFQ_SET_READY(&sc->sc_if.if_snd);
if_attach(&sc->sc_if);
if_alloc_sadl(&sc->sc_if);
#if NBPFILTER > 0
bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
#endif
}
LIST_INSERT_HEAD(&sl_softc_list, sc, sc_iflist);
return 0;
}
static int
sl_clone_destroy(struct ifnet *ifp)
{
struct sl_softc *sc = (struct sl_softc *)ifp->if_softc;
if (sc->sc_ttyp != NULL)
return EBUSY; /* Not removing it */
LIST_REMOVE(sc, sc_iflist);
if_detach(ifp);
FREE(sc, M_DEVBUF);
return 0;
}
static int
@ -253,7 +276,6 @@ slopen(dev, tp)
{
struct proc *p = curproc; /* XXX */
struct sl_softc *sc;
int nsl;
int error;
int s;
@ -263,7 +285,7 @@ slopen(dev, tp)
if (tp->t_linesw->l_no == SLIPDISC)
return (0);
for (nsl = NSL, sc = sl_softc; --nsl >= 0; sc++)
LIST_FOREACH(sc, &sl_softc_list, sc_iflist)
if (sc->sc_ttyp == NULL) {
#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
sc->sc_si = softintr_establish(IPL_SOFTNET,
@ -675,9 +697,8 @@ void
slnetisr(void)
{
struct sl_softc *sc;
int i;
for (i = 0; i < NSL; i++) {
LIST_FOREACH(sc, &sl_softc_list, sc_iflist)
sc = &sl_softc[i];
if (sc->sc_ttyp == NULL)
continue;
@ -1033,4 +1054,3 @@ slioctl(ifp, cmd, data)
splx(s);
return (error);
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_slvar.h,v 1.25 2003/08/07 16:32:54 agc Exp $ */
/* $NetBSD: if_slvar.h,v 1.26 2004/12/05 05:43:04 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -68,6 +68,7 @@ struct sl_softc {
struct slcompress sc_comp; /* tcp compression data */
#endif
struct timeval sc_lastpacket; /* for watchdog */
LIST_ENTRY(sl_softc) sc_iflist;
};
/* internal flags */

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_strip.c,v 1.53 2004/08/19 20:58:24 christos Exp $ */
/* $NetBSD: if_strip.c,v 1.54 2004/12/05 05:43:04 christos Exp $ */
/* from: NetBSD: if_sl.c,v 1.38 1996/02/13 22:00:23 christos Exp $ */
/*
@ -87,9 +87,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_strip.c,v 1.53 2004/08/19 20:58:24 christos Exp $");
#include "strip.h"
__KERNEL_RCSID(0, "$NetBSD: if_strip.c,v 1.54 2004/12/05 05:43:04 christos Exp $");
#include "opt_inet.h"
#include "bpfilter.h"
@ -214,7 +212,13 @@ typedef char ttychar_t;
#define ABT_COUNT 3 /* count of escapes for abort */
#define ABT_WINDOW (ABT_COUNT*2+2) /* in seconds - time to count */
struct strip_softc strip_softc[NSTRIP];
static int strip_clone_create(struct if_clone *, int);
static int strip_clone_destroy(struct ifnet *);
static LIST_HEAD(, strip_softc) strip_softc_list;
struct if_clone strip_cloner =
IF_CLONE_INITIALIZER("strip", strip_clone_create, strip_clone_destroy);
#define STRIP_FRAME_END 0x0D /* carriage return */
@ -330,42 +334,60 @@ void strip_timeout __P((void *x));
/*
* Called from boot code to establish sl interfaces.
*/
void
stripattach(n)
int n;
stripattach(void)
{
LIST_INIT(&strip_softc_list);
if_clone_attach(&strip_cloner);
}
int
strip_clone_create(struct if_clone *ifc, int unit)
{
struct strip_softc *sc;
int i = 0;
for (sc = strip_softc; i < NSTRIP; sc++) {
sc->sc_unit = i; /* XXX */
snprintf(sc->sc_if.if_xname, sizeof(sc->sc_if.if_xname),
"strip%d", i++);
callout_init(&sc->sc_timo_ch);
sc->sc_if.if_softc = sc;
sc->sc_if.if_mtu = SLMTU;
sc->sc_if.if_flags = 0;
sc->sc_if.if_type = IFT_OTHER;
MALLOC(sc, struct sl_softc *, sizeof(*sc), M_DEVBUF, M_WAIT|M_ZERO);
sc->sc_unit = unit;
(void)snprintf(sc->sc_if.if_xname, sizeof(sc->sc_if.if_xname),
"%s%d", ifc->ifc_name, i++);
callout_init(&sc->sc_timo_ch);
sc->sc_if.if_softc = sc;
sc->sc_if.if_mtu = SLMTU;
sc->sc_if.if_flags = 0;
sc->sc_if.if_type = IFT_OTHER;
#if 0
sc->sc_if.if_flags |= SC_AUTOCOMP /* | IFF_POINTOPOINT | IFF_MULTICAST*/;
sc->sc_if.if_flags |= SC_AUTOCOMP /* | IFF_POINTOPOINT | IFF_MULTICAST*/;
#endif
sc->sc_if.if_type = IFT_SLIP;
sc->sc_if.if_ioctl = stripioctl;
sc->sc_if.if_output = stripoutput;
sc->sc_if.if_dlt = DLT_SLIP;
sc->sc_fastq.ifq_maxlen = 32;
IFQ_SET_READY(&sc->sc_if.if_snd);
sc->sc_if.if_type = IFT_SLIP;
sc->sc_if.if_ioctl = stripioctl;
sc->sc_if.if_output = stripoutput;
sc->sc_if.if_dlt = DLT_SLIP;
sc->sc_fastq.ifq_maxlen = 32;
IFQ_SET_READY(&sc->sc_if.if_snd);
sc->sc_if.if_watchdog = strip_watchdog;
if_attach(&sc->sc_if);
if_alloc_sadl(&sc->sc_if);
sc->sc_if.if_watchdog = strip_watchdog;
if_attach(&sc->sc_if);
if_alloc_sadl(&sc->sc_if);
#if NBPFILTER > 0
bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
#endif
}
LIST_INSERT_HEAD(&strip_softc_list, sc, sc_iflist);
}
static int
strip_clone_destroy(struct ifnet *ifp)
{
struct strip_softc *sc = (struct strip_softc *)ifp->if_softc;
if (sc->sc_ttyp != NULL)
return EBUSY; /* Not removing it */
LIST_REMOVE(sc, sc_iflist);
if_detach(ifp);
FREE(sc, M_DEVBUF);
return 0;
}
static int
@ -443,7 +465,7 @@ stripopen(dev, tp)
if (tp->t_linesw->l_no == STRIPDISC)
return (0);
for (nstrip = NSTRIP, sc = strip_softc; --nstrip >= 0; sc++) {
LIST_FOREACH(sc, &strip_softc_list, sc_iflist) {
if (sc->sc_ttyp == NULL) {
#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
sc->sc_si = softintr_establish(IPL_SOFTNET,
@ -1065,10 +1087,8 @@ void
stripnetisr(void)
{
struct strip_softc *sc;
int i;
for (i = 0; i < NSTRIP; i++) {
sc = &strip_softc[i];
LIST_FOREACH(sc, &strip_softc_list, sc_iflist) {
if (sc->sc_ttyp == NULL)
continue;
stripintr(sc);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_stripvar.h,v 1.12 2001/06/14 05:44:25 itojun Exp $ */
/* $NetBSD: if_stripvar.h,v 1.13 2004/12/05 05:43:04 christos Exp $ */
#ifndef _NET_IF_STRIPVAR_H_
#define _NET_IF_STRIPVAR_H_
@ -41,6 +41,7 @@ struct strip_softc {
long sc_statetimo; /* When (secs) current state ends */
struct timeval sc_lastpacket; /* for watchdog */
LIST_ENTRY(strip_softc) sc_iflist;
};
@ -55,7 +56,7 @@ struct strip_softc {
#define SC_AUTOCOMP IFF_LINK2 /* auto-enable TCP compression */
#ifdef _KERNEL
void stripattach __P((int n));
void stripattach __P((void));
void stripclose __P((struct tty *));
void stripinput __P((int, struct tty *));
int stripioctl __P((struct ifnet *, u_long, caddr_t));