summaryrefslogtreecommitdiff
path: root/sys/netgraph
diff options
context:
space:
mode:
authorJulian Elischer <julian@FreeBSD.org>1999-11-17 07:46:40 +0000
committerJulian Elischer <julian@FreeBSD.org>1999-11-17 07:46:40 +0000
commit506c1ff0bbebd40a72705a5dbc3aa9756b2fe380 (patch)
tree6b06be35d71409541dc1f455f921b90b5996e7e1 /sys/netgraph
parenta397540e2b654a7871b34f3f7a05240d284bcbb1 (diff)
Notes
Diffstat (limited to 'sys/netgraph')
-rw-r--r--sys/netgraph/netgraph.h5
-rw-r--r--sys/netgraph/ng_async.c98
-rw-r--r--sys/netgraph/ng_async.h7
-rw-r--r--sys/netgraph/ng_base.c2
-rw-r--r--sys/netgraph/ng_iface.c39
-rw-r--r--sys/netgraph/ng_socket.c2
-rw-r--r--sys/netgraph/ng_socket.h4
-rw-r--r--sys/netgraph/ng_tty.c15
8 files changed, 100 insertions, 72 deletions
diff --git a/sys/netgraph/netgraph.h b/sys/netgraph/netgraph.h
index 94649e607642..34395b7aa4c4 100644
--- a/sys/netgraph/netgraph.h
+++ b/sys/netgraph/netgraph.h
@@ -224,6 +224,11 @@ DECLARE_MODULE(ng_##typename, ng_##typename##_mod, sub, order)
/* Special malloc() type for netgraph structs and ctrl messages */
MALLOC_DECLARE(M_NETGRAPH);
+/* XXX Temporarily assign ourself an ISR number (1 seems unused) */
+#ifndef NETISR_NETGRAPH
+#define NETISR_NETGRAPH 1
+#endif
+
int ng_bypass(hook_p hook1, hook_p hook2);
void ng_cutlinks(node_p node);
int ng_con_nodes(node_p node,
diff --git a/sys/netgraph/ng_async.c b/sys/netgraph/ng_async.c
index 397e7e757681..d148ff09b5ab 100644
--- a/sys/netgraph/ng_async.c
+++ b/sys/netgraph/ng_async.c
@@ -64,8 +64,8 @@
#include <net/ppp_defs.h>
-/* LCP protocol number */
-#define PROTO_LCP 0xc021
+/* Optimize opening and closing flags into one? Set to max # seconds delay */
+#define SYNC_OPT_TIME 1 /* one second maximum */
/* Async decode state */
#define MODE_HUNT 0
@@ -77,12 +77,15 @@ struct private {
node_p node; /* Our node */
hook_p async; /* Asynchronous side */
hook_p sync; /* Synchronous side */
+ hook_p sync2; /* Synchronous side, full escapes */
u_char amode; /* Async hunt/esape mode */
u_int16_t fcs; /* Decoded async FCS (so far) */
u_char *abuf; /* Buffer to encode sync into */
u_char *sbuf; /* Buffer to decode async into */
u_int slen; /* Length of data in sbuf */
+#if SYNC_OPT_TIME
long lasttime; /* Time of last async packet sent */
+#endif
struct ng_async_cfg cfg; /* Configuration */
struct ng_async_stat stats; /* Statistics */
};
@@ -178,6 +181,8 @@ nga_newhook(node_p node, hook_p hook, const char *name)
hookp = &sc->async;
else if (!strcmp(name, NG_ASYNC_HOOK_SYNC))
hookp = &sc->sync;
+ else if (!strcmp(name, NG_ASYNC_HOOK_SYNC2))
+ hookp = &sc->sync2;
else
return (EINVAL);
if (*hookp)
@@ -196,7 +201,18 @@ nga_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
if (hook == sc->sync)
return (nga_rcv_sync(sc, m, meta));
- if (hook == sc->async)
+ else if (hook == sc->sync2) {
+ const u_char acfcompSave = sc->cfg.acfcomp;
+ const u_int32_t accmSave = sc->cfg.accm;
+ int rtn;
+
+ sc->cfg.acfcomp = 0;
+ sc->cfg.accm = ~0;
+ rtn = nga_rcv_sync(sc, m, meta);
+ sc->cfg.acfcomp = acfcompSave;
+ sc->cfg.accm = accmSave;
+ return (rtn);
+ } else if (hook == sc->async)
return (nga_rcv_async(sc, m, meta));
panic(__FUNCTION__);
}
@@ -319,13 +335,17 @@ nga_disconnect(hook_p hook)
hookp = &sc->async;
else if (hook == sc->sync)
hookp = &sc->sync;
+ else if (hook == sc->sync2)
+ hookp = &sc->sync2;
else
panic(__FUNCTION__);
if (!*hookp)
panic(__FUNCTION__ "2");
*hookp = NULL;
bzero(&sc->stats, sizeof(sc->stats));
+#if SYNC_OPT_TIME
sc->lasttime = 0;
+#endif
if (hook->node->numhooks == 0)
ng_rmnode(hook->node);
return (0);
@@ -352,57 +372,28 @@ nga_async_add(const sc_p sc, u_int16_t *fcs, u_int32_t accm, int *len, u_char x)
}
/*
- * Receive incoming synchronous data.
+ * Receive incoming synchronous data. Any "meta" information means
+ * for us to apply full ACCM to this frame.
*/
static int
nga_rcv_sync(const sc_p sc, struct mbuf *m, meta_p meta)
{
struct ifnet *const rcvif = m->m_pkthdr.rcvif;
- int acfcomp, alen, error = 0;
- struct timeval time;
u_int16_t fcs, fcs0;
- u_int32_t accm;
+ int alen, error = 0;
-#define ADD_BYTE(x) nga_async_add(sc, &fcs, accm, &alen, (x))
+#define ADD_BYTE(x) \
+ nga_async_add(sc, &fcs, meta ? ~0 : sc->cfg.accm, &alen, (x))
- /* Check for bypass mode */
if (!sc->cfg.enabled) {
NG_SEND_DATA(error, sc->async, m, meta);
return (error);
}
-
- /* Defaults for ACF compression and ACCM */
- accm = sc->cfg.accm;
- acfcomp = sc->cfg.acfcomp;
-
- /* Special case LCP frames: disable ACF and enable ACCM */
- {
- struct mbuf *n = m;
- int off, proto;
-
- for (proto = off = 0; (proto & 1) == 0; off++) {
- while (n != NULL && off >= n->m_len) {
- n = n->m_next;
- off = 0;
- }
- if (n == NULL)
- break;
- proto = (proto << 8) | mtod(n, u_char *)[off];
- }
- if (proto == PROTO_LCP) {
- accm = ~0;
- acfcomp = 0;
- }
- }
-
- /* Check for overflow */
if (m->m_pkthdr.len > sc->cfg.smru) {
sc->stats.syncOverflows++;
NG_FREE_DATA(m, meta);
return (EMSGSIZE);
}
-
- /* Update stats */
sc->stats.syncFrames++;
sc->stats.syncOctets += m->m_pkthdr.len;
@@ -411,22 +402,32 @@ nga_rcv_sync(const sc_p sc, struct mbuf *m, meta_p meta)
fcs = PPP_INITFCS;
/* Add beginning sync flag if it's been long enough to need one */
- getmicrotime(&time);
- if (time.tv_sec >= sc->lasttime + 1) {
- sc->abuf[alen++] = PPP_FLAG;
- sc->lasttime = time.tv_sec;
+#if SYNC_OPT_TIME
+ {
+ struct timeval time;
+
+ getmicrotime(&time);
+ if (time.tv_sec >= sc->lasttime + SYNC_OPT_TIME) {
+ sc->abuf[alen++] = PPP_FLAG;
+ sc->lasttime = time.tv_sec;
+ }
}
+#else
+ sc->abuf[alen++] = PPP_FLAG;
+#endif
/* Add option address and control fields, then packet payload */
- if (!acfcomp) {
+ if (!sc->cfg.acfcomp || meta) {
ADD_BYTE(PPP_ALLSTATIONS);
ADD_BYTE(PPP_UI);
}
- while (m != NULL) {
+ while (m) {
struct mbuf *n;
while (m->m_len > 0) {
- ADD_BYTE(*mtod(m, u_char *));
+ u_char const ch = *mtod(m, u_char *);
+
+ ADD_BYTE(ch);
m->m_data++;
m->m_len--;
}
@@ -441,18 +442,17 @@ nga_rcv_sync(const sc_p sc, struct mbuf *m, meta_p meta)
sc->abuf[alen++] = PPP_FLAG;
/* Put frame in an mbuf and ship it off */
- if (!(m = m_devget(sc->abuf, alen, 0, rcvif, NULL))) {
- NG_FREE_META(meta);
+ NG_FREE_META(meta);
+ if (!(m = m_devget(sc->abuf, alen, 0, rcvif, NULL)))
error = ENOBUFS;
- } else
+ else
NG_SEND_DATA(error, sc->async, m, meta);
return (error);
}
/*
* Receive incoming asynchronous data
- * XXX Technically, we should strip out incoming characters
- * that are in our ACCM. Not sure if this is good or not.
+ * XXX technically, we should strip out supposedly escaped characters
*/
static int
nga_rcv_async(const sc_p sc, struct mbuf * m, meta_p meta)
diff --git a/sys/netgraph/ng_async.h b/sys/netgraph/ng_async.h
index 008cf2eb4ea5..f08290fd43f7 100644
--- a/sys/netgraph/ng_async.h
+++ b/sys/netgraph/ng_async.h
@@ -45,11 +45,12 @@
/* Type name and cookie */
#define NG_ASYNC_NODE_TYPE "async"
-#define NGM_ASYNC_COOKIE 886473716
+#define NGM_ASYNC_COOKIE 886473715
/* Hook names */
-#define NG_ASYNC_HOOK_SYNC "sync" /* Sync frames */
-#define NG_ASYNC_HOOK_ASYNC "async" /* Async-encoded frames */
+#define NG_ASYNC_HOOK_SYNC "sync" /* Normal encoding */
+#define NG_ASYNC_HOOK_SYNC2 "sync2" /* Full ACCM, no ACF comp. */
+#define NG_ASYNC_HOOK_ASYNC "async" /* Normal decoding */
/* Maximum receive size bounds (for both sync and async sides) */
#define NG_ASYNC_MIN_MRU 1
diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c
index 2ab8126cc11e..82b1ace2f1df 100644
--- a/sys/netgraph/ng_base.c
+++ b/sys/netgraph/ng_base.c
@@ -115,6 +115,7 @@ ng_make_node(const char *typename, node_p *nodepp)
/* Locate the node type */
if ((type = ng_findtype(typename)) == NULL) {
+#if 0
char *path, filename[NG_TYPELEN + 4];
linker_file_t lf;
int error;
@@ -131,6 +132,7 @@ ng_make_node(const char *typename, node_p *nodepp)
/* Try again, as now the type should have linked itself in */
if ((type = ng_findtype(typename)) == NULL)
+#endif
return (ENXIO);
}
diff --git a/sys/netgraph/ng_iface.c b/sys/netgraph/ng_iface.c
index 751f09d28bd5..80fb9ee89eb5 100644
--- a/sys/netgraph/ng_iface.c
+++ b/sys/netgraph/ng_iface.c
@@ -103,7 +103,12 @@
#include <netns/ns_if.h>
#endif
+#include "bpfilter.h"
+
+#if NBPFILTER > 0
#include <net/bpf.h>
+#include <net/bpfdesc.h>
+#endif
/* This struct describes one address family */
struct iffam {
@@ -174,7 +179,9 @@ static void ng_iface_start(struct ifnet *ifp);
static int ng_iface_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
static int ng_iface_output(struct ifnet *ifp, struct mbuf *m0,
struct sockaddr *dst, struct rtentry *rt0);
+#if NBPFILTER > 0
static void ng_iface_bpftap(struct ifnet *ifp, struct mbuf *m, u_int af);
+#endif
#ifdef DEBUG
static void ng_iface_print_ioctl(struct ifnet *ifp, int cmd, caddr_t data);
#endif
@@ -367,7 +374,9 @@ ng_iface_output(struct ifnet *ifp, struct mbuf *m,
}
/* Berkeley packet filter */
+#if NBPFILTER > 0
ng_iface_bpftap(ifp, m, dst->sa_family);
+#endif
/* Check address family to determine hook (if known) */
if (iffam == NULL) {
@@ -401,6 +410,7 @@ ng_iface_start(struct ifnet *ifp)
printf("%s%d: %s called?", ifp->if_name, ifp->if_unit, __FUNCTION__);
}
+#if NBPFILTER > 0
/*
* Flash a packet by the BPF (requires prepending 4 byte AF header)
* Note the phoney mbuf; this is OK because BPF treats it read-only.
@@ -410,21 +420,20 @@ ng_iface_bpftap(struct ifnet *ifp, struct mbuf *m, u_int af)
{
struct mbuf m2;
- if (ifp->if_bpf) {
- if (af == AF_UNSPEC) {
- af = *(mtod(m, int *));
- m->m_len -= sizeof(int);
- m->m_pkthdr.len -= sizeof(int);
- m->m_data += sizeof(int);
- }
- if (!ifp->if_bpf)
- return;
- m2.m_next = m;
- m2.m_len = 4;
- m2.m_data = (char *) &af;
- bpf_mtap(ifp, &m2);
+ if (af == AF_UNSPEC) {
+ af = *(mtod(m, int *));
+ m->m_len -= sizeof(int);
+ m->m_pkthdr.len -= sizeof(int);
+ m->m_data += sizeof(int);
}
+ if (!ifp->if_bpf)
+ return;
+ m2.m_next = m;
+ m2.m_len = 4;
+ m2.m_data = (char *) &af;
+ bpf_mtap(ifp, &m2);
}
+#endif /* NBPFILTER > 0 */
#ifdef DEBUG
/*
@@ -528,7 +537,9 @@ ng_iface_constructor(node_p *nodep)
/* Attach the interface */
if_attach(ifp);
+#if NBPFILTER > 0
bpfattach(ifp, DLT_NULL, sizeof(u_int));
+#endif
/* Done */
return (0);
@@ -703,8 +714,10 @@ ng_iface_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
/* Note receiving interface */
m->m_pkthdr.rcvif = ifp;
+#if NBPFILTER > 0
/* Berkeley packet filter */
ng_iface_bpftap(ifp, m, iffam->af);
+#endif
/* Ignore any meta-data */
NG_FREE_META(meta);
diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c
index 65e09f5a1ce0..331c06eb9f8e 100644
--- a/sys/netgraph/ng_socket.c
+++ b/sys/netgraph/ng_socket.c
@@ -972,7 +972,7 @@ ngs_mod_event(module_t mod, int event, void *data)
switch (event) {
case MOD_LOAD:
/* Register protocol domain */
- net_add_domain(&ngdomain);
+ error = net_add_domain(&ngdomain);
break;
case MOD_UNLOAD:
/* Insure there are no open netgraph sockets */
diff --git a/sys/netgraph/ng_socket.h b/sys/netgraph/ng_socket.h
index 1aacdf37b4de..7abc6cc6ff90 100644
--- a/sys/netgraph/ng_socket.h
+++ b/sys/netgraph/ng_socket.h
@@ -48,6 +48,10 @@
#define NGM_SOCKET_COOKIE 851601233
/* Netgraph socket(2) constants */
+#ifndef PF_NETGRAPH
+#define PF_NETGRAPH 31
+#define AF_NETGRAPH 31
+#endif
#define NG_DATA 1
#define NG_CONTROL 2
diff --git a/sys/netgraph/ng_tty.c b/sys/netgraph/ng_tty.c
index bacbb72995d1..5e43041f044d 100644
--- a/sys/netgraph/ng_tty.c
+++ b/sys/netgraph/ng_tty.c
@@ -69,7 +69,6 @@
#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,6 +157,7 @@ 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 = {
@@ -178,7 +178,6 @@ NETGRAPH_INIT(tty, &typestruct);
static int ngt_unit;
static int ngt_nodeop_ok; /* OK to create/remove node */
-static int ngt_ldisc;
/******************************************************************
LINE DISCIPLINE METHODS
@@ -197,13 +196,13 @@ ngt_open(dev_t dev, struct tty *tp)
int s, error;
/* Super-user only */
- if ((error = suser(p)))
+ if ((error = suser(p->p_ucred, &p->p_acflag)))
return (error);
s = splnet();
(void) spltty(); /* XXX is this necessary? */
/* Already installed? */
- if (tp->t_line == NETGRAPHDISC) {
+ if (tp->t_line == ngt_ldisc) {
sc = (sc_p) tp->t_sc;
if (sc != NULL && sc->tp == tp)
goto done;
@@ -655,7 +654,7 @@ done:
static int
ngt_mod_event(module_t mod, int event, void *data)
{
- /* struct ng_type *const type = data;*/
+ struct ng_type *const type = data;
int s, error = 0;
switch (event) {
@@ -676,13 +675,17 @@ ngt_mod_event(module_t mod, int event, void *data)
/* Register line discipline */
s = spltty();
- if ((ngt_ldisc = ldisc_register(NETGRAPHDISC, &ngt_disc)) < 0) {
+ if ((ngt_ldisc = ldisc_register(LDISC_LOAD, &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: