]> git.ozlabs.org Git - ppp.git/blob - pppd/pppd.h
Update DFS's legal name and email address to correct values. (#381)
[ppp.git] / pppd / pppd.h
1 /*
2  * pppd.h - PPP daemon global declarations.
3  *
4  * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * 3. The name "Carnegie Mellon University" must not be used to
19  *    endorse or promote products derived from this software without
20  *    prior written permission. For permission or any legal
21  *    details, please contact
22  *      Office of Technology Transfer
23  *      Carnegie Mellon University
24  *      5000 Forbes Avenue
25  *      Pittsburgh, PA  15213-3890
26  *      (412) 268-4387, fax: (412) 268-7395
27  *      tech-transfer@andrew.cmu.edu
28  *
29  * 4. Redistributions of any form whatsoever must retain the following
30  *    acknowledgment:
31  *    "This product includes software developed by Computing Services
32  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
33  *
34  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
41  *
42  * $Id: pppd.h,v 1.96 2008/06/23 11:47:18 paulus Exp $
43  */
44
45 #ifndef PPP_PPPD_H
46 #define PPP_PPPD_H
47
48 #include "pppdconf.h"
49
50 #include <stdio.h>              /* for FILE */
51 #include <stdlib.h>             /* for encrypt */
52 #include <unistd.h>             /* for setkey */
53 #include <stdarg.h>
54 #include <stdint.h>
55 #include <sys/types.h>          /* for u_int32_t, if defined */
56 #if defined(SOL2)
57 #include <net/ppp_defs.h>
58 #else
59 #include <linux/ppp_defs.h>
60 #endif
61
62 #ifdef PPP_WITH_IPV6CP
63 #if defined(SOL2)
64 #include <netinet/in.h>
65
66 typedef union {
67     uint8_t     e8[8];          /* lower 64-bit IPv6 address */
68     uint32_t    e32[2];         /* lower 64-bit IPv6 address */
69 } eui64_t;
70
71 /*
72  * Declare the two below, since in.h only defines them when _KERNEL
73  * is declared - which shouldn't be true when dealing with user-land programs
74  */
75 #define s6_addr8        _S6_un._S6_u8
76 #define s6_addr32       _S6_un._S6_u32
77
78 #else /* else if not defined(SOL2) */
79
80 /*
81  * TODO:
82  *
83  * Maybe this should be done by processing struct in6_addr directly...
84  */
85 typedef union
86 {
87     u_int8_t e8[8];
88     u_int16_t e16[4];
89     u_int32_t e32[2];
90 } eui64_t;
91
92 #endif /* defined(SOL2) */
93 #endif
94
95 /*
96  * Limits.
97  */
98
99 #define NUM_PPP         1       /* One PPP interface supported (per process) */
100 #define MAXWORDLEN      1024    /* max length of word in file (incl null) */
101 #define MAXARGS         1       /* max # args to a command */
102 #define MAXNAMELEN      256     /* max length of hostname or name for auth */
103 #define MAXSECRETLEN    256     /* max length of password or secret */
104
105 /*
106  * If PPP_DRV_NAME is not defined, use the default "ppp" as the device name.
107  * Where should PPP_DRV_NAME come from? Do we include it here?
108  */
109 #if !defined(PPP_DRV_NAME)
110 #define PPP_DRV_NAME    "ppp"
111 #endif /* !defined(PPP_DRV_NAME) */
112
113 /*
114  * Option descriptor structure.
115  */
116
117 typedef unsigned char   bool;
118
119 enum opt_type {
120         o_special_noarg = 0,
121         o_special = 1,
122         o_bool,
123         o_int,
124         o_uint32,
125         o_string,
126         o_wild
127 };
128
129 typedef struct {
130         char    *name;          /* name of the option */
131         enum opt_type type;
132         void    *addr;
133         char    *description;
134         unsigned int flags;
135         void    *addr2;
136         int     upper_limit;
137         int     lower_limit;
138         const char *source;
139         short int priority;
140         short int winner;
141 } option_t;
142
143 /* Values for flags */
144 #define OPT_VALUE       0xff    /* mask for presupplied value */
145 #define OPT_HEX         0x100   /* int option is in hex */
146 #define OPT_NOARG       0x200   /* option doesn't take argument */
147 #define OPT_OR          0x400   /* for u32, OR in argument to value */
148 #define OPT_INC         0x400   /* for o_int, increment value */
149 #define OPT_A2OR        0x800   /* for o_bool, OR arg to *(u_char *)addr2 */
150 #define OPT_PRIV        0x1000  /* privileged option */
151 #define OPT_STATIC      0x2000  /* string option goes into static array */
152 #define OPT_NOINCR      0x2000  /* for o_int, value mustn't be increased */
153 #define OPT_LLIMIT      0x4000  /* check value against lower limit */
154 #define OPT_ULIMIT      0x8000  /* check value against upper limit */
155 #define OPT_LIMITS      (OPT_LLIMIT|OPT_ULIMIT)
156 #define OPT_ZEROOK      0x10000 /* 0 value is OK even if not within limits */
157 #define OPT_HIDE        0x10000 /* for o_string, print value as ?????? */
158 #define OPT_A2LIST      0x20000 /* for o_special, keep list of values */
159 #define OPT_A2CLRB      0x20000 /* o_bool, clr val bits in *(u_char *)addr2 */
160 #define OPT_ZEROINF     0x40000 /* with OPT_NOINCR, 0 == infinity */
161 #define OPT_PRIO        0x80000 /* process option priorities for this option */
162 #define OPT_PRIOSUB     0x100000 /* subsidiary member of priority group */
163 #define OPT_ALIAS       0x200000 /* option is alias for previous option */
164 #define OPT_A2COPY      0x400000 /* addr2 -> second location to rcv value */
165 #define OPT_ENABLE      0x800000 /* use *addr2 as enable for option */
166 #define OPT_A2CLR       0x1000000 /* clear *(bool *)addr2 */
167 #define OPT_PRIVFIX     0x2000000 /* user can't override if set by root */
168 #define OPT_INITONLY    0x4000000 /* option can only be set in init phase */
169 #define OPT_DEVEQUIV    0x8000000 /* equiv to device name */
170 #define OPT_DEVNAM      (OPT_INITONLY | OPT_DEVEQUIV)
171 #define OPT_A2PRINTER   0x10000000 /* *addr2 printer_func to print option */
172 #define OPT_A2STRVAL    0x20000000 /* *addr2 points to current string value */
173 #define OPT_NOPRINT     0x40000000 /* don't print this option at all */
174
175 #define OPT_VAL(x)      ((x) & OPT_VALUE)
176
177 /* Values for priority */
178 #define OPRIO_DEFAULT   0       /* a default value */
179 #define OPRIO_CFGFILE   1       /* value from a configuration file */
180 #define OPRIO_CMDLINE   2       /* value from the command line */
181 #define OPRIO_SECFILE   3       /* value from options in a secrets file */
182 #define OPRIO_ROOT      100     /* added to priority if OPT_PRIVFIX && root */
183
184 #ifndef GIDSET_TYPE
185 #define GIDSET_TYPE     gid_t
186 #endif
187
188 /* Structure representing a list of permitted IP addresses. */
189 struct permitted_ip {
190     int         permit;         /* 1 = permit, 0 = forbid */
191     u_int32_t   base;           /* match if (addr & mask) == base */
192     u_int32_t   mask;           /* base and mask are in network byte order */
193 };
194
195 /*
196  * Unfortunately, the linux kernel driver uses a different structure
197  * for statistics from the rest of the ports.
198  * This structure serves as a common representation for the bits
199  * pppd needs.
200  */
201 struct pppd_stats {
202     uint64_t            bytes_in;
203     uint64_t            bytes_out;
204     unsigned int        pkts_in;
205     unsigned int        pkts_out;
206 };
207
208 /* Used for storing a sequence of words.  Usually malloced. */
209 struct wordlist {
210     struct wordlist     *next;
211     char                *word;
212 };
213
214 /* An endpoint discriminator, used with multilink. */
215 #define MAX_ENDP_LEN    20      /* maximum length of discriminator value */
216 struct epdisc {
217     unsigned char       class;
218     unsigned char       length;
219     unsigned char       value[MAX_ENDP_LEN];
220 };
221
222 /* values for epdisc.class */
223 #define EPD_NULL        0       /* null discriminator, no data */
224 #define EPD_LOCAL       1
225 #define EPD_IP          2
226 #define EPD_MAC         3
227 #define EPD_MAGIC       4
228 #define EPD_PHONENUM    5
229
230 typedef void (*notify_func)(void *, int);
231 typedef void (*printer_func)(void *, char *, ...);
232
233 struct notifier {
234     struct notifier *next;
235     notify_func     func;
236     void            *arg;
237 };
238
239 /*
240  * Global variables.
241  */
242
243 extern int      got_sigterm;    /* SIGINT or SIGTERM was received */
244 extern int      hungup;         /* Physical layer has disconnected */
245 extern int      ifunit;         /* Interface unit number */
246 extern char     ifname[];       /* Interface name (IFNAMSIZ) */
247 extern char     hostname[];     /* Our hostname */
248 extern u_char   outpacket_buf[]; /* Buffer for outgoing packets */
249 extern int      devfd;          /* fd of underlying device */
250 extern int      fd_ppp;         /* fd for talking PPP */
251 extern int      phase;          /* Current state of link - see values below */
252 extern int      baud_rate;      /* Current link speed in bits/sec */
253 extern char     *progname;      /* Name of this program */
254 extern int      redirect_stderr;/* Connector's stderr should go to file */
255 extern char     peer_authname[];/* Authenticated name of peer */
256 extern int      auth_done[NUM_PPP]; /* Methods actually used for auth */
257 extern int      privileged;     /* We were run by real-uid root */
258 extern int      need_holdoff;   /* Need holdoff period after link terminates */
259 extern char     **script_env;   /* Environment variables for scripts */
260 extern int      detached;       /* Have detached from controlling tty */
261 extern GIDSET_TYPE groups[];    /* groups the user is in */
262 extern int      ngroups;        /* How many groups valid in groups */
263 extern struct pppd_stats link_stats; /* byte/packet counts etc. for link */
264 extern int      link_stats_valid; /* set if link_stats is valid */
265 extern unsigned link_connect_time; /* time the link was up for */
266 extern int      using_pty;      /* using pty as device (notty or pty opt.) */
267 extern int      log_to_fd;      /* logging to this fd as well as syslog */
268 extern bool     log_default;    /* log_to_fd is default (stdout) */
269 extern char     *no_ppp_msg;    /* message to print if ppp not in kernel */
270 extern volatile int status;     /* exit status for pppd */
271 extern bool     devnam_fixed;   /* can no longer change devnam */
272 extern int      unsuccess;      /* # unsuccessful connection attempts */
273 extern int      do_callback;    /* set if we want to do callback next */
274 extern int      doing_callback; /* set if this is a callback */
275 extern int      error_count;    /* # of times error() has been called */
276 extern char     ppp_devnam[];   /* name of PPP tty (maybe ttypx) */
277 extern char     remote_number[MAXNAMELEN]; /* Remote telephone number, if avail. */
278 extern int      ppp_session_number; /* Session number (eg PPPoE session) */
279 extern int      fd_devnull;     /* fd open to /dev/null */
280
281 extern int      listen_time;    /* time to listen first (ms) */
282 extern bool     doing_multilink;
283 extern bool     multilink_master;
284 extern bool     bundle_eof;
285 extern bool     bundle_terminating;
286
287 extern struct notifier *pidchange;   /* for notifications of pid changing */
288 extern struct notifier *phasechange; /* for notifications of phase changes */
289 extern struct notifier *exitnotify;  /* for notification that we're exiting */
290 extern struct notifier *sigreceived; /* notification of received signal */
291 extern struct notifier *ip_up_notifier;     /* IPCP has come up */
292 extern struct notifier *ip_down_notifier;   /* IPCP has gone down */
293 extern struct notifier *ipv6_up_notifier;   /* IPV6CP has come up */
294 extern struct notifier *ipv6_down_notifier; /* IPV6CP has gone down */
295 extern struct notifier *auth_up_notifier; /* peer has authenticated */
296 extern struct notifier *link_down_notifier; /* link has gone down */
297 extern struct notifier *fork_notifier;  /* we are a new child process */
298
299 /* Values for do_callback and doing_callback */
300 #define CALLBACK_DIALIN         1       /* we are expecting the call back */
301 #define CALLBACK_DIALOUT        2       /* we are dialling out to call back */
302
303 /*
304  * Variables set by command-line options.
305  */
306
307 extern int      debug;          /* Debug flag */
308 extern int      kdebugflag;     /* Tell kernel to print debug messages */
309 extern int      default_device; /* Using /dev/tty or equivalent */
310 extern char     devnam[];       /* Device name */
311 extern int      crtscts;        /* Use hardware flow control */
312 extern int      stop_bits;      /* Number of serial port stop bits */
313 extern bool     modem;          /* Use modem control lines */
314 extern int      inspeed;        /* Input/Output speed requested */
315 extern u_int32_t netmask;       /* IP netmask to set on interface */
316 extern bool     lockflag;       /* Create lock file to lock the serial dev */
317 extern bool     nodetach;       /* Don't detach from controlling tty */
318 #ifdef SYSTEMD
319 extern bool     up_sdnotify;    /* Notify systemd once link is up (implies nodetach) */
320 #endif
321 extern bool     updetach;       /* Detach from controlling tty when link up */
322 extern bool     master_detach;  /* Detach when multilink master without link */
323 extern char     *initializer;   /* Script to initialize physical link */
324 extern char     *connect_script; /* Script to establish physical link */
325 extern char     *disconnect_script; /* Script to disestablish physical link */
326 extern char     *welcomer;      /* Script to welcome client after connection */
327 extern char     *ptycommand;    /* Command to run on other side of pty */
328 extern int      maxconnect;     /* Maximum connect time (seconds) */
329 extern char     user[MAXNAMELEN];/* Our name for authenticating ourselves */
330 extern char     passwd[MAXSECRETLEN];   /* Password for PAP or CHAP */
331 extern bool     auth_required;  /* Peer is required to authenticate */
332 extern bool     persist;        /* Reopen link after it goes down */
333 extern bool     uselogin;       /* Use /etc/passwd for checking PAP */
334 extern bool     session_mgmt;   /* Do session management (login records) */
335 extern char     our_name[MAXNAMELEN];/* Our name for authentication purposes */
336 extern char     remote_name[MAXNAMELEN]; /* Peer's name for authentication */
337 extern bool     explicit_remote;/* remote_name specified with remotename opt */
338 extern bool     demand;         /* Do dial-on-demand */
339 extern char     *ipparam;       /* Extra parameter for ip up/down scripts */
340 extern bool     cryptpap;       /* Others' PAP passwords are encrypted */
341 extern int      idle_time_limit;/* Shut down link if idle for this long */
342 extern int      holdoff;        /* Dead time before restarting */
343 extern bool     holdoff_specified; /* true if user gave a holdoff value */
344 extern bool     notty;          /* Stdin/out is not a tty */
345 extern char     *pty_socket;    /* Socket to connect to pty */
346 extern char     *record_file;   /* File to record chars sent/received */
347 extern bool     sync_serial;    /* Device is synchronous serial device */
348 extern int      maxfail;        /* Max # of unsuccessful connection attempts */
349 extern char     linkname[];     /* logical name for link */
350 extern bool     tune_kernel;    /* May alter kernel settings as necessary */
351 extern int      connect_delay;  /* Time to delay after connect script */
352 extern int      max_data_rate;  /* max bytes/sec through charshunt */
353 extern int      req_unit;       /* interface unit number to use */
354 extern char     path_ipup[];    /* pathname of ip-up script */
355 extern char     path_ipdown[];  /* pathname of ip-down script */
356 extern char     req_ifname[]; /* interface name to use (IFNAMSIZ) */
357 extern bool     multilink;      /* enable multilink operation */
358 extern bool     noendpoint;     /* don't send or accept endpt. discrim. */
359 extern char     *bundle_name;   /* bundle name for multilink */
360 extern bool     dump_options;   /* print out option values */
361 extern bool     show_options;   /* show all option names and descriptions */
362 extern bool     dryrun;         /* check everything, print options, exit */
363 extern int      child_wait;     /* # seconds to wait for children at end */
364
365 #ifdef PPP_WITH_IPV6CP
366 extern char     path_ipv6up[]; /* pathname of ipv6-up script */
367 extern char     path_ipv6down[]; /* pathname of ipv6-down script */
368 #endif
369
370 #if defined(PPP_WITH_EAPTLS) || defined(PPP_WITH_PEAP)
371 #define TLS_VERIFY_NONE     "none"
372 #define TLS_VERIFY_NAME     "name"
373 #define TLS_VERIFY_SUBJECT  "subject"
374 #define TLS_VERIFY_SUFFIX   "suffix"
375
376 extern char *crl_dir;
377 extern char *crl_file;
378 extern char *ca_path;
379 extern char *cacert_file;
380
381 extern char *max_tls_version;
382 extern bool tls_verify_key_usage;
383 extern char *tls_verify_method;
384 #endif /* PPP_WITH_EAPTLS || PPP_WITH_PEAP */
385
386 #ifdef PPP_WITH_EAPTLS
387 extern char *pkcs12_file;
388 #endif /* PPP_WITH_EAPTLS */
389
390 extern unsigned int maxoctets;       /* Maximum octetes per session (in bytes) */
391 extern int       maxoctets_dir;      /* Direction :
392                                       0 - in+out (default)
393                                       1 - in
394                                       2 - out
395                                       3 - max(in,out) */
396 extern int       maxoctets_timeout;  /* Timeout for check of octets limit */
397 #define PPP_OCTETS_DIRECTION_SUM        0
398 #define PPP_OCTETS_DIRECTION_IN         1
399 #define PPP_OCTETS_DIRECTION_OUT        2
400 #define PPP_OCTETS_DIRECTION_MAXOVERAL  3
401 /* same as previos, but little different on RADIUS side */
402 #define PPP_OCTETS_DIRECTION_MAXSESSION 4
403
404 #ifdef PPP_WITH_FILTER
405 extern struct   bpf_program pass_filter;   /* Filter for pkts to pass */
406 extern struct   bpf_program active_filter; /* Filter for link-active pkts */
407 #endif
408
409 #ifdef PPP_WITH_MSLANMAN
410 extern bool     ms_lanman;      /* Use LanMan password instead of NT */
411                                 /* Has meaning only with MS-CHAP challenges */
412 #endif
413
414 /* Values for auth_pending, auth_done */
415 #define PAP_WITHPEER    0x1
416 #define PAP_PEER        0x2
417 #define CHAP_WITHPEER   0x4
418 #define CHAP_PEER       0x8
419 #define EAP_WITHPEER    0x10
420 #define EAP_PEER        0x20
421
422 /* Values for auth_done only */
423 #define CHAP_MD5_WITHPEER       0x40
424 #define CHAP_MD5_PEER           0x80
425 #define CHAP_MS_SHIFT           8       /* LSB position for MS auths */
426 #define CHAP_MS_WITHPEER        0x100
427 #define CHAP_MS_PEER            0x200
428 #define CHAP_MS2_WITHPEER       0x400
429 #define CHAP_MS2_PEER           0x800
430
431 extern char *current_option;    /* the name of the option being parsed */
432 extern int  privileged_option;  /* set iff the current option came from root */
433 extern char *option_source;     /* string saying where the option came from */
434 extern int  option_priority;    /* priority of current options */
435
436 /*
437  * Values for phase.
438  */
439 #define PHASE_DEAD              0
440 #define PHASE_INITIALIZE        1
441 #define PHASE_SERIALCONN        2
442 #define PHASE_DORMANT           3
443 #define PHASE_ESTABLISH         4
444 #define PHASE_AUTHENTICATE      5
445 #define PHASE_CALLBACK          6
446 #define PHASE_NETWORK           7
447 #define PHASE_RUNNING           8
448 #define PHASE_TERMINATE         9
449 #define PHASE_DISCONNECT        10
450 #define PHASE_HOLDOFF           11
451 #define PHASE_MASTER            12
452
453 /*
454  * The following struct gives the addresses of procedures to call
455  * for a particular protocol.
456  */
457 struct protent {
458     u_short protocol;           /* PPP protocol number */
459     /* Initialization procedure */
460     void (*init)(int unit);
461     /* Process a received packet */
462     void (*input)(int unit, u_char *pkt, int len);
463     /* Process a received protocol-reject */
464     void (*protrej)(int unit);
465     /* Lower layer has come up */
466     void (*lowerup)(int unit);
467     /* Lower layer has gone down */
468     void (*lowerdown)(int unit);
469     /* Open the protocol */
470     void (*open)(int unit);
471     /* Close the protocol */
472     void (*close)(int unit, char *reason);
473     /* Print a packet in readable form */
474     int  (*printpkt)(u_char *pkt, int len, printer_func printer, void *arg);
475     /* Process a received data packet */
476     void (*datainput)(int unit, u_char *pkt, int len);
477     bool enabled_flag;          /* 0 iff protocol is disabled */
478     char *name;                 /* Text name of protocol */
479     char *data_name;            /* Text name of corresponding data protocol */
480     option_t *options;          /* List of command-line options */
481     /* Check requested options, assign defaults */
482     void (*check_options)(void);
483     /* Configure interface for demand-dial */
484     int  (*demand_conf)(int unit);
485     /* Say whether to bring up link for this pkt */
486     int  (*active_pkt)(u_char *pkt, int len);
487 };
488
489 /* Table of pointers to supported protocols */
490 extern struct protent *protocols[];
491
492 /*
493  * This struct contains pointers to a set of procedures for
494  * doing operations on a "channel".  A channel provides a way
495  * to send and receive PPP packets - the canonical example is
496  * a serial port device in PPP line discipline (or equivalently
497  * with PPP STREAMS modules pushed onto it).
498  */
499 struct channel {
500         /* set of options for this channel */
501         option_t *options;
502         /* find and process a per-channel options file */
503         void (*process_extra_options)(void);
504         /* check all the options that have been given */
505         void (*check_options)(void);
506         /* get the channel ready to do PPP, return a file descriptor */
507         int  (*connect)(void);
508         /* we're finished with the channel */
509         void (*disconnect)(void);
510         /* put the channel into PPP `mode' */
511         int  (*establish_ppp)(int);
512         /* take the channel out of PPP `mode', restore loopback if demand */
513         void (*disestablish_ppp)(int);
514         /* set the transmit-side PPP parameters of the channel */
515         void (*send_config)(int, u_int32_t, int, int);
516         /* set the receive-side PPP parameters of the channel */
517         void (*recv_config)(int, u_int32_t, int, int);
518         /* cleanup on error or normal exit */
519         void (*cleanup)(void);
520         /* close the device, called in children after fork */
521         void (*close)(void);
522 };
523
524 extern struct channel *the_channel;
525
526 /*
527  * This structure contains environment variables that are set or unset
528  * by the user.
529  */
530 struct userenv {
531         struct userenv *ue_next;
532         char *ue_value;         /* value (set only) */
533         bool ue_isset;          /* 1 for set, 0 for unset */
534         bool ue_priv;           /* from privileged source */
535         const char *ue_source;  /* source name */
536         char ue_name[1];        /* variable name */
537 };
538
539 extern struct userenv *userenv_list;
540
541 /*
542  * Prototypes.
543  */
544
545 /* Procedures exported from main.c. */
546 void set_ifunit(int);   /* set stuff that depends on ifunit */
547 void detach(void);      /* Detach from controlling tty */
548 void die(int);          /* Cleanup and exit */
549 void quit(void);                /* like die(1) */
550 void novm(char *);      /* Say we ran out of memory, and die */
551 void timeout(void (*func)(void *), void *arg, int s, int us);
552                                 /* Call func(arg) after s.us seconds */
553 void untimeout(void (*func)(void *), void *arg);
554                                 /* Cancel call to func(arg) */
555 void record_child(int, char *, void (*) (void *), void *, int);
556 pid_t safe_fork(int, int, int); /* Fork & close stuff in child */
557 int  device_script(char *cmd, int in, int out, int dont_wait);
558                                 /* Run `cmd' with given stdin and stdout */
559 pid_t run_program(char *prog, char **args, int must_exist,
560                   void (*done)(void *), void *arg, int wait);
561                                 /* Run program prog with args in child */
562 void reopen_log(void);  /* (re)open the connection to syslog */
563 void print_link_stats(void); /* Print stats, if available */
564 void reset_link_stats(int); /* Reset (init) stats when link goes up */
565 void update_link_stats(int); /* Get stats at link termination */
566 void script_setenv(char *, char *, int);        /* set script env var */
567 void script_unsetenv(char *);           /* unset script env var */
568 void new_phase(int);    /* signal start of new phase */
569 void add_notifier(struct notifier **, notify_func, void *);
570 void remove_notifier(struct notifier **, notify_func, void *);
571 void notify(struct notifier *, int);
572 int  ppp_send_config(int, int, u_int32_t, int, int);
573 int  ppp_recv_config(int, int, u_int32_t, int, int);
574 const char *protocol_name(int);
575 void remove_pidfiles(void);
576 void lock_db(void);
577 void unlock_db(void);
578
579 /* Procedures exported from tty.c. */
580 void tty_init(void);
581
582 /* Procedures exported from utils.c. */
583 void log_packet(u_char *, int, char *, int);
584                                 /* Format a packet and log it with syslog */
585 void print_string(char *, int,  printer_func, void *);
586                                 /* Format a string for output */
587 int slprintf(char *, int, char *, ...);         /* sprintf++ */
588 int vslprintf(char *, int, char *, va_list);    /* vsprintf++ */
589 size_t strlcpy(char *, const char *, size_t);   /* safe strcpy */
590 size_t strlcat(char *, const char *, size_t);   /* safe strncpy */
591 void dbglog(char *, ...);       /* log a debug message */
592 void info(char *, ...); /* log an informational message */
593 void notice(char *, ...);       /* log a notice-level message */
594 void warn(char *, ...); /* log a warning message */
595 void error(char *, ...);        /* log an error message */
596 void fatal(char *, ...);        /* log an error message and die(1) */
597 void init_pr_log(const char *, int); /* initialize for using pr_log */
598 void pr_log(void *, char *, ...);       /* printer fn, output to syslog */
599 void end_pr_log(void);  /* finish up after using pr_log */
600 void dump_packet(const char *, u_char *, int);
601                                 /* dump packet to debug log if interesting */
602 ssize_t complete_read(int, void *, size_t);
603                                 /* read a complete buffer */
604
605 /* Procedures exported from auth.c */
606 void link_required(int);          /* we are starting to use the link */
607 void start_link(int);     /* bring the link up now */
608 void link_terminated(int);  /* we are finished with the link */
609 void link_down(int);      /* the LCP layer has left the Opened state */
610 void upper_layers_down(int);/* take all NCPs down */
611 void link_established(int); /* the link is up; authenticate now */
612 void start_networks(int);   /* start all the network control protos */
613 void continue_networks(int); /* start network [ip, etc] control protos */
614 void np_up(int, int);     /* a network protocol has come up */
615 void np_down(int, int);   /* a network protocol has gone down */
616 void np_finished(int, int); /* a network protocol no longer needs link */
617 void auth_peer_fail(int, int);
618                                 /* peer failed to authenticate itself */
619 void auth_peer_success(int, int, int, char *, int);
620                                 /* peer successfully authenticated itself */
621 void auth_withpeer_fail(int, int);
622                                 /* we failed to authenticate ourselves */
623 void auth_withpeer_success(int, int, int);
624                                 /* we successfully authenticated ourselves */
625 void auth_check_options(void);
626                                 /* check authentication options supplied */
627 void auth_reset(int);   /* check what secrets we have */
628 int  check_passwd(int, char *, int, char *, int, char **);
629                                 /* Check peer-supplied username/password */
630 int  get_secret(int, char *, char *, char *, int *, int);
631                                 /* get "secret" for chap */
632 int  get_srp_secret(int unit, char *client, char *server, char *secret,
633     int am_server);
634 int  auth_ip_addr(int, u_int32_t);
635                                 /* check if IP address is authorized */
636 int  auth_number(void); /* check if remote number is authorized */
637 int  bad_ip_adrs(u_int32_t);
638                                 /* check if IP address is unreasonable */
639
640 /* Procedures exported from demand.c */
641 void demand_conf(void); /* config interface(s) for demand-dial */
642 void demand_block(void);        /* set all NPs to queue up packets */
643 void demand_unblock(void); /* set all NPs to pass packets */
644 void demand_discard(void); /* set all NPs to discard packets */
645 void demand_rexmit(int);        /* retransmit saved frames for an NP */
646 int  loop_chars(unsigned char *, int); /* process chars from loopback */
647 int  loop_frame(unsigned char *, int); /* should we bring link up? */
648
649 /* Procedures exported from multilink.c */
650 #ifdef PPP_WITH_MULTILINK
651 void mp_check_options(void); /* Check multilink-related options */
652 int  mp_join_bundle(void);  /* join our link to an appropriate bundle */
653 void mp_exit_bundle(void);  /* have disconnected our link from bundle */
654 void mp_bundle_terminated(void);
655 char *epdisc_to_str(struct epdisc *); /* string from endpoint discrim. */
656 int  str_to_epdisc(struct epdisc *, char *); /* endpt disc. from str */
657 #else
658 #define mp_bundle_terminated()  /* nothing */
659 #define mp_exit_bundle()        /* nothing */
660 #define doing_multilink         0
661 #define multilink_master        0
662 #endif
663
664 /* Procedures exported from sys-*.c */
665 void sys_init(void);    /* Do system-dependent initialization */
666 void sys_cleanup(void); /* Restore system state before exiting */
667 int  sys_check_options(void); /* Check options specified */
668 void sys_close(void);   /* Clean up in a child before execing */
669 int  ppp_available(void);       /* Test whether ppp kernel support exists */
670 int  get_pty(int *, int *, char *, int);        /* Get pty master/slave */
671 int  open_ppp_loopback(void); /* Open loopback for demand-dialling */
672 int  tty_establish_ppp(int);  /* Turn serial port into a ppp interface */
673 void tty_disestablish_ppp(int); /* Restore port to normal operation */
674 void generic_disestablish_ppp(int dev_fd); /* Restore device setting */
675 int  generic_establish_ppp(int dev_fd); /* Make a ppp interface */
676 void make_new_bundle(int, int, int, int); /* Create new bundle */
677 int  bundle_attach(int);        /* Attach link to existing bundle */
678 void cfg_bundle(int, int, int, int); /* Configure existing bundle */
679 void destroy_bundle(void); /* Tell driver to destroy bundle */
680 void clean_check(void); /* Check if line was 8-bit clean */
681 void set_up_tty(int, int); /* Set up port's speed, parameters, etc. */
682 void restore_tty(int);  /* Restore port's original parameters */
683 void setdtr(int, int);  /* Raise or lower port's DTR line */
684 void output(int, u_char *, int); /* Output a PPP packet */
685 void wait_input(struct timeval *);
686                                 /* Wait for input, with timeout */
687 void add_fd(int);               /* Add fd to set to wait for */
688 void remove_fd(int);    /* Remove fd from set to wait for */
689 int  read_packet(u_char *); /* Read PPP packet */
690 int  get_loop_output(void); /* Read pkts from loopback */
691 void tty_send_config(int, u_int32_t, int, int);
692                                 /* Configure i/f transmit parameters */
693 void tty_set_xaccm(ext_accm);
694                                 /* Set extended transmit ACCM */
695 void tty_recv_config(int, u_int32_t, int, int);
696                                 /* Configure i/f receive parameters */
697 int  ccp_test(int, u_char *, int, int);
698                                 /* Test support for compression scheme */
699 void ccp_flags_set(int, int, int);
700                                 /* Set kernel CCP state */
701 int  ccp_fatal_error(int); /* Test for fatal decomp error in kernel */
702 int  get_idle_time(int, struct ppp_idle *);
703                                 /* Find out how long link has been idle */
704 int  get_ppp_stats(int, struct pppd_stats *);
705                                 /* Return link statistics */
706 void netif_set_mtu(int, int); /* Set PPP interface MTU */
707 int  netif_get_mtu(int);      /* Get PPP interface MTU */
708 int  sifvjcomp(int, int, int, int);
709                                 /* Configure VJ TCP header compression */
710 int  sifup(int);                /* Configure i/f up for one protocol */
711 int  sifnpmode(int u, int proto, enum NPmode mode);
712                                 /* Set mode for handling packets for proto */
713 int  sifdown(int);      /* Configure i/f down for one protocol */
714 int  sifaddr(int, u_int32_t, u_int32_t, u_int32_t);
715                                 /* Configure IPv4 addresses for i/f */
716 int  cifaddr(int, u_int32_t, u_int32_t);
717                                 /* Reset i/f IP addresses */
718 #ifdef PPP_WITH_IPV6CP
719 int  sif6up(int);               /* Configure i/f up for IPv6 */
720 int  sif6down(int);     /* Configure i/f down for IPv6 */
721 int  sif6addr(int, eui64_t, eui64_t);
722                                 /* Configure IPv6 addresses for i/f */
723 int  cif6addr(int, eui64_t, eui64_t);
724                                 /* Remove an IPv6 address from i/f */
725 #endif
726 int  sifdefaultroute(int, u_int32_t, u_int32_t, bool replace_default_rt);
727                                 /* Create default route through i/f */
728 int  cifdefaultroute(int, u_int32_t, u_int32_t);
729                                 /* Delete default route through i/f */
730 #ifdef PPP_WITH_IPV6CP
731 int  sif6defaultroute(int, eui64_t, eui64_t);
732                                 /* Create default IPv6 route through i/f */
733 int  cif6defaultroute(int, eui64_t, eui64_t);
734                                 /* Delete default IPv6 route through i/f */
735 #endif
736 int  sifproxyarp(int, u_int32_t);
737                                 /* Add proxy ARP entry for peer */
738 int  cifproxyarp(int, u_int32_t);
739                                 /* Delete proxy ARP entry for peer */
740 u_int32_t GetMask(u_int32_t); /* Get appropriate netmask for address */
741 int  lock(char *);      /* Create lock file for device */
742 int  relock(int);               /* Rewrite lock file with new pid */
743 void unlock(void);      /* Delete previously-created lock file */
744 void logwtmp(const char *, const char *, const char *);
745                                 /* Write entry to wtmp file */
746 int  get_host_seed(void);       /* Get host-dependent random number seed */
747 int  have_route_to(u_int32_t); /* Check if route to addr exists */
748 #ifdef PPP_WITH_FILTER
749 int  set_filters(struct bpf_program *pass, struct bpf_program *active);
750                                 /* Set filter programs in kernel */
751 #endif
752 int  get_if_hwaddr(u_char *addr, char *name);
753 int  get_first_ether_hwaddr(u_char *addr);
754 int get_time(struct timeval *);
755                                 /* Get current time, monotonic if possible. */
756
757 /* Procedures exported from options.c */
758 int setipaddr(char *, char **, int); /* Set local/remote ip addresses */
759 int  parse_args(int argc, char **argv);
760                                 /* Parse options from arguments given */
761 int  options_from_file(char *filename, int must_exist, int check_prot,
762                        int privileged);
763                                 /* Parse options from an options file */
764 int  options_from_user(void); /* Parse options from user's .ppprc */
765 int  options_for_tty(void); /* Parse options from /etc/ppp/options.tty */
766 int  options_from_list(struct wordlist *, int privileged);
767                                 /* Parse options from a wordlist */
768 int  getword(FILE *f, char *word, int *newlinep, char *filename);
769                                 /* Read a word from a file */
770 void option_error(char *fmt, ...);
771                                 /* Print an error message about an option */
772 int int_option(char *, int *);
773                                 /* Simplified number_option for decimal ints */
774 void add_options(option_t *); /* Add extra options */
775 void check_options(void);       /* check values after all options parsed */
776 int  override_value(char *, int, const char *);
777                                 /* override value if permitted by priority */
778 void print_options(printer_func, void *);
779                                 /* print out values of all options */
780 void showopts(void);
781                 /* show all option names and description */
782 int parse_dotted_ip(char *, u_int32_t *);
783
784 /*
785  * Hooks to enable plugins to change various things.
786  */
787 extern int (*new_phase_hook)(int);
788 extern int (*idle_time_hook)(struct ppp_idle *);
789 extern int (*holdoff_hook)(void);
790 extern int (*pap_check_hook)(void);
791 extern int (*pap_auth_hook)(char *user, char *passwd, char **msgp,
792                             struct wordlist **paddrs,
793                             struct wordlist **popts);
794 extern void (*pap_logout_hook)(void);
795 extern int (*pap_passwd_hook)(char *user, char *passwd);
796 extern int (*allowed_address_hook)(u_int32_t addr);
797 extern void (*ip_up_hook)(void);
798 extern void (*ip_down_hook)(void);
799 extern void (*ip_choose_hook)(u_int32_t *);
800 extern void (*ipv6_up_hook)(void);
801 extern void (*ipv6_down_hook)(void);
802
803 extern int (*chap_check_hook)(void);
804 extern int (*chap_passwd_hook)(char *user, char *passwd);
805 extern void (*multilink_join_hook)(void);
806
807 #ifdef PPP_WITH_EAPTLS
808 extern int (*eaptls_passwd_hook)(char *user, char *passwd);
809 #endif
810
811 /* Let a plugin snoop sent and received packets.  Useful for L2TP */
812 extern void (*snoop_recv_hook)(unsigned char *p, int len);
813 extern void (*snoop_send_hook)(unsigned char *p, int len);
814
815 /*
816  * Inline versions of get/put char/short/long.
817  * Pointer is advanced; we assume that both arguments
818  * are lvalues and will already be in registers.
819  * cp MUST be u_char *.
820  */
821 #define GETCHAR(c, cp) { \
822         (c) = *(cp)++; \
823 }
824 #define PUTCHAR(c, cp) { \
825         *(cp)++ = (u_char) (c); \
826 }
827
828
829 #define GETSHORT(s, cp) { \
830         (s) = *(cp)++ << 8; \
831         (s) |= *(cp)++; \
832 }
833 #define PUTSHORT(s, cp) { \
834         *(cp)++ = (u_char) ((s) >> 8); \
835         *(cp)++ = (u_char) (s); \
836 }
837
838 #define GETLONG(l, cp) { \
839         (l) = *(cp)++ << 8; \
840         (l) |= *(cp)++; (l) <<= 8; \
841         (l) |= *(cp)++; (l) <<= 8; \
842         (l) |= *(cp)++; \
843 }
844 #define PUTLONG(l, cp) { \
845         *(cp)++ = (u_char) ((l) >> 24); \
846         *(cp)++ = (u_char) ((l) >> 16); \
847         *(cp)++ = (u_char) ((l) >> 8); \
848         *(cp)++ = (u_char) (l); \
849 }
850
851 #define INCPTR(n, cp)   ((cp) += (n))
852 #define DECPTR(n, cp)   ((cp) -= (n))
853
854 /*
855  * System dependent definitions for user-level 4.3BSD UNIX implementation.
856  */
857
858 #define TIMEOUT(r, f, t)        timeout((r), (f), (t), 0)
859 #define UNTIMEOUT(r, f)         untimeout((r), (f))
860
861 #define BCOPY(s, d, l)          memcpy(d, s, l)
862 #define BZERO(s, n)             memset(s, 0, n)
863 #define BCMP(s1, s2, l)         memcmp(s1, s2, l)
864
865 #define PRINTMSG(m, l)          { info("Remote message: %0.*v", l, m); }
866
867 /*
868  * MAKEHEADER - Add Header fields to a packet.
869  */
870 #define MAKEHEADER(p, t) { \
871     PUTCHAR(PPP_ALLSTATIONS, p); \
872     PUTCHAR(PPP_UI, p); \
873     PUTSHORT(t, p); }
874
875 /*
876  * Exit status values.
877  */
878 #define EXIT_OK                 0
879 #define EXIT_FATAL_ERROR        1
880 #define EXIT_OPTION_ERROR       2
881 #define EXIT_NOT_ROOT           3
882 #define EXIT_NO_KERNEL_SUPPORT  4
883 #define EXIT_USER_REQUEST       5
884 #define EXIT_LOCK_FAILED        6
885 #define EXIT_OPEN_FAILED        7
886 #define EXIT_CONNECT_FAILED     8
887 #define EXIT_PTYCMD_FAILED      9
888 #define EXIT_NEGOTIATION_FAILED 10
889 #define EXIT_PEER_AUTH_FAILED   11
890 #define EXIT_IDLE_TIMEOUT       12
891 #define EXIT_CONNECT_TIME       13
892 #define EXIT_CALLBACK           14
893 #define EXIT_PEER_DEAD          15
894 #define EXIT_HANGUP             16
895 #define EXIT_LOOPBACK           17
896 #define EXIT_INIT_FAILED        18
897 #define EXIT_AUTH_TOPEER_FAILED 19
898 #define EXIT_TRAFFIC_LIMIT      20
899 #define EXIT_CNID_AUTH_FAILED   21
900
901 /*
902  * Debug macros.  Slightly useful for finding bugs in pppd, not particularly
903  * useful for finding out why your connection isn't being established.
904  */
905 #ifdef DEBUGALL
906 #define DEBUGMAIN       1
907 #define DEBUGFSM        1
908 #define DEBUGLCP        1
909 #define DEBUGIPCP       1
910 #define DEBUGIPV6CP     1
911 #define DEBUGUPAP       1
912 #define DEBUGCHAP       1
913 #endif
914
915 #ifndef LOG_PPP                 /* we use LOG_LOCAL2 for syslog by default */
916 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
917   || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
918   || defined(DEBUGCHAP) || defined(DEBUG) || defined(DEBUGIPV6CP)
919 #define LOG_PPP LOG_LOCAL2
920 #else
921 #define LOG_PPP LOG_DAEMON
922 #endif
923 #endif /* LOG_PPP */
924
925 #ifdef DEBUGMAIN
926 #define MAINDEBUG(x)    if (debug) dbglog x
927 #else
928 #define MAINDEBUG(x)
929 #endif
930
931 #ifdef DEBUGSYS
932 #define SYSDEBUG(x)     if (debug) dbglog x
933 #else
934 #define SYSDEBUG(x)
935 #endif
936
937 #ifdef DEBUGFSM
938 #define FSMDEBUG(x)     if (debug) dbglog x
939 #else
940 #define FSMDEBUG(x)
941 #endif
942
943 #ifdef DEBUGLCP
944 #define LCPDEBUG(x)     if (debug) dbglog x
945 #else
946 #define LCPDEBUG(x)
947 #endif
948
949 #ifdef DEBUGIPCP
950 #define IPCPDEBUG(x)    if (debug) dbglog x
951 #else
952 #define IPCPDEBUG(x)
953 #endif
954
955 #ifdef DEBUGIPV6CP
956 #define IPV6CPDEBUG(x)  if (debug) dbglog x
957 #else
958 #define IPV6CPDEBUG(x)
959 #endif
960
961 #ifdef DEBUGUPAP
962 #define UPAPDEBUG(x)    if (debug) dbglog x
963 #else
964 #define UPAPDEBUG(x)
965 #endif
966
967 #ifdef DEBUGCHAP
968 #define CHAPDEBUG(x)    if (debug) dbglog x
969 #else
970 #define CHAPDEBUG(x)
971 #endif
972
973 #ifndef SIGTYPE
974 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
975 #define SIGTYPE void
976 #else
977 #define SIGTYPE int
978 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
979 #endif /* SIGTYPE */
980
981 #ifndef MIN
982 #define MIN(a, b)       ((a) < (b)? (a): (b))
983 #endif
984 #ifndef MAX
985 #define MAX(a, b)       ((a) > (b)? (a): (b))
986 #endif
987
988 #ifndef offsetof
989 #define offsetof(type, member) ((size_t) &((type *)0)->member)
990 #endif
991
992 #endif /* PPP_PPPD_H */