diff options
author | archie <archie@FreeBSD.org> | 1999-12-03 21:17:30 +0000 |
---|---|---|
committer | archie <archie@FreeBSD.org> | 1999-12-03 21:17:30 +0000 |
commit | 2bb264d4df9f7a0124b3916344d7be225c4dda75 (patch) | |
tree | c3f33752b310fced2d0cf27f8b24883a455547fc /sys/netgraph/ng_base.c | |
parent | 39d5a6d9a112c694b6ddfe314cd3fabd50842d57 (diff) | |
download | FreeBSD-src-2bb264d4df9f7a0124b3916344d7be225c4dda75.zip FreeBSD-src-2bb264d4df9f7a0124b3916344d7be225c4dda75.tar.gz |
Add a new function ng_findhook() for finding a node's hook;
if the node type provides a more efficient implementation than
the normal linear scan, use it.
Reviewed by: julian
Diffstat (limited to 'sys/netgraph/ng_base.c')
-rw-r--r-- | sys/netgraph/ng_base.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c index 7d20e80..7ddc3bb 100644 --- a/sys/netgraph/ng_base.c +++ b/sys/netgraph/ng_base.c @@ -662,11 +662,9 @@ ng_add_hook(node_p node, const char *name, hook_p *hookp) TRAP_ERROR; return (EINVAL); } - LIST_FOREACH(hook, &node->hooks, hooks) { - if (strcmp(hook->name, name) == 0) { - TRAP_ERROR; - return (EEXIST); - } + if (ng_findhook(node, name) != NULL) { + TRAP_ERROR; + return (EEXIST); } /* Allocate the hook and link it up */ @@ -741,6 +739,26 @@ ng_connect(hook_p hook1, hook_p hook2) } /* + * Find a hook + * + * Node types may supply their own optimized routines for finding + * hooks. If none is supplied, we just do a linear search. + */ +hook_p +ng_findhook(node_p node, const char *name) +{ + hook_p hook; + + if (node->type->findhook != NULL) + return (*node->type->findhook)(node, name); + LIST_FOREACH(hook, &node->hooks, hooks) { + if (hook->name != NULL && strcmp(hook->name, name) == 0) + return (hook); + } + return (NULL); +} + +/* * Destroy a hook * * As hooks are always attached, this really destroys two hooks. @@ -1060,10 +1078,7 @@ ng_path2node(node_p here, const char *address, node_p *destp, char **rtnp) continue; /* We have a segment, so look for a hook by that name */ - LIST_FOREACH(hook, &node->hooks, hooks) { - if (hook->name && strcmp(hook->name, segment) == 0) - break; - } + hook = ng_findhook(node, segment); /* Can't get there from here... */ if (hook == NULL @@ -1236,11 +1251,7 @@ ng_generic_msg(node_p here, struct ng_mesg *msg, const char *retaddr, return (EINVAL); } rmh->ourhook[sizeof(rmh->ourhook) - 1] = '\0'; - LIST_FOREACH(hook, &here->hooks, hooks) { - if (hook->name && strcmp(hook->name, rmh->ourhook) == 0) - break; - } - if (hook) + if ((hook = ng_findhook(here, rmh->ourhook)) != NULL) ng_destroy_hook(hook); break; } |