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