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

📄 snmpnat.c

📁 nat PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 4 页
字号:
    bzero ((char *)&data, sizeof (NAT_TBL_ENTRY));    data.natIndex = *tlist;    for ( ; vbp; vbp = vbp->vb_link) 	{        switch (vbp->vb_ml.ml_last_match) 	    {            case LEAF_natSessionMaxIdleTime:                data.natSessionMaxIdleTime = vbp->value_u.v_number;                            varToSet |= NAT_SESS_MAX_IDLETIME;                break;            case LEAF_natUdpSessionMaxIdleTime:                data.natUdpSessionMaxIdleTime = vbp->value_u.v_number;                      varToSet |= NAT_UDP_SESS_MAX_IDLETIME;                break;            case LEAF_natIcmpSessionMaxIdleTime:                data.natIcmpSessionMaxIdleTime = vbp->value_u.v_number;                       varToSet |= NAT_ICMP_SESS_MAX_IDLETIME;                break;            case LEAF_natTcpUpSessionMaxIdleTime:                data.natTcpUpSessionMaxIdleTime = vbp->value_u.v_number;                        varToSet |= NAT_TCPUP_SESS_MAX_IDLETIME;                break;            case LEAF_natTcpDiscSessionMaxIdleTime:                data.natTcpDiscSessionMaxIdleTime = vbp->value_u.v_number;                       varToSet |= NAT_TCPDISC_SESS_MAX_IDLETIME;                break;            case LEAF_natTcpClosingSessionMaxIdleTime:                data.natTcpClosingSessionMaxIdleTime = vbp->value_u.v_number;                        varToSet |= NAT_TCPCLOS_SESS_MAX_IDLETIME;                break;            case LEAF_natTcpSyncSessionMaxIdleTime:                data.natTcpSyncSessionMaxIdleTime = vbp->value_u.v_number;                  varToSet |= NAT_TCPSYNC_SESS_MAX_IDLETIME;                break;            case LEAF_natLogMask:                data.natLogMask = vbp->value_u.v_number;                  varToSet |= NAT_LOG_MASK;                break;            case LEAF_natEnable:                data.natEnable = vbp->value_u.v_number;                    varToSet |= NAT_ENABLE;                break;            case LEAF_natDefXEnable:                data.natDefXEnable = vbp->value_u.v_number;                       varToSet |= NAT_DEF_X_ENABLE;                break;            case LEAF_natGlobalAddrFilter:                data.natGlobalAddrFilter = vbp->value_u.v_number;                    varToSet |= NAT_GLOBAL_ADDR_FILTER;                break;            case LEAF_natStaticBindEnable:                data.natStaticBindEnable = vbp->value_u.v_number;                   varToSet |= NAT_STATIC_BIND_ENABLE;                break;            default:                setproc_error(pktp, vbp, COMMIT_FAILED);                return;            }        setproc_good (pktp, vbp);        }                pVbpSaved->undoproc = (UNDOPROC_T *) natEntryUndo;    /* Call the m2 routine to do the commit */    if( m2NatTblEntrySet (&data , varToSet) != OK )        {        /*         * Commit failed so we should remove the undo buffer, else when         * the undo is done we might end up with an undo failed error         * instead of commit failed.         */        snmpVbPrivFree (pVbpSaved);        setproc_error (pktp, pVbpSaved, COMMIT_FAILED);        return;        }    }/*******************************************************************************  natEntryUndo -**  Undo routine for natEntry table **  Parameters to this routine are* *  <lastmatch> - the last oid component that was matched to get to this leaf.*  <tlist>     - count of components remaining in the unmatched portion i.e.*                the length of the instance portion.*  <tlist>     - ptr to the oid sequence remaining, i.e. the instance portion.*  <pktp>      - ptr to internal representation of the snmp pkt.*  <vbp>       - ptr to var bind being processed.**  RETURNS: N/A*/LOCAL void natEntryUndo    (    OIDC_T              lastmatch,    int                 tcount,    OIDC_T *            tlist,    SNMP_PKT_T *        pktp,    VB_T *              vbp    )    {    NAT_TBL_ENTRY *     pSetEntry = (NAT_TBL_ENTRY *)vbp->vb_priv;    int varToSet = 0;    if (pSetEntry == NULL)        {        goto goodReturn;        }    varToSet = (NAT_SESS_MAX_IDLETIME |                NAT_UDP_SESS_MAX_IDLETIME |                NAT_ICMP_SESS_MAX_IDLETIME |         	NAT_TCPUP_SESS_MAX_IDLETIME |                NAT_TCPDISC_SESS_MAX_IDLETIME |                 NAT_TCPCLOS_SESS_MAX_IDLETIME |                 NAT_TCPSYNC_SESS_MAX_IDLETIME | 	        NAT_LOG_MASK | NAT_ENABLE |                 NAT_STATIC_BIND_ENABLE | 	        NAT_DEF_X_ENABLE | 	        NAT_GLOBAL_ADDR_FILTER );    if (m2NatTblEntrySet (pSetEntry , varToSet) != OK )        {        undoproc_error (pktp, vbp, UNDO_FAILED);        return;        }goodReturn:    undoproc_good (pktp, vbp);    return;    } /****************************************************************************** *  natDescGetValue -  Routine to extract info from NAT_SCALARS structure * *  <lastmatch> - the last oid component that was matched to get to this leaf. *  <pktp>      - ptr to internal representation of the snmp pkt. *  <vbp>       - ptr to var bind being processed. *  <pData> - ptr to NAT_SCALARS structure containing the info required *                for this instance. * *  RETURNS: N/A */static int natDescGetValue    (    OIDC_T       lastmatch,    SNMP_PKT_T  *pktp,    VB_T        *vbp,    NAT_SCALARS *pData    )    {    int         length;    OCTET_T    *pBuf;    switch(lastmatch)         {        case LEAF_natNumber:            getproc_got_int32(pktp, vbp, pData->natNumber);            break;        case LEAF_natSessionNumber:            getproc_got_int32(pktp, vbp, pData->natSessionNumber);               break;        case LEAF_natSwVersion:            length = strlen ((char*) pData->natSwVersion);            pBuf = SNMP_memory_alloc (length);	    if (pBuf == NULL)	        {	        getproc_error (pktp, vbp, GEN_ERR);	        return (GEN_ERR);	        }	    MEMCPY (pBuf, pData->natSwVersion, length);	    getproc_got_string (pktp, vbp, length, pBuf, BFL_IS_DYNAMIC,	                        VT_STRING );            break;            	case LEAF_natPrRealmType:            length = strlen ((char*) pData->natPrRealmType);            pBuf = SNMP_memory_alloc (length);	    if (pBuf == NULL)	        {	        getproc_error (pktp, vbp, GEN_ERR);	        return (GEN_ERR);	        }	    MEMCPY (pBuf, pData->natPrRealmType, length);	    getproc_got_string (pktp, vbp, length, pBuf, BFL_IS_DYNAMIC,	                        VT_STRING );            break;        case LEAF_natExtRealmType:            length = strlen ((char*) pData->natExtRealmType);            pBuf = SNMP_memory_alloc (length);	    if (pBuf == NULL)	        {	        getproc_error (pktp, vbp, GEN_ERR);	        return (GEN_ERR);	        }	    MEMCPY (pBuf, pData->natExtRealmType, length);	    getproc_got_string (pktp, vbp, length, pBuf, BFL_IS_DYNAMIC,	                        VT_STRING );            break;        default:            return GEN_ERR;    }    return NO_ERROR;    }/*******************************************************************************  natDescGet -   Get method routine for  natDescriptor.* *  Parameters to this routine are* *  <lastmatch> - the last oid component that was matched to get to this leaf.*  <compc>     - count of components remaining in the unmatched portion i.e.*                the length of the instance portion.*  <compl>     - ptr to the oid sequence remaining, i.e. the instance portion.*  <pktp>      - ptr to internal representation of the snmp pkt.*  <vbp>       - ptr to var bind being processed.**  NOMANUAL**  RETURNS: N/A*/void natDescGet    (    OIDC_T      lastmatch,    int         tcount,    OIDC_T     *tlist,    SNMP_PKT_T *pktp,    VB_T       *vbp    )    {    NAT_SCALARS data;                                 int         error;    /* find all the varbinds that share the same getproc and instance */    group_by_getproc_and_instance (pktp, vbp, tcount, tlist);    /* check that the instance is exactly .0 */    if (!((tcount == 1) && (*tlist == 0)))        {        for ( ; vbp; vbp = vbp->vb_link)            {            getproc_nosuchins(pktp, vbp);	    }        return;        }    else        {        /* Zero out the structure */        bzero ((char *)&data, sizeof (data));        /* extract the values for all the objects in NAT_SCALARS */        if (m2NatScalarsGet (&data) != 0)     	    {            for ( ; vbp; vbp = vbp->vb_link)	        {                getproc_error(pktp, vbp, GEN_ERR);	        }            return;            }        else            {            /* retrieve all the values from the same data structure */            for ( ; vbp; vbp = vbp->vb_link)	        {                if ((error = natDescGetValue (vbp->vb_ml.ml_last_match,                     pktp, vbp, &data)) != NO_ERROR)	            {                    getproc_error(pktp, vbp, error);	            }                }            }        }    } /****************************************************************************** *  natBindEntryGetValue -  Routine to extract info from natBind Table * *  <lastmatch> - the last oid component that was matched to get to this leaf. *  <pktp>      - ptr to internal representation of the snmp pkt. *  <vbp>       - ptr to var bind being processed. *  <pData>     - ptr to NAT_BINDTBL_ENTRY structure containing the info  *                required for this instance. * *  RETURNS: N/A */static int natBindEntryGetValue    (    OIDC_T            lastmatch,    SNMP_PKT_T        *pktp,    VB_T              *vbp,    NAT_BINDTBL_ENTRY *pData    )    {    int         length;    OCTET_T    *pBuf;    switch(lastmatch)        {        case LEAF_natBindStatic:            /* Values:             *  true(1)  = VAL_natBindStatic_true             *  false(2) = VAL_natBindStatic_false             */            getproc_got_int32(pktp, vbp, pData->natBindStatic);               break;        case LEAF_natBindType:            /* Values:             *  address(1)   = VAL_natBindType_address             *  transport(2) = VAL_natBindType_transport             */            getproc_got_int32(pktp, vbp, pData->natBindType);               break;        case LEAF_natBindLocalAddress:            getproc_got_ip_address(pktp, vbp, pData->natBindLocalAddress);                break;        case LEAF_natBindLocalPort:            getproc_got_int32(pktp, vbp, pData->natBindLocalPort);               break;        case LEAF_natBindRemAddress:            getproc_got_ip_address(pktp, vbp, pData->natBindRemAddress);                break;        case LEAF_natBindRemPort:            getproc_got_int32(pktp, vbp, pData->natBindRemPort);                break;        case LEAF_natBindMaxLeaseTime:            getproc_got_int32(pktp, vbp, pData->natBindMaxLeaseTime);                break;        case LEAF_natBindLeaseLeft:            getproc_got_int32(pktp, vbp, pData->natBindLeaseLeft);                break;        case LEAF_natBindMaxIdle:            getproc_got_int32(pktp, vbp, pData->natBindMaxIdle);                break;        case LEAF_natBindCurrIdle:            getproc_got_int32(pktp, vbp, pData->natBindCurrIdle);               break;        case LEAF_natBindDirection:            /* Values:             *  unidirectional(1) = VAL_natBindDirection_unidirectional             *  bidirectional(2)  = VAL_natBindDirection_bidirectional             */            getproc_got_int32(pktp, vbp, pData->natBindDirection);                break;        case LEAF_natBindLocalIfNumber:            getproc_got_int32(pktp, vbp, pData->natBindLocalIfNumber);                break;        case LEAF_natBindExtIfNumber:            getproc_got_int32(pktp, vbp, pData->natBindExtIfNumber);                break;        case LEAF_natBindLocalIfName:            length = strlen ((char*) pData->natBindLocalIfName);            pBuf = SNMP_memory_alloc (length);	    if (pBuf == NULL)	        {	        getproc_error (pktp, vbp, GEN_ERR);	        return (GEN_ERR);	        }	    MEMCPY (pBuf, pData->natBindLocalIfName, length);	    getproc_got_string (pktp, vbp, length, pBuf, BFL_IS_DYNAMIC,	                        VT_STRING );            break;        case LEAF_natBindExtIfName:            length = strlen ((char*) pData->natBindExtIfName);            pBuf = SNMP_memory_alloc (length);	    if (pBuf == NULL)	        {	        getproc_error (pktp, vbp, GEN_ERR);	        return (GEN_ERR);	        }	    MEMCPY (pBuf, pData->natBindExtIfName, length);	    getproc_got_string (pktp, vbp, length, pBuf, BFL_IS_DYNAMIC,	                        VT_STRING );            break;        case LEAF_natBindProto:            /* Values:             *  tcp(1)  = VAL_natBindProto_tcp             *  udp(2)  = VAL_natBindProto_udp             *  icmp(3) = VAL_natBindProto_icmp             */            getproc_got_int32(pktp, vbp, pData->natBindProto);                break;        case LEAF_natBindAction:            /* Values:             *  active(1)        = VAL_natBindAction_active             *  notInService(2)  = VAL_natBindAction_notInService             *  notReady(3)      = VAL_natBindAction_notReady             *  createAndGo(4)   = VAL_natBindAction_createAndGo             *  createAndWait(5) = VAL_natBindAction_createAndWait             *  destroy(6)       = VAL_natBindAction_destroy             */            getproc_got_int32(pktp, vbp, pData->natBindAction);                break;        case LEAF_natBindContrAgent:            getproc_got_int32(pktp, vbp, pData->natBindContrAgent);                break;        default:            return GEN_ERR;        }    return NO_ERROR;    }/*******************************************************************************  natBindEntryGet -   Get method routine for  natBindTable.* *  Parameters to this routine are* *  <lastmatch> - the last oid component that was matched to get to this leaf.*  <tcount>     - count of components remaining in the unmatched portion i.e.*                the length of the instance portion.*  <tlist>     - ptr to the oid sequence remaining, i.e. the instance portion.*  <pktp>      - ptr to internal representation of the snmp pkt.*  <vbp>       - ptr to var bind being processed.**  NOMANUAL**  RETURNS: N/A*/void natBindEntryGet    (    OIDC_T      lastmatch,    int         tcount,    OIDC_T     *tlist,    SNMP_PKT_T *pktp,    VB_T       *vbp    )    {    NAT_BINDTBL_ENTRY data;                                int               error;    OIDC_T     *tlistTemp;    DBG_PRINT(("into natBindEntryGet\n"));                  if (tcount != NAT_BINDTBL_INSTANCE_LEN)	{        for ( ; vbp; vbp = vbp->vb_link)            {            getproc_nosuchins(pktp, vbp);	    }        return;	}    /* find all the varbinds that share the same getproc and instance */        group_by_getproc_and_instance(pktp, vbp, tcount, tlist);

⌨️ 快捷键说明

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