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

📄 m2ppplib.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* m2pppLib.c - SNMP MIB-2 to Remote Access PPP framework interface library *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01a,17jul02,emr  Bring in line for ATM 2.0 development and release01d,28may02,rvr fixed build warnings (teamf1)01c,14feb00,adb WRS coding conventions01b,26jan00,abd replaced references to pfwTable.h structures and routines                 with references to avlLib.h structures and routines.01a,06jan00,sj  created.*//*DESCRIPTIONThis library serves as an interface layer between the SNMP agent and the RemoteAccess PPP framework. It is essential to the implementation of all PPP relatedManagement Information Bases. It creates and supports a database dereferencing interface indices to PFW_STACK_OBJ pointers.INCLUDE FILES: m2pppLib.h, pfwStack.h*//* includes */#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "semLib.h"#include "logLib.h"#include "pfw/pfw.h"#include "pfw/pfwStack.h"#include "avlLib.h"#include "ppp/m2pppLib.h"/* defines */#define M2_PPP_LIB_SEM_TAKE(m2pppLibSem)                            \    do  {                                                           \        if  (semTake(m2pppLibSem, WAIT_FOREVER) != OK)              \            {                                                       \            logMsg("Failure to acquire #m2pppLibSem semaphore\n",   \                   0,0,0,0,0,0);                                    \            return ERROR;                                           \            };                                                      \        }   while(0)#define M2_PPP_LIB_SEM_GIVE(m2pppLibSem)                                \    do  {                                                               \        if  (semGive(m2pppLibSem) !=OK)                                 \            {                                                           \            logMsg("semGive failed; #m2pppLibSem is likely invalid\n",  \                   0,0,0,0,0,0);                                        \            return ERROR;                                               \            };                                                          \        }   while(0)#define POPULATE_M2_PPP_KEY_ENTRY       \    do  {                               \        keyEntry.avlBase.left = NULL;   \        keyEntry.avlBase.right = NULL;  \        keyEntry.avlBase.height = 1;    \        keyEntry.ifIndex = ifIndex;     \        keyEntry.stackObj = NULL;       \        }   while(0)    /* typedefs */typedef struct m2pppIfIndexToStackObjEntry               /* The m2pppIfIndexToStackObjEntry inherits from AVL_NODE and                * it will be the node type of the m2pppIfIndexToStackObjTree.                * The unique identifier of such a node will be its ifIndex.                */    {    AVL_NODE         avlBase;  /* base class avl tree node */    UINT32           ifIndex;  /* unique identifier for each PPP link */                               /* Values of ifIndex are ordered by "<"                                 */    PFW_STACK_OBJ *  stackObj; /* corresponding PPP framework stack instance */                               /* Note that we will encounter a conflict of                                * naming conventions: stackObj is a pointer                                * to a struct and throughout the pfw and ppp                                * directories this notation is used; that is,                                * prefices or suffices indicating pointers are                                * ommitted. However, to be consistent with                                 * avlLib conventions we would discriminately                                * add Ptr to tree and node pointers.                                 */    } M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY;/* globals *//* locals */LOCAL SEM_ID        m2pppLibSem = NULL;LOCAL AVL_TREE      m2pppIfIndexToStackObjTree = NULL;                     /* pointer to the root node of the tree */LOCAL AVL_TREE *    m2pppIfIndexToStackObjTreePtr = &m2pppIfIndexToStackObjTree;                    /* pointer to the tree */                    /* Note that avlInsert requires as input a valid pointer                      * to an AVL_TREE pointing to a valid pointer to AVL_NODE.                     * In the body of avlInsert the input AVL_TREE pointer                     * will be dereferenced to an AVL_TREE i.e. to an                      * AVL_NODE pointer which subsequently will be evaluated.                     * It is simpler to statically declare and initialize both.                     *//* forwards */LOCAL int compareMain          /* Manipulation of an avlTree requires a function that compares keys.           * This function is instance specific and its arguments are a pointer           * to an AVL_NODE and a generic argument to be used as a key bind. We           * will pass a key by passing a pointer to an encompassing tree node.           */    (    void *              nodePtr,     GENERIC_ARGUMENT    keyPtr    );/******************************************************************************** m2pppLibInit - initialize the MIB-2 library for Remote Access PPP Framework** It creates and allocates all structures necessary for the installation of* the ifIndex to PFW_STACK_OBJ database.** NOTE: There will be no action if m2pppLibSem is non-NULL.** RETURNS: OK if the initialization was successful and ERROR otherwise.*/STATUS m2pppLibInit(void)    {    if  (NULL == m2pppLibSem)         {        if  ((m2pppLibSem = semMCreate(SEM_DELETE_SAFE |                                        SEM_Q_PRIORITY |                                        SEM_INVERSION_SAFE))             != NULL)            {            return OK;            }        else            {            logMsg("m2pppLibInit failed due to semaphore creation failure\n",                    0,0,0,0,0,0);            return ERROR;            }        }    else        {        logMsg("m2pppLibInit was called but m2pppLibSem was not NULL\n",               0,0,0,0,0,0);        return ERROR;        }    }/******************************************************************************** m2pppInterfaceRegister - register a PPP interface for management via SNMP** Dynamic registration of PFW_STACK_OBJ structures via their interface indices.** NOTE: We do not check the validity of the input.** RETURNS: OK if an entry with the input data was successfully created and* entered to the database and ERROR otherwise.*/STATUS m2pppInterfaceRegister    (    UINT32 ifIndex,             /* ifIndex of the PFW_STACK_OBJ to be added */    PFW_STACK_OBJ * stackObj    /* pointer to the PFW_STACK_OBJ to be added */    )    {    M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY *    newEntryPtr;    GENERIC_ARGUMENT auxGenericArgument;        /* This routine is a wrapper of avlInsert.      * First we attempt to allocate memory for the newEntry     * Subsequently we initialize newEntry and keyEntry and      * we pass to avlInsert pointers to newEntry and keyEntry.     * In our design compareMain considers as key of a node the whole node and     * accepts as arguments two M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY pointers.      * This design simplifies the handling of trees with multiple keys.     */    if  (ifIndex > MAX_IF_INDEX) return ERROR;    M2_PPP_LIB_SEM_TAKE(m2pppLibSem);    if  (NULL == (newEntryPtr =                   (M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY *)                  malloc(sizeof(M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY))))        /* We are responsible for memory management.         * The functionality of avlLib does not include memory management.         */        {        logMsg("malloc failure in m2pppInterfaceRegister; ifIndex = %u\n",                ifIndex, 0,0,0,0,0);        M2_PPP_LIB_SEM_GIVE(m2pppLibSem);        return ERROR;        }    else            {        newEntryPtr->avlBase.left = NULL;        newEntryPtr->avlBase.right = NULL;        newEntryPtr->avlBase.height = 1;        newEntryPtr->ifIndex = ifIndex; /* newEntry non-trivial datum */        newEntryPtr->stackObj = stackObj; /*newEntry not-trivial datum */        }    /* avlInsert's first argument should point to a pointer to the root node */    auxGenericArgument.p = (void *)newEntryPtr;        if  (avlInsert(m2pppIfIndexToStackObjTreePtr,                   newEntryPtr,                    auxGenericArgument,                   compareMain)                   /* note that newEntryPtr appears twice */         != OK)        {        /* A node with the given ifIndex exists already on the tree */        free(newEntryPtr);        M2_PPP_LIB_SEM_GIVE(m2pppLibSem);        return ERROR;        }    else        {        M2_PPP_LIB_SEM_GIVE(m2pppLibSem);        return OK;        }    }/******************************************************************************** m2pppInterfaceUnregister - Unregister an SNMP managed PPP interface ** Dynamic deregistration of PPP interfaces.** RETURNS: OK if an entry exists with the input <ifIndex> key* and ERROR otherwise.*/STATUS m2pppInterfaceUnregister    (    UINT32 ifIndex  /* the ifIndex of the interface that we want to remove */    )    {    M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY  keyEntry;    M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY *    retrievedEntryPtr;    GENERIC_ARGUMENT auxGenericArgument;        /* This routine is a wrapper of avlDelete.      * In our design compareMain considers as key of a node the whole node and     * accepts as arguments two M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY pointers.      * This design simplifies the handling of trees with multiple keys.     * After initializing keyEntry we pass its address to avlSearch.     */    if  (ifIndex > MAX_IF_INDEX) return ERROR;    M2_PPP_LIB_SEM_TAKE(m2pppLibSem);    POPULATE_M2_PPP_KEY_ENTRY;    /* avlDelete's first argument should point to a pointer to the root node */    /* Note that avlDelete does not perform memory management.     * If a node with the input <ifIndex> exists on the tree then     * avlDelete removes it from the tree, rebalances the tree, and returns      * the node for memory management to the caller. Else it returns NULL.     */    auxGenericArgument.p = (void *)(&keyEntry);        if  (NULL ==          (retrievedEntryPtr =           avlDelete(m2pppIfIndexToStackObjTreePtr,                     auxGenericArgument,                    compareMain)))        {        /* A node with the given ifIndex does not exist on the tree */        M2_PPP_LIB_SEM_GIVE(m2pppLibSem);        return ERROR;        }    else        {        free(retrievedEntryPtr);            M2_PPP_LIB_SEM_GIVE(m2pppLibSem);        return OK;        }       }

⌨️ 快捷键说明

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