Lines Matching defs:hook
87 static struct mtx ng_nodelist_mtx; /* protects global node/hook lists */
234 static int ng_con_part2(node_p node, item_p item, hook_p hook);
235 static int ng_con_part3(node_p node, item_p item, hook_p hook);
242 void ng_destroy_hook(hook_p hook);
246 int ng_path_parse(char *addr, char **node, char **path, char **hook);
254 "netgraph hook structures");
262 #define _NG_ALLOC_HOOK(hook) \
263 hook = malloc(sizeof(*hook), M_NETGRAPH_HOOK, M_NOWAIT | M_ZERO)
296 hook_p hook;
299 hook = LIST_FIRST(&ng_freehooks);
300 if (hook) {
301 LIST_REMOVE(hook, hk_hooks);
302 bcopy(&hook->hk_all, &temp, sizeof(temp));
303 bzero(hook, sizeof(struct ng_hook));
304 bcopy(&temp, &hook->hk_all, sizeof(temp));
306 hook->hk_magic = HK_MAGIC;
309 _NG_ALLOC_HOOK(hook);
310 if (hook) {
311 hook->hk_magic = HK_MAGIC;
313 SLIST_INSERT_HEAD(&ng_allhooks, hook, hk_all);
317 return (hook);
347 #define NG_ALLOC_HOOK(hook) do { (hook) = ng_alloc_hook(); } while (0)
350 #define NG_FREE_HOOK(hook) \
353 LIST_INSERT_HEAD(&ng_freehooks, hook, hk_hooks); \
354 hook->hk_magic = 0; \
368 #define NG_ALLOC_HOOK(hook) _NG_ALLOC_HOOK(hook)
371 #define NG_FREE_HOOK(hook) do { free((hook), M_NETGRAPH_HOOK); } while (0)
669 /* Initialize hook list for new node */
717 hook_p hook;
744 while ((hook = LIST_FIRST(&node->nd_hooks)) != NULL)
745 ng_destroy_hook(hook);
1043 they are connected to the 'dead' hook.
1047 * Remove a hook reference
1050 ng_unref_hook(hook_p hook)
1053 if (hook == &ng_deadhook)
1056 if (refcount_release(&hook->hk_refs)) { /* we were the last */
1057 if (_NG_HOOK_NODE(hook)) /* it'll probably be ng_deadnode */
1058 _NG_NODE_UNREF((_NG_HOOK_NODE(hook)));
1059 NG_FREE_HOOK(hook);
1064 * Add an unconnected hook to a node. Only used internally.
1070 hook_p hook;
1083 /* Allocate the hook and link it up */
1084 NG_ALLOC_HOOK(hook);
1085 if (hook == NULL) {
1089 hook->hk_refs = 1; /* add a reference for us to return */
1090 hook->hk_flags = HK_INVALID;
1091 hook->hk_peer = &ng_deadhook; /* start off this way */
1092 hook->hk_node = node;
1093 NG_NODE_REF(node); /* each hook counts as a reference */
1095 /* Set hook name */
1096 strlcpy(NG_HOOK_NAME(hook), name, NG_HOOKSIZ);
1100 * If it fails, the unref of the hook will also unref the node.
1103 if ((error = (*node->nd_type->newhook)(node, hook, name))) {
1104 NG_HOOK_UNREF(hook); /* this frees the hook */
1112 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks);
1114 NG_HOOK_REF(hook); /* one for the node */
1117 *hookp = hook;
1122 * Find a hook
1126 * XXX Possibly we should add a reference to the hook?
1131 hook_p hook;
1135 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
1136 if (NG_HOOK_IS_VALID(hook) &&
1137 (strcmp(NG_HOOK_NAME(hook), name) == 0))
1138 return (hook);
1144 * Destroy a hook
1148 * from each other first. We reconnect the peer hook to the 'dead'
1149 * hook so that it can still exist after we depart. We then
1152 * message. We hold a reference to the peer hook so we are guaranteed that
1153 * the peer hook and node are still going to exist until
1154 * we are finished there as the hook holds a ref on the node.
1155 * We run this same code again on the peer hook, but that time it is already
1156 * attached to the 'dead' hook.
1158 * This routine is called at all stages of hook creation
1162 ng_destroy_hook(hook_p hook)
1167 if (hook == &ng_deadhook) { /* better safe than sorry */
1178 hook->hk_flags |= HK_INVALID;
1180 peer = NG_HOOK_PEER(hook);
1181 node = NG_HOOK_NODE(hook);
1190 hook->hk_peer = &ng_deadhook; /* Nor us, them */
1202 NG_HOOK_UNREF(hook); /* account for peer link */
1209 * Remove the hook from the node's list to avoid possible recursion
1215 LIST_REMOVE(hook, hk_hooks);
1222 * inherrited from the hook we are destroying)
1224 (*node->nd_type->disconnect) (hook);
1231 _NG_HOOK_NODE(hook) = &ng_deadnode;
1233 NG_HOOK_UNREF(hook); /* Account for linkage (in list) to node */
1345 ng_con_part3(node_p node, item_p item, hook_p hook)
1351 * Our caller has a reference on the hook.
1354 * The peer hook has a reference on the hook.
1358 if (NG_HOOK_NODE(hook) == &ng_deadnode) {
1369 if (hook->hk_node->nd_type->connect) {
1370 if ((error = (*hook->hk_node->nd_type->connect) (hook))) {
1371 ng_destroy_hook(hook); /* also zaps peer */
1381 hook->hk_flags &= ~HK_INVALID;
1388 ng_con_part2(node_p node, item_p item, hook_p hook)
1395 * Our caller has a reference on the hook.
1398 * The peer hook has a reference on the hook.
1400 * First check the hook name is unique.
1403 if (ng_findhook(node, NG_HOOK_NAME(hook)) != NULL) {
1405 ng_destroy_hook(hook); /* should destroy peer too */
1411 * If it fails, the unref of the hook will also unref the attached node,
1413 * The peer hook will also be destroyed.
1416 if ((error = (*node->nd_type->newhook)(node, hook,
1417 hook->hk_name))) {
1418 ng_destroy_hook(hook); /* should destroy peer too */
1428 hook->hk_node = node; /* just overwrite ng_deadnode */
1429 NG_NODE_REF(node); /* each hook counts as a reference */
1430 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks);
1432 NG_HOOK_REF(hook); /* one for the node */
1443 if (hook->hk_node->nd_type->connect) {
1444 if ((error = (*hook->hk_node->nd_type->connect) (hook))) {
1445 ng_destroy_hook(hook); /* also zaps peer */
1455 peer = hook->hk_peer;
1459 ng_destroy_hook(hook);
1467 ng_destroy_hook(hook); /* also zaps peer */
1470 hook->hk_flags &= ~HK_INVALID; /* need both to be able to work */
1486 hook_p hook;
1492 if ((error = ng_add_hook(node, name, &hook))) /* gives us a ref */
1494 /* Allocate the other hook and link it up */
1498 ng_destroy_hook(hook); /* XXX check ref counts so far */
1499 NG_HOOK_UNREF(hook); /* including our ref */
1504 hook2->hk_peer = hook; /* Link the two together */
1505 hook->hk_peer = hook2;
1506 NG_HOOK_REF(hook); /* Add a ref for the peer to each*/
1519 ng_destroy_hook(hook); /* also zaps peer */
1522 NG_HOOK_UNREF(hook); /* Let each hook go if it wants to */
1531 * it has a hook, because it cannot really have any work until then,
1573 /* Each hook is referenced by the other */
1624 ng_rmhook_part2(node_p node, hook_p hook, void *arg1, int arg2)
1626 ng_destroy_hook(hook);
1631 ng_rmhook_self(hook_p hook)
1634 node_p node = NG_HOOK_NODE(hook);
1639 error = ng_send_fn(node, hook, &ng_rmhook_part2, NULL, 0);
1646 * Such a string can refer to a specific node or a specific hook
1651 * of hook names separated by dots. This breaks out the original
1654 * the final hook component of <PATH>, if any, otherwise NULL.
1661 char *node, *path, *hook;
1703 /* If PATH has a dot, then we're not talking about a hook */
1705 for (hook = path, k = 0; path[k]; k++)
1707 hook = NULL;
1711 path = hook = NULL;
1719 *hookp = hook;
1788 hook_p hook;
1803 /* We have a segment, so look for a hook by that name */
1804 hook = ng_findhook(node, segment);
1808 if (hook == NULL || NG_HOOK_PEER(hook) == NULL ||
1809 NG_HOOK_NOT_VALID(hook) ||
1810 NG_HOOK_NOT_VALID(NG_HOOK_PEER(hook))) {
1821 * *** Idea.. store an ng_ID_t in each hook and use that
1822 * instead of the direct hook in this crawl?
1825 if ((node = NG_PEER_NODE(hook)))
1837 if (hook != NULL) {
1838 *lasthook = NG_HOOK_PEER(hook);
2211 * Reference to destination rcv hook if relevant.
2229 hook_p hook;
2250 hook = NGI_HOOK(item);
2251 /* Valid hook and mbuf are mandatory for data. */
2253 KASSERT(hook != NULL, ("ng_snd_item: hook for data is NULL"));
2261 * writer semantics. Similarly, the node may say one hook always
2266 (hook && (hook->hk_flags & HK_FORCE_WRITER))) {
2277 if ((flags & NG_QUEUE) || (hook && (hook->hk_flags & HK_QUEUE))) {
2279 } else if (hook && (hook->hk_flags & HK_TO_INBOUND) &&
2296 ((node->nd_flags & NGF_HI_STACK) || (hook &&
2297 (hook->hk_flags & HK_HI_STACK)))))
2360 * to run it on the appropriate node/hook.
2366 hook_p hook;
2376 NGI_GET_HOOK(item, hook); /* clears stored hook */
2389 KASSERT(hook != NULL, ("ng_apply_item: hook for data is NULL"));
2390 if (NG_HOOK_NOT_VALID(hook) ||
2398 * Give preference to the hook over-ride method.
2400 if ((!(rcvdata = hook->hk_rcvdata)) &&
2401 (!(rcvdata = NG_HOOK_NODE(hook)->nd_type->rcvdata))) {
2406 error = (*rcvdata)(hook, item);
2409 if (hook && NG_HOOK_NOT_VALID(hook)) {
2411 * The hook has been zapped then we can't use it.
2415 NG_HOOK_UNREF(hook);
2416 hook = NULL;
2434 * reference a node or hook that has just been
2440 error = ng_generic_msg(node, item, hook);
2443 if (((!hook) || (!(rcvmsg = hook->hk_rcvmsg))) &&
2450 error = (*rcvmsg)(node, item, hook);
2465 /* Same is about some internal functions and invalid hook. */
2466 if (hook && NG_HOOK_NOT_VALID(hook) &&
2477 (*NGI_FN(item))(node, hook, NGI_ARG1(item),
2481 error = (*NGI_FN2(item))(node, item, hook);
2489 if (hook)
2490 NG_HOOK_UNREF(hook);
2582 hook_p hook;
2590 if ((hook = ng_findhook(here, rmh->ourhook)) != NULL)
2591 ng_destroy_hook(hook);
2618 hook_p hook;
2638 LIST_FOREACH(hook, &here->nd_hooks, hk_hooks) {
2646 if (NG_HOOK_NOT_VALID(hook))
2648 strcpy(link->ourhook, NG_HOOK_NAME(hook));
2649 strcpy(link->peerhook, NG_PEER_HOOK_NAME(hook));
2650 if (NG_PEER_NODE_NAME(hook)[0] != '\0')
2652 NG_PEER_NODE_NAME(hook));
2654 NG_PEER_NODE(hook)->nd_type->name);
2655 link->nodeinfo.id = ng_node2ID(NG_PEER_NODE(hook));
2656 link->nodeinfo.hooks = NG_PEER_NODE(hook)->nd_numhooks;
3038 /* If we still have a node or hook referenced... */
3264 dumphook (hook_p hook, char *file, int line)
3266 printf("hook: name %s, %d refs, Last touched:\n",
3267 _NG_HOOK_NAME(hook), hook->hk_refs);
3269 hook->lastfile, hook->lastline);
3362 hook_p hook;
3365 SLIST_FOREACH(hook, &ng_allhooks, hk_all) {
3367 dumphook(hook, NULL, 0);
3510 printf("item already has hook"); \
3511 kdb_enter(KDB_WHY_NETGRAPH, "has hook"); \
3528 * Note that the hook loaded is the REMOTE hook.
3597 ng_address_hook(node_p here, item_p item, hook_p hook, ng_ID_t retaddr)
3604 * Since a hook holds a reference on its node, once we know
3609 if ((hook == NULL) || NG_HOOK_NOT_VALID(hook) ||
3610 NG_HOOK_NOT_VALID(peer = NG_HOOK_PEER(hook)) ||
3611 NG_NODE_NOT_VALID(peernode = NG_PEER_NODE(hook))) {
3636 hook_p hook = NULL;
3644 error = ng_path2noderef(here, address, &dest, &hook);
3650 if (hook)
3651 NGI_SET_HOOK(item, hook);
3681 * Possibly indicate an arrival hook too.
3682 * Useful for removing that hook :-)
3685 ng_package_msg_self(node_p here, hook_p hook, struct ng_mesg *msg)
3703 if (hook) {
3704 NG_HOOK_REF(hook);
3705 NGI_SET_HOOK(item, hook);
3717 ng_send_fn(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2)
3720 return ng_send_fn1(node, hook, fn, arg1, arg2, NG_NOFLAGS);
3724 ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2,
3735 if (hook) {
3736 NG_HOOK_REF(hook);
3737 NGI_SET_HOOK(item, hook);
3754 ng_send_fn2(node_p node, hook_p hook, item_p pitem, ng_item_fn2 *fn, void *arg1,
3779 if (hook) {
3780 NG_HOOK_REF(hook);
3781 NGI_SET_HOOK(item, hook);
3806 ng_callout(struct callout *c, node_p node, hook_p hook, int ticks,
3817 if (hook) {
3818 NG_HOOK_REF(hook);
3819 NGI_SET_HOOK(item, hook);