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