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

📄 ax_sub.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  Copyright 2000-2005 Wind River Systems, Inc. *  All rights reserved.  Provided under license only. *  Distribution or other use of this software is only *  permitted pursuant to the terms of a license agreement *  from Wind River Systems (and is otherwise prohibited). *  Refer to that license agreement for terms of use. *//* ax_sub.c  - default IO routines for the SNMP AgentX subagent */#include <copyright_wrs.h>/*modification history-------------------------01e,19apr05,job  update copyright notices01d,19oct04,job  add include line for selectLib.h01c,01dec03,job  update copyright information01b,17sep03,ten  Set ax_timeout to 2 seconds01a,29Nov00,tneale Created for AgentX subagent*//* * $Log: ax_sub.c,v $ * Revision 1.4  2002/08/26 20:31:06  josh * modifications to the code to eliminate warnings from Diab compiler * * Revision 1.3  2002/06/20 15:21:04  meister * Fixed some function storage class compiler warnings * (static/non-static inconsistencies) * * Revision 1.2  2002/06/06 21:11:42  tneale * Changed names of the #defines for master IP address and registration OID * * Revision 1.1  2002/06/05 19:48:09  tneale * Added dynamic configuration of AgentX subagent.  Moved ax_sub.c to the ax_sub directory * * Revision 1.2  2001/11/08 22:18:29  meister * rework pathnames * * Revision 1.1.1.1  2001/11/05 17:47:49  tneale * Tornado shuffle * * Revision 1.2  2001/04/16 19:38:42  josh * merging the kingfisher branch onto the trunk * * Revision 1.1.2.2  2001/03/12 22:11:31  tneale * Updated copyright * * Revision 1.1.2.1  2000/12/05 22:08:03  tneale * AgentX subagent support code * * *//* * This module implements the I/O routines used by the SNMP AgentX subagent.* agent.  All incoming messages from the AgentX master agent will be * processed in an auxiliary task, 'tAxSub'.  *  * When 'tSnmpd' spawns 'tAxSub', it assigns snmpAxSubagentTask() to* manage the process.  This function first initializes the subagent by* opening a session with the master agent and registering the mib* tree that this subagent will be responsible for.  The subtree is* specified by the OID which the subagent send to the master at* registration.  Thereafter, when the master agent receives an SNMP* request regarding that subtree it will send the request to this* subagent.** The subagent then waits on the socket to receive messages from the * master agent.  Any SNMP request message subsequently received will * result in a call to envoy_ax_chunk_handler() to allow for processing * of chunked * data (since we're using TCP, there's no guarantee that a * request will be sent in a single packet).* */#include <msgQLib.h>#include <inetLib.h>#include <semLib.h>#include <taskLib.h>#include <selectLib.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/vxagent/axCfg.h>#include <wrn/wm/snmp/vxagent/snmpdLib.h>/* defines */#define TIME                    20    /* Timeout for masterIpcSend */#define SUBAGENT_PRIO           151   /* tMonQue priority */#define SUBAGENT_STACK_SIZE     5000  /* tMonQue stacksize */#define SUBAGENT_OPTS           0     /* tMonQue options *//* Locals  */typedef struct ax_foo_s {    bits16_t                    ref_count;    ENVOY_AX_CHUNK_T            chunk;    char                       *dest_name;    bits8_t                     op;    boolean_t                   open_done;} ax_foo_t;static int axSocket;unsigned char rcvBuf[2048];bits32_t                        ax_packet_id = 1;ENVOY_AX_SA_SB_T                ax_sasb;ax_foo_t                        ax_myfoo;char     *ax_destination      = 0;char     *ax_context          = 0;bits8_t   ax_ndc              = 0;inaddr_t  ax_dest_addr        = 0;bits32_t  ax_session_id       = 0;bits8_t   ax_timeout          = 2;bits8_t   ax_priority         = 128;bits8_t   ax_byte_order       = 0;static char *ax_strings[] = {  "none", "open", "close",  "register", "unregister", "get",    "next",  "bulk", "test", "commit", "undo",     "cleanup",    "notify", "ping",  "allocate index", "deallocate index", "add ac", "remove ac", "response" };/* forward declarations */LOCAL void axSubAdmin (ptr_t cookie, ptr_t axPkt);LOCAL void axSubAdd (ptr_t cookie);LOCAL void axSubFree (ptr_t cookie, int errorStat);LOCAL int axSubSend (ptr_t cookie, ptr_t pAxPkt,                      ptr_t pVbList, ALENGTH_T need);LOCAL void snmpAxSubagentTask (void);/* This is the root of the AgentX subagent agent's mib tree  */extern MIBNODE_T                axsub_root_node;int envoy_ax_sa_mib_root_node (ptr_t cookie, SNMP_PKT_T *pktp){        pktp->mib_root = &axsub_root_node;        return (0);}/********************************************************************************* axSubagentIoInit - create the IPC mechanism at the SNMP master agent** This routine, called from snmpIoInit(), creates the SNMP subagent agent side* of the inter-process communication (IPC) mechanism used to carry messages* between AgentX subagents and the master agent.  In this implementation,* axSubagentIoInit() opens a TCP socket and connects to the master agent* through it.  The subagent does this prior to sending any control messages* or otherwise passing AgentX traffic to the master agent.** The socket created by axSubagentIoInit() is used by 'tAxSub'. The purpose of* 'tAxSub' is to open a session with the master agent and register the objects * this subagent will be responsible for.  The task then waits for incoming * messages from the AgentX master and passes the packets off to the handler as * necessary.** RETURNS: OK or ERROR.**/STATUS axSubagentIoInit ( void )    {    struct sockaddr_in axSock;    int                true = TRUE;        /*  create the AgentX socket  */    if ((axSocket = socket (AF_INET, SOCK_STREAM, 0)) == -1)        {        snmpdLog (SNMP_ERROR, "Unable to create AgentX subagent socket\n");        return (ERROR);        }        axSock.sin_family = AF_INET;    axSock.sin_port = htons (ENVOY_AX_MASTER_PORT);    if ((axSock.sin_addr.s_addr=inet_addr(WMSNMP_AXMAST_IP_ADDRESS))==ERROR)        {        snmpdLog (SNMP_ERROR, "AgentX subagent error: unknown server\n");        return (ERROR);        }    if (connect (axSocket, (struct sockaddr *)&axSock, sizeof (axSock)) == -1)        {        snmpdLog (SNMP_ERROR, "Can't connect to AgentX master socket\n");        return (ERROR);        }    if (ioctl(axSocket, FIONBIO, (int) &true) == -1)         {        snmpdLog (SNMP_ERROR, "Can't set socket to non-blocking mode\n");        return (ERROR);        }    return (OK);    }/********************************************************************************* snmpAxSubagentSpawn - spawn 'tAxSub' to run snmpAxSaMonitor()** This function spawns the 'tAxSub' task to run snmpAgentXTask(), a function * that waits on the AgentX socket.  The snmpAgentXTask() starts by registering* the subagents mib tree with then master agent.  It then accepts incoming * packets and, if they are SNMP request PDUs it processes them by calling * envoy_ax_chunk_handler().** RETURNS: N/A.**/void snmpAxSubagentSpawn (void)    {    if (taskSpawn ("tAxSub", SUBAGENT_PRIO, SUBAGENT_OPTS, SUBAGENT_STACK_SIZE,                    (FUNCPTR) snmpAxSubagentTask, 0, 0, 0, 0,                   0, 0, 0, 0, 0, 0) == ERROR)        snmpdLog (SNMP_ERROR, "Error in spawning AgentX subagent task\n");    return;    } /********************************************************************************* axSubagentInit - 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.**/static int axSubagentInit ()    {    EBUFFER_T          ebuff;    OIDC_T             oidc[WMSNMP_AXSUB_REGOID_LEN+1] =                             WMSNMP_AXSUB_REGOID_LIST;    OBJ_ID_T           obj;    int                used, got, retval;    fd_set             ready;    struct timeval     tvp;     /* Set up various AgentX variables & structures */    envoy_ax_sa_state_init(&ax_sasb);    envoy_ax_chunk_init(&ax_myfoo.chunk);    ax_myfoo.ref_count = 0;    ax_myfoo.open_done = 0;    ax_packet_id = 1;     /* Issue the AgentX Open command  */     ax_myfoo.op = ENVOY_AX_OPEN;     EBufferInitialize(&ebuff);    obj.num_components = 0;    obj.component_list = 0;     if (envoy_ax_pkt_create_open(&ebuff, 1, ax_byte_order,                                  0, ax_timeout, 0, (bits8_t *) 0, &obj))         {        snmpdLog (SNMP_ERROR, "Unable to create open packet\n");        EBufferClean(&ebuff);        envoy_ax_chunk_clean(&ax_myfoo.chunk);        return (ERROR);        }     MEMCPY(rcvBuf, EBufferStart(&ebuff), EBufferUsed(&ebuff));    used = EBufferUsed(&ebuff);         EBufferClean(&ebuff);     if (send(axSocket, (char *) rcvBuf, used, 0) == -1)         {        snmpdLog (SNMP_ERROR, "Couldn't send the AgentX open command\n");        envoy_ax_chunk_clean(&ax_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);

⌨️ 快捷键说明

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