/********************************************************************** *%FUNCTION: relayHandlePADT *%ARGUMENTS: * iface -- interface on which packet was received * packet -- the PADT packet *%RETURNS: * Nothing *%DESCRIPTION: * Receives and processes a PADT packet. ***********************************************************************/ void relayHandlePADT(PPPoEInterface const *iface, PPPoEPacket *packet, int size) { SessionHash *sh; PPPoESession *ses; /* Destination address must be interface's MAC address */ if (memcmp(packet->ethHdr.h_dest, iface->mac, ETH_ALEN)) { return; } sh = findSession(packet->ethHdr.h_source, packet->session); if (!sh) { return; } /* Relay the PADT to the peer */ sh = sh->peer; ses = sh->ses; packet->session = sh->sesNum; memcpy(packet->ethHdr.h_source, sh->interface->mac, ETH_ALEN); memcpy(packet->ethHdr.h_dest, sh->peerMac, ETH_ALEN); sendPacket(NULL, sh->interface->sessionSock, packet, size); /* Destroy the session */ freeSession(ses, "Received PADT"); }
/** * abort a special sync session * * @param sessid - the session identity which to abort * * @return 0-SUCCESS, else failure */ int ZQSyncSessAbort( IN int sessid ) { int b_found = 0; PZQSESSION p_session = NULL; ZUtilStartQScan( &p_zqsync->sessQ ); while ( (p_session = (PZQSESSION)ZUtilGetNextQNode( &p_zqsync->sessQ )) ) { if ( p_session->i_id == sessid ) { b_found = 1; ZUtilRemoveNodeFromScan( &p_zqsync->sessQ, &p_session->node ); p_session->b_exit = 1; p_session->eventType = ZQSYNC_SESS_ABORT; ZUtilGenEvent( &p_session->event ); break; } } ZUtilStopQScan( &p_zqsync->sessQ ); if (b_found) { pthread_join( p_session->sessThr, NULL ); freeSession( &p_session ); return MPSYNC_SUCCESS; } return MPSYNC_FAILURE; }
/** * abort all sync sessions * * @return 0-SUCCESS, else failure */ int ZQSyncSessAbortAll( ) { PZQSESSION p_session = NULL; ZUtilStartQScan( &p_zqsync->sessQ ); while ( (p_session = (PZQSESSION)ZUtilGetNextQNode( &p_zqsync->sessQ )) ) { ZUtilRemoveNodeFromScan( &p_zqsync->sessQ, &p_session->node ); p_session->b_exit = 1; p_session->eventType = ZQSYNC_SESS_ABORT; ZUtilGenEvent( &p_session->event ); pthread_join( p_session->sessThr, NULL ); freeSession( &p_session ); } ZUtilStopQScan( &p_zqsync->sessQ ); return MPSYNC_SUCCESS; }
RTSMB_STATIC void rtsmb_srv_net_connection_close (PNET_SESSIONCTX pSCtx ) { RTSMB_DEBUG_OUTPUT_STR ("CloseConnection: socket ", RTSMB_DEBUG_TYPE_ASCII); RTSMB_DEBUG_OUTPUT_DINT (pSCtx->sock); RTSMB_DEBUG_OUTPUT_STR (" closed\n", RTSMB_DEBUG_TYPE_ASCII); SMBS_CloseSession( &(pSCtx->smbCtx) ); /* kill conection */ if (rtp_net_closesocket((RTP_SOCKET) pSCtx->sock)) { RTSMB_DEBUG_OUTPUT_STR("ERROR IN CLOSESOCKET\n", RTSMB_DEBUG_TYPE_ASCII); } freeSession (pSCtx); }
/********************************************************************** *%FUNCTION: cleanSessions *%ARGUMENTS: * None *%RETURNS: * Nothing *%DESCRIPTION: * Goes through active sessions and cleans sessions idle for longer * than IdleTimeout seconds. ***********************************************************************/ void cleanSessions(void) { PPPoESession *cur, *next; cur = ActiveSessions; while(cur) { next = cur->next; if (Epoch - cur->epoch > IdleTimeout) { /* Send PADT to each peer */ relaySendError(CODE_PADT, cur->acHash->sesNum, cur->acHash->interface, cur->acHash->peerMac, NULL, "RP-PPPoE: Relay: Session exceeded idle timeout"); relaySendError(CODE_PADT, cur->clientHash->sesNum, cur->clientHash->interface, cur->clientHash->peerMac, NULL, "RP-PPPoE: Relay: Session exceeded idle timeout"); freeSession(cur, "Idle Timeout"); } cur = next; } }
int main(int argc, char * argv[]){ returncode = 0; int status; struct tree * mib_tree; if(argv[1] != NULL && strcmp("-h", argv[1]) == 0 || strcmp("--help", argv[1]) == 0){ PrintHelp(); return 0; } if(argv[1] == NULL || argv[2] == NULL || argv[3] == NULL || argv[4]== NULL) { printf("Argument invalide (hostname, variable, warning, critical)\n"); } snmp_sess_init(&session); session.version = SNMP_VERSION_1; session.community = "public"; session.community_len = strlen(session.community); session.peername = argv[1]; session_handle = snmp_open(&session); add_mibdir("/usr/share/snmp/mibs/"); pdu = snmp_pdu_create(SNMP_MSG_GET); char variable[50]; snprintf(variable, 50, argv[2]); if(strcmp("CPULOAD", variable) == 0){ processSnmpGet("NETWORK-APPLIANCE-MIB::cpuBusyTimePerCent.0"); int result = atoi(resultString + 2); if(result >= atoi(argv[4])){ returncode = 2; } else if (result >= atoi(argv[3])){ returncode = 1; } printf("CPU Load : %d %% | cpu_load=%d %%\n", result, result); } else if(strcmp("PS", variable) == 0){ processSnmpGet("NETWORK-APPLIANCE-MIB::envFailedPowerSupplyCount.0"); int result = atoi(resultString); if(result >= atoi(argv[4])){ returncode = 2; } else if (result >= atoi(argv[3])){ returncode = 1; } printf("Failed Power Supply : %d\n", result); } else if(strcmp("FAN", variable) == 0){ processSnmpGet("NETWORK-APPLIANCE-MIB::envFailedFanCount.0"); int result = atoi(resultString); if(result >= atoi(argv[4])){ returncode = 2; } else if (result >= atoi(argv[3])){ returncode = 1; } printf("Failed FAN : %d\n", result); } else if(strcmp("TEMP", variable) == 0){ processSnmpGet("NETWORK-APPLIANCE-MIB::envOverTemperature.0"); int result = atoi(resultString); if(result == 2){ returncode = 2; printf("Over Temperatur : YES"); } else{ printf("Over Temperatur : NO"); } } else if(strcmp("NVRAM", variable) == 0){ processSnmpGet("NETWORK-APPLIANCE-MIB::nvramBatteryStatus.0"); int result = atoi(resultString); if(result > 1){ returncode = 2; } printf("NVRAM battery status: %d\n", result); } else{ printf("Invalid argument"); freeSession(); return 3; } freeSession(); return returncode; }
/** * start a sync session * * @param devId - device identity * @param p_dmcHandle - the special cp handle * @param dmsUDN - AL-1'S dms UDN * @param zqdUDN - AL-1'S zqdevice UDN * @param associated - to associate playlist id list, seprated by ',' * @param disassociated - to disassociate playlist id list, seprated by ',' * @param p_sessid - the created session identity * @return 0-SUCCESS, else failure */ int ZQSyncSessStart( IN int devId, IN void* p_dmcHandle, IN const char* dmsUDN, IN const char* zqdUDN, IN const char* associated, IN const char* disassociated, int* p_sessid) { PZQSESSION p_session = NULL; PZDEVICE p_device = NULL; int b_found = 0; int i_ret; if ( dmsUDN == NULL /* || zqdUDN == NULL*/ || p_dmcHandle == NULL ) { ZError( DBG_MISC, "Invalid paramters" ); return MPSYNC_FAILURE; } ZUtilStartQScan( &p_zqsync->sessQ ); while ( (p_session = (PZQSESSION)ZUtilGetNextQNode( &p_zqsync->sessQ )) ) { if ( !strcmp(p_session->p_device->psz_dmsUDN, dmsUDN) ) { b_found = 1; break; } } ZUtilStopQScan( &p_zqsync->sessQ ); if (b_found) { ZError( DBG_MISC, "This device is sync now." ); return MPSYNC_FAILURE; } p_device = ( PZDEVICE )malloc( sizeof(ZDEVICE) ); if (!p_device) { ZError( DBG_MISC, "Out of memory." ); return MPSYNC_FAILURE; } memset( p_device, 0, sizeof(ZDEVICE) ); p_device->i_id = devId; p_device->p_dmcHandle = p_dmcHandle; p_device->psz_dmsUDN = strdup( dmsUDN ); if ( zqdUDN ) p_device->psz_zqdUDN = strdup( zqdUDN ); if ( associated ) p_device->psz_associated = strdup( associated ); if ( disassociated ) p_device->psz_disassociated = strdup( disassociated ); p_session = ( PZQSESSION )malloc( sizeof(ZQSESSION) ); if (!p_session) { ZError( DBG_MISC, "Out of memory." ); return MPSYNC_FAILURE; } memset( p_session, 0, sizeof(ZQSESSION) ); p_session->p_device = p_device; p_session->b_exit = 0; ZUtilInitEvent( &p_session->event ); ZUtilAddHeadQ( &p_zqsync->sessQ, &p_session->node ); i_ret = pthread_create( &p_session->sessThr, NULL, SyncThreadMain, p_session ); if ( i_ret ) { ZError( DBG_MISC, "Thread create failure." ); freeSession( &p_session ); return MPSYNC_FAILURE; } p_session->i_id = (int)p_session->sessThr; return MPSYNC_SUCCESS; }
static void* SyncThreadMain( void* ctx ) { int i_id, i_ret, i; char psz_id[9]; IXML_Document *actResult = NULL; char* psz_class = NULL; PZQSESSION p_session = ( PZQSESSION) ctx; PZDEVICE p_device = p_session->p_device; PCP_DEV_NODE dmsNode = NULL; ZError( DBG_MISC, "Sync thread start..." ); p_session->i_id = (int)p_session->sessThr; PZQSYNCEVENT p_event = NULL; /*step 1: notify event*/ p_session->status = SESSION_STARTED; p_session->startTime = (int)time(NULL); p_session->eventType = ZQSYNC_SESS_UNKNOWN; if ( p_event == NULL ) { p_event = (PZQSYNCEVENT)malloc( sizeof(ZQSYNCEVENT) ); p_event->p_session = p_session; p_event->message = NULL; } p_event->event = ZQSYNC_SESS_START; p_zqsync->eventHandle( p_event ); /*step 2: disassociation process*/ ZError( DBG_MISC, "Disassociated precess start..." ); if ( p_device->psz_disassociated && strlen(p_device->psz_disassociated)>0 ) { p_session->psz_disassociated = p_device->psz_disassociated; while ( GetNextDisassociatedID( p_session, &i_id ) ) { GetCurrentDMS( p_session, p_event ); sprintf(psz_id, "%d", i_id); p_event->event = ZQSYNC_SESS_PROGRESS; p_session->i_currDisassociated = i_id; p_session->step = ZQSYNC_STEP_1; //Add by wfu begin p_event->event= ZQSYNC_STEP_1; //Add by wfu end p_zqsync->eventHandle( p_event ); i_ret = DMCCDSBrowse(p_device->p_dmcHandle, dmsNode, psz_id, "BrowseMetadata", "*", 0, 0, NULL, &actResult); if ( i_ret == -1 || !actResult ) { ZError(DBG_MISC, "Can't perform browse for %d containerID", i_id); } else {//we do real disassociate now psz_class = GetObjectClass( actResult ); ixmlDocument_free(actResult); actResult = NULL; if ( psz_class && !strcmp(UPNP_PLAYLIST_CONTAINER_CLASS, psz_class) ) {//real disassociate local if (deleteLocalPlaylistContainer( p_device, psz_id )==0) DisassignContainer( p_session, psz_id ); free( psz_class ); psz_class = NULL; }//end real disassociate local else ZError(DBG_MISC, "%d is not a object of class %s.", i_id, UPNP_PLAYLIST_CONTAINER_CLASS); }//end real disassociate //TODO:invoke zqdevice to update disassociated checkEvent( p_session, p_event ); } } ZError( DBG_MISC, "Handle exist items precess start..." ); /*step 3: handle exist items in local*/ p_event->event = ZQSYNC_SESS_PROGRESS; p_session->step = ZQSYNC_STEP_2; //Add by wfu begin p_event->step = ZQSYNC_STEP_2; //Add by wfu end. i = 0; while ( 1 ) { i_ret = ZDBGetNextPlaylist( p_zqsync->zDBHandle, p_device->psz_dmsUDN, i, psz_id ); ZError( DBG_MISC, "ZDBGetNextPlaylist return %d...", i_ret ); if ( i_ret ) break; ZError( DBG_MISC, "Process local playlist %s...", psz_id ); p_event->i_checked = atoi( psz_id ); p_zqsync->eventHandle( p_event ); GetCurrentDMS( p_session, p_event ); i_ret = checkLocalPlaylistContainer( p_device, dmsNode, psz_id ); if ( i_ret<0 ) { ZError( DBG_MISC, "check local playlist failure." ); } i++; checkEvent( p_session, p_event ); } ZError( DBG_MISC, "Associated preccess start..." ); /*step 4: association process*/ if ( p_device->psz_associated && strlen(p_device->psz_associated)>0 ) { p_session->psz_associated = p_device->psz_associated; while ( GetNextAssociatedID( p_session, &i_id ) ) { ZError( DBG_MISC, "Associated playlist -> %d...", i_id ); GetCurrentDMS( p_session, p_event ); sprintf(psz_id, "%d", i_id); p_event->event = ZQSYNC_SESS_PROGRESS; p_session->i_currDisassociated = i_id; p_session->step = ZQSYNC_STEP_3; //Add by wfu begin p_event->step = ZQSYNC_STEP_3; //Add by wfu end p_zqsync->eventHandle( p_event ); ZError( DBG_MISC, "Get metadata for playlist -> %d...", i_id ); i_ret = DMCCDSBrowse(p_device->p_dmcHandle, dmsNode, psz_id, "BrowseMetadata", "*", 0, 0, NULL, &actResult); if ( i_ret == -1 || !actResult ) { ZError(DBG_MISC, "Can't perform browse for %d containerID", i_id); } else {//we do real associate now psz_class = GetObjectClass( actResult ); if ( psz_class && !strcmp(UPNP_PLAYLIST_CONTAINER_CLASS, psz_class) ) {//real associate local addLocalPlaylist( p_device, psz_id, actResult ); free( psz_class ); psz_class = NULL; ixmlDocument_free(actResult); actResult = NULL; while ( 1 ) { GetCurrentDMS( p_session, p_event ); i_ret = addLocalPlaylistItems( p_device, psz_id, dmsNode ); if ( i_ret < 0 ) goto funcOut; else if ( i_ret == 1 ) break; checkEvent( p_session, p_event ); }//end while }//end real associate local else ZError(DBG_MISC, "%d is not a object of class %s.", i_id, UPNP_PLAYLIST_CONTAINER_CLASS); }//end real associate checkEvent( p_session, p_event ); } } ZError( DBG_MISC, "Associated preccess complete..." ); p_event->event = ZQSYNC_SESS_STOP; p_zqsync->eventHandle( p_event ); ZUtilRemoveQ( &p_zqsync->sessQ, &p_session->node ); freeSession( &p_session ); checkIsolatedAlbum( p_zqsync->zDBHandle ); funcOut: ZError( DBG_MISC, "sync exit..." ); if ( p_event ) { if ( p_event->message ) free(p_event->message); free( p_event ); } if ( actResult ) { ixmlDocument_free(actResult); actResult = NULL; } if ( psz_class ) free( psz_class ); return NULL; }
/** * Associate a new session with this instance of the filter. * * Create the file to log to and open it. * * @param instance The filter instance data * @param session The session itself * @return Session specific data for this session */ static void * newSession(FILTER *instance, SESSION *session) { TEE_INSTANCE *my_instance = (TEE_INSTANCE *) instance; TEE_SESSION *my_session; char *remote, *userName; if (strcmp(my_instance->service->name, session->service->name) == 0) { MXS_ERROR("%s: Recursive use of tee filter in service.", session->service->name); my_session = NULL; goto retblock; } HASHTABLE* ht = hashtable_alloc(100, simple_str_hash, strcmp); bool is_loop = detect_loops(my_instance, ht, session->service); hashtable_free(ht); if (is_loop) { MXS_ERROR("%s: Recursive use of tee filter in service.", session->service->name); my_session = NULL; goto retblock; } if ((my_session = calloc(1, sizeof(TEE_SESSION))) != NULL) { my_session->active = 1; my_session->residual = 0; my_session->tee_replybuf = NULL; my_session->client_dcb = session->client; my_session->instance = my_instance; my_session->client_multistatement = false; my_session->queue = NULL; spinlock_init(&my_session->tee_lock); if (my_instance->source && (remote = session_get_remote(session)) != NULL) { if (strcmp(remote, my_instance->source)) { my_session->active = 0; MXS_WARNING("Tee filter is not active."); } } userName = session_getUser(session); if (my_instance->userName && userName && strcmp(userName, my_instance->userName)) { my_session->active = 0; MXS_WARNING("Tee filter is not active."); } if (my_session->active) { DCB* dcb; SESSION* ses; FILTER_DEF* dummy; UPSTREAM* dummy_upstream; if ((dcb = dcb_clone(session->client)) == NULL) { freeSession(instance, (void *) my_session); my_session = NULL; MXS_ERROR("Creating client DCB for Tee " "filter failed. Terminating session."); goto retblock; } if ((dummy = filter_alloc("tee_dummy", "tee_dummy")) == NULL) { dcb_close(dcb); freeSession(instance, (void *) my_session); my_session = NULL; MXS_ERROR("tee: Allocating memory for " "dummy filter definition failed." " Terminating session."); goto retblock; } if ((ses = session_alloc(my_instance->service, dcb)) == NULL) { filter_free(dummy); dcb_close(dcb); freeSession(instance, (void *) my_session); my_session = NULL; MXS_ERROR("Creating client session for Tee " "filter failed. Terminating session."); goto retblock; } ss_dassert(ses->ses_is_child); dummy->obj = GetModuleObject(); dummy->filter = NULL; my_session->branch_session = ses; my_session->branch_dcb = dcb; my_session->dummy_filterdef = dummy; if ((dummy_upstream = filterUpstream( dummy, my_session, &ses->tail)) == NULL) { filter_free(dummy); closeSession(instance, (void*) my_session); dcb_close(dcb); free(my_session); MXS_ERROR("tee: Allocating memory for" "dummy upstream failed." " Terminating session."); return NULL; } ses->tail = *dummy_upstream; MySQLProtocol* protocol = (MySQLProtocol*) session->client->protocol; my_session->use_ok = protocol->client_capabilities & (1 << 6); free(dummy_upstream); } } retblock: return my_session; }
void deleteSession(Session* s) { freeSession(s); pthread_exit(NULL); }