MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_con_nodes

Function ng_con_nodes

freebsd/netgraph/ng_base.c:1477–1521  ·  view source on GitHub ↗

* Connect this node with another node. We assume that this node is * currently locked, as we are only called from an NGM_CONNECT message. */

Source from the content-addressed store, hash-verified

1475 * currently locked, as we are only called from an NGM_CONNECT message.
1476 */
1477static int
1478ng_con_nodes(item_p item, node_p node, const char *name,
1479 node_p node2, const char *name2)
1480{
1481 int error;
1482 hook_p hook;
1483 hook_p hook2;
1484
1485 if (ng_findhook(node2, name2) != NULL) {
1486 return(EEXIST);
1487 }
1488 if ((error = ng_add_hook(node, name, &hook))) /* gives us a ref */
1489 return (error);
1490 /* Allocate the other hook and link it up */
1491 NG_ALLOC_HOOK(hook2);
1492 if (hook2 == NULL) {
1493 TRAP_ERROR();
1494 ng_destroy_hook(hook); /* XXX check ref counts so far */
1495 NG_HOOK_UNREF(hook); /* including our ref */
1496 return (ENOMEM);
1497 }
1498 hook2->hk_refs = 1; /* start with a reference for us. */
1499 hook2->hk_flags = HK_INVALID;
1500 hook2->hk_peer = hook; /* Link the two together */
1501 hook->hk_peer = hook2;
1502 NG_HOOK_REF(hook); /* Add a ref for the peer to each*/
1503 NG_HOOK_REF(hook2);
1504 hook2->hk_node = &ng_deadnode;
1505 strlcpy(NG_HOOK_NAME(hook2), name2, NG_HOOKSIZ);
1506
1507 /*
1508 * Queue the function above.
1509 * Procesing continues in that function in the lock context of
1510 * the other node.
1511 */
1512 if ((error = ng_send_fn2(node2, hook2, item, &ng_con_part2, NULL, 0,
1513 NG_NOFLAGS))) {
1514 printf("failed in ng_con_nodes(): %d\n", error);
1515 ng_destroy_hook(hook); /* also zaps peer */
1516 }
1517
1518 NG_HOOK_UNREF(hook); /* Let each hook go if it wants to */
1519 NG_HOOK_UNREF(hook2);
1520 return (error);
1521}
1522
1523/*
1524 * Make a peer and connect.

Callers 1

ng_generic_msgFunction · 0.70

Calls 6

ng_findhookFunction · 0.70
ng_add_hookFunction · 0.70
ng_destroy_hookFunction · 0.70
ng_send_fn2Function · 0.70
strlcpyFunction · 0.50
printfFunction · 0.50

Tested by

no test coverage detected