📄 m2ppplinkgroup.c
字号:
/* m2pppLinkGroup.c - SNMP PPP Link MIB Group implementation *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01g,18dec02,qhu rollback the change made previously. 01f,18dec02,qhu delete m2pppIpcpGroupInterfacesTable in m2pppIpcpGroupUnregister, SPR 85198.01e,16sep02,rp fix for SPR 8206901d,28may02,rvr fixed build warnings (teamf1)01c,17mar00,adb HTML Manual fixes01b,22feb00,sj fixing memory leak in Register01a,06jan00,sj created.*//*DESCRIPTIONThis library implements pppLinkStatusTable and pppLinkConfigTable which arepare of the PPP Link MIB Group which is specified in RFC 1471.INCLUDE FILES: m2pppLinkGroup.h lcpInterfaces.h pfwStack.hSEE ALSO: m2pppLib*//* includes */#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "logLib.h"#include "tickLib.h"#include "pfw/pfw.h"#include "pfw/pfwStack.h"#include "pfw/pfwTable.h"#include "pfw/pfwMemory.h"#include "ppp/m2pppLib.h"#include "ppp/m2pppLinkGroup.h"#include "ppp/interfaces/lcpInterfaces.h"/* defines *//* typedefs */typedef struct m2pppLinkGroupInterfacesEntry { PFW_OBJ * pfwObj; /*framework for which*/ /*these interfaces */ /* exist */ int key; /* tableItem number */ PPP_LINK_STATUS_ENTRY_INTERFACE * pppLinkStatusEntry; PPP_LINK_CONFIG_ENTRY_INTERFACE * pppLinkConfigEntry; }M2_PPP_LINK_GROUP_INTERFACES_ENTRY;/* globals *//* locals */LOCAL PFW_TABLE_OBJ * m2pppLinkGroupInterfacesTable = NULL;/* forwards */LOCAL M2_PPP_LINK_GROUP_INTERFACES_ENTRY * linkGroupInterfacesGet (PFW_OBJ *);LOCAL BOOL compareLinkGroupEntry (UINT32 key, void * pItem, void * arg);/******************************************************************************** m2pppLinkGroupRegister - register/initialize PPP Link MIB Group interfaces** This routine allows the PPP framework component that supports the PPP* Link MIB Group to publish its support. Typically the LCP* framework component supports this MIB. * * RETURNS: OK on successful registration and ERROR otherwise** SEE ALSO: m2pppLib*/STATUS m2pppLinkGroupRegister ( PFW_OBJ * pfwObj /* PPP Framework context */ ) { M2_PPP_LINK_GROUP_INTERFACES_ENTRY * linkGroupInterfaces; int id; if (m2pppLinkGroupInterfacesTable == NULL) { if ((m2pppLinkGroupInterfacesTable = pfwTableCreate(NULL,2,-1)) == NULL) { printf ("m2pppLinkGroupInit: Failed to create m2pppLinkGroupInterfacesTable \n"); return ERROR; } } if ((linkGroupInterfaces = pfwMalloc(pfwObj, sizeof(M2_PPP_LINK_GROUP_INTERFACES_ENTRY))) == NULL) { return ERROR; } /* get the interface pointers */ linkGroupInterfaces->pfwObj = pfwObj; if ((id = pfwInterfaceIdGet(pfwObj, "PPP_LINK_STATUS_ENTRY_INTERFACE")) == 0) { logMsg("m2LinkGroup: Could not get linkStatus interface ID\n", 1,2,3,4,5,6); pfwFree(linkGroupInterfaces); return ERROR; } if ((linkGroupInterfaces->pppLinkStatusEntry = (PPP_LINK_STATUS_ENTRY_INTERFACE *) pfwInterfaceObjGetViaPfwObj (pfwObj,id)) == NULL) { pfwPrintError (__FILE__, "m2pppLinkGroupInit", __LINE__, pfwObj, 0,"No PPP_LINK_STATUS_ENTRY_INTERFACE!"); pfwFree(linkGroupInterfaces); return ERROR; } if ((id = pfwInterfaceIdGet(pfwObj, "PPP_LINK_CONFIG_ENTRY_INTERFACE")) == 0) { logMsg("m2LinkGroup: Could not get linkConfig interface ID\n", 1,2,3,4,5,6); pfwFree(linkGroupInterfaces); return ERROR; } if ((linkGroupInterfaces->pppLinkConfigEntry = (PPP_LINK_CONFIG_ENTRY_INTERFACE *) pfwInterfaceObjGetViaPfwObj (pfwObj,id)) == NULL) { pfwPrintError (__FILE__, "m2pppLinkGroupInit", __LINE__, pfwObj, 0,"No PPP_LINK_CONFIG_ENTRY_INTERFACE!"); pfwFree(linkGroupInterfaces); return ERROR; } /* save interfaces information in table */ linkGroupInterfaces->key = pfwTableItemAdd(m2pppLinkGroupInterfacesTable,linkGroupInterfaces); return OK; }/******************************************************************************** m2pppLinkGroupUnregister - withdraw PPP Link MIB Group support** This routine allows the PPP framework component that supports the PPP* Link MIB Group to withdraw its support.** RETURNS: OK on success and ERROR otherwise* * SEE ALSO: m2pppLib*/STATUS m2pppLinkGroupUnregister ( PFW_OBJ * pfwObj /* PPP Framework context */ ) { M2_PPP_LINK_GROUP_INTERFACES_ENTRY * linkGroupInterfaces; if (m2pppLinkGroupInterfacesTable == NULL) return ERROR; if ((linkGroupInterfaces = linkGroupInterfacesGet(pfwObj)) == NULL) return ERROR; pfwInterfaceReferenceDelete( &linkGroupInterfaces->pppLinkStatusEntry->interfaceObj); pfwInterfaceReferenceDelete( &linkGroupInterfaces->pppLinkConfigEntry->interfaceObj); /* delete interfaces information from table */ pfwTableItemDelete(m2pppLinkGroupInterfacesTable,linkGroupInterfaces->key); pfwFree(linkGroupInterfaces); return OK; }/******************************************************************************** m2pppLinkStatusEntryLookup - access pppLinkStatusEntry keyed by link ID** This routine retrieves pppLinkStatusEntry data based on PPP link ID.** The first and only entry of the array argument <oid> specifies the link ID* which is the key to the pppLinkStatusEntry. The argument <oidLen> that * specifies the number of elements in the <oid> array should be set to 1.** If <M2_PPP_ENTRY_MATCH_TYPE> is set to M2_PPP_ENTRY_EXACT_MATCH * the data that correspond to the input key will be retrieved.* If <M2_PPP_ENTRY_MATCH_TYPE> is set to M2_PPP_ENTRY_NEXT_MATCH, * the data corresponding to the key that is minimum superior to the* input key will be retrieved, provided that an entry exists with * key superior to the input key. ** The input key may be 0 only in the M2_PPP_ENTRY_NEXT_MATCH case call.** This routine must be called before a set operation can be performed for any* of the leaf objects in this entry in order to retrieve the necessary * references and contexts which are stored in the corresponding* PPP_LINK_STATUS_ENTRY_DATA structure.** RETURNS: OK or ERROR** SEE ALSO: m2pppLib*/STATUS m2pppLinkStatusEntryLookup ( UINT32 oidLen, /* should be set to 1 */ UINT32 * oid, /* should point to link ID */ PPP_LINK_STATUS_ENTRY_DATA * data, /* placeholder for retrieved data */ M2_PPP_ENTRY_MATCH_TYPE match /* EXACT or NEXT */ ) { int ifIndex = (oid != NULL && oidLen == 1) ? *oid : 0; int nextIfIndex = 0; M2_PPP_LINK_GROUP_INTERFACES_ENTRY * linkGroupInterfaces; if (match == M2_PPP_ENTRY_EXACT_MATCH && ifIndex <= 0) return ERROR; else if (match == M2_PPP_ENTRY_NEXT_MATCH && ifIndex < 0) return ERROR; if ((match == M2_PPP_ENTRY_EXACT_MATCH) && (m2pppInterfaceStackObjGet(ifIndex,&data->stackObj) != OK)) return ERROR; if ((match == M2_PPP_ENTRY_NEXT_MATCH) && (m2pppNextInterfaceStackObjGet((UINT32)ifIndex,(UINT32 *)&nextIfIndex,&data->stackObj) != OK)) return ERROR; if (data->stackObj == NULL) return ERROR; if ((linkGroupInterfaces = linkGroupInterfacesGet(pfwStackObjPfwGet(data->stackObj))) == NULL) return ERROR; data->interface = linkGroupInterfaces->pppLinkStatusEntry; if ((data->state = pfwPluginObjStateGet (data->stackObj, data->interface->interfaceObj.pluginObj)) == NULL) return ERROR; return OK; }/******************************************************************************** m2pppLinkConfigEntryLookup - access pppLinkConfigEntry keyed by link ID** This routine retrieves pppLinkConfigEntry data based on PPP link ID.** The first and only entry of the array argument <oid> specifies the link ID* which is the key to the pppLinkConfigEntry. The argument <oidLen> that * specifies the number of elements in the <oid> array should be set to 1.** If <M2_PPP_ENTRY_MATCH_TYPE> is set to M2_PPP_ENTRY_EXACT_MATCH * the data that correspond to the input key will be retrieved.* If <M2_PPP_ENTRY_MATCH_TYPE> is set to M2_PPP_ENTRY_NEXT_MATCH, * the data corresponding to the key that is minimum superior to the* input key will be retrieved, provided that an entry exists with * key superior to the input key. ** The input key may be 0 only in the M2_PPP_ENTRY_NEXT_MATCH case call.** This routine must be called before a set operation can be performed for any* of the leaf objects in this entry in order to retrieve the necessary * references and contexts which are stored in the corresponding* PPP_LINK_CONFIG_ENTRY_DATA structure.** RETURNS: OK or ERROR** SEE ALSO: m2pppLib*/STATUS m2pppLinkConfigEntryLookup ( UINT32 oidLen, /* should be set to 1 */ UINT32 * oid, /* should point to link ID */ PPP_LINK_CONFIG_ENTRY_DATA * data, /* placeholder for retrieved data */ M2_PPP_ENTRY_MATCH_TYPE match /* EXACT or NEXT */ ) { int ifIndex = (oid != NULL && oidLen == 1) ? *oid : 0; int nextIfIndex =0; M2_PPP_LINK_GROUP_INTERFACES_ENTRY * linkGroupInterfaces; if (match == M2_PPP_ENTRY_EXACT_MATCH && ifIndex <= 0) return ERROR; else if (match == M2_PPP_ENTRY_NEXT_MATCH && ifIndex < 0) return ERROR; if ((match == M2_PPP_ENTRY_EXACT_MATCH) && (m2pppInterfaceStackObjGet(ifIndex,&data->stackObj) != OK)) return ERROR; if ((match == M2_PPP_ENTRY_NEXT_MATCH) && (m2pppNextInterfaceStackObjGet((UINT32)ifIndex,(UINT32 *)&nextIfIndex,&data->stackObj) != OK)) return ERROR; if (data->stackObj == NULL) return ERROR; if ((linkGroupInterfaces = linkGroupInterfacesGet(pfwStackObjPfwGet(data->stackObj))) == NULL) return ERROR; data->interface = linkGroupInterfaces->pppLinkConfigEntry; if ((data->state = pfwPluginObjStateGet (data->stackObj, data->interface->interfaceObj.pluginObj)) == NULL) return ERROR; return OK; }/******************************************************************************** linkGroupInterfacesGet -*/LOCAL M2_PPP_LINK_GROUP_INTERFACES_ENTRY * linkGroupInterfacesGet ( PFW_OBJ * pfwObj ) { int key; key = pfwTableTraverse(m2pppLinkGroupInterfacesTable, compareLinkGroupEntry,pfwObj); if (key == 0) return NULL; else return (pfwTableItemGet(m2pppLinkGroupInterfacesTable,key)); }/******************************************************************************** compareLinkGroupEntry -*/LOCAL BOOL compareLinkGroupEntry ( UINT32 key, void * pItem, void * arg ) { M2_PPP_LINK_GROUP_INTERFACES_ENTRY * tableEntry = pItem; PFW_OBJ * thisPfw = arg; if (tableEntry->pfwObj == thisPfw) return TRUE; return FALSE; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -