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

Function ng_destroy_hook

freebsd/netgraph/ng_base.c:1157–1230  ·  view source on GitHub ↗

* Destroy a hook * * As hooks are always attached, this really destroys two hooks. * The one given, and the one attached to it. Disconnect the hooks * from each other first. We reconnect the peer hook to the 'dead' * hook so that it can still exist after we depart. We then * send the peer its own destroy message. This ensures that we only * interact with the peer's structures when it is loc

Source from the content-addressed store, hash-verified

1155 * on error detection and must be able to handle any such stage.
1156 */
1157void
1158ng_destroy_hook(hook_p hook)
1159{
1160 hook_p peer;
1161 node_p node;
1162
1163 if (hook == &ng_deadhook) { /* better safe than sorry */
1164 printf("ng_destroy_hook called on deadhook\n");
1165 return;
1166 }
1167
1168 /*
1169 * Protect divorce process with mutex, to avoid races on
1170 * simultaneous disconnect.
1171 */
1172 TOPOLOGY_WLOCK();
1173
1174 hook->hk_flags |= HK_INVALID;
1175
1176 peer = NG_HOOK_PEER(hook);
1177 node = NG_HOOK_NODE(hook);
1178
1179 if (peer && (peer != &ng_deadhook)) {
1180 /*
1181 * Set the peer to point to ng_deadhook
1182 * from this moment on we are effectively independent it.
1183 * send it an rmhook message of its own.
1184 */
1185 peer->hk_peer = &ng_deadhook; /* They no longer know us */
1186 hook->hk_peer = &ng_deadhook; /* Nor us, them */
1187 if (NG_HOOK_NODE(peer) == &ng_deadnode) {
1188 /*
1189 * If it's already divorced from a node,
1190 * just free it.
1191 */
1192 TOPOLOGY_WUNLOCK();
1193 } else {
1194 TOPOLOGY_WUNLOCK();
1195 ng_rmhook_self(peer); /* Send it a surprise */
1196 }
1197 NG_HOOK_UNREF(peer); /* account for peer link */
1198 NG_HOOK_UNREF(hook); /* account for peer link */
1199 } else
1200 TOPOLOGY_WUNLOCK();
1201
1202 TOPOLOGY_NOTOWNED();
1203
1204 /*
1205 * Remove the hook from the node's list to avoid possible recursion
1206 * in case the disconnection results in node shutdown.
1207 */
1208 if (node == &ng_deadnode) { /* happens if called from ng_con_nodes() */
1209 return;
1210 }
1211 LIST_REMOVE(hook, hk_hooks);
1212 node->nd_numhooks--;
1213 if (node->nd_type->disconnect) {
1214 /*

Callers 8

ng_rmnodeFunction · 0.70
ng_bypassFunction · 0.70
ng_con_part3Function · 0.70
ng_con_part2Function · 0.70
ng_con_nodesFunction · 0.70
ng_mkpeerFunction · 0.70
ng_rmhook_part2Function · 0.70
ng_generic_msgFunction · 0.70

Calls 2

ng_rmhook_selfFunction · 0.70
printfFunction · 0.50

Tested by

no test coverage detected