summaryrefslogtreecommitdiffstats
path: root/sys/netgraph
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>2008-12-25 09:02:55 +0000
committerjulian <julian@FreeBSD.org>2008-12-25 09:02:55 +0000
commiteee0b0af37a4e6c930723b74c3f0e62b48b0707c (patch)
treeaf8b5cb3308d829b84a8f55e3e37e04f8f10a2a3 /sys/netgraph
parentfb811d854f9df0f6906413c5f69516a5de35cabe (diff)
downloadFreeBSD-src-eee0b0af37a4e6c930723b74c3f0e62b48b0707c.zip
FreeBSD-src-eee0b0af37a4e6c930723b74c3f0e62b48b0707c.tar.gz
shave about 7% off the overhead of ng_ether by using per-hook
receive data methods.
Diffstat (limited to 'sys/netgraph')
-rw-r--r--sys/netgraph/ng_ether.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/sys/netgraph/ng_ether.c b/sys/netgraph/ng_ether.c
index d76e7e1..c03befc 100644
--- a/sys/netgraph/ng_ether.c
+++ b/sys/netgraph/ng_ether.c
@@ -102,8 +102,8 @@ static void ng_ether_detach(struct ifnet *ifp);
static void ng_ether_link_state(struct ifnet *ifp, int state);
/* Other functions */
-static int ng_ether_rcv_lower(node_p node, struct mbuf *m);
-static int ng_ether_rcv_upper(node_p node, struct mbuf *m);
+static int ng_ether_rcv_lower(hook_p node, item_p item);
+static int ng_ether_rcv_upper(hook_p node, item_p item);
/* Netgraph node methods */
static ng_constructor_t ng_ether_constructor;
@@ -389,13 +389,16 @@ ng_ether_newhook(node_p node, hook_p hook, const char *name)
name = NG_ETHER_HOOK_LOWER;
/* Which hook? */
- if (strcmp(name, NG_ETHER_HOOK_UPPER) == 0)
+ if (strcmp(name, NG_ETHER_HOOK_UPPER) == 0) {
hookptr = &priv->upper;
- else if (strcmp(name, NG_ETHER_HOOK_LOWER) == 0)
+ NG_HOOK_SET_RCVDATA(hook, ng_ether_rcv_upper);
+ } else if (strcmp(name, NG_ETHER_HOOK_LOWER) == 0) {
hookptr = &priv->lower;
- else if (strcmp(name, NG_ETHER_HOOK_ORPHAN) == 0)
+ NG_HOOK_SET_RCVDATA(hook, ng_ether_rcv_lower);
+ } else if (strcmp(name, NG_ETHER_HOOK_ORPHAN) == 0) {
hookptr = &priv->orphan;
- else
+ NG_HOOK_SET_RCVDATA(hook, ng_ether_rcv_lower);
+ } else
return (EINVAL);
/* Check if already connected (shouldn't be, but doesn't hurt) */
@@ -571,21 +574,13 @@ ng_ether_rcvmsg(node_p node, item_p item, hook_p lasthook)
/*
* Receive data on a hook.
+ * Since we use per-hook recveive methods this should never be called.
*/
static int
ng_ether_rcvdata(hook_p hook, item_p item)
{
- const node_p node = NG_HOOK_NODE(hook);
- const priv_p priv = NG_NODE_PRIVATE(node);
- struct mbuf *m;
-
- NGI_GET_M(item, m);
NG_FREE_ITEM(item);
- if (hook == priv->lower || hook == priv->orphan)
- return ng_ether_rcv_lower(node, m);
- if (hook == priv->upper)
- return ng_ether_rcv_upper(node, m);
panic("%s: weird hook", __func__);
#ifdef RESTARTABLE_PANICS /* so we don't get an error msg in LINT */
return (0);
@@ -596,12 +591,18 @@ ng_ether_rcvdata(hook_p hook, item_p item)
* Handle an mbuf received on the "lower" or "orphan" hook.
*/
static int
-ng_ether_rcv_lower(node_p node, struct mbuf *m)
+ng_ether_rcv_lower(hook_p hook, item_p item)
{
+ struct mbuf *m;
+ const node_p node = NG_HOOK_NODE(hook);
const priv_p priv = NG_NODE_PRIVATE(node);
struct ifnet *const ifp = priv->ifp;
+ NGI_GET_M(item, m);
+ NG_FREE_ITEM(item);
+
/* Check whether interface is ready for packets */
+
if (!((ifp->if_flags & IFF_UP) &&
(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
NG_FREE_M(m);
@@ -639,11 +640,16 @@ ng_ether_rcv_lower(node_p node, struct mbuf *m)
* Handle an mbuf received on the "upper" hook.
*/
static int
-ng_ether_rcv_upper(node_p node, struct mbuf *m)
+ng_ether_rcv_upper(hook_p hook, item_p item)
{
+ struct mbuf *m;
+ const node_p node = NG_HOOK_NODE(hook);
const priv_p priv = NG_NODE_PRIVATE(node);
struct ifnet *ifp = priv->ifp;
+ NGI_GET_M(item, m);
+ NG_FREE_ITEM(item);
+
/* Check length and pull off header */
if (m->m_pkthdr.len < sizeof(struct ether_header)) {
NG_FREE_M(m);
OpenPOWER on IntegriCloud