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