📄 m2iflib.c
字号:
semGive (m2InterfaceSem); if (pM2TrapRtn != NULL) { (*pM2TrapRtn)(M2_LINK_UP_TRAP, pIfIndex->ifIndex, pM2TrapRtnArg); } return OK; } case M2_IF_TABLE_REMOVE: { semTake (m2InterfaceSem, WAIT_FOREVER); /* Remove the node from the tree */ if ((pIfIndex = (M2_IFINDEX *)avlDelete(pM2IfRootPtr, (GENERIC_ARGUMENT)index, nextIndex)) == NULL) { semGive (m2InterfaceSem); return ERROR; } pIfStackTbl = pIfIndex->pNextLower; while (pIfStackTbl != NULL) { pTempS = pIfStackTbl; pIfStackTbl = pIfStackTbl->pNextLower; KHEAP_FREE((char *)pTempS); } pIfRcvAddrTbl = pIfIndex->pRcvAddr; while (pIfRcvAddrTbl != NULL) { pTempR = pIfRcvAddrTbl; pIfRcvAddrTbl = pIfRcvAddrTbl->pNextEntry; KHEAP_FREE((char *)pTempR); } KHEAP_FREE((char *)pIfIndex); m2IfCount--;#ifdef VIRTUAL_STACK _ifTableLastChange = centiSecsGet();#else /* VIRTUAL_STACK */ ifTableLastChange = centiSecsGet();#endif /* VIRTUAL_STACK */ semGive (m2InterfaceSem); if ( (pM2TrapRtn != NULL) && (pIfNet->if_ioctl != NULL) && ((*pIfNet->if_ioctl)(pIfNet, SIOCGMIB2233, (caddr_t)&pM2Id) == 0) ) { if (pM2Id->m2Data.mibXIfTbl.ifLinkUpDownTrapEnable == M2_LINK_UP_DOWN_TRAP_ENABLED) { (*pM2TrapRtn)(M2_LINK_DOWN_TRAP, pIfIndex->ifIndex, pM2TrapRtnArg); } } return OK; } default: return ERROR; } }/******************************************************************************** rcvEtherAddrGet - populate the rcvAddr fields for the ifRcvAddressTable** This function needs to be called to add all physical addresses for which an* interface may receive or send packets. This includes unicast and multicast* addresses. The address is inserted into the linked list maintained in the* AVL node corresponding to the interface. Given the ifnet struct and the* AVL node corresponding to the interface, this function goes through all the* physical addresses associated with this interface and adds them into the* linked list.** RETURNS: OK, if successful; ERROR, otherwise. */LOCAL STATUS rcvEtherAddrGet ( struct ifnet * pIfNet, /* pointer to the interface's ifnet */ M2_IFINDEX * pIfIndexEntry /* avl node */ ) { struct arpcom * pIfArpcom = (struct arpcom*) pIfNet; unsigned char * pEnetAddr = pIfArpcom->ac_enaddr; LIST * pMCastList = NULL; ETHER_MULTI * pEtherMulti = NULL; /* Copy the list of mcast addresses */ if ( (pIfArpcom->ac_if.if_ioctl != NULL) && ((*pIfArpcom->ac_if.if_ioctl)((struct ifnet *)pIfArpcom, SIOCGMCASTLIST, (caddr_t)&pMCastList) != 0) ) { return (ERROR); } /* First create the entry for the unicast address */ rcvEtherAddrAdd (pIfIndexEntry, pEnetAddr); /* Loop thru the mcast linked list and add the addresses */ for ( pEtherMulti = (ETHER_MULTI *) lstFirst (pMCastList); pEtherMulti != NULL; pEtherMulti = (ETHER_MULTI *) lstNext ((NODE *)pEtherMulti) ) { rcvEtherAddrAdd (pIfIndexEntry, (unsigned char *)pEtherMulti->addr); } return (OK); }/****************************************************************************** rcvEtherAddrAdd - add a physical address into the linked list** This function is a helper function for rcvEtherAddrGet. It is called to* add a single physical address into the linked list of addresses maintained* by the AVL node.** RETURNS: OK, if successful; ERROR, otherwise.*/LOCAL STATUS rcvEtherAddrAdd ( M2_IFINDEX * pIfIndexEntry, /* the avl node */ unsigned char * pEnetAddr /* the addr to be added */ ) { M2_IFRCVADDRTBL * pIfRcvAddr = NULL; M2_IFRCVADDRTBL ** ppTemp = &pIfIndexEntry->pRcvAddr; if (pEnetAddr) { pIfRcvAddr = KHEAP_ALLOC(sizeof (M2_IFRCVADDRTBL)); if (!pIfRcvAddr) return ERROR; bcopy (pEnetAddr, pIfRcvAddr->ifRcvAddrAddr.phyAddress, ETHERADDRLEN); pIfRcvAddr->ifRcvAddrAddr.addrLength = ETHERADDRLEN; pIfRcvAddr->ifRcvAddrStatus = ROW_ACTIVE; pIfRcvAddr->ifRcvAddrType = STORAGE_NONVOLATILE; pIfRcvAddr->pNextEntry = NULL; if (pIfIndexEntry->pRcvAddr) { while (*ppTemp) { if (memcmp (pEnetAddr, (*ppTemp)->ifRcvAddrAddr.phyAddress, ETHERADDRLEN) > 0) { ppTemp = &(*ppTemp)->pNextEntry; continue; } else { pIfRcvAddr->pNextEntry = *ppTemp; break; } } } else { pIfIndexEntry->pRcvAddr = pIfRcvAddr; } return (OK); } return (ERROR); }/******************************************************************************** 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.** 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; struct ifnet * pIfNetEntry = NULL; int index; M2_ID * pM2Id = NULL; M2_DATA * pM2Entry = (M2_DATA *)pIfReqEntry; M2_NETDRVCNFG ifDrvCnfg; /* Validate pointer to requeste structure */ if (pIfReqEntry == NULL) { errnoSet (S_m2Lib_INVALID_PARAMETER); return (ERROR); } semTake (m2InterfaceSem, WAIT_FOREVER); /* * For a M2_EXACT_VALUE search, look up the index provided in the * request and get the node from our internal tree. For a * M2_NEXT_VALUE search, look up the successor of this node. */ /* First, Validate the bounds of the requested index */ index = pM2Entry->mibIfTbl.ifIndex; if (index > ifsInList || index < 0) { semGive (m2InterfaceSem); errnoSet (S_m2Lib_ENTRY_NOT_FOUND); return (ERROR); } /* Check to see if it is a EXACT search or a next search */ if (search == M2_EXACT_VALUE) { pIfIndexEntry = (M2_IFINDEX *) avlSearch (pM2IfRoot, (GENERIC_ARGUMENT)index, nextIndex); } else { pIfIndexEntry = (M2_IFINDEX *) avlSuccessorGet (pM2IfRoot, (GENERIC_ARGUMENT)index, nextIndex); } if (!pIfIndexEntry) { semGive (m2InterfaceSem); errnoSet (S_m2Lib_ENTRY_NOT_FOUND); return (ERROR); } /* Initialize the provided structure */ bzero ((char *) pM2Entry, sizeof (M2_DATA)); /* Get the pointer to the ifnet struct for this ifIndex */ pIfNetEntry = (struct ifnet *) pIfIndexEntry->pIfStats; /* Get the interface data from the driver via the Ioctl */ if (pIfIndexEntry->mibStyle == TRUE) { /* Call the RFC 2233 Ioctl */ if ( (pIfNetEntry->if_ioctl != NULL) && ((*pIfNetEntry->if_ioctl)(pIfNetEntry, SIOCGMIB2233, (caddr_t)&pM2Id) != 0) ) { /* ioctl failed, copy default values and return */ m2IfDefaultValsGet (pM2Entry, pIfIndexEntry); pM2Entry->mibIfTbl.ifIndex = pIfIndexEntry->ifIndex; m2IfCommonValsGet (pM2Entry, pIfIndexEntry); semGive(m2InterfaceSem); return (OK); } memcpy ((char *)pM2Entry, (char *)&pM2Id->m2Data, sizeof (M2_DATA)); pM2Entry->mibIfTbl.ifIndex = pIfIndexEntry->ifIndex; semGive (m2InterfaceSem); return (OK); } else { /* Declare variables for RFC 1213 support */ M2_INTERFACETBL * pM2IntTblEntry = &pM2Entry->mibIfTbl; M2_NETDRVCNTRS m2DrvCounters; /* Enter some of the values that we already know */ pM2IntTblEntry->ifIndex = pIfIndexEntry->ifIndex; /* Do what we used to do before for the RFC 1213 only counters */ if ( (pIfNetEntry->if_ioctl != NULL) && ((*pIfNetEntry->if_ioctl)(pIfNetEntry, SIOCGMIB2CNTRS, (caddr_t)&m2DrvCounters) != 0) ) { m2IfDefaultValsGet (pM2Entry, pIfIndexEntry); } else { /* Fill parameters with driver counters */ m2IfDefaultValsGet (pM2Entry, pIfIndexEntry); pM2IntTblEntry->ifSpeed = m2DrvCounters.ifSpeed; pM2IntTblEntry->ifInOctets = m2DrvCounters.ifInOctets; pM2IntTblEntry->ifInDiscards = m2DrvCounters.ifInDiscards; pM2IntTblEntry->ifInUnknownProtos = m2DrvCounters.ifInUnknownProtos; pM2IntTblEntry->ifOutOctets = m2DrvCounters.ifOutOctets; pM2IntTblEntry->ifOutDiscards = m2DrvCounters.ifOutDiscards; /* We can now do the second ioctl to get drv cnfg params */ if ( (*pIfNetEntry->if_ioctl) && ((*pIfNetEntry->if_ioctl)(pIfNetEntry, SIOCGMIB2CNFG, (caddr_t)&ifDrvCnfg) == 0) ) { /* Copy the ifType and the ifSpecific values */ pM2IntTblEntry->ifType = ifDrvCnfg.ifType; if (ifDrvCnfg.ifSpecific.idLength > 0) { bcopy (((char *) ifDrvCnfg.ifSpecific.idArray), ((char *) pM2IntTblEntry->ifSpecific.idArray), ifDrvCnfg.ifSpecific.idLength * sizeof (long)); pM2IntTblEntry->ifSpecific.idLength = ifDrvCnfg.ifSpecific.idLength; } } else { /* * no info from ioctl, make an educated guess at * the driver configuration */ if (strncmp(pIfNetEntry->if_name, "lo", 2) == 0) { /* IP Loop back interface. */ pM2IntTblEntry->ifType = M2_ifType_softwareLoopback; pM2IntTblEntry->ifSpeed = 0; } else if (strncmp(pIfNetEntry->if_name, "sl", 2) == 0) { /* Slip Network Interface */ pM2IntTblEntry->ifType = M2_ifType_slip; pM2IntTblEntry->ifSpeed = 19200; /* Baud Rate ??? */ } else if (strncmp(pIfNetEntry->if_name, "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); } semGive (m2InterfaceSem); return (OK); }/******************************************************************************** m2IfDefaultValsGet - get the default values for the counters*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -