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