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