FreeBSD/sys/netgraph/bluetooth/socket/ng_btsocket_sco.c
/*
 * Route cleanup task. Gets scheduled when hook is disconnected. Here we 
 * will find all sockets that use "invalid" hook and disconnect them.
 */
Route cleanup task. Gets scheduled when hook is disconnected. Here we
will find all sockets that use "invalid" hook and disconnect them.
Route cleanup task . Gets scheduled when hook is disconnected . Here we will find all sockets that use " invalid " hook and disconnect them .
static void
ng_btsocket_sco_rtclean(void *context, int pending)
{
	ng_btsocket_sco_pcb_p		pcb = NULL, pcb_next = NULL;
	ng_btsocket_sco_rtentry_p	rt = NULL;
	mtx_lock(&ng_btsocket_sco_sockets_mtx);
	for(pcb = LIST_FIRST(&ng_btsocket_sco_sockets); pcb != NULL; ) {
		mtx_lock(&pcb->pcb_mtx);
		pcb_next = LIST_NEXT(pcb, next);
		if (pcb->rt != NULL &&
		    pcb->rt->hook != NULL && NG_HOOK_NOT_VALID(pcb->rt->hook)) {
			if (pcb->flags & NG_BTSOCKET_SCO_TIMO)
				ng_btsocket_sco_untimeout(pcb);
			pcb->rt = NULL;
			pcb->so->so_error = ENETDOWN;
			pcb->state = NG_BTSOCKET_SCO_CLOSED;
			soisdisconnected(pcb->so);
		}
		mtx_unlock(&pcb->pcb_mtx);
		pcb = pcb_next;
	}
	mtx_unlock(&ng_btsocket_sco_sockets_mtx);
	mtx_lock(&ng_btsocket_sco_rt_mtx);
	for (rt = LIST_FIRST(&ng_btsocket_sco_rt); rt != NULL; ) {
		ng_btsocket_sco_rtentry_p	rt_next = LIST_NEXT(rt, next);
		if (rt->hook != NULL && NG_HOOK_NOT_VALID(rt->hook)) {
			LIST_REMOVE(rt, next);
			NG_HOOK_SET_PRIVATE(rt->hook, NULL);
			NG_HOOK_UNREF(rt->hook); 
			bzero(rt, sizeof(*rt));
			free(rt, M_NETGRAPH_BTSOCKET_SCO);
		}
		rt = rt_next;
	}
	mtx_unlock(&ng_btsocket_sco_rt_mtx);
}
static void ng_btsocket_sco_rtclean ( void * context , int pending ) { ng_btsocket_sco_pcb_p pcb = NULL , pcb_next = NULL ; ng_btsocket_sco_rtentry_p rt = NULL ; mtx_lock ( & ng_btsocket_sco_sockets_mtx ) ; for ( pcb = LIST_FIRST ( & ng_btsocket_sco_sockets ) ; pcb != NULL ; ) { mtx_lock ( & pcb -> pcb_mtx ) ; pcb_next = LIST_NEXT ( pcb , next ) ; if ( pcb -> rt != NULL && pcb -> rt -> hook != NULL && NG_HOOK_NOT_VALID ( pcb -> rt -> hook ) ) { if ( pcb -> flags & NG_BTSOCKET_SCO_TIMO ) ng_btsocket_sco_untimeout ( pcb ) ; pcb -> rt = NULL ; pcb -> so -> so_error = ENETDOWN ; pcb -> state = NG_BTSOCKET_SCO_CLOSED ; soisdisconnected ( pcb -> so ) ; } mtx_unlock ( & pcb -> pcb_mtx ) ; pcb = pcb_next ; } mtx_unlock ( & ng_btsocket_sco_sockets_mtx ) ; mtx_lock ( & ng_btsocket_sco_rt_mtx ) ; for ( rt = LIST_FIRST ( & ng_btsocket_sco_rt ) ; rt != NULL ; ) { ng_btsocket_sco_rtentry_p rt_next = LIST_NEXT ( rt , next ) ; if ( rt -> hook != NULL && NG_HOOK_NOT_VALID ( rt -> hook ) ) { LIST_REMOVE ( rt , next ) ; NG_HOOK_SET_PRIVATE ( rt -> hook , NULL ) ; NG_HOOK_UNREF ( rt -> hook ) ; bzero ( rt , sizeof ( * rt ) ) ; free ( rt , M_NETGRAPH_BTSOCKET_SCO ) ; } rt = rt_next ; } mtx_unlock ( & ng_btsocket_sco_rt_mtx ) ; }
Route cleanup task.
Route cleanup task .
/*
	 * First disconnect all sockets that use "invalid" hook
	 */ /*
	 * Now cleanup routing table
	 */ /* Remove extra reference */