* Instantiate a node of the requested type */
| 592 | * Instantiate a node of the requested type |
| 593 | */ |
| 594 | int |
| 595 | ng_make_node(const char *typename, node_p *nodepp) |
| 596 | { |
| 597 | struct ng_type *type; |
| 598 | int error; |
| 599 | |
| 600 | /* Check that the type makes sense */ |
| 601 | if (typename == NULL) { |
| 602 | TRAP_ERROR(); |
| 603 | return (EINVAL); |
| 604 | } |
| 605 | |
| 606 | /* Locate the node type. If we fail we return. Do not try to load |
| 607 | * module. |
| 608 | */ |
| 609 | if ((type = ng_findtype(typename)) == NULL) |
| 610 | return (ENXIO); |
| 611 | |
| 612 | /* |
| 613 | * If we have a constructor, then make the node and |
| 614 | * call the constructor to do type specific initialisation. |
| 615 | */ |
| 616 | if (type->constructor != NULL) { |
| 617 | if ((error = ng_make_node_common(type, nodepp)) == 0) { |
| 618 | if ((error = ((*type->constructor)(*nodepp))) != 0) { |
| 619 | NG_NODE_UNREF(*nodepp); |
| 620 | } |
| 621 | } |
| 622 | } else { |
| 623 | /* |
| 624 | * Node has no constructor. We cannot ask for one |
| 625 | * to be made. It must be brought into existence by |
| 626 | * some external agency. The external agency should |
| 627 | * call ng_make_node_common() directly to get the |
| 628 | * netgraph part initialised. |
| 629 | */ |
| 630 | TRAP_ERROR(); |
| 631 | error = EINVAL; |
| 632 | } |
| 633 | return (error); |
| 634 | } |
| 635 | |
| 636 | /* |
| 637 | * Generic node creation. Called by node initialisation for externally |
no test coverage detected