FreeBSD/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.c
/*
 * Disconnect a hook and shutdown all tee nodes that were connected to that
 * hook.
 */
Disconnect a hook and shutdown all tee nodes that were connected to that
hook.
Disconnect a hook and shutdown all tee nodes that were connected to that hook .
int
ng_rmhook_tee_id(ng_ID_t node, const char *hook)
{
	struct ng_mesg *resp;
	struct hooklist *hooklist;
	u_int i;
	int first = 1;
	ng_ID_t next_node;
	const char *next_hook;
  again:
	if ((resp = ng_dialog_id(node, NGM_GENERIC_COOKIE, NGM_LISTHOOKS,
	    NULL, 0)) == NULL)
		return (0);
	hooklist = (struct hooklist *)(void *)resp->data;
	for (i = 0; i < hooklist->nodeinfo.hooks; i++)
		if (strcmp(hooklist->link[i].ourhook, hook) == 0)
			break;
	if (i == hooklist->nodeinfo.hooks) {
		free(resp);
		return (0);
	}
	next_node = 0;
	next_hook = NULL;
	if (strcmp(hooklist->link[i].nodeinfo.type, "tee") == 0) {
		if (strcmp(hooklist->link[i].peerhook, "left") == 0) {
			next_node = hooklist->link[i].nodeinfo.id;
			next_hook = "right";
		} else if (strcmp(hooklist->link[i].peerhook, "right") == 0) {
			next_node = hooklist->link[i].nodeinfo.id;
			next_hook = "left";
		}
	}
	free(resp);
	if (first) {
		ng_rmhook_id(node, hook);
		first = 0;
	} else {
		ng_shutdown_id(node);
	}
	if ((node = next_node) == 0)
		return (0);
	hook = next_hook;
	goto again;
}
int ng_rmhook_tee_id ( ng_ID_t node , const char * hook ) { struct ng_mesg * resp ; struct hooklist * hooklist ; u_int i ; int first = 1 ; ng_ID_t next_node ; const char * next_hook ; again : if ( ( resp = ng_dialog_id ( node , NGM_GENERIC_COOKIE , NGM_LISTHOOKS , NULL , 0 ) ) == NULL ) return ( 0 ) ; hooklist = ( struct hooklist * ) ( void * ) resp -> data ; for ( i = 0 ; i < hooklist -> nodeinfo . hooks ; i ++ ) if ( strcmp ( hooklist -> link [ i ] . ourhook , hook ) == 0 ) break ; if ( i == hooklist -> nodeinfo . hooks ) { free ( resp ) ; return ( 0 ) ; } next_node = 0 ; next_hook = NULL ; if ( strcmp ( hooklist -> link [ i ] . nodeinfo . type , " " ) == 0 ) { if ( strcmp ( hooklist -> link [ i ] . peerhook , " " ) == 0 ) { next_node = hooklist -> link [ i ] . nodeinfo . id ; next_hook = " " ; } else if ( strcmp ( hooklist -> link [ i ] . peerhook , " " ) == 0 ) { next_node = hooklist -> link [ i ] . nodeinfo . id ; next_hook = " " ; } } free ( resp ) ; if ( first ) { ng_rmhook_id ( node , hook ) ; first = 0 ; } else { ng_shutdown_id ( node ) ; } if ( ( node = next_node ) == 0 ) return ( 0 ) ; hook = next_hook ; goto again ; }
Disconnect a hook and shutdown all tee nodes that were connected to that
 hook.
Disconnect a hook and shutdown all tee nodes that were connected to that hook .
/* if we have just shutdown a tee node, which had no other hooks
	 * connected, the node id may already be wrong here. */