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

📄 ppplib.c

📁 vxworks的tcpip协议栈源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* pppLib.c - Point-to-Point Protocol library *//* Copyright 1995 Wind River Systems, Inc. */#include "copyright_wrs.h"/* * Copyright (c) 1989 Carnegie Mellon University. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by Carnegie Mellon University.  The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. *//*modification history--------------------01v,17feb99,sgv  Fix for spr 24560, proper cleanup when ppp options file 		 cannot be accessed01u,31aug98,fle  doc : got rid of simple quotes to avoid bold troubles01t,15aug97,sgv  fixed spr #9109. In cleanup routine, ppp_if[unit] 		 is checked for NULL memory address before freeing it01s,10dec96,vin  fixed problem with die(..) if OPT_SILENT or OPT_PASSIVE		 is specified. Made changes to term(..) so that pppDelete()		 would work even if silent or passive options are specified.		 fixed SPR 7604.01r,15nov96,vin  fixed problem with OPT_DRIVER_DEBUG, establish_ppp() 		 should be called after the options are set. The only		 dependency is that pppopen() should be called before		 establish_ppp().01q,19dec95,vin  doc tweaks.01p,30nov95,vin  added hooks on a unit basis.01o,11jul95,dzb  doc tweaks.01n,22jun95,dzb  changed [un]timeout() to ppp_[un]timeout().                 removed usehostname option.  Enhanced doc.01m,12jun95,dzb  added MIBII counter for unknown protocol packets.                 changed [dis]connect strings to global hook routines.                 header file consolidation.  removed device_script().		 removed perror() reference.01l,08jun95,dzb  made LOG_NOTICE message printed even w/o debug option.01k,16may95,dzb  put back in login option doc.01j,09may95,dzb  added callout to pppSecretLibInit().                 switched all lcp_close() calls to go through die().01i,03may95,dzb  doc tweaks: removed login option, fixed require_chap_file,                 added pap_passwd option.01h,07mar95,dzb  changed cfree() to free() (ANSI).  Changed name to pppLib.c.                 additional doc/formatting.01g,13feb95,dab  fixed pppDelete() for multi unit support (SPR #4062).01f,09feb95,dzb  fixed proto tbl input call for multi unit support (SPR #4062).01e,07feb95,dab  changed syslog to MAINDEBUG for reg status messages.            dzb  changed to look at (errno != EINTR) after sigsuspend().01d,24jan95,dzb  ifdef VXW5_1 for timer_create() backwards capatibility.                 renamed params for pppInit() and ppp_task().01c,13jan95,dab  enhanced doc.01b,22dec94,dzb  tree shuffle and warning cleanup.01a,21dec94,dab  VxWorks port - first WRS version.	   +dzb  added: path for ppp header files, WRS copyright.*//*DESCRIPTIONThis library implements the VxWorks Point-to-Point Protocol (PPP)facility.  PPP allows VxWorks to communicate with other machines by sendingencapsulated multi-protocol datagrams over a point-to-point serial link.VxWorks may have up to 16 PPP interfaces active at any one time.  Eachindividual interface (or "unit") operates independent of the state ofother PPP units.USER-CALLABLE ROUTINESPPP network interfaces are initialized using the pppInit() routine. This routine's parameters specify the unit number, the name of the serial interface (<tty>) device, Internet (IP) addresses for both ends of the link,the interface baud rate, an optional pointer to a configuration options structure, and an optional pointer to a configuration options file.  The pppDelete() routine deletes a specified PPP interface.DATA ENCAPSULATIONPPP uses HDLC-like framing, in which five header and three trailer octets areused to encapsulate each datagram.  In environments where bandwidth is ata premium, the total encapsulation may be shortened to four octets withthe available address/control and protocol field compression options.LINK CONTROL PROTOCOLPPP incorporates a link-layer protocol called Link Control Protocol (LCP),which is responsible for the link set up, configuration, and termination.LCP provides for automatic negotiation of several link options, includingdatagram encapsulation format, user authentication, and link monitoring(LCP echo request/reply).NETWORK CONTROL PROTOCOLSPPP's Network Control Protocols (NCP) allow PPP to support different network protocols.  VxWorks supports only one NCP, the InternetProtocol Control Protocol (IPCP), which allows the establishment andconfiguration of IP over PPP links.  IPCP supports the negotiation of IPaddresses and TCP/IP header compression (commonly called "VJ" compression).AUTHENTICATIONThe VxWorks PPP implementation supports two separate user authenticationprotocols: the Password Authentication Protocol (PAP) and theChallenge-Handshake Authentication Protocol (CHAP).  While PAP onlyauthenticates at the time of link establishment, CHAP may be configured toperiodically require authentication throughout the life of the link.Both protocols are independent of one another, and either may be configuredin through the PPP options structure or options file.IMPLEMENTATIONEach VxWorks PPP interface is handled by two tasks: the daemon task(tPPP<unit>) and the write task (tPPP<unit>Wrt).The daemon task controls the various PPP control protocols (LCP, IPCP, CHAP,and PAP).  Each PPP interface has its own daemon task that handles linkset up, negotiation of link options, link-layer user athentication, andlink termination.  The daemon task is not used for the actual sending andreceiving of IP datagrams.The write task controls the transmit end of a PPP driver interface.Each PPP interface has its own write task that handles the actual sendingof a packet by writing data to the <tty> device.  Whenever a packet is readyto be sent out, the PPP driver activates this task by giving a semaphore.The write task then completes the packet framing and writesthe packet data to the <tty> device.The receive end of the PPP interface is implemented as a "hook" intothe <tty> device driver.  The <tty> driver's receive interrupt service routine(ISR) calls the PPP driver's ISR every time a character is received on theserial channel.  When the correct PPP framing character sequence is received,the PPP ISR schedules the tNetTask task to call the PPP input routine.The PPP input routine reads a whole PPP packet out of the <tty> ringbuffer and processes it according to PPP framing rules.The packet is then queued either to the IP input queue or to the PPP daemontask input queue.INCLUDE FILES: pppLib.hSEE ALSO: ifLib, tyLib, pppSecretLib, pppShow,.pG "Network", .I "RFC-1332: The PPP Internet Protocol Control Protocol (IPCP)", .I "RFC-1334: PPP Authentication Protocols", .I "RFC-1548: The Point-to-Point Protocol (PPP)", .I "RFC-1549: PPP in HDLC Framing"ACKNOWLEDGEMENTThis program is based on original work done by Paul Mackerras ofAustralian National University, Brad Parker, Greg Christy, Drew D. Perkins,Rick Adams, and Chris Torek.INTERNAL         pppInit               pppDelete             |                     |            |                     |            |                     |         pppopen   pppwrite    pppclose   pppintr   pppread   pppioctl           /\          |          |          |                         /  \         |          |          |                       /    \    pppoutput      |          |                     /      \       |          |          |                   /        \      |          |          |             pppalloc pppWrtTask <-      pppdealloc ppp_tty_read       |                                      |                 |                                      |                 |                                      |             pppattach                               pppinput                                             |                                             |                                             |                                          ppppktin*/#include "vxWorks.h"#include "string.h"#include "sigLib.h"#include "sysLib.h"#include "sockLib.h"#include "ioLib.h"#include "iosLib.h"#include "excLib.h"#include "time.h"#include "timers.h"#include "taskLib.h"#include "taskVarLib.h"#include "hostLib.h"#include "sys/ioctl.h"#include "netinet/in.h"#include "arpa/inet.h"#include "stdio.h"#include "signal.h"#include "errno.h"#include "fcntl.h"#include "sys/types.h"#include "sys/stat.h"#include "sys/socket.h"#include "sys/times.h"#include "net/if.h"#include "netLib.h"#include "pppLib.h"/* PPP parameter structure */typedef struct ppp_parms{	char *task_name;        char *devname;        char *local_addr;        char *remote_addr;        char *filename;        int unit;        int baud;        PPP_OPTIONS options;} PPP_PARMS;/* globals */int ppp_unit;				/* PPP unit id */PPP_TASK_VARS *ppp_if[NPPP];		/* per task PPP variables */PPP_PARMS *ppp_parms[NPPP];		/* PPP parameters */PPP_HOOK_RTNS * pppHookRtns [NPPP];	/* PPP table of hooks */int ppp_task_priority		= 55;int ppp_task_options		= VX_FP_TASK | VX_DEALLOC_STACK;int ppp_task_stack_size		= 0x4000;char *ppp_task_name		= "tPPP";/* prototypes */static int  baud_rate_of __ARGS((int));static int  translate_speed __ARGS((int));static int  set_up_tty __ARGS((int));static void hup __ARGS((int));static void intr __ARGS((int));static void term __ARGS((int));static void alrm __ARGS((int));static void io __ARGS(());static void incdebug __ARGS((int));static void nodebug __ARGS((int));static void cleanup __ARGS((int, int, caddr_t));/* * PPP Data Link Layer "protocol" table. * One entry per supported protocol. */static struct protent {    u_short protocol;    void (*init)();    void (*input)();    void (*protrej)();    int  (*printpkt)();    char *name;} prottbl[] = {    { LCP, lcp_init, lcp_input, lcp_protrej, lcp_printpkt, "LCP" },    { IPCP, ipcp_init, ipcp_input, ipcp_protrej, ipcp_printpkt, "IPCP" },    { UPAP, upap_init, upap_input, upap_protrej, upap_printpkt, "PAP" },    { CHAP, ChapInit, ChapInput, ChapProtocolReject, ChapPrintPkt, "CHAP" },};#define N_PROTO         (sizeof(prottbl) / sizeof(prottbl[0]))/********************************************************************************* pppInit - initialize a PPP network interface** This routine initializes a Point-to-Point Protocol (PPP) network interface.* The parameters to this routine specify the unit number (<unit>) of the* PPP interface, the name of the serial interface (<tty>) device (<devname>),* the IP addresses of the local and remote ends of the link, the interface* baud rate, an optional configuration options structure pointer, and an* optional configuration options file name.** IP ADDRESSES:* The <local_addr> and <remote_addr> parameters specify the IP addresses* of the local and remote ends of the PPP link, respectively.* If <local_addr> is NULL, the local IP address will be negotiated with* the remote peer.  If the remote peer does not assign a local IP address,* it will default to the address associated with the local target's machine* name.  If <remote_addr> is NULL, the remote peer's IP address will obtained* from the remote peer.  A routing table entry to the remote peer will be* automatically added once the PPP link is established.** CONFIGURATION OPTIONS STRUCTURE:* The optional parameter <pOptions> specifies configuration options for* the PPP link.  If NULL, this parameter is ignored, otherwise it* is assumed to be a pointer to a PPP_OPTIONS options structure (defined* in h/netinet/ppp/options.h).** The "flags" member of the PPP_OPTIONS structure is a bit-mask, where the* following bit-flags may be specified:* .iP "OPT_NO_ALL"* Do not request/allow any options.* .iP "OPT_PASSIVE_MODE"* Set passive mode.* .iP "OPT_SILENT_MODE"* Set silent mode.* .iP "OPT_DEFAULTROUTE"* Add default route.* .iP "OPT_PROXYARP"* Add proxy ARP entry.* .iP "OPT_IPCP_ACCEPT_LOCAL"* Accept peer's idea of the local IP address.* .iP "OPT_IPCP_ACCEPT_REMOTE"* Accept peer's idea of the remote IP address.* .iP "OPT_NO_IP"* Disable IP address negotiation.* .iP "OPT_NO_ACC"* Disable address/control compression.* .iP "OPT_NO_PC"* Disable protocol field compression.* .iP "OPT_NO_VJ"* Disable VJ (Van Jacobson) compression.* .iP "OPT_NO_VJCCOMP"* Disable VJ (Van Jacobson) connnection ID compression.* .iP "OPT_NO_ASYNCMAP"* Disable async map negotiation.* .iP "OPT_NO_MN"* Disable magic number negotiation.* .iP "OPT_NO_MRU"* Disable MRU (Maximum Receive Unit) negotiation.* .iP "OPT_NO_PAP"* Do not allow PAP authentication with peer.* .iP "OPT_NO_CHAP"* Do not allow CHAP authentication with peer.* .iP "OPT_REQUIRE_PAP"* Require PAP authentication with peer.* .iP "OPT_REQUIRE_CHAP"* Require CHAP authentication with peer.* .iP "OPT_LOGIN"* Use the login password database for PAP authentication of peer.* .iP "OPT_DEBUG"* Enable PPP daemon debug mode.* .iP "OPT_DRIVER_DEBUG"* Enable PPP driver debug mode.* .LP** The remaining members of the PPP_OPTIONS structure specify PPP configurations* options that require string values.  These options are:* .iP "char *asyncmap"* Set the desired async map to the specified string.* .iP "char *escape_chars"* Set the chars to escape on transmission to the specified string.* .iP "char *vj_max_slots"* Set maximum number of VJ compression header slots to the specified string.* .iP "char *netmask"* Set netmask value for negotiation to the specified string.* .iP "char *mru"* Set MRU value for negotiation to the specified string.* .iP "char *mtu"* Set MTU (Maximum Transmission Unit) value for negotiation to the* specified string.* .iP "char *lcp_echo_failure"* Set the maximum number of consecutive LCP echo failures to the specified* string.* .iP "char *lcp_echo_interval"* Set the interval in seconds between LCP echo requests to the specified string.* .iP "char *lcp_restart"* Set the timeout in seconds for the LCP negotiation to the specified string.* .iP "char *lcp_max_terminate"* Set the maximum number of transmissions for LCP termination requests* to the specified string.* .iP "char *lcp_max_configure"* Set the maximum number of transmissions for LCP configuration* requests to the specified string.* .iP "char *lcp_max_failure"* Set the maximum number of LCP configuration NAKs to the specified string.* .iP "char *ipcp_restart"* Set the timeout in seconds for IPCP negotiation to the specified string.* .iP "char *ipcp_max_terminate"* Set the maximum number of transmissions for IPCP termination requests* to the specified string.* .iP "char *ipcp_max_configure"* Set the maximum number of transmissions for IPCP configuration requests* to the specified string.* .iP "char *ipcp_max_failure"* Set the maximum number of IPCP configuration NAKs to the specified string.* .iP "char *local_auth_name"* Set the local name for authentication to the specified string.* .iP "char *remote_auth_name"* Set the remote name for authentication to the specified string.* .iP "char *pap_file"* Get PAP secrets from the specified file.  This option is necessary* if either peer requires PAP authentication.* .iP "char *pap_user_name"* Set the user name for PAP authentication with the peer to the* specified string.* .iP "char *pap_passwd"* Set the password for PAP authentication with the peer to the specified string.* .iP "char *pap_restart"* Set the timeout in seconds for PAP negotiation to the specified string.* .iP "char *pap_max_authreq"* Set the maximum number of transmissions for PAP authentication* requests to the specified string.* .iP "char *chap_file"* Get CHAP secrets from the specified file.  This option is necessary* if either peer requires CHAP authentication.* .iP "char *chap_restart"* Set the timeout in seconds for CHAP negotiation to the specified string.* .iP "char *chap_interval"* Set the interval in seconds for CHAP rechallenge to the specified string.* .iP "char *chap_max_challenge"* Set the maximum number of transmissions for CHAP challenge to the* specified string.

⌨️ 快捷键说明

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