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

Function ng_add_hook

freebsd/netgraph/ng_base.c:1063–1115  ·  view source on GitHub ↗

* Add an unconnected hook to a node. Only used internally. * Assumes node is locked. (XXX not yet true ) */

Source from the content-addressed store, hash-verified

1061 * Assumes node is locked. (XXX not yet true )
1062 */
1063static int
1064ng_add_hook(node_p node, const char *name, hook_p *hookp)
1065{
1066 hook_p hook;
1067 int error = 0;
1068
1069 /* Check that the given name is good */
1070 if (name == NULL) {
1071 TRAP_ERROR();
1072 return (EINVAL);
1073 }
1074 if (ng_findhook(node, name) != NULL) {
1075 TRAP_ERROR();
1076 return (EEXIST);
1077 }
1078
1079 /* Allocate the hook and link it up */
1080 NG_ALLOC_HOOK(hook);
1081 if (hook == NULL) {
1082 TRAP_ERROR();
1083 return (ENOMEM);
1084 }
1085 hook->hk_refs = 1; /* add a reference for us to return */
1086 hook->hk_flags = HK_INVALID;
1087 hook->hk_peer = &ng_deadhook; /* start off this way */
1088 hook->hk_node = node;
1089 NG_NODE_REF(node); /* each hook counts as a reference */
1090
1091 /* Set hook name */
1092 strlcpy(NG_HOOK_NAME(hook), name, NG_HOOKSIZ);
1093
1094 /*
1095 * Check if the node type code has something to say about it
1096 * If it fails, the unref of the hook will also unref the node.
1097 */
1098 if (node->nd_type->newhook != NULL) {
1099 if ((error = (*node->nd_type->newhook)(node, hook, name))) {
1100 NG_HOOK_UNREF(hook); /* this frees the hook */
1101 return (error);
1102 }
1103 }
1104 /*
1105 * The 'type' agrees so far, so go ahead and link it in.
1106 * We'll ask again later when we actually connect the hooks.
1107 */
1108 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks);
1109 node->nd_numhooks++;
1110 NG_HOOK_REF(hook); /* one for the node */
1111
1112 if (hookp)
1113 *hookp = hook;
1114 return (0);
1115}
1116
1117/*
1118 * Find a hook

Callers 2

ng_con_nodesFunction · 0.70
ng_mkpeerFunction · 0.70

Calls 2

ng_findhookFunction · 0.70
strlcpyFunction · 0.50

Tested by

no test coverage detected