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

📄 pppvsend.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* pppVsEnd.c - PPP VS END network interface driver *//* Copyright 1984-2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01t,10jun03,ijm use STACK_NAME to distinguish network stacks01s,15may03,ijm included in6_var.h01r,12may03,ijm included routeCmd.h01q,01may03,ijm updated to use if6Lib API instead of ifconfig01p,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.01o,05nov02,ijm use printf instead of logMsg01n,01nov02,ijm added workaround for IPv6 SPR# 81835: unable to ping PPP                interfaces unless an additional link local address is added                manually.  Workaround is to set inet6 up flag before                setting remote and local addresses to have IPv6 stack                generate the additional link local address                automatically.01m,29oct02,ijm compile for IPv6, or router stack only;01l,22oct02,ijm include vpppstr.h 01k,27aug02,ijm For IPv6, set link up01j,22aug02,ijm fixed diab compiler warnings. Return proper value                in pppIoctl for RFC2233 case.01i,09aug02,adb DOC edits01h,18jul02,ijm use inet6 down or inet down instead of down01g,26jun02,ijm added support for dual stack01f,21feb02,ijm removed extra parameter to logMsg in ipInterfaceUp01e,20feb02,ijm fixed compilation warnings in pppUnload, bringUpIpInterface                and bringDownIpInterface01d,06feb02,ijm added missing call to m2pppInterfaceUnregister in                ipInterfaceUp, SPR#71583.  Set pStackData->pDrvCtrl to NULL                in stackDelete,SPR #71855.  Free packet if ERROR in                pppEndSend, SPR#71998.01c,30oct01,ijm made compilation conditional on ROUTER_STACK                since this component requires support for                point-to-multipoint interfaces from the                IP Router Stack01b,29oct01,ijm fixed compilation warnings, changed rasammP.h                path, replaced mRouteAdd with mRouteEntryAdd                replaced inet_ntoa with inet_ntoa_b, made call                to m2IfFree only if PPP_END_RFC2233_CAPABLE is defined,                free memory for interface parameters in ipInterfaceUp                and ipInterfaceDown, if error.01a,12jul01,rp  created, based on openstack pppEnd.c*//*DESCRIPTIONThis module implements the PPP VS END component.  PPP VS END resides inthe interface layer of the data plane. PPP VS END is the component thatinterfaces with the vxWorks network stack. The PPP VS END component implements the functions required of a frameworkplug-in-object, an END network interface driver, and also the functionsnecessary to configure and remove the PPP END driver as an IP interfacemanaged by SNMP.PPP VS END is similar to pppEnd, but it supports additional featureswhich are available in some network stack versions.  These features are:1.  Optional virtual stack support: multiple IP stacks coexist.  This    feature is available in WindNet Router Stack 1.x.  Compile PPP source    defining VIRTUAL_STACK, to configure virtual stack support.2.  Optional Point-To-Multipoint (PMP) support: Instead of presenting to    IP one point-to-point END driver per PPP connection --each with a    corresponding host route--, a single PMP END interface is presented    to IP to represent multiple PPP connections --as a subnet-- with a    single network route.    The RASAMM library is used to configure pools of IP addresses assigned    to peers.  Each pool is associated with one PMP interface. For sending,    since IP packets for any of the destinations in the pool are all    delivered by the MUX to the single PMP interface,  PPP END uses RASAMM    API to retrieve the PPP stack corresponding to each destination.    While PMP minimizes routing table storage space, it has drawbacks:       1. Retrieving the appropriate PPP stack corresponding to a          destination is slower than the single route table lookup done for          regular PPP interfaces.  The route table lookup yields the route          to the PMP device.  Additional function calls are done PER PACKET          to locate the destination stack, and to determine the MTU of the          destination stack.       2. In addition, when connections are established, additional processing          is done to configure the first driver in the pool and to replace that          driver when the corresponding connection is torn down.       3. PMP devices are not made multicast capable since multicast packets          would have to be sent to each driver in the pool, making this a slow          operation.       4. PPP ifType (23) is found in RFC 1700.  PMP is not a standard          interface type.    PMP support is available in T2.2 and Windnet Router Stack 1.0.    Compile PPP source defining PPP_END_PMP_CAPABLE, to configure    PMP support.3.  Optional IPv6 support.  In IPv4/IPv6 Dual Stack, to configure support    for IPv6, compile PPP source defining INET6.     4.  RFC 2233 MIB interface counters.  RFC 2233 counter support is    available in T2.2, WindNet Router Stack 1.0, and IPv4/IPv6    Dual Stack.When a PPP stack is created, PPP VS END is registered with the MUX andattached to IPv4 -- and/or IPv6.For IPv4, when the IPCP component is UP, it passes the negotiated local anddestination IP addresses to the END component via the PPP_IP_INTERFACEinterfaceUp function.  These addresses are used to configure the END interfaceas a Point-To-Point IP interface, to create a route for its peer, and toassociate the loopback interface to its local address.  At this point, theinterface is UP and IPv4 can use it to send and receive packets. When IPCP isDOWN, the PPP_IP_INTERFACE interfaceDown function is called to remove routesand set the DOWN flag for the END driver.  When the PPP stack is deleted,the END driver releases all allocated resources by detaching from IP, andunloading from the MUX.For IPv6, the process is similar.  IPV6CP passes the negotiated interfaceidentifier to configure link local addresses.For every PPP connection attached to IP, the network stack will create an ifnet data structure 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 beunique, for a given device name there can be at most 32767 interfaces-- unless  the ifnet definition is changed and the network stackcode is recompiled.The default interface name scheme is to use "ppp" as the device namefor all frameworks and arbitrarily allocate unit numbers amongframeworks based on the value of PPP_END_MAX_SESSIONS_PER_FRWK.Users should devise a scheme suitable to their needs.The PPP VS END component implements the following interfaces:  PPP_LINK_ID_INTERFACE: provides interface link id  COMPONENT_ACCEPTABLE_PROTOCOLS_INTERFACE: provides the receive protocols                                            that PPP VS END can handle.  PPP_IF_IFX_TABLE_INTERFACE: ifTable and ifXTable RFC2233 counters  PPP_IF_STACK_TABLE_INTERFACE:  ifStackTable RFC 2233 counters  PPP_VSID_INTERFACE: get and set the virtual stack identifier (VSID)  PPP_IP_INTERFACE: up/down IPv4 link configuration   PPP_IP_ROUTES_INTERFACE: IPv4 add/delete route, set interface mask   PPP_IP_DNS_INTERFACE:  IPv4 set/get primary and secondary DNS addresses  PPP_IPV6_INTERFACE: up/down IPv6 link configurationThe PPP VS END component raises the following events:  PPP_INTERFACE_UP_EVENT  PPP_INTERFACE_DOWN_EVENT  PPP_IPV6_INTERFACE_UP_EVENT  PPP_IPV6_INTERFACE_DOWN_EVENTThe PPP VS END component subscribes to the following events:  PPP_SUB_LAYER_TX_BLOCKED: to return END_ERR_BLOCKED status to network layer                            when the physical layer cannot send.  PPP_SUB_LAYER_TX_UNBLOCKED: to call muxTxRestart when physical layer                              can send again.The PPP VS END component offers the following configuration parameters:  end_pollRxQueueSize: poll mode receive queue size  end_vsName: virtual stack parameterNOTE: PPP VS END cannot be installed on network stack versions that lack      support for RFC 2233 counters: T2.0.2 and below.*//* includes */#include "vxWorks.h"#include "pfw/pfw.h"  /*                       * pfw.h includes header files needed for proper                       * compilation of network stack include files below                       */#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)) || (defined ROUTER_STACK))#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 "netinet/if_ether.h"#include "net/unixLib.h"#include "net/if.h"#include "net/route.h"#include "inetLib.h"#include "ifLib.h"#include "netBufLib.h"#include "sys/ioctl.h"#include "resolvLib.h"#include <ipProto.h>#include "netinet/in.h"#include "ppp/kstart.h"#include "ppp/kppp.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/pppVsEndComponent.h"#include "private/ppp/vpppstr.h"#ifdef VIRTUAL_STACK#include "netinet/vsLib.h"#include "ppp/interfaces/pppVsidInterface.h"#endif /* VIRTUAL_STACK */#ifdef PPP_END_PMP_CAPABLE#include "ppp/rasamm.h"#include "private/ppp/rasammP.h"#endif /* PPP_END_PMP_CAPABLE */#if ((defined STACK_NAME) && (STACK_NAME == STACK_NAME_V4_V6))#include "net/utils/routeCmd.h"#include "if6Lib.h"#include "netinet6/in6_var.h"#else#include "routeLib.h"#endif /* ((defined STACK_NAME) && (STACK_NAME == STACK_NAME_V4_V6)) *//* defines */#define PPP_END_MAX_SESSIONS_PER_FRWK  256 /* See DESCRIPTION section above */#define DEF_POLL_RX_QUEUE_SIZE 10#define IPV4_ADDRESS_MBLK_TAGGED	0xabcdef12#define PPP_END_NAME_MAX_LENGTH  12  /* < "ppp" + unitNum (short) + 1 */#define PPP_END_ROUTEC_STRING (PPP_END_NAME_MAX_LENGTH + \                                 2*INET6_ADDR_LEN + 100)                                /* for routec command */#define pppsenderr(e) do { error = (e); goto bad;} while (0)/* virtual stack defines */#define PPP_END_MGMT_STACK 	"stack0"  /* virtual stack 0 *//* PMP defines */#define DEFAULT_PMP_MTU    1500#ifndef IPV4_ADDR_LEN#define IPV4_ADDR_LEN 4#endif/* typedefs */typedef struct pppDrvCtrl    {    END_OBJ end;    PFW_PLUGIN_OBJ_STATE *state;    int unitNum;    } PPP_DRV_CTRL; typedef enum endOperatingMode    {    END_NORMAL_MODE,    END_POLLED_MODE    } END_OPERATING_MODE;typedef enum endRxArrayOper    {    END_PROTOCOL_ADD,    END_PROTOCOL_REMOVE    } END_RX_ARRAY_OPER;typedef enum endRxAcceptableProtocols    {    END_IPV4_PROTOCOL,    END_IPV6_PROTOCOL,    MAXIMUM_END_PROTOCOLS    } END_RX_ACCEPTABLE_PROTOCOLS;/* Component data per instance: one per pfw */typedef struct pppVsEndComponent    {    PFW_COMPONENT_OBJ component;    COMPONENT_ACCEPTABLE_PROTOCOLS_INTERFACE	    componentAcceptableProtocolsInterface;    PPP_LINK_ID_INTERFACE pppLinkIdInterface;    PPP_IF_IFX_TABLE_INTERFACE pppIfIfXTableInterface;    PPP_IF_STACK_TABLE_INTERFACE pppIfStackTableInterface;#ifdef INET    PPP_IP_INTERFACE pppIpInterface;    PPP_IP_ROUTES_INTERFACE pppIpRoutesInterface;    PPP_IP_DNS_INTERFACE pppIpDnsInterface;#endif /* INET */#ifdef INET6    PPP_IPV6_INTERFACE pppIpv6Interface;#endif /* INET6 */#ifdef VIRTUAL_STACK    PPP_VSID_INTERFACE pppVsidInterface;#endif /* VIRTUAL_STACK */    } PPP_VS_END_COMPONENT;typedef struct pppVsEndStackData    {    PFW_INTERFACE_STATE_PAIR pppLinkStatusInterface;    PPP_DRV_CTRL *pDrvCtrl;    struct ifnet *pIfnet;    BOOL            administrativeInterfaceControl;    BOOL            txBlocked;    END_OPERATING_MODE mode;    M_BLK_ID receivedPacketQHead;    M_BLK_ID receivedPacketQTail;    UINT32   receivedPacketQSize;    PFW_PLUGIN_OBJ_CALLBACKS    * callbacks;    char            primaryDnsAddr[INET_ADDR_LEN];    char            secondaryDnsAddr[INET_ADDR_LEN];    UINT ipProtocolType[MAXIMUM_END_PROTOCOLS];    ACCEPTABLE_PROTOCOLS_ARRAY recvAcceptableProtocols;    int             pfwAuxIfId;    PFW_INTERFACE_STATE_PAIR      pfwRFC2233CountPair;    BOOL            pfwRFC2233CountTest;#ifdef INET    PFW_EVENT_OBJ * interfaceUpEvent;    PFW_EVENT_OBJ * interfaceDownEvent;#endif /* INET */#ifdef INET6    PFW_EVENT_OBJ * ipv6InterfaceUpEvent;    PFW_EVENT_OBJ * ipv6InterfaceDownEvent;#endif /* INET6 */#ifdef PPP_END_PMP_CAPABLE    UINT32  rasPoolId;	    BOOL    supportPMP;	    UINT32  dstIpAddr;    PPP_DRV_CTRL *pDstDrvCtrl;#endif /* PPP_END_PMP_CAPABLE */#ifdef VIRTUAL_STACK    VSID		vsid;#endif /* VIRTUAL_STACK */    } PPP_VS_END_STACK_DATA;typedef struct pppVsEndProfileData    {    PPP_VS_END_STACK_DATA	* pEndStackData;    UINT32		pollRxQueueSize;#ifdef VIRTUAL_STACK    VSID		vsid;#endif /* VIRTUAL_STACK */    } PPP_VS_END_PROFILE_DATA;#ifdef INET typedef struct interfaceParms    {    char        ifName[PPP_END_NAME_MAX_LENGTH];    char        ifSrcAddr[INET_ADDR_LEN];    char        ifDestAddr[INET_ADDR_LEN];    ULONG       mask;    int         mtu;    } INTERFACE_PARMS;typedef struct mRouteParms    {    char        * pDest;    char        * pGateway;    ULONG       mask;    int         tos;    int         flags;    } M_ROUTE_PARMS;#endif /* INET */#ifdef INET6typedef struct ipv6InterfaceParms    {    char        ifName[PPP_END_NAME_MAX_LENGTH];    char        ifSrcAddr[INET6_ADDR_LEN];    char        ifDestAddr[INET6_ADDR_LEN];    char        mask[INET6_ADDR_LEN];    int         mtu;    } IPV6_INTERFACE_PARMS;#endif /* INET6 */

⌨️ 快捷键说明

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