67#include <sys/ioccom.h>
68#include <sys/kernel.h>
69#include <sys/malloc.h>
72#include <sys/socket.h>
73#include <sys/syslog.h>
75#include <sys/ttycom.h>
79#include <net/if_var.h>
99#define FLG_DEBUG 0x0002
110#define ERROUT(x) do { error = (x); goto done; } while (0)
140#define NGTLOCK(sc) IF_LOCK(&sc->outq)
141#define NGTUNLOCK(sc) IF_UNLOCK(&sc->outq)
159 sc = malloc(
sizeof(*sc), M_NETGRAPH, M_WAITOK | M_ZERO);
164 mtx_init(&sc->outq.ifq_mtx,
"ng_tty node+queue", NULL, MTX_DEF);
211 if (hook != sc->hook)
212 panic(
"%s", __func__);
233 ttyhook_unregister(tp);
237 mtx_destroy(&(sc)->outq.ifq_mtx);
239 free(sc, M_NETGRAPH);
252 struct ng_mesg *msg, *resp = NULL;
263 p = pfind(((
int *)msg->
data)[0]);
264 if (p == NULL || (p->p_flag & P_WEXIT))
268 error = ttyhook_register(&sc->tp, p, ((
int *)msg->
data)[1],
280 hotchar = *((
int *) msg->
data);
281 if (hotchar != (u_char) hotchar && hotchar != -1)
283 sc->hotchar = hotchar;
291 *((
int *) resp->
data) = sc->hotchar;
314 struct tty *tp = sc->tp;
317 if (hook != sc->hook)
318 panic(
"%s", __func__);
329 if (_IF_QFULL(&sc->outq)) {
330 IF_UNLOCK(&sc->outq);
335 _IF_ENQUEUE(&sc->outq, m);
336 sc->outqlen += m->m_pkthdr.len;
337 IF_UNLOCK(&sc->outq);
342 ttydevsw_outwakeup(tp);
351 sc_p sc = ttyhook_softc(tp);
359 IF_DEQUEUE(&sc->outq, m);
366 memcpy((
char *)buf + total, mtod(m,
char *),
length);
380 IF_PREPEND(&sc->outq, m);
385 sc->outqlen -= total;
386 IF_UNLOCK(&sc->outq);
387 MPASS(sc->outqlen >= 0);
395 sc_p sc = ttyhook_softc(tp);
397 return (sc->outqlen);
409 sc_p sc = ttyhook_softc(tp);
415 tty_assert_locked(tp);
417 if (sc->hook == NULL)
420 m = m_getm2(NULL, len, M_NOWAIT, MT_DATA, M_PKTHDR);
427 m->m_pkthdr.rcvif = NULL;
429 for (mb = m; mb != NULL; mb = mb->m_next) {
430 length =
min(M_TRAILINGSPACE(mb), len - total);
432 memcpy(mtod(m,
char *), (
const char *)buf + total,
length);
435 m->m_pkthdr.len +=
length;
457 sc_p sc = ttyhook_softc(tp);
462 tty_assert_locked(tp);
464 if (sc->hook == NULL)
470 log(LOG_DEBUG,
"%s: line error %x\n",
477 MGETHDR(m, M_NOWAIT, MT_DATA);
484 m->m_len = m->m_pkthdr.len = 0;
485 m->m_pkthdr.rcvif = NULL;
490 *mtod(m, u_char *) = c;
496 if (sc->hotchar == -1 || c == sc->hotchar || m->m_len >= MHLEN) {
int ng_connect_t(hook_p hook)
#define NG_HOOK_NODE(hook)
int ng_rcvmsg_t(node_p node, item_p item, hook_p lasthook)
int ng_disconnect_t(hook_p hook)
#define NG_NODE_SET_PRIVATE(node, val)
#define NG_RESPOND_MSG(error, here, item, resp)
#define NG_NODE_UNREF(node)
#define NG_NODE_NAME(node)
#define NG_SEND_DATA_ONLY(error, hook, m)
#define NG_HOOK_FORCE_QUEUE(hook)
int ng_rcvdata_t(hook_p hook, item_p item)
int ng_shutdown_t(node_p node)
#define NG_FREE_ITEM(item)
int ng_constructor_t(node_p node)
#define NGI_GET_MSG(i, m)
#define NG_NODE_PRIVATE(node)
int ng_newhook_t(node_p node, hook_p hook, const char *name)
#define NG_MKRESPONSE(rsp, msg, len, how)
static ng_disconnect_t ngt_disconnect
static ng_rcvmsg_t ngt_rcvmsg
static ng_connect_t ngt_connect
NETGRAPH_INIT(tty, &typestruct)
static th_rint_poll_t ngt_rint_poll
static ng_constructor_t ngt_constructor
static th_getc_inject_t ngt_getc_inject
static ng_newhook_t ngt_newhook
static struct ng_type typestruct
static ng_rcvdata_t ngt_rcvdata
static struct ttyhook ngt_hook
static ng_shutdown_t ngt_shutdown
static th_rint_t ngt_rint
static th_getc_poll_t ngt_getc_poll
static th_rint_bypass_t ngt_rint_bypass
struct ng_mesg::ng_msghdr header