1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* ng_tty.c
|
2005-01-07 01:45:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
1999-10-21 09:06:11 +00:00
|
|
|
* Copyright (c) 1996-1999 Whistle Communications, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Subject to the following obligations and disclaimer of warranty, use and
|
|
|
|
* redistribution of this software, in source or object code forms, with or
|
|
|
|
* without modifications are expressly permitted by Whistle Communications;
|
|
|
|
* provided, however, that:
|
|
|
|
* 1. Any and all reproductions of the source or object code must include the
|
|
|
|
* copyright notice above and the following disclaimer of warranties; and
|
|
|
|
* 2. No rights are granted, in any manner or form, to use Whistle
|
|
|
|
* Communications, Inc. trademarks, including the mark "WHISTLE
|
|
|
|
* COMMUNICATIONS" on advertising, endorsements, or otherwise except as
|
|
|
|
* such appears in the above copyright notice or in the software.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
|
|
|
|
* TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
|
|
|
|
* REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
|
|
|
|
* INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
|
|
|
* WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
|
|
|
|
* REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
|
|
|
|
* SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
|
|
|
|
* IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
|
|
|
|
* RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
|
|
|
|
* WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
|
|
* PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
|
|
|
|
* OF SUCH DAMAGE.
|
|
|
|
*
|
2000-10-24 17:32:45 +00:00
|
|
|
* Author: Archie Cobbs <archie@freebsd.org>
|
1999-10-21 09:06:11 +00:00
|
|
|
*
|
2008-10-03 05:14:54 +00:00
|
|
|
* Updated by Andrew Thompson <thompsa@FreeBSD.org> for MPSAFE TTY.
|
|
|
|
*
|
1999-10-21 09:06:11 +00:00
|
|
|
* $FreeBSD$
|
1999-11-01 10:00:40 +00:00
|
|
|
* $Whistle: ng_tty.c,v 1.21 1999/11/01 09:24:52 julian Exp $
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2008-10-03 05:14:54 +00:00
|
|
|
* This file implements TTY hooks to link in to the netgraph system. The node
|
|
|
|
* is created and then passed the callers opened TTY file descriptor number to
|
|
|
|
* NGM_TTY_SET_TTY, this will hook the tty via ttyhook_register().
|
1999-10-21 09:06:11 +00:00
|
|
|
*
|
2008-10-03 05:14:54 +00:00
|
|
|
* Incoming data is delivered directly to ng_tty via the TTY bypass hook as a
|
|
|
|
* buffer pointer and length, this is converted to a mbuf and passed to the
|
|
|
|
* peer.
|
1999-10-21 09:06:11 +00:00
|
|
|
*
|
2008-10-03 05:14:54 +00:00
|
|
|
* If the TTY device does not support bypass then incoming characters are
|
|
|
|
* delivered to the hook one at a time, each in its own mbuf. You may
|
|
|
|
* optionally define a ``hotchar,'' which causes incoming characters to be
|
|
|
|
* buffered up until either the hotchar is seen or the mbuf is full (MHLEN
|
|
|
|
* bytes). Then all buffered characters are immediately delivered.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
#include <sys/errno.h>
|
1999-10-21 09:06:11 +00:00
|
|
|
#include <sys/fcntl.h>
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
1999-10-21 09:06:11 +00:00
|
|
|
#include <sys/tty.h>
|
1999-10-23 04:28:11 +00:00
|
|
|
#include <sys/ttycom.h>
|
2008-11-08 06:25:57 +00:00
|
|
|
#include <sys/proc.h>
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_var.h>
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
#include <netgraph/ng_message.h>
|
|
|
|
#include <netgraph/netgraph.h>
|
|
|
|
#include <netgraph/ng_tty.h>
|
|
|
|
|
|
|
|
/* Per-node private info */
|
2008-10-03 05:14:54 +00:00
|
|
|
struct ngt_softc {
|
|
|
|
struct tty *tp; /* Terminal device */
|
|
|
|
node_p node; /* Netgraph node */
|
|
|
|
hook_p hook; /* Netgraph hook */
|
|
|
|
struct ifqueue outq; /* Queue of outgoing data */
|
|
|
|
size_t outqlen; /* Number of bytes in outq */
|
|
|
|
struct mbuf *m; /* Incoming non-bypass data buffer */
|
|
|
|
short hotchar; /* Hotchar, or -1 if none */
|
|
|
|
u_int flags; /* Flags */
|
1999-10-21 09:06:11 +00:00
|
|
|
};
|
2008-10-03 05:14:54 +00:00
|
|
|
typedef struct ngt_softc *sc_p;
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/* Flags */
|
|
|
|
#define FLG_DEBUG 0x0002
|
|
|
|
|
|
|
|
/* Netgraph methods */
|
2008-10-03 05:14:54 +00:00
|
|
|
static ng_constructor_t ngt_constructor;
|
|
|
|
static ng_rcvmsg_t ngt_rcvmsg;
|
|
|
|
static ng_shutdown_t ngt_shutdown;
|
|
|
|
static ng_newhook_t ngt_newhook;
|
|
|
|
static ng_connect_t ngt_connect;
|
|
|
|
static ng_rcvdata_t ngt_rcvdata;
|
|
|
|
static ng_disconnect_t ngt_disconnect;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
#define ERROUT(x) do { error = (x); goto done; } while (0)
|
|
|
|
|
2008-10-03 05:14:54 +00:00
|
|
|
static th_getc_inject_t ngt_getc_inject;
|
|
|
|
static th_getc_poll_t ngt_getc_poll;
|
|
|
|
static th_rint_t ngt_rint;
|
|
|
|
static th_rint_bypass_t ngt_rint_bypass;
|
|
|
|
static th_rint_poll_t ngt_rint_poll;
|
|
|
|
|
|
|
|
static struct ttyhook ngt_hook = {
|
|
|
|
.th_getc_inject = ngt_getc_inject,
|
|
|
|
.th_getc_poll = ngt_getc_poll,
|
|
|
|
.th_rint = ngt_rint,
|
|
|
|
.th_rint_bypass = ngt_rint_bypass,
|
|
|
|
.th_rint_poll = ngt_rint_poll,
|
1999-10-21 09:06:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Netgraph node type descriptor */
|
|
|
|
static struct ng_type typestruct = {
|
2004-05-29 00:51:19 +00:00
|
|
|
.version = NG_ABI_VERSION,
|
|
|
|
.name = NG_TTY_NODE_TYPE,
|
|
|
|
.constructor = ngt_constructor,
|
|
|
|
.rcvmsg = ngt_rcvmsg,
|
|
|
|
.shutdown = ngt_shutdown,
|
|
|
|
.newhook = ngt_newhook,
|
|
|
|
.connect = ngt_connect,
|
|
|
|
.rcvdata = ngt_rcvdata,
|
|
|
|
.disconnect = ngt_disconnect,
|
1999-10-21 09:06:11 +00:00
|
|
|
};
|
|
|
|
NETGRAPH_INIT(tty, &typestruct);
|
|
|
|
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
#define NGTLOCK(sc) IF_LOCK(&sc->outq)
|
|
|
|
#define NGTUNLOCK(sc) IF_UNLOCK(&sc->outq)
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/******************************************************************
|
2008-10-03 05:14:54 +00:00
|
|
|
NETGRAPH NODE METHODS
|
1999-10-21 09:06:11 +00:00
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/*
|
2008-10-03 05:14:54 +00:00
|
|
|
* Initialize a new node of this type.
|
|
|
|
*
|
|
|
|
* We only allow nodes to be created as a result of setting
|
|
|
|
* the line discipline on a tty, so always return an error if not.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2008-10-03 05:14:54 +00:00
|
|
|
ngt_constructor(node_p node)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
|
|
|
sc_p sc;
|
|
|
|
|
2008-10-03 05:14:54 +00:00
|
|
|
/* Allocate private structure */
|
2011-04-18 09:12:27 +00:00
|
|
|
sc = malloc(sizeof(*sc), M_NETGRAPH, M_WAITOK | M_ZERO);
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
|
2008-10-03 05:14:54 +00:00
|
|
|
NG_NODE_SET_PRIVATE(node, sc);
|
|
|
|
sc->node = node;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2008-10-03 05:14:54 +00:00
|
|
|
mtx_init(&sc->outq.ifq_mtx, "ng_tty node+queue", NULL, MTX_DEF);
|
2010-05-03 07:32:50 +00:00
|
|
|
IFQ_SET_MAXLEN(&sc->outq, ifqmaxlen);
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
|
|
|
|
return (0);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new hook. There can only be one.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ngt_newhook(node_p node, hook_p hook, const char *name)
|
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const sc_p sc = NG_NODE_PRIVATE(node);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
if (strcmp(name, NG_TTY_HOOK))
|
|
|
|
return (EINVAL);
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
if (sc->hook)
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
return (EISCONN);
|
|
|
|
|
|
|
|
NGTLOCK(sc);
|
1999-10-21 09:06:11 +00:00
|
|
|
sc->hook = hook;
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
NGTUNLOCK(sc);
|
|
|
|
|
|
|
|
return (0);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
|
2000-12-12 18:52:14 +00:00
|
|
|
/*
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
* Set the hook into queueing mode (for outgoing packets),
|
|
|
|
* so that we wont deliver mbuf thru the whole graph holding
|
|
|
|
* tty locks.
|
2000-12-12 18:52:14 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ngt_connect(hook_p hook)
|
|
|
|
{
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
NG_HOOK_FORCE_QUEUE(hook);
|
2000-12-12 18:52:14 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* Disconnect the hook
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ngt_disconnect(hook_p hook)
|
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
if (hook != sc->hook)
|
2010-10-13 17:21:21 +00:00
|
|
|
panic("%s", __func__);
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
|
|
|
|
NGTLOCK(sc);
|
1999-10-21 09:06:11 +00:00
|
|
|
sc->hook = NULL;
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
NGTUNLOCK(sc);
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove this node. The does the netgraph portion of the shutdown.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ngt_shutdown(node_p node)
|
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const sc_p sc = NG_NODE_PRIVATE(node);
|
2008-10-03 05:14:54 +00:00
|
|
|
struct tty *tp;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2008-10-03 05:14:54 +00:00
|
|
|
tp = sc->tp;
|
|
|
|
if (tp != NULL) {
|
|
|
|
tty_lock(tp);
|
|
|
|
ttyhook_unregister(tp);
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
}
|
|
|
|
/* Free resources */
|
2008-10-03 05:14:54 +00:00
|
|
|
IF_DRAIN(&sc->outq);
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
mtx_destroy(&(sc)->outq.ifq_mtx);
|
|
|
|
NG_NODE_UNREF(sc->node);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(sc, M_NETGRAPH);
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive control message
|
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ngt_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2008-11-08 06:25:57 +00:00
|
|
|
struct proc *p;
|
2001-01-08 05:34:06 +00:00
|
|
|
const sc_p sc = NG_NODE_PRIVATE(node);
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
struct ng_mesg *msg, *resp = NULL;
|
1999-10-21 09:06:11 +00:00
|
|
|
int error = 0;
|
|
|
|
|
2001-01-06 00:46:47 +00:00
|
|
|
NGI_GET_MSG(item, msg);
|
1999-10-21 09:06:11 +00:00
|
|
|
switch (msg->header.typecookie) {
|
|
|
|
case NGM_TTY_COOKIE:
|
|
|
|
switch (msg->header.cmd) {
|
2008-10-03 05:14:54 +00:00
|
|
|
case NGM_TTY_SET_TTY:
|
|
|
|
if (sc->tp != NULL)
|
|
|
|
return (EBUSY);
|
2008-11-08 06:25:57 +00:00
|
|
|
|
|
|
|
p = pfind(((int *)msg->data)[0]);
|
2008-12-13 21:17:46 +00:00
|
|
|
if (p == NULL || (p->p_flag & P_WEXIT))
|
2008-11-08 06:25:57 +00:00
|
|
|
return (ESRCH);
|
2008-12-13 21:17:46 +00:00
|
|
|
_PHOLD(p);
|
2008-11-08 06:25:57 +00:00
|
|
|
PROC_UNLOCK(p);
|
2008-12-13 21:17:46 +00:00
|
|
|
error = ttyhook_register(&sc->tp, p, ((int *)msg->data)[1],
|
|
|
|
&ngt_hook, sc);
|
|
|
|
PRELE(p);
|
2008-10-03 05:14:54 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
break;
|
1999-10-21 09:06:11 +00:00
|
|
|
case NGM_TTY_SET_HOTCHAR:
|
|
|
|
{
|
|
|
|
int hotchar;
|
|
|
|
|
|
|
|
if (msg->header.arglen != sizeof(int))
|
|
|
|
ERROUT(EINVAL);
|
|
|
|
hotchar = *((int *) msg->data);
|
|
|
|
if (hotchar != (u_char) hotchar && hotchar != -1)
|
|
|
|
ERROUT(EINVAL);
|
|
|
|
sc->hotchar = hotchar; /* race condition is OK */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NGM_TTY_GET_HOTCHAR:
|
|
|
|
NG_MKRESPONSE(resp, msg, sizeof(int), M_NOWAIT);
|
|
|
|
if (!resp)
|
|
|
|
ERROUT(ENOMEM);
|
|
|
|
/* Race condition here is OK */
|
|
|
|
*((int *) resp->data) = sc->hotchar;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERROUT(EINVAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERROUT(EINVAL);
|
|
|
|
}
|
|
|
|
done:
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_RESPOND_MSG(error, node, item, resp);
|
|
|
|
NG_FREE_MSG(msg);
|
1999-10-21 09:06:11 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2008-10-03 05:14:54 +00:00
|
|
|
/*
|
|
|
|
* Receive incoming data from netgraph system. Put it on our
|
|
|
|
* output queue and start output if necessary.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ngt_rcvdata(hook_p hook, item_p item)
|
|
|
|
{
|
|
|
|
const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
|
|
|
|
struct tty *tp = sc->tp;
|
|
|
|
struct mbuf *m;
|
|
|
|
|
|
|
|
if (hook != sc->hook)
|
2010-10-13 17:21:21 +00:00
|
|
|
panic("%s", __func__);
|
2008-10-03 05:14:54 +00:00
|
|
|
|
|
|
|
NGI_GET_M(item, m);
|
|
|
|
NG_FREE_ITEM(item);
|
|
|
|
|
|
|
|
if (tp == NULL) {
|
|
|
|
NG_FREE_M(m);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
IF_LOCK(&sc->outq);
|
|
|
|
if (_IF_QFULL(&sc->outq)) {
|
|
|
|
_IF_DROP(&sc->outq);
|
|
|
|
IF_UNLOCK(&sc->outq);
|
|
|
|
NG_FREE_M(m);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
_IF_ENQUEUE(&sc->outq, m);
|
|
|
|
sc->outqlen += m->m_pkthdr.len;
|
|
|
|
IF_UNLOCK(&sc->outq);
|
|
|
|
|
|
|
|
/* notify the TTY that data is ready */
|
|
|
|
tty_lock(tp);
|
|
|
|
if (!tty_gone(tp))
|
|
|
|
ttydevsw_outwakeup(tp);
|
|
|
|
tty_unlock(tp);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
ngt_getc_inject(struct tty *tp, void *buf, size_t len)
|
|
|
|
{
|
|
|
|
sc_p sc = ttyhook_softc(tp);
|
|
|
|
size_t total = 0;
|
|
|
|
int length;
|
|
|
|
|
|
|
|
while (len) {
|
|
|
|
struct mbuf *m;
|
|
|
|
|
|
|
|
/* Remove first mbuf from queue */
|
|
|
|
IF_DEQUEUE(&sc->outq, m);
|
|
|
|
if (m == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Send as much of it as possible */
|
|
|
|
while (m != NULL) {
|
|
|
|
length = min(m->m_len, len);
|
|
|
|
memcpy((char *)buf + total, mtod(m, char *), length);
|
|
|
|
|
|
|
|
m->m_data += length;
|
|
|
|
m->m_len -= length;
|
|
|
|
total += length;
|
|
|
|
len -= length;
|
|
|
|
|
|
|
|
if (m->m_len > 0)
|
|
|
|
break; /* device can't take any more */
|
|
|
|
m = m_free(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put remainder of mbuf chain (if any) back on queue */
|
|
|
|
if (m != NULL) {
|
|
|
|
IF_PREPEND(&sc->outq, m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IF_LOCK(&sc->outq);
|
|
|
|
sc->outqlen -= total;
|
|
|
|
IF_UNLOCK(&sc->outq);
|
|
|
|
MPASS(sc->outqlen >= 0);
|
|
|
|
|
|
|
|
return (total);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
ngt_getc_poll(struct tty *tp)
|
|
|
|
{
|
|
|
|
sc_p sc = ttyhook_softc(tp);
|
|
|
|
|
|
|
|
return (sc->outqlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Optimised TTY input.
|
|
|
|
*
|
|
|
|
* We get a buffer pointer to hopefully a complete data frame. Do not check for
|
|
|
|
* the hotchar, just pass it on.
|
|
|
|
*/
|
|
|
|
static size_t
|
|
|
|
ngt_rint_bypass(struct tty *tp, const void *buf, size_t len)
|
|
|
|
{
|
|
|
|
sc_p sc = ttyhook_softc(tp);
|
|
|
|
node_p node = sc->node;
|
|
|
|
struct mbuf *m, *mb;
|
|
|
|
size_t total = 0;
|
|
|
|
int error = 0, length;
|
|
|
|
|
|
|
|
tty_lock_assert(tp, MA_OWNED);
|
|
|
|
|
|
|
|
if (sc->hook == NULL)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
m = m_getm2(NULL, len, M_DONTWAIT, MT_DATA, M_PKTHDR);
|
|
|
|
if (m == NULL) {
|
|
|
|
if (sc->flags & FLG_DEBUG)
|
|
|
|
log(LOG_ERR,
|
|
|
|
"%s: can't get mbuf\n", NG_NODE_NAME(node));
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
m->m_pkthdr.rcvif = NULL;
|
|
|
|
|
|
|
|
for (mb = m; mb != NULL; mb = mb->m_next) {
|
|
|
|
length = min(M_TRAILINGSPACE(mb), len - total);
|
|
|
|
|
|
|
|
memcpy(mtod(m, char *), (const char *)buf + total, length);
|
|
|
|
mb->m_len = length;
|
|
|
|
total += length;
|
|
|
|
m->m_pkthdr.len += length;
|
|
|
|
}
|
|
|
|
if (sc->m != NULL) {
|
|
|
|
/*
|
|
|
|
* Odd, we have changed from non-bypass to bypass. It is
|
|
|
|
* unlikely but not impossible, flush the data first.
|
|
|
|
*/
|
|
|
|
sc->m->m_data = sc->m->m_pktdat;
|
|
|
|
NG_SEND_DATA_ONLY(error, sc->hook, sc->m);
|
|
|
|
sc->m = NULL;
|
|
|
|
}
|
|
|
|
NG_SEND_DATA_ONLY(error, sc->hook, m);
|
|
|
|
|
|
|
|
return (total);
|
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
/*
|
2008-10-03 05:14:54 +00:00
|
|
|
* Receive data coming from the device one char at a time, when it is not in
|
|
|
|
* bypass mode.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2008-10-03 05:14:54 +00:00
|
|
|
ngt_rint(struct tty *tp, char c, int flags)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2008-10-03 05:14:54 +00:00
|
|
|
sc_p sc = ttyhook_softc(tp);
|
|
|
|
node_p node = sc->node;
|
|
|
|
struct mbuf *m;
|
Locking and cleanup of tty netgraph node. Tty stack is Giant-locked,
so we need to acquire Giant in netgraph methods, so that we don't
race with line discipline methods. Remove NET_NEEDS_GIANT.
- Packets coming into node from netgraph are queued in ifqueue
attached to node private data.
- Mutex in struct ifqueue is used to lock not only the queue, but
the whole private data, and tp->t_lsc field.
- tp->t_lsc pointer is used to indicate whether line discipline is
attached to netgraph or not.
- Use FLG_DIE flag to indicate that node may be destroyed.
(This protection doesn't work, and it didn't before. Must be redesigned.)
- Increment ngt_unit atomically, removing mutex.
- Acquire Giant, when executing ngt_start() from netgraph context.
- Acquire Giant, when {,de}registering line discipline.
- Uncomment forcing queue mode on peers hook, since this is reasonable.
- Force queue mode on our hook, to avoid acquiring Giant when coming from
network stack. We may already hold some mutexes at this point.
Cleanups:
- Use callout_pending() instead of our own flag.
- Remove spl(9) calls. Now we can use return() instead of ERROUT().
style(9):
- Sort includes.
- Sparse initializer for struct linesw.
- Remove some empty lines, sort declarations.
Reviewed by: julian, phk
MFC after: 1 month
2005-01-13 07:43:12 +00:00
|
|
|
int error = 0;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2008-10-03 05:14:54 +00:00
|
|
|
tty_lock_assert(tp, MA_OWNED);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2008-10-03 05:14:54 +00:00
|
|
|
if (sc->hook == NULL)
|
|
|
|
return (0);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2008-10-03 05:14:54 +00:00
|
|
|
if (flags != 0) {
|
|
|
|
/* framing error or overrun on this char */
|
|
|
|
if (sc->flags & FLG_DEBUG)
|
|
|
|
log(LOG_DEBUG, "%s: line error %x\n",
|
|
|
|
NG_NODE_NAME(node), flags);
|
|
|
|
return (0);
|
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2008-10-03 05:14:54 +00:00
|
|
|
/* Get a new header mbuf if we need one */
|
|
|
|
if (!(m = sc->m)) {
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (!m) {
|
|
|
|
if (sc->flags & FLG_DEBUG)
|
|
|
|
log(LOG_ERR,
|
|
|
|
"%s: can't get mbuf\n", NG_NODE_NAME(node));
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
m->m_len = m->m_pkthdr.len = 0;
|
|
|
|
m->m_pkthdr.rcvif = NULL;
|
|
|
|
sc->m = m;
|
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2008-10-03 05:14:54 +00:00
|
|
|
/* Add char to mbuf */
|
|
|
|
*mtod(m, u_char *) = c;
|
|
|
|
m->m_data++;
|
|
|
|
m->m_len++;
|
|
|
|
m->m_pkthdr.len++;
|
|
|
|
|
|
|
|
/* Ship off mbuf if it's time */
|
|
|
|
if (sc->hotchar == -1 || c == sc->hotchar || m->m_len >= MHLEN) {
|
|
|
|
m->m_data = m->m_pktdat;
|
|
|
|
sc->m = NULL;
|
|
|
|
NG_SEND_DATA_ONLY(error, sc->hook, m); /* Will queue */
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
2008-10-03 05:14:54 +00:00
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2008-10-03 05:14:54 +00:00
|
|
|
|
|
|
|
static size_t
|
|
|
|
ngt_rint_poll(struct tty *tp)
|
|
|
|
{
|
|
|
|
/* We can always accept input */
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|