original files of m241
This commit is contained in:
@@ -0,0 +1,853 @@
|
||||
/* m2IfMgtLib.c - MIB-II interface management APIs for SNMP */
|
||||
|
||||
/* Copyright 1993 - 2013,2014 Wind River Systems, Inc. */
|
||||
#include "copyright_wrs.h"
|
||||
|
||||
/*
|
||||
modification history
|
||||
--------------------
|
||||
02j,02feb16,rjq Incorrect calling ipnet API(VXW6-217).
|
||||
02i,15Apr14,rjq Fix for VXW6-81779.
|
||||
02h,22May13,bbz m2IfTblEntryGet() in m2IfMgtLib.c does not use the result
|
||||
value from muxTkCookieGet() correctly.(WIND00415873)
|
||||
02g,10Apr13,rjq Implement ifType and ifLastChange value.
|
||||
02f,25mar13,rjq Fixed memory leak after calling ipnet_if_get_index_array
|
||||
02e,14mar13,rjq set ifStackLastChange return 0
|
||||
02d,29sep10,h_x Fix build and coverity warnings
|
||||
02c,18aug10,h_x Fix WIND00226752
|
||||
02b,21jun10,h_x Fix WIND00217113
|
||||
02a,23apr10,h_x Fix WIND00208662
|
||||
01z,01apr10,h_x Fix warnings
|
||||
01y,31jul08,zhr Fixed WIND00129362, mottsec interface
|
||||
01x,14jul08,zhr Updated for ixe interface and clean compiling warning
|
||||
01w,11jul08,zhr Updated for apigen and clean up the code
|
||||
01v,10jun08,zhr Fixed WIND00125256
|
||||
01u,28Feb08,zhr Migrated to IPNET
|
||||
01s,14apr05,sar Remove the attempted optimization when using admin status
|
||||
to bring an interface up or down as it wasn't quite correct
|
||||
01r,25jan05,sar Modify sysuptime to be based on 64 bit ticks
|
||||
01q,12jan05,vvv osdep.h cleanup
|
||||
01p,26aug04,vvv fixed Diab warning
|
||||
01o,26aug04,niq unified stack merge
|
||||
01n,13may04,vvv fixed incorrect dereference in m2IfRcvAddrEntrySet() (SPR
|
||||
#97098)
|
||||
01m,05dec03,xli change include path
|
||||
01l,02dec03,zl use avlUintLib instead of avlLib
|
||||
01k,20nov03,niq osdep.h cleanup
|
||||
01i,06nov03,rlm Ran batch header update for header re-org
|
||||
01h,20oct03,zl changed for new avlLib without GENERIC_ARGUMENT
|
||||
01g,08sep03,vvv merged from ACCORDION_BASE6_MERGE_BASELINE
|
||||
01f,01may03,spm Tornado 2.2 CP1 merge (from m2IfLib, ver 02b,20mar03,wap:
|
||||
TOR2_2-CP1-F label, tor2_2-patch branch, /wind/river VOB)
|
||||
01e,10apr03,ijm fixed diab compiler warnings
|
||||
01d,10feb03,vvv added INET6 protection
|
||||
01c,30sep02,kbw making man page edits
|
||||
01b,30sep02,vvv fixed problem in stackEntryIsTop (SPR #71316)
|
||||
01a,25sep02,ham split m2IfLib to m2IfLib and m2IfMgtLib
|
||||
*/
|
||||
/*
|
||||
DESCRIPTION
|
||||
This library provides MIB-II interface management APIs for SNMP. This
|
||||
library does not include the counter-related APIs. The counter-related
|
||||
APIs are provided in m2IfLib.
|
||||
|
||||
To use this library, include the INCLUDE_MIB2_IFMGT configuration component.
|
||||
|
||||
To retrieve an interface table entry:
|
||||
.CS
|
||||
M2_INTERFACETBL interfaceEntry;
|
||||
|
||||
/@ Specify zero as the index to get the first entry in the table @/
|
||||
|
||||
interfaceEntry.ifIndex = 2; /@ Get interface with index 2 @/
|
||||
|
||||
if (m2IfTblEntryGet (M2_EXACT_VALUE, &interfaceEntry) == OK)
|
||||
/@ values in interfaceEntry are valid @/
|
||||
.CE
|
||||
|
||||
To retrieve an interface's operational state:
|
||||
.CS
|
||||
M2_INTERFACETBL ifEntryToSet;
|
||||
|
||||
ifEntryToSet.ifIndex = 2; /@ Select interface with index 2 @/
|
||||
/@ MIB-II value to set the interface @/
|
||||
/@ to the down state. @/
|
||||
ifEntryToSet.ifAdminStatus = M2_ifAdminStatus_down;
|
||||
|
||||
if (m2IfTblEntrySet (&ifEntryToSet) == OK)
|
||||
/@ Interface is now in the down state @/
|
||||
.CE
|
||||
|
||||
INCLUDE FILES: m2Lib.h
|
||||
|
||||
SEE ALSO: m2Lib, m2SysLib, m2IpLib, m2IcmpLib, m2UdpLib, m2TcpLib
|
||||
*/
|
||||
|
||||
/* includes */
|
||||
|
||||
#include <vxWorks.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <m2IfLib.h>
|
||||
#include "sysLib.h"
|
||||
#include <muxLib.h>
|
||||
#include <muxTkLib.h>
|
||||
#include <end.h>
|
||||
#include <net/if.h>
|
||||
#include <ipnet_h.h>
|
||||
#include <ipcom_vxworks.h>
|
||||
#include <ipcom_route.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <oemtypes.h>
|
||||
#include <m2wrsnmp.h>
|
||||
#include <private/muxLibP.h>
|
||||
|
||||
/* defines */
|
||||
|
||||
#define END_OBJ_MIB 1 /* Used in ifnetToEndFieldsGet() */
|
||||
#define END_OBJ_FLAGS 2 /* Used in ifnetToEndFieldsGet() */
|
||||
#define bits32_t sbits32_t
|
||||
#define MAX_DEV_NAME_LEN 10
|
||||
#define INVALID_UNIT_NUM 99
|
||||
#define CNT_2233_ENABLE 1
|
||||
#define IPNET_CODE_LOCK_M2()
|
||||
#define IPNET_CODE_LOCK_M2_READ(handle) \
|
||||
handle = ipnet_suspend_stack(); \
|
||||
if (handle == IP_NULL) \
|
||||
return -1;
|
||||
|
||||
#define IPNET_CODE_M2_UNLOCK(handle) \
|
||||
ipnet_resume_stack(handle);
|
||||
|
||||
/* imports */
|
||||
|
||||
#ifndef VIRTUAL_STACK
|
||||
IMPORT int ifsInList; /* Actual number of interfaces in our list */
|
||||
IMPORT int m2IfCount; /* Number of network interfaces */
|
||||
#ifdef WRSNMP
|
||||
IMPORT int ifxAccess; /* ifxTalbe access */
|
||||
#else
|
||||
int ifxAccess;
|
||||
#endif
|
||||
IMPORT int m2If64BitCounters;
|
||||
IMPORT FUNCPTR pM2TrapRtn; /* Pointer to trap routine supplied by the user */
|
||||
IMPORT void * pM2TrapRtnArg;/* Pointer to trap routine argument supplied by */
|
||||
/* the user */
|
||||
|
||||
/* last time a row was added/removed from the ifTable/ifXTable */
|
||||
IMPORT ULONG m2IfTableLastChange;
|
||||
|
||||
/* last time a row was added/removed from the ifStackTable or when the
|
||||
* ifStackStatus was last changed */
|
||||
IMPORT ULONG m2IfStackLastChange;
|
||||
BOOL pollUpdateOn = FALSE;
|
||||
|
||||
/* Semaphore used to protect the Interface group */
|
||||
|
||||
IMPORT SEM_ID m2InterfaceSem;
|
||||
#ifndef END_POLL_STATS_ROUTINE_HOOK
|
||||
#define END_POLL_STATS_ROUTINE_HOOK m2PollStatsIfPoll
|
||||
#endif
|
||||
IMPORT FUNCPTR _func_m2PollStatsIfPoll;
|
||||
|
||||
#endif /* VIRTUAL_STACK */
|
||||
|
||||
/* locals */
|
||||
|
||||
LOCAL STATUS m2IfDefaultValsGet (M2_DATA *, M2_IFINDEX *);
|
||||
LOCAL STATUS m2IfCommonValsGet (M2_DATA *, M2_IFINDEX *);
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* m2IfMgtLibInit - initialize MIB2 I/F Management Library
|
||||
*
|
||||
* This routine initializes the MIB2 interface management library which
|
||||
* provides APIs for interface management.
|
||||
*
|
||||
* RETURNS: OK if successful, ERROR if an error occured
|
||||
*
|
||||
* ERRNO: N/A
|
||||
*/
|
||||
|
||||
STATUS m2IfMgtLibInit
|
||||
(
|
||||
void
|
||||
)
|
||||
{
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* m2IfTblEntryGet - get a MIB-II interface-group table entry
|
||||
*
|
||||
* This routine maps the MIB-II interface index to the system's internal
|
||||
* interface index. The internal representation is in the form of a balanced
|
||||
* AVL tree indexed by ifIndex of the interface. The <search> parameter is
|
||||
* set to either M2_EXACT_VALUE or M2_NEXT_VALUE; for a discussion of its use,
|
||||
* see the manual entry for m2Lib. The interface table values are returned in a
|
||||
* structure of type M2_DATA, which is passed as the second argument to this
|
||||
* routine.
|
||||
*
|
||||
* NOTE: m2IfTblEntryGet() automatically increments the value of ifIndex when
|
||||
* search parameter is set to M2_NEXT_VALUE
|
||||
*
|
||||
* RETURNS:
|
||||
* OK, or 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, m2IfInit(), m2IfGroupInfoGet(), m2IfTblEntrySet(), m2IfDelete()
|
||||
*/
|
||||
STATUS m2IfTblEntryGet
|
||||
(
|
||||
int search, /* M2_EXACT_VALUE or M2_NEXT_VALUE */
|
||||
void * pIfReqEntry /* pointer to requested interface entry */
|
||||
)
|
||||
{
|
||||
M2_IFINDEX * pIfIndexEntry = NULL;
|
||||
M2_ID * pM2Id = NULL;
|
||||
M2_DATA * pM2Entry = (M2_DATA *)pIfReqEntry;
|
||||
|
||||
/* ipnet variables for m2Lib migration. */
|
||||
Ipnet_netif * best_netif;
|
||||
bits32_t * ifindexes = NULL;
|
||||
unsigned int ifTable_num_entries;
|
||||
unsigned int i;
|
||||
Ip_u32 tlist;
|
||||
void * pCookie = NULL;
|
||||
char * mapdevName = NULL;
|
||||
char devName[MAX_DEV_NAME_LEN];
|
||||
int unit = INVALID_UNIT_NUM;
|
||||
M2_INTERFACETBL * pM2IntTblEntry = &pM2Entry->mibIfTbl;
|
||||
void * suspend_handle;
|
||||
char name[IP_IFNAMSIZ]; /* interface name */
|
||||
Ip_u32 ifindex; /* Interface index */
|
||||
|
||||
memset (devName, 0, sizeof(devName));
|
||||
|
||||
/* Validate pointer to requeste structure */
|
||||
|
||||
if (pIfReqEntry == NULL)
|
||||
{
|
||||
errnoSet (S_m2Lib_INVALID_PARAMETER);
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
tlist = pM2Entry->mibIfTbl.ifIndex;
|
||||
|
||||
ifTable_num_entries = IPNET_NETIF_NUM_ATTACHED;
|
||||
|
||||
IPNET_CODE_LOCK_M2_READ(suspend_handle);
|
||||
|
||||
ifindexes = (bits32_t *) ipnet_if_get_index_array (IPCOM_VR_ANY, 0,
|
||||
(unsigned *)&ifTable_num_entries);
|
||||
if (ifindexes == IP_NULL)
|
||||
{
|
||||
IPNET_CODE_M2_UNLOCK(suspend_handle);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Get entry of interface table from ipnet */
|
||||
|
||||
best_netif = 0;
|
||||
|
||||
for ( i=0; i < ifTable_num_entries ; i++ )
|
||||
{
|
||||
if ( search == M2_NEXT_VALUE)
|
||||
{
|
||||
if (ifindexes[i]>tlist)
|
||||
{
|
||||
if ((best_netif = ipnet_if_indextonetif(IPCOM_VR_ANY, (Ip_u32)ifindexes[i])) == (Ipnet_netif*) NULL)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* M2_EXECT_VALUE */
|
||||
{
|
||||
if (ifindexes[i] == tlist )
|
||||
{
|
||||
if ((best_netif = ipnet_if_indextonetif(IPCOM_VR_ANY, (Ip_u32)ifindexes[i])) == NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(ifindexes);
|
||||
|
||||
if ( best_netif == 0)
|
||||
{
|
||||
IPNET_CODE_M2_UNLOCK(suspend_handle);
|
||||
return (ERROR);
|
||||
}
|
||||
memset(name, 0, sizeof(name));
|
||||
strncpy(name, best_netif->ipcom.name, IP_IFNAMSIZ - 1);
|
||||
ifindex = best_netif->ipcom.ifindex;
|
||||
IPNET_CODE_M2_UNLOCK(suspend_handle);
|
||||
|
||||
/* Try to map net stack interface name to end interface name. */
|
||||
if ((mapdevName = (char *)ipcom_get_mux_dev_name(name)) != NULL)
|
||||
strncpy(devName, mapdevName, strlen(mapdevName)-1);
|
||||
else
|
||||
strncpy(devName, name, strlen(name) - 1);
|
||||
unit = (name[strlen(name)-1])-0x30;
|
||||
|
||||
/* Initialize the provided structure */
|
||||
bzero ((char *) pM2Entry, sizeof (M2_DATA));
|
||||
pIfIndexEntry = (M2_IFINDEX*) malloc(sizeof(M2_IFINDEX));
|
||||
if(pIfIndexEntry == NULL)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
pIfIndexEntry->ifIndex = ifindex;
|
||||
|
||||
/*
|
||||
* Get the interface data from the driver via the muxIoctl
|
||||
* For driver such as ixe, gei and mottsec needs to turn endPollStats
|
||||
*/
|
||||
|
||||
pCookie = muxTkCookieGet(devName, unit);
|
||||
if ((strncmp(devName, "ixe",3) == 0) && !pollUpdateOn)
|
||||
{
|
||||
_func_m2PollStatsIfPoll = (FUNCPTR)END_POLL_STATS_ROUTINE_HOOK;
|
||||
endPollStatsInit (PCOOKIE_TO_ENDOBJ(pCookie), END_POLL_STATS_ROUTINE_HOOK);
|
||||
pollUpdateOn = TRUE;
|
||||
}
|
||||
|
||||
if (((strncmp(devName, "mottsec",7) == 0) || (strstr (devName, "gei") != NULL)) && !pollUpdateOn)
|
||||
{
|
||||
_func_m2PollStatsIfPoll = (FUNCPTR)END_POLL_STATS_ROUTINE_HOOK;
|
||||
endPollStatsInit (PCOOKIE_TO_ENDOBJ(pCookie), END_POLL_STATS_ROUTINE_HOOK);
|
||||
pollUpdateOn = TRUE;
|
||||
}
|
||||
|
||||
if (ifxAccess & IF_MIB_2233)
|
||||
{
|
||||
/* RFC 2233 */
|
||||
if ( strcmp(name, "lo0") == 0)
|
||||
{
|
||||
m2IfDefaultValsGet (pM2Entry, pIfIndexEntry);
|
||||
pM2Entry->mibIfTbl.ifIndex = ifindex;
|
||||
m2IfCommonValsGet (pM2Entry, pIfIndexEntry);
|
||||
ifxAccess &= 0;
|
||||
free(pIfIndexEntry);
|
||||
return (OK);
|
||||
}
|
||||
if ( pCookie == NULL ||
|
||||
(muxIoctl( pCookie, EIOCGMIB2233, (caddr_t)&pM2Id) != OK))
|
||||
{
|
||||
free(pIfIndexEntry);
|
||||
return (ERROR);
|
||||
}
|
||||
memcpy ((char *)pM2Entry, (char *)&pM2Id->m2Data, sizeof (M2_DATA));
|
||||
pM2Entry->mibIfTbl.ifIndex = ifindex;
|
||||
ifxAccess &= 0;
|
||||
free(pIfIndexEntry);
|
||||
return (OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Declare variables for RFC 1213 support */
|
||||
|
||||
pM2Entry->mibIfTbl.ifIndex = ifindex;
|
||||
if (muxIoctl( pCookie, EIOCGMIB2233, (caddr_t)&pM2Id) == OK)
|
||||
{
|
||||
/* Fill parameters with driver counters */
|
||||
m2IfDefaultValsGet (pM2Entry, pIfIndexEntry);
|
||||
pM2IntTblEntry->ifSpeed = pM2Id->m2Data.mibIfTbl.ifSpeed;
|
||||
pM2IntTblEntry->ifType = pM2Id->m2Data.mibIfTbl.ifType;
|
||||
pM2IntTblEntry->ifLastChange = pM2Id->m2Data.mibIfTbl.ifLastChange;
|
||||
|
||||
pM2IntTblEntry->ifInOctets = pM2Id->m2Data.mibIfTbl.ifInOctets;
|
||||
pM2IntTblEntry->ifInUcastPkts = pM2Id->m2Data.mibIfTbl.ifInUcastPkts;
|
||||
pM2IntTblEntry->ifInNUcastPkts = pM2Id->m2Data.mibIfTbl.ifInNUcastPkts;
|
||||
pM2IntTblEntry->ifInDiscards = pM2Id->m2Data.mibIfTbl.ifInDiscards;
|
||||
pM2IntTblEntry->ifInUnknownProtos = pM2Id->m2Data.mibIfTbl.ifInUnknownProtos;
|
||||
pM2IntTblEntry->ifInErrors = pM2Id->m2Data.mibIfTbl.ifInErrors;
|
||||
|
||||
pM2IntTblEntry->ifOutOctets = pM2Id->m2Data.mibIfTbl.ifOutOctets;
|
||||
pM2IntTblEntry->ifOutUcastPkts = pM2Id->m2Data.mibIfTbl.ifOutUcastPkts;
|
||||
pM2IntTblEntry->ifOutNUcastPkts = pM2Id->m2Data.mibIfTbl.ifOutNUcastPkts;
|
||||
pM2IntTblEntry->ifOutDiscards = pM2Id->m2Data.mibIfTbl.ifOutDiscards;
|
||||
pM2IntTblEntry->ifOutErrors = pM2Id->m2Data.mibIfTbl.ifOutErrors;
|
||||
|
||||
/* memcpy ((char *)pM2Entry, (char *)&pM2Id->m2Data, sizeof (M2_DATA)); */
|
||||
}
|
||||
else if ((devName[0] != 0) && (unit != INVALID_UNIT_NUM))
|
||||
{
|
||||
/*
|
||||
* no info from ioctl, make an educated guess at
|
||||
* the driver configuration
|
||||
*/
|
||||
m2IfDefaultValsGet (pM2Entry, pIfIndexEntry);
|
||||
if (strncmp(devName, "lo", 2) == 0)
|
||||
{
|
||||
/* IP Loop back interface. */
|
||||
sprintf ((char *)(pM2Entry->mibXIfTbl.ifName), "%s", name);
|
||||
pM2IntTblEntry->ifType = M2_ifType_softwareLoopback;
|
||||
pM2IntTblEntry->ifSpeed = 0;
|
||||
}
|
||||
else
|
||||
if (strncmp(devName, "sl", 2) == 0)
|
||||
{
|
||||
/* Slip Network Interface */
|
||||
|
||||
pM2IntTblEntry->ifType = M2_ifType_slip;
|
||||
pM2IntTblEntry->ifSpeed = 19200; /* Baud Rate ??? */
|
||||
}
|
||||
else
|
||||
if (strncmp(devName, "ppp", 3) == 0)
|
||||
{
|
||||
/* PPP Network Interface */
|
||||
|
||||
pM2IntTblEntry->ifType = M2_ifType_ppp;
|
||||
pM2IntTblEntry->ifSpeed = 19200; /* Baud Rate ??? */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use Ethernet parameters as defaults */
|
||||
|
||||
pM2IntTblEntry->ifType =
|
||||
M2_ifType_ethernet_csmacd;
|
||||
pM2IntTblEntry->ifSpeed = 10000000;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fill in the other parameters */
|
||||
m2IfCommonValsGet (pM2Entry, pIfIndexEntry);
|
||||
pM2Entry->mibIfTbl.ifIndex = ifindex;
|
||||
}
|
||||
free(pIfIndexEntry);
|
||||
return (OK);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* m2IfDefaultValsGet - get the default values for the counters
|
||||
*
|
||||
* This function fills the given struct with the default values as
|
||||
* specified in the RFC. We will enter this routine only if the ioctl
|
||||
* to the driver fails.
|
||||
*
|
||||
* RETURNS: n/a
|
||||
*/
|
||||
|
||||
LOCAL STATUS m2IfDefaultValsGet
|
||||
(
|
||||
M2_DATA * pM2Data, /* The requested entry */
|
||||
M2_IFINDEX * pIfIndexEntry /* The ifindex node */
|
||||
)
|
||||
{
|
||||
|
||||
if (!(ifxAccess & IF_MIB_2233))
|
||||
{
|
||||
pM2Data->mibIfTbl.ifInOctets = 0;
|
||||
pM2Data->mibIfTbl.ifInUcastPkts = 0;
|
||||
pM2Data->mibIfTbl.ifInNUcastPkts = 0;
|
||||
pM2Data->mibIfTbl.ifInDiscards = 0;
|
||||
pM2Data->mibIfTbl.ifInErrors = 0;
|
||||
pM2Data->mibIfTbl.ifInUnknownProtos = 0;
|
||||
|
||||
pM2Data->mibIfTbl.ifOutOctets = 0;
|
||||
pM2Data->mibIfTbl.ifOutUcastPkts = 0;
|
||||
pM2Data->mibIfTbl.ifOutNUcastPkts = 0;
|
||||
pM2Data->mibIfTbl.ifOutDiscards = 0;
|
||||
pM2Data->mibIfTbl.ifOutErrors = 0;
|
||||
|
||||
pM2Data->mibIfTbl.ifOutQLen = 0;
|
||||
}
|
||||
|
||||
pM2Data->mibXIfTbl.ifInMulticastPkts = 0;
|
||||
pM2Data->mibXIfTbl.ifInBroadcastPkts = 0;
|
||||
|
||||
pM2Data->mibXIfTbl.ifOutMulticastPkts = 0;
|
||||
pM2Data->mibXIfTbl.ifOutBroadcastPkts = 0;
|
||||
|
||||
memset(&(pM2Data->mibXIfTbl.ifHCInOctets), 0, sizeof(UI64));
|
||||
memset(&(pM2Data->mibXIfTbl.ifHCInUcastPkts), 0, sizeof(UI64));
|
||||
memset(&(pM2Data->mibXIfTbl.ifHCInMulticastPkts), 0, sizeof(UI64));
|
||||
memset(&(pM2Data->mibXIfTbl.ifHCInBroadcastPkts), 0, sizeof(UI64));
|
||||
|
||||
memset(&(pM2Data->mibXIfTbl.ifHCOutOctets), 0, sizeof(UI64));
|
||||
memset(&(pM2Data->mibXIfTbl.ifHCOutUcastPkts), 0, sizeof(UI64));
|
||||
memset(&(pM2Data->mibXIfTbl.ifHCOutMulticastPkts), 0, sizeof(UI64));
|
||||
memset(&(pM2Data->mibXIfTbl.ifHCOutBroadcastPkts), 0, sizeof(UI64));
|
||||
|
||||
memset(pM2Data->mibXIfTbl.ifName, 0, M2DISPLAYSTRSIZE);
|
||||
|
||||
pM2Data->mibXIfTbl.ifLinkUpDownTrapEnable = M2_LINK_UP_DOWN_TRAP_DISABLED;
|
||||
|
||||
pM2Data->mibXIfTbl.ifHighSpeed = 0;
|
||||
|
||||
pM2Data->mibXIfTbl.ifPromiscuousMode = M2_PROMISCUOUS_MODE_OFF;
|
||||
|
||||
pM2Data->mibXIfTbl.ifConnectorPresent = M2_CONNECTOR_NOT_PRESENT;
|
||||
|
||||
memset(pM2Data->mibXIfTbl.ifAlias, 0, M2DISPLAYSTRSIZE);
|
||||
|
||||
pM2Data->mibXIfTbl.ifCounterDiscontinuityTime = 0;
|
||||
|
||||
return (OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* m2IfCommonValsGet - get the common values
|
||||
*
|
||||
* This function updates the requested struct with all the data that is
|
||||
* independent of the driver ioctl. This information can be obtained
|
||||
* from the ifnet structures.
|
||||
*
|
||||
* RETURNS: n/a
|
||||
*/
|
||||
|
||||
LOCAL int m2IfCommonValsGet
|
||||
(
|
||||
M2_DATA * pM2Data, /* The requested struct */
|
||||
M2_IFINDEX * pIfIndexEntry /* The ifindex node */
|
||||
)
|
||||
{
|
||||
M2_INTERFACETBL * pM2IntTblEntry = &pM2Data->mibIfTbl;
|
||||
Ipnet_netif * best_netif = NULL;
|
||||
bits32_t * ifindexes = NULL;
|
||||
unsigned int i;
|
||||
unsigned int ifTable_num_entries;
|
||||
void * suspend_handle;
|
||||
|
||||
ifTable_num_entries = IPNET_NETIF_NUM_ATTACHED;
|
||||
IPNET_CODE_LOCK_M2_READ(suspend_handle);
|
||||
ifindexes = (bits32_t*) ipnet_if_get_index_array (IPCOM_VR_ANY, 0,
|
||||
(unsigned *)&ifTable_num_entries);
|
||||
|
||||
for ( i=0; i < ifTable_num_entries; i++ )
|
||||
if (ifindexes[i] == pIfIndexEntry->ifIndex )
|
||||
{
|
||||
if ((best_netif = ipnet_if_indextonetif(IPCOM_VR_ANY, (Ip_u32)ifindexes[i])) == (Ipnet_netif*) NULL)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(ifindexes);
|
||||
if(best_netif == NULL)
|
||||
{
|
||||
IPNET_CODE_M2_UNLOCK(suspend_handle);
|
||||
return ERROR;
|
||||
}
|
||||
sprintf ((char *)(pM2IntTblEntry->ifDescr), "%s", best_netif->ipcom.name);
|
||||
pM2IntTblEntry->ifMtu = best_netif->ipcom.mtu;
|
||||
|
||||
/* If the device does not have a hardware address set it to zero */
|
||||
|
||||
if (best_netif->ipcom.flags & (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_NOARP))
|
||||
{
|
||||
memset(&(pM2IntTblEntry->ifPhysAddress), 0, sizeof(M2_PHYADDR));
|
||||
}
|
||||
else
|
||||
{
|
||||
bcopy (((char *) best_netif->ipcom.link_addr),
|
||||
((char *) pM2IntTblEntry->ifPhysAddress.phyAddress),
|
||||
ETHERADDRLEN);
|
||||
|
||||
pM2IntTblEntry->ifPhysAddress.addrLength = ETHERADDRLEN;
|
||||
}
|
||||
|
||||
/* Get the ifAdminStatus, ifLastChange, and ifOperStatus */
|
||||
|
||||
if (IP_BIT_ISSET (best_netif->ipcom.flags, IP_IFF_UP))
|
||||
{
|
||||
pM2IntTblEntry->ifAdminStatus = VAL_ifAdminStatus_up;
|
||||
}
|
||||
else
|
||||
{
|
||||
pM2IntTblEntry->ifAdminStatus = VAL_ifAdminStatus_down;
|
||||
}
|
||||
|
||||
if (IP_BIT_ARESET (best_netif->ipcom.flags, IP_IFF_UP | IP_IFF_RUNNING))
|
||||
{
|
||||
pM2IntTblEntry->ifOperStatus = VAL_ifOperStatus_up;
|
||||
}
|
||||
else
|
||||
{
|
||||
pM2IntTblEntry->ifOperStatus = VAL_ifOperStatus_down;
|
||||
}
|
||||
pM2IntTblEntry->ifLastChange = best_netif->ipcom.mib2.ifLastChange;
|
||||
|
||||
/* If the device does not have a value set it with values of ipnet stack */
|
||||
if (strncmp (best_netif->ipcom.name, "lo0", 3) == 0)
|
||||
{
|
||||
if (!ifxAccess)
|
||||
{
|
||||
pM2IntTblEntry->ifLastChange = best_netif->ipcom.mib2.ifLastChange;
|
||||
pM2IntTblEntry->ifInOctets = best_netif->ipcom.mib2.ifInOctets;
|
||||
pM2IntTblEntry->ifInUcastPkts = best_netif->ipcom.mib2.ifInUcastPkts;
|
||||
pM2IntTblEntry->ifInDiscards = best_netif->ipcom.mib2.ifInDiscards;
|
||||
pM2IntTblEntry->ifInErrors = best_netif->ipcom.mib2.ifInErrors;
|
||||
pM2IntTblEntry->ifInUnknownProtos = best_netif->ipcom.mib2.ifInUnknownProtos;
|
||||
pM2IntTblEntry->ifOutOctets = best_netif->ipcom.mib2.ifOutOctets;
|
||||
pM2IntTblEntry->ifOutUcastPkts = best_netif->ipcom.mib2.ifOutUcastPkts;
|
||||
pM2IntTblEntry->ifOutDiscards = best_netif->ipcom.mib2.ifOutDiscards;
|
||||
pM2IntTblEntry->ifOutErrors = best_netif->ipcom.mib2.ifOutErrors;
|
||||
}
|
||||
if (ifxAccess)/* ifXtable common variables */
|
||||
{
|
||||
sprintf ((char *)(pM2Data->mibXIfTbl.ifName), "%s", best_netif->ipcom.name);
|
||||
pM2Data->mibXIfTbl.ifInMulticastPkts = best_netif->ipcom.mib2.ifOutMulticastPkts;
|
||||
pM2Data->mibXIfTbl.ifInBroadcastPkts = best_netif->ipcom.mib2.ifInBroadcastPkts;
|
||||
pM2Data->mibXIfTbl.ifOutMulticastPkts = best_netif->ipcom.mib2.ifOutMulticastPkts;
|
||||
pM2Data->mibXIfTbl.ifOutBroadcastPkts = best_netif->ipcom.mib2.ifOutBroadcastPkts;
|
||||
pM2Data->mibXIfTbl.ifLinkUpDownTrapEnable = best_netif->ipcom.mib2.ifLinkUpDownTrapEnable;
|
||||
if (IP_BIT_ISSET (best_netif->ipcom.flags, IP_IFF_PROMISC))
|
||||
pM2Data->mibXIfTbl.ifPromiscuousMode = VAL_ifPromiscuousMode_true;
|
||||
else
|
||||
pM2Data->mibXIfTbl.ifPromiscuousMode = VAL_ifPromiscuousMode_false;
|
||||
pM2Data->mibXIfTbl.ifConnectorPresent = VAL_ifConnectorPresent_false;
|
||||
pM2Data->mibXIfTbl.ifLinkUpDownTrapEnable = (ULONG)best_netif->ipcom.mib2.ifLinkUpDownTrapEnable;
|
||||
pM2Data->mibXIfTbl.ifHighSpeed = (best_netif->ipcom.type == IP_IFT_PPP)? (Mib2_Gauge32)0UL:(Mib2_Gauge32)100UL;
|
||||
memset((char *)(pM2Data->mibXIfTbl.ifAlias), 0, M2DISPLAYSTRSIZE);
|
||||
pM2Data->mibXIfTbl.ifCounterDiscontinuityTime = 0;
|
||||
}
|
||||
}
|
||||
else /* interface is not loopback */
|
||||
{
|
||||
if (ifxAccess)
|
||||
{
|
||||
sprintf ((char *)(pM2Data->mibXIfTbl.ifName), "%s", best_netif->ipcom.name);
|
||||
pM2Data->mibXIfTbl.ifLinkUpDownTrapEnable = (ULONG)best_netif->ipcom.mib2.ifLinkUpDownTrapEnable;
|
||||
if (IP_BIT_ISSET (best_netif->ipcom.flags, IP_IFF_PROMISC))
|
||||
pM2Data->mibXIfTbl.ifPromiscuousMode = VAL_ifPromiscuousMode_true;
|
||||
else
|
||||
pM2Data->mibXIfTbl.ifPromiscuousMode = VAL_ifPromiscuousMode_false;
|
||||
pM2Data->mibXIfTbl.ifConnectorPresent = VAL_ifConnectorPresent_false;
|
||||
|
||||
}
|
||||
}
|
||||
IPNET_CODE_M2_UNLOCK(suspend_handle);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* m2IfTblEntrySet - set the state of a MIB-II interface entry to UP or DOWN
|
||||
*
|
||||
* This routine selects the interface specified in the input parameter
|
||||
* <pIfReqEntry> and sets the interface parameters to the requested state.
|
||||
* It is the responsibility of the calling routine to set the interface
|
||||
* index, and to make sure that the state specified in the
|
||||
* `ifAdminStatus' field of the structure at <pIfTblEntry> is a valid
|
||||
* MIB-II state, up(1) or down(2).
|
||||
*
|
||||
* The fields that can be modified by this routine are the following:
|
||||
* ifAdminStatus
|
||||
*
|
||||
* RETURNS: OK, or ERROR if the input parameter is not specified, an interface
|
||||
* is no longer valid, the interface index is incorrect, or the ioctl() command
|
||||
* to the interface fails.
|
||||
*
|
||||
* ERRNO:
|
||||
* S_m2Lib_INVALID_PARAMETER
|
||||
* S_m2Lib_ENTRY_NOT_FOUND
|
||||
* S_m2Lib_IF_CNFG_CHANGED
|
||||
*
|
||||
* SEE ALSO:
|
||||
* m2IfInit(), m2IfGroupInfoGet(), m2IfTblEntryGet(), m2IfDelete()
|
||||
*/
|
||||
|
||||
STATUS m2IfTblEntrySet
|
||||
(
|
||||
void * pIfReqEntry /* pointer to requested entry to change */
|
||||
)
|
||||
{
|
||||
int index;
|
||||
IF_SETENTRY * pM2Entry = (IF_SETENTRY *)pIfReqEntry;
|
||||
bits32_t * ifindexes;
|
||||
Ipnet_netif * best_netif = NULL;
|
||||
unsigned int ifTable_num_entries;
|
||||
unsigned int i;
|
||||
struct Ip_ifreq ifreq;
|
||||
Ip_fd fd;
|
||||
void *suspend_handle;
|
||||
char name[IP_IFNAMSIZ]; /* interface name */
|
||||
|
||||
|
||||
/* Validate the bounds of the requested index */
|
||||
|
||||
index = pM2Entry->ifIndex;
|
||||
|
||||
ifTable_num_entries = IPNET_NETIF_NUM_ATTACHED;
|
||||
if (index < 0 || index > ifTable_num_entries)
|
||||
{
|
||||
errnoSet (S_m2Lib_ENTRY_NOT_FOUND);
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
IPNET_CODE_LOCK_M2_READ(suspend_handle);
|
||||
|
||||
/* Get the node associated with the index */
|
||||
|
||||
ifindexes = (bits32_t*) ipnet_if_get_index_array (IPCOM_VR_ANY, 0,
|
||||
(unsigned *)&ifTable_num_entries);
|
||||
if (ifindexes == IP_NULL)
|
||||
{
|
||||
IPNET_CODE_M2_UNLOCK(suspend_handle);
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
for (i=0; i < ifTable_num_entries ; i++)
|
||||
{
|
||||
if (ifindexes[i] == index)
|
||||
{
|
||||
best_netif = ipnet_if_indextonetif(IPCOM_VR_ANY, (Ip_u32)ifindexes[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(ifindexes);
|
||||
|
||||
if (best_netif == NULL)
|
||||
{
|
||||
IPNET_CODE_M2_UNLOCK(suspend_handle);
|
||||
return (ERROR);
|
||||
}
|
||||
memset(name, 0, sizeof(name));
|
||||
strncpy(name, best_netif->ipcom.name, IP_IFNAMSIZ - 1);
|
||||
IPNET_CODE_M2_UNLOCK(suspend_handle);
|
||||
/*
|
||||
* The only supported state changes for the interface are UP and DOWN.
|
||||
* The TEST case is not supported by the drivers. If our caller does
|
||||
* set the status to TEST, which they shouldn't, the interface will be
|
||||
* brought down with an status of TEST.
|
||||
*/
|
||||
|
||||
/* Do we need to call the Ioctl as a result of any of the above */
|
||||
|
||||
if (pM2Entry->varToSet & (M2_varId_ifAdminStatus |
|
||||
M2_varId_ifPromiscuousMode))
|
||||
{
|
||||
/*
|
||||
* The network semaphore is not taken for this operation because the
|
||||
* called routine takes the network semphore. Issue the IOCTL to the
|
||||
* driver routine, and verify that the request is honored.
|
||||
*/
|
||||
fd = ipcom_socket(IP_AF_INET, IP_SOCK_DGRAM, IP_IPPROTO_UDP);
|
||||
if (fd != IP_INVALID_SOCKET)
|
||||
{
|
||||
/* Change interface status */
|
||||
ipcom_memset(&ifreq, 0, sizeof(struct Ip_ifreq));
|
||||
ipcom_strcpy(ifreq.ifr_name, best_netif->ipcom.name);
|
||||
if (ipcom_socketioctl(fd, IP_SIOCGIFFLAGS,
|
||||
&ifreq) < 0)
|
||||
{
|
||||
(void)ipcom_socketclose(fd);
|
||||
return ERROR;
|
||||
}
|
||||
if (pM2Entry->ifAdminStatus == 1)
|
||||
IP_BIT_SET(ifreq.ip_ifr_flags, IP_IFF_UP);
|
||||
else
|
||||
IP_BIT_CLR(ifreq.ip_ifr_flags, IP_IFF_UP);
|
||||
if (ipcom_socketioctl (fd, IP_SIOCSIFFLAGS,
|
||||
&ifreq) < 0)
|
||||
{
|
||||
(void)ipcom_socketclose(fd);
|
||||
return ERROR;
|
||||
}
|
||||
(void)ipcom_socketclose(fd);
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* m2IfGroupInfoGet - get the MIB-II interface-group scalar variables
|
||||
*
|
||||
* This routine fills the interface-group structure at <pIfInfo> with
|
||||
* the values of MIB-II interface-group global variables.
|
||||
*
|
||||
* RETURNS: OK, or ERROR if <pIfInfo> is not a valid pointer.
|
||||
*
|
||||
* ERRNO:
|
||||
* S_m2Lib_INVALID_PARAMETER
|
||||
*
|
||||
* SEE ALSO:
|
||||
* m2IfInit(), m2IfTblEntryGet(), m2IfTblEntrySet(), m2IfDelete()
|
||||
*/
|
||||
|
||||
STATUS m2IfGroupInfoGet
|
||||
(
|
||||
M2_INTERFACE * pIfInfo /* pointer to interface group structure */
|
||||
)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
Ipcom_mib2_TimeStamp timeStp;
|
||||
void *suspend_handle;
|
||||
|
||||
if (pIfInfo == NULL)
|
||||
{
|
||||
errnoSet (S_m2Lib_INVALID_PARAMETER);
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Number of network interfaces in the system independent of
|
||||
* their state
|
||||
*/
|
||||
|
||||
IPNET_CODE_LOCK_M2_READ(suspend_handle);
|
||||
pIfInfo->ifNumber = IPNET_NETIF_NUM_ATTACHED;
|
||||
IPNET_CODE_M2_UNLOCK(suspend_handle);
|
||||
|
||||
if (ipcom_mib2_get_ipv4InterfaceTableLastChange(&timeStp) == -1 )
|
||||
return (ERROR);
|
||||
pIfInfo->ifTableLastChange = timeStp;
|
||||
pIfInfo->ifStackLastChange = 0;
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* The following function have not been implemented to support vxWorks-6.7
|
||||
*/
|
||||
|
||||
STATUS m2IfRcvAddrEntryGet
|
||||
(
|
||||
int search, /* exact search or next search */
|
||||
int * pIndex, /* pointer to the ifIndex */
|
||||
M2_IFRCVADDRTBL * pIfReqEntry /* struct for the values */
|
||||
)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
STATUS m2IfRcvAddrEntrySet
|
||||
(
|
||||
int varToSet, /* entries that need to be modified */
|
||||
int index, /* search type */
|
||||
M2_IFRCVADDRTBL * pIfReqEntry /* struct containing the new values */
|
||||
)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
STATUS m2IfStackEntryGet
|
||||
(
|
||||
int search, /* M2_EXACT_VALUE or M2_NEXT_VALUE */
|
||||
int * pHighIndex, /* the higher layer's ifIndex */
|
||||
M2_IFSTACKTBL * pIfReqEntry /* pointer to the requested entry */
|
||||
)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user