44 #ifdef PPP_INCLUDE_SETTINGS_HEADER 45 #include "ppp_settings.h" 64 #define LITTLE_ENDIAN 1234 68 #define BIG_ENDIAN 4321 72 #define BYTE_ORDER LITTLE_ENDIAN 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)) 86 u16_t ppp_htons(u16_t x);
88 #define ppp_ntohs(x) ppp_htons(x) 91 u32_t ppp_htonl(u32_t x);
93 #define ppp_ntohl(x) ppp_htonl(x) 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) 114 #define PPP_CTRL_PBUF_TYPE PBUF_RAM 115 #define PPP_CTRL_PBUF_MAX_SIZE 512 117 #define PPP_CTRL_PBUF_TYPE PBUF_POOL 118 #define PPP_CTRL_PBUF_MAX_SIZE PBUF_POOL_BUFSIZE 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]) 131 #define PPP_ALLSTATIONS 0xff 133 #define PPP_FLAG 0x7e 134 #define PPP_ESCAPE 0x7d 135 #define PPP_TRANS 0x20 146 #define PPP_VJC_COMP 0x2d 147 #define PPP_VJC_UNCOMP 0x2f 150 #define PPP_IPV6 0x57 153 #define PPP_COMP 0xfd 155 #define PPP_IPCP 0x8021 157 #define PPP_ATCP 0x8029 158 #define PPP_IPXCP 0x802b 161 #define PPP_IPV6CP 0x8057 164 #define PPP_CCP 0x80fd 167 #define PPP_ECP 0x8053 169 #define PPP_LCP 0xc021 171 #define PPP_PAP 0xc023 174 #define PPP_LQR 0xc025 177 #define PPP_CHAP 0xc223 180 #define PPP_CBCP 0xc029 183 #define PPP_EAP 0xc227 190 struct link_callbacks {
192 void (*connect) (ppp_pcb *pcb,
void *ctx);
195 void (*listen) (ppp_pcb *pcb,
void *ctx);
198 void (*disconnect) (ppp_pcb *pcb,
void *ctx);
200 err_t (*free) (ppp_pcb *pcb,
void *ctx);
202 err_t (*write)(ppp_pcb *pcb,
void *ctx,
struct pbuf *p);
204 err_t (*netif_output)(ppp_pcb *pcb,
void *ctx,
struct pbuf *p, u_short protocol);
206 void (*send_config)(ppp_pcb *pcb,
void *ctx, u32_t accm,
int pcomp,
int accomp);
208 void (*recv_config)(ppp_pcb *pcb,
void *ctx, u32_t accm,
int pcomp,
int accomp);
224 #if PPP_STATS_SUPPORT 226 unsigned int ppp_ibytes;
227 unsigned int ppp_ipackets;
228 unsigned int ppp_ierrors;
229 unsigned int ppp_obytes;
230 unsigned int ppp_opackets;
231 unsigned int ppp_oerrors;
236 unsigned int vjs_packets;
237 unsigned int vjs_compressed;
238 unsigned int vjs_searches;
239 unsigned int vjs_misses;
240 unsigned int vjs_uncompressedin;
241 unsigned int vjs_compressedin;
242 unsigned int vjs_errorin;
243 unsigned int vjs_tossed;
256 unsigned int unc_bytes;
257 unsigned int unc_packets;
258 unsigned int comp_bytes;
259 unsigned int comp_packets;
260 unsigned int inc_bytes;
261 unsigned int inc_packets;
265 struct ppp_comp_stats {
273 #if PPP_IDLETIMELIMIT 290 #define EPD_PHONENUM 5 295 #ifdef HAVE_MULTILINK 296 extern u8_t multilink;
297 extern u8_t doing_multilink;
298 extern u8_t multilink_master;
299 extern u8_t bundle_eof;
300 extern u8_t bundle_terminating;
304 extern unsigned int maxoctets;
305 extern int maxoctets_dir;
310 extern int maxoctets_timeout;
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 316 #define PPP_OCTETS_DIRECTION_MAXSESSION 4 322 #define PPP_DATAINPUT 0 331 void (*init) (ppp_pcb *pcb);
333 void (*input) (ppp_pcb *pcb, u_char *pkt,
int len);
335 void (*protrej) (ppp_pcb *pcb);
337 void (*lowerup) (ppp_pcb *pcb);
339 void (*lowerdown) (ppp_pcb *pcb);
341 void (*open) (ppp_pcb *pcb);
343 void (*close) (ppp_pcb *pcb,
const char *reason);
346 int (*printpkt) (
const u_char *pkt,
int len,
347 void (*printer) (
void *,
const char *, ...),
352 void (*datainput) (ppp_pcb *pcb, u_char *pkt,
int len);
356 const char *data_name;
361 void (*check_options) (void);
365 int (*demand_conf) (
int unit);
367 int (*active_pkt) (u_char *pkt,
int len);
372 extern const struct protent*
const protocols[];
377 #define PAP_WITHPEER 0x1 381 #define CHAP_WITHPEER 0x4 382 #define CHAP_PEER 0x8 385 #define EAP_WITHPEER 0x10 386 #define EAP_PEER 0x20 391 #define CHAP_MD5_WITHPEER 0x40 392 #define CHAP_MD5_PEER 0x80 394 #define CHAP_MS_SHIFT 8 395 #define CHAP_MS_WITHPEER 0x100 396 #define CHAP_MS_PEER 0x200 397 #define CHAP_MS2_WITHPEER 0x400 398 #define CHAP_MS2_PEER 0x800 406 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5) 408 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_MD5) 412 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_NONE) 415 #if PPP_STATS_SUPPORT 420 unsigned int bytes_in;
421 unsigned int bytes_out;
422 unsigned int pkts_in;
423 unsigned int pkts_out;
445 ppp_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);
449 void ppp_start(ppp_pcb *pcb);
452 void ppp_link_failed(ppp_pcb *pcb);
455 void ppp_link_end(ppp_pcb *pcb);
458 void ppp_input(ppp_pcb *pcb,
struct pbuf *pb);
466 err_t ppp_write(ppp_pcb *pcb,
struct pbuf *p);
469 void ppp_link_terminated(ppp_pcb *pcb);
471 void new_phase(ppp_pcb *pcb,
int p);
473 int ppp_send_config(ppp_pcb *pcb,
int mtu, u32_t accm,
int pcomp,
int accomp);
474 int ppp_recv_config(ppp_pcb *pcb,
int mru, u32_t accm,
int pcomp,
int accomp);
477 int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask);
478 int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr);
480 int sifproxyarp(ppp_pcb *pcb, u32_t his_adr);
481 int cifproxyarp(ppp_pcb *pcb, u32_t his_adr);
484 int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2);
485 int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2);
488 int sifvjcomp(ppp_pcb *pcb,
int vjcomp,
int cidcomp,
int maxcid);
490 int sifup(ppp_pcb *pcb);
491 int sifdown (ppp_pcb *pcb);
492 u32_t get_mask(u32_t addr);
496 int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
497 int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
498 int sif6up(ppp_pcb *pcb);
499 int sif6down (ppp_pcb *pcb);
503 int sifnpmode(ppp_pcb *pcb,
int proto,
enum NPmode mode);
506 void netif_set_mtu(ppp_pcb *pcb,
int mtu);
507 int netif_get_mtu(ppp_pcb *pcb);
511 int ccp_test(ppp_pcb *pcb, u_char *opt_ptr,
int opt_len,
int for_transmit);
513 void ccp_set(ppp_pcb *pcb, u8_t isopen, u8_t isup, u8_t receive_method, u8_t transmit_method);
514 void ccp_reset_comp(ppp_pcb *pcb);
515 void ccp_reset_decomp(ppp_pcb *pcb);
517 int ccp_fatal_error(ppp_pcb *pcb);
521 #if PPP_IDLETIMELIMIT 522 int get_idle_time(ppp_pcb *pcb,
struct ppp_idle *ip);
526 int get_loop_output(
void);
531 const char * protocol_name(
int proto);
535 #if PPP_STATS_SUPPORT 536 void print_link_stats(
void);
537 void reset_link_stats(
int u);
538 void update_link_stats(
int u);
549 #define GETCHAR(c, cp) { \ 552 #define PUTCHAR(c, cp) { \ 553 *(cp)++ = (u_char) (c); \ 555 #define GETSHORT(s, cp) { \ 556 (s) = *(cp)++ << 8; \ 559 #define PUTSHORT(s, cp) { \ 560 *(cp)++ = (u_char) ((s) >> 8); \ 561 *(cp)++ = (u_char) (s); \ 563 #define GETLONG(l, cp) { \ 564 (l) = *(cp)++ << 8; \ 565 (l) |= *(cp)++; (l) <<= 8; \ 566 (l) |= *(cp)++; (l) <<= 8; \ 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); \ 576 #define INCPTR(n, cp) ((cp) += (n)) 577 #define DECPTR(n, cp) ((cp) -= (n)) 579 #define BZERO(s, n) memset(s, 0, n) 580 #define BCMP(s1, s2, l) memcmp(s1, s2, l) 582 #define PRINTMSG(m, l) { ppp_info("Remote message: %0.*v", l, m); } 587 #define MAKEHEADER(p, t) { \ 588 PUTCHAR(PPP_ALLSTATIONS, p); \ 589 PUTCHAR(PPP_UI, p); \ 593 void link_required(ppp_pcb *pcb);
594 void link_terminated(ppp_pcb *pcb);
595 void link_down(ppp_pcb *pcb);
596 void upper_layers_down(ppp_pcb *pcb);
597 void link_established(ppp_pcb *pcb);
598 void start_networks(ppp_pcb *pcb);
599 void continue_networks(ppp_pcb *pcb);
602 int auth_check_passwd(ppp_pcb *pcb,
char *auser,
int userlen,
char *apasswd,
int passwdlen,
const char **msg,
int *msglen);
604 void auth_peer_fail(ppp_pcb *pcb,
int protocol);
606 void auth_peer_success(ppp_pcb *pcb,
int protocol,
int prot_flavor,
const char *name,
int namelen);
609 void auth_withpeer_fail(ppp_pcb *pcb,
int protocol);
611 void auth_withpeer_success(ppp_pcb *pcb,
int protocol,
int prot_flavor);
614 void np_up(ppp_pcb *pcb,
int proto);
615 void np_down(ppp_pcb *pcb,
int proto);
616 void np_finished(ppp_pcb *pcb,
int proto);
618 int get_secret(ppp_pcb *pcb,
const char *client,
const char *server,
char *secret,
int *secret_len,
int am_server);
627 void demand_conf (
void);
628 void demand_block (
void);
629 void demand_unblock (
void);
630 void demand_discard (
void);
631 void demand_rexmit (
int, u32_t);
632 int loop_chars (
unsigned char *,
int);
633 int loop_frame (
unsigned char *,
int);
637 #ifdef HAVE_MULTILINK 638 void mp_check_options (
void);
639 int mp_join_bundle (
void);
640 void mp_exit_bundle (
void);
641 void mp_bundle_terminated (
void);
642 char *epdisc_to_str (
struct epdisc *);
643 int str_to_epdisc (
struct epdisc *,
char *);
645 #define mp_bundle_terminated() 646 #define mp_exit_bundle() 647 #define doing_multilink 0 648 #define multilink_master 0 652 void ppp_print_string(
const u_char *p,
int len,
void (*printer) (
void *,
const char *, ...),
void *arg);
653 int ppp_slprintf(
char *buf,
int buflen,
const char *fmt, ...);
654 int ppp_vslprintf(
char *buf,
int buflen,
const char *fmt, va_list args);
655 size_t ppp_strlcpy(
char *dest,
const char *src,
size_t len);
656 size_t ppp_strlcat(
char *dest,
const char *src,
size_t len);
657 void ppp_dbglog(
const char *fmt, ...);
658 void ppp_info(
const char *fmt, ...);
659 void ppp_notice(
const char *fmt, ...);
660 void ppp_warn(
const char *fmt, ...);
661 void ppp_error(
const char *fmt, ...);
662 void ppp_fatal(
const char *fmt, ...);
664 void ppp_dump_packet(ppp_pcb *pcb,
const char *tag,
unsigned char *p,
int len);