From 3bad9ff50ad9ad982e37138fba76f0a388b87139 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 3 Jun 2012 20:25:32 +0200 Subject: [PATCH] ppp_impl.h is back! --- src/netif/ppp/auth.c | 2 +- src/netif/ppp/ccp.c | 2 +- src/netif/ppp/chap-md5.c | 2 +- src/netif/ppp/chap-new.c | 2 +- src/netif/ppp/chap_ms.c | 2 +- src/netif/ppp/demand.c | 2 +- src/netif/ppp/eap.c | 2 +- src/netif/ppp/ecp.c | 2 +- src/netif/ppp/fsm.c | 2 +- src/netif/ppp/ipcp.c | 2 +- src/netif/ppp/lcp.c | 2 +- src/netif/ppp/magic.c | 2 +- src/netif/ppp/multilink.c | 2 +- src/netif/ppp/options.c | 2 +- src/netif/ppp/ppp.c | 2 +- src/netif/ppp/ppp.h | 741 +++----------------------------------- src/netif/ppp/ppp_impl.h | 706 ++++++++++++++++++++++++++++++++++++ src/netif/ppp/ppp_oe.c | 2 +- src/netif/ppp/pppcrypt.c | 2 +- src/netif/ppp/upap.c | 2 +- src/netif/ppp/utils.c | 2 +- 21 files changed, 776 insertions(+), 709 deletions(-) create mode 100644 src/netif/ppp/ppp_impl.h diff --git a/src/netif/ppp/auth.c b/src/netif/ppp/auth.c index cdb067df..df0d4de7 100644 --- a/src/netif/ppp/auth.c +++ b/src/netif/ppp/auth.c @@ -103,7 +103,7 @@ #include #endif /* UNUSED */ -#include "ppp.h" +#include "ppp_impl.h" #include "fsm.h" #include "lcp.h" diff --git a/src/netif/ppp/ccp.c b/src/netif/ppp/ccp.c index 47b1027b..293c39e8 100644 --- a/src/netif/ppp/ccp.c +++ b/src/netif/ppp/ccp.c @@ -34,7 +34,7 @@ #include #include -#include "ppp.h" +#include "ppp_impl.h" #include "fsm.h" #include "ccp.h" diff --git a/src/netif/ppp/chap-md5.c b/src/netif/ppp/chap-md5.c index 3f6734e1..45750308 100644 --- a/src/netif/ppp/chap-md5.c +++ b/src/netif/ppp/chap-md5.c @@ -36,7 +36,7 @@ #include #endif /* UNUSED */ -#include "ppp.h" +#include "ppp_impl.h" #include "chap-new.h" #include "chap-md5.h" diff --git a/src/netif/ppp/chap-new.c b/src/netif/ppp/chap-new.c index 7c0b1c1a..fbeacabf 100644 --- a/src/netif/ppp/chap-new.c +++ b/src/netif/ppp/chap-new.c @@ -36,7 +36,7 @@ #include #endif /* UNUSED */ -#include "ppp.h" +#include "ppp_impl.h" #if 0 /* UNUSED */ #include "session.h" diff --git a/src/netif/ppp/chap_ms.c b/src/netif/ppp/chap_ms.c index e70c28fc..a5caa54b 100644 --- a/src/netif/ppp/chap_ms.c +++ b/src/netif/ppp/chap_ms.c @@ -87,7 +87,7 @@ #include #endif /* UNUSED */ -#include "ppp.h" +#include "ppp_impl.h" #include "chap-new.h" #include "chap_ms.h" diff --git a/src/netif/ppp/demand.c b/src/netif/ppp/demand.c index b2f146d6..5ef93755 100644 --- a/src/netif/ppp/demand.c +++ b/src/netif/ppp/demand.c @@ -52,7 +52,7 @@ #include #endif -#include "ppp.h" +#include "ppp_impl.h" #include "fsm.h" #include "ipcp.h" diff --git a/src/netif/ppp/eap.c b/src/netif/ppp/eap.c index 737f5411..e1b4f103 100644 --- a/src/netif/ppp/eap.c +++ b/src/netif/ppp/eap.c @@ -46,7 +46,7 @@ #include "lwip/opt.h" #if PPP_SUPPORT && EAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ -#include "ppp.h" +#include "ppp_impl.h" #include "polarssl/md5.h" #include "eap.h" diff --git a/src/netif/ppp/ecp.c b/src/netif/ppp/ecp.c index a355c48a..90f3ee20 100644 --- a/src/netif/ppp/ecp.c +++ b/src/netif/ppp/ecp.c @@ -62,7 +62,7 @@ #include -#include "ppp.h" +#include "ppp_impl.h" #include "fsm.h" #include "ecp.h" diff --git a/src/netif/ppp/fsm.c b/src/netif/ppp/fsm.c index 585ec8e7..4a31a904 100644 --- a/src/netif/ppp/fsm.c +++ b/src/netif/ppp/fsm.c @@ -55,7 +55,7 @@ #include #endif /* UNUSED */ -#include "ppp.h" +#include "ppp_impl.h" #include "fsm.h" diff --git a/src/netif/ppp/ipcp.c b/src/netif/ppp/ipcp.c index 8106ffa1..330de3f3 100644 --- a/src/netif/ppp/ipcp.c +++ b/src/netif/ppp/ipcp.c @@ -59,7 +59,7 @@ #include #endif /* UNUSED */ -#include "ppp.h" +#include "ppp_impl.h" #include "fsm.h" #include "ipcp.h" diff --git a/src/netif/ppp/lcp.c b/src/netif/ppp/lcp.c index c8d12455..5212d934 100644 --- a/src/netif/ppp/lcp.c +++ b/src/netif/ppp/lcp.c @@ -53,7 +53,7 @@ #include #endif /* UNUSED */ -#include "ppp.h" +#include "ppp_impl.h" #include "fsm.h" #include "lcp.h" diff --git a/src/netif/ppp/magic.c b/src/netif/ppp/magic.c index 73377cf7..e945f26a 100644 --- a/src/netif/ppp/magic.c +++ b/src/netif/ppp/magic.c @@ -75,7 +75,7 @@ #include "lwip/opt.h" #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ -#include "ppp.h" +#include "ppp_impl.h" #include "polarssl/md5.h" #include "magic.h" diff --git a/src/netif/ppp/multilink.c b/src/netif/ppp/multilink.c index 4c7ae95e..0ca3309c 100644 --- a/src/netif/ppp/multilink.c +++ b/src/netif/ppp/multilink.c @@ -49,7 +49,7 @@ #include #include -#include "ppp.h" +#include "ppp_impl.h" #include "fsm.h" #include "lcp.h" diff --git a/src/netif/ppp/options.c b/src/netif/ppp/options.c index eb718f09..b4d334f7 100644 --- a/src/netif/ppp/options.c +++ b/src/netif/ppp/options.c @@ -75,7 +75,7 @@ #endif #endif /* PPP_FILTER */ -#include "ppp.h" +#include "ppp_impl.h" #if defined(ultrix) || defined(NeXT) char *strdup __P((char *)); diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 2be4388f..c5c35cf0 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -91,7 +91,7 @@ #include "lwip/sio.h" #include "lwip/ip.h" /* for ip_input() */ -#include "ppp.h" +#include "ppp_impl.h" #include "fsm.h" #include "lcp.h" diff --git a/src/netif/ppp/ppp.h b/src/netif/ppp/ppp.h index a84efbaa..17fd91ee 100644 --- a/src/netif/ppp/ppp.h +++ b/src/netif/ppp/ppp.h @@ -7,13 +7,13 @@ * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this -* notice and the following disclaimer are included verbatim in any +* notice and the following disclaimer are included verbatim in any * distributions. No written agreement, license, or royalty fee is required * for any of the authorized uses. * * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, @@ -34,390 +34,28 @@ #include "lwip/opt.h" #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ -#ifndef PPPMY_H_ -#define PPPMY_H_ +#ifndef PPP_H +#define PPP_H -#include /* formats */ - -#if defined(__STDC__) -#include -#define __V(x) x -#else -#include -#define __V(x) (va_alist) va_dcl -#define const -#define volatile -#endif - -#ifndef __P -#ifdef __STDC__ -#define __P(x) x -#else -#define __P(x) () -#endif -#endif - -#ifndef bool -typedef unsigned char bool; -#endif - -#include "lwip/netif.h" #include "lwip/def.h" -#include "lwip/timers.h" #include "lwip/sio.h" +#include "lwip/stats.h" +#include "lwip/mem.h" +#include "lwip/netif.h" +#include "lwip/sys.h" +#include "lwip/timers.h" -#include "pppdebug.h" -#ifdef INET6 -#include "eui64.h" +#ifndef __u_char_defined + +/* Type definitions for BSD code. */ +typedef unsigned long u_long; +typedef unsigned int u_int; +typedef unsigned short u_short; +typedef unsigned char u_char; + #endif -/* - * Limits. - */ -#define NUM_PPP 1 /* One PPP interface supported (per process) */ -#define MAXWORDLEN 1024 /* max length of word in file (incl null) */ -#define MAXARGS 1 /* max # args to a command */ -#define MAXNAMELEN 256 /* max length of hostname or name for auth */ -#define MAXSECRETLEN 256 /* max length of password or secret */ - - -/* - * The basic PPP frame. - */ -#define PPP_HDRLEN 4 /* octets for standard ppp header */ -#define PPP_FCSLEN 2 /* octets for FCS */ - -#define PPP_ADDRESS(p) (((u_char *)(p))[0]) -#define PPP_CONTROL(p) (((u_char *)(p))[1]) -#define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3]) - -/* - * Significant octet values. - */ -#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */ -#define PPP_UI 0x03 /* Unnumbered Information */ -#define PPP_FLAG 0x7e /* Flag Sequence */ -#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */ -#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */ - -/* - * Protocol field values. - */ -#define PPP_IP 0x21 /* Internet Protocol */ -#if 0 /* UNUSED */ -#define PPP_AT 0x29 /* AppleTalk Protocol */ -#define PPP_IPX 0x2b /* IPX protocol */ -#endif /* UNUSED */ -#if VJ_SUPPORT -#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */ -#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */ -#endif /* VJ_SUPPORT */ -#ifdef INET6 -#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */ -#endif /* INET6 */ -#if CCP_SUPPORT -#define PPP_COMP 0xfd /* compressed packet */ -#endif /* CCP_SUPPORT */ -#define PPP_IPCP 0x8021 /* IP Control Protocol */ -#if 0 /* UNUSED */ -#define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */ -#define PPP_IPXCP 0x802b /* IPX Control Protocol */ -#endif /* UNUSED */ -#ifdef INET6 -#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */ -#endif /* INET6 */ -#if CCP_SUPPORT -#define PPP_CCP 0x80fd /* Compression Control Protocol */ -#endif /* CCP_SUPPORT */ -#if ECP_SUPPORT -#define PPP_ECP 0x8053 /* Encryption Control Protocol */ -#endif /* ECP_SUPPORT */ -#define PPP_LCP 0xc021 /* Link Control Protocol */ -#if PAP_SUPPORT -#define PPP_PAP 0xc023 /* Password Authentication Protocol */ -#endif /* PAP_SUPPORT */ -#if LQR_SUPPORT -#define PPP_LQR 0xc025 /* Link Quality Report protocol */ -#endif /* LQR_SUPPORT */ -#if CHAP_SUPPORT -#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */ -#endif /* CHAP_SUPPORT */ -#if CBCP_SUPPORT -#define PPP_CBCP 0xc029 /* Callback Control Protocol */ -#endif /* CBCP_SUPPORT */ -#if EAP_SUPPORT -#define PPP_EAP 0xc227 /* Extensible Authentication Protocol */ -#endif /* EAP_SUPPORT */ - -/* - * Values for FCS calculations. - */ -#define PPP_INITFCS 0xffff /* Initial FCS value */ -#define PPP_GOODFCS 0xf0b8 /* Good final FCS value */ -#define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff]) - -/* - * A 32-bit unsigned integral type. - */ - -#if !defined(__BIT_TYPES_DEFINED__) && !defined(_BITYPES) \ - && !defined(__FreeBSD__) && (NS_TARGET < 40) -#ifdef UINT32_T -typedef UINT32_T u_int32_t; -#else -typedef unsigned int u_int32_t; -typedef unsigned short u_int16_t; -#endif -#endif - -/* - * Extended asyncmap - allows any character to be escaped. - */ -typedef u_char ext_accm[32]; - -/* - * What to do with network protocol (NP) packets. - */ -enum NPmode { - NPMODE_PASS, /* pass the packet through */ - NPMODE_DROP, /* silently drop the packet */ - NPMODE_ERROR, /* return an error */ - NPMODE_QUEUE /* save it up for later. */ -}; - -/* - * Statistics. - */ -#if PPP_STATS_SUPPORT -struct pppstat { - unsigned int ppp_ibytes; /* bytes received */ - unsigned int ppp_ipackets; /* packets received */ - unsigned int ppp_ierrors; /* receive errors */ - unsigned int ppp_obytes; /* bytes sent */ - unsigned int ppp_opackets; /* packets sent */ - unsigned int ppp_oerrors; /* transmit errors */ -}; - -#if VJ_SUPPORT -struct vjstat { - unsigned int vjs_packets; /* outbound packets */ - unsigned int vjs_compressed; /* outbound compressed packets */ - unsigned int vjs_searches; /* searches for connection state */ - unsigned int vjs_misses; /* times couldn't find conn. state */ - unsigned int vjs_uncompressedin; /* inbound uncompressed packets */ - unsigned int vjs_compressedin; /* inbound compressed packets */ - unsigned int vjs_errorin; /* inbound unknown type packets */ - unsigned int vjs_tossed; /* inbound packets tossed because of error */ -}; -#endif /* VJ_SUPPORT */ - -struct ppp_stats { - struct pppstat p; /* basic PPP statistics */ -#if VJ_SUPPORT - struct vjstat vj; /* VJ header compression statistics */ -#endif /* VJ_SUPPORT */ -}; - -#if CCP_SUPPORT -struct compstat { - unsigned int unc_bytes; /* total uncompressed bytes */ - unsigned int unc_packets; /* total uncompressed packets */ - unsigned int comp_bytes; /* compressed bytes */ - unsigned int comp_packets; /* compressed packets */ - unsigned int inc_bytes; /* incompressible bytes */ - unsigned int inc_packets; /* incompressible packets */ - unsigned int ratio; /* recent compression ratio << 8 */ -}; - -struct ppp_comp_stats { - struct compstat c; /* packet compression statistics */ - struct compstat d; /* packet decompression statistics */ -}; -#endif /* CCP_SUPPORT */ - -#endif /* PPP_STATS_SUPPORT */ - -/* - * The following structure records the time in seconds since - * the last NP packet was sent or received. - */ -/* FIXME: add idle time support and make it optional */ -struct ppp_idle { - time_t xmit_idle; /* time since last NP packet sent */ - time_t recv_idle; /* time since last NP packet received */ -}; - -/* FIXME: make endpoint discriminator optional */ - -/* An endpoint discriminator, used with multilink. */ -#define MAX_ENDP_LEN 20 /* maximum length of discriminator value */ -struct epdisc { - unsigned char class; - unsigned char length; - unsigned char value[MAX_ENDP_LEN]; -}; - -/* values for epdisc.class */ -#define EPD_NULL 0 /* null discriminator, no data */ -#define EPD_LOCAL 1 -#define EPD_IP 2 -#define EPD_MAC 3 -#define EPD_MAGIC 4 -#define EPD_PHONENUM 5 - -/* FIXME: global variables per PPP session */ - -/* - * Global variables. - */ -/* FIXME: improve debug flag */ -extern int debug; /* Debug flag */ - -/* FIXME: is our_name really necessary ? */ -extern char our_name[MAXNAMELEN];/* Our name for authentication purposes */ -extern char remote_name[MAXNAMELEN]; /* Peer's name for authentication */ -extern bool explicit_remote;/* remote_name specified with remotename opt */ - -/* FIXME: make it a compile time option */ -extern int idle_time_limit;/* Shut down link if idle for this long */ - -extern int phase; /* Current state of link - see values below */ -extern int error_count; /* # of times error() has been called */ -extern int unsuccess; /* # unsuccessful connection attempts */ -extern int listen_time; /* time to listen first (ms) */ -extern int status; /* exit status for pppd */ -extern int need_holdoff; /* Need holdoff period after link terminates */ -/* FIXME: remove ifunit */ -extern int ifunit; /* Interface unit number */ -extern u_char outpacket_buf[]; /* Buffer for outgoing packets */ - -/* FIXME: add more HAVE_MULTILINK */ -extern bool multilink; /* enable multilink operation */ - -/* FIXME: it is really necessary ? */ -extern int maxconnect; /* Maximum connect time (seconds) */ - -#ifdef HAVE_MULTILINK -extern bool doing_multilink; -extern bool multilink_master; -extern bool bundle_eof; -extern bool bundle_terminating; -#endif - -#ifdef MAXOCTETS -extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */ -extern int maxoctets_dir; /* Direction : - 0 - in+out (default) - 1 - in - 2 - out - 3 - max(in,out) */ -extern int maxoctets_timeout; /* Timeout for check of octets limit */ -#define PPP_OCTETS_DIRECTION_SUM 0 -#define PPP_OCTETS_DIRECTION_IN 1 -#define PPP_OCTETS_DIRECTION_OUT 2 -#define PPP_OCTETS_DIRECTION_MAXOVERAL 3 -/* same as previos, but little different on RADIUS side */ -#define PPP_OCTETS_DIRECTION_MAXSESSION 4 -#endif - -/* - * The following struct gives the addresses of procedures to call - * for a particular protocol. - */ -struct protent { - u_short protocol; /* PPP protocol number */ - /* Initialization procedure */ - void (*init) __P((int unit)); - /* Process a received packet */ - void (*input) __P((int unit, u_char *pkt, int len)); - /* Process a received protocol-reject */ - void (*protrej) __P((int unit)); - /* Lower layer has come up */ - void (*lowerup) __P((int unit)); - /* Lower layer has gone down */ - void (*lowerdown) __P((int unit)); - /* Open the protocol */ - void (*open) __P((int unit)); - /* Close the protocol */ - void (*close) __P((int unit, char *reason)); -#if PRINTPKT_SUPPORT - /* Print a packet in readable form */ - int (*printpkt) __P((u_char *pkt, int len, - void (*printer) __P((void *, char *, ...)), - void *arg)); -#endif /* PRINTPKT_SUPPORT */ - /* FIXME: data input is only used by CCP, which is not supported at this time, - * should we remove this entry and save some flash ? - */ - /* Process a received data packet */ - void (*datainput) __P((int unit, u_char *pkt, int len)); - bool enabled_flag; /* 0 iff protocol is disabled */ -#if PRINTPKT_SUPPORT - char *name; /* Text name of protocol */ - char *data_name; /* Text name of corresponding data protocol */ -#endif /* PRINTPKT_SUPPORT */ -#if PPP_OPTIONS - option_t *options; /* List of command-line options */ - /* Check requested options, assign defaults */ - void (*check_options) __P((void)); -#endif /* PPP_OPTIONS */ -#if DEMAND_SUPPORT - /* Configure interface for demand-dial */ - int (*demand_conf) __P((int unit)); - /* Say whether to bring up link for this pkt */ - int (*active_pkt) __P((u_char *pkt, int len)); -#endif /* DEMAND_SUPPORT */ -}; - -/* Table of pointers to supported protocols */ -extern struct protent *protocols[]; - - -/* Values for auth_pending, auth_done */ -#if PAP_SUPPORT -#define PAP_WITHPEER 0x1 -#define PAP_PEER 0x2 -#endif /* PAP_SUPPORT */ -#if CHAP_SUPPORT -#define CHAP_WITHPEER 0x4 -#define CHAP_PEER 0x8 -#endif /* CHAP_SUPPORT */ -#if EAP_SUPPORT -#define EAP_WITHPEER 0x10 -#define EAP_PEER 0x20 -#endif /* EAP_SUPPORT */ - -/* Values for auth_done only */ -#if CHAP_SUPPORT -#define CHAP_MD5_WITHPEER 0x40 -#define CHAP_MD5_PEER 0x80 -#if MSCHAP_SUPPORT -#define CHAP_MS_SHIFT 8 /* LSB position for MS auths */ -#define CHAP_MS_WITHPEER 0x100 -#define CHAP_MS_PEER 0x200 -#define CHAP_MS2_WITHPEER 0x400 -#define CHAP_MS2_PEER 0x800 -#endif /* MSCHAP_SUPPORT */ -#endif /* CHAP_SUPPORT */ - -/* - * Values for phase. - */ -#define PHASE_DEAD 0 -#define PHASE_INITIALIZE 1 -#define PHASE_SERIALCONN 2 -#define PHASE_DORMANT 3 -#define PHASE_ESTABLISH 4 -#define PHASE_AUTHENTICATE 5 -#define PHASE_CALLBACK 6 -#define PHASE_NETWORK 7 -#define PHASE_RUNNING 8 -#define PHASE_TERMINATE 9 -#define PHASE_DISCONNECT 10 -#define PHASE_HOLDOFF 11 -#define PHASE_MASTER 12 - /************************* *** PUBLIC DEFINITIONS *** @@ -454,58 +92,14 @@ struct ppp_addrs { ip_addr_t our_ipaddr, his_ipaddr, netmask, dns1, dns2; }; -#if PPP_STATS_SUPPORT -/* - * PPP statistics structure - */ -struct pppd_stats { - unsigned int bytes_in; - unsigned int bytes_out; - unsigned int pkts_in; - unsigned int pkts_out; -}; -#endif /* PPP_STATS_SUPPORT */ - -/* FIXME: use PPP option instead ? */ - -struct ppp_settings { - - u_int disable_defaultip : 1; /* Don't use hostname for default IP addrs */ - u_int auth_required : 1; /* Peer is required to authenticate */ - u_int explicit_remote : 1; /* remote_name specified with remotename opt */ -#if PAP_SUPPORT - u_int refuse_pap : 1; /* Don't wanna auth. ourselves with PAP */ -#endif /* PAP_SUPPORT */ -#if CHAP_SUPPORT - u_int refuse_chap : 1; /* Don't wanna auth. ourselves with CHAP */ -#endif /* CHAP_SUPPORT */ -#if MSCHAP_SUPPORT - u_int refuse_mschap : 1; /* Don't wanna auth. ourselves with MS-CHAP */ - u_int refuse_mschap_v2 : 1; /* Don't wanna auth. ourselves with MS-CHAPv2 */ -#endif /* MSCHAP_SUPPORT */ -#if EAP_SUPPORT - u_int refuse_eap : 1; /* Don't wanna auth. ourselves with EAP */ -#endif /* EAP_SUPPORT */ - u_int usehostname : 1; /* Use hostname for our_name */ - u_int usepeerdns : 1; /* Ask peer for DNS adds */ - - u_short idle_time_limit; /* Shut down link if idle for this long */ - int maxconnect; /* Maximum connect time (seconds) */ - - char user [MAXNAMELEN + 1]; /* Username for PAP */ - char passwd [MAXSECRETLEN + 1]; /* Password for PAP, secret for CHAP */ - char our_name [MAXNAMELEN + 1]; /* Our name for authentication purposes */ - /* FIXME: re-enable that */ - /* char remote_name[MAXNAMELEN + 1]; */ /* Peer's name for authentication */ -}; - -struct ppp_settings ppp_settings; - /************************ *** PUBLIC FUNCTIONS *** ************************/ +/* Initialize the PPP subsystem. */ +int ppp_init(void); + /* Warning: Using PPPAUTHTYPE_ANY might have security consequences. * RFC 1994 says: * @@ -529,21 +123,19 @@ enum pppAuthType { #if CHAP_SUPPORT PPPAUTHTYPE_CHAP, #endif /* CHAP_SUPPORT */ +#if PAP_SUPPORT PPPAUTHTYPE_PAP, +#endif /* PAP_SUPPORT */ PPPAUTHTYPE_ANY, PPPAUTHTYPE_NONE }; -/* Initialize the PPP subsystem. */ -int ppp_init(void); - void ppp_set_auth(enum pppAuthType authType, const char *user, const char *passwd); /* Link status callback function prototype */ typedef void (*pppLinkStatusCB_fn)(void *ctx, int errCode, void *arg); #if PPPOS_SUPPORT - /* * Open a new PPP connection using the given serial I/O device. * This initializes the PPP control block but does not @@ -556,30 +148,23 @@ typedef void (*pppLinkStatusCB_fn)(void *ctx, int errCode, void *arg); * an error code (negative) on failure. */ int pppOverSerialOpen(sio_fd_t fd, pppLinkStatusCB_fn linkStatusCB, void *linkStatusCtx); - -#if !PPP_INPROC_OWNTHREAD -/* - * PPP over Serial: this is the input function to be called for received data. - * If PPP_INPROC_OWNTHREAD==1, a separate input thread using the blocking - * sio_read() is used, so this is deactivated. - */ -void pppos_input(int pd, u_char* data, int len); -#endif /* !PPP_INPROC_OWNTHREAD */ - #endif /* PPPOS_SUPPORT */ #if PPPOE_SUPPORT /* - * Open a new PPP Over Ethernet (PPPOE) connection. + * Open a new PPP Over Ethernet (PPPoE) connection. */ int ppp_over_ethernet_open(struct netif *ethif, const char *service_name, const char *concentrator_name, pppLinkStatusCB_fn linkStatusCB, void *linkStatusCtx); #endif /* PPPOE_SUPPORT */ +/* for source code compatibility */ +#define pppOpen(fd,cb,ls) pppOverSerialOpen(fd,cb,ls) + /* - * Close a PPP connection and release the descriptor. + * Close a PPP connection and release the descriptor. * Any outstanding packets in the queues are dropped. - * Return 0 on success, an error code on failure. + * Return 0 on success, an error code on failure. */ int pppClose(int pd); @@ -588,261 +173,37 @@ int pppClose(int pd); */ void pppSigHUP(int pd); +/* + * Get and set parameters for the given connection. + * Return 0 on success, an error code on failure. + */ +int pppIOCtl(int pd, int cmd, void *arg); + +/* + * Return the Maximum Transmission Unit for the given PPP connection. + */ +/* FIXME: demystify MTU support */ +u_short pppMTU(int pd); + +#if PPPOS_SUPPORT && !PPP_INPROC_OWNTHREAD +/* + * PPP over Serial: this is the input function to be called for received data. + * If PPP_INPROC_OWNTHREAD==1, a seperate input thread using the blocking + * sio_read() is used, so this is deactivated. + */ +void pppos_input(int pd, u_char* data, int len); +#endif /* PPPOS_SUPPORT && !PPP_INPROC_OWNTHREAD */ + + #if LWIP_NETIF_STATUS_CALLBACK /* Set an lwIP-style status-callback for the selected PPP device */ void ppp_set_netif_statuscallback(int pd, netif_status_callback_fn status_callback); #endif /* LWIP_NETIF_STATUS_CALLBACK */ - #if LWIP_NETIF_LINK_CALLBACK /* Set an lwIP-style link-callback for the selected PPP device */ void ppp_set_netif_linkcallback(int pd, netif_status_callback_fn link_callback); #endif /* LWIP_NETIF_LINK_CALLBACK */ - - - -/* ------------------------------------------------------ * - * --- EVERYTHING BELOW SHOULD BE CONSIDERED PRIVATE ---- * - * ------------------------------------------------------ */ - -/* PPP flow functions - */ -#if PPPOE_SUPPORT -void pppOverEthernetInitFailed(int pd); -/* function called by pppoe.c */ -void ppp_input_over_ethernet(int pd, struct pbuf *pb); -#endif /* PPPOE_SUPPORT */ - -int pppIOCtl(int pd, int cmd, void *arg); - -/* FIXME: demystify MTU support */ -u_short pppMTU(int pd); - -/* function called by all PPP subsystems to send packets */ -int ppp_write(int pd, const u_char *s, int n); - -/* functions called by auth.c link_terminated() */ -void pppLinkDown(int pd); -void pppLinkTerminated(int pd); - -/* merge a pbuf chain into one pbuf */ -struct pbuf * ppp_singlebuf(struct pbuf *p); - - -/* Functions called by various PPP subsystems to configure - * the PPP interface or change the PPP phase. - */ -void new_phase(int p); - -#if PPPOS_SUPPORT -void ppp_set_xaccm(int unit, ext_accm *accm); -#endif /* PPPOS_SUPPORT */ -int ppp_send_config(int unit, int mtu, u_int32_t accm, int pcomp, int accomp); -int ppp_recv_config(int unit, int mru, u_int32_t accm, int pcomp, int accomp); - -int sifaddr(int unit, u_int32_t our_adr, u_int32_t his_adr, u_int32_t net_mask); -int cifaddr(int unit, u_int32_t our_adr, u_int32_t his_adr); - -int sifup(int u); -int sifdown (int u); - -int sifnpmode(int u, int proto, enum NPmode mode); - -void netif_set_mtu(int unit, int mtu); -int netif_get_mtu(int mtu); - -int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway, bool replace); -int cifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway); - -int sifproxyarp (int unit, u_int32_t his_adr); -int cifproxyarp (int unit, u_int32_t his_adr); - -int sifvjcomp (int u, int vjcomp, int cidcomp, int maxcid); - -int get_idle_time(int u, struct ppp_idle *ip); - -int get_loop_output(void); - -u_int32_t GetMask (u_int32_t addr); - - -/* Optional protocol names list, to make our messages a little more informative. */ -#if PPP_PROTOCOLNAME -const char * protocol_name(int proto); -#endif /* PPP_PROTOCOLNAME */ - - -/* Optional stats support, to get some statistics on the PPP interface */ -#if PPP_STATS_SUPPORT -void print_link_stats(void); /* Print stats, if available */ -void reset_link_stats(int u); /* Reset (init) stats when link goes up */ -void update_link_stats(int u); /* Get stats at link termination */ -#endif /* PPP_STATS_SUPPORT */ - - - -/* - * Inline versions of get/put char/short/long. - * Pointer is advanced; we assume that both arguments - * are lvalues and will already be in registers. - * cp MUST be u_char *. - */ -#define GETCHAR(c, cp) { \ - (c) = *(cp)++; \ -} -#define PUTCHAR(c, cp) { \ - *(cp)++ = (u_char) (c); \ -} - - -#define GETSHORT(s, cp) { \ - (s) = *(cp)++ << 8; \ - (s) |= *(cp)++; \ -} -#define PUTSHORT(s, cp) { \ - *(cp)++ = (u_char) ((s) >> 8); \ - *(cp)++ = (u_char) (s); \ -} - -#define GETLONG(l, cp) { \ - (l) = *(cp)++ << 8; \ - (l) |= *(cp)++; (l) <<= 8; \ - (l) |= *(cp)++; (l) <<= 8; \ - (l) |= *(cp)++; \ -} -#define PUTLONG(l, cp) { \ - *(cp)++ = (u_char) ((l) >> 24); \ - *(cp)++ = (u_char) ((l) >> 16); \ - *(cp)++ = (u_char) ((l) >> 8); \ - *(cp)++ = (u_char) (l); \ -} - -#define INCPTR(n, cp) ((cp) += (n)) -#define DECPTR(n, cp) ((cp) -= (n)) - -/* - * System dependent definitions for user-level 4.3BSD UNIX implementation. - */ -#define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0) -#define TIMEOUTMS(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t), (f), (a)); } while(0) -#define UNTIMEOUT(f, a) sys_untimeout((f), (a)) - -#define BZERO(s, n) memset(s, 0, n) -#define BCMP(s1, s2, l) memcmp(s1, s2, l) - -#define PRINTMSG(m, l) { info("Remote message: %0.*v", l, m); } - -/* - * MAKEHEADER - Add Header fields to a packet. - */ -#define MAKEHEADER(p, t) { \ - PUTCHAR(PPP_ALLSTATIONS, p); \ - PUTCHAR(PPP_UI, p); \ - PUTSHORT(t, p); } - -/* - * Exit status values. - */ -#define EXIT_OK 0 -#define EXIT_FATAL_ERROR 1 -#define EXIT_OPTION_ERROR 2 -#define EXIT_NOT_ROOT 3 -#define EXIT_NO_KERNEL_SUPPORT 4 -#define EXIT_USER_REQUEST 5 -#define EXIT_LOCK_FAILED 6 -#define EXIT_OPEN_FAILED 7 -#define EXIT_CONNECT_FAILED 8 -#define EXIT_PTYCMD_FAILED 9 -#define EXIT_NEGOTIATION_FAILED 10 -#define EXIT_PEER_AUTH_FAILED 11 -#define EXIT_IDLE_TIMEOUT 12 -#define EXIT_CONNECT_TIME 13 -#define EXIT_CALLBACK 14 -#define EXIT_PEER_DEAD 15 -#define EXIT_HANGUP 16 -#define EXIT_LOOPBACK 17 -#define EXIT_INIT_FAILED 18 -#define EXIT_AUTH_TOPEER_FAILED 19 -#ifdef MAXOCTETS -#define EXIT_TRAFFIC_LIMIT 20 -#endif -#define EXIT_CNID_AUTH_FAILED 21 - -/* Procedures exported from auth.c */ -void link_required __P((int)); /* we are starting to use the link */ -void link_terminated __P((int)); /* we are finished with the link */ -void link_down __P((int)); /* the LCP layer has left the Opened state */ -void upper_layers_down __P((int));/* take all NCPs down */ -void link_established __P((int)); /* the link is up; authenticate now */ -void start_networks __P((int)); /* start all the network control protos */ -void continue_networks __P((int)); /* start network [ip, etc] control protos */ - -void auth_peer_fail __P((int, int)); - /* peer failed to authenticate itself */ -void auth_peer_success __P((int, int, int, char *, int)); - /* peer successfully authenticated itself */ -void auth_withpeer_fail __P((int, int)); - /* we failed to authenticate ourselves */ -void auth_withpeer_success __P((int, int, int)); - /* we successfully authenticated ourselves */ -void np_up __P((int, int)); /* a network protocol has come up */ -void np_down __P((int, int)); /* a network protocol has gone down */ -void np_finished __P((int, int)); /* a network protocol no longer needs link */ -void auth_reset __P((int)); /* check what secrets we have */ -int get_secret __P((int, char *, char *, char *, int *, int)); - /* get "secret" for chap */ - -/* Procedures exported from ipcp.c */ -/* int parse_dotted_ip __P((char *, u_int32_t *)); */ - -/* Procedures exported from demand.c */ -#if DEMAND_SUPPORT -void demand_conf __P((void)); /* config interface(s) for demand-dial */ -void demand_block __P((void)); /* set all NPs to queue up packets */ -void demand_unblock __P((void)); /* set all NPs to pass packets */ -void demand_discard __P((void)); /* set all NPs to discard packets */ -void demand_rexmit __P((int, u_int32_t)); /* retransmit saved frames for an NP*/ -int loop_chars __P((unsigned char *, int)); /* process chars from loopback */ -int loop_frame __P((unsigned char *, int)); /* should we bring link up? */ -#endif /* DEMAND_SUPPORT */ - -/* Procedures exported from multilink.c */ -#ifdef HAVE_MULTILINK -void mp_check_options __P((void)); /* Check multilink-related options */ -int mp_join_bundle __P((void)); /* join our link to an appropriate bundle */ -void mp_exit_bundle __P((void)); /* have disconnected our link from bundle */ -void mp_bundle_terminated __P((void)); -char *epdisc_to_str __P((struct epdisc *)); /* string from endpoint discrim. */ -int str_to_epdisc __P((struct epdisc *, char *)); /* endpt disc. from str */ -#else -#define mp_bundle_terminated() /* nothing */ -#define mp_exit_bundle() /* nothing */ -#define doing_multilink 0 -#define multilink_master 0 -#endif - -/* Procedures exported from utils.c. */ -void print_string __P((char *, int, void (*) (void *, char *, ...), - void *)); /* Format a string for output */ -int slprintf __P((char *, int, char *, ...)); /* sprintf++ */ -int vslprintf __P((char *, int, char *, va_list)); /* vsprintf++ */ -size_t strlcpy __P((char *, const char *, size_t)); /* safe strcpy */ -size_t strlcat __P((char *, const char *, size_t)); /* safe strncpy */ -void dbglog __P((char *, ...)); /* log a debug message */ -void info __P((char *, ...)); /* log an informational message */ -void notice __P((char *, ...)); /* log a notice-level message */ -void warn __P((char *, ...)); /* log a warning message */ -void error __P((char *, ...)); /* log an error message */ -void fatal __P((char *, ...)); /* log an error message and die(1) */ -void init_pr_log __P((const char *, int)); /* initialize for using pr_log */ -void pr_log __P((void *, char *, ...)); /* printer fn, output to syslog */ -void end_pr_log __P((void)); /* finish up after using pr_log */ -#if PRINTPKT_SUPPORT -void dump_packet __P((const char *, u_char *, int)); - /* dump packet to debug log if interesting */ -#endif /* PRINTPKT_SUPPORT */ - - -#endif /* PPPMY_H_ */ +#endif /* PPP_H */ #endif /* PPP_SUPPORT */ diff --git a/src/netif/ppp/ppp_impl.h b/src/netif/ppp/ppp_impl.h new file mode 100644 index 00000000..da846727 --- /dev/null +++ b/src/netif/ppp/ppp_impl.h @@ -0,0 +1,706 @@ +/***************************************************************************** +* ppp.h - Network Point to Point Protocol header file. +* +* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. +* portions Copyright (c) 1997 Global Election Systems Inc. +* +* The authors hereby grant permission to use, copy, modify, distribute, +* and license this software and its documentation for any purpose, provided +* that existing copyright notices are retained in all copies and that this +* notice and the following disclaimer are included verbatim in any +* distributions. No written agreement, license, or royalty fee is required +* for any of the authorized uses. +* +* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +****************************************************************************** +* REVISION HISTORY +* +* 03-01-01 Marc Boucher +* Ported to lwIP. +* 97-11-05 Guy Lancaster , Global Election Systems Inc. +* Original derived from BSD codes. +*****************************************************************************/ + +#include "lwip/opt.h" +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef PPP_IMP_H_ +#define PPP_IMP_H_ + +#include /* formats */ + +#if defined(__STDC__) +#include +#define __V(x) x +#else +#include +#define __V(x) (va_alist) va_dcl +#define const +#define volatile +#endif + +#ifndef __P +#ifdef __STDC__ +#define __P(x) x +#else +#define __P(x) () +#endif +#endif + +#ifndef bool +typedef unsigned char bool; +#endif + +#include "lwip/netif.h" +#include "lwip/def.h" +#include "lwip/timers.h" +#include "lwip/sio.h" + +#include "ppp.h" +#include "pppdebug.h" + +#ifdef INET6 +#include "eui64.h" +#endif + +/* + * Limits. + */ +#define NUM_PPP 1 /* One PPP interface supported (per process) */ +#define MAXWORDLEN 1024 /* max length of word in file (incl null) */ +#define MAXARGS 1 /* max # args to a command */ +#define MAXNAMELEN 256 /* max length of hostname or name for auth */ +#define MAXSECRETLEN 256 /* max length of password or secret */ + + +/* + * The basic PPP frame. + */ +#define PPP_HDRLEN 4 /* octets for standard ppp header */ +#define PPP_FCSLEN 2 /* octets for FCS */ + +#define PPP_ADDRESS(p) (((u_char *)(p))[0]) +#define PPP_CONTROL(p) (((u_char *)(p))[1]) +#define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3]) + +/* + * Significant octet values. + */ +#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */ +#define PPP_UI 0x03 /* Unnumbered Information */ +#define PPP_FLAG 0x7e /* Flag Sequence */ +#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */ +#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */ + +/* + * Protocol field values. + */ +#define PPP_IP 0x21 /* Internet Protocol */ +#if 0 /* UNUSED */ +#define PPP_AT 0x29 /* AppleTalk Protocol */ +#define PPP_IPX 0x2b /* IPX protocol */ +#endif /* UNUSED */ +#if VJ_SUPPORT +#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */ +#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */ +#endif /* VJ_SUPPORT */ +#ifdef INET6 +#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */ +#endif /* INET6 */ +#if CCP_SUPPORT +#define PPP_COMP 0xfd /* compressed packet */ +#endif /* CCP_SUPPORT */ +#define PPP_IPCP 0x8021 /* IP Control Protocol */ +#if 0 /* UNUSED */ +#define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */ +#define PPP_IPXCP 0x802b /* IPX Control Protocol */ +#endif /* UNUSED */ +#ifdef INET6 +#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */ +#endif /* INET6 */ +#if CCP_SUPPORT +#define PPP_CCP 0x80fd /* Compression Control Protocol */ +#endif /* CCP_SUPPORT */ +#if ECP_SUPPORT +#define PPP_ECP 0x8053 /* Encryption Control Protocol */ +#endif /* ECP_SUPPORT */ +#define PPP_LCP 0xc021 /* Link Control Protocol */ +#if PAP_SUPPORT +#define PPP_PAP 0xc023 /* Password Authentication Protocol */ +#endif /* PAP_SUPPORT */ +#if LQR_SUPPORT +#define PPP_LQR 0xc025 /* Link Quality Report protocol */ +#endif /* LQR_SUPPORT */ +#if CHAP_SUPPORT +#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */ +#endif /* CHAP_SUPPORT */ +#if CBCP_SUPPORT +#define PPP_CBCP 0xc029 /* Callback Control Protocol */ +#endif /* CBCP_SUPPORT */ +#if EAP_SUPPORT +#define PPP_EAP 0xc227 /* Extensible Authentication Protocol */ +#endif /* EAP_SUPPORT */ + +/* + * Values for FCS calculations. + */ +#define PPP_INITFCS 0xffff /* Initial FCS value */ +#define PPP_GOODFCS 0xf0b8 /* Good final FCS value */ +#define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff]) + +/* + * A 32-bit unsigned integral type. + */ + +#if !defined(__BIT_TYPES_DEFINED__) && !defined(_BITYPES) \ + && !defined(__FreeBSD__) && (NS_TARGET < 40) +#ifdef UINT32_T +typedef UINT32_T u_int32_t; +#else +typedef unsigned int u_int32_t; +typedef unsigned short u_int16_t; +#endif +#endif + +/* + * Extended asyncmap - allows any character to be escaped. + */ +typedef u_char ext_accm[32]; + +/* + * What to do with network protocol (NP) packets. + */ +enum NPmode { + NPMODE_PASS, /* pass the packet through */ + NPMODE_DROP, /* silently drop the packet */ + NPMODE_ERROR, /* return an error */ + NPMODE_QUEUE /* save it up for later. */ +}; + +/* + * Statistics. + */ +#if PPP_STATS_SUPPORT +struct pppstat { + unsigned int ppp_ibytes; /* bytes received */ + unsigned int ppp_ipackets; /* packets received */ + unsigned int ppp_ierrors; /* receive errors */ + unsigned int ppp_obytes; /* bytes sent */ + unsigned int ppp_opackets; /* packets sent */ + unsigned int ppp_oerrors; /* transmit errors */ +}; + +#if VJ_SUPPORT +struct vjstat { + unsigned int vjs_packets; /* outbound packets */ + unsigned int vjs_compressed; /* outbound compressed packets */ + unsigned int vjs_searches; /* searches for connection state */ + unsigned int vjs_misses; /* times couldn't find conn. state */ + unsigned int vjs_uncompressedin; /* inbound uncompressed packets */ + unsigned int vjs_compressedin; /* inbound compressed packets */ + unsigned int vjs_errorin; /* inbound unknown type packets */ + unsigned int vjs_tossed; /* inbound packets tossed because of error */ +}; +#endif /* VJ_SUPPORT */ + +struct ppp_stats { + struct pppstat p; /* basic PPP statistics */ +#if VJ_SUPPORT + struct vjstat vj; /* VJ header compression statistics */ +#endif /* VJ_SUPPORT */ +}; + +#if CCP_SUPPORT +struct compstat { + unsigned int unc_bytes; /* total uncompressed bytes */ + unsigned int unc_packets; /* total uncompressed packets */ + unsigned int comp_bytes; /* compressed bytes */ + unsigned int comp_packets; /* compressed packets */ + unsigned int inc_bytes; /* incompressible bytes */ + unsigned int inc_packets; /* incompressible packets */ + unsigned int ratio; /* recent compression ratio << 8 */ +}; + +struct ppp_comp_stats { + struct compstat c; /* packet compression statistics */ + struct compstat d; /* packet decompression statistics */ +}; +#endif /* CCP_SUPPORT */ + +#endif /* PPP_STATS_SUPPORT */ + +/* + * The following structure records the time in seconds since + * the last NP packet was sent or received. + */ +/* FIXME: add idle time support and make it optional */ +struct ppp_idle { + time_t xmit_idle; /* time since last NP packet sent */ + time_t recv_idle; /* time since last NP packet received */ +}; + +/* FIXME: make endpoint discriminator optional */ + +/* An endpoint discriminator, used with multilink. */ +#define MAX_ENDP_LEN 20 /* maximum length of discriminator value */ +struct epdisc { + unsigned char class; + unsigned char length; + unsigned char value[MAX_ENDP_LEN]; +}; + +/* values for epdisc.class */ +#define EPD_NULL 0 /* null discriminator, no data */ +#define EPD_LOCAL 1 +#define EPD_IP 2 +#define EPD_MAC 3 +#define EPD_MAGIC 4 +#define EPD_PHONENUM 5 + +/* FIXME: global variables per PPP session */ + +/* + * Global variables. + */ +/* FIXME: improve debug flag */ +extern int debug; /* Debug flag */ + +/* FIXME: is our_name really necessary ? */ +extern char our_name[MAXNAMELEN];/* Our name for authentication purposes */ +extern char remote_name[MAXNAMELEN]; /* Peer's name for authentication */ +extern bool explicit_remote;/* remote_name specified with remotename opt */ + +/* FIXME: make it a compile time option */ +extern int idle_time_limit;/* Shut down link if idle for this long */ + +extern int phase; /* Current state of link - see values below */ +extern int error_count; /* # of times error() has been called */ +extern int unsuccess; /* # unsuccessful connection attempts */ +extern int listen_time; /* time to listen first (ms) */ +extern int status; /* exit status for pppd */ +extern int need_holdoff; /* Need holdoff period after link terminates */ +/* FIXME: remove ifunit */ +extern int ifunit; /* Interface unit number */ +extern u_char outpacket_buf[]; /* Buffer for outgoing packets */ + +/* FIXME: add more HAVE_MULTILINK */ +extern bool multilink; /* enable multilink operation */ + +/* FIXME: it is really necessary ? */ +extern int maxconnect; /* Maximum connect time (seconds) */ + +#ifdef HAVE_MULTILINK +extern bool doing_multilink; +extern bool multilink_master; +extern bool bundle_eof; +extern bool bundle_terminating; +#endif + +#ifdef MAXOCTETS +extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */ +extern int maxoctets_dir; /* Direction : + 0 - in+out (default) + 1 - in + 2 - out + 3 - max(in,out) */ +extern int maxoctets_timeout; /* Timeout for check of octets limit */ +#define PPP_OCTETS_DIRECTION_SUM 0 +#define PPP_OCTETS_DIRECTION_IN 1 +#define PPP_OCTETS_DIRECTION_OUT 2 +#define PPP_OCTETS_DIRECTION_MAXOVERAL 3 +/* same as previos, but little different on RADIUS side */ +#define PPP_OCTETS_DIRECTION_MAXSESSION 4 +#endif + +/* + * The following struct gives the addresses of procedures to call + * for a particular protocol. + */ +struct protent { + u_short protocol; /* PPP protocol number */ + /* Initialization procedure */ + void (*init) __P((int unit)); + /* Process a received packet */ + void (*input) __P((int unit, u_char *pkt, int len)); + /* Process a received protocol-reject */ + void (*protrej) __P((int unit)); + /* Lower layer has come up */ + void (*lowerup) __P((int unit)); + /* Lower layer has gone down */ + void (*lowerdown) __P((int unit)); + /* Open the protocol */ + void (*open) __P((int unit)); + /* Close the protocol */ + void (*close) __P((int unit, char *reason)); +#if PRINTPKT_SUPPORT + /* Print a packet in readable form */ + int (*printpkt) __P((u_char *pkt, int len, + void (*printer) __P((void *, char *, ...)), + void *arg)); +#endif /* PRINTPKT_SUPPORT */ + /* FIXME: data input is only used by CCP, which is not supported at this time, + * should we remove this entry and save some flash ? + */ + /* Process a received data packet */ + void (*datainput) __P((int unit, u_char *pkt, int len)); + bool enabled_flag; /* 0 iff protocol is disabled */ +#if PRINTPKT_SUPPORT + char *name; /* Text name of protocol */ + char *data_name; /* Text name of corresponding data protocol */ +#endif /* PRINTPKT_SUPPORT */ +#if PPP_OPTIONS + option_t *options; /* List of command-line options */ + /* Check requested options, assign defaults */ + void (*check_options) __P((void)); +#endif /* PPP_OPTIONS */ +#if DEMAND_SUPPORT + /* Configure interface for demand-dial */ + int (*demand_conf) __P((int unit)); + /* Say whether to bring up link for this pkt */ + int (*active_pkt) __P((u_char *pkt, int len)); +#endif /* DEMAND_SUPPORT */ +}; + +/* Table of pointers to supported protocols */ +extern struct protent *protocols[]; + + +/* Values for auth_pending, auth_done */ +#if PAP_SUPPORT +#define PAP_WITHPEER 0x1 +#define PAP_PEER 0x2 +#endif /* PAP_SUPPORT */ +#if CHAP_SUPPORT +#define CHAP_WITHPEER 0x4 +#define CHAP_PEER 0x8 +#endif /* CHAP_SUPPORT */ +#if EAP_SUPPORT +#define EAP_WITHPEER 0x10 +#define EAP_PEER 0x20 +#endif /* EAP_SUPPORT */ + +/* Values for auth_done only */ +#if CHAP_SUPPORT +#define CHAP_MD5_WITHPEER 0x40 +#define CHAP_MD5_PEER 0x80 +#if MSCHAP_SUPPORT +#define CHAP_MS_SHIFT 8 /* LSB position for MS auths */ +#define CHAP_MS_WITHPEER 0x100 +#define CHAP_MS_PEER 0x200 +#define CHAP_MS2_WITHPEER 0x400 +#define CHAP_MS2_PEER 0x800 +#endif /* MSCHAP_SUPPORT */ +#endif /* CHAP_SUPPORT */ + +/* + * Values for phase. + */ +#define PHASE_DEAD 0 +#define PHASE_INITIALIZE 1 +#define PHASE_SERIALCONN 2 +#define PHASE_DORMANT 3 +#define PHASE_ESTABLISH 4 +#define PHASE_AUTHENTICATE 5 +#define PHASE_CALLBACK 6 +#define PHASE_NETWORK 7 +#define PHASE_RUNNING 8 +#define PHASE_TERMINATE 9 +#define PHASE_DISCONNECT 10 +#define PHASE_HOLDOFF 11 +#define PHASE_MASTER 12 + + +#if PPP_STATS_SUPPORT +/* + * PPP statistics structure + */ +struct pppd_stats { + unsigned int bytes_in; + unsigned int bytes_out; + unsigned int pkts_in; + unsigned int pkts_out; +}; +#endif /* PPP_STATS_SUPPORT */ + +/* FIXME: fill the struct below with option.c global variables */ + +struct ppp_settings { + + u_int disable_defaultip : 1; /* Don't use hostname for default IP addrs */ + u_int auth_required : 1; /* Peer is required to authenticate */ + u_int explicit_remote : 1; /* remote_name specified with remotename opt */ +#if PAP_SUPPORT + u_int refuse_pap : 1; /* Don't wanna auth. ourselves with PAP */ +#endif /* PAP_SUPPORT */ +#if CHAP_SUPPORT + u_int refuse_chap : 1; /* Don't wanna auth. ourselves with CHAP */ +#endif /* CHAP_SUPPORT */ +#if MSCHAP_SUPPORT + u_int refuse_mschap : 1; /* Don't wanna auth. ourselves with MS-CHAP */ + u_int refuse_mschap_v2 : 1; /* Don't wanna auth. ourselves with MS-CHAPv2 */ +#endif /* MSCHAP_SUPPORT */ +#if EAP_SUPPORT + u_int refuse_eap : 1; /* Don't wanna auth. ourselves with EAP */ +#endif /* EAP_SUPPORT */ + u_int usehostname : 1; /* Use hostname for our_name */ + u_int usepeerdns : 1; /* Ask peer for DNS adds */ + + u_short idle_time_limit; /* Shut down link if idle for this long */ + int maxconnect; /* Maximum connect time (seconds) */ + + char user [MAXNAMELEN + 1]; /* Username for PAP */ + char passwd [MAXSECRETLEN + 1]; /* Password for PAP, secret for CHAP */ + char our_name [MAXNAMELEN + 1]; /* Our name for authentication purposes */ + /* FIXME: re-enable that */ + /* char remote_name[MAXNAMELEN + 1]; */ /* Peer's name for authentication */ +}; + +struct ppp_settings ppp_settings; + + +/* PPP flow functions + */ +#if PPPOE_SUPPORT +void pppOverEthernetInitFailed(int pd); +/* function called by pppoe.c */ +void ppp_input_over_ethernet(int pd, struct pbuf *pb); +#endif /* PPPOE_SUPPORT */ + +/* function called by all PPP subsystems to send packets */ +int ppp_write(int pd, const u_char *s, int n); + +/* functions called by auth.c link_terminated() */ +void pppLinkDown(int pd); +void pppLinkTerminated(int pd); + +/* merge a pbuf chain into one pbuf */ +struct pbuf * ppp_singlebuf(struct pbuf *p); + + +/* Functions called by various PPP subsystems to configure + * the PPP interface or change the PPP phase. + */ +void new_phase(int p); + +#if PPPOS_SUPPORT +void ppp_set_xaccm(int unit, ext_accm *accm); +#endif /* PPPOS_SUPPORT */ +int ppp_send_config(int unit, int mtu, u_int32_t accm, int pcomp, int accomp); +int ppp_recv_config(int unit, int mru, u_int32_t accm, int pcomp, int accomp); + +int sifaddr(int unit, u_int32_t our_adr, u_int32_t his_adr, u_int32_t net_mask); +int cifaddr(int unit, u_int32_t our_adr, u_int32_t his_adr); + +int sifup(int u); +int sifdown (int u); + +int sifnpmode(int u, int proto, enum NPmode mode); + +void netif_set_mtu(int unit, int mtu); +int netif_get_mtu(int mtu); + +int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway, bool replace); +int cifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway); + +int sifproxyarp (int unit, u_int32_t his_adr); +int cifproxyarp (int unit, u_int32_t his_adr); + +int sifvjcomp (int u, int vjcomp, int cidcomp, int maxcid); + +int get_idle_time(int u, struct ppp_idle *ip); + +int get_loop_output(void); + +u_int32_t GetMask (u_int32_t addr); + + +/* Optional protocol names list, to make our messages a little more informative. */ +#if PPP_PROTOCOLNAME +const char * protocol_name(int proto); +#endif /* PPP_PROTOCOLNAME */ + + +/* Optional stats support, to get some statistics on the PPP interface */ +#if PPP_STATS_SUPPORT +void print_link_stats(void); /* Print stats, if available */ +void reset_link_stats(int u); /* Reset (init) stats when link goes up */ +void update_link_stats(int u); /* Get stats at link termination */ +#endif /* PPP_STATS_SUPPORT */ + + + +/* + * Inline versions of get/put char/short/long. + * Pointer is advanced; we assume that both arguments + * are lvalues and will already be in registers. + * cp MUST be u_char *. + */ +#define GETCHAR(c, cp) { \ + (c) = *(cp)++; \ +} +#define PUTCHAR(c, cp) { \ + *(cp)++ = (u_char) (c); \ +} + + +#define GETSHORT(s, cp) { \ + (s) = *(cp)++ << 8; \ + (s) |= *(cp)++; \ +} +#define PUTSHORT(s, cp) { \ + *(cp)++ = (u_char) ((s) >> 8); \ + *(cp)++ = (u_char) (s); \ +} + +#define GETLONG(l, cp) { \ + (l) = *(cp)++ << 8; \ + (l) |= *(cp)++; (l) <<= 8; \ + (l) |= *(cp)++; (l) <<= 8; \ + (l) |= *(cp)++; \ +} +#define PUTLONG(l, cp) { \ + *(cp)++ = (u_char) ((l) >> 24); \ + *(cp)++ = (u_char) ((l) >> 16); \ + *(cp)++ = (u_char) ((l) >> 8); \ + *(cp)++ = (u_char) (l); \ +} + +#define INCPTR(n, cp) ((cp) += (n)) +#define DECPTR(n, cp) ((cp) -= (n)) + +/* + * System dependent definitions for user-level 4.3BSD UNIX implementation. + */ +#define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0) +#define TIMEOUTMS(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t), (f), (a)); } while(0) +#define UNTIMEOUT(f, a) sys_untimeout((f), (a)) + +#define BZERO(s, n) memset(s, 0, n) +#define BCMP(s1, s2, l) memcmp(s1, s2, l) + +#define PRINTMSG(m, l) { info("Remote message: %0.*v", l, m); } + +/* + * MAKEHEADER - Add Header fields to a packet. + */ +#define MAKEHEADER(p, t) { \ + PUTCHAR(PPP_ALLSTATIONS, p); \ + PUTCHAR(PPP_UI, p); \ + PUTSHORT(t, p); } + +/* + * Exit status values. + */ +#define EXIT_OK 0 +#define EXIT_FATAL_ERROR 1 +#define EXIT_OPTION_ERROR 2 +#define EXIT_NOT_ROOT 3 +#define EXIT_NO_KERNEL_SUPPORT 4 +#define EXIT_USER_REQUEST 5 +#define EXIT_LOCK_FAILED 6 +#define EXIT_OPEN_FAILED 7 +#define EXIT_CONNECT_FAILED 8 +#define EXIT_PTYCMD_FAILED 9 +#define EXIT_NEGOTIATION_FAILED 10 +#define EXIT_PEER_AUTH_FAILED 11 +#define EXIT_IDLE_TIMEOUT 12 +#define EXIT_CONNECT_TIME 13 +#define EXIT_CALLBACK 14 +#define EXIT_PEER_DEAD 15 +#define EXIT_HANGUP 16 +#define EXIT_LOOPBACK 17 +#define EXIT_INIT_FAILED 18 +#define EXIT_AUTH_TOPEER_FAILED 19 +#ifdef MAXOCTETS +#define EXIT_TRAFFIC_LIMIT 20 +#endif +#define EXIT_CNID_AUTH_FAILED 21 + +/* Procedures exported from auth.c */ +void link_required __P((int)); /* we are starting to use the link */ +void link_terminated __P((int)); /* we are finished with the link */ +void link_down __P((int)); /* the LCP layer has left the Opened state */ +void upper_layers_down __P((int));/* take all NCPs down */ +void link_established __P((int)); /* the link is up; authenticate now */ +void start_networks __P((int)); /* start all the network control protos */ +void continue_networks __P((int)); /* start network [ip, etc] control protos */ + +void auth_peer_fail __P((int, int)); + /* peer failed to authenticate itself */ +void auth_peer_success __P((int, int, int, char *, int)); + /* peer successfully authenticated itself */ +void auth_withpeer_fail __P((int, int)); + /* we failed to authenticate ourselves */ +void auth_withpeer_success __P((int, int, int)); + /* we successfully authenticated ourselves */ +void np_up __P((int, int)); /* a network protocol has come up */ +void np_down __P((int, int)); /* a network protocol has gone down */ +void np_finished __P((int, int)); /* a network protocol no longer needs link */ +void auth_reset __P((int)); /* check what secrets we have */ +int get_secret __P((int, char *, char *, char *, int *, int)); + /* get "secret" for chap */ + +/* Procedures exported from ipcp.c */ +/* int parse_dotted_ip __P((char *, u_int32_t *)); */ + +/* Procedures exported from demand.c */ +#if DEMAND_SUPPORT +void demand_conf __P((void)); /* config interface(s) for demand-dial */ +void demand_block __P((void)); /* set all NPs to queue up packets */ +void demand_unblock __P((void)); /* set all NPs to pass packets */ +void demand_discard __P((void)); /* set all NPs to discard packets */ +void demand_rexmit __P((int, u_int32_t)); /* retransmit saved frames for an NP*/ +int loop_chars __P((unsigned char *, int)); /* process chars from loopback */ +int loop_frame __P((unsigned char *, int)); /* should we bring link up? */ +#endif /* DEMAND_SUPPORT */ + +/* Procedures exported from multilink.c */ +#ifdef HAVE_MULTILINK +void mp_check_options __P((void)); /* Check multilink-related options */ +int mp_join_bundle __P((void)); /* join our link to an appropriate bundle */ +void mp_exit_bundle __P((void)); /* have disconnected our link from bundle */ +void mp_bundle_terminated __P((void)); +char *epdisc_to_str __P((struct epdisc *)); /* string from endpoint discrim. */ +int str_to_epdisc __P((struct epdisc *, char *)); /* endpt disc. from str */ +#else +#define mp_bundle_terminated() /* nothing */ +#define mp_exit_bundle() /* nothing */ +#define doing_multilink 0 +#define multilink_master 0 +#endif + +/* Procedures exported from utils.c. */ +void print_string __P((char *, int, void (*) (void *, char *, ...), + void *)); /* Format a string for output */ +int slprintf __P((char *, int, char *, ...)); /* sprintf++ */ +int vslprintf __P((char *, int, char *, va_list)); /* vsprintf++ */ +size_t strlcpy __P((char *, const char *, size_t)); /* safe strcpy */ +size_t strlcat __P((char *, const char *, size_t)); /* safe strncpy */ +void dbglog __P((char *, ...)); /* log a debug message */ +void info __P((char *, ...)); /* log an informational message */ +void notice __P((char *, ...)); /* log a notice-level message */ +void warn __P((char *, ...)); /* log a warning message */ +void error __P((char *, ...)); /* log an error message */ +void fatal __P((char *, ...)); /* log an error message and die(1) */ +void init_pr_log __P((const char *, int)); /* initialize for using pr_log */ +void pr_log __P((void *, char *, ...)); /* printer fn, output to syslog */ +void end_pr_log __P((void)); /* finish up after using pr_log */ +#if PRINTPKT_SUPPORT +void dump_packet __P((const char *, u_char *, int)); + /* dump packet to debug log if interesting */ +#endif /* PRINTPKT_SUPPORT */ + + +#endif /* PPP_IMP_H_ */ + +#endif /* PPP_SUPPORT */ diff --git a/src/netif/ppp/ppp_oe.c b/src/netif/ppp/ppp_oe.c index caba219e..50a966d8 100644 --- a/src/netif/ppp/ppp_oe.c +++ b/src/netif/ppp/ppp_oe.c @@ -80,7 +80,7 @@ #include "lwip/memp.h" #include "lwip/stats.h" -#include "ppp.h" +#include "ppp_impl.h" #include "netif/ppp_oe.h" diff --git a/src/netif/ppp/pppcrypt.c b/src/netif/ppp/pppcrypt.c index 6a3a4ab6..dd6963e8 100644 --- a/src/netif/ppp/pppcrypt.c +++ b/src/netif/ppp/pppcrypt.c @@ -33,7 +33,7 @@ #include "lwip/opt.h" #if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not necessary */ -#include "ppp.h" +#include "ppp_impl.h" #include "pppcrypt.h" diff --git a/src/netif/ppp/upap.c b/src/netif/ppp/upap.c index 8eae19d5..07ea3853 100644 --- a/src/netif/ppp/upap.c +++ b/src/netif/ppp/upap.c @@ -52,7 +52,7 @@ #include #endif /* UNUSED */ -#include "ppp.h" +#include "ppp_impl.h" #include "upap.h" diff --git a/src/netif/ppp/utils.c b/src/netif/ppp/utils.c index 4869c057..e1340388 100644 --- a/src/netif/ppp/utils.c +++ b/src/netif/ppp/utils.c @@ -60,7 +60,7 @@ #include /* isdigit() */ -#include "ppp.h" +#include "ppp_impl.h" #include "fsm.h" #include "lcp.h"