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()
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()
1070 hook_p hook; in ng_add_hook() local
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()
1096 strlcpy(NG_HOOK_NAME(hook), name, NG_HOOKSIZ); 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()
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()
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()
1215 LIST_REMOVE(hook, hk_hooks); 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
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
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()
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()
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()
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()
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()
1661 char *node, *path, *hook; in ng_path_parse() local
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
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()
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()
2229 hook_p hook; in ng_snd_item() local
2250 hook = NGI_HOOK(item); in ng_snd_item()
2253 KASSERT(hook != NULL, ("ng_snd_item: hook for data is NULL")); 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()
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()
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()
2415 NG_HOOK_UNREF(hook); in ng_apply_item()
2416 hook = NULL; 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()
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()
3264 dumphook (hook_p hook, char *file, int line) in dumphook() argument
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()
3597 ng_address_hook(node_p here, item_p item, hook_p hook, ng_ID_t retaddr) in ng_address_hook() argument
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()
3685 ng_package_msg_self(node_p here, hook_p hook, struct ng_mesg *msg) in ng_package_msg_self() argument
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()