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

📄 m2iflib.c

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
* 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 void m2IfDefaultValsGet    (    M2_DATA *    pM2Data,        /* The requested entry */    M2_IFINDEX * pIfIndexEntry   /* The ifindex node */    )    {    struct ifnet * pIfNetEntry = (struct ifnet *)pIfIndexEntry->pIfStats;    /* We will check only for loopback here */    if (strncmp(pIfNetEntry->if_name, "lo", 2) == 0)        pM2Data->mibIfTbl.ifType = M2_ifType_softwareLoopback;    else        pM2Data->mibIfTbl.ifType = M2_ifType_other;    if (pIfIndexEntry->mibStyle == TRUE)        {        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;    }/******************************************************************************** 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 void m2IfCommonValsGet    (    M2_DATA *    pM2Data,        /* The requested struct */    M2_IFINDEX * pIfIndexEntry   /* The ifindex node */    )    {    struct ifnet *    pIfNetEntry    = (struct ifnet *)pIfIndexEntry->pIfStats;    M2_INTERFACETBL * pM2IntTblEntry = &pM2Data->mibIfTbl;    struct arpcom *   pArpcomEntry   = (struct arpcom *)pIfNetEntry;        sprintf (pM2IntTblEntry->ifDescr, "%s%d",                     pIfNetEntry->if_name, pIfNetEntry->if_unit);    if (!pM2IntTblEntry->ifSpecific.idLength)        {        memcpy (pM2IntTblEntry->ifSpecific.idArray, pIfIndexEntry->ifOid.idArray,            ((int) pIfIndexEntry->ifOid.idLength * sizeof (long)));        pM2IntTblEntry->ifSpecific.idLength = pIfIndexEntry->ifOid.idLength;        }    pM2IntTblEntry->ifMtu = pIfNetEntry->if_mtu;    /* If the device does not have a hardware address set it to zero */     if (pIfNetEntry->if_flags &                        (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_NOARP))        {        memset(&(pM2IntTblEntry->ifPhysAddress), 0, sizeof(M2_PHYADDR));        }    else        {        bcopy (((char *) pArpcomEntry->ac_enaddr),              ((char *) pM2IntTblEntry->ifPhysAddress.phyAddress),                                                          ETHERADDRLEN);        pM2IntTblEntry->ifPhysAddress.addrLength = ETHERADDRLEN;        }    /* Get the ifAdminStatus, ifLastChange, and ifOperStatus  */    pM2IntTblEntry->ifAdminStatus = (((pIfNetEntry->if_flags & IFF_UP) != 0) ?                                     M2_ifAdminStatus_up :                                     M2_ifAdminStatus_down);    /*    pNetIf->netIfAdminStatus  = pIfReqEntry->ifAdminStatus;    pM2IntTblEntry->ifLastChange = pIfNetEntry->netIfLastChange;    */    pM2IntTblEntry->ifOperStatus = (((pIfNetEntry->if_flags & IFF_UP) != 0) ?                                    M2_ifOperStatus_up : M2_ifOperStatus_down);    if (pIfIndexEntry->mibStyle != TRUE)        {        pM2IntTblEntry->ifInUcastPkts  = pIfNetEntry->if_ipackets -                                         pIfNetEntry->if_imcasts;        pM2IntTblEntry->ifInNUcastPkts = pIfNetEntry->if_imcasts;        pM2IntTblEntry->ifInErrors     = pIfNetEntry->if_ierrors;        pM2IntTblEntry->ifOutUcastPkts = pIfNetEntry->if_opackets -                                         pIfNetEntry->if_omcasts;        pM2IntTblEntry->ifOutNUcastPkts= pIfNetEntry->if_omcasts;        pM2IntTblEntry->ifOutErrors    = pIfNetEntry->if_oerrors;	pM2IntTblEntry->ifOutQLen      = pIfNetEntry->if_snd.ifq_len;        /*         * XXX Due to inconsistant increment between ifInUnknownProtos by         * muxReceive and if_noproto by do_protocol_with_type, this routine         * will synchronize both statistics here. In future, these increments         * should be consistantly updated at the same place.         */        pIfNetEntry->if_noproto = pM2IntTblEntry->ifInUnknownProtos; /* XXX */        }    return;    }/******************************************************************************** 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, ifAlias, ifLinkUpDownTrapEnable and ifName.** 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;    M2_IFINDEX *    pIfIndexEntry = NULL;    struct ifnet *  pIfNetEntry = NULL;    struct ifreq    ifReqChange;    IF_SETENTRY *   pM2Entry = (IF_SETENTRY *)pIfReqEntry;    M2_ID *         pM2Id = NULL;        semTake (m2InterfaceSem, WAIT_FOREVER);    /* Validate the bounds of the requested index  */    index = pM2Entry->ifIndex;    if (index < 0 || index > ifsInList)        {	errnoSet (S_m2Lib_ENTRY_NOT_FOUND);        semGive (m2InterfaceSem);        return (ERROR);        }    /* Get the node associated with the index */    pIfIndexEntry = (M2_IFINDEX *) avlSearch (pM2IfRoot,                                       (GENERIC_ARGUMENT)index, nextIndex);    if (!pIfIndexEntry)	{	semGive (m2InterfaceSem);        return (ERROR);        }    pIfNetEntry = (struct ifnet *) pIfIndexEntry->pIfStats;    /*     * The only supported state changes for the interface are UP and DOWN.     * The TEST case is not supported by the drivers.     */    if (pM2Entry->varToSet & M2_varId_ifAdminStatus)        {        if (pM2Entry->ifAdminStatus == M2_ifAdminStatus_up)            {            /*             * If the driver is in the UP state, there is no need to send the             * IOCTL command, otherwise format the IOCTL request.             */            if ( (pIfNetEntry->if_flags & IFF_UP) == 0)                ifReqChange.ifr_flags = pIfNetEntry->if_flags | IFF_UP;            else                pM2Entry->varToSet =                     pM2Entry->varToSet & ~M2_varId_ifAdminStatus;            }        else            {            /* 	     * If the driver is in the DOWN state, there is no need to send the	     * IOCTL command, otherwise format the IOCTL request. 	     */             if ((pIfNetEntry->if_flags & IFF_UP) != 0)                ifReqChange.ifr_flags = pIfNetEntry->if_flags & ~IFF_UP;            else                pM2Entry->varToSet =                       pM2Entry->varToSet & ~M2_varId_ifAdminStatus;            }        /* Stop if no work is needed. */        if (pM2Entry->varToSet == 0)	    {	    semGive (m2InterfaceSem);            return (OK);	    }        }    /* Check to see if we have to set the promiscuous mode */    if (pM2Entry->varToSet & M2_varId_ifPromiscuousMode)        {        if (pM2Entry->ifPromiscuousMode == M2_ifPromiscuousMode_on)            ifReqChange.ifr_flags = pIfNetEntry->if_flags | IFF_PROMISC;        else             ifReqChange.ifr_flags = pIfNetEntry->if_flags & ~IFF_PROMISC;        }    /* 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.         */        sprintf (ifReqChange.ifr_name,"%s%d", pIfNetEntry->if_name,						pIfNetEntry->if_unit);        if ((*pIfIndexEntry->ifIoctl)(0, SIOCSIFFLAGS, (char *)&ifReqChange) != 0)            {            semGive (m2InterfaceSem);            return (ERROR);            }        if ( (pIfNetEntry->if_ioctl != NULL) &&             ((*pIfNetEntry->if_ioctl)(pIfNetEntry, SIOCGMIB2233,                                       (caddr_t)&pM2Id) == OK) )            {	    if (pM2Entry->varToSet & M2_varId_ifAdminStatus)		{		(*pM2Id->m2VarUpdateRtn)(pM2Id, M2_varId_ifAdminStatus,					(caddr_t)pM2Entry->ifAdminStatus);                }            if (pM2Entry->varToSet & M2_varId_ifPromiscuousMode)		{		(*pM2Id->m2VarUpdateRtn)(pM2Id, M2_varId_ifPromiscuousMode,					(caddr_t)pM2Entry->ifPromiscuousMode);                }            }        }    else         {        /*          * For the others, we have to get a pointer to the interface          * table, so we call the SIOCSMIB2233 IOCTL and let the driver         * call our appropriate set routine. In this case, the set         * routine is m2IfSnmpSet().         */        if ( (pIfNetEntry->if_ioctl) &&             ((*pIfNetEntry->if_ioctl) (pIfNetEntry, SIOCSMIB2233,                                               (caddr_t)pIfReqEntry) != 0) )            {            semGive (m2InterfaceSem);            return (ERROR);            }        }    semGive (m2InterfaceSem);    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 */    )    {    semTake (m2InterfaceSem, WAIT_FOREVER);     /* Validate the input parameter pointer */    if (pIfInfo == NULL)        {        semGive (m2InterfaceSem);	errnoSet (S_m2Lib_INVALID_PARAMETER);        return (ERROR);        }    /*     * Number of network interfaces in the system independent of     * their state     */     pIfInfo->ifNumber = m2IfCount;  #ifdef VIRTUAL_STACK    pIfInfo->ifTableLastChange = _ifTableLastChange;    pIfInfo->ifStackLastChange = _ifStackLastChange;#else    /* VIRTUAL_STACK */    pIfInfo->ifTableLastChange = ifTableLastChange;    pIfInfo->ifStackLastChange = ifStackLastChange;#endif   /* VIRTUAL_STACK */     semGive (m2InterfaceSem);    return OK;    }/******************************************************************************** m2IfStackTblUpdate - update the relationship between the sub-layers** This function must be called to setup the relationship between the* ifIndex values for each sub-layer. This information is required to * support the ifStackTable for RFC 2233. Using this data, we can easily* determine which sub-layer runs on top of which other. ** <action> is either M2_STACK_TABLE_INSERT or M2_STACK_TABLE_REMOVE.** Each AVL node keeps a linked list of all the l

⌨️ 快捷键说明

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