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