Mbed OS Reference
Loading...
Searching...
No Matches
ppp_impl.h
1/*****************************************************************************
2* /@code
3*
4* ppp.h - Network Point to Point Protocol header file.
5*
6* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
7* portions Copyright (c) 1997 Global Election Systems Inc.
8*
9* The authors hereby grant permission to use, copy, modify, distribute,
10* and license this software and its documentation for any purpose, provided
11* that existing copyright notices are retained in all copies and that this
12* notice and the following disclaimer are included verbatim in any
13* distributions. No written agreement, license, or royalty fee is required
14* for any of the authorized uses.
15*
16* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
17* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27******************************************************************************
28* REVISION HISTORY
29*
30* 03-01-01 Marc Boucher <marc@mbsi.ca>
31* Ported to lwIP.
32* 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
33* Original derived from BSD codes.
34*
35* /@endcode
36*****************************************************************************/
37#ifndef PPP_IMPL_H
38#define PPP_IMPL_H
39
40#include "ppp_opts.h"
41
42#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
43
44#ifdef PPP_INCLUDE_SETTINGS_HEADER
45#include "ppp_settings.h"
46#endif
47
48#include <stdio.h> /* formats */
49#include <stdarg.h>
50#include <string.h>
51#include <stdlib.h> /* strtol() */
52
53#include "ppp.h"
54#include "pppdebug.h"
55
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60/*
61 * Endian conversion macros
62 */
63#ifndef LITTLE_ENDIAN
64#define LITTLE_ENDIAN 1234
65#endif
66
67#ifndef BIG_ENDIAN
68#define BIG_ENDIAN 4321
69#endif
70
71#ifndef BYTE_ORDER
72#define BYTE_ORDER LITTLE_ENDIAN
73#endif
74
75#if BYTE_ORDER == BIG_ENDIAN
76#define ppp_htons(x) ((u16_t)(x))
77#define ppp_ntohs(x) ((u16_t)(x))
78#define ppp_htonl(x) ((u32_t)(x))
79#define ppp_ntohl(x) ((u32_t)(x))
80#define PP_HTONS(x) ((u16_t)(x))
81#define PP_NTOHS(x) ((u16_t)(x))
82#define PP_HTONL(x) ((u32_t)(x))
83#define PP_NTOHL(x) ((u32_t)(x))
84#else /* BYTE_ORDER != BIG_ENDIAN */
85#ifndef ppp_htons
86u16_t ppp_htons(u16_t x);
87#endif
88#define ppp_ntohs(x) ppp_htons(x)
89
90#ifndef ppp_htonl
91u32_t ppp_htonl(u32_t x);
92#endif
93#define ppp_ntohl(x) ppp_htonl(x)
94
95/* These macros should be calculated by the preprocessor and are used
96 with compile-time constants only (so that there is no little-endian
97 overhead at runtime). */
98#define PP_HTONS(x) ((u16_t)((((x) & (u16_t)0x00ffU) << 8) | (((x) & (u16_t)0xff00U) >> 8)))
99#define PP_NTOHS(x) PP_HTONS(x)
100#define PP_HTONL(x) ((((x) & (u32_t)0x000000ffUL) << 24) | \
101 (((x) & (u32_t)0x0000ff00UL) << 8) | \
102 (((x) & (u32_t)0x00ff0000UL) >> 8) | \
103 (((x) & (u32_t)0xff000000UL) >> 24))
104#define PP_NTOHL(x) PP_HTONL(x)
105#endif /* BYTE_ORDER == BIG_ENDIAN */
106
107/*
108 * Memory used for control packets.
109 *
110 * PPP_CTRL_PBUF_MAX_SIZE is the amount of memory we allocate when we
111 * cannot figure out how much we are going to use before filling the buffer.
112 */
113#if PPP_USE_PBUF_RAM
114#define PPP_CTRL_PBUF_TYPE PBUF_RAM
115#define PPP_CTRL_PBUF_MAX_SIZE 512
116#else /* PPP_USE_PBUF_RAM */
117#define PPP_CTRL_PBUF_TYPE PBUF_POOL
118#define PPP_CTRL_PBUF_MAX_SIZE PBUF_POOL_BUFSIZE
119#endif /* PPP_USE_PBUF_RAM */
120
121/*
122 * The basic PPP frame.
123 */
124#define PPP_ADDRESS(p) (((u_char *)(p))[0])
125#define PPP_CONTROL(p) (((u_char *)(p))[1])
126#define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3])
127
128/*
129 * Significant octet values.
130 */
131#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
132#define PPP_UI 0x03 /* Unnumbered Information */
133#define PPP_FLAG 0x7e /* Flag Sequence */
134#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
135#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
136
137/*
138 * Protocol field values.
139 */
140#define PPP_IP 0x21 /* Internet Protocol */
141#if 0 /* UNUSED */
142#define PPP_AT 0x29 /* AppleTalk Protocol */
143#define PPP_IPX 0x2b /* IPX protocol */
144#endif /* UNUSED */
145#if VJ_SUPPORT
146#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
147#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
148#endif /* VJ_SUPPORT */
149#if PPP_IPV6_SUPPORT
150#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */
151#endif /* PPP_IPV6_SUPPORT */
152#if CCP_SUPPORT
153#define PPP_COMP 0xfd /* compressed packet */
154#endif /* CCP_SUPPORT */
155#define PPP_IPCP 0x8021 /* IP Control Protocol */
156#if 0 /* UNUSED */
157#define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */
158#define PPP_IPXCP 0x802b /* IPX Control Protocol */
159#endif /* UNUSED */
160#if PPP_IPV6_SUPPORT
161#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */
162#endif /* PPP_IPV6_SUPPORT */
163#if CCP_SUPPORT
164#define PPP_CCP 0x80fd /* Compression Control Protocol */
165#endif /* CCP_SUPPORT */
166#if ECP_SUPPORT
167#define PPP_ECP 0x8053 /* Encryption Control Protocol */
168#endif /* ECP_SUPPORT */
169#define PPP_LCP 0xc021 /* Link Control Protocol */
170#if PAP_SUPPORT
171#define PPP_PAP 0xc023 /* Password Authentication Protocol */
172#endif /* PAP_SUPPORT */
173#if LQR_SUPPORT
174#define PPP_LQR 0xc025 /* Link Quality Report protocol */
175#endif /* LQR_SUPPORT */
176#if CHAP_SUPPORT
177#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */
178#endif /* CHAP_SUPPORT */
179#if CBCP_SUPPORT
180#define PPP_CBCP 0xc029 /* Callback Control Protocol */
181#endif /* CBCP_SUPPORT */
182#if EAP_SUPPORT
183#define PPP_EAP 0xc227 /* Extensible Authentication Protocol */
184#endif /* EAP_SUPPORT */
185
186/*
187 * The following struct gives the addresses of procedures to call
188 * for a particular lower link level protocol.
189 */
190struct link_callbacks {
191 /* Start a connection (e.g. Initiate discovery phase) */
192 void (*connect) (ppp_pcb *pcb, void *ctx);
193#if PPP_SERVER
194 /* Listen for an incoming connection (Passive mode) */
195 void (*listen) (ppp_pcb *pcb, void *ctx);
196#endif /* PPP_SERVER */
197 /* End a connection (i.e. initiate disconnect phase) */
198 void (*disconnect) (ppp_pcb *pcb, void *ctx);
199 /* Free lower protocol control block */
200 err_t (*free) (ppp_pcb *pcb, void *ctx);
201 /* Write a pbuf to a ppp link, only used from PPP functions to send PPP packets. */
202 err_t (*write)(ppp_pcb *pcb, void *ctx, struct pbuf *p);
203 /* Send a packet from stack core (IPv4 or IPv6) */
204 err_t (*netif_output)(ppp_pcb *pcb, void *ctx, struct pbuf *p, u_short protocol);
205 /* configure the transmit-side characteristics of the PPP interface */
206 void (*send_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp);
207 /* confire the receive-side characteristics of the PPP interface */
208 void (*recv_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp);
209};
210
211/*
212 * What to do with network protocol (NP) packets.
213 */
214enum NPmode {
215 NPMODE_PASS, /* pass the packet through */
216 NPMODE_DROP, /* silently drop the packet */
217 NPMODE_ERROR, /* return an error */
218 NPMODE_QUEUE /* save it up for later. */
219};
220
221/*
222 * Statistics.
223 */
224#if PPP_STATS_SUPPORT
225struct pppstat {
226 unsigned int ppp_ibytes; /* bytes received */
227 unsigned int ppp_ipackets; /* packets received */
228 unsigned int ppp_ierrors; /* receive errors */
229 unsigned int ppp_obytes; /* bytes sent */
230 unsigned int ppp_opackets; /* packets sent */
231 unsigned int ppp_oerrors; /* transmit errors */
232};
233
234#if VJ_SUPPORT
235struct vjstat {
236 unsigned int vjs_packets; /* outbound packets */
237 unsigned int vjs_compressed; /* outbound compressed packets */
238 unsigned int vjs_searches; /* searches for connection state */
239 unsigned int vjs_misses; /* times couldn't find conn. state */
240 unsigned int vjs_uncompressedin; /* inbound uncompressed packets */
241 unsigned int vjs_compressedin; /* inbound compressed packets */
242 unsigned int vjs_errorin; /* inbound unknown type packets */
243 unsigned int vjs_tossed; /* inbound packets tossed because of error */
244};
245#endif /* VJ_SUPPORT */
246
247struct ppp_stats {
248 struct pppstat p; /* basic PPP statistics */
249#if VJ_SUPPORT
250 struct vjstat vj; /* VJ header compression statistics */
251#endif /* VJ_SUPPORT */
252};
253
254#if CCP_SUPPORT
255struct compstat {
256 unsigned int unc_bytes; /* total uncompressed bytes */
257 unsigned int unc_packets; /* total uncompressed packets */
258 unsigned int comp_bytes; /* compressed bytes */
259 unsigned int comp_packets; /* compressed packets */
260 unsigned int inc_bytes; /* incompressible bytes */
261 unsigned int inc_packets; /* incompressible packets */
262 unsigned int ratio; /* recent compression ratio << 8 */
263};
264
265struct ppp_comp_stats {
266 struct compstat c; /* packet compression statistics */
267 struct compstat d; /* packet decompression statistics */
268};
269#endif /* CCP_SUPPORT */
270
271#endif /* PPP_STATS_SUPPORT */
272
273#if PPP_IDLETIMELIMIT
274/*
275 * The following structure records the time in seconds since
276 * the last NP packet was sent or received.
277 */
278struct ppp_idle {
279 time_t xmit_idle; /* time since last NP packet sent */
280 time_t recv_idle; /* time since last NP packet received */
281};
282#endif /* PPP_IDLETIMELIMIT */
283
284/* values for epdisc.class */
285#define EPD_NULL 0 /* null discriminator, no data */
286#define EPD_LOCAL 1
287#define EPD_IP 2
288#define EPD_MAC 3
289#define EPD_MAGIC 4
290#define EPD_PHONENUM 5
291
292/*
293 * Global variables.
294 */
295#ifdef HAVE_MULTILINK
296extern u8_t multilink; /* enable multilink operation */
297extern u8_t doing_multilink;
298extern u8_t multilink_master;
299extern u8_t bundle_eof;
300extern u8_t bundle_terminating;
301#endif
302
303#ifdef MAXOCTETS
304extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */
305extern int maxoctets_dir; /* Direction :
306 0 - in+out (default)
307 1 - in
308 2 - out
309 3 - max(in,out) */
310extern int maxoctets_timeout; /* Timeout for check of octets limit */
311#define PPP_OCTETS_DIRECTION_SUM 0
312#define PPP_OCTETS_DIRECTION_IN 1
313#define PPP_OCTETS_DIRECTION_OUT 2
314#define PPP_OCTETS_DIRECTION_MAXOVERAL 3
315/* same as previos, but little different on RADIUS side */
316#define PPP_OCTETS_DIRECTION_MAXSESSION 4
317#endif
318
319/* Data input may be used by CCP and ECP, remove this entry
320 * from struct protent to save some flash
321 */
322#define PPP_DATAINPUT 0
323
324/*
325 * The following struct gives the addresses of procedures to call
326 * for a particular protocol.
327 */
328struct protent {
329 u_short protocol; /* PPP protocol number */
330 /* Initialization procedure */
331 void (*init) (ppp_pcb *pcb);
332 /* Process a received packet */
333 void (*input) (ppp_pcb *pcb, u_char *pkt, int len);
334 /* Process a received protocol-reject */
335 void (*protrej) (ppp_pcb *pcb);
336 /* Lower layer has come up */
337 void (*lowerup) (ppp_pcb *pcb);
338 /* Lower layer has gone down */
339 void (*lowerdown) (ppp_pcb *pcb);
340 /* Open the protocol */
341 void (*open) (ppp_pcb *pcb);
342 /* Close the protocol */
343 void (*close) (ppp_pcb *pcb, const char *reason);
344#if PRINTPKT_SUPPORT
345 /* Print a packet in readable form */
346 int (*printpkt) (const u_char *pkt, int len,
347 void (*printer) (void *, const char *, ...),
348 void *arg);
349#endif /* PRINTPKT_SUPPORT */
350#if PPP_DATAINPUT
351 /* Process a received data packet */
352 void (*datainput) (ppp_pcb *pcb, u_char *pkt, int len);
353#endif /* PPP_DATAINPUT */
354#if PRINTPKT_SUPPORT
355 const char *name; /* Text name of protocol */
356 const char *data_name; /* Text name of corresponding data protocol */
357#endif /* PRINTPKT_SUPPORT */
358#if PPP_OPTIONS
359 option_t *options; /* List of command-line options */
360 /* Check requested options, assign defaults */
361 void (*check_options) (void);
362#endif /* PPP_OPTIONS */
363#if DEMAND_SUPPORT
364 /* Configure interface for demand-dial */
365 int (*demand_conf) (int unit);
366 /* Say whether to bring up link for this pkt */
367 int (*active_pkt) (u_char *pkt, int len);
368#endif /* DEMAND_SUPPORT */
369};
370
371/* Table of pointers to supported protocols */
372extern const struct protent* const protocols[];
373
374
375/* Values for auth_pending, auth_done */
376#if PAP_SUPPORT
377#define PAP_WITHPEER 0x1
378#define PAP_PEER 0x2
379#endif /* PAP_SUPPORT */
380#if CHAP_SUPPORT
381#define CHAP_WITHPEER 0x4
382#define CHAP_PEER 0x8
383#endif /* CHAP_SUPPORT */
384#if EAP_SUPPORT
385#define EAP_WITHPEER 0x10
386#define EAP_PEER 0x20
387#endif /* EAP_SUPPORT */
388
389/* Values for auth_done only */
390#if CHAP_SUPPORT
391#define CHAP_MD5_WITHPEER 0x40
392#define CHAP_MD5_PEER 0x80
393#if MSCHAP_SUPPORT
394#define CHAP_MS_SHIFT 8 /* LSB position for MS auths */
395#define CHAP_MS_WITHPEER 0x100
396#define CHAP_MS_PEER 0x200
397#define CHAP_MS2_WITHPEER 0x400
398#define CHAP_MS2_PEER 0x800
399#endif /* MSCHAP_SUPPORT */
400#endif /* CHAP_SUPPORT */
401
402/* Supported CHAP protocols */
403#if CHAP_SUPPORT
404
405#if MSCHAP_SUPPORT
406#define CHAP_MDTYPE_SUPPORTED (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5)
407#else /* MSCHAP_SUPPORT */
408#define CHAP_MDTYPE_SUPPORTED (MDTYPE_MD5)
409#endif /* MSCHAP_SUPPORT */
410
411#else /* CHAP_SUPPORT */
412#define CHAP_MDTYPE_SUPPORTED (MDTYPE_NONE)
413#endif /* CHAP_SUPPORT */
414
415#if PPP_STATS_SUPPORT
416/*
417 * PPP statistics structure
418 */
419struct pppd_stats {
420 unsigned int bytes_in;
421 unsigned int bytes_out;
422 unsigned int pkts_in;
423 unsigned int pkts_out;
424};
425#endif /* PPP_STATS_SUPPORT */
426
427
428/*
429 * PPP private functions
430 */
431
432
433/*
434 * Functions called from stack core.
435 */
436
437/* initialize the PPP subsystem */
438int ppp_init(void);
439
440/*
441 * Functions called from PPP link protocols.
442 */
443
444/* Create a new PPP control block */
445ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, void *link_ctx_cb,
446 ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
447
448/* Initiate LCP open request */
449void ppp_start(ppp_pcb *pcb);
450
451/* Called when link failed to setup */
452void ppp_link_failed(ppp_pcb *pcb);
453
454/* Called when link is normally down (i.e. it was asked to end) */
455void ppp_link_end(ppp_pcb *pcb);
456
457/* function called to process input packet */
458void ppp_input(ppp_pcb *pcb, struct pbuf *pb);
459
460
461/*
462 * Functions called by PPP protocols.
463 */
464
465/* function called by all PPP subsystems to send packets */
466err_t ppp_write(ppp_pcb *pcb, struct pbuf *p);
467
468/* functions called by auth.c link_terminated() */
469void ppp_link_terminated(ppp_pcb *pcb);
470
471void new_phase(ppp_pcb *pcb, int p);
472
473int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp);
474int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp);
475
476#if PPP_IPV4_SUPPORT
477int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask);
478int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr);
479#if 0 /* UNUSED - PROXY ARP */
480int sifproxyarp(ppp_pcb *pcb, u32_t his_adr);
481int cifproxyarp(ppp_pcb *pcb, u32_t his_adr);
482#endif /* UNUSED - PROXY ARP */
483#if PPP_DNS
484int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2);
485int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2);
486#endif /* PPP_DNS */
487#if VJ_SUPPORT
488int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid);
489#endif /* VJ_SUPPORT */
490int sifup(ppp_pcb *pcb);
491int sifdown (ppp_pcb *pcb);
492u32_t get_mask(u32_t addr);
493#endif /* PPP_IPV4_SUPPORT */
494
495#if PPP_IPV6_SUPPORT
496int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
497int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
498int sif6up(ppp_pcb *pcb);
499int sif6down (ppp_pcb *pcb);
500#endif /* PPP_IPV6_SUPPORT */
501
502#if DEMAND_SUPPORT
503int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode);
504#endif /* DEMAND_SUPPORt */
505
506void netif_set_mtu(ppp_pcb *pcb, int mtu);
507int netif_get_mtu(ppp_pcb *pcb);
508
509#if CCP_SUPPORT
510#if 0 /* unused */
511int ccp_test(ppp_pcb *pcb, u_char *opt_ptr, int opt_len, int for_transmit);
512#endif /* unused */
513void ccp_set(ppp_pcb *pcb, u8_t isopen, u8_t isup, u8_t receive_method, u8_t transmit_method);
514void ccp_reset_comp(ppp_pcb *pcb);
515void ccp_reset_decomp(ppp_pcb *pcb);
516#if 0 /* unused */
517int ccp_fatal_error(ppp_pcb *pcb);
518#endif /* unused */
519#endif /* CCP_SUPPORT */
520
521#if PPP_IDLETIMELIMIT
522int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip);
523#endif /* PPP_IDLETIMELIMIT */
524
525#if DEMAND_SUPPORT
526int get_loop_output(void);
527#endif /* DEMAND_SUPPORT */
528
529/* Optional protocol names list, to make our messages a little more informative. */
530#if PPP_PROTOCOLNAME
531const char * protocol_name(int proto);
532#endif /* PPP_PROTOCOLNAME */
533
534/* Optional stats support, to get some statistics on the PPP interface */
535#if PPP_STATS_SUPPORT
536void print_link_stats(void); /* Print stats, if available */
537void reset_link_stats(int u); /* Reset (init) stats when link goes up */
538void update_link_stats(int u); /* Get stats at link termination */
539#endif /* PPP_STATS_SUPPORT */
540
541
542
543/*
544 * Inline versions of get/put char/short/long.
545 * Pointer is advanced; we assume that both arguments
546 * are lvalues and will already be in registers.
547 * cp MUST be u_char *.
548 */
549#define GETCHAR(c, cp) { \
550 (c) = *(cp)++; \
551}
552#define PUTCHAR(c, cp) { \
553 *(cp)++ = (u_char) (c); \
554}
555#define GETSHORT(s, cp) { \
556 (s) = *(cp)++ << 8; \
557 (s) |= *(cp)++; \
558}
559#define PUTSHORT(s, cp) { \
560 *(cp)++ = (u_char) ((s) >> 8); \
561 *(cp)++ = (u_char) (s); \
562}
563#define GETLONG(l, cp) { \
564 (l) = *(cp)++ << 8; \
565 (l) |= *(cp)++; (l) <<= 8; \
566 (l) |= *(cp)++; (l) <<= 8; \
567 (l) |= *(cp)++; \
568}
569#define PUTLONG(l, cp) { \
570 *(cp)++ = (u_char) ((l) >> 24); \
571 *(cp)++ = (u_char) ((l) >> 16); \
572 *(cp)++ = (u_char) ((l) >> 8); \
573 *(cp)++ = (u_char) (l); \
574}
575
576#define INCPTR(n, cp) ((cp) += (n))
577#define DECPTR(n, cp) ((cp) -= (n))
578
579#define BZERO(s, n) memset(s, 0, n)
580#define BCMP(s1, s2, l) memcmp(s1, s2, l)
581
582#define PRINTMSG(m, l) { ppp_info("Remote message: %0.*v", l, m); }
583
584/*
585 * MAKEHEADER - Add Header fields to a packet.
586 */
587#define MAKEHEADER(p, t) { \
588 PUTCHAR(PPP_ALLSTATIONS, p); \
589 PUTCHAR(PPP_UI, p); \
590 PUTSHORT(t, p); }
591
592/* Procedures exported from auth.c */
593void link_required(ppp_pcb *pcb); /* we are starting to use the link */
594void link_terminated(ppp_pcb *pcb); /* we are finished with the link */
595void link_down(ppp_pcb *pcb); /* the LCP layer has left the Opened state */
596void upper_layers_down(ppp_pcb *pcb); /* take all NCPs down */
597void link_established(ppp_pcb *pcb); /* the link is up; authenticate now */
598void start_networks(ppp_pcb *pcb); /* start all the network control protos */
599void continue_networks(ppp_pcb *pcb); /* start network [ip, etc] control protos */
600#if PPP_AUTH_SUPPORT
601#if PPP_SERVER
602int auth_check_passwd(ppp_pcb *pcb, char *auser, int userlen, char *apasswd, int passwdlen, const char **msg, int *msglen);
603 /* check the user name and passwd against configuration */
604void auth_peer_fail(ppp_pcb *pcb, int protocol);
605 /* peer failed to authenticate itself */
606void auth_peer_success(ppp_pcb *pcb, int protocol, int prot_flavor, const char *name, int namelen);
607 /* peer successfully authenticated itself */
608#endif /* PPP_SERVER */
609void auth_withpeer_fail(ppp_pcb *pcb, int protocol);
610 /* we failed to authenticate ourselves */
611void auth_withpeer_success(ppp_pcb *pcb, int protocol, int prot_flavor);
612 /* we successfully authenticated ourselves */
613#endif /* PPP_AUTH_SUPPORT */
614void np_up(ppp_pcb *pcb, int proto); /* a network protocol has come up */
615void np_down(ppp_pcb *pcb, int proto); /* a network protocol has gone down */
616void np_finished(ppp_pcb *pcb, int proto); /* a network protocol no longer needs link */
617#if PPP_AUTH_SUPPORT
618int get_secret(ppp_pcb *pcb, const char *client, const char *server, char *secret, int *secret_len, int am_server);
619 /* get "secret" for chap */
620#endif /* PPP_AUTH_SUPPORT */
621
622/* Procedures exported from ipcp.c */
623/* int parse_dotted_ip (char *, u32_t *); */
624
625/* Procedures exported from demand.c */
626#if DEMAND_SUPPORT
627void demand_conf (void); /* config interface(s) for demand-dial */
628void demand_block (void); /* set all NPs to queue up packets */
629void demand_unblock (void); /* set all NPs to pass packets */
630void demand_discard (void); /* set all NPs to discard packets */
631void demand_rexmit (int, u32_t); /* retransmit saved frames for an NP*/
632int loop_chars (unsigned char *, int); /* process chars from loopback */
633int loop_frame (unsigned char *, int); /* should we bring link up? */
634#endif /* DEMAND_SUPPORT */
635
636/* Procedures exported from multilink.c */
637#ifdef HAVE_MULTILINK
638void mp_check_options (void); /* Check multilink-related options */
639int mp_join_bundle (void); /* join our link to an appropriate bundle */
640void mp_exit_bundle (void); /* have disconnected our link from bundle */
641void mp_bundle_terminated (void);
642char *epdisc_to_str (struct epdisc *); /* string from endpoint discrim. */
643int str_to_epdisc (struct epdisc *, char *); /* endpt disc. from str */
644#else
645#define mp_bundle_terminated() /* nothing */
646#define mp_exit_bundle() /* nothing */
647#define doing_multilink 0
648#define multilink_master 0
649#endif
650
651#if PPP_DEBUG
652
653/* Procedures exported from utils.c. */
654void ppp_print_string(const u_char *p, int len, void (*printer) (void *, const char *, ...), void *arg); /* Format a string for output */
655int ppp_slprintf(char *buf, int buflen, const char *fmt, ...); /* sprintf++ */
656int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args); /* vsprintf++ */
657size_t ppp_strlcpy(char *dest, const char *src, size_t len); /* safe strcpy */
658size_t ppp_strlcat(char *dest, const char *src, size_t len); /* safe strncpy */
659void ppp_dbglog(const char *fmt, ...); /* log a debug message */
660void ppp_info(const char *fmt, ...); /* log an informational message */
661void ppp_notice(const char *fmt, ...); /* log a notice-level message */
662void ppp_warn(const char *fmt, ...); /* log a warning message */
663void ppp_error(const char *fmt, ...); /* log an error message */
664void ppp_fatal(const char *fmt, ...); /* log an error message and die(1) */
665#if PRINTPKT_SUPPORT
666void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len);
667 /* dump packet to debug log if interesting */
668#endif /* PRINTPKT_SUPPORT */
669
670#else
671
672#define ppp_print_string(...)
673#define ppp_slprintf(...)
674#define ppp_vslprintf(...)
675#define ppp_strlcpy(...)
676#define ppp_strlcat(...)
677#define ppp_dbglog(...)
678#define ppp_info(...)
679#define ppp_notice(...)
680#define ppp_warn(...)
681#define ppp_error(...)
682#define ppp_fatal(...)
683
684#endif /* PPP_DEBUG */
685
686/*
687 * Number of necessary timers analysis.
688 *
689 * PPP use at least one timer per each of its protocol, but not all protocols are
690 * active at the same time, thus the number of necessary timeouts is actually
691 * lower than enabled protocols. Here is the actual necessary timeouts based
692 * on code analysis.
693 *
694 * Note that many features analysed here are not working at all and are only
695 * there for a comprehensive analysis of necessary timers in order to prevent
696 * having to redo that each time we add a feature.
697 *
698 * Timer list
699 *
700 * | holdoff timeout
701 * | low level protocol timeout (PPPoE or PPPoL2P)
702 * | LCP delayed UP
703 * | LCP retransmit (FSM)
704 * | LCP Echo timer
705 * .| PAP or CHAP or EAP authentication
706 * . | ECP retransmit (FSM)
707 * . | CCP retransmit (FSM) when MPPE is enabled
708 * . | CCP retransmit (FSM) when MPPE is NOT enabled
709 * . | IPCP retransmit (FSM)
710 * . .| IP6CP retransmit (FSM)
711 * . . | Idle time limit
712 * . . | Max connect time
713 * . . | Max octets
714 * . . | CCP RACK timeout
715 * . . .
716 * PPP_PHASE_DEAD
717 * PPP_PHASE_HOLDOFF
718 * | . . .
719 * PPP_PHASE_INITIALIZE
720 * | . . .
721 * PPP_PHASE_ESTABLISH
722 * | . . .
723 * |. . .
724 * | . .
725 * PPP_PHASE_AUTHENTICATE
726 * | . .
727 * || . .
728 * PPP_PHASE_NETWORK
729 * | || . .
730 * | ||| .
731 * PPP_PHASE_RUNNING
732 * | .|||||
733 * | . ||||
734 * PPP_PHASE_TERMINATE
735 * | . ||||
736 * PPP_PHASE_NETWORK
737 * |. .
738 * PPP_PHASE_ESTABLISH
739 * PPP_PHASE_DISCONNECT
740 * PPP_PHASE_DEAD
741 *
742 * Alright, PPP basic retransmission and LCP Echo consume one timer.
743 * 1
744 *
745 * If authentication is enabled one timer is necessary during authentication.
746 * 1 + PPP_AUTH_SUPPORT
747 *
748 * If ECP is enabled one timer is necessary before IPCP and/or IP6CP, one more
749 * is necessary if CCP is enabled (only with MPPE support but we don't care much
750 * up to this detail level).
751 * 1 + ECP_SUPPORT + CCP_SUPPORT
752 *
753 * If CCP is enabled it might consume a timer during IPCP or IP6CP, thus
754 * we might use IPCP, IP6CP and CCP timers simultaneously.
755 * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT
756 *
757 * When entering running phase, IPCP or IP6CP is still running. If idle time limit
758 * is enabled one more timer is necessary. Same for max connect time and max
759 * octets features. Furthermore CCP RACK might be used past this point.
760 * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT
761 *
762 * IPv4 or IPv6 must be enabled, therefore we don't need to take care the authentication
763 * and the CCP + ECP case, thus reducing overall complexity.
764 * 1 + PPP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT)
765 *
766 * We don't support PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS features
767 * and adding those defines to ppp_opts.h just for having the value always
768 * defined to 0 isn't worth it.
769 * 1 + PPP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + CCP_SUPPORT)
770 *
771 * Thus, the following is enough for now.
772 * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT
773 */
774
775#ifdef __cplusplus
776}
777#endif
778
779#endif /* PPP_SUPPORT */
780#endif /* PPP_IMPL_H */