⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tae_sa.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 2 页
字号:
    } /********************************************************************************* io_init - create the IPC mechanism at the SNMP master agent** This routine,** RETURNS: OK or ERROR.**/ LOCAL STATUS io_init ( void )    {    struct sockaddr_in axSock;    int                true = TRUE;    /*  create the AgentX socket  */    if ((tae_sa_socket = socket (AF_INET, SOCK_STREAM, 0)) == -1)        {        tae_sa_log (TAE_SA_ERROR, "Unable to create AgentX subagent socket\n");        return (ERROR);        }    axSock.sin_family = AF_INET;    axSock.sin_port = htons (ENVOY_AX_MASTER_PORT);    axSock.sin_addr.s_addr = INADDR_ANY;    if (connect (tae_sa_socket, (struct sockaddr *)&axSock, sizeof (axSock)) == -1)        {        tae_sa_log (TAE_SA_ERROR, "Can't connect to AgentX master socket\n");        return (ERROR);        }    if (ioctl(tae_sa_socket, FIONBIO, (int) &true) == -1)        {        tae_sa_log (TAE_SA_ERROR, "Can't set socket to non-blocking mode\n");        return (ERROR);        }     return (OK);    } /********************************************************************************* sa_init - Start a session and register the subtree** This function does the start-up process of the AgentX subagent.  This* consists of opening a session with the master agent using the socket* created earlier, then sending a registration request.  If this function* returns without error then the registration was successful.** RETURNS: OK or ERROR.**/ LOCAL int sa_init (void)    {    EBUFFER_T          ebuff;    OBJ_ID_T           obj;    int                used, got, retval;    fd_set             ready;    struct timeval     tvp;    OBJ_ID_T          *mib_subtrees;     /* Set up various AgentX variables & structures */    envoy_ax_sa_state_init(&tae_sa_sasb);    envoy_ax_chunk_init(&tae_sa_myfoo.chunk);    tae_sa_myfoo.ref_count = 0;    tae_sa_myfoo.open_done = 0;    tae_sa_packet_id = 1;     /* Issue the AgentX Open command  */     tae_sa_myfoo.op = ENVOY_AX_OPEN;     EBufferInitialize(&ebuff);    obj.num_components = 0;    obj.component_list = 0;     if (envoy_ax_pkt_create_open(&ebuff, 1, tae_sa_byte_order,                                 0, tae_sa_timeout, 0, (bits8_t *) 0, &obj))        {        tae_sa_log (TAE_SA_ERROR, "Unable to create open packet\n");        EBufferClean(&ebuff);        envoy_ax_chunk_clean(&tae_sa_myfoo.chunk);        return (ERROR);        }     MEMCPY(tae_sa_buf, EBufferStart(&ebuff), EBufferUsed(&ebuff));    used = EBufferUsed(&ebuff);        EBufferClean(&ebuff);     if (send(tae_sa_socket, tae_sa_buf, used, 0) == -1)        {        tae_sa_log (TAE_SA_ERROR, "Couldn't send the AgentX open command\n");        envoy_ax_chunk_clean(&tae_sa_myfoo.chunk);        return (ERROR);        }     /* After we send the open command, we have to get a response and     * run it through the engine.  */    do        {        tvp.tv_sec = 1;        tvp.tv_usec = 0;          FD_ZERO(&ready);        FD_SET(tae_sa_socket, &ready);        if ((retval = select(tae_sa_socket+1, &ready, 0, 0, &tvp)) < 0)            {            tae_sa_log (TAE_SA_ERROR, "Select failed...\n");            close(tae_sa_socket);            return (ERROR);            }         if ((retval) && FD_ISSET(tae_sa_socket, &ready))            {            do                {                if ((got = recv(tae_sa_socket, (char *) tae_sa_buf,                                sizeof(tae_sa_buf), 0)) == -1)                    {                    if (errno != EWOULDBLOCK)                        {                        close(tae_sa_socket);                        envoy_ax_chunk_clean(&tae_sa_myfoo.chunk);                        tae_sa_log (TAE_SA_ERROR,                            "Error in receiving OPEN response\n");                        return (ERROR);                        }                    break;                    }                envoy_ax_chunk_handler(tae_sa_buf, got,                                       envoy_ax_sa_handler, &tae_sa_myfoo.chunk,                                       &tae_sa_sasb, taeSaAdmin,                                       taeSaSend, taeSaFree,                                       taeSaAdd, &tae_sa_myfoo);                }            while (1);            }        else            break;        }    while(1);      /* Register with the Master agent */    tae_sa_myfoo.op = ENVOY_AX_REGISTER;     mib_subtrees = get_mib_registration_subtrees ();    if (mib_subtrees)        {        obj.num_components = mib_subtrees->num_components;        obj.component_list = mib_subtrees->component_list;        }    else        {        printf ("\nHouston, we have a problem....\n");        obj.num_components = 0;        }         while (obj.num_components > 0)        {         EBufferInitialize(&ebuff);         if (envoy_ax_pkt_create_registrations(&ebuff, 1, ENVOY_AX_REGISTER,                                              (tae_sa_byte_order | tae_sa_ndc),                                              tae_sa_packet_id++, tae_sa_session_id,                                              tae_sa_timeout, tae_sa_priority,                                              0, mib_subtrees, 0, sizeof(tae_sa_context),                                              (bits8_t *) tae_sa_context) != 0)            {            tae_sa_log (TAE_SA_ERROR, "Couldn't create registration packet\n");            EBufferClean(&ebuff);            envoy_ax_chunk_clean(&tae_sa_myfoo.chunk);            close(tae_sa_socket);            return(ERROR);            }         MEMCPY(tae_sa_buf, EBufferStart(&ebuff), EBufferUsed(&ebuff));        used = EBufferUsed(&ebuff);         EBufferClean(&ebuff);         if (send(tae_sa_socket, tae_sa_buf, used, 0) == -1)            {            tae_sa_log (TAE_SA_ERROR, "Sending registration packet failed!\n");            EBufferClean(&ebuff);            envoy_ax_chunk_clean(&tae_sa_myfoo.chunk);            close(tae_sa_socket);            return(ERROR);            }         EBufferClean(&ebuff);         /* Again, we need to check our responses... */        do            {            tvp.tv_sec = 1;            tvp.tv_usec = 0;             FD_ZERO(&ready);            FD_SET(tae_sa_socket, &ready);            if ((retval = select(tae_sa_socket+1, &ready, 0, 0, &tvp)) < 0)                {                tae_sa_log (TAE_SA_ERROR, "Select failed...\n");                close(tae_sa_socket);                }             if ((retval) && FD_ISSET(tae_sa_socket, &ready))                {                do                    {                    if ((got = recv(tae_sa_socket, (char *) tae_sa_buf,                                    sizeof(tae_sa_buf), 0)) == -1)                        {                        if (errno != EWOULDBLOCK)                            {                            close(tae_sa_socket);                            envoy_ax_chunk_clean(&tae_sa_myfoo.chunk);                            tae_sa_log (TAE_SA_ERROR,                                "Error in receiving REGISTER response\n");                            return (ERROR);                            }                        break;                        }                     envoy_ax_chunk_handler(tae_sa_buf, got,                                           envoy_ax_sa_handler,                                           &tae_sa_myfoo.chunk, &tae_sa_sasb,                                           taeSaAdmin, taeSaSend,                                           taeSaFree, taeSaAdd,                                           &tae_sa_myfoo);                    }                while (1);                }            else                break;            }            while(1);        mib_subtrees++;        obj.num_components = mib_subtrees->num_components;        obj.component_list = mib_subtrees->component_list;        }     /*     * At this point, we have reason to believe that we've opened our     * session and properly registered our subtree.  We can now go on     * to the main select() loop.     */     return (OK);    }  /********************************************************************************* sa_main - wait for connections and messages from the subagents** This routine calls axSubagentInit to open a session with the master agent* and register the subagents mib.  The task then sits in a select() loop on* the AgentX socket and waits for the master to send messages.** Messages received will be passed through to envoy_ax_chunk_handler().** RETURNS: N/A**/ LOCAL void sa_main (void)    {    EBUFFER_T               ebuff;    int                     socklive = 1;     EBufferInitialize(&ebuff);    EBufferClean(&ebuff);     while (socklive)        {        int got;        fd_set ready;         /* Set up the select call and then wait for a packet */        FD_ZERO(&ready);        FD_SET(tae_sa_socket, &ready);        if (select(tae_sa_socket+1, &ready, 0, 0, 0) < 0)            {            tae_sa_log (TAE_SA_ERROR, "Select failed ...\n");            socklive = 0;            continue;            }           /* If we receive anything, it's got to be for AgentX */        if (FD_ISSET(tae_sa_socket, &ready))            {            do                {                /* We've received data on our connection... */                if ((got = recv(tae_sa_socket, (char *)tae_sa_buf,                                sizeof(tae_sa_buf), 0)) == -1)                    {                    if (errno != EWOULDBLOCK)                        {                        close(tae_sa_socket);                        envoy_ax_chunk_clean(&tae_sa_myfoo.chunk);                        socklive = 0;                        }                    break;                    }                 if (envoy_ax_chunk_handler(tae_sa_buf, got,                                           envoy_ax_sa_handler,                                           &tae_sa_myfoo.chunk, &tae_sa_sasb,                                           taeSaAdmin, taeSaSend,                                           taeSaFree, taeSaAdd,                                           &tae_sa_myfoo))                    {                    close(tae_sa_socket);                    envoy_ax_chunk_clean(&tae_sa_myfoo.chunk);                    socklive = 0;                    break;                    }                } while (1);            }        }    }  /******************************************************************************** subagentTask - entry point for the axsub agent task** RETURNS: ERROR  on error else never returns.** NOMANUAL*/ LOCAL STATUS subagentTask (void)    {    if (io_init () == ERROR)        {        tae_sa_log (TAE_SA_ERROR, "Error in initializing AgentX subagent task\n");        return (ERROR);        }    envoy_init ();    if (SNMP_CoarseLock == NULL)        {        tae_sa_log (TAE_SA_ERROR, "Unable to create semaphores for TAE subagent\n");        return (ERROR);        }    if (sa_init () == ERROR)        {        tae_sa_log (TAE_SA_ERROR, "Could not initialize TAE subagent\n");        return (ERROR);        }    sa_main ();     /* If we ever return there must be an error */    return (ERROR);    }/******************************************************************************** tae_sa_init - initialize the TAE subagent** This routine initializes the TAE subagent. ** The <traceLevel> parameter specifies the level of messages logged* by the agent.** RETURNS: OK on successful initialization, otherwise ERROR.** NOMANUAL**/ LOCAL STATUS tae_sa_init    (    int                    traceLevel          /* trace level */    )    {     int    tmr_task_id;    int    sa_task_id;    tae_sa_trace_level = traceLevel;    tae_sa_wdid = wdCreate();    if (tae_sa_wdid == NULL)        {        tae_sa_log (TAE_SA_ERROR, "Unable to create TAE subagent wd timer\n");        return (ERROR);        }     tae_sa_sid = semBCreate (0, SEM_EMPTY);    if (tae_sa_sid == NULL)        {        tae_sa_log (TAE_SA_ERROR, "Unable to create TAE subagent timer semaphore\n");        return (ERROR);        }     tmr_task_id = taskSpawn("tTaeSaTmr", TIMER_PRI, 0, TIMER_STK, 		(FUNCPTR) timerTask, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);     if (tmr_task_id == ERROR)        {        tae_sa_log (TAE_SA_ERROR, "Unable to create TAE subagent timer task\n");        return (ERROR);        }    sa_task_id = taskSpawn ("tTaeSa", SUBAGENT_PRI, 0, SUBAGENT_STK,                (FUNCPTR) subagentTask, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);    if (sa_task_id == ERROR)        {        tae_sa_log (TAE_SA_ERROR, "Unable to create TAE subagent task\n");        return (ERROR);        }     return (OK);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -