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

📄 natmgmt.c

📁 vxworks下ppp的实现源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* natMgmt.c - Module that interacts with core NAT code for SNMP *//* Copyright 2000-2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01r,01aug03,vks  bind_id check in m2NatSessTblEntryGet for IP, TCP and UDP packets01q,29jul03,vks  bug fix: added a check for bind_id in case of an IP packet in                 m2NatSessTblEntryGet routine. This will avoid null pointer                 exception that happens when NAT is in Basic mode with a                 static entry and no active session exists01p,29apr03,myz  fixed diab warnings01o,25apr03,svk  Implement version number01n,24apr03,zhu  updated copyright01m,21apr03,myz  replaced swap(_long) with the ntohs(l) and htons(l) macros.01l,15nov02,zhu  SPR#84194: SNMP crashes for UDP session entry01k,18oct01,tkuo Use inet_ntoa_b() instead of inet_ntoa() in m2NatBindTblEntrySet.				 Also fixed latest patch in m2NatTblEntryGet() as it caused 				 NatTable to be skipped.01j,28aug01,zhu  making bug fixes01i,05apr01,ann  making bug fixes01h,04apr01,zhu  fixing bugs for ipAddress and others01g,16mar01,zhu  adding m2 Error check01f,12mar01,ann  removing the reference to natMibInit01e,27nov00,ann  correcting errors from testing01d,13nov00,ann  adding the proto and bind objects in m2NatBindTblEntryGet01c,06nov00,ann  adding the net to host conversions01b,03nov00,ann  making some changes for the bind table row creation01a,14aug00,ann  written*//* * DESCRIPTION * This module implements the GET and the SET routines that interact * with the NAT code to get and set the variables. The APIs, here, are * called by the stub routines in snmpnat.c whenever queries are made for * NAT objects. Although, these routines have been written mainly for * SNMP stub routines, they are quite generic and can be utilized by * other protocols. *//* includes */#include "nat_api.h"#include "natAlgApi.h"#include "natMgmt.h"#include "nat.h"#include "m2Lib.h"#include "errnoLib.h"/* globals */typedef struct loc_rem_pair {    IP_ADDRESS    locAddr;    USHORT        locPort;    IP_ADDRESS    remAddr;    USHORT        remPort;} LOC_REM_PAIR;NAT_DATA          natData;    /* The NAT management repository *//* locals *//* forward declarations */LOCAL UINT16 ipAddrAndPortCmp (IP_ADDRESS *, USHORT *, IP_ADDRESS *, USHORT *,                                IP_ADDRESS *, USHORT *, IP_ADDRESS *, USHORT *,                                UINT16, int);void   natBoolValModify (BOOL, int *);LOCAL STATUS transListWalk (IP_ADDRESS *, USHORT *, IP_ADDRESS *, USHORT *,                             IP_ADDRESS *, USHORT *, IP_ADDRESS *, USHORT *,                             IP_ADDRESS *, USHORT *, IP_ADDRESS *, USHORT *,                             UINT16, int);LOCAL void   natBindInfoGet (NAT_CLASS *, int *, int *, int *, int *, int *, 			     int *, int *, int *, int *);/************************************************************************** *  * natMgmtInit - Initialization routine for NAT management resources * * This routine initializes all the tables associated with NAT for  * servicing management queries via SNMP. It creates the semaphore that * synchronizes accesses to these resources. This routine is the main * init routine that has to be called to initialize the NAT management * functionality. * * RETURNS: OK    if initialization was successful *          ERROR if an error occurred */STATUS natMgmtInit    (    void    )    {    NAT_SCALARS *    pNatScalars = &natData.natScalars;    /* Initialize the semaphore that provides mutual exclusion */    natData.natMgmtSem = semMCreate (SEM_Q_FIFO | SEM_DELETE_SAFE);            if (natData.natMgmtSem == NULL)        return ERROR;    /* Initialize the NAT scalars */    pNatScalars->natNumber = NUM_NAT_DEVICES;    strcpy ((char *)pNatScalars->natSwVersion, natVersion);    /* Initialize the NAT table */    natRealmModify (pNatScalars, PR_REALM_TYPE, EXT_REALM_TYPE);    return OK;    }/************************************************************************** *  * m2NatScalarsGet - Get routine for NAT scalars * * This routine gets a copy of the data associated with the NAT scalars. * The objects that are retrieved by this routine are: * * natNumber : number of NAT devices on the systems * natSessionNumber : number of NAT session numbers * natSwVersion : Version of NAT code * natPrRealmType : Version of IP realm supported on private network * natExtRealmType : Version of IP realm supported on external network * * RETURNS: OK    if an entry was found *          ERROR otherwise */STATUS m2NatScalarsGet    (    NAT_SCALARS *    pNatScalars    /* Pointer to scalars struct */    )    {    int             ipStaticCount   = 0;    int             ipDynamicCount   = 0;    int             tcpStaticCount  = 0;    int             tcpDynamicCount  = 0;    int             udpStaticCount  = 0;    int             udpDynamicCount  = 0;    int             icmpDynamicCount = 0;    int             staticCount = 0;    int             dynamicCount = 0;    NAT_SCALARS *   pNatData = &natData.natScalars;    if (!pNatScalars)	{	errnoSet(S_m2Lib_ENTRY_NOT_FOUND);        return ERROR;	}    pNatScalars->natNumber        = pNatData->natNumber;    /* Get a count of all the sessions we are running */    natBindInfoGet (&nat, &ipStaticCount, &ipDynamicCount, &tcpStaticCount, 		    &tcpDynamicCount, &udpStaticCount, &udpDynamicCount, 		    &icmpDynamicCount, &staticCount, &dynamicCount);    pNatScalars->natSessionNumber = dynamicCount + staticCount;       bcopy ((char *)pNatData->natSwVersion, (char *)pNatScalars->natSwVersion,                                    sizeof (pNatData->natSwVersion));    bcopy ((char *)pNatData->natPrRealmType,(char *)pNatScalars->natPrRealmType,				sizeof (pNatData->natPrRealmType));    bcopy ((char *)pNatData->natExtRealmType,	   (char *)pNatScalars->natExtRealmType,            sizeof (pNatData->natExtRealmType));    return OK;    }/************************************************************************** *  * m2NatScalarsSet - Set routine for NAT Scalars * * This is a dummy routine that is present here for future extensions * * RETURNS: OK    if an entry was found *          ERROR otherwise */STATUS m2NatScalarsSet     (    NAT_SCALARS *    pNatScalars,    /* Buffer containing vals */    int              varsToSet       /* Bit map of objects to set */    )    {    return OK;    }/************************************************************************** *  * m2NatTblEntryGet - Get/Next routine for NAT table * * This routine gets a copy of the data associated with the NAT table. * Depending on the <searchType> variable, it either returns the requested * NAT device's objects or returns the contents of the lexicographic  * successor of the requested NAT device in the table. * * NOTE that the current NAT implementation does not support more than one * NAT device. The NAT MIB, however, asuumes that there could be more than  * one NAT device. Hence, this code is implemented as if the there are  * multiple NAT devices. * * RETURNS: OK    if an entry was found *          ERROR otherwise */STATUS m2NatTblEntryGet    (    NAT_TBL_ENTRY *    pNatTblEntry,    /* Pointer to NAT table */    int                searchType       /* GET_VALUE or NEXT_VALUE */    )    {    int             ipStaticCount   = 0;    int             ipDynamicCount   = 0;    int             tcpStaticCount  = 0;    int             tcpDynamicCount  = 0;    int             udpStaticCount  = 0;    int             udpDynamicCount  = 0;    int             icmpDynamicCount = 0;    int             staticCount = 0;    int             dynamicCount = 0;    NAT_CLASS *     pNatClass = &nat;    if (!pNatTblEntry)        return ERROR;    if (searchType != GET_VALUE && searchType != NEXT_VALUE)        return ERROR;    /*      * If, at a later time, the NAT implementation is upgraded to allow     * the existance of more than one NAT device, uncomment the for     * loop below and enclose all the code following it within this     * for loop. Also, change the pNatClass initialization above to     * NULL instead of the nat global's address.     */    /*     * for (index = 1; index <= NAT_NUM_DEVICES; index++)     *     {     *     if (nat[index] == pNatTblEntry->natIndex)     *         {     *         pNatClass = &nat[index];     *         break;     *         }     *     }     */    /*      * If you uncomment the code above, change pNatTblEntry->natindex      * to index and remove the following searchType == NEXT_VALUE check      */    if (pNatTblEntry->natIndex > NUM_NAT_DEVICES)        {        errnoSet(S_m2Lib_ENTRY_NOT_FOUND);        return ERROR;        }    /* Populate the objects with the values from the NAT implementation */            pNatTblEntry->natIndex = NUM_NAT_DEVICES;    pNatTblEntry->natTypeMask = NAT_TYPES_SUPPORTED;           /*      * Perform the following inits based on wether we are in Basic      * NAT mode or NAPT. For convenience, we club all those objects     * that make this check right here instead of having to perform     * an if-else each time. Before going into the conditional      * statements, we get the total number of static translation      * entries in the system.     */    natBindInfoGet (pNatClass, &ipStaticCount, &ipDynamicCount, &tcpStaticCount, 		    &tcpDynamicCount, &udpStaticCount, &udpDynamicCount, 		    &icmpDynamicCount, &staticCount, &dynamicCount);    pNatTblEntry->natTotalBinds = staticCount + dynamicCount;    if (pNatClass->single_global_address_enabled)        {        /* NAPT mode */        pNatTblEntry->natType |= NAT_NAPT;        pNatTblEntry->natMaxStaticBinds = MAXIMUM_NUMBER_OF_STATIC_ENTRIES;        pNatTblEntry->natCurrStaticBinds = staticCount;        pNatTblEntry->natCurrDynamicBinds = dynamicCount;        pNatTblEntry->natMaxStaticIpBinds = MAXIMUM_NUMBER_OF_IP_STATIC_ENTRIES;        pNatTblEntry->natCurrStaticIpBinds = ipStaticCount;        pNatTblEntry->natCurrDynamicIpBinds = ipDynamicCount;        pNatTblEntry->natMaxStaticTcpBinds =                                      MAXIMUM_NUMBER_OF_TCP_STATIC_ENTRIES;        pNatTblEntry->natCurrStaticTcpBinds = tcpStaticCount;             pNatTblEntry->natCurrDynamicTcpBinds = tcpDynamicCount;             pNatTblEntry->natMaxStaticUdpBinds =                                        MAXIMUM_NUMBER_OF_UDP_STATIC_ENTRIES;        pNatTblEntry->natCurrStaticUdpBinds = udpStaticCount;        pNatTblEntry->natCurrDynamicUdpBinds = udpDynamicCount;        pNatTblEntry->natSessionMaxIdleTime = pNatClass->ip_translation_entry_timer;;        pNatTblEntry->natUdpSessionMaxIdleTime =                                   pNatClass->udp_translation_entry_timer;        pNatTblEntry->natIcmpSessionMaxIdleTime =                                   pNatClass->icmp_translation_entry_timer;        }    else        {         /* Basic NAT mode */        pNatTblEntry->natType |= NAT_BASIC;        pNatTblEntry->natMaxStaticBinds = MAXIMUM_NUMBER_OF_STATIC_ENTRIES;        pNatTblEntry->natCurrStaticBinds = staticCount;        pNatTblEntry->natCurrDynamicBinds = dynamicCount;        pNatTblEntry->natMaxStaticIpBinds = MAXIMUM_NUMBER_OF_STATIC_ENTRIES;        pNatTblEntry->natCurrStaticIpBinds = ipStaticCount;        pNatTblEntry->natCurrDynamicIpBinds = ipDynamicCount;        pNatTblEntry->natMaxStaticTcpBinds = -1;        pNatTblEntry->natCurrStaticTcpBinds = -1;             pNatTblEntry->natCurrDynamicTcpBinds = tcpDynamicCount;             pNatTblEntry->natMaxStaticUdpBinds = -1;        pNatTblEntry->natCurrStaticUdpBinds = -1;        pNatTblEntry->natCurrDynamicUdpBinds = -1;        pNatTblEntry->natSessionMaxIdleTime =                                   pNatClass->ip_translation_entry_timer;        pNatTblEntry->natUdpSessionMaxIdleTime = 0;        pNatTblEntry->natIcmpSessionMaxIdleTime = 0;        }    /* Fill up the common timer values */    pNatTblEntry->natTcpUpSessionMaxIdleTime =                                    pNatClass->tcp_connected_timer;    pNatTblEntry->natTcpDiscSessionMaxIdleTime =                                   pNatClass->tcp_disconnected_timer;    pNatTblEntry->natTcpClosingSessionMaxIdleTime =                                   pNatClass->tcp_closing_timer;

⌨️ 快捷键说明

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