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