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

Function ng_con_part2

freebsd/netgraph/ng_base.c:1383–1471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1381}
1382
1383static int
1384ng_con_part2(node_p node, item_p item, hook_p hook)
1385{
1386 hook_p peer;
1387 int error = 0;
1388
1389 /*
1390 * When we run, we know that the node 'node' is locked for us.
1391 * Our caller has a reference on the hook.
1392 * Our caller has a reference on the node.
1393 * (In this case our caller is ng_apply_item() ).
1394 * The peer hook has a reference on the hook.
1395 * our node pointer points to the 'dead' node.
1396 * First check the hook name is unique.
1397 * Should not happen because we checked before queueing this.
1398 */
1399 if (ng_findhook(node, NG_HOOK_NAME(hook)) != NULL) {
1400 TRAP_ERROR();
1401 ng_destroy_hook(hook); /* should destroy peer too */
1402 printf("failed in ng_con_part2()\n");
1403 ERROUT(EEXIST);
1404 }
1405 /*
1406 * Check if the node type code has something to say about it
1407 * If it fails, the unref of the hook will also unref the attached node,
1408 * however since that node is 'ng_deadnode' this will do nothing.
1409 * The peer hook will also be destroyed.
1410 */
1411 if (node->nd_type->newhook != NULL) {
1412 if ((error = (*node->nd_type->newhook)(node, hook,
1413 hook->hk_name))) {
1414 ng_destroy_hook(hook); /* should destroy peer too */
1415 printf("failed in ng_con_part2()\n");
1416 ERROUT(error);
1417 }
1418 }
1419
1420 /*
1421 * The 'type' agrees so far, so go ahead and link it in.
1422 * We'll ask again later when we actually connect the hooks.
1423 */
1424 hook->hk_node = node; /* just overwrite ng_deadnode */
1425 NG_NODE_REF(node); /* each hook counts as a reference */
1426 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks);
1427 node->nd_numhooks++;
1428 NG_HOOK_REF(hook); /* one for the node */
1429
1430 /*
1431 * We now have a symmetrical situation, where both hooks have been
1432 * linked to their nodes, the newhook methods have been called
1433 * And the references are all correct. The hooks are still marked
1434 * as invalid, as we have not called the 'connect' methods
1435 * yet.
1436 * We can call the local one immediately as we have the
1437 * node locked, but we need to queue the remote one.
1438 */
1439 if (hook->hk_node->nd_type->connect) {
1440 if ((error = (*hook->hk_node->nd_type->connect) (hook))) {

Callers

nothing calls this directly

Calls 4

ng_findhookFunction · 0.70
ng_destroy_hookFunction · 0.70
ng_send_fn2Function · 0.70
printfFunction · 0.50

Tested by

no test coverage detected