diff options
author | julian <julian@FreeBSD.org> | 2004-06-25 19:22:05 +0000 |
---|---|---|
committer | julian <julian@FreeBSD.org> | 2004-06-25 19:22:05 +0000 |
commit | dfb6d511956c2a209c86265e60dde6f108cf61b3 (patch) | |
tree | e6486f45de5c63b28a090942d8f046694d0329cb /sys/netgraph | |
parent | d754d951b906e8d0c99ea9917952cdfb8c5c9378 (diff) | |
download | FreeBSD-src-dfb6d511956c2a209c86265e60dde6f108cf61b3.zip FreeBSD-src-dfb6d511956c2a209c86265e60dde6f108cf61b3.tar.gz |
Convert Netgraph to use mbuf tags to pass its meta information around.
Thanks to Sam for importing tags in a way that allowed this to be done.
Submitted by: Gleb Smirnoff <glebius@cell.sick.ru>
Also allow the sr and ar drivers to create netgraph versions of their modules.
Document the change to the ksocket node.
Diffstat (limited to 'sys/netgraph')
-rw-r--r-- | sys/netgraph/atm/uni/ng_uni_cust.h | 1 | ||||
-rw-r--r-- | sys/netgraph/netgraph.h | 18 | ||||
-rw-r--r-- | sys/netgraph/ng_ksocket.c | 53 | ||||
-rw-r--r-- | sys/netgraph/ng_ksocket.h | 10 | ||||
-rw-r--r-- | sys/netgraph/ng_lmi.c | 26 | ||||
-rw-r--r-- | sys/netgraph/ng_parse.c | 1 |
6 files changed, 54 insertions, 55 deletions
diff --git a/sys/netgraph/atm/uni/ng_uni_cust.h b/sys/netgraph/atm/uni/ng_uni_cust.h index 84e63e8..121d7ab 100644 --- a/sys/netgraph/atm/uni/ng_uni_cust.h +++ b/sys/netgraph/atm/uni/ng_uni_cust.h @@ -38,6 +38,7 @@ #include <sys/queue.h> #include <sys/lock.h> #include <sys/mutex.h> +#include <sys/mbuf.h> #include <netgraph/ng_message.h> #include <netgraph/netgraph.h> #include <netgraph/atm/ngatmbase.h> diff --git a/sys/netgraph/netgraph.h b/sys/netgraph/netgraph.h index 99adc60..90d2056 100644 --- a/sys/netgraph/netgraph.h +++ b/sys/netgraph/netgraph.h @@ -1137,10 +1137,24 @@ struct callout_handle ng_item_fn *fn, void * arg1, int arg2); /* - * prototypes the user should DEFINITLY not use directly + * prototypes the user should DEFINITELY not use directly */ void ng_free_item(item_p item); /* Use NG_FREE_ITEM instead */ int ng_mod_event(module_t mod, int what, void *arg); -#endif /* _NETGRAPH_NETGRAPH_H_ */ +/* + * Tag definitions and constants + */ + +#define NG_TAG_PRIO 1 +struct ng_tag_prio { + struct m_tag tag; + char priority; + char discardability; +}; + +#define NG_PRIO_CUTOFF 32 +#define NG_PRIO_LINKSTATE 64 + +#endif /* _NETGRAPH_NETGRAPH_H_ */ diff --git a/sys/netgraph/ng_ksocket.c b/sys/netgraph/ng_ksocket.c index 458bbde..715baa9 100644 --- a/sys/netgraph/ng_ksocket.c +++ b/sys/netgraph/ng_ksocket.c @@ -893,9 +893,9 @@ ng_ksocket_rcvdata(hook_p hook, item_p item) const priv_p priv = NG_NODE_PRIVATE(node); struct socket *const so = priv->so; struct sockaddr *sa = NULL; - meta_p meta; int error; struct mbuf *m; + struct sa_tag *stag; /* Avoid reentrantly sending on the socket */ if ((priv->flags & KSF_SENDING) != 0) { @@ -903,35 +903,20 @@ ng_ksocket_rcvdata(hook_p hook, item_p item) return (EDEADLK); } - /* Extract data and meta information */ + /* Extract data */ NGI_GET_M(item, m); - NGI_GET_META(item, meta); NG_FREE_ITEM(item); - /* If any meta info, look for peer socket address */ - if (meta != NULL) { - struct meta_field_header *field; - - /* Look for peer socket address */ - for (field = &meta->options[0]; - (caddr_t)field < (caddr_t)meta + meta->used_len; - field = (struct meta_field_header *) - ((caddr_t)field + field->len)) { - if (field->cookie != NGM_KSOCKET_COOKIE - || field->type != NG_KSOCKET_META_SOCKADDR) - continue; - sa = (struct sockaddr *)field->data; - break; - } - } + /* Look if socket address is stored in packet tags */ + if ((stag = (struct sa_tag *)m_tag_locate(m, NGM_KSOCKET_COOKIE, + NG_KSOCKET_TAG_SOCKADDR, NULL)) != NULL) + sa = &stag->sa; /* Send packet */ priv->flags |= KSF_SENDING; error = (*so->so_proto->pr_usrreqs->pru_sosend)(so, sa, 0, m, 0, 0, td); priv->flags &= ~KSF_SENDING; - /* Clean up and exit */ - NG_FREE_META(meta); return (error); } @@ -1103,7 +1088,6 @@ ng_ksocket_incoming2(node_p node, hook_p hook, void *arg1, int waitflag) flags = MSG_DONTWAIT; while (1) { struct sockaddr *sa = NULL; - meta_p meta = NULL; struct mbuf *n; /* Try to get next packet from socket */ @@ -1124,30 +1108,23 @@ ng_ksocket_incoming2(node_p node, hook_p hook, void *arg1, int waitflag) for (n = m, m->m_pkthdr.len = 0; n != NULL; n = n->m_next) m->m_pkthdr.len += n->m_len; - /* Put peer's socket address (if any) into a meta info blob */ + /* Put peer's socket address (if any) into a tag */ if (sa != NULL) { - struct meta_field_header *mhead; - u_int len; + struct sa_tag *stag; - len = sizeof(*meta) + sizeof(*mhead) + sa->sa_len; - MALLOC(meta, meta_p, len, M_NETGRAPH_META, - M_NOWAIT | M_ZERO); - if (meta == NULL) { + stag = (struct sa_tag *)m_tag_alloc(NGM_KSOCKET_COOKIE, + NG_KSOCKET_TAG_SOCKADDR, sa->sa_len, M_NOWAIT); + if (stag == NULL) { FREE(sa, M_SONAME); goto sendit; } - mhead = &meta->options[0]; - meta->allocated_len = len; - meta->used_len = len; - mhead->cookie = NGM_KSOCKET_COOKIE; - mhead->type = NG_KSOCKET_META_SOCKADDR; - mhead->len = sizeof(*mhead) + sa->sa_len; - bcopy(sa, mhead->data, sa->sa_len); + bcopy(sa, &stag->sa, sa->sa_len); FREE(sa, M_SONAME); + m_tag_prepend(m, &stag->tag); } -sendit: /* Forward data with optional peer sockaddr as meta info */ - NG_SEND_DATA(error, priv->hook, m, meta); +sendit: /* Forward data with optional peer sockaddr as packet tag */ + NG_SEND_DATA_ONLY(error, priv->hook, m); } /* diff --git a/sys/netgraph/ng_ksocket.h b/sys/netgraph/ng_ksocket.h index cad5164..d9d1932 100644 --- a/sys/netgraph/ng_ksocket.h +++ b/sys/netgraph/ng_ksocket.h @@ -94,7 +94,13 @@ enum { NGM_KSOCKET_GETOPT, }; -/* Meta information ID's */ -#define NG_KSOCKET_META_SOCKADDR 1 /* data is struct sockaddr */ +/* Structure for sockaddr tag */ +struct sa_tag { + struct m_tag tag; + struct sockaddr sa; +}; + +/* Tag information ID's */ +#define NG_KSOCKET_TAG_SOCKADDR 1 /* data is struct sockaddr */ #endif /* _NETGRAPH_NG_KSOCKET_H_ */ diff --git a/sys/netgraph/ng_lmi.c b/sys/netgraph/ng_lmi.c index cb6fbb1..368d201 100644 --- a/sys/netgraph/ng_lmi.c +++ b/sys/netgraph/ng_lmi.c @@ -306,14 +306,13 @@ nglmi_startup(sc_p sc) sc->handle = timeout(LMI_ticker, sc, hz); } -#define META_PAD 16 static void nglmi_inquire(sc_p sc, int full) { struct mbuf *m; + struct ng_tag_prio *ptag; char *cptr, *start; int error; - meta_p meta = NULL; if (sc->lmi_channel == NULL) return; @@ -323,17 +322,18 @@ nglmi_inquire(sc_p sc, int full) return; } m->m_pkthdr.rcvif = NULL; - /* Allocate a meta struct (and leave some slop for options to be - * added by other modules). */ - MALLOC(meta, meta_p, sizeof(*meta) + META_PAD, M_NETGRAPH_META, M_NOWAIT); - if (meta != NULL) { /* if it failed, well, it was optional anyhow */ - meta->used_len = (u_short) sizeof(struct ng_meta); - meta->allocated_len - = (u_short) sizeof(struct ng_meta) + META_PAD; - meta->flags = 0; - meta->priority = NG_LMI_LMI_PRIORITY; - meta->discardability = -1; + + /* Attach a tag to packet, marking it of link level state priority, so + * that device driver would put it in the beginning of queue */ + + ptag = (struct ng_tag_prio *)m_tag_alloc(NGM_GENERIC_COOKIE, NG_TAG_PRIO, + (sizeof(struct ng_tag_prio) - sizeof(struct m_tag)), M_NOWAIT); + if (ptag != NULL) { /* if it failed, well, it was optional anyhow */ + ptag->priority = NG_PRIO_LINKSTATE; + ptag->discardability = -1; + m_tag_prepend(m, &ptag->tag); } + m->m_data += 4; /* leave some room for a header */ cptr = start = mtod(m, char *); /* add in the header for an LMI inquiry. */ @@ -371,7 +371,7 @@ nglmi_inquire(sc_p sc, int full) /* Send it */ m->m_len = m->m_pkthdr.len = cptr - start; - NG_SEND_DATA(error, sc->lmi_channel, m, meta); + NG_SEND_DATA_ONLY(error, sc->lmi_channel, m); /* If we've been sending requests for long enough, and there has * been no response, then mark as DOWN, any DLCIs that are UP. */ diff --git a/sys/netgraph/ng_parse.c b/sys/netgraph/ng_parse.c index 37c5cc4..69090bea 100644 --- a/sys/netgraph/ng_parse.c +++ b/sys/netgraph/ng_parse.c @@ -46,6 +46,7 @@ #include <sys/kernel.h> #include <sys/errno.h> #include <sys/malloc.h> +#include <sys/mbuf.h> #include <sys/ctype.h> #include <net/ethernet.h> |