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

📄 m2iplib.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 3 页
字号:
/* m2IpLib.c - MIB-II IP-group API for SNMP agents *//* Copyright 1984 - 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01k,16mar99,spm  recovered orphaned code from tor1_0_1.sens1_1 (SPR #25770)01j,29sep98,spm  added support for dynamic routing protocols (SPR #9374)01i,30dec97,vin  fixed SPR 2009001h,26aug97,spm  removed compiler warnings (SPR #7866)01g,17may96,rjc  routeEntryFill called with 1 less parmam. fixed.01f,03apr96,rjc  set the m2RouteSem semaphore to NULL in in m2IpDelete01e,25jan95,jdi  doc cleanup.01d,11nov94,rhp  fixed typo in library man page01c,11nov94,rhp  edited man pages01b,03mar94,elh  modifed m2IpRouteTblEntrySet to return ERROR if rtioctl		 failed.01a,08dec93,jag  written*//*DESCRIPTIONThis library provides MIB-II services for the IP group.  It providesroutines to initialize the group, access the group scalar variables, readthe table IP address, route and ARP table.  The route and ARP table canalso be modified.  For a broader description of MIB-II services,see the manual entry for m2Lib.USING THIS LIBRARYTo use this library, the MIB-II interface group must also be initialized;see the manual entry for m2IfLib.  This library (m2IpLib) can beinitialized and deleted by calling m2IpInit() and m2IpDelete()respectively, if only the IP group's services are needed.  If full MIB-IIsupport is used, this group and all other groups can be initialized anddeleted by calling m2Init() and m2Delete().The following example demonstrates how to access and change IP scalarvariables:.CS    M2_IP   ipVars;    int     varToSet;    if (m2IpGroupInfoGet (&ipVars) == OK)	/@ values in ipVars are valid @/    /@ if IP is forwarding packets (MIB-II value is 1) turn it off @/    if (ipVars.ipForwarding == M2_ipForwarding_forwarding)	{				    /@ Not forwarding (MIB-II value is 2) @/	ipVars.ipForwarding = M2_ipForwarding_not_forwarding;      	varToSet |= M2_IPFORWARDING;	}    /@ change the IP default time to live parameter @/    ipVars.ipDefaultTTL = 55;    if (m2IpGroupInfoSet (varToSet, &ipVars) == OK)	/@ values in ipVars are valid @/.CEThe IP address table is a read-only table.  Entries to this table can be retrieved as follows:.CS    M2_IPADDRTBL ipAddrEntry;    /@ Specify the index as zero to get the first entry in the table @/    ipAddrEntry.ipAdEntAddr = 0;       /@ Local IP address in host byte order @/    /@ get the first entry in the table @/    if ((m2IpAddrTblEntryGet (M2_NEXT_VALUE, &ipAddrEntry) == OK)	/@ values in ipAddrEntry in the first entry are valid  @/    /@ Process first entry in the table @/    /@      * For the next call, increment the index returned in the previous call.     * The increment is to the next possible lexicographic entry; for     * example, if the returned index was 147.11.46.8 the index passed in the     * next invocation should be 147.11.46.9.  If an entry in the table     * matches the specified index, then that entry is returned.     * Otherwise the closest entry following it, in lexicographic order,     * is returned.     @/    /@ get the second entry in the table @/    if ((m2IpAddrTblEntryGet (M2_NEXT_VALUE, &ipAddrEntryEntry) == OK)	/@ values in ipAddrEntry in the second entry are valid  @/.CEThe IP Address Translation Table (ARP table) includes the functionality ofthe AT group plus additional functionality.  The AT group is supportedthrough this MIB-II table.  Entries in this table can be added anddeleted.  An entry is deleted (with a set operation) by setting the`ipNetToMediaType' field to the MIB-II "invalid" value (2).  The following example shows how to delete an entry:.CSM2_IPATRANSTBL        atEntry;    /@ Specify the index for the connection to be deleted in the table @/    atEntry.ipNetToMediaIfIndex     = 1       /@ interface index @/    /@ destination IP address in host byte order @/    atEntry.ipNetToMediaNetAddress  = 0x930b2e08;					    /@ mark entry as invalid @/    atEntry.ipNetToMediaType        = M2_ipNetToMediaType_invalid;     /@ set the entry in the table @/    if ((m2IpAtransTblEntrySet (&atEntry) == OK)	/@ Entry deleted successfully @/.CEThe IP route table allows for entries to be read, deleted, and modified.  Thisexample demonstrates how an existing route is deleted:.CS    M2_IPROUTETBL        routeEntry;    /@ Specify the index for the connection to be deleted in the table @/    /@ destination IP address in host byte order @/    routeEntry.ipRouteDest       = 0x930b2e08;						/@ mark entry as invalid @/    routeEntry.ipRouteType       = M2_ipRouteType_invalid;    /@ set the entry in the table @/    if ((m2IpRouteTblEntrySet (M2_IP_ROUTE_TYPE, &routeEntry) == OK)	/@ Entry deleted successfully @/.CEINCLUDE FILES: m2Lib.h SEE ALSO:m2Lib, m2SysLib, m2IfLib, m2IcmpLib, m2UdpLib, m2TcpLib*//* includes */#include "vxWorks.h"#include "stdlib.h"#include "m2Lib.h"#include "private/m2LibP.h"#include "netLib.h"#include <netinet/in_systm.h>#include <netinet/in.h>#include <netinet/ip.h>#include <netinet/ip_var.h>#include <net/route.h>#include <net/radix.h>#include <netinet/in_var.h>#include <netinet/if_ether.h>#include <net/if_dl.h>#include <net/if_arp.h>#include "ioctl.h"#include "net/mbuf.h"#include "tickLib.h"#include "sysLib.h"#include "routeLib.h"#include "semLib.h"#include "errnoLib.h"/* defines */#define M2_MAX_ROUTE_DEFAULT 	40/* globals */LOCAL int 		m2RouteTableSaved;LOCAL int		m2RouteTableSize;LOCAL int		m2NumRouteEntries;LOCAL M2_IPROUTETBL   * m2RouteTable;LOCAL SEM_ID            m2RouteSem;/* * The zero object id is used throught out the MIB-II library to fill OID  * requests when an object ID is not provided by a group variable. */LOCAL M2_OBJECTID ipZeroObjectId = { 2, {0,0} };/* forward declarations */LOCAL int       m2RouteTableGet();LOCAL int 	routeCacheInit (struct radix_node *rn, void *	pRtArg);/* external declarations */extern SEM_ID		m2InterfaceSem;IMPORT struct radix_node_head *rt_tables[]; /* table of radix nodes */IMPORT struct	llinfo_arp llinfo_arp; IMPORT int 	arpioctl (int, caddr_t);IMPORT routeEntryFill (struct ortentry *, int, int, BOOL);IMPORT int  _ipCfgFlags; /******************************************************************************** m2IpInit - initialize MIB-II IP-group access** This routine allocates the resources needed to allow access to the MIB-II* IP variables.  This routine must be called before any IP variables* can be accessed.  The parameter <maxRouteTableSize> is used to increase the* default size of the MIB-II route table cache.** RETURNS:* OK, or ERROR if the route table or the route semaphore cannot be allocated.** ERRNO:* S_m2Lib_CANT_CREATE_ROUTE_SEM** SEE ALSO:* m2IpGroupInfoGet(), m2IpGroupInfoSet(), m2IpAddrTblEntryGet(),* m2IpAtransTblEntrySet(),  m2IpRouteTblEntryGet(), m2IpRouteTblEntrySet(), * m2IpDelete()*/STATUS m2IpInit    (    int		maxRouteTableSize 	/* max size of routing table */     )    {    /* initialize the routing table stuff */    if (m2RouteTable == NULL)	{	/* only initialized the first time called */        m2RouteTableSaved = 0;	m2RouteTableSize = (maxRouteTableSize == 0) ? 			   M2_MAX_ROUTE_DEFAULT :  maxRouteTableSize ;    	m2RouteTable = (M2_IPROUTETBL *) calloc (m2RouteTableSize, 				   	         sizeof (M2_IPROUTETBL));	if (m2RouteTable == NULL)	    {	    return (ERROR);	    }	}        if (m2RouteSem == NULL)            {	    m2RouteSem = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE |				   SEM_DELETE_SAFE);	    if (m2RouteSem == NULL)		{	        errnoSet (S_m2Lib_CANT_CREATE_ROUTE_SEM);		return (ERROR);		}	    }    (void) m2RouteTableGet (m2RouteTable, m2RouteTableSize);    return (OK);    }/******************************************************************************** m2IpGroupInfoGet - get the MIB-II IP-group scalar variables** This routine fills in the IP structure at <pIpInfo> with the* values of MIB-II IP global variables.** RETURNS: OK, or ERROR if <pIpInfo> is not a valid pointer.** ERRNO:* S_m2Lib_INVALID_PARAMETER** SEE ALSO: m2IpInit(), m2IpGroupInfoSet(), m2IpAddrTblEntryGet(),* m2IpAtransTblEntrySet(), m2IpRouteTblEntryGet(), m2IpRouteTblEntrySet(),* m2IpDelete()*/STATUS m2IpGroupInfoGet    (    M2_IP * pIpInfo	/* pointer to IP MIB-II global group variables */    )    {     /* Validate Pointer to IP structure */     if (pIpInfo == NULL)	{	errnoSet (S_m2Lib_INVALID_PARAMETER);        return (ERROR);	}     if (_ipCfgFlags & IP_DO_FORWARDING)        pIpInfo->ipForwarding       = M2_ipForwarding_forwarding;    else        pIpInfo->ipForwarding       = M2_ipForwarding_not_forwarding;     pIpInfo->ipDefaultTTL       = ipTimeToLive;    pIpInfo->ipInReceives       = ipstat.ips_total;     pIpInfo->ipInHdrErrors      = ipstat.ips_badsum + ipstat.ips_tooshort +                                  ipstat.ips_toosmall + ipstat.ips_badhlen +                                  ipstat.ips_badlen + ipstat.ips_badoptions +				  ipstat.ips_badvers;     pIpInfo->ipInAddrErrors     = ipstat.ips_cantforward;    pIpInfo->ipForwDatagrams    = ipstat.ips_forward;    pIpInfo->ipReasmReqds       = ipstat.ips_fragments;    pIpInfo->ipReasmFails       = ipstat.ips_fragdropped +                                  ipstat.ips_fragtimeout;    pIpInfo->ipReasmOKs         = ipstat.ips_reassembled;     pIpInfo->ipInDiscards       = ipstat.ips_toosmall;    pIpInfo->ipInUnknownProtos  = ipstat.ips_noproto;     pIpInfo->ipInDelivers       = ipstat.ips_delivered;     pIpInfo->ipOutRequests      = ipstat.ips_localout;    pIpInfo->ipFragOKs          = ipstat.ips_fragmented;    pIpInfo->ipFragFails        = ipstat.ips_cantfrag;    pIpInfo->ipFragCreates      = ipstat.ips_ofragments;    pIpInfo->ipOutDiscards      = ipstat.ips_odropped;    pIpInfo->ipOutNoRoutes      = ipstat.ips_noroute;    pIpInfo->ipReasmTimeout     = IPFRAGTTL;     /*      * The MIB-II defines this variable to be the number of routing entries     * that were discarded to free up buffer space.  The BSD VxWorks      * implementation does not free routes to free buffer space.     */    pIpInfo->ipRoutingDiscards  = 0;     return (OK);    }/******************************************************************************** m2IpGroupInfoSet - set MIB-II IP-group variables to new values** This routine sets one or more variables in the IP group, as specified in the* input structure <pIpInfo> and the bit field parameter <varToSet>.** RETURNS: OK, or ERROR if <pIpInfo> is not a valid pointer, or <varToSet> has* an invalid bit field.** ERRNO:*  S_m2Lib_INVALID_PARAMETER*  S_m2Lib_INVALID_VAR_TO_SET** SEE ALSO: m2IpInit(), m2IpGroupInfoGet(), m2IpAddrTblEntryGet(), * m2IpAtransTblEntrySet(), m2IpRouteTblEntryGet(),* m2IpRouteTblEntrySet(), m2IpDelete()*/STATUS m2IpGroupInfoSet    (    unsigned int varToSet,   /* bit field used to set variables */    M2_IP * pIpInfo	     /* ptr to the MIB-II IP group global variables */    )    {     /* Validate pointer and variable */     if (pIpInfo == NULL ||        (varToSet & (M2_IPFORWARDING | M2_IPDEFAULTTTL)) == 0)	{	if (pIpInfo == NULL)	    errnoSet (S_m2Lib_INVALID_PARAMETER);	else	    errnoSet (S_m2Lib_INVALID_VAR_TO_SET);        return (ERROR);	}     /*     * This variable is toggle from NOT forwarding to forwarding, and vice versa     */    if (varToSet & M2_IPFORWARDING)        {        if (pIpInfo->ipForwarding == M2_ipForwarding_not_forwarding)            _ipCfgFlags &= (~IP_DO_FORWARDING);        else            _ipCfgFlags |= IP_DO_FORWARDING;         }     /*     * Set the new time.  The calling routine is expected to have verified that     * the new time is a valid value.     */    if (varToSet & M2_IPDEFAULTTTL)        ipTimeToLive = pIpInfo->ipDefaultTTL;     return (OK);    } /******************************************************************************** m2IpAddrTblEntryGet - get an IP MIB-II address entry** This routine traverses the IP address table and does an M2_EXACT_VALUE or* a M2_NEXT_VALUE search based on the <search> parameter.  The calling * routine is responsible for supplying a valid MIB-II entry index in the* input structure <pIpAddrTblEntry>.  The index is the local IP* address. The first entry in the table is retrieved by doing a NEXT search* with the index field set to zero. ** RETURNS: * OK, ERROR if the input parameter is not specified, or a match is not found.** ERRNO:*  S_m2Lib_INVALID_PARAMETER*  S_m2Lib_ENTRY_NOT_FOUND** SEE ALSO:* m2Lib, m2IpInit(), m2IpGroupInfoGet(), m2IpGroupInfoSet(), * m2IpAtransTblEntrySet(), m2IpRouteTblEntryGet(), m2IpRouteTblEntrySet(),

⌨️ 快捷键说明

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