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

📄 snmpnat.c

📁 nat PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 4 页
字号:
    /* use the instance (tcount and tlist) to look up the entry in the     * table.     */            if ( (unsigned int)(*(tlist + IP_ADDR_LEN)) > 0xffff ||         (unsigned int)(*(tlist + NAT_BINDTBL_REMOTE_PORT_OFFSET)) > 0xffff)        {        for ( ; vbp; vbp = vbp->vb_link)            {            getproc_nosuchins(pktp, vbp);	    }        DBG_PRINT(("natBindEntryGet: Error local port %d, remote port %d\n",              (unsigned int)(*(tlist + IP_ADDR_LEN)),             (unsigned int)(*(tlist + NAT_BINDTBL_REMOTE_PORT_OFFSET)) ));        return;        }            for (tlistTemp = tlist; tlistTemp < (tlist + IP_ADDR_LEN); tlistTemp++)        {        if ( (unsigned int)(*tlistTemp) > 0xff )            {            for ( ; vbp; vbp = vbp->vb_link)	        {                getproc_nosuchins(pktp, vbp);	        }	    DBG_PRINT(("natBindEntryGet: Error local addr: 0x%x\n", 	             (unsigned int)(*tlistTemp)));            return;            }        }    for (tlistTemp = (tlist + NAT_BINDTBL_REMOTE_ADDRESS_OFFSET);          tlistTemp < (tlist + NAT_BINDTBL_REMOTE_ADDRESS_OFFSET + IP_ADDR_LEN);         tlistTemp++)        {        if ((unsigned int)(*tlistTemp)> 0xff )            {            for ( ; vbp; vbp = vbp->vb_link)	        {                getproc_nosuchins(pktp, vbp);	        }	    DBG_PRINT(("natBindEntryGet: Error remote addr: 0x%x\n", 	            (unsigned int)(*tlistTemp) ));            return;            }        }    bzero ((char *)&data, sizeof (data));    data.natBindLocalPort = *(tlist + IP_ADDR_LEN);    data.natBindRemPort = *(tlist + NAT_BINDTBL_REMOTE_PORT_OFFSET);    DBG_PRINT(("localport %d, remport %d\n",              data.natBindLocalPort,data.natBindRemPort));    if ( snmpOidToIpHostOrder (IP_ADDR_LEN, tlist , &data.natBindLocalAddress)             || snmpOidToIpHostOrder (IP_ADDR_LEN, tlist +              NAT_BINDTBL_REMOTE_ADDRESS_OFFSET, &data.natBindRemAddress) ||              (m2NatBindTblEntryGet (&data , GET_VALUE) != OK) )	{        DBG_PRINT(("natBindEntryGet: Error Local addr: 0x%x, remote addr:"            "0x%x \n", (unsigned int)data.natBindLocalAddress,             (unsigned int)data.natBindRemAddress));        for ( ; vbp; vbp = vbp->vb_link)	    {            getproc_nosuchins(pktp, vbp);	    }        return;        }    else 	{        /* retrieve all the values from the same data structure */        for ( ; vbp; vbp = vbp->vb_link) 	    {            if ((error = natBindEntryGetValue (vbp->vb_ml.ml_last_match, pktp,                                                vbp, &data)) != NO_ERROR)                getproc_error(pktp, vbp, error);            }        }    }    /*******************************************************************************  natBindEntryNext -**  Next method routine for  nat bind group tabular variables.**  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.***  RETURNS: N/A* */void natBindEntryNext    (    OIDC_T      lastmatch,    int         tcount,    OIDC_T     *tlist,    SNMP_PKT_T *pktp,    VB_T       *vbp    )    {    OIDC_T            natBindIndex[NAT_BINDTBL_INDEX_LEN];    NAT_BINDTBL_ENTRY data;          OIDC_T     *tlistTemp;    BOOL       overFlow = FALSE;    DBG_PRINT(("into natBindEntryNext\n"));                   /* find all the varbinds that share the same getproc and instance */    group_by_getproc_and_instance(pktp, vbp, tcount, tlist);        if (tcount == 0 )        {        bzero((char *)&data, sizeof(data));        }    else        {        for (tlistTemp = tlist; tlistTemp < (tlist + IP_ADDR_LEN); tlistTemp++)            {            if ((unsigned int)(*tlistTemp) > 0xff)                {                *tlistTemp = 0xff;                overFlow = TRUE;                }            }        snmpOidToIpHostOrder (IP_ADDR_LEN, tlist , &data.natBindLocalAddress);        for (tlistTemp = (tlist + NAT_BINDTBL_REMOTE_ADDRESS_OFFSET);              tlistTemp < (tlist + NAT_BINDTBL_REMOTE_ADDRESS_OFFSET +              IP_ADDR_LEN); tlistTemp++)            {            if ((unsigned int)(*tlistTemp) > 0xff)                {                *tlistTemp = 0xff;                overFlow = TRUE;                }            }        snmpOidToIpHostOrder (IP_ADDR_LEN, tlist +                               NAT_BINDTBL_REMOTE_ADDRESS_OFFSET,                               &data.natBindRemAddress);             DBG_PRINT(("natBindEntryNext: oid localport 0x%x, remport 0x%x\n",              *(tlist + IP_ADDR_LEN),             *(tlist + NAT_BINDTBL_REMOTE_PORT_OFFSET)));                if ( (unsigned int)(*(tlist + IP_ADDR_LEN)) <= 0xffff )                 data.natBindLocalPort = *(tlist + IP_ADDR_LEN);        else            {            data.natBindLocalPort = 0xffff;            overFlow = TRUE;            }                    if ( (unsigned int)(*(tlist + NAT_BINDTBL_REMOTE_PORT_OFFSET))                <= 0xffff)                data.natBindRemPort = *(tlist + NAT_BINDTBL_REMOTE_PORT_OFFSET);        else            {            data.natBindRemPort = 0xffff;            overFlow = TRUE;            }                   DBG_PRINT(("natBindEntryNext: processed local addr: 0x%x, remote addr:"            "0x%x, localport %d, remport %d\n",             (unsigned int)data.natBindLocalAddress,             (unsigned int)data.natBindRemAddress,            data.natBindLocalPort,data.natBindRemPort));        }    if ( m2NatBindTblEntryGet (&data, NEXT_VALUE ) != OK)	{	for ( ; vbp != NULL; vbp = vbp->vb_link)	    {	    snmpNextError (pktp, vbp);            }	    return;	}    /*      * Create oid sequence for nat index retrieved. This ip_to_rlist routine     * expects to see the IP address in the network byte order. We have anyway     * done a htonl in m2NatBindTblEntryGet.     */        (void) ip_to_rlist (data.natBindLocalAddress, natBindIndex);    (void) ip_to_rlist (data.natBindRemAddress,                         natBindIndex + NAT_BINDTBL_REMOTE_ADDRESS_OFFSET);    *(natBindIndex + IP_ADDR_LEN) = data.natBindLocalPort;    *(natBindIndex + NAT_BINDTBL_REMOTE_PORT_OFFSET) = data.natBindRemPort;    if (overFlow)        {        /* the current oid is greater or eaqual to the result oid, wrong*/        while (oidcmp2(NAT_BINDTBL_INDEX_LEN, tlist, NAT_BINDTBL_INDEX_LEN,               natBindIndex) >=0 )            {            DBG_PRINT(("natBindEntryNext: search next when overflow\n"));            /* IP addresses in data are in network order after the last             * m2NatBindTblEntryGet call. But must call m2NatBindTblEntryGet             * with data in host order              */            data.natBindLocalAddress = ntohl(data.natBindLocalAddress);            data.natBindRemAddress = ntohl(data.natBindRemAddress);            if ( m2NatBindTblEntryGet (&data, NEXT_VALUE ) != OK)	            {	            for ( ; vbp != NULL; vbp = vbp->vb_link)	                {	                snmpNextError (pktp, vbp);                    }                    DBG_PRINT(("natBindEntryNext: overflow next not found\n"));	            return;	            }                    (void) ip_to_rlist (data.natBindLocalAddress, natBindIndex);            (void) ip_to_rlist (data.natBindRemAddress,                         natBindIndex + NAT_BINDTBL_REMOTE_ADDRESS_OFFSET);            *(natBindIndex + IP_ADDR_LEN) = data.natBindLocalPort;            *(natBindIndex + NAT_BINDTBL_REMOTE_PORT_OFFSET) =                 data.natBindRemPort;            }        }    DBG_PRINT(("natBindEntryNext: got next local addr: 0x%x, remote addr:"        "0x%x, localport %d, remport %d\n",         (unsigned int)data.natBindLocalAddress,         (unsigned int)data.natBindRemAddress,        data.natBindLocalPort,data.natBindRemPort));            for (    ; vbp; vbp = vbp->vb_link)        {           /* install instance part of next instance found */        nextproc_next_instance (pktp, vbp, NAT_BINDTBL_INDEX_LEN,                                 natBindIndex);        natBindEntryGetValue (vbp->vb_ml.ml_last_match, pktp, vbp, &data);        }    }/*******************************************************************************  natBindEntryTest -  Test 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**  RETURN: N/A**/void natBindEntryTest    (    OIDC_T      lastmatch,    int         tcount,    OIDC_T     *tlist,    SNMP_PKT_T *pktp,    VB_T       *vbp    )    {    NAT_BINDTBL_ENTRY data;    int               errorStatus = NO_ERROR;    int               found  = 0;    int               proto = -1;    int               action = -1;    VB_T *            pVbpTemp = vbp;    struct create_row rowObjs[] =                                   {                                      {&l_natBindAction, 0x01},                                      {&l_natBindProto, 0x01}                                  };     DBG_PRINT(("into natBindEntryTest\n"));     /*      * We do not have an appropriate API in NAT to create bindings for Basic      * mode. So, we bail out for Basic NAT     */    if (natTypeFind() != NAT_NAPT)        {        errorStatus = INCONSISTENT_VALUE;        goto errorReturn;        }    /*      * Check for a valid index length then for valid ip address and     * valid port no (for both local and remote ends)     */    bzero ((char *)&data, sizeof (data));    data.natBindLocalPort = *(tlist + IP_ADDR_LEN);    data.natBindRemPort = *(tlist + NAT_BINDTBL_REMOTE_PORT_OFFSET);    if ( (tcount != NAT_BINDTBL_INDEX_LEN) ||          (snmpOidToIpHostOrder (IP_ADDR_LEN, tlist, &data.natBindLocalAddress))         ||(snmpOidToIpHostOrder (IP_ADDR_LEN, tlist +          NAT_BINDTBL_REMOTE_ADDRESS_OFFSET, &data.natBindRemAddress)) )        {        DBG_PRINT(("Err natBindEntryTest: Local addr: 0x%x, remote addr: 0x%x \n",             (unsigned int)data.natBindLocalAddress,             (unsigned int)data.natBindRemAddress));        errorStatus = NO_SUCH_NAME;        goto errorReturn;        }    /* remote address&port must be 0 cause only static entry add/del allowed*/    if (data.natBindRemAddress)        {        errorStatus = WRONG_VALUE;        goto errorReturn;        }    pVbpTemp = vb_extract_row (pktp, vbp_to_index(pktp, vbp), tcount, tlist,                                     NAT_BIND_RW_OBJS, rowObjs);    if (pVbpTemp == NULL)        {        errorStatus = INCONSISTENT_VALUE;        DBG_PRINT(("natBindEntryTest: no row\n"));        /*test the value anyway, so that bad value will be returned first*/        pVbpTemp = vbp;        }    for ( ; pVbpTemp; pVbpTemp = pVbpTemp->vb_link)        {        switch (pVbpTemp->vb_ml.ml_last_match)            {            case LEAF_natBindProto:                switch (VB_GET_INT32(pVbpTemp))                     {                    case VAL_natBindProto_tcp:                        proto = VAL_natBindProto_tcp;                        break;                    case VAL_natBindProto_udp:                        proto = VAL_natBindProto_udp;                        break;                    case VAL_natBindProto_icmp:                    case VAL_natBindProto_ip:                        errorStatus = WRONG_VALUE;                        goto errorReturn;                          default:                        errorStatus = WRONG_VALUE;                        goto errorReturn;                    }                break;                    case LEAF_natBindAction:                switch (VB_GET_INT32(pVbpTemp))                     {                    case VAL_natBindAction_active:                    case VAL_natBindAction_notInService:                    case VAL_natBindAction_notReady:                    case VAL_natBindAction_createAndWait:                        errorStatus = WRONG_VALUE;                        goto errorReturn;                    case VAL_natBindAction_createAndGo:                        action = VAL_natBindAction_createAndGo;                        break;                    case VAL_natBindAction_destroy:                        action = VAL_natBindAction_destroy;                        break;                    default:                        errorStatus = WRONG_VALUE;                        goto errorReturn;                    }                break;                        default:                errorStatus = WRONG_VALUE;                goto errorReturn;            }        }    if (errorStatus != NO_ERROR)        goto errorReturn;    if (proto == VAL_natBindProto_tcp)        {        if (natTcpStaticFind(data.natBindLocalAddress, data.natBindLocalPort,            data.natBindRemPort) == OK )            found = 1;            }    else if (proto == VAL_natBindProto_udp)        {        if (natUdpStaticFind(data.natBindLocalAddress, data.natBindLocalPort,            data.natBindRemPort) == OK )            found = 1;            }    /* Allowed scenarios:     *      * 1. createAndGo a new static entry, must provide proto     * 2. desctory an existing static entry, must provide proto and match     *    actual proto in the data     */    if ( (action == VAL_natBindAction_createAndGo && found) ||         (action == VAL_natBindAction_destroy && !found) )       {       errorStatus = WRONG_VALUE;       DBG_PRINT(("natBindEntryTest err: (not)found\n"));       goto errorReturn;       }    testproc_good (pktp, vbp);    DBG_PRINT(("natBindEntryTest good\n"));    return;errorReturn:    testproc_error (pktp, vbp, errorStatus);    DBG_PRINT(("natBindEntryTest err\n"));    return;    }/*******************************************************************************  natBindEntrySet -  Set 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 natBindEntrySet    (    OIDC_T      lastmatch,    int         tcount,    OIDC_T     *tlist,    SNMP_PKT_T *pktp,    VB_T       *vbp    )    {    NAT_BINDTBL_ENTRY data;      int               varToSet = 0;                      VB_T *            pVbpTemp = vbp;    /* Copy the data from the varbind fields */

⌨️ 快捷键说明

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