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