# BRCM_VERSION=3
[bcm963xx.git] / userapps / opensource / ppp / pppoe / pppd.h
1 /*
2  * pppd.h - PPP daemon global declarations.
3  *
4  * Copyright (c) 1989 Carnegie Mellon University.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are permitted
8  * provided that the above copyright notice and this paragraph are
9  * duplicated in all such forms and that any documentation,
10  * advertising materials, and other materials related to such
11  * distribution and use acknowledge that the software was developed
12  * by Carnegie Mellon University.  The name of the
13  * University may not be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * $Id: pppd.h,v 1.59 2001/03/12 22:58:59 paulus Exp $
20  */
21
22 /*
23  * TODO:
24  */
25
26 #ifndef __PPPD_H__
27 #define __PPPD_H__
28
29 #include <stdio.h>              /* for FILE */
30 #include <limits.h>             /* for NGROUPS_MAX */
31 #include <sys/param.h>          /* for MAXPATHLEN and BSD4_4, if defined */
32 #include <sys/types.h>          /* for u_int32_t, if defined */
33 #include <sys/time.h>           /* for struct timeval */
34 #include <net/ppp_defs.h>
35 #include "patchlevel.h"
36
37 #if defined(__STDC__)
38 #include <stdarg.h>
39 #define __V(x)  x
40 #else
41 #include <varargs.h>
42 #define __V(x)  (va_alist) va_dcl
43 #define const
44 #define volatile
45 #endif
46
47 #ifdef INET6
48 #include "eui64.h"
49 #endif
50
51 /*
52  * Limits.
53  */
54
55 // brcm
56 #ifdef MAXPATHLEN
57 #undef MAXPATHLEN
58 #endif
59 #define MAXPATHLEN      64
60
61 #define NUM_PPP         1       /* One PPP interface supported (per process) */
62 #define MAXWORDLEN      1024    /* max length of word in file (incl null) */
63 #define MAXARGS         1       /* max # args to a command */
64 #define MAXNAMELEN      256     /* max length of hostname or name for auth */
65 #define MAXSECRETLEN    256     /* max length of password or secret */
66 #define MAXSRVNAMELEN   256
67 /*
68  * Option descriptor structure.
69  */
70
71 typedef unsigned char   bool;
72
73 enum opt_type {
74         o_special_noarg = 0,
75         o_special = 1,
76         o_bool,
77         o_int,
78         o_uint32,
79         o_string,
80         o_wild,
81 };
82
83 typedef struct {
84         char    *name;          /* name of the option */
85         enum opt_type type;
86         void    *addr;
87         char    *description;
88         int     flags;
89         void    *addr2;
90         int     upper_limit;
91         int     lower_limit;
92         const char *source;
93         short int priority;
94         short int winner;
95 } option_t;
96
97 /* Values for flags */
98 #define OPT_VALUE       0xff    /* mask for presupplied value */
99 #define OPT_HEX         0x100   /* int option is in hex */
100 #define OPT_NOARG       0x200   /* option doesn't take argument */
101 #define OPT_OR          0x400   /* OR in argument to value */
102 #define OPT_INC         0x800   /* increment value */
103 #define OPT_PRIV        0x1000  /* privileged option */
104 #define OPT_STATIC      0x2000  /* string option goes into static array */
105 #define OPT_LLIMIT      0x4000  /* check value against lower limit */
106 #define OPT_ULIMIT      0x8000  /* check value against upper limit */
107 #define OPT_LIMITS      (OPT_LLIMIT|OPT_ULIMIT)
108 #define OPT_ZEROOK      0x10000 /* 0 value is OK even if not within limits */
109 #define OPT_HIDE        0x10000 /* for o_string, print value as ?????? */
110 #define OPT_A2LIST      0x10000 /* for o_special, keep list of values */
111 #define OPT_NOINCR      0x20000 /* value mustn't be increased */
112 #define OPT_ZEROINF     0x40000 /* with OPT_NOINCR, 0 == infinity */
113 #define OPT_PRIO        0x80000 /* process option priorities for this option */
114 #define OPT_PRIOSUB     0x100000 /* subsidiary member of priority group */
115 #define OPT_ALIAS       0x200000 /* option is alias for previous option */
116 #define OPT_A2COPY      0x400000 /* addr2 -> second location to rcv value */
117 #define OPT_ENABLE      0x800000 /* use *addr2 as enable for option */
118 #define OPT_A2CLR       0x1000000 /* clear *(bool *)addr2 */
119 #define OPT_PRIVFIX     0x2000000 /* user can't override if set by root */
120 #define OPT_INITONLY    0x4000000 /* option can only be set in init phase */
121 #define OPT_DEVEQUIV    0x8000000 /* equiv to device name */
122 #define OPT_DEVNAM      (OPT_INITONLY | OPT_DEVEQUIV)
123 #define OPT_A2PRINTER   0x10000000 /* *addr2 is a fn for printing option */
124 #define OPT_A2STRVAL    0x20000000 /* *addr2 points to current string value */
125 #define OPT_NOPRINT     0x40000000 /* don't print this option at all */
126
127 #define OPT_VAL(x)      ((x) & OPT_VALUE)
128
129 /* Values for priority */
130 #define OPRIO_DEFAULT   0       /* a default value */
131 #define OPRIO_CFGFILE   1       /* value from a configuration file */
132 #define OPRIO_CMDLINE   2       /* value from the command line */
133 #define OPRIO_SECFILE   3       /* value from options in a secrets file */
134 #define OPRIO_ROOT      100     /* added to priority if OPT_PRIVFIX && root */
135
136 #ifndef GIDSET_TYPE
137 #define GIDSET_TYPE     gid_t
138 #endif
139
140 /* Structure representing a list of permitted IP addresses. */
141 struct permitted_ip {
142     int         permit;         /* 1 = permit, 0 = forbid */
143     u_int32_t   base;           /* match if (addr & mask) == base */
144     u_int32_t   mask;           /* base and mask are in network byte order */
145 };
146
147 /*
148  * Unfortunately, the linux kernel driver uses a different structure
149  * for statistics from the rest of the ports.
150  * This structure serves as a common representation for the bits
151  * pppd needs.
152  */
153 struct pppd_stats {
154     unsigned int        bytes_in;
155     unsigned int        bytes_out;
156 };
157
158 /* Used for storing a sequence of words.  Usually malloced. */
159 struct wordlist {
160     struct wordlist     *next;
161     char                *word;
162 };
163
164 /* An endpoint discriminator, used with multilink. */
165 #define MAX_ENDP_LEN    20      /* maximum length of discriminator value */
166 struct epdisc {
167     unsigned char       class;
168     unsigned char       length;
169     unsigned char       value[MAX_ENDP_LEN];
170 };
171
172 /* values for epdisc.class */
173 #define EPD_NULL        0       /* null discriminator, no data */
174 #define EPD_LOCAL       1
175 #define EPD_IP          2
176 #define EPD_MAC         3
177 #define EPD_MAGIC       4
178 #define EPD_PHONENUM    5
179
180 typedef void (*notify_func) __P((void *, int));
181
182 struct notifier {
183     struct notifier *next;
184     notify_func     func;
185     void            *arg;
186 };
187
188 /*
189  * Global variables.
190  */
191
192 extern int      hungup;         /* Physical layer has disconnected */
193 extern int      ifunit;         /* Interface unit number */
194 extern char     ifname[];       /* Interface name */
195 extern char     hostname[];     /* Our hostname */
196 extern u_char   outpacket_buf[]; /* Buffer for outgoing packets */
197 extern int      phase;          /* Current state of link - see values below */
198 extern int      baud_rate;      /* Current link speed in bits/sec */
199 extern char     *progname;      /* Name of this program */
200 extern int      redirect_stderr;/* Connector's stderr should go to file */
201 extern char     peer_authname[];/* Authenticated name of peer */
202 extern int      privileged;     /* We were run by real-uid root */
203 extern int      need_holdoff;   /* Need holdoff period after link terminates */
204 extern char     **script_env;   /* Environment variables for scripts */
205 extern int      detached;       /* Have detached from controlling tty */
206 extern GIDSET_TYPE groups[NGROUPS_MAX]; /* groups the user is in */
207 extern int      ngroups;        /* How many groups valid in groups */
208 extern struct pppd_stats link_stats; /* byte/packet counts etc. for link */
209 extern int      link_stats_valid; /* set if link_stats is valid */
210 extern int      link_connect_time; /* time the link was up for */
211 extern int      using_pty;      /* using pty as device (notty or pty opt.) */
212 extern int      log_to_fd;      /* logging to this fd as well as syslog */
213 extern bool     log_default;    /* log_to_fd is default (stdout) */
214 extern char     *no_ppp_msg;    /* message to print if ppp not in kernel */
215 extern volatile int status;     /* exit status for pppd */
216 extern bool     devnam_fixed;   /* can no longer change devnam */
217 extern int      unsuccess;      /* # unsuccessful connection attempts */
218 extern int      do_callback;    /* set if we want to do callback next */
219 extern int      doing_callback; /* set if this is a callback */
220 extern char     ppp_devnam[MAXPATHLEN];
221 extern struct notifier *pidchange;   /* for notifications of pid changing */
222 extern struct notifier *phasechange; /* for notifications of phase changes */
223 extern struct notifier *exitnotify;  /* for notification that we're exiting */
224 extern struct notifier *sigreceived; /* notification of received signal */
225 extern int      listen_time;    /* time to listen first (ms) */
226
227 /* Values for do_callback and doing_callback */
228 #define CALLBACK_DIALIN         1       /* we are expecting the call back */
229 #define CALLBACK_DIALOUT        2       /* we are dialling out to call back */
230
231 #define OFFSET1 10
232 #define OFFSET2 100000
233
234 /*
235  * Variables set by command-line options.
236  */
237
238 /* Debug flags */
239 extern int      DEB_DISC,DEB_DISC2;
240 extern int      debug;          /* Debug flag */
241 extern int      kdebugflag;     /* Tell kernel to print debug messages */
242 extern int      default_device; /* Using /dev/tty or equivalent */
243 extern char     devnam[MAXPATHLEN];     /* Device name */
244 extern int      crtscts;        /* Use hardware flow control */
245 extern bool     modem;          /* Use modem control lines */
246 extern int      inspeed;        /* Input/Output speed requested */
247 extern u_int32_t netmask;       /* IP netmask to set on interface */
248 extern bool     lockflag;       /* Create lock file to lock the serial dev */
249 extern bool     nodetach;       /* Don't detach from controlling tty */
250 extern bool     updetach;       /* Detach from controlling tty when link up */
251 extern char     *initializer;   /* Script to initialize physical link */
252 extern char     *connect_script; /* Script to establish physical link */
253 extern char     *disconnect_script; /* Script to disestablish physical link */
254 extern char     *welcomer;      /* Script to welcome client after connection */
255 extern char     *ptycommand;    /* Command to run on other side of pty */
256 extern int      maxconnect;     /* Maximum connect time (seconds) */
257 extern char     user[MAXNAMELEN];/* Our name for authenticating ourselves */
258 extern char     passwd[MAXSECRETLEN];   /* Password for PAP or CHAP */
259 extern bool     auth_required;  /* Peer is required to authenticate */
260 extern bool     persist;        /* Reopen link after it goes down */
261 extern bool     uselogin;       /* Use /etc/passwd for checking PAP */
262 extern char     our_name[MAXNAMELEN];/* Our name for authentication purposes */
263 extern char     remote_name[MAXNAMELEN]; /* Peer's name for authentication */
264 extern bool     explicit_remote;/* remote_name specified with remotename opt */
265 extern bool     demand;         /* Do dial-on-demand */
266
267 //Added by marson 2006/06/23 for ppp never up
268 extern bool     alwayson;       /* whether dial when system up*/
269
270 extern char     *ipparam;       /* Extra parameter for ip up/down scripts */
271 extern bool     cryptpap;       /* Others' PAP passwords are encrypted */
272 extern int      idle_time_limit;/* Shut down link if idle for this long */
273 extern int      holdoff;        /* Dead time before restarting */
274 extern bool     holdoff_specified; /* true if user gave a holdoff value */
275 extern bool     notty;          /* Stdin/out is not a tty */
276 extern char     *pty_socket;    /* Socket to connect to pty */
277 extern char     *record_file;   /* File to record chars sent/received */
278 extern bool     sync_serial;    /* Device is synchronous serial device */
279 extern int      maxfail;        /* Max # of unsuccessful connection attempts */
280 extern char     linkname[MAXPATHLEN]; /* logical name for link */
281 extern bool     tune_kernel;    /* May alter kernel settings as necessary */
282 extern int      connect_delay;  /* Time to delay after connect script */
283 extern int      max_data_rate;  /* max bytes/sec through charshunt */
284 extern int      req_unit;       /* interface unit number to use */
285 extern char     req_name[MAXPATHLEN]; /* logical name for link */
286 extern bool     multilink;      /* enable multilink operation */
287 extern bool     noendpoint;     /* don't send or accept endpt. discrim. */
288 extern char     *bundle_name;   /* bundle name for multilink */
289 extern bool     dump_options;   /* print out option values */
290 extern bool     dryrun;         /* check everything, print options, exit */
291
292 #ifdef PPP_FILTER
293 extern struct   bpf_program pass_filter;   /* Filter for pkts to pass */
294 extern struct   bpf_program active_filter; /* Filter for link-active pkts */
295 #endif
296
297 #ifdef MSLANMAN
298 extern bool     ms_lanman;      /* Use LanMan password instead of NT */
299                                 /* Has meaning only with MS-CHAP challenges */
300 #endif
301
302 extern char *current_option;    /* the name of the option being parsed */
303 extern int  privileged_option;  /* set iff the current option came from root */
304 extern char *option_source;     /* string saying where the option came from */
305 extern int  option_priority;    /* priority of current options */
306
307 /*
308  * Values for phase.
309  */
310 #define PHASE_DEAD              0
311 #define PHASE_INITIALIZE        1
312 #define PHASE_SERIALCONN        2
313 #define PHASE_DORMANT           3
314 #define PHASE_ESTABLISH         4
315 #define PHASE_AUTHENTICATE      5
316 #define PHASE_CALLBACK          6
317 #define PHASE_NETWORK           7
318 #define PHASE_RUNNING           8
319 #define PHASE_TERMINATE         9
320 #define PHASE_DISCONNECT        10
321 #define PHASE_HOLDOFF           11
322
323 /*
324  * The following struct gives the addresses of procedures to call
325  * for a particular protocol.
326  */
327 struct protent {
328     u_short protocol;           /* PPP protocol number */
329     /* Initialization procedure */
330     void (*init) __P((int unit));
331     /* Process a received packet */
332     void (*input) __P((int unit, u_char *pkt, int len));
333     /* Process a received protocol-reject */
334     void (*protrej) __P((int unit));
335     /* Lower layer has come up */
336     void (*lowerup) __P((int unit));
337     /* Lower layer has gone down */
338     void (*lowerdown) __P((int unit));
339     /* Open the protocol */
340     void (*open) __P((int unit));
341     /* Close the protocol */
342     void (*close) __P((int unit, char *reason));
343     /* Print a packet in readable form */
344     int  (*printpkt) __P((u_char *pkt, int len,
345                           void (*printer) __P((void *, char *, ...)),
346                           void *arg));
347     /* Process a received data packet */
348     void (*datainput) __P((int unit, u_char *pkt, int len));
349     bool enabled_flag;          /* 0 iff protocol is disabled */
350     char *name;                 /* Text name of protocol */
351     char *data_name;            /* Text name of corresponding data protocol */
352     option_t *options;          /* List of command-line options */
353     /* Check requested options, assign defaults */
354     void (*check_options) __P((void));
355     /* Configure interface for demand-dial */
356     int  (*demand_conf) __P((int unit));
357     /* Say whether to bring up link for this pkt */
358     int  (*active_pkt) __P((u_char *pkt, int len));
359 };
360
361 /* Table of pointers to supported protocols */
362 extern struct protent *protocols[];
363
364 /*
365  * This struct contains pointers to a set of procedures for
366  * doing operations on a "channel".  A channel provides a way
367  * to send and receive PPP packets - the canonical example is
368  * a serial port device in PPP line discipline (or equivalently
369  * with PPP STREAMS modules pushed onto it).
370  */
371 struct channel {
372         /* set of options for this channel */
373         option_t *options;
374         /* find and process a per-channel options file */
375         void (*process_extra_options) __P((void));
376         /* check all the options that have been given */
377         void (*check_options) __P((void));
378         /* get the channel ready to do PPP, return a file descriptor */
379         int  (*connect) __P((void));
380         /* we're finished with the channel */
381         void (*disconnect) __P((void));
382         /* put the channel into PPP `mode' */
383         int  (*establish_ppp) __P((int));
384         /* take the channel out of PPP `mode', restore loopback if demand */
385         void (*disestablish_ppp) __P((int));
386         /* set the transmit-side PPP parameters of the channel */
387         void (*send_config) __P((int, u_int32_t, int, int));
388         /* set the receive-side PPP parameters of the channel */
389         void (*recv_config) __P((int, u_int32_t, int, int));
390         /* cleanup on error or normal exit */
391         void (*cleanup) __P((void));
392         /* close the device, called in children after fork */
393         void (*close) __P((void));
394 };
395
396 extern struct channel *the_channel;
397
398 #define ppp_send_config(unit, mtu, accm, pc, acc)                        \
399 do {                                                                     \
400         if (the_channel->send_config)                                    \
401                 (*the_channel->send_config)((mtu), (accm), (pc), (acc)); \
402 } while (0)
403
404 #define ppp_recv_config(unit, mtu, accm, pc, acc)                        \
405 do {                                                                     \
406         if (the_channel->send_config)                                    \
407                 (*the_channel->recv_config)((mtu), (accm), (pc), (acc)); \
408 } while (0)
409
410 /*
411  * Prototypes.
412  */
413
414 /* Procedures exported from main.c. */
415 void set_ifunit __P((int));     /* set stuff that depends on ifunit */
416 void detach __P((void));        /* Detach from controlling tty */
417 void die __P((int));            /* Cleanup and exit */
418 void quit __P((void));          /* like die(1) */
419 void novm __P((char *));        /* Say we ran out of memory, and die */
420 void timeout __P((void (*func)(void *), void *arg, int s, int us));
421                                 /* Call func(arg) after s.us seconds */
422 void untimeout __P((void (*func)(void *), void *arg));
423                                 /* Cancel call to func(arg) */
424 void record_child __P((int, char *, void (*) (void *), void *));
425 int  device_script __P((char *cmd, int in, int out, int dont_wait));
426                                 /* Run `cmd' with given stdin and stdout */
427 pid_t run_program __P((char *prog, char **args, int must_exist,
428                        void (*done)(void *), void *arg));
429                                 /* Run program prog with args in child */
430 void reopen_log __P((void));    /* (re)open the connection to syslog */
431 void update_link_stats __P((int)); /* Get stats at link termination */
432 void script_setenv __P((char *, char *, int));  /* set script env var */
433 void script_unsetenv __P((char *));             /* unset script env var */
434 void new_phase __P((int));      /* signal start of new phase */
435 void add_notifier __P((struct notifier **, notify_func, void *));
436 void remove_notifier __P((struct notifier **, notify_func, void *));
437 void notify __P((struct notifier *, int));
438
439 /* Procedures exported from tty.c. */
440 void tty_init __P((void));
441
442 /* Procedures exported from utils.c. */
443 void log_packet __P((u_char *, int, char *, int));
444                                 /* Format a packet and log it with syslog */
445 void print_string __P((char *, int,  void (*) (void *, char *, ...),
446                 void *));       /* Format a string for output */
447 int slprintf __P((char *, int, char *, ...));           /* sprintf++ */
448 int vslprintf __P((char *, int, char *, va_list));      /* vsprintf++ */
449 size_t strlcpy __P((char *, const char *, size_t));     /* safe strcpy */
450 size_t strlcat __P((char *, const char *, size_t));     /* safe strncpy */
451 void dbglog __P((char *, ...)); /* log a debug message */
452 void info __P((char *, ...));   /* log an informational message */
453 void notice __P((char *, ...)); /* log a notice-level message */
454 void warn __P((char *, ...));   /* log a warning message */
455 void error __P((char *, ...));  /* log an error message */
456 void fatal __P((char *, ...));  /* log an error message and die(1) */
457 void init_pr_log __P((char *, int));    /* initialize for using pr_log */
458 void pr_log __P((void *, char *, ...)); /* printer fn, output to syslog */
459 void end_pr_log __P((void));    /* finish up after using pr_log */
460
461 /* Procedures exported from auth.c */
462 void link_required __P((int));    /* we are starting to use the link */
463 void link_terminated __P((int));  /* we are finished with the link */
464 void link_down __P((int));        /* the LCP layer has left the Opened state */
465 void link_established __P((int)); /* the link is up; authenticate now */
466 void start_networks __P((void));  /* start all the network control protos */
467 void np_up __P((int, int));       /* a network protocol has come up */
468 void np_down __P((int, int));     /* a network protocol has gone down */
469 void np_finished __P((int, int)); /* a network protocol no longer needs link */
470 void auth_peer_fail __P((int, int));
471                                 /* peer failed to authenticate itself */
472 void auth_peer_success __P((int, int, char *, int));
473                                 /* peer successfully authenticated itself */
474 void auth_withpeer_fail __P((int, int));
475                                 /* we failed to authenticate ourselves */
476 void auth_withpeer_success __P((int, int));
477                                 /* we successfully authenticated ourselves */
478 void auth_check_options __P((void));
479                                 /* check authentication options supplied */
480 void auth_reset __P((int));     /* check what secrets we have */
481 int  check_passwd __P((int, char *, int, char *, int, char **));
482                                 /* Check peer-supplied username/password */
483 int  get_secret __P((int, char *, char *, char *, int *, int));
484                                 /* get "secret" for chap */
485 int  auth_ip_addr __P((int, u_int32_t));
486                                 /* check if IP address is authorized */
487 int  bad_ip_adrs __P((u_int32_t));
488                                 /* check if IP address is unreasonable */
489
490 /* Procedures exported from demand.c */
491 void demand_conf __P((void));   /* config interface(s) for demand-dial */
492 void demand_block __P((void));  /* set all NPs to queue up packets */
493 void demand_unblock __P((void)); /* set all NPs to pass packets */
494 void demand_discard __P((void)); /* set all NPs to discard packets */
495 void demand_rexmit __P((int));  /* retransmit saved frames for an NP */
496 int  loop_chars __P((unsigned char *, int)); /* process chars from loopback */
497 int  loop_frame __P((unsigned char *, int)); /* should we bring link up? */
498
499 /* Procedures exported from multilink.c */
500 void mp_check_options __P((void)); /* Check multilink-related options */
501 int  mp_join_bundle __P((void));  /* join our link to an appropriate bundle */
502 char *epdisc_to_str __P((struct epdisc *)); /* string from endpoint discrim. */
503 int  str_to_epdisc __P((struct epdisc *, char *)); /* endpt disc. from str */
504
505 /* Procedures exported from sys-*.c */
506 void sys_init __P((void));      /* Do system-dependent initialization */
507 void sys_cleanup __P((void));   /* Restore system state before exiting */
508 int  sys_check_options __P((void)); /* Check options specified */
509 void sys_close __P((void));     /* Clean up in a child before execing */
510 int  ppp_available __P((void)); /* Test whether ppp kernel support exists */
511 int  get_pty __P((int *, int *, char *, int));  /* Get pty master/slave */
512 int  open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */
513 int  tty_establish_ppp __P((int));  /* Turn serial port into a ppp interface */
514 void tty_disestablish_ppp __P((int)); /* Restore port to normal operation */
515 void generic_disestablish_ppp __P((int dev_fd)); /* Restore device setting */
516 int  generic_establish_ppp __P((int dev_fd)); /* Make a ppp interface */
517 void make_new_bundle __P((int, int, int, int)); /* Create new bundle */
518 int  bundle_attach __P((int));  /* Attach link to existing bundle */
519 void cfg_bundle __P((int, int, int, int)); /* Configure existing bundle */
520 void clean_check __P((void));   /* Check if line was 8-bit clean */
521 void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */
522 void restore_tty __P((int));    /* Restore port's original parameters */
523 void setdtr __P((int, int));    /* Raise or lower port's DTR line */
524 void output __P((int, u_char *, int)); /* Output a PPP packet */
525 void wait_input __P((struct timeval *));
526                                 /* Wait for input, with timeout */
527 void add_fd __P((int));         /* Add fd to set to wait for */
528 void remove_fd __P((int));      /* Remove fd from set to wait for */
529 int  read_packet __P((u_char *)); /* Read PPP packet */
530 int  get_loop_output __P((void)); /* Read pkts from loopback */
531 void tty_send_config __P((int, u_int32_t, int, int));
532                                 /* Configure i/f transmit parameters */
533 void tty_set_xaccm __P((ext_accm));
534                                 /* Set extended transmit ACCM */
535 void tty_recv_config __P((int, u_int32_t, int, int));
536                                 /* Configure i/f receive parameters */
537 int  ccp_test __P((int, u_char *, int, int));
538                                 /* Test support for compression scheme */
539 void ccp_flags_set __P((int, int, int));
540                                 /* Set kernel CCP state */
541 int  ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */
542 int  get_idle_time __P((int, struct ppp_idle *));
543                                 /* Find out how long link has been idle */
544 int  get_ppp_stats __P((int, struct pppd_stats *));
545                                 /* Return link statistics */
546 void netif_set_mtu __P((int, int)); /* Set PPP interface MTU */
547 int  sifvjcomp __P((int, int, int, int));
548                                 /* Configure VJ TCP header compression */
549 int  sifup __P((int));          /* Configure i/f up for one protocol */
550 int  sifnpmode __P((int u, int proto, enum NPmode mode));
551                                 /* Set mode for handling packets for proto */
552 int  sifdown __P((int));        /* Configure i/f down for one protocol */
553 int  sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t));
554                                 /* Configure IPv4 addresses for i/f */
555 int  cifaddr __P((int, u_int32_t, u_int32_t));
556                                 /* Reset i/f IP addresses */
557 #ifdef INET6
558 int  sif6addr __P((int, eui64_t, eui64_t));
559                                 /* Configure IPv6 addresses for i/f */
560 int  cif6addr __P((int, eui64_t, eui64_t));
561                                 /* Remove an IPv6 address from i/f */
562 #endif
563 int  sifdefaultroute __P((int, u_int32_t, u_int32_t));
564                                 /* Create default route through i/f */
565 int  cifdefaultroute __P((int, u_int32_t, u_int32_t));
566                                 /* Delete default route through i/f */
567 int  sifproxyarp __P((int, u_int32_t));
568                                 /* Add proxy ARP entry for peer */
569 int  cifproxyarp __P((int, u_int32_t));
570                                 /* Delete proxy ARP entry for peer */
571 u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */
572 int  lock __P((char *));        /* Create lock file for device */
573 int  relock __P((int));         /* Rewrite lock file with new pid */
574 void unlock __P((void));        /* Delete previously-created lock file */
575 void logwtmp __P((const char *, const char *, const char *));
576                                 /* Write entry to wtmp file */
577 int  get_host_seed __P((void)); /* Get host-dependent random number seed */
578 int  have_route_to __P((u_int32_t)); /* Check if route to addr exists */
579 #ifdef PPP_FILTER
580 int  set_filters __P((struct bpf_program *pass, struct bpf_program *active));
581                                 /* Set filter programs in kernel */
582 #endif
583 #ifdef IPX_CHANGE
584 int  sipxfaddr __P((int, unsigned long, unsigned char *));
585 int  cipxfaddr __P((int));
586 #endif
587 int  get_if_hwaddr __P((u_char *addr, char *name));
588 char *get_first_ethernet __P((void));
589
590 /* Procedures exported from options.c */
591 int  parse_args __P((int argc, char **argv));
592                                 /* Parse options from arguments given */
593 int  options_from_file __P((char *filename, int must_exist, int check_prot,
594                             int privileged));
595                                 /* Parse options from an options file */
596 int  options_from_user __P((void)); /* Parse options from user's .ppprc */
597 int  options_for_tty __P((void)); /* Parse options from /etc/ppp/options.tty */
598 int  options_from_list __P((struct wordlist *, int privileged));
599                                 /* Parse options from a wordlist */
600 int  getword __P((FILE *f, char *word, int *newlinep, char *filename));
601                                 /* Read a word from a file */
602 void option_error __P((char *fmt, ...));
603                                 /* Print an error message about an option */
604 int int_option __P((char *, int *));
605                                 /* Simplified number_option for decimal ints */
606 void add_options __P((option_t *)); /* Add extra options */
607 void check_options __P((void)); /* check values after all options parsed */
608 int remove_option __P((char *)); /* Disable the specified option */
609 int  override_value __P((const char *, int, const char *));
610                                 /* override value if permitted by priority */
611 void print_options __P((void (*) __P((void *, char *, ...)), void *));
612                                 /* print out values of all options */
613
614 int parse_dotted_ip __P((char *, u_int32_t *));
615
616 /*
617  * Hooks to enable plugins to change various things.
618  */
619 extern int (*new_phase_hook) __P((int));
620 extern int (*idle_time_hook) __P((struct ppp_idle *));
621 extern int (*holdoff_hook) __P((void));
622 extern int (*pap_check_hook) __P((void));
623 extern int (*pap_auth_hook) __P((char *user, char *passwd, char **msgp,
624                                  struct wordlist **paddrs,
625                                  struct wordlist **popts));
626 extern void (*pap_logout_hook) __P((void));
627 extern int (*pap_passwd_hook) __P((char *user, char *passwd));
628 extern void (*ip_up_hook) __P((void));
629 extern void (*ip_down_hook) __P((void));
630 extern void (*ip_choose_hook) __P((u_int32_t *));
631
632 // brcm
633 extern void create_msg(int lognumber);
634 extern int ipext;
635 extern int opflag;
636 extern bool refuse_pap; 
637 extern bool refuse_chap;
638 extern int autoscan;
639 extern int autoscanP2;
640 extern int ses_retries;
641 extern bool llc_encaps;
642 extern bool vc_encaps;
643 extern char session_path[];
644 extern int redisconn;
645 extern void save_session_info(unsigned char *remote_addr, int sid);
646 extern int get_sock_intf(const char *devnam);
647 extern char oldsession[MAXPATHLEN];  /* Mac address and session ID of the previous session */
648 extern char pppoe_srv_name[];
649 extern int srvdisc;
650
651
652 // brcm
653
654 /*
655  * Inline versions of get/put char/short/long.
656  * Pointer is advanced; we assume that both arguments
657  * are lvalues and will already be in registers.
658  * cp MUST be u_char *.
659  */
660 #define GETCHAR(c, cp) { \
661         (c) = *(cp)++; \
662 }
663 #define PUTCHAR(c, cp) { \
664         *(cp)++ = (u_char) (c); \
665 }
666
667
668 #define GETSHORT(s, cp) { \
669         (s) = *(cp)++ << 8; \
670         (s) |= *(cp)++; \
671 }
672 #define PUTSHORT(s, cp) { \
673         *(cp)++ = (u_char) ((s) >> 8); \
674         *(cp)++ = (u_char) (s); \
675 }
676
677 #define GETLONG(l, cp) { \
678         (l) = *(cp)++ << 8; \
679         (l) |= *(cp)++; (l) <<= 8; \
680         (l) |= *(cp)++; (l) <<= 8; \
681         (l) |= *(cp)++; \
682 }
683 #define PUTLONG(l, cp) { \
684         *(cp)++ = (u_char) ((l) >> 24); \
685         *(cp)++ = (u_char) ((l) >> 16); \
686         *(cp)++ = (u_char) ((l) >> 8); \
687         *(cp)++ = (u_char) (l); \
688 }
689
690 #define INCPTR(n, cp)   ((cp) += (n))
691 #define DECPTR(n, cp)   ((cp) -= (n))
692
693 /*
694  * System dependent definitions for user-level 4.3BSD UNIX implementation.
695  */
696
697 #define TIMEOUT(r, f, t)        timeout((r), (f), (t), 0)
698 #define UNTIMEOUT(r, f)         untimeout((r), (f))
699
700 #define BCOPY(s, d, l)          memcpy(d, s, l)
701 #define BZERO(s, n)             memset(s, 0, n)
702
703 #define PRINTMSG(m, l)          { info("Remote message: %0.*v", l, m); }
704
705 /*
706  * MAKEHEADER - Add Header fields to a packet.
707  */
708 #define MAKEHEADER(p, t) { \
709     PUTCHAR(PPP_ALLSTATIONS, p); \
710     PUTCHAR(PPP_UI, p); \
711     PUTSHORT(t, p); }
712
713 /*
714  * Exit status values.
715  */
716 #define EXIT_OK                 0
717 #define EXIT_FATAL_ERROR        1
718 #define EXIT_OPTION_ERROR       2
719 #define EXIT_NOT_ROOT           3
720 #define EXIT_NO_KERNEL_SUPPORT  4
721 #define EXIT_USER_REQUEST       5
722 #define EXIT_LOCK_FAILED        6
723 #define EXIT_OPEN_FAILED        7
724 #define EXIT_CONNECT_FAILED     8
725 #define EXIT_PTYCMD_FAILED      9
726 #define EXIT_NEGOTIATION_FAILED 10
727 #define EXIT_PEER_AUTH_FAILED   11
728 #define EXIT_IDLE_TIMEOUT       12
729 #define EXIT_CONNECT_TIME       13
730 #define EXIT_CALLBACK           14
731 #define EXIT_PEER_DEAD          15
732 #define EXIT_HANGUP             16
733 #define EXIT_LOOPBACK           17
734 #define EXIT_INIT_FAILED        18
735 #define EXIT_AUTH_TOPEER_FAILED 19
736
737 extern bool isDialUpEnabled;
738 /*
739  * Debug macros.  Slightly useful for finding bugs in pppd, not particularly
740  * useful for finding out why your connection isn't being established.
741  */
742 #ifdef DEBUGALL
743 #define DEBUGMAIN       1
744 #define DEBUGFSM        1
745 #define DEBUGLCP        1
746 #define DEBUGIPCP       1
747 #define DEBUGIPV6CP     1
748 #define DEBUGUPAP       1
749 #define DEBUGCHAP       1
750 #endif
751
752 #ifndef LOG_PPP                 /* we use LOG_LOCAL2 for syslog by default */
753 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
754   || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
755   || defined(DEBUGCHAP) || defined(DEBUG) || defined(DEBUGIPV6CP)
756 #define LOG_PPP LOG_LOCAL2
757 #else
758 #define LOG_PPP LOG_DAEMON
759 #endif
760 #endif /* LOG_PPP */
761
762 #ifdef DEBUGMAIN
763 #define MAINDEBUG(x)    if (debug) dbglog x
764 #else
765 #define MAINDEBUG(x)
766 #endif
767
768 #ifdef DEBUGSYS
769 #define SYSDEBUG(x)     if (debug) dbglog x
770 #else
771 #define SYSDEBUG(x)
772 #endif
773
774 #ifdef DEBUGFSM
775 #define FSMDEBUG(x)     if (debug) dbglog x
776 #else
777 #define FSMDEBUG(x)
778 #endif
779
780 #ifdef DEBUGLCP
781 #define LCPDEBUG(x)     if (debug) dbglog x
782 #else
783 #define LCPDEBUG(x)
784 #endif
785
786 #ifdef DEBUGIPCP
787 #define IPCPDEBUG(x)    if (debug) dbglog x
788 #else
789 #define IPCPDEBUG(x)
790 #endif
791
792 #ifdef DEBUGIPV6CP
793 #define IPV6CPDEBUG(x)  if (debug) dbglog x
794 #else
795 #define IPV6CPDEBUG(x)
796 #endif
797
798 #ifdef DEBUGUPAP
799 #define UPAPDEBUG(x)    if (debug) dbglog x
800 #else
801 #define UPAPDEBUG(x)
802 #endif
803
804 #ifdef DEBUGCHAP
805 #define CHAPDEBUG(x)    if (debug) dbglog x
806 #else
807 #define CHAPDEBUG(x)
808 #endif
809
810 #ifdef DEBUGIPXCP
811 #define IPXCPDEBUG(x)   if (debug) dbglog x
812 #else
813 #define IPXCPDEBUG(x)
814 #endif
815
816 #ifndef SIGTYPE
817 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
818 #define SIGTYPE void
819 #else
820 #define SIGTYPE int
821 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
822 #endif /* SIGTYPE */
823
824 #ifndef MIN
825 #define MIN(a, b)       ((a) < (b)? (a): (b))
826 #endif
827 #ifndef MAX
828 #define MAX(a, b)       ((a) > (b)? (a): (b))
829 #endif
830
831 #endif /* __PPP_H__ */