📄 pppend.c
字号:
/* pppEnd.c - PPP END network interface driver *//* Copyright 1984-1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02o,10jun03,ijm use STACK_NAME to distinguish network stacks02n,15nov02,ijm do not add loopback route for the local PPP interface, network stack should take care of it, see SPR# 84192. Added documentation for default ppp interface naming scheme. Use PPP_END_MAX_SESSIONS_PER_FRWK instead of 256.02m,04nov02,ijm adding IFF_MULTICAST flag;use printf instead of logMsg02l,22aug02,ijm return proper value for EIOCGMIB2233 ioctl02k,28jun02,ijm do not compile for IPv602j,28may02,rvr fixed build warnings 02i,20feb02,ijm fixed compilation warning in pppUnload02h,06feb02,ijm set pStackData->pDrvCtrl to NULL in stackDelete, SPR#71855 Set END_MIB_2233 flag in pppLoad and set pDrvCtrl->end.pMib2Tbl to NULL in pppUnload if RFC2233 capable.02g,31oct01,ijm free pMib2Tbl if PPP_END_RFC2233_CAPABLE in pppUnload. fixed receiveIf compilation warning.02f,25apr01,sj delete routes unconditionally in bringDownIpInterface02e,23apr01,sj use malloc() to allocate END_OBJ for T2CP4 and dont free it in pppUnload()02d,20apr01,ijm removed redundant calls to ifFlagSet in pppStart, pppStop and createIpInterface02c,16apr01,sj added conditional compilation for RFC_2233 support02b,27mar01,ijm added compilation flag PPP_T2CP3_OR_BELOW_COMPATIBLE to handle (T2CP4 = T2.0.2) change in formAddress prototype (see end.h)02a,26mar01,ijm updated pppAddressForm's prototype for T2.0.2. Added loopback route for local PPP address so local ping works. 01z,02mar01,ijm added ioctl command SIOCSIFDSTADDR01y,17jan01,ijm moved prepending of PPP header from pppEndSend to its proper place in pppAddressForm01x,16nov00,sj publish and respond to PPP_SUB_LAYER_TX_BLOCKED/UNBLOCKED events01w,29sep00,sj Merging in and reorganizing RFC2233 instrumentation01v,29sep00,sj merging with TOR2_0-WINDNET_PPP-CUM_PATCH_201u,22sep00,cn deleting END object's txSem in pppUnload ().01t,07sep00,sj comment out mRouteAdd failed code01s,05sep00,cn freeing address strings in bringUpIpInterface (), bringDownIpInterface () (SPR# 34219).01s,04aug00,adb Set invalid IP address upon IP interface creation01r,28jul00,adb Set IFF_RUNNING when interface is up and embed END_OBJ in PPP_DRV_CTRL01q,27jun00,bsn added ipRouteAdd, ipRouteDel, ipSetIfMask to PPP_IP_INTERFACE01p,22jun00,sj on failure of mRouteAdd() drop link01o,10apr00,cn zero-out llHdrInfo in pppPacketDataGet () SPR# 30767 Also added setting of pNetPool in pppEndLoad () SPR# 30768.01n,21mar00,sj removed bad typecast for pfwPluginObjStateLock argument01m,13mar00,sj append unit# to ifName in pppStart and pppStop + lock state in pppIoctl01l,25feb00,sj set a mask for IP interface in createIpInterface01k,23feb00,sj Pedantic ANSI fixes01j,22feb00,sj changed m2pppInterfaceAdd to m2pppInterfaceRegister01i,17feb00,sj changed to mRouteAdd/Del and use ifFlagSet for changing IFstate01h,10feb00,sj added calls to m2pppInterfaceAdd and Delete01g,07feb00,sj adding EIOCSFLAGS support + PPP_LINK_ID_INTERFACE support01f,15dec99,sgv Added multicast support; delete route on if_down()01e,30nov99,sj muxDevUnload after ipDetach01d,30nov99,sj perform ifNet UP and DOWN operations in netTask context01c,29nov99,sgv Added comments01b,28oct99,sgv modified to the new framework01a,12apr99,sgv written.*//*DESCRIPTIONThis component implements END interface for the PPP Stack. This componentresides in the interface layer of the data plane.This component provides an END interface for upper layer network protocols such as IP to interfacewith the PPP stack*//* includes */#include "vxWorks.h"#include "stdlib.h"#include "logLib.h"#include "intLib.h"#include "end.h" /* Common END structures. */#include "endLib.h"#if (!((defined STACK_NAME) && (STACK_NAME == STACK_NAME_V4_V6)))#include "lstLib.h" /* Needed to maintain protocol list. */#include "netLib.h"#include "stdio.h"#include "errno.h"#include "errnoLib.h"#include "net/mbuf.h"#include "netinet/in.h"#include "netinet/ip.h"#include "net/systm.h"#include "net/if.h"#include "net/route.h"#include "routeLib.h"#include "inetLib.h"#include "ifLib.h"#include "netBufLib.h"#include "sys/ioctl.h"#include "ppp/kstart.h"#include "ppp/kppp.h"#include "pfw/pfw.h"#include "pfw/pfwStack.h"#include "pfw/pfwComponent.h"#include "pfw/pfwTimer.h"#include "pfw/pfwEvent.h"#include "pfw/pfwLayer.h"#include "pfw/pfwMemory.h"#include "pfw/pfwProfile.h"#include "ppp/m2pppLib.h"#include "ppp/interfaces/pppIpInterfaces.h"#include "ppp/interfaces/lcpInterfaces.h"#include "ppp/interfaces/pppLinkIdInterface.h"#include "ppp/interfaces/componentAcceptableProtocolsInterface.h"#include "ppp/interfaces/pppInterfacesGroupInterfaces.h"#include "ppp/pppEndComponent.h"#include "resolvLib.h"/* externs */IMPORT int ipAttach(int unit, char* pDevice);IMPORT int ipDetach(int unit, char* pDevice);/* typedefs */#define PPP_END_MAX_SESSIONS_PER_FRWK 256 /* * Arbitrary allocation scheme * of PPP interface unit numbers * per framework. * See pppLoad for more details. */typedef struct pppDrvCtrl { END_OBJ end; PFW_PLUGIN_OBJ_STATE *state; PFW_STACK_ID connectionId; } PPP_DRV_CTRL;/* Component data per instance: one per pfw */typedef struct pppEndComponent { PFW_COMPONENT_OBJ component; PPP_IP_INTERFACE pppIpInterface; PPP_IP_ROUTES_INTERFACE pppIpRoutesInterface; PPP_IP_DNS_INTERFACE pppIpDnsInterface; COMPONENT_ACCEPTABLE_PROTOCOLS_INTERFACE componentAcceptableProtocolsInterface; PPP_LINK_ID_INTERFACE pppLinkIdInterface;#ifdef PPP_END_RFC2233_CAPABLE PPP_IF_IFX_TABLE_INTERFACE pppIfIfXTableInterface; PPP_IF_STACK_TABLE_INTERFACE pppIfStackTableInterface;#endif /* PPP_END_RFC2233_CAPABLE */ } PPP_END_COMPONENT;typedef struct pppEndStackData { PFW_INTERFACE_STATE_PAIR pppLinkStatusInterface; PPP_DRV_CTRL *pDrvCtrl; struct ifnet *pIfnet; BOOL administrativeInterfaceControl; BOOL txBlocked; PFW_EVENT_OBJ * interfaceUpEvent; PFW_EVENT_OBJ * interfaceDownEvent; PFW_PLUGIN_OBJ_CALLBACKS * callbacks; char primaryDnsAddr[INET_ADDR_LEN]; char secondaryDnsAddr[INET_ADDR_LEN]; /* auxiliary variables aiding RFC 2233 counters's implementation */ int pfwAuxIfId; PFW_INTERFACE_STATE_PAIR pfwRFC2233CountPair; BOOL pfwRFC2233CountTest; } PPP_END_STACK_DATA;/* PPP END Specific interfaces. */END_OBJ * pppLoad (char *initString, void *tmp);/* locals */LOCAL STATUS pppUnload (END_OBJ * pEnd);LOCAL STATUS pppStart (PPP_DRV_CTRL *pDrvCtrl);LOCAL STATUS pppStop (PPP_DRV_CTRL *pDrvCtrl);LOCAL STATUS pppEndSend (void * pCookie, M_BLK_ID pMblk);LOCAL STATUS pppBind (PPP_DRV_CTRL * pDrvCtrl,void * pNetSvcInfo, void * drvInfo, long type);LOCAL STATUS pppPacketDataGet (M_BLK_ID pMblk,LL_HDR_INFO *llHdrInfo);LOCAL int pppIoctl (END_OBJ * pEnd, int cmd, caddr_t data);#ifdef PPP_T2CP3_OR_BELOW_COMPATIBLELOCAL M_BLK_ID pppAddressForm (M_BLK_ID pMblk, M_BLK_ID pSrcAddr, M_BLK_ID pDstAddr);#elseLOCAL M_BLK_ID pppAddressForm (M_BLK_ID pMblk, M_BLK_ID pSrcAddr, M_BLK_ID pDstAddr, BOOL bcastFlag);#endif /* PPP_T2CP3_OR_BELOW_COMPATIBLE */LOCAL STATUS pppMCastAddrAdd (PPP_DRV_CTRL* pDrvCtrl, char* pAddress);LOCAL STATUS pppMCastAddrDel (PPP_DRV_CTRL* pDrvCtrl, char* pAddress);LOCAL STATUS pppMCastAddrGet (PPP_DRV_CTRL* pDrvCtrl, MULTI_TABLE* pTable);LOCAL STATUS sendIf (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS receiveIf (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS stackAdd (PFW_PLUGIN_OBJ_STATE *, PFW_PLUGIN_OBJ_CALLBACKS *);LOCAL STATUS stackDelete (PFW_PLUGIN_OBJ_STATE *);LOCAL STATUS pppEndStackDataConstruct (PFW_OBJ *, void * stackData, void * profileData);LOCAL STATUS createIpInterface (PFW_PLUGIN_OBJ_STATE *state);LOCAL STATUS deleteIpInterface (PFW_PLUGIN_OBJ_STATE *state);LOCAL STATUS ipInterfaceUp (PFW_PLUGIN_OBJ_STATE *state, char *srcAddr, char *dstAddr);LOCAL STATUS ipInterfaceDown (PFW_PLUGIN_OBJ_STATE *state, char *source, char *destination);LOCAL UINT32 pppLinkIdGet ( PFW_PLUGIN_OBJ_STATE * state);#ifdef PPP_END_RFC2233_CAPABLELOCAL STATUS ifCounterUpdateWrap ( PFW_PLUGIN_OBJ_STATE * state, UINT ctrId, ULONG incrAmount );LOCAL STATUS ifVariableUpdateWrap ( PFW_PLUGIN_OBJ_STATE * state, UINT varId, caddr_t pData );LOCAL STATUS ifStackStatusSet ( PFW_PLUGIN_OBJ_STATE * state, int rowStatus );#endif /* PPP_END_RFC2233_CAPABLE */LOCAL STATUS sendPathAcceptableProtocolsGet (PFW_PLUGIN_OBJ_STATE *state, ACCEPTABLE_PROTOCOLS_ARRAY **sendProtocols);LOCAL STATUS receivePathAcceptableProtocolsGet (PFW_PLUGIN_OBJ_STATE *state, ACCEPTABLE_PROTOCOLS_ARRAY **recvProtocols);LOCAL STATUS endInterfaceBind (PFW_PLUGIN_OBJ * pluginObj);LOCAL UINT ipProtocolType[1] = {PPP_IP_PROTOCOL};LOCAL ACCEPTABLE_PROTOCOLS_ARRAY recvAcceptableProtocols = {1, ipProtocolType};LOCAL void bringUpIpInterface(char *ifName,char *srcAddr,char *dstAddr,int mtu);LOCAL void bringDownIpInterface(char *ifName,char *srcAddr,char *dstAddr);LOCAL STATUS ipRouteAdd (PFW_PLUGIN_OBJ_STATE *, char *, char *, unsigned long, int , int);LOCAL STATUS ipRouteDelete (PFW_PLUGIN_OBJ_STATE *, char *, unsigned long, int , int);LOCAL STATUS ipSetIfMask (PFW_PLUGIN_OBJ_STATE *, unsigned long);LOCAL void pppEndRouteAdd (char *, char *, unsigned long , int , int );LOCAL void pppEndRouteDelete (char *, unsigned long , int , int );LOCAL void pppEndSetIfMask(char *, unsigned long);LOCAL void ipDnsAddressGet ( PFW_PLUGIN_OBJ_STATE *, char * primaryDnsAddress, char * secondaryDnsAddress);LOCAL void ipDnsAddressSet ( PFW_PLUGIN_OBJ_STATE *, char * primaryDnsAddress, char * secondaryDnsAddress);/* event handlers */LOCAL STATUS txBlockedEventHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData); LOCAL STATUS txUnblockedEventHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData); /* globals */LOCAL NET_FUNCS pppFuncTable = { /* since we cast all these function pointers to * generic (FUNCPTR) our compiler loses type information */ (FUNCPTR)pppStart, /* start func */ (FUNCPTR)pppStop, /* stop func */ (FUNCPTR)pppUnload, /* unload func */ (FUNCPTR)pppIoctl, /* ioctl func */ (FUNCPTR)pppEndSend, /* send func */ (FUNCPTR)pppMCastAddrAdd, /* mcast add func */ (FUNCPTR)pppMCastAddrDel, /* mcast delete func */ (FUNCPTR)pppMCastAddrGet, /* mcast get func */ (FUNCPTR)NULL, /* polling send func */ (FUNCPTR)NULL, /* polling receive func */ pppAddressForm, /* Addr form func */ (FUNCPTR)pppPacketDataGet, /* Packet data get func */ (FUNCPTR)NULL, /* packet addr get func */ (FUNCPTR)pppBind /* Info xchange b/n network service and n/w driver */ };/********************************************************************************* pppLoad -** NOMANUAL*/END_OBJ * pppLoad ( char *initString, /* We receive the connectionId in the initString */ void *tmp ) { PPP_DRV_CTRL *pDrvCtrl; PFW_PLUGIN_OBJ_STATE *state; PFW_STACK_ID connectionId; PFW_ID pfwId; int unitNum; char *holder = NULL; char *token; UINT8 pppEndBuf[6]; if (initString[0] == 0) { bcopy((char *)"ppp", initString, 3); return (0); } strtok_r (initString, ":", &holder); token = strtok_r (NULL, ":", &holder); state = (PFW_PLUGIN_OBJ_STATE *)strtoul(token, NULL, 16); /* allocate the device structure */#ifdef PPP_T2CP3_OR_BELOW_COMPATIBLE pDrvCtrl = (PPP_DRV_CTRL *)pfwMalloc(state->pluginObj->pfwObj, sizeof(PPP_DRV_CTRL));#else pDrvCtrl = (PPP_DRV_CTRL *)malloc(sizeof(PPP_DRV_CTRL));#endif /* PPP_T2CP3_OR_BELOW_COMPATIBLE */ if (pDrvCtrl == NULL) { return (NULL); } bzero((char *)pDrvCtrl, sizeof (PPP_DRV_CTRL)); ((PPP_END_STACK_DATA *)state->stackData)->pDrvCtrl = pDrvCtrl; pDrvCtrl->state = state; pDrvCtrl->connectionId = connectionId = pfwStackIdGet(state->stackObj); pfwId = pfwIdGet (state->pluginObj->pfwObj); /* * For every PPP connection attached to IP, the network stack will * create an ifnet data structures to hold the information related * to the interface. The if_unit field is a short. if_name can be * at most END_NAME_MAX. * * Since the combination of a device name and its unit number must be * unique, for a given device name there can be at most 32767 interfaces * -- unless the ifnet definition is changed and the network stack * code is recompiled. * * The default interface name scheme is to use "ppp" as the device name * for all frameworks and arbitrarily allocate unit numbers among * frameworks based on the value of PPP_END_MAX_SESSIONS_PER_FRWK. * Users should devise a scheme suitable to their needs. */ unitNum = (pfwId - 1)* PPP_END_MAX_SESSIONS_PER_FRWK + connectionId; /* Store the cookie (END_OBJ) in the PPP driver control structure */ /* store the netPoolId in the end object */ pDrvCtrl->end.pNetPool = pfwNetPoolIdGet (state->pluginObj->pfwObj); /* Pointer back to the device data. */ pDrvCtrl->end.devObject.pDevice = (void *)pDrvCtrl; /* Assign the NET_FUNCS in the END_OBJ */ if ((END_OBJ_INIT (&(pDrvCtrl->end), (DEV_OBJ *)pDrvCtrl, "ppp", unitNum, &pppFuncTable, "ppp END Driver.") == ERROR) || /* * Do not define PPP_END_RFC2233_CAPABLE if PPP is installed * on top of T2CP3, T2CP4 = T202, or T3.1. On these stacks * there is support at the network stack level, but none of the network * Ethernet drivers supports RFC2233. All network drivers, not just * PPP must support RFC2233. Define PPP_END_RFC2233_CAPABLE if * PPP is installed with WindNet Router Stack, PNE, or T2.2. */#ifndef PPP_END_RFC2233_CAPABLE END_MIB_INIT(&(pDrvCtrl->end), M2_ifType_ppp, pppEndBuf, 0, 1500, 0))#else ((pDrvCtrl->end.pMib2Tbl = m2IfAlloc(M2_ifType_ppp, (UINT8*) pppEndBuf, 0, /* interface addr length*/ 1500, /* default MTU */ 0, "ppp", unitNum)) == NULL))#endif /* PPP_END_RFC2233_CAPABLE */ { return (NULL); }#ifndef PPP_END_RFC2233_CAPABLE END_OBJ_READY (&(pDrvCtrl->end), IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST);#else END_OBJ_READY (&(pDrvCtrl->end),IFF_POINTOPOINT | IFF_NOARP | END_MIB_2233 | IFF_MULTICAST);#endif /* PPP_END_RFC2233_CAPABLE */ return (&(pDrvCtrl->end)); }/********************************************************************************* pppUnload -** NOMANUAL*/LOCAL STATUS pppUnload ( END_OBJ * pEnd ) /* The original version had interface STATUS(*)(PPP_DRV_CTRL*) * but different body. The current version of the PPP_DRV_CTRL * structure has the END_OBJ embedded into it as first element. * The NPT patch version of the NET_FUNCS structure expects * for pppUnload a function pointer of type STATUS(*)(END_OBJ *). * If the NPT patch is not applied then this function would be * called with argument a pointer to a PPP_DRV_CTRL structure. * However, our compiler does NOT warn us of differences * in function prototypes provided that we typecast the * function pointers to generic function pointers. * Hence, even if we do not apply the NPT patch, still we would * have compilation without warnings and the functionality * would be the same in either case; that is, free PPP_DRV_CTRL. */ {#if (defined PPP_T2CP3_OR_BELOW_COMPATIBLE || defined PPP_END_RFC2233_CAPABLE) PPP_DRV_CTRL *pDrvCtrl = (PPP_DRV_CTRL *)pEnd;#endif /* PPP_T2CP3_OR_BELOW_COMPATIBLE || PPP_END_RFC2233_CAPABLE */ if (pEnd->txSem != NULL) { semDelete (pEnd->txSem); pEnd->txSem = NULL; }#ifdef PPP_END_RFC2233_CAPABLE /* Free MIB-II entries */ m2IfFree(pDrvCtrl->end.pMib2Tbl); pDrvCtrl->end.pMib2Tbl = NULL;#endif /* PPP_END_RFC2233_CAPABLE */#ifdef PPP_T2CP3_OR_BELOW_COMPATIBLE pfwFree(pDrvCtrl);#endif /* PPP_T2CP3_OR_BELOW_COMPATIBLE */ return (OK); }/********************************************************************************* pppStart -** NOMANUAL*/LOCAL STATUS pppStart ( PPP_DRV_CTRL *pDrvCtrl ) { PFW_STACK_ID connectionId; PFW_ID pfwId; int unitNum; char ifName[PFW_MAX_NAME_LENGTH]; struct ifnet * pIfnet; connectionId = pfwStackIdGet (pDrvCtrl->state->stackObj); pfwId = pfwIdGet (pDrvCtrl->state->pluginObj->pfwObj); unitNum = (pfwId - 1)* PPP_END_MAX_SESSIONS_PER_FRWK + connectionId; sprintf(ifName,"ppp%d",unitNum); /* Get the ifnet from the interface name */ if ((pIfnet = ifunit (ifName)) == NULL) return ERROR; return OK; }/********************************************************************************* pppStop -** NOMANUAL*/LOCAL STATUS pppStop ( PPP_DRV_CTRL *pDrvCtrl ) { PFW_STACK_ID connectionId; PFW_ID pfwId; int unitNum; char ifName[PFW_MAX_NAME_LENGTH];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -