Now that Netgraph is in the system there are some cleanups we can do.
Also save a slightly closer to completion version of the PPPOE code. Submitted by: Archie Cobbs <archie@freebsd.org>
This commit is contained in:
parent
c2d68eb829
commit
4376a3e634
@ -42,14 +42,16 @@
|
||||
.Nm ng_tty
|
||||
.Nd netgraph node type that is also a line discipline
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <sys/ttycom.h>
|
||||
.Fd #include <netgraph/ng_message.h>
|
||||
.Fd #include <netgraph/ng_tty.h>
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm tty
|
||||
node type is both a netgraph node type and a line discipline.
|
||||
A new node is created when the corresponding line discipline is
|
||||
registered on a tty device (see
|
||||
A new node is created when the corresponding line discipline,
|
||||
.Dv NETGRAPHDISC ,
|
||||
is registered on a tty device (see
|
||||
.Xr tty 4 ")."
|
||||
.Pp
|
||||
The node has a single hook called
|
||||
@ -112,18 +114,6 @@ The
|
||||
control message is not valid, and always returns the error
|
||||
.Er EOPNOTSUPP .
|
||||
.Sh BUGS
|
||||
The
|
||||
.Nm tty
|
||||
type registers its line discipline when the type is installed,
|
||||
where it is dynamically assigned an integer index.
|
||||
Unfortunately, there's no way to know what this integer is
|
||||
except by reading the output of
|
||||
.Xr dmesg 8 .
|
||||
The fix for this is to have line disciplines identified by
|
||||
unique ASCII strings instead of fixed integer constants,
|
||||
or else to assign one of those constants to
|
||||
.Nm ng_tty .
|
||||
.Pp
|
||||
The serial driver code also has a notion of a ``hot character.''
|
||||
Unfortunately, this value is statically defined in terms of the
|
||||
line discipline and cannot be changed.
|
||||
|
@ -158,7 +158,7 @@ This node shuts down upon receipt of a
|
||||
.Dv NGM_SHUTDOWN
|
||||
control message, or when all hooks have been disconnected.
|
||||
.Sh BUGS
|
||||
This node type requires that the file
|
||||
When used as a loadable kernel module, this node type requires that the file
|
||||
.Dv "net/slcompress.c"
|
||||
was compiled into the kernel. Currently the only way to insure this
|
||||
is to include the
|
||||
|
@ -165,7 +165,7 @@ The available line disciplines are listed in
|
||||
.Pa Aq sys/ttycom.h
|
||||
and currently are:
|
||||
.Pp
|
||||
.Bl -tag -width TIOCGWINSZ -compact
|
||||
.Bl -tag -width NETGRAPHDISC -compact
|
||||
.It TTYDISC
|
||||
Termios interactive line discipline.
|
||||
.It TABLDISC
|
||||
@ -174,6 +174,10 @@ Tablet line discipline.
|
||||
Serial IP line discipline.
|
||||
.It PPPDISC
|
||||
PPP line discipline.
|
||||
.It NETGRAPHDISC
|
||||
Netgraph
|
||||
.Xr ng_tty 8
|
||||
line discipline.
|
||||
.El
|
||||
.Pp
|
||||
.It Dv TIOCGETD Fa int *ldisc
|
||||
@ -394,4 +398,5 @@ is cleared in the terminal.
|
||||
.Xr ioctl 2 ,
|
||||
.Xr pty 4 ,
|
||||
.Xr termios 4 ,
|
||||
.Xr ng_tty 8 ,
|
||||
.Xr getty 8
|
||||
|
@ -404,6 +404,7 @@ options NETGRAPH_RFC1490
|
||||
options NETGRAPH_TEE
|
||||
options NETGRAPH_TTY
|
||||
options NETGRAPH_UI
|
||||
options NETGRAPH_VJC
|
||||
|
||||
#
|
||||
# Network interfaces:
|
||||
|
@ -576,6 +576,8 @@ netgraph/ng_socket.c optional netgraph_socket
|
||||
netgraph/ng_tee.c optional netgraph_tee
|
||||
netgraph/ng_tty.c optional netgraph_tty
|
||||
netgraph/ng_UI.c optional netgraph_UI
|
||||
netgraph/ng_vjc.c optional netgraph_vjc
|
||||
net/slcompress.c optional netgraph_vjc
|
||||
netinet/if_atm.c optional atm
|
||||
netinet/if_ether.c optional ether
|
||||
netinet/igmp.c optional inet
|
||||
|
@ -404,6 +404,7 @@ options NETGRAPH_RFC1490
|
||||
options NETGRAPH_TEE
|
||||
options NETGRAPH_TTY
|
||||
options NETGRAPH_UI
|
||||
options NETGRAPH_VJC
|
||||
|
||||
#
|
||||
# Network interfaces:
|
||||
|
@ -404,6 +404,7 @@ options NETGRAPH_RFC1490
|
||||
options NETGRAPH_TEE
|
||||
options NETGRAPH_TTY
|
||||
options NETGRAPH_UI
|
||||
options NETGRAPH_VJC
|
||||
|
||||
#
|
||||
# Network interfaces:
|
||||
|
@ -47,7 +47,7 @@
|
||||
#include <sys/conf.h>
|
||||
|
||||
#ifndef MAXLDISC
|
||||
#define MAXLDISC 8
|
||||
#define MAXLDISC 9
|
||||
#endif
|
||||
|
||||
static l_open_t l_noopen;
|
||||
@ -82,15 +82,16 @@ struct linesw linesw[MAXLDISC] =
|
||||
NODISC(3), /* TABLDISC */
|
||||
NODISC(4), /* SLIPDISC */
|
||||
NODISC(5), /* PPPDISC */
|
||||
NODISC(6), /* loadable */
|
||||
NODISC(6), /* NETGRAPHDISC */
|
||||
NODISC(7), /* loadable */
|
||||
NODISC(8), /* loadable */
|
||||
};
|
||||
|
||||
int nlinesw = sizeof (linesw) / sizeof (linesw[0]);
|
||||
|
||||
static struct linesw nodisc = NODISC(0);
|
||||
|
||||
#define LOADABLE_LDISC 6
|
||||
#define LOADABLE_LDISC 7
|
||||
/*
|
||||
* ldisc_register: Register a line discipline.
|
||||
*
|
||||
@ -125,7 +126,7 @@ ldisc_register(discipline, linesw_p)
|
||||
|
||||
/*
|
||||
* ldisc_deregister: Deregister a line discipline obtained with
|
||||
* ldisc_register. Can only deregister "loadable" ones now.
|
||||
* ldisc_register.
|
||||
*
|
||||
* discipline: Index for discipline to unload.
|
||||
*/
|
||||
@ -133,7 +134,7 @@ void
|
||||
ldisc_deregister(discipline)
|
||||
int discipline;
|
||||
{
|
||||
if (discipline >= LOADABLE_LDISC && discipline < MAXLDISC) {
|
||||
if (discipline < MAXLDISC) {
|
||||
linesw[discipline] = nodisc;
|
||||
}
|
||||
}
|
||||
|
@ -42,14 +42,16 @@
|
||||
.Nm ng_tty
|
||||
.Nd netgraph node type that is also a line discipline
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <sys/ttycom.h>
|
||||
.Fd #include <netgraph/ng_message.h>
|
||||
.Fd #include <netgraph/ng_tty.h>
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm tty
|
||||
node type is both a netgraph node type and a line discipline.
|
||||
A new node is created when the corresponding line discipline is
|
||||
registered on a tty device (see
|
||||
A new node is created when the corresponding line discipline,
|
||||
.Dv NETGRAPHDISC ,
|
||||
is registered on a tty device (see
|
||||
.Xr tty 4 ")."
|
||||
.Pp
|
||||
The node has a single hook called
|
||||
@ -112,18 +114,6 @@ The
|
||||
control message is not valid, and always returns the error
|
||||
.Er EOPNOTSUPP .
|
||||
.Sh BUGS
|
||||
The
|
||||
.Nm tty
|
||||
type registers its line discipline when the type is installed,
|
||||
where it is dynamically assigned an integer index.
|
||||
Unfortunately, there's no way to know what this integer is
|
||||
except by reading the output of
|
||||
.Xr dmesg 8 .
|
||||
The fix for this is to have line disciplines identified by
|
||||
unique ASCII strings instead of fixed integer constants,
|
||||
or else to assign one of those constants to
|
||||
.Nm ng_tty .
|
||||
.Pp
|
||||
The serial driver code also has a notion of a ``hot character.''
|
||||
Unfortunately, this value is statically defined in terms of the
|
||||
line discipline and cannot be changed.
|
||||
|
@ -42,14 +42,16 @@
|
||||
.Nm ng_tty
|
||||
.Nd netgraph node type that is also a line discipline
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <sys/ttycom.h>
|
||||
.Fd #include <netgraph/ng_message.h>
|
||||
.Fd #include <netgraph/ng_tty.h>
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm tty
|
||||
node type is both a netgraph node type and a line discipline.
|
||||
A new node is created when the corresponding line discipline is
|
||||
registered on a tty device (see
|
||||
A new node is created when the corresponding line discipline,
|
||||
.Dv NETGRAPHDISC ,
|
||||
is registered on a tty device (see
|
||||
.Xr tty 4 ")."
|
||||
.Pp
|
||||
The node has a single hook called
|
||||
@ -112,18 +114,6 @@ The
|
||||
control message is not valid, and always returns the error
|
||||
.Er EOPNOTSUPP .
|
||||
.Sh BUGS
|
||||
The
|
||||
.Nm tty
|
||||
type registers its line discipline when the type is installed,
|
||||
where it is dynamically assigned an integer index.
|
||||
Unfortunately, there's no way to know what this integer is
|
||||
except by reading the output of
|
||||
.Xr dmesg 8 .
|
||||
The fix for this is to have line disciplines identified by
|
||||
unique ASCII strings instead of fixed integer constants,
|
||||
or else to assign one of those constants to
|
||||
.Nm ng_tty .
|
||||
.Pp
|
||||
The serial driver code also has a notion of a ``hot character.''
|
||||
Unfortunately, this value is statically defined in terms of the
|
||||
line discipline and cannot be changed.
|
||||
|
@ -158,7 +158,7 @@ This node shuts down upon receipt of a
|
||||
.Dv NGM_SHUTDOWN
|
||||
control message, or when all hooks have been disconnected.
|
||||
.Sh BUGS
|
||||
This node type requires that the file
|
||||
When used as a loadable kernel module, this node type requires that the file
|
||||
.Dv "net/slcompress.c"
|
||||
was compiled into the kernel. Currently the only way to insure this
|
||||
is to include the
|
||||
|
@ -158,7 +158,7 @@ This node shuts down upon receipt of a
|
||||
.Dv NGM_SHUTDOWN
|
||||
control message, or when all hooks have been disconnected.
|
||||
.Sh BUGS
|
||||
This node type requires that the file
|
||||
When used as a loadable kernel module, this node type requires that the file
|
||||
.Dv "net/slcompress.c"
|
||||
was compiled into the kernel. Currently the only way to insure this
|
||||
is to include the
|
||||
|
@ -174,6 +174,7 @@ static void pppoe_start(sessp sp);
|
||||
static void sendpacket(sessp sp);
|
||||
static void pppoe_ticker(void *arg);
|
||||
static struct pppoe_tag* scan_tags(sessp sp, struct pppoe_hdr* ph);
|
||||
static int pppoe_send_event(sessp sp, enum cmd cmdid);
|
||||
|
||||
/*************************************************************************
|
||||
* Some basic utilities from the Linux version with author's permission.*
|
||||
@ -923,6 +924,7 @@ ng_PPPoE_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
|
||||
make_packet(sp);
|
||||
sp->state = PPPOE_NEWCONNECTED;
|
||||
sendpacket(sp);
|
||||
pppoe_send_event(sp, NGM_PPPOE_SUCCESS);
|
||||
/*
|
||||
* Having sent the last Negotiation header,
|
||||
* Set up the stored packet header to
|
||||
@ -936,6 +938,7 @@ ng_PPPoE_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
|
||||
sp->pkt_hdr.eh.ether_type
|
||||
= ETHERTYPE_PPPOE_SESS;
|
||||
sp->pkt_hdr.ph.code = 0;
|
||||
pppoe_send_event(sp, NGM_PPPOE_SUCCESS);
|
||||
break;
|
||||
case PADS_CODE:
|
||||
/*
|
||||
@ -986,6 +989,7 @@ ng_PPPoE_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
|
||||
m_freem(neg->m);
|
||||
FREE(sp->neg, M_NETGRAPH);
|
||||
sp->neg = NULL;
|
||||
pppoe_send_event(sp, NGM_PPPOE_SUCCESS);
|
||||
break;
|
||||
case PADT_CODE:
|
||||
/*
|
||||
@ -1002,7 +1006,9 @@ ng_PPPoE_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
|
||||
}
|
||||
/* send message to creator */
|
||||
/* close hook */
|
||||
ng_destroy_hook(sendhook);
|
||||
if (sendhook) {
|
||||
ng_destroy_hook(sendhook);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LEAVE(EPFNOSUPPORT);
|
||||
@ -1189,6 +1195,9 @@ ng_PPPoE_disconnect(hook_p hook)
|
||||
privp->ethernet_hook = NULL;
|
||||
} else {
|
||||
sp = hook->private;
|
||||
if (sp->state != PPPOE_SNONE ) {
|
||||
pppoe_send_event(sp, NGM_PPPOE_CLOSE);
|
||||
}
|
||||
untimeout(pppoe_ticker, hook, sp->neg->timeout_handle);
|
||||
FREE(sp, M_NETGRAPH);
|
||||
}
|
||||
@ -1228,6 +1237,7 @@ pppoe_ticker(void *arg)
|
||||
if ((neg->timeout <<= 1) > PPPOE_TIMEOUT_LIMIT) {
|
||||
if (sp->state == PPPOE_SREQ) {
|
||||
/* revert to SINIT mode */
|
||||
pppoe_start(sp);
|
||||
} else {
|
||||
neg->timeout = PPPOE_TIMEOUT_LIMIT;
|
||||
}
|
||||
@ -1236,7 +1246,6 @@ pppoe_ticker(void *arg)
|
||||
case PPPOE_PRIMED:
|
||||
case PPPOE_SOFFER:
|
||||
/* a timeout on these says "give up" */
|
||||
/* XXX should notify creator */
|
||||
ng_destroy_hook(hook);
|
||||
break;
|
||||
default:
|
||||
@ -1341,3 +1350,17 @@ scan_tags(sessp sp, struct pppoe_hdr* ph)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
pppoe_send_event(sessp sp, enum cmd cmdid)
|
||||
{
|
||||
int error;
|
||||
struct ng_mesg *msg;
|
||||
struct ngPPPoE_sts *sts;
|
||||
|
||||
NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, cmdid,
|
||||
sizeof(struct ngPPPoE_sts), M_NOWAIT);
|
||||
sts = (struct ngPPPoE_sts *)msg->data;
|
||||
strncpy(sts->hook, sp->hook->name, NG_HOOKLEN + 1);
|
||||
error = ng_send_msg(sp->hook->node, msg, sp->creator, NULL);
|
||||
return (error);
|
||||
}
|
||||
|
@ -66,7 +66,7 @@
|
||||
* Netgraph commands understood by this node type.
|
||||
* FAIL, SUCCESS and CLOSE are sent by the node rather than received.
|
||||
********************************************************************/
|
||||
enum {
|
||||
enum cmd {
|
||||
NGM_PPPOE_SET_FLAG = 1,
|
||||
NGM_PPPOE_CONNECT = 2, /* Client, Try find this service */
|
||||
NGM_PPPOE_LISTEN = 3, /* Server, Await a request for this service */
|
||||
@ -115,7 +115,7 @@ struct ngPPPoE_init_data {
|
||||
* (to report which hook has failed or connected). The message is sent
|
||||
* to whoever requested the connection. (close may use this too).
|
||||
*/
|
||||
struct ngPPPoE_req {
|
||||
struct ngPPPoE_sts {
|
||||
char hook[NG_HOOKLEN + 1]; /* hook associated with event session */
|
||||
};
|
||||
|
||||
|
@ -69,6 +69,7 @@
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/tty.h>
|
||||
#include <sys/ttycom.h>
|
||||
#include <sys/syslog.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/ioccom.h>
|
||||
@ -158,7 +159,6 @@ static struct linesw ngt_disc = {
|
||||
ttymodem,
|
||||
NG_TTY_DFL_HOTCHAR /* XXX can't change this in serial driver */
|
||||
};
|
||||
static int ngt_ldisc = -1;
|
||||
|
||||
/* Netgraph node type descriptor */
|
||||
static struct ng_type typestruct = {
|
||||
@ -203,7 +203,7 @@ ngt_open(dev_t dev, struct tty *tp)
|
||||
(void) spltty(); /* XXX is this necessary? */
|
||||
|
||||
/* Already installed? */
|
||||
if (tp->t_line == ngt_ldisc) {
|
||||
if (tp->t_line == NETGRAPHDISC) {
|
||||
sc = (sc_p) tp->t_sc;
|
||||
if (sc != NULL && sc->tp == tp)
|
||||
goto done;
|
||||
@ -676,17 +676,13 @@ ngt_mod_event(module_t mod, int event, void *data)
|
||||
|
||||
/* Register line discipline */
|
||||
s = spltty();
|
||||
if ((ngt_ldisc = ldisc_register(LDISC_LOAD, &ngt_disc)) < 0) {
|
||||
if ((ngt_ldisc = ldisc_register(NETGRAPHDISC, &ngt_disc)) < 0) {
|
||||
splx(s);
|
||||
log(LOG_ERR, "%s: can't register line discipline",
|
||||
__FUNCTION__);
|
||||
return (EIO);
|
||||
}
|
||||
splx(s);
|
||||
|
||||
/* OK */
|
||||
log(LOG_INFO, "line discipline #%d registered to"
|
||||
" netgraph node type \"%s\"\n", ngt_ldisc, type->name);
|
||||
break;
|
||||
|
||||
case MOD_UNLOAD:
|
||||
|
@ -135,5 +135,6 @@ struct winsize {
|
||||
#define TABLDISC 3 /* tablet discipline */
|
||||
#define SLIPDISC 4 /* serial IP discipline */
|
||||
#define PPPDISC 5 /* PPP discipline */
|
||||
#define NETGRAPHDISC 6 /* Netgraph tty node discipline */
|
||||
|
||||
#endif /* !_SYS_TTYCOM_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user