📄 m2iflib.c
字号:
* ----------------------------------------* ifDescr | char ** ifType | UINT* ifMtu | ULONG* ifSpeed | ULONG* ifPhysAddress | M2_PHYADDR ** ifAdminStatus | ULONG* ifOperStatus | ULONG* ifLastChange | ULONG* ifOutQLen | ULONG* ifSpecific | M2_OBJECTID ** ifName | char ** ifLinkUpDownTrapEnable | UINT* ifHighSpeed | ULONG* ifPromiscuousMode | UINT* ifConnectorPresent | UINT* ifAlias | char ** \te* RETURNS: ERROR, if the M2_ID is NULL; OK, if the variable was updated.*/STATUS m2IfVariableUpdate ( M2_ID * pId, /* The pointer to the device M2_ID object */ UINT varId, /* Variable to update */ caddr_t pData /* Data to use */ ) { M2_DATA * pMib2Data; if (pId == NULL) return ERROR; pMib2Data = &(pId->m2Data); switch (varId) { case M2_varId_ifDescr: strcpy(pMib2Data->mibIfTbl.ifDescr, (char *)pData); break; case M2_varId_ifType: pMib2Data->mibIfTbl.ifType = (UINT)pData; break; case M2_varId_ifMtu: pMib2Data->mibIfTbl.ifMtu = (ULONG)pData; break; case M2_varId_ifSpeed: pMib2Data->mibIfTbl.ifSpeed = (ULONG)pData; break; case M2_varId_ifPhysAddress: memcpy(&(pMib2Data->mibIfTbl.ifPhysAddress), (M2_PHYADDR *)pData, sizeof(M2_PHYADDR)); break; case M2_varId_ifAdminStatus: pMib2Data->mibIfTbl.ifAdminStatus = (ULONG)pData; break; case M2_varId_ifOperStatus: pMib2Data->mibIfTbl.ifOperStatus = (ULONG)pData; break; case M2_varId_ifLastChange: pMib2Data->mibIfTbl.ifLastChange = (ULONG)pData; break; case M2_varId_ifOutQLen: pMib2Data->mibIfTbl.ifOutQLen = (ULONG)pData; break; case M2_varId_ifSpecific: memcpy(&(pMib2Data->mibIfTbl.ifSpecific), (M2_OBJECTID *)pData, sizeof(M2_OBJECTID)); break; case M2_varId_ifName: strcpy(pMib2Data->mibXIfTbl.ifName, (char *)pData); break; case M2_varId_ifLinkUpDownTrapEnable: pMib2Data->mibXIfTbl.ifLinkUpDownTrapEnable = (UINT)pData; break; case M2_varId_ifHighSpeed: pMib2Data->mibXIfTbl.ifHighSpeed = (ULONG)pData; break; case M2_varId_ifPromiscuousMode: pMib2Data->mibXIfTbl.ifPromiscuousMode = (UINT)pData; break; case M2_varId_ifConnectorPresent: pMib2Data->mibXIfTbl.ifConnectorPresent = (UINT)pData; break; case M2_varId_ifAlias: strcpy(pMib2Data->mibXIfTbl.ifAlias, (char *)pData); break; default: return ERROR; } return OK; }/***************************************************************************** m2IfPktCountRtnInstall - install an interface packet counter routine** This function installs a routine in the M2_ID. This routine is a packet* counter which is able to update all the interface counters.** RETURNS: ERROR if the M2_ID is NULL, OK if the routine was installed.*/STATUS m2IfPktCountRtnInstall ( M2_ID * pId, M2_PKT_COUNT_RTN pRtn ) { if (pId == NULL) return ERROR; pId->m2PktCountRtn = pRtn; return OK; }/***************************************************************************** m2IfCtrUpdateRtnInstall - install an interface counter update routine** This function installs a routine in the M2_ID. This routine is able to* update a single specified interface counter.** RETURNS: ERROR if the M2_ID is NULL, OK if the routine was installed.*/STATUS m2IfCtrUpdateRtnInstall ( M2_ID * pId, M2_CTR_UPDATE_RTN pRtn ) { if (pId == NULL) return ERROR; pId->m2CtrUpdateRtn = pRtn; return OK; }/***************************************************************************** m2IfVarUpdateRtnInstall - install an interface variable update routine** This function installs a routine in the M2_ID. This routine is able to* update a single specified interface variable.** RETURNS: ERROR if the M2_ID is NULL, OK if the routine was installed.*/STATUS m2IfVarUpdateRtnInstall ( M2_ID * pId, M2_VAR_UPDATE_RTN pRtn ) { if (pId == NULL) return ERROR; pId->m2VarUpdateRtn = pRtn; return OK; }/******************************************************************************** centiSecsGet - get hundredths of a second** The number of hundredths of a second that have passed since this routine was* first called.** RETURNS: Hundredths of a second since the group was initialized.** SEE ALSO: N/A*/LOCAL unsigned long centiSecsGet (void) { unsigned long currCentiSecs; unsigned long clkRate = sysClkRateGet (); unsigned long tempTime = tickGet (); currCentiSecs = tempTime; tempTime *= 100; if (startCentiSecs == 0) startCentiSecs = tempTime / clkRate; if (currCentiSecs != (tempTime / 100)) currCentiSecs = (currCentiSecs / clkRate) * 100; else currCentiSecs = tempTime / clkRate; return (currCentiSecs - startCentiSecs); }/******************************************************************************** m2IfInit - initialize MIB-II interface-group routines** This routine allocates the resources needed to allow access to the * MIB-II interface-group variables. This routine must be called before any * interface variables can be accessed. The input parameter <pTrapRtn> is an* optional pointer to a user-supplied SNMP trap generator. The input parameter* <pTrapArg> is an optional argument to the trap generator. Only one trap* generator is supported.** RETURNS: OK, if successful; ERROR, if an error occurred.** ERRNO:* S_m2Lib_CANT_CREATE_IF_SEM** SEE ALSO: * m2IfGroupInfoGet(), m2IfTblEntryGet(), m2IfTblEntrySet(), m2IfDelete()*/STATUS m2IfInit ( FUNCPTR pTrapRtn, /* pointer to user trap generator */ void * pTrapArg /* pointer to user trap generator argument */ ) {#ifdef VIRTUAL_STACK /* Allocate space for former global variables. */ if (vsTbl[myStackNum]->pM2IfGlobals == NULL) { vsTbl[myStackNum]->pM2IfGlobals = (VS_M2_IF *) KHEAP_ALLOC (sizeof (VS_M2_IF)); if (vsTbl[myStackNum]->pM2IfGlobals == NULL) return (ERROR); bzero ( (char *)vsTbl [myStackNum]->pM2IfGlobals, sizeof (VS_M2_IF)); /* * Perform the static initialization which the compiler provides * automatically for the non-virtual stack. */ pM2IfRoot = NULL; pM2IfRootPtr = &pM2IfRoot; }#endif /* VIRTUAL_STACK */ /* add hooks for if.c */ _m2SetIfLastChange = (FUNCPTR) m2SetIfLastChange; _m2IfTableUpdate = (FUNCPTR) m2IfTableUpdate; /* Create the Interface semaphore */ if (m2InterfaceSem == NULL) { m2InterfaceSem = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE); if (m2InterfaceSem == NULL) {#ifdef VIRTUAL_STACK KHEAP_FREE (vsTbl[myStackNum]->pM2IfGlobals); vsTbl[myStackNum]->pM2IfGlobals = NULL;#endif /* VIRTUAL_STACK */ errnoSet (S_m2Lib_CANT_CREATE_IF_SEM); return (ERROR); } } /* Take the interface semaphore, and initialize group global variables */ semTake (m2InterfaceSem, WAIT_FOREVER); pM2TrapRtn = pTrapRtn; pM2TrapRtnArg = pTrapArg;#ifdef VIRTUAL_STACK _ifTableLastChange = 0; _ifStackLastChange = 0;#else /* VIRTUAL_STACK */ ifTableLastChange = 0; ifStackLastChange = 0;#endif /* VIRTUAL_STACK */ semGive (m2InterfaceSem); (void) centiSecsGet (); /* Initialize group time reference */ return (OK); }/***************************************************************************** m2IfTableUpdate - insert or remove an entry in the ifTable** This routine is called by if_attach and if_detach to insert/remove* an entry from the local m2IfLib ifTable. The status can be either* M2_IF_TABLE_INSERT or M2_IF_TABLE_REMOVE. The ifIndex that is searched* for in the AVL tree is specified in given the ifnet struct.* <if_ioctl> is a function pointer to change the flags on the interface.* <addr_get> is a function pointer to add the interface's addresses to* ifRcvAddressTable. Ethernet interfaces can use NULL for both function* pointers, other interfaces will need to pass an appropriate function.** RETURNS: ERROR if entry does not exist, OK if the entry was deleted*/STATUS m2IfTableUpdate ( struct ifnet * pIfNet, UINT status, /* attaching or detaching */ int (*if_ioctl) /* protocol specific ioctl or null for default (ethernet) */ (struct socket*,u_long,caddr_t), STATUS (*addr_get) /* func to grab the interface's addrs, null for default (ethernet) */ (struct ifnet*, M2_IFINDEX*) ) { UINT index; M2_IFINDEX * pIfIndex; M2_IFSTACKTBL * pIfStackTbl; M2_IFSTACKTBL * pTempS; M2_IFRCVADDRTBL * pIfRcvAddrTbl; M2_IFRCVADDRTBL * pTempR; M2_ID * pM2Id = NULL; long * pFlags = NULL; index = pIfNet->if_index; switch (status) { case M2_IF_TABLE_INSERT: { pIfIndex = KHEAP_ALLOC(sizeof(M2_IFINDEX)); if (!pIfIndex) return ERROR; memset(pIfIndex, 0, sizeof(M2_IFINDEX)); pIfIndex->ifIndex = index; pIfIndex->pIfStats = pIfNet; /* Set the MIB style flag */ pFlags = (long *) ifnetToEndFieldsGet (pIfNet, END_OBJ_FLAGS); if (pFlags) { if (*pFlags & END_MIB_2233) pIfIndex->mibStyle = TRUE; else pIfIndex->mibStyle = FALSE; } if (if_ioctl) /* use supplied ioctl */ { pIfIndex->ifIoctl = if_ioctl; } else /* default */ { pIfIndex->ifIoctl = ifioctl; } if (addr_get) { pIfIndex->rcvAddrGet = addr_get; } else { pIfIndex->rcvAddrGet = rcvEtherAddrGet; } /* Set Interface OID to default */ memcpy(pIfIndex->ifOid.idArray, ifZeroObjectId.idArray, ifZeroObjectId.idLength * sizeof(long)); pIfIndex->ifOid.idLength = ifZeroObjectId.idLength; /* Fill in the unicast and the multicast addresses */ (*pIfIndex->rcvAddrGet)(pIfNet, pIfIndex); semTake (m2InterfaceSem, WAIT_FOREVER); /* Insert the node in the tree */ if (avlInsert(pM2IfRootPtr, pIfIndex, (GENERIC_ARGUMENT)index, nextIndex) != OK) { semGive (m2InterfaceSem); KHEAP_FREE((char *)pIfIndex); return ERROR; } m2IfCount++; ifsInList = index;#ifdef VIRTUAL_STACK _ifTableLastChange = centiSecsGet();#else /* VIRTUAL_STACK */ ifTableLastChange = centiSecsGet();#endif /* VIRTUAL_STACK */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -