Lines Matching refs:hook
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);
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
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()
1046 ng_unref_hook(hook_p hook) in ng_unref_hook() argument
1049 if (hook == &ng_deadhook) in ng_unref_hook()
1052 if (refcount_release(&hook->hk_refs)) { /* we were the last */ in ng_unref_hook()
1053 if (_NG_HOOK_NODE(hook)) /* it'll probably be ng_deadnode */ in ng_unref_hook()
1054 _NG_NODE_UNREF((_NG_HOOK_NODE(hook))); in ng_unref_hook()
1055 NG_FREE_HOOK(hook); in ng_unref_hook()
1066 hook_p hook; in ng_add_hook() local
1080 NG_ALLOC_HOOK(hook); in ng_add_hook()
1081 if (hook == NULL) { in ng_add_hook()
1085 hook->hk_refs = 1; /* add a reference for us to return */ in ng_add_hook()
1086 hook->hk_flags = HK_INVALID; in ng_add_hook()
1087 hook->hk_peer = &ng_deadhook; /* start off this way */ in ng_add_hook()
1088 hook->hk_node = node; in ng_add_hook()
1092 strlcpy(NG_HOOK_NAME(hook), name, NG_HOOKSIZ); in ng_add_hook()
1099 if ((error = (*node->nd_type->newhook)(node, hook, name))) { in ng_add_hook()
1100 NG_HOOK_UNREF(hook); /* this frees the hook */ in ng_add_hook()
1108 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks); in ng_add_hook()
1110 NG_HOOK_REF(hook); /* one for the node */ in ng_add_hook()
1113 *hookp = hook; in ng_add_hook()
1127 hook_p hook; in ng_findhook() local
1131 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) { in ng_findhook()
1132 if (NG_HOOK_IS_VALID(hook) && in ng_findhook()
1133 (strcmp(NG_HOOK_NAME(hook), name) == 0)) in ng_findhook()
1134 return (hook); in ng_findhook()
1158 ng_destroy_hook(hook_p hook) in ng_destroy_hook() argument
1163 if (hook == &ng_deadhook) { /* better safe than sorry */ in ng_destroy_hook()
1174 hook->hk_flags |= HK_INVALID; in ng_destroy_hook()
1176 peer = NG_HOOK_PEER(hook); in ng_destroy_hook()
1177 node = NG_HOOK_NODE(hook); in ng_destroy_hook()
1186 hook->hk_peer = &ng_deadhook; /* Nor us, them */ in ng_destroy_hook()
1198 NG_HOOK_UNREF(hook); /* account for peer link */ in ng_destroy_hook()
1211 LIST_REMOVE(hook, hk_hooks); in ng_destroy_hook()
1220 (*node->nd_type->disconnect) (hook); in ng_destroy_hook()
1227 _NG_HOOK_NODE(hook) = &ng_deadnode; in ng_destroy_hook()
1229 NG_HOOK_UNREF(hook); /* Account for linkage (in list) to node */ in ng_destroy_hook()
1341 ng_con_part3(node_p node, item_p item, hook_p hook) in ng_con_part3() argument
1354 if (NG_HOOK_NODE(hook) == &ng_deadnode) { in ng_con_part3()
1365 if (hook->hk_node->nd_type->connect) { in ng_con_part3()
1366 if ((error = (*hook->hk_node->nd_type->connect) (hook))) { in ng_con_part3()
1367 ng_destroy_hook(hook); /* also zaps peer */ in ng_con_part3()
1377 hook->hk_flags &= ~HK_INVALID; in ng_con_part3()
1384 ng_con_part2(node_p node, item_p item, hook_p hook) in ng_con_part2() argument
1399 if (ng_findhook(node, NG_HOOK_NAME(hook)) != NULL) { in ng_con_part2()
1401 ng_destroy_hook(hook); /* should destroy peer too */ in ng_con_part2()
1412 if ((error = (*node->nd_type->newhook)(node, hook, in ng_con_part2()
1413 hook->hk_name))) { in ng_con_part2()
1414 ng_destroy_hook(hook); /* should destroy peer too */ in ng_con_part2()
1424 hook->hk_node = node; /* just overwrite ng_deadnode */ in ng_con_part2()
1426 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks); in ng_con_part2()
1428 NG_HOOK_REF(hook); /* one for the node */ in ng_con_part2()
1439 if (hook->hk_node->nd_type->connect) { in ng_con_part2()
1440 if ((error = (*hook->hk_node->nd_type->connect) (hook))) { in ng_con_part2()
1441 ng_destroy_hook(hook); /* also zaps peer */ in ng_con_part2()
1451 peer = hook->hk_peer; in ng_con_part2()
1455 ng_destroy_hook(hook); in ng_con_part2()
1463 ng_destroy_hook(hook); /* also zaps peer */ in ng_con_part2()
1466 hook->hk_flags &= ~HK_INVALID; /* need both to be able to work */ in ng_con_part2()
1482 hook_p hook; in ng_con_nodes() local
1488 if ((error = ng_add_hook(node, name, &hook))) /* gives us a ref */ in ng_con_nodes()
1494 ng_destroy_hook(hook); /* XXX check ref counts so far */ in ng_con_nodes()
1495 NG_HOOK_UNREF(hook); /* including our ref */ in ng_con_nodes()
1500 hook2->hk_peer = hook; /* Link the two together */ in ng_con_nodes()
1501 hook->hk_peer = hook2; in ng_con_nodes()
1502 NG_HOOK_REF(hook); /* Add a ref for the peer to each*/ in ng_con_nodes()
1515 ng_destroy_hook(hook); /* also zaps peer */ in ng_con_nodes()
1518 NG_HOOK_UNREF(hook); /* Let each hook go if it wants to */ in ng_con_nodes()
1620 ng_rmhook_part2(node_p node, hook_p hook, void *arg1, int arg2) in ng_rmhook_part2() argument
1622 ng_destroy_hook(hook); in ng_rmhook_part2()
1627 ng_rmhook_self(hook_p hook) in ng_rmhook_self() argument
1630 node_p node = NG_HOOK_NODE(hook); in ng_rmhook_self()
1635 error = ng_send_fn(node, hook, &ng_rmhook_part2, NULL, 0); in ng_rmhook_self()
1657 char *node, *path, *hook; in ng_path_parse() local
1701 for (hook = path, k = 0; path[k]; k++) in ng_path_parse()
1703 hook = NULL; in ng_path_parse()
1707 path = hook = NULL; in ng_path_parse()
1715 *hookp = hook; in ng_path_parse()
1784 hook_p hook; in ng_path2noderef() local
1800 hook = ng_findhook(node, segment); in ng_path2noderef()
1804 if (hook == NULL || NG_HOOK_PEER(hook) == NULL || in ng_path2noderef()
1805 NG_HOOK_NOT_VALID(hook) || in ng_path2noderef()
1806 NG_HOOK_NOT_VALID(NG_HOOK_PEER(hook))) { in ng_path2noderef()
1821 if ((node = NG_PEER_NODE(hook))) in ng_path2noderef()
1833 if (hook != NULL) { in ng_path2noderef()
1834 *lasthook = NG_HOOK_PEER(hook); in ng_path2noderef()
2225 hook_p hook; in ng_snd_item() local
2246 hook = NGI_HOOK(item); in ng_snd_item()
2249 KASSERT(hook != NULL, ("ng_snd_item: hook for data is NULL")); in ng_snd_item()
2262 (hook && (hook->hk_flags & HK_FORCE_WRITER))) { in ng_snd_item()
2273 if ((flags & NG_QUEUE) || (hook && (hook->hk_flags & HK_QUEUE))) { in ng_snd_item()
2275 } else if (hook && (hook->hk_flags & HK_TO_INBOUND) && in ng_snd_item()
2292 ((node->nd_flags & NGF_HI_STACK) || (hook && in ng_snd_item()
2293 (hook->hk_flags & HK_HI_STACK))))) in ng_snd_item()
2363 hook_p hook; in ng_apply_item() local
2373 NGI_GET_HOOK(item, hook); /* clears stored hook */ in ng_apply_item()
2386 KASSERT(hook != NULL, ("ng_apply_item: hook for data is NULL")); in ng_apply_item()
2387 if (NG_HOOK_NOT_VALID(hook) || in ng_apply_item()
2397 if ((!(rcvdata = hook->hk_rcvdata)) && in ng_apply_item()
2398 (!(rcvdata = NG_HOOK_NODE(hook)->nd_type->rcvdata))) { in ng_apply_item()
2403 error = (*rcvdata)(hook, item); in ng_apply_item()
2406 if (hook && NG_HOOK_NOT_VALID(hook)) { in ng_apply_item()
2412 NG_HOOK_UNREF(hook); in ng_apply_item()
2413 hook = NULL; in ng_apply_item()
2437 error = ng_generic_msg(node, item, hook); in ng_apply_item()
2440 if (((!hook) || (!(rcvmsg = hook->hk_rcvmsg))) && in ng_apply_item()
2447 error = (*rcvmsg)(node, item, hook); in ng_apply_item()
2463 if (hook && NG_HOOK_NOT_VALID(hook) && in ng_apply_item()
2474 (*NGI_FN(item))(node, hook, NGI_ARG1(item), in ng_apply_item()
2478 error = (*NGI_FN2(item))(node, item, hook); in ng_apply_item()
2486 if (hook) in ng_apply_item()
2487 NG_HOOK_UNREF(hook); in ng_apply_item()
2579 hook_p hook; in ng_generic_msg() local
2587 if ((hook = ng_findhook(here, rmh->ourhook)) != NULL) in ng_generic_msg()
2588 ng_destroy_hook(hook); in ng_generic_msg()
2615 hook_p hook; in ng_generic_msg() local
2635 LIST_FOREACH(hook, &here->nd_hooks, hk_hooks) { in ng_generic_msg()
2643 if (NG_HOOK_NOT_VALID(hook)) in ng_generic_msg()
2645 strcpy(link->ourhook, NG_HOOK_NAME(hook)); in ng_generic_msg()
2646 strcpy(link->peerhook, NG_PEER_HOOK_NAME(hook)); in ng_generic_msg()
2647 if (NG_PEER_NODE_NAME(hook)[0] != '\0') in ng_generic_msg() local
2649 NG_PEER_NODE_NAME(hook)); in ng_generic_msg()
2651 NG_PEER_NODE(hook)->nd_type->name); in ng_generic_msg()
2652 link->nodeinfo.id = ng_node2ID(NG_PEER_NODE(hook)); in ng_generic_msg()
2653 link->nodeinfo.hooks = NG_PEER_NODE(hook)->nd_numhooks; in ng_generic_msg()
3257 dumphook (hook_p hook, char *file, int line) in dumphook() argument
3260 _NG_HOOK_NAME(hook), hook->hk_refs); in dumphook()
3262 hook->lastfile, hook->lastline); in dumphook()
3355 hook_p hook; in ng_dumphooks() local
3358 SLIST_FOREACH(hook, &ng_allhooks, hk_all) { in ng_dumphooks()
3360 dumphook(hook, NULL, 0); in ng_dumphooks()
3577 ng_address_hook(node_p here, item_p item, hook_p hook, ng_ID_t retaddr) in ng_address_hook() argument
3589 if ((hook == NULL) || NG_HOOK_NOT_VALID(hook) || in ng_address_hook()
3590 NG_HOOK_NOT_VALID(peer = NG_HOOK_PEER(hook)) || in ng_address_hook()
3591 NG_NODE_NOT_VALID(peernode = NG_PEER_NODE(hook))) { in ng_address_hook()
3616 hook_p hook = NULL; in ng_address_path() local
3624 error = ng_path2noderef(here, address, &dest, &hook); in ng_address_path()
3630 if (hook) in ng_address_path()
3631 NGI_SET_HOOK(item, hook); in ng_address_path()
3665 ng_package_msg_self(node_p here, hook_p hook, struct ng_mesg *msg) in ng_package_msg_self() argument
3683 if (hook) { in ng_package_msg_self()
3684 NG_HOOK_REF(hook); in ng_package_msg_self()
3685 NGI_SET_HOOK(item, hook); in ng_package_msg_self()
3697 ng_send_fn(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2) in ng_send_fn() argument
3700 return ng_send_fn1(node, hook, fn, arg1, arg2, NG_NOFLAGS); in ng_send_fn()
3704 ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2, in ng_send_fn1() argument
3715 if (hook) { in ng_send_fn1()
3716 NG_HOOK_REF(hook); in ng_send_fn1()
3717 NGI_SET_HOOK(item, hook); in ng_send_fn1()
3734 ng_send_fn2(node_p node, hook_p hook, item_p pitem, ng_item_fn2 *fn, void *arg1, in ng_send_fn2() argument
3759 if (hook) { in ng_send_fn2()
3760 NG_HOOK_REF(hook); in ng_send_fn2()
3761 NGI_SET_HOOK(item, hook); in ng_send_fn2()
3786 ng_callout(struct callout *c, node_p node, hook_p hook, int ticks, in ng_callout() argument
3797 if (hook) { in ng_callout()
3798 NG_HOOK_REF(hook); in ng_callout()
3799 NGI_SET_HOOK(item, hook); in ng_callout()