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

📄 natmgmt.c

📁 vxworks下ppp的实现源码
💻 C
📖 第 1 页 / 共 5 页
字号:
                               addr,                               pNatBindEntry->natBindLocalPort,                               pNatBindEntry->natBindRemPort                               ) != OK)                {                return ERROR;                }            }        return OK;        }    /*      * If we reached here, then an entry already exists and the only action     * we allow is to delete it.     */    if (pNatBindEntry->natBindAction == NAT_BIND_DELETE)        {        if (pNatBindEntry->natBindProto == TCP_TRANS_LIST)            {            if (natTcpStaticDelete (                              addr,                              pNatBindEntry->natBindLocalPort,                              pNatBindEntry->natBindRemPort                              ) != OK)                {                return ERROR;                }            }        else            {            if (natUdpStaticDelete (                              addr,                              pNatBindEntry->natBindLocalPort,                              pNatBindEntry->natBindRemPort                             ) != OK)                {                return ERROR;                }            }		        return OK;        }    /*      * if we reach here, it means we didn't provide correct action, return ERROR.     */    return ERROR;    }/**************************************************************************  * * m2NatBindTblEntryGet - Get/Next Routine for the bind table *  * This routine performs the lookup of all the objects associated with * a particular bind entry, as specified by the loc addr, loc port,  * rem addr and rem port combination. If the search type is NEXT_VALUE, * the objects that are looked up are that for the lexicographic  * successor of the given combination. And you should increment the  * lowest part of the index by 1 for search type NEXT_VALUE. * * * RETURNS: OK    if a successful lookup was done, *          ERROR otherwise */STATUS m2NatBindTblEntryGet    (    NAT_BINDTBL_ENTRY *   pNatBindEntry,    /* pointer to buffer */    int                   searchType        /* GET/NEXT */    )    {    IP_TRANSLATION_ENTRY *    pIpEntry = NULL;    TCP_TRANSLATION_ENTRY *   pTcpEntry = NULL;    UDP_TRANSLATION_ENTRY *   pUdpEntry = NULL;    ICMP_TRANSLATION_ENTRY *  pIcmpEntry = NULL;    void *                    pBestEntry = NULL;    IP_ADDRESS                savLocAddr;    IP_ADDRESS                savRemAddr;    USHORT                    savLocPort;    USHORT                    savRemPort;    UINT16                    matchType = 0;    IP_ADDRESS                icmpGlobAddr = nat.global_address;    int                       index;    int                       found = 0;    UINT16                    natType;    USHORT                    basicPort = 0xffff;    if (!pNatBindEntry)        return ERROR;    /*      * Initialize the ports and the IP address of the saved entry to the     * maximum possible values     */    savLocAddr = 0xffffffff;    savRemAddr = 0xffffffff;    savLocPort = 0xffff;    savRemPort = 0xffff;    if (nat.single_global_address_enabled == TRUE)	natType = NAT_NAPT;    else	natType = NAT_BASIC;        /* Both basic NAT and NAPT will go through this*/           pIpEntry = (IP_TRANSLATION_ENTRY *)DLL_FIRST                                   ((DL_LIST *)&nat.natg.ip_translation_list);    while (pIpEntry && !found)        {        if (transListWalk (                           &pIpEntry->sa_local_address, &basicPort,                           &pIpEntry->sa_global_address, &basicPort,                           &pNatBindEntry->natBindLocalAddress,			   &pNatBindEntry->natBindLocalPort,                           &pNatBindEntry->natBindRemAddress, 			   &pNatBindEntry->natBindRemPort,                           &savLocAddr, &savLocPort,                           &savRemAddr, &savRemPort,                           natType, searchType                          ) != ERROR)            {            pBestEntry = pIpEntry;            matchType = IP_TRANS_LIST;            if (searchType == GET_VALUE)                {                found = 1;                break;                }            }        /*          * If this is a GET_VALUE search, and we found an entry, then we are         * done. If this is a NEXT_VALUE, then we execute this code in any case.         */        if ( (searchType == NEXT_VALUE) || (searchType == GET_VALUE && !found) )            {            /*              * We now search the TCP translation list within each of these IP             * translation entries             */            pTcpEntry = (TCP_TRANSLATION_ENTRY *)DLL_FIRST			    ((DL_LIST *)&pIpEntry->tcp_translation_list);            while (pTcpEntry)                {                if (transListWalk (                           &pTcpEntry->local_address,                            &pTcpEntry->local_port,                           &pTcpEntry->remote_address,                           &pTcpEntry->remote_port,                           &pNatBindEntry->natBindLocalAddress,                           &pNatBindEntry->natBindLocalPort,                           &pNatBindEntry->natBindRemAddress,                            &pNatBindEntry->natBindRemPort,                           &savLocAddr, &savLocPort,                            &savRemAddr, &savRemPort,                           natType, searchType                          ) != ERROR)                    {                    pBestEntry = pTcpEntry;                    matchType = TCP_TRANS_LIST;                    if (searchType == GET_VALUE)                        {                        found = 1;                        break;                        }                    }                pTcpEntry = (TCP_TRANSLATION_ENTRY *)                         DLL_NEXT ((DL_NODE *) pTcpEntry);	        }	    }         /* Done with this IP entry, get the next one */	            pIpEntry = (IP_TRANSLATION_ENTRY *)                     DLL_NEXT ((DL_NODE *) pIpEntry);        }    /* The following code will be only executed at NAPT mode*/    if (natType == NAT_NAPT)        {        /*          * NAPT mode :         * We will have to browse through the other three lists - TCP, UDP and         * ICMP to figure out our best match;         * If this is a GET_VALUE search, and we found an entry, then we are         * done. If this is a NEXT_VALUE, then we execute this code in any case.         * We will start off with the TCP list          */               if ( (searchType == NEXT_VALUE) || (searchType == GET_VALUE && !found) )	    {            pTcpEntry = (TCP_TRANSLATION_ENTRY *) DLL_FIRST                                 ((DL_LIST *) &nat.nats.tcp_translation_list);            while (pTcpEntry)                {                if (transListWalk (                                  &pTcpEntry->local_address,                                   &pTcpEntry->local_port,                                  &pTcpEntry->remote_address,                                  &pTcpEntry->remote_port,                                  &pNatBindEntry->natBindLocalAddress,                                  &pNatBindEntry->natBindLocalPort,                                  &pNatBindEntry->natBindRemAddress,                                   &pNatBindEntry->natBindRemPort,                                  &savLocAddr, &savLocPort,                                   &savRemAddr, &savRemPort,                                  natType, searchType                                  ) != ERROR)                    {                    pBestEntry = pTcpEntry;                    matchType = TCP_TRANS_LIST;                    if (searchType == GET_VALUE)                        {                        found = 1;                        break;                        }                    }                pTcpEntry = (TCP_TRANSLATION_ENTRY *)                             DLL_NEXT ((DL_NODE *) pTcpEntry);                }            }        /*          * If this is a GET_VALUE search, and we found an entry, then we are         * done. If this is a NEXT_VALUE, then we execute this code in any case.         */        if ( (searchType == NEXT_VALUE) || (searchType == GET_VALUE && !found) )            {            pUdpEntry = (UDP_TRANSLATION_ENTRY *)                          DLL_FIRST ((DL_LIST *) &nat.nats.udp_translation_list);            while (pUdpEntry)                {                if (transListWalk (                                   &pUdpEntry->local_address,                                    &pUdpEntry->local_port,                                   &pUdpEntry->remote_address,                                   &pUdpEntry->remote_port,                                   &pNatBindEntry->natBindLocalAddress,                                   &pNatBindEntry->natBindLocalPort,                                   &pNatBindEntry->natBindRemAddress,                                    &pNatBindEntry->natBindRemPort,                                   &savLocAddr, &savLocPort,                                    &savRemAddr, &savRemPort,                                   natType, searchType                                  ) != ERROR)                    {                    pBestEntry = pUdpEntry;                    matchType = UDP_TRANS_LIST;                    if (searchType == GET_VALUE)                        {                        found = 1;                        break;                        }                    }                pUdpEntry = (UDP_TRANSLATION_ENTRY *)                         DLL_NEXT ((DL_NODE *) pUdpEntry);                }            }        /*          * If this is a GET_VALUE search, and we found an entry, then we are         * done. If this is a NEXT_VALUE, then we execute this code in any case.         */        if ( (searchType == NEXT_VALUE) || (searchType == GET_VALUE && !found) )            {            /* Look thru the ICMP list */            pIcmpEntry = (ICMP_TRANSLATION_ENTRY *)                          DLL_FIRST((DL_LIST *) &nat.nats.icmp_translation_list);            while (pIcmpEntry)                {                if (transListWalk (                                   &pIcmpEntry->local_address,                                    &pIcmpEntry->icmp_identifier,                                   &icmpGlobAddr,                                   &pIcmpEntry->spoofed_icmp_identifier,                                   &pNatBindEntry->natBindLocalAddress,                                   &pNatBindEntry->natBindLocalPort,                                   &pNatBindEntry->natBindRemAddress,                                    &pNatBindEntry->natBindRemPort,                                   &savLocAddr, &savLocPort,                                    &savRemAddr, &savRemPort,                                   natType, searchType                                  ) != ERROR)                    {                    pBestEntry = pIcmpEntry;                    matchType = ICMP_TRANS_LIST;                    if (searchType == GET_VALUE)                        {                        found = 1;                        break;                        }                    }                pIcmpEntry = (ICMP_TRANSLATION_ENTRY *)                         DLL_NEXT ((DL_NODE *) pIcmpEntry);                }            }        }    /* pBestEntry should have the best match, so start copying the values */    switch (matchType)        {        case IP_TRANS_LIST:            pIpEntry = (IP_TRANSLATION_ENTRY *) pBestEntry;            pNatBindEntry->natBindStatic = (pIpEntry->static_entry) ?                                         STATIC_ENTRY : DYNAMIC_ENTRY;            pNatBindEntry->natBindType = ADDRESS_BINDING;            pNatBindEntry->natBindLocalAddress = htonl(pIpEntry->sa_local_address);            pNatBindEntry->natBindLocalPort = 0xffff;            pNatBindEntry->natBindRemAddress = htonl(pIpEntry->sa_global_address);            pNatBindEntry->natBindRemPort = 0xffff;            pNatBindEntry->natBindMaxLeaseTime = 0xffffffff;            pNatBindEntry->natBindLeaseLeft = 0xffffffff;            pNatBindEntry->natBindMaxIdle = nat.ip_translation_entry_timer;            pNatBindEntry->natBindCurrIdle = pIpEntry->time_stamp;            pNatBindEntry->natBindDirection = NAT_UNIDIRECTIONAL;            pNatBindEntry->natBindProto = IP_TRANS_LIST;            pNatBindEntry->natBindAction = NAT_BIND_ACTIVE;            break;        case TCP_TRANS_LIST:            pTcpEntry = (TCP_TRANSLATION_ENTRY *) pBestEntry;            pNatBindEntry->natBindStatic = (pTcpEntry->static_entry) ?                                         STATIC_ENTRY : DYNAMIC_ENTRY;            pNatBindEntry->natBindType = TRANSPORT_BINDING;            pNatBindEntry->natBindLocalAddress = htonl(pTcpEntry->local_address);            pNatBindEntry->natBindLocalPort = pTcpEntry->local_port;            pNatBindEntry->natBindRemAddress =                                     htonl(pTcpEntry->remote_address);            pNatBindEntry->natBindRemPort = pTcpEntry->remote_port;            pNatBindEntry->natBindMaxLeaseTime = 0xffffffff;

⌨️ 快捷键说明

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