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

📄 ax_ma.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 5 页
字号:
        getproc_got_empty(pktp, vbp);        break;    case VT_IPADDRESS:        MEMCPY(&(vbp->value_u.v_network_address),                &(rvbp->value_u.v_network_address), 4);	        getproc_good(pktp, vbp);	vbp->vb_data_flags_n_type = data_type;        break;    case VT_COUNTER64:#if !(INSTALL_ENVOY_SNMP_USE_V2_TYPES)	if (pktp->snmp_version == SNMP_VERSION_1)	    return(1);#endif        getproc_got_uint64(pktp, vbp, &(rvbp->value_u.v_counter64));        break;    case VT_ENDOFMIB:	nextproc_no_next(pktp, vbp);	break;    case VT_NOSUCHINS:	getproc_nosuchins(pktp, vbp);	break;    case VT_NOSUCHOBJ:	if (pktp->snmp_version == SNMP_VERSION_1) {	    pktp->pdu.std_pdu.error_status = NO_SUCH_NAME;	    pktp->pdu.std_pdu.error_index = vbp_to_index(pktp, vbp) + 1; 	    }	else	    vbp->vb_data_flags_n_type = VT_NOSUCHOBJ;	break;    default:        getproc_error(pktp, vbp, GEN_ERR);        break;    }return(0);}/****************************************************************************NAME: ax_prep_and_send_queryPURPOSE: Set up and send the query to the agentx sub agent.	 The processing is pretty much the same for all of the	 snmp requests so we have one routine with a small amount	 of pdu type specific info.PARAMETERS: SNMP_PKT_T * packet being processed	    VB_T       * var bind being processed	    bits8_t      type of the query to sendRETURNS: int 0 = success	    -1 = hard failure such as unable to allocate memory	     1 = unable to find session****************************************************************************/static int  ax_prep_and_send_query(SNMP_PKT_T *pktp,			 VB_T       *vbp,			 bits8_t     pdu_type,			 int         tcount,			 bits32_t    timeout){ENVOY_AX_PKT_T query_pkt;ENVOY_AX_SESSION_T *session;ENVOY_TIMER_32_T *tm32;int err_ret, send_stat;/* initialize the agentx packet structure */envoy_ax_pkt_init(&query_pkt);query_pkt.version        = ENVOY_AX_VERSION_1;query_pkt.type           = pdu_type;query_pkt.session_id     = vbp->vb_ml.ml_leaf->session_id;#ifdef ENVOY_AX_TRANSLATE_CONTEXTswitch (query_pkt.type) {    case ENVOY_AX_REGISTER:    case ENVOY_AX_UNREGISTER:    case ENVOY_AX_GET:    case ENVOY_AX_NEXT:    case ENVOY_AX_BULK:    case ENVOY_AX_TEST:    case ENVOY_AX_NOTIFY:    case ENVOY_AX_PING:    case ENVOY_AX_INDEX_ALLOCATE:    case ENVOY_AX_INDEX_DEALLOCATE:    case ENVOY_AX_ADD_AC:    case ENVOY_AX_REMOVE_AC:        ENVOY_AX_TRANSLATE_CONTEXT(pktp, &query_pkt);        /* And now check for EBuffer consistency in query_pkt.context */        if ((EBufferUsed(&query_pkt.context) != 0) && 	    (EBufferStart(&query_pkt.context) != 0))	    query_pkt.flags |= ENVOY_AX_BIT_NDC;        break;    default:        break;    }#endif/* build the timer block and space for the packet id */tm32 = (ENVOY_TIMER_32_T *)SNMP_memory_alloc(sizeof(ENVOY_TIMER_32_T));if (tm32 == 0)    return(-1);/* build the control block and attach it to the request list */tm32->id = ax_make_cb(pktp, vbp, tcount);if (tm32->id == 0) {    SNMP_memory_free(tm32);    return(-1);    }query_pkt.packet_id = tm32->id;/* Determine the transaction id.  If this is the first packet   the ax_trans_id field in the packet struct will be 0, we   then use the packet_id as the transaction id, otherwise   we use the transaction id from the packet */if (pktp->ax_trans_id == 0)    pktp->ax_trans_id = tm32->id;query_pkt.transaction_id = pktp->ax_trans_id;err_ret = 0;session = ax_session_find_index(query_pkt.session_id, &err_ret);if (session) {    /* calculate the timeout value it's the maximum of all of the values */    if (timeout < agentxDefaultTimeout)        timeout = agentxDefaultTimeout;    if (timeout < session->timeout)        timeout = session->timeout;    /* set up the flags and try to send the request */    query_pkt.flags |= session->flags;    send_stat = session->send(session->cookie, &query_pkt, vbp,                              envoy_ax_pkt_size(&query_pkt, vbp));    /* all done with the session, so we can release it */    ax_session_release(session);    if (send_stat == 0) {        /* if we didn't have any errors try to set up the timer */	envoy_tm_init(&(tm32->timer));	tm32->timer.cookie = tm32;	tm32->timer.handler = ax_timer;	if (envoy_tm_set(&(tm32->timer), timeout * 1000) == 0)	    return(0);        }    /* we weren't able to send the packet so set up the error code */    err_ret = -1;    }else {     /* no session, so set up the error code properly */    if (err_ret)        err_ret = -1;    else        err_ret = 1;    }/* We got here due to an error either in the send attempt or   when trying to set up the timer.  In both cases we clean   up the timer block and remove and cleanup the agentx control block */SNMP_memory_free(ax_uninstall_cb(tm32->id));SNMP_memory_free(tm32);return(err_ret);}/****************************************************************************NAME: ax_error_transferPURPOSE: move an error indication from the sub agent reply to the	 main snmp packet structurePARAMETERS: SNMP_PKT_T * snmp packet being processed	    VB_T       * var bind being processed	    bits32_t     error status	    bits32_t     error index	    int          number of varbinds we sent to the sub agentRETURNS: void****************************************************************************/static void  ax_error_transfer(SNMP_PKT_T *pktp,		    VB_T       *vbp,		    bits32_t    error_stat,		    bits32_t    error_index,		    int         tcount){VB_T *tvbp;bits32_t i;if (error_index > (bits32_t)tcount)    pktp->pdu.std_pdu.error_status = GEN_ERR;else {    /*      * Convert AgentX specific errors to GenErr     */    if (error_stat >= LAST_ERROR) error_stat = GEN_ERR;    pktp->pdu.std_pdu.error_status = error_stat;    /* Then translate the index back to the original range */    if (error_index == 0)        pktp->pdu.std_pdu.error_index = 0;    else  {        for (i = error_index - 1, tvbp = vbp; i; i--, tvbp = tvbp->vb_link)	    ;        pktp->pdu.std_pdu.error_index  = vbp_to_index(pktp, tvbp) + 1;        }    }}/****************************************************************************NAME: ax_getproc_endPURPOSE: The end section of an agentx getproc routine.  This	 is the routine that gets called when a response to	 a get query arrives.PARAMETERS: SNMP_PKT_T     * packet being processed	    VB_T           * var bind being processed	    int              number of varbinds that we sent	    ENVOY_AX_PKT_T * response packetRETURNS: void****************************************************************************/static void  ax_getproc_end(SNMP_PKT_T       *pktp,		 VB_T             *vbp,		 int               tcount,		 ENVOY_AX_PKT_T   *ax_pkt){VB_T *tvbp, *rvbp;/* mark the first vbp as being done so we won't trip over it later */getproc_good(pktp, vbp);/* If we had an error on the sub agent transfer it to the main   packet structure */if (ax_pkt->error_stat) {    ax_error_transfer(pktp, vbp, ax_pkt->error_stat,		      ax_pkt->error_index, tcount);    return;    }/* There wasn't an error, make sure we got the same number of vbs   back as we sent down */if (tcount != ax_pkt->data.proc_data.vbl_str.vbl_count) {    pktp->pdu.std_pdu.error_status = GEN_ERR;    return;    }for (tvbp = vbp, rvbp = ax_pkt->data.proc_data.vbl_str.vblist;     tvbp;     tvbp = tvbp->vb_link, rvbp++) {    if (ax_transfer_value(pktp, tvbp, rvbp)) {        pktp->pdu.std_pdu.error_status = NO_SUCH_NAME;	pktp->pdu.std_pdu.error_index  = vbp_to_index(pktp, tvbp) + 1;	tvbp->vb_flags |= VFLAG_GET_DONE;        }    }}/****************************************************************************\NOMANUALNAME: ax_getprocPURPOSE: Get method routine for use with agentx protocolPARAMETERS: OIDC_T       last subid matched, column tag	    int          number of subids in the instance	    OIDC_T     * array of subids in the instance	    SNMP_PKT_T * the packet being processed	    VB_T       * the var bind being processedRETURNS: void****************************************************************************/void  ax_getproc(OIDC_T      lastmatch,	     int         tcount,	     OIDC_T     *tlist,	     SNMP_PKT_T *pktp,	     VB_T       *vbp){VB_T *tvbp;bits32_t timeout;int vbcount;/* find all varbinds for this operation */group_by_session(pktp, vbp);timeout = vbp->vb_ml.ml_leaf->timeout;/* mark all but the first vbp as done */for(tvbp = vbp->vb_link, vbcount = 1; tvbp; tvbp = tvbp->vb_link, vbcount++) {    getproc_good(pktp, tvbp);    if (timeout < tvbp->vb_ml.ml_leaf->timeout)        timeout = tvbp->vb_ml.ml_leaf->timeout;    }/* try to send the request */if (ax_prep_and_send_query(pktp, vbp, ENVOY_AX_GET, vbcount, timeout))    /* We had an error while sending the request       tag the varbind as having an error */    getproc_error(pktp, vbp, GEN_ERR);return;}/****************************************************************************NAME: ax_nextproc_endPURPOSE: The end section of an agentx nextproc routine.  This is	 the routine that gets called when a response to a next	 query arrivesPARAMETERS: SNMP_PKT_T     * the packet being processed	    VB_T           * the var bind being processed	    int              number of varbinds that we sent	    ENVOY_AX_PKT_T * response packetRETURNS: void****************************************************************************/static void  ax_nextproc_end(SNMP_PKT_T     *pktp,		  VB_T           *vbp,		  int             tcount,		  ENVOY_AX_PKT_T *ax_pkt){VB_T *tvbp, *rvbp;/* mark the first vbp as being done so we won't trip over it later */nextproc_good(pktp, vbp);/* If we had an error on the sub agent transfer it to the main   packet structure */if (ax_pkt->error_stat) {    ax_error_transfer(pktp, vbp, ax_pkt->error_stat,		      ax_pkt->error_index, tcount);    return;    }/* There wasn't an error, make sure we got the same number of vbs   back as we sent down */if (tcount != ax_pkt->data.proc_data.vbl_str.vbl_count) {    pktp->pdu.std_pdu.error_status = GEN_ERR;    return;    }for (tvbp = vbp, rvbp = ax_pkt->data.proc_data.vbl_str.vblist;     tvbp;     tvbp = tvbp->vb_link, rvbp++) {#if (INSTALL_ENVOY_AGENTX_NEXT_CHECK)    /* Make sure the returned objects are within the boundary we       sent to the sub agent if the user wants */    if (tvbp->ax_search_end.num_components &&	(oidcmp2(tvbp->ax_search_end.num_components,		 tvbp->ax_search_end.component_list,		 rvbp->vb_obj_id.num_components,		 rvbp->vb_obj_id.component_list) <= 0)) {        nextproc_no_next(pktp, tvbp);	continue;        }#endif    if (ax_transfer_value(pktp, tvbp, rvbp)) {        nextproc_no_next(pktp, tvbp);	continue;        }        Clean_Obj_ID(&tvbp->vb_obj_id);    copy_object_id(&rvbp->vb_obj_id, &tvbp->vb_obj_id);    init_object_id(&rvbp->vb_obj_id);    tvbp->vb_flags |= VFLAG_NEXT_VCREQ;    /* reset the remaining object info to avoid accidents, this       means we don't know what the remaining info was but that's       okay because we know that the object was an agentx object       and we don't use that info on the master side */    init_object_id(&tvbp->vb_ml.ml_remaining_objid);    }}/****************************************************************************\NOMANUALNAME: ax_nextprocPURPOSE: Next method routine for use with agentx protocolPARAMETERS: OIDC_T       last subid matched, column tag	    int          number of subids in the instance	    OIDC_T     * array of subids in the instance	    SNMP_PKT_T * the packet being processed	    VB_T       * the var bind being processedRETURNS: void****************************************************************************/void  ax_nextproc(OIDC_T      lastmatch,	      int         tcount,	      OIDC_T     *tlist,	      SNMP_PKT_T *pktp,	      VB_T       *vbp){VB_T *tvbp;bits32_t timeout;int vbcount;/* find all varbinds for this operation */group_by_session(pktp, vbp);timeout = vbp->vb_ml.ml_leaf->timeout;/* mark all but the first vbp as done */for(tvbp = vbp->vb_link, vbcount = 1; tvbp; tvbp = tvbp->vb_link, vbcount++) {    nextproc_good(pktp, tvbp);    if (timeout < tvbp->vb_ml.ml_leaf->timeout)        timeout = tvbp->vb_ml.ml_leaf->timeout;    }/* Try to build and send the request, -1 is a gen_err, 0 is success

⌨️ 快捷键说明

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