]> git.ozlabs.org Git - ppp.git/blob - pppd/pppd.h
3154360016b96d554c57aef6ccab05ce7ec3dbc6
[ppp.git] / pppd / pppd.h
1 /*
2  * pppd.h - PPP daemon global declarations.
3  *
4  * Copyright (c) 1989 Carnegie Mellon University.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are permitted
8  * provided that the above copyright notice and this paragraph are
9  * duplicated in all such forms and that any documentation,
10  * advertising materials, and other materials related to such
11  * distribution and use acknowledge that the software was developed
12  * by Carnegie Mellon University.  The name of the
13  * University may not be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * $Id: pppd.h,v 1.26 1999/03/02 05:59:22 paulus Exp $
20  */
21
22 /*
23  * TODO:
24  */
25
26 #ifndef __PPPD_H__
27 #define __PPPD_H__
28
29 #include <stdio.h>              /* for FILE */
30 #include <sys/param.h>          /* for MAXPATHLEN and BSD4_4, if defined */
31 #include <sys/types.h>          /* for u_int32_t, if defined */
32 #include <sys/time.h>           /* for struct timeval */
33 #include <net/ppp_defs.h>
34
35 #if __STDC__
36 #include <stdarg.h>
37 #define __V(x)  x
38 #else
39 #include <varargs.h>
40 #define __V(x)  (va_alist) va_dcl
41 #define const
42 #endif
43
44 /*
45  * Limits.
46  */
47
48 #define NUM_PPP         1       /* One PPP interface supported (per process) */
49 #define MAXWORDLEN      1024    /* max length of word in file (incl null) */
50 #define MAXARGS         1       /* max # args to a command */
51 #define MAXNAMELEN      256     /* max length of hostname or name for auth */
52 #define MAXSECRETLEN    256     /* max length of password or secret */
53
54 /*
55  * Option descriptor structure.
56  */
57
58 typedef unsigned char   bool;
59
60 enum opt_type {
61         o_special_noarg = 0,
62         o_special = 1,
63         o_bool,
64         o_int,
65         o_uint32,
66         o_string,
67 };
68
69 typedef struct {
70         char    *name;          /* name of the option */
71         enum opt_type type;
72         void    *addr;
73         char    *description;
74         int     flags;
75         void    *addr2;
76         int     upper_limit;
77         int     lower_limit;
78 } option_t;
79
80 /* Values for flags */
81 #define OPT_VALUE       0xff    /* mask for presupplied value */
82 #define OPT_HEX         0x100   /* int option is in hex */
83 #define OPT_NOARG       0x200   /* option doesn't take argument */
84 #define OPT_OR          0x400   /* OR in argument to value */
85 #define OPT_INC         0x800   /* increment value */
86 #define OPT_PRIV        0x1000  /* privileged option */
87 #define OPT_STATIC      0x2000  /* string option goes into static array */
88 #define OPT_LLIMIT      0x4000  /* check value against lower limit */
89 #define OPT_ULIMIT      0x8000  /* check value against upper limit */
90 #define OPT_LIMITS      (OPT_LLIMIT|OPT_ULIMIT)
91 #define OPT_ZEROOK      0x10000 /* 0 value is OK even if not within limits */
92 #define OPT_NOINCR      0x20000 /* value mustn't be increased */
93 #define OPT_ZEROINF     0x40000 /* with OPT_NOINCR, 0 == infinity */
94 #define OPT_A2INFO      0x100000 /* addr2 -> option_info to update */
95 #define OPT_A2COPY      0x200000 /* addr2 -> second location to rcv value */
96 #define OPT_ENABLE      0x400000 /* use *addr2 as enable for option */
97
98 #define OPT_VAL(x)      ((x) & OPT_VALUE)
99
100 /*
101  * Global variables.
102  */
103
104 extern int      hungup;         /* Physical layer has disconnected */
105 extern int      ifunit;         /* Interface unit number */
106 extern char     ifname[];       /* Interface name */
107 extern int      ttyfd;          /* Serial device file descriptor */
108 extern char     hostname[];     /* Our hostname */
109 extern u_char   outpacket_buf[]; /* Buffer for outgoing packets */
110 extern int      phase;          /* Current state of link - see values below */
111 extern int      baud_rate;      /* Current link speed in bits/sec */
112 extern char     *progname;      /* Name of this program */
113 extern int      redirect_stderr;/* Connector's stderr should go to file */
114 extern char     peer_authname[];/* Authenticated name of peer */
115 extern int      privileged;     /* We were run by real-uid root */
116 extern int      need_holdoff;   /* Need holdoff period after link terminates */
117 extern char     **script_env;   /* Environment variables for scripts */
118 extern int      detached;       /* Have detached from controlling tty */
119 extern int      uid;            /* Real user ID of the user running pppd */
120
121 /*
122  * Variables set by command-line options.
123  */
124
125 extern int      debug;          /* Debug flag */
126 extern int      kdebugflag;     /* Tell kernel to print debug messages */
127 extern int      default_device; /* Using /dev/tty or equivalent */
128 extern char     devnam[];       /* Device name */
129 extern int      crtscts;        /* Use hardware flow control */
130 extern bool     modem;          /* Use modem control lines */
131 extern int      inspeed;        /* Input/Output speed requested */
132 extern u_int32_t netmask;       /* IP netmask to set on interface */
133 extern bool     lockflag;       /* Create lock file to lock the serial dev */
134 extern bool     nodetach;       /* Don't detach from controlling tty */
135 extern bool     updetach;       /* Detach from controlling tty when link up */
136 extern char     *connector;     /* Script to establish physical link */
137 extern char     *disconnector;  /* Script to disestablish physical link */
138 extern char     *welcomer;      /* Script to welcome client after connection */
139 extern int      maxconnect;     /* Maximum connect time (seconds) */
140 extern char     user[];         /* Our name for authenticating ourselves */
141 extern char     passwd[];       /* Password for PAP */
142 extern bool     auth_required;  /* Peer is required to authenticate */
143 extern bool     persist;        /* Reopen link after it goes down */
144 extern bool     uselogin;       /* Use /etc/passwd for checking PAP */
145 extern char     our_name[];     /* Our name for authentication purposes */
146 extern char     remote_name[];  /* Peer's name for authentication */
147 extern int      explicit_remote;/* remote_name specified with remotename opt */
148 extern bool     demand;         /* Do dial-on-demand */
149 extern char     *ipparam;       /* Extra parameter for ip up/down scripts */
150 extern bool     cryptpap;       /* Others' PAP passwords are encrypted */
151 extern int      idle_time_limit;/* Shut down link if idle for this long */
152 extern int      holdoff;        /* Dead time before restarting */
153 #ifdef PPP_FILTER
154 extern struct   bpf_program pass_filter;   /* Filter for pkts to pass */
155 extern struct   bpf_program active_filter; /* Filter for link-active pkts */
156 #endif
157
158 char *current_option;           /* the name of the option being parsed */
159 int  privileged_option;         /* set iff the current option came from root */
160 char *option_source;            /* string saying where the option came from */
161
162 #ifdef MSLANMAN
163 extern bool     ms_lanman;      /* Use LanMan password instead of NT */
164                                 /* Has meaning only with MS-CHAP challenges */
165 #endif
166
167 /*
168  * Values for phase.
169  */
170 #define PHASE_DEAD              0
171 #define PHASE_INITIALIZE        1
172 #define PHASE_DORMANT           2
173 #define PHASE_ESTABLISH         3
174 #define PHASE_AUTHENTICATE      4
175 #define PHASE_CALLBACK          5
176 #define PHASE_NETWORK           6
177 #define PHASE_TERMINATE         7
178 #define PHASE_HOLDOFF           8
179
180 /*
181  * The following struct gives the addresses of procedures to call
182  * for a particular protocol.
183  */
184 struct protent {
185     u_short protocol;           /* PPP protocol number */
186     /* Initialization procedure */
187     void (*init) __P((int unit));
188     /* Process a received packet */
189     void (*input) __P((int unit, u_char *pkt, int len));
190     /* Process a received protocol-reject */
191     void (*protrej) __P((int unit));
192     /* Lower layer has come up */
193     void (*lowerup) __P((int unit));
194     /* Lower layer has gone down */
195     void (*lowerdown) __P((int unit));
196     /* Open the protocol */
197     void (*open) __P((int unit));
198     /* Close the protocol */
199     void (*close) __P((int unit, char *reason));
200     /* Print a packet in readable form */
201     int  (*printpkt) __P((u_char *pkt, int len,
202                           void (*printer) __P((void *, char *, ...)),
203                           void *arg));
204     /* Process a received data packet */
205     void (*datainput) __P((int unit, u_char *pkt, int len));
206     bool enabled_flag;          /* 0 iff protocol is disabled */
207     char *name;                 /* Text name of protocol */
208     option_t *options;          /* List of command-line options */
209     /* Check requested options, assign defaults */
210     void (*check_options) __P((void));
211     /* Configure interface for demand-dial */
212     int  (*demand_conf) __P((int unit));
213     /* Say whether to bring up link for this pkt */
214     int  (*active_pkt) __P((u_char *pkt, int len));
215 };
216
217 /* Table of pointers to supported protocols */
218 extern struct protent *protocols[];
219
220 /*
221  * Prototypes.
222  */
223
224 /* Procedures exported from main.c. */
225 void detach __P((void));        /* Detach from controlling tty */
226 void die __P((int));            /* Cleanup and exit */
227 void quit __P((void));          /* like die(1) */
228 void novm __P((char *));        /* Say we ran out of memory, and die */
229 void timeout __P((void (*func)(void *), void *arg, int t));
230                                 /* Call func(arg) after t seconds */
231 void untimeout __P((void (*func)(void *), void *arg));
232                                 /* Cancel call to func(arg) */
233 pid_t run_program __P((char *prog, char **args, int must_exist,
234                        void (*done)(void *), void *arg));
235                                 /* Run program prog with args in child */
236 void demuxprotrej __P((int, int));
237                                 /* Demultiplex a Protocol-Reject */
238 void format_packet __P((u_char *, int, void (*) (void *, char *, ...),
239                 void *));       /* Format a packet in human-readable form */
240 void log_packet __P((u_char *, int, char *, int));
241                                 /* Format a packet and log it with syslog */
242 void print_string __P((char *, int,  void (*) (void *, char *, ...),
243                 void *));       /* Format a string for output */
244 int fmtmsg __P((char *, int, char *, ...));             /* sprintf++ */
245 int vfmtmsg __P((char *, int, char *, va_list));        /* vsprintf++ */
246 void script_setenv __P((char *, char *));       /* set script env var */
247 void script_unsetenv __P((char *));             /* unset script env var */
248
249 /* Procedures exported from auth.c */
250 void link_required __P((int));    /* we are starting to use the link */
251 void link_terminated __P((int));  /* we are finished with the link */
252 void link_down __P((int));        /* the LCP layer has left the Opened state */
253 void link_established __P((int)); /* the link is up; authenticate now */
254 void np_up __P((int, int));       /* a network protocol has come up */
255 void np_down __P((int, int));     /* a network protocol has gone down */
256 void np_finished __P((int, int)); /* a network protocol no longer needs link */
257 void auth_peer_fail __P((int, int));
258                                 /* peer failed to authenticate itself */
259 void auth_peer_success __P((int, int, char *, int));
260                                 /* peer successfully authenticated itself */
261 void auth_withpeer_fail __P((int, int));
262                                 /* we failed to authenticate ourselves */
263 void auth_withpeer_success __P((int, int));
264                                 /* we successfully authenticated ourselves */
265 void auth_check_options __P((void));
266                                 /* check authentication options supplied */
267 void auth_reset __P((int));     /* check what secrets we have */
268 int  check_passwd __P((int, char *, int, char *, int, char **, int *));
269                                 /* Check peer-supplied username/password */
270 int  get_secret __P((int, char *, char *, char *, int *, int));
271                                 /* get "secret" for chap */
272 int  auth_ip_addr __P((int, u_int32_t));
273                                 /* check if IP address is authorized */
274 int  bad_ip_adrs __P((u_int32_t));
275                                 /* check if IP address is unreasonable */
276 void check_access __P((FILE *, char *));
277                                 /* check permissions on secrets file */
278
279 /* Procedures exported from demand.c */
280 void demand_conf __P((void));   /* config interface(s) for demand-dial */
281 void demand_block __P((void));  /* set all NPs to queue up packets */
282 void demand_unblock __P((void)); /* set all NPs to pass packets */
283 void demand_discard __P((void)); /* set all NPs to discard packets */
284 void demand_rexmit __P((int));  /* retransmit saved frames for an NP */
285 int  loop_chars __P((unsigned char *, int)); /* process chars from loopback */
286 int  loop_frame __P((unsigned char *, int)); /* process frame from loopback */
287
288 /* Procedures exported from sys-*.c */
289 void sys_init __P((void));      /* Do system-dependent initialization */
290 void sys_cleanup __P((void));   /* Restore system state before exiting */
291 int  sys_check_options __P((void)); /* Check options specified */
292 void sys_close __P((void));     /* Clean up in a child before execing */
293 int  ppp_available __P((void)); /* Test whether ppp kernel support exists */
294 void open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */
295 void establish_ppp __P((int));  /* Turn serial port into a ppp interface */
296 void restore_loop __P((void));  /* Transfer ppp unit back to loopback */
297 void disestablish_ppp __P((int)); /* Restore port to normal operation */
298 void clean_check __P((void));   /* Check if line was 8-bit clean */
299 void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */
300 void restore_tty __P((int));    /* Restore port's original parameters */
301 void setdtr __P((int, int));    /* Raise or lower port's DTR line */
302 void output __P((int, u_char *, int)); /* Output a PPP packet */
303 void wait_input __P((struct timeval *));
304                                 /* Wait for input, with timeout */
305 void wait_loop_output __P((struct timeval *));
306                                 /* Wait for pkt from loopback, with timeout */
307 void wait_time __P((struct timeval *)); /* Wait for given length of time */
308 int  read_packet __P((u_char *)); /* Read PPP packet */
309 int  get_loop_output __P((void)); /* Read pkts from loopback */
310 void ppp_send_config __P((int, int, u_int32_t, int, int));
311                                 /* Configure i/f transmit parameters */
312 void ppp_set_xaccm __P((int, ext_accm));
313                                 /* Set extended transmit ACCM */
314 void ppp_recv_config __P((int, int, u_int32_t, int, int));
315                                 /* Configure i/f receive parameters */
316 int  ccp_test __P((int, u_char *, int, int));
317                                 /* Test support for compression scheme */
318 void ccp_flags_set __P((int, int, int));
319                                 /* Set kernel CCP state */
320 int  ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */
321 int  get_idle_time __P((int, struct ppp_idle *));
322                                 /* Find out how long link has been idle */
323 int  sifvjcomp __P((int, int, int, int));
324                                 /* Configure VJ TCP header compression */
325 int  sifup __P((int));          /* Configure i/f up (for IP) */
326 int  sifnpmode __P((int u, int proto, enum NPmode mode));
327                                 /* Set mode for handling packets for proto */
328 int  sifdown __P((int));        /* Configure i/f down (for IP) */
329 int  sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t));
330                                 /* Configure IP addresses for i/f */
331 int  cifaddr __P((int, u_int32_t, u_int32_t));
332                                 /* Reset i/f IP addresses */
333 int  sifdefaultroute __P((int, u_int32_t, u_int32_t));
334                                 /* Create default route through i/f */
335 int  cifdefaultroute __P((int, u_int32_t, u_int32_t));
336                                 /* Delete default route through i/f */
337 int  sifproxyarp __P((int, u_int32_t));
338                                 /* Add proxy ARP entry for peer */
339 int  cifproxyarp __P((int, u_int32_t));
340                                 /* Delete proxy ARP entry for peer */
341 u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */
342 int  lock __P((char *));        /* Create lock file for device */
343 void unlock __P((void));        /* Delete previously-created lock file */
344 int  daemon __P((int, int));    /* Detach us from terminal session */
345 void logwtmp __P((const char *, const char *, const char *));
346                                 /* Write entry to wtmp file */
347 int  get_host_seed __P((void)); /* Get host-dependent random number seed */
348 int  have_route_to __P((u_int32_t)); /* Check if route to addr exists */
349 void hangup_modem __P((int));   /* Make modem hang up */
350 #ifdef PPP_FILTER
351 int  set_filters __P((struct bpf_program *pass, struct bpf_program *active));
352                                 /* Set filter programs in kernel */
353 #endif
354 #ifdef IPX_CHANGE
355 int  sipxfaddr __P((int, unsigned long, unsigned char *));
356 int  cipxfaddr __P((int));
357 #endif
358
359 /* Procedures exported from options.c */
360 int  parse_args __P((int argc, char **argv));
361                                 /* Parse options from arguments given */
362 void usage __P((void));         /* Print a usage message */
363 int  options_from_file __P((char *filename, int must_exist, int check_prot,
364                             int privileged));
365                                 /* Parse options from an options file */
366 int  options_from_user __P((void)); /* Parse options from user's .ppprc */
367 int  options_for_tty __P((void)); /* Parse options from /etc/ppp/options.tty */
368 void scan_args __P((int argc, char **argv));
369                                 /* Look for tty name in command-line args */
370 int  getword __P((FILE *f, char *word, int *newlinep, char *filename));
371                                 /* Read a word from a file */
372 void option_error __P((char *fmt, ...));
373                                 /* Print an error message about an option */
374 int readable __P((int fd));     /* Is fd readable by real user? */
375 int number_option __P((char *, u_int32_t *, int));
376                                 /* Parse a numerical option */
377 int int_option __P((char *, int *));
378                                 /* Simplified number_option for decimal ints */
379
380 /*
381  * This structure is used to store information about certain
382  * options, such as where the option value came from (/etc/ppp/options,
383  * command line, etc.) and whether it came from a privileged source.
384  */
385
386 struct option_info {
387     int     priv;               /* was value set by sysadmin? */
388     char    *source;            /* where option came from */
389 };
390
391 extern struct option_info devnam_info;
392 extern struct option_info connector_info;
393 extern struct option_info disconnector_info;
394 extern struct option_info welcomer_info;
395
396 /*
397  * Inline versions of get/put char/short/long.
398  * Pointer is advanced; we assume that both arguments
399  * are lvalues and will already be in registers.
400  * cp MUST be u_char *.
401  */
402 #define GETCHAR(c, cp) { \
403         (c) = *(cp)++; \
404 }
405 #define PUTCHAR(c, cp) { \
406         *(cp)++ = (u_char) (c); \
407 }
408
409
410 #define GETSHORT(s, cp) { \
411         (s) = *(cp)++ << 8; \
412         (s) |= *(cp)++; \
413 }
414 #define PUTSHORT(s, cp) { \
415         *(cp)++ = (u_char) ((s) >> 8); \
416         *(cp)++ = (u_char) (s); \
417 }
418
419 #define GETLONG(l, cp) { \
420         (l) = *(cp)++ << 8; \
421         (l) |= *(cp)++; (l) <<= 8; \
422         (l) |= *(cp)++; (l) <<= 8; \
423         (l) |= *(cp)++; \
424 }
425 #define PUTLONG(l, cp) { \
426         *(cp)++ = (u_char) ((l) >> 24); \
427         *(cp)++ = (u_char) ((l) >> 16); \
428         *(cp)++ = (u_char) ((l) >> 8); \
429         *(cp)++ = (u_char) (l); \
430 }
431
432 #define INCPTR(n, cp)   ((cp) += (n))
433 #define DECPTR(n, cp)   ((cp) -= (n))
434
435 #undef  FALSE
436 #define FALSE   0
437 #undef  TRUE
438 #define TRUE    1
439
440 /*
441  * System dependent definitions for user-level 4.3BSD UNIX implementation.
442  */
443
444 #define DEMUXPROTREJ(u, p)      demuxprotrej(u, p)
445
446 #define TIMEOUT(r, f, t)        timeout((r), (f), (t))
447 #define UNTIMEOUT(r, f)         untimeout((r), (f))
448
449 #define BCOPY(s, d, l)          memcpy(d, s, l)
450 #define BZERO(s, n)             memset(s, 0, n)
451 #define EXIT(u)                 quit()
452
453 #define PRINTMSG(m, l)  { m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); }
454
455 /*
456  * MAKEHEADER - Add Header fields to a packet.
457  */
458 #define MAKEHEADER(p, t) { \
459     PUTCHAR(PPP_ALLSTATIONS, p); \
460     PUTCHAR(PPP_UI, p); \
461     PUTSHORT(t, p); }
462
463
464 #ifdef DEBUGALL
465 #define DEBUGMAIN       1
466 #define DEBUGFSM        1
467 #define DEBUGLCP        1
468 #define DEBUGIPCP       1
469 #define DEBUGUPAP       1
470 #define DEBUGCHAP       1
471 #endif
472
473 #ifndef LOG_PPP                 /* we use LOG_LOCAL2 for syslog by default */
474 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
475   || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
476   || defined(DEBUGCHAP) || defined(DEBUG)
477 #define LOG_PPP LOG_LOCAL2
478 #else
479 #define LOG_PPP LOG_DAEMON
480 #endif
481 #endif /* LOG_PPP */
482
483 #ifdef DEBUGMAIN
484 #define MAINDEBUG(x)    if (debug) syslog x
485 #else
486 #define MAINDEBUG(x)
487 #endif
488
489 #ifdef DEBUGSYS
490 #define SYSDEBUG(x)     if (debug) syslog x
491 #else
492 #define SYSDEBUG(x)
493 #endif
494
495 #ifdef DEBUGFSM
496 #define FSMDEBUG(x)     if (debug) syslog x
497 #else
498 #define FSMDEBUG(x)
499 #endif
500
501 #ifdef DEBUGLCP
502 #define LCPDEBUG(x)     if (debug) syslog x
503 #else
504 #define LCPDEBUG(x)
505 #endif
506
507 #ifdef DEBUGIPCP
508 #define IPCPDEBUG(x)    if (debug) syslog x
509 #else
510 #define IPCPDEBUG(x)
511 #endif
512
513 #ifdef DEBUGUPAP
514 #define UPAPDEBUG(x)    if (debug) syslog x
515 #else
516 #define UPAPDEBUG(x)
517 #endif
518
519 #ifdef DEBUGCHAP
520 #define CHAPDEBUG(x)    if (debug) syslog x
521 #else
522 #define CHAPDEBUG(x)
523 #endif
524
525 #ifdef DEBUGIPXCP
526 #define IPXCPDEBUG(x)   if (debug) syslog x
527 #else
528 #define IPXCPDEBUG(x)
529 #endif
530
531 #ifndef SIGTYPE
532 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
533 #define SIGTYPE void
534 #else
535 #define SIGTYPE int
536 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
537 #endif /* SIGTYPE */
538
539 #ifndef MIN
540 #define MIN(a, b)       ((a) < (b)? (a): (b))
541 #endif
542 #ifndef MAX
543 #define MAX(a, b)       ((a) > (b)? (a): (b))
544 #endif
545
546 #endif /* __PPP_H__ */