diff options
author | mav <mav@FreeBSD.org> | 2007-09-21 08:24:08 +0000 |
---|---|---|
committer | mav <mav@FreeBSD.org> | 2007-09-21 08:24:08 +0000 |
commit | 01f9f6963585c85073d89375ac95b6c91e063d1a (patch) | |
tree | d8bec977cc24228d5135df4e903a86b12972aa5f | |
parent | 14a66bdd4b5fb1668b671e9f8aa238fb41ae3084 (diff) | |
download | FreeBSD-src-01f9f6963585c85073d89375ac95b6c91e063d1a.zip FreeBSD-src-01f9f6963585c85073d89375ac95b6c91e063d1a.tar.gz |
This is optimization of ether and debug hooks determination. It
simplifies code and should speedup pppoe_findsession() function which is
called for every incoming packet.
Approved by: re (kensmith), glebius (mentor)
-rw-r--r-- | sys/netgraph/ng_pppoe.c | 71 |
1 files changed, 27 insertions, 44 deletions
diff --git a/sys/netgraph/ng_pppoe.c b/sys/netgraph/ng_pppoe.c index 3ebb1a6..026f87d7 100644 --- a/sys/netgraph/ng_pppoe.c +++ b/sys/netgraph/ng_pppoe.c @@ -280,9 +280,7 @@ static int pppoe_send_event(sessp sp, enum cmd cmdid); static uint16_t get_new_sid(node_p node) { - priv_p privp = NG_NODE_PRIVATE(node); static int pppoe_sid = 10; - sessp sp; hook_p hook; uint16_t val; @@ -299,11 +297,11 @@ restart: /* Check it isn't already in use. */ LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) { - /* Don't check special hooks. */ - if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook) - || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) + sessp sp = NG_HOOK_PRIVATE(hook); + + /* Skip any nonsession hook. */ + if (sp == NULL) continue; - sp = NG_HOOK_PRIVATE(hook); if (sp->Session_ID == val) goto restart; } @@ -446,16 +444,14 @@ make_packet(sessp sp) { static hook_p pppoe_match_svc(node_p node, const struct pppoe_tag *tag) { - priv_p privp = NG_NODE_PRIVATE(node); hook_p hook; LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) { sessp sp = NG_HOOK_PRIVATE(hook); negp neg; - /* Skip any hook that is debug or ethernet. */ - if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook) || - (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) + /* Skip any nonsession hook. */ + if (sp == NULL) continue; /* Skip any sessions which are not in LISTEN mode. */ @@ -494,7 +490,6 @@ pppoe_match_svc(node_p node, const struct pppoe_tag *tag) static int pppoe_broadcast_padi(node_p node, struct mbuf *m0) { - priv_p privp = NG_NODE_PRIVATE(node); hook_p hook; int error = 0; @@ -506,8 +501,7 @@ pppoe_broadcast_padi(node_p node, struct mbuf *m0) * Go through all listening hooks and * broadcast the PADI packet up there */ - if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook) || - (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) + if (sp == NULL) continue; if (sp->state != PPPOE_LISTENING) @@ -530,16 +524,14 @@ pppoe_broadcast_padi(node_p node, struct mbuf *m0) static hook_p pppoe_find_svc(node_p node, const char *svc_name, int svc_len) { - priv_p privp = NG_NODE_PRIVATE(node); hook_p hook; LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) { sessp sp = NG_HOOK_PRIVATE(hook); negp neg; - /* Skip any hook that is debug or ethernet. */ - if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook) || - (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) + /* Skip any nonsession hook. */ + if (sp == NULL) continue; /* Skip any sessions which are not in LISTEN mode. */ @@ -562,8 +554,6 @@ pppoe_find_svc(node_p node, const char *svc_name, int svc_len) static hook_p pppoe_findsession(node_p node, const struct pppoe_full_hdr *wh) { - priv_p privp = NG_NODE_PRIVATE(node); - sessp sp = NULL; hook_p hook = NULL; uint16_t session = ntohs(wh->ph.sid); @@ -571,18 +561,16 @@ pppoe_findsession(node_p node, const struct pppoe_full_hdr *wh) * Find matching peer/session combination. */ LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) { - /* don't check special hooks */ - if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook) - || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) { + sessp sp = NG_HOOK_PRIVATE(hook); + + /* Skip any nonsession hook. */ + if (sp == NULL) continue; - } - sp = NG_HOOK_PRIVATE(hook); - if ( ( (sp->state == PPPOE_CONNECTED) - || (sp->state == PPPOE_NEWCONNECTED) ) - && (sp->Session_ID == session) - && (bcmp(sp->pkt_hdr.eh.ether_dhost, - wh->eh.ether_shost, - ETHER_ADDR_LEN)) == 0) { + if (sp->Session_ID == session && + (sp->state == PPPOE_CONNECTED || + sp->state == PPPOE_NEWCONNECTED) && + bcmp(sp->pkt_hdr.eh.ether_dhost, + wh->eh.ether_shost, ETHER_ADDR_LEN) == 0) { break; } } @@ -594,16 +582,14 @@ pppoe_findsession(node_p node, const struct pppoe_full_hdr *wh) static hook_p pppoe_finduniq(node_p node, const struct pppoe_tag *tag) { - priv_p privp = NG_NODE_PRIVATE(node); hook_p hook = NULL; union uniq uniq; bcopy(tag->tag_data, uniq.bytes, sizeof(void *)); /* Cycle through all known hooks. */ LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) { - /* Don't check special hooks. */ - if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook) - || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) + /* Skip any nonsession hook. */ + if (NG_HOOK_PRIVATE(hook) == NULL) continue; if (uniq.pointer == NG_HOOK_PRIVATE(hook)) break; @@ -661,10 +647,8 @@ ng_pppoe_newhook(node_p node, hook_p hook, const char *name) if (strcmp(name, NG_PPPOE_HOOK_ETHERNET) == 0) { privp->ethernet_hook = hook; - NG_HOOK_SET_PRIVATE(hook, &privp->ethernet_hook); } else if (strcmp(name, NG_PPPOE_HOOK_DEBUG) == 0) { privp->debug_hook = hook; - NG_HOOK_SET_PRIVATE(hook, &privp->debug_hook); } else { /* * Any other unique name is OK. @@ -781,12 +765,11 @@ ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook) if (hook == NULL) LEAVE(ENOENT); - if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook) || - (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) - LEAVE(EINVAL); - sp = NG_HOOK_PRIVATE(hook); + if (sp == NULL) + LEAVE(EINVAL); + if (msg->header.cmd == NGM_PPPOE_LISTEN) { /* * Ensure we aren't already listening for this @@ -1146,14 +1129,14 @@ ng_pppoe_rcvdata(hook_p hook, item_p item) __func__, node->nd_ID, node, item, hook->hk_name, hook); NGI_GET_M(item, m); - if (NG_HOOK_PRIVATE(hook) == &privp->debug_hook) { + if (hook == privp->debug_hook) { /* * Data from the debug hook gets sent without modification * straight to the ethernet. */ NG_FWD_ITEM_HOOK( error, item, privp->ethernet_hook); privp->packets_out++; - } else if (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook) { + } else if (hook == privp->ethernet_hook) { /* * Incoming data. * Dig out various fields from the packet. @@ -1681,9 +1664,9 @@ ng_pppoe_disconnect(hook_p hook) int hooks; hooks = NG_NODE_NUMHOOKS(node); /* This one already not counted. */ - if (NG_HOOK_PRIVATE(hook) == &privp->debug_hook) { + if (hook == privp->debug_hook) { privp->debug_hook = NULL; - } else if (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook) { + } else if (hook == privp->ethernet_hook) { privp->ethernet_hook = NULL; if (NG_NODE_IS_VALID(node)) ng_rmnode_self(node); |