MCPcopy Index your code
hub / github.com/F-Stack/f-stack / ng_make_node_common

Function ng_make_node_common

freebsd/netgraph/ng_base.c:641–694  ·  view source on GitHub ↗

* Generic node creation. Called by node initialisation for externally * instantiated nodes (e.g. hardware, sockets, etc ). * The returned node has a reference count of 1. */

Source from the content-addressed store, hash-verified

639 * The returned node has a reference count of 1.
640 */
641int
642ng_make_node_common(struct ng_type *type, node_p *nodepp)
643{
644 node_p node;
645
646 /* Require the node type to have been already installed */
647 if (ng_findtype(type->name) == NULL) {
648 TRAP_ERROR();
649 return (EINVAL);
650 }
651
652 /* Make a node and try attach it to the type */
653 NG_ALLOC_NODE(node);
654 if (node == NULL) {
655 TRAP_ERROR();
656 return (ENOMEM);
657 }
658 node->nd_type = type;
659#ifdef VIMAGE
660 node->nd_vnet = curvnet;
661#endif
662 NG_NODE_REF(node); /* note reference */
663 type->refs++;
664
665 NG_QUEUE_LOCK_INIT(&node->nd_input_queue);
666 STAILQ_INIT(&node->nd_input_queue.queue);
667 node->nd_input_queue.q_flags = 0;
668
669 /* Initialize hook list for new node */
670 LIST_INIT(&node->nd_hooks);
671
672 /* Get an ID and put us in the hash chain. */
673 IDHASH_WLOCK();
674 for (;;) { /* wrap protection, even if silly */
675 node_p node2 = NULL;
676 node->nd_ID = V_nextID++; /* 137/sec for 1 year before wrap */
677
678 /* Is there a problem with the new number? */
679 NG_IDHASH_FIND(node->nd_ID, node2); /* already taken? */
680 if ((node->nd_ID != 0) && (node2 == NULL)) {
681 break;
682 }
683 }
684 V_ng_nodes++;
685 if (V_ng_nodes * 2 > V_ng_ID_hmask)
686 ng_ID_rehash();
687 LIST_INSERT_HEAD(&V_ng_ID_hash[NG_IDHASH_FN(node->nd_ID)], node,
688 nd_idnodes);
689 IDHASH_WUNLOCK();
690
691 /* Done */
692 *nodepp = node;
693 return (0);
694}
695
696/*
697 * Forceably start the shutdown process on a node. Either call

Callers 15

ng_ipfw_mod_eventFunction · 0.70
ng_ether_attachFunction · 0.70
ng_gif_attachFunction · 0.70
ng_attach_cntlFunction · 0.70
ng_ksocket_acceptFunction · 0.70
ng_make_nodeFunction · 0.70
ng_h4_openFunction · 0.50
ubt_attachFunction · 0.50
ng_btsocket_hci_raw_initFunction · 0.50

Calls 2

ng_findtypeFunction · 0.70
ng_ID_rehashFunction · 0.70

Tested by

no test coverage detected