]> git.ozlabs.org Git - ppp.git/blob - pppd/pppd.h
removed some functions made static and other unused stuff.
[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.32 1999/03/19 01:28:27 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 #define OPT_PRIVFIX     0x800000 /* can't be overridden if noauth */
98
99 #define OPT_VAL(x)      ((x) & OPT_VALUE)
100
101 #ifndef GIDSET_TYPE
102 #define GIDSET_TYPE     gid_t
103 #endif
104
105 /* Structure representing a list of permitted IP addresses. */
106 struct permitted_ip {
107     int         permit;         /* 1 = permit, 0 = forbid */
108     u_int32_t   base;           /* match if (addr & mask) == base */
109     u_int32_t   mask;           /* base and mask are in network byte order */
110 };
111
112 /*
113  * Global variables.
114  */
115
116 extern int      hungup;         /* Physical layer has disconnected */
117 extern int      ifunit;         /* Interface unit number */
118 extern char     ifname[];       /* Interface name */
119 extern int      ttyfd;          /* Serial device file descriptor */
120 extern char     hostname[];     /* Our hostname */
121 extern u_char   outpacket_buf[]; /* Buffer for outgoing packets */
122 extern int      phase;          /* Current state of link - see values below */
123 extern int      baud_rate;      /* Current link speed in bits/sec */
124 extern char     *progname;      /* Name of this program */
125 extern int      redirect_stderr;/* Connector's stderr should go to file */
126 extern char     peer_authname[];/* Authenticated name of peer */
127 extern int      privileged;     /* We were run by real-uid root */
128 extern int      need_holdoff;   /* Need holdoff period after link terminates */
129 extern char     **script_env;   /* Environment variables for scripts */
130 extern int      detached;       /* Have detached from controlling tty */
131 extern GIDSET_TYPE groups[NGROUPS_MAX]; /* groups the user is in */
132 extern int      ngroups;        /* How many groups valid in groups */
133
134 /*
135  * Variables set by command-line options.
136  */
137
138 extern int      debug;          /* Debug flag */
139 extern int      kdebugflag;     /* Tell kernel to print debug messages */
140 extern int      default_device; /* Using /dev/tty or equivalent */
141 extern char     devnam[MAXPATHLEN];     /* Device name */
142 extern int      crtscts;        /* Use hardware flow control */
143 extern bool     modem;          /* Use modem control lines */
144 extern int      inspeed;        /* Input/Output speed requested */
145 extern u_int32_t netmask;       /* IP netmask to set on interface */
146 extern bool     lockflag;       /* Create lock file to lock the serial dev */
147 extern bool     nodetach;       /* Don't detach from controlling tty */
148 extern bool     updetach;       /* Detach from controlling tty when link up */
149 extern char     *connector;     /* Script to establish physical link */
150 extern char     *disconnector;  /* Script to disestablish physical link */
151 extern char     *welcomer;      /* Script to welcome client after connection */
152 extern int      maxconnect;     /* Maximum connect time (seconds) */
153 extern char     user[MAXNAMELEN];/* Our name for authenticating ourselves */
154 extern char     passwd[MAXSECRETLEN];   /* Password for PAP */
155 extern bool     auth_required;  /* Peer is required to authenticate */
156 extern bool     persist;        /* Reopen link after it goes down */
157 extern bool     uselogin;       /* Use /etc/passwd for checking PAP */
158 extern char     our_name[MAXNAMELEN];/* Our name for authentication purposes */
159 extern char     remote_name[MAXNAMELEN]; /* Peer's name for authentication */
160 extern bool     explicit_remote;/* remote_name specified with remotename opt */
161 extern bool     demand;         /* Do dial-on-demand */
162 extern char     *ipparam;       /* Extra parameter for ip up/down scripts */
163 extern bool     cryptpap;       /* Others' PAP passwords are encrypted */
164 extern int      idle_time_limit;/* Shut down link if idle for this long */
165 extern int      holdoff;        /* Dead time before restarting */
166
167 #ifdef PPP_FILTER
168 extern struct   bpf_program pass_filter;   /* Filter for pkts to pass */
169 extern struct   bpf_program active_filter; /* Filter for link-active pkts */
170 #endif
171
172 char *current_option;           /* the name of the option being parsed */
173 int  privileged_option;         /* set iff the current option came from root */
174 char *option_source;            /* string saying where the option came from */
175
176 #ifdef MSLANMAN
177 extern bool     ms_lanman;      /* Use LanMan password instead of NT */
178                                 /* Has meaning only with MS-CHAP challenges */
179 #endif
180
181 /*
182  * Values for phase.
183  */
184 #define PHASE_DEAD              0
185 #define PHASE_INITIALIZE        1
186 #define PHASE_DORMANT           2
187 #define PHASE_ESTABLISH         3
188 #define PHASE_AUTHENTICATE      4
189 #define PHASE_CALLBACK          5
190 #define PHASE_NETWORK           6
191 #define PHASE_TERMINATE         7
192 #define PHASE_HOLDOFF           8
193
194 /*
195  * The following struct gives the addresses of procedures to call
196  * for a particular protocol.
197  */
198 struct protent {
199     u_short protocol;           /* PPP protocol number */
200     /* Initialization procedure */
201     void (*init) __P((int unit));
202     /* Process a received packet */
203     void (*input) __P((int unit, u_char *pkt, int len));
204     /* Process a received protocol-reject */
205     void (*protrej) __P((int unit));
206     /* Lower layer has come up */
207     void (*lowerup) __P((int unit));
208     /* Lower layer has gone down */
209     void (*lowerdown) __P((int unit));
210     /* Open the protocol */
211     void (*open) __P((int unit));
212     /* Close the protocol */
213     void (*close) __P((int unit, char *reason));
214     /* Print a packet in readable form */
215     int  (*printpkt) __P((u_char *pkt, int len,
216                           void (*printer) __P((void *, char *, ...)),
217                           void *arg));
218     /* Process a received data packet */
219     void (*datainput) __P((int unit, u_char *pkt, int len));
220     bool enabled_flag;          /* 0 iff protocol is disabled */
221     char *name;                 /* Text name of protocol */
222     char *data_name;            /* Text name of corresponding data protocol */
223     option_t *options;          /* List of command-line options */
224     /* Check requested options, assign defaults */
225     void (*check_options) __P((void));
226     /* Configure interface for demand-dial */
227     int  (*demand_conf) __P((int unit));
228     /* Say whether to bring up link for this pkt */
229     int  (*active_pkt) __P((u_char *pkt, int len));
230 };
231
232 /* Table of pointers to supported protocols */
233 extern struct protent *protocols[];
234
235 /*
236  * Prototypes.
237  */
238
239 /* Procedures exported from main.c. */
240 void detach __P((void));        /* Detach from controlling tty */
241 void die __P((int));            /* Cleanup and exit */
242 void quit __P((void));          /* like die(1) */
243 void novm __P((char *));        /* Say we ran out of memory, and die */
244 void timeout __P((void (*func)(void *), void *arg, int t));
245                                 /* Call func(arg) after t seconds */
246 void untimeout __P((void (*func)(void *), void *arg));
247                                 /* Cancel call to func(arg) */
248 pid_t run_program __P((char *prog, char **args, int must_exist,
249                        void (*done)(void *), void *arg));
250                                 /* Run program prog with args in child */
251 void demuxprotrej __P((int, int));
252                                 /* Demultiplex a Protocol-Reject */
253 void log_packet __P((u_char *, int, char *, int));
254                                 /* Format a packet and log it with syslog */
255 void print_string __P((char *, int,  void (*) (void *, char *, ...),
256                 void *));       /* Format a string for output */
257 int slprintf __P((char *, int, char *, ...));           /* sprintf++ */
258 int vslprintf __P((char *, int, char *, va_list));      /* vsprintf++ */
259 void script_setenv __P((char *, char *));       /* set script env var */
260 void script_unsetenv __P((char *));             /* unset script env var */
261 size_t strlcpy __P((char *, const char *, size_t));     /* safe strcpy */
262 size_t strlcat __P((char *, const char *, size_t));     /* safe strncpy */
263 void dbglog __P((char *, ...)); /* log a debug message */
264 void info __P((char *, ...));   /* log an informational message */
265 void notice __P((char *, ...)); /* log a notice-level message */
266 void warn __P((char *, ...));   /* log a warning message */
267 void error __P((char *, ...));  /* log an error message */
268 void fatal __P((char *, ...));  /* log an error message and die(1) */
269
270 /* Procedures exported from auth.c */
271 void link_required __P((int));    /* we are starting to use the link */
272 void link_terminated __P((int));  /* we are finished with the link */
273 void link_down __P((int));        /* the LCP layer has left the Opened state */
274 void link_established __P((int)); /* the link is up; authenticate now */
275 void np_up __P((int, int));       /* a network protocol has come up */
276 void np_down __P((int, int));     /* a network protocol has gone down */
277 void np_finished __P((int, int)); /* a network protocol no longer needs link */
278 void auth_peer_fail __P((int, int));
279                                 /* peer failed to authenticate itself */
280 void auth_peer_success __P((int, int, char *, int));
281                                 /* peer successfully authenticated itself */
282 void auth_withpeer_fail __P((int, int));
283                                 /* we failed to authenticate ourselves */
284 void auth_withpeer_success __P((int, int));
285                                 /* we successfully authenticated ourselves */
286 void auth_check_options __P((void));
287                                 /* check authentication options supplied */
288 void auth_reset __P((int));     /* check what secrets we have */
289 int  check_passwd __P((int, char *, int, char *, int, char **, int *));
290                                 /* Check peer-supplied username/password */
291 int  get_secret __P((int, char *, char *, char *, int *, int));
292                                 /* get "secret" for chap */
293 int  auth_ip_addr __P((int, u_int32_t));
294                                 /* check if IP address is authorized */
295 int  bad_ip_adrs __P((u_int32_t));
296                                 /* check if IP address is unreasonable */
297
298 /* Procedures exported from demand.c */
299 void demand_conf __P((void));   /* config interface(s) for demand-dial */
300 void demand_block __P((void));  /* set all NPs to queue up packets */
301 void demand_unblock __P((void)); /* set all NPs to pass packets */
302 void demand_discard __P((void)); /* set all NPs to discard packets */
303 void demand_rexmit __P((int));  /* retransmit saved frames for an NP */
304 int  loop_chars __P((unsigned char *, int)); /* process chars from loopback */
305
306 /* Procedures exported from sys-*.c */
307 void sys_init __P((void));      /* Do system-dependent initialization */
308 void sys_cleanup __P((void));   /* Restore system state before exiting */
309 int  sys_check_options __P((void)); /* Check options specified */
310 void sys_close __P((void));     /* Clean up in a child before execing */
311 int  ppp_available __P((void)); /* Test whether ppp kernel support exists */
312 int  open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */
313 int  establish_ppp __P((int));  /* Turn serial port into a ppp interface */
314 void restore_loop __P((void));  /* Transfer ppp unit back to loopback */
315 void disestablish_ppp __P((int)); /* Restore port to normal operation */
316 void clean_check __P((void));   /* Check if line was 8-bit clean */
317 void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */
318 void restore_tty __P((int));    /* Restore port's original parameters */
319 void setdtr __P((int, int));    /* Raise or lower port's DTR line */
320 void output __P((int, u_char *, int)); /* Output a PPP packet */
321 void wait_input __P((struct timeval *));
322                                 /* Wait for input, with timeout */
323 void add_fd __P((int));         /* Add fd to set to wait for */
324 void remove_fd __P((int));      /* Remove fd from set to wait for */
325 int  read_packet __P((u_char *)); /* Read PPP packet */
326 int  get_loop_output __P((void)); /* Read pkts from loopback */
327 void ppp_send_config __P((int, int, u_int32_t, int, int));
328                                 /* Configure i/f transmit parameters */
329 void ppp_set_xaccm __P((int, ext_accm));
330                                 /* Set extended transmit ACCM */
331 void ppp_recv_config __P((int, int, u_int32_t, int, int));
332                                 /* Configure i/f receive parameters */
333 int  ccp_test __P((int, u_char *, int, int));
334                                 /* Test support for compression scheme */
335 void ccp_flags_set __P((int, int, int));
336                                 /* Set kernel CCP state */
337 int  ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */
338 int  get_idle_time __P((int, struct ppp_idle *));
339                                 /* Find out how long link has been idle */
340 int  sifvjcomp __P((int, int, int, int));
341                                 /* Configure VJ TCP header compression */
342 int  sifup __P((int));          /* Configure i/f up (for IP) */
343 int  sifnpmode __P((int u, int proto, enum NPmode mode));
344                                 /* Set mode for handling packets for proto */
345 int  sifdown __P((int));        /* Configure i/f down (for IP) */
346 int  sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t));
347                                 /* Configure IP addresses for i/f */
348 int  cifaddr __P((int, u_int32_t, u_int32_t));
349                                 /* Reset i/f IP addresses */
350 int  sifdefaultroute __P((int, u_int32_t, u_int32_t));
351                                 /* Create default route through i/f */
352 int  cifdefaultroute __P((int, u_int32_t, u_int32_t));
353                                 /* Delete default route through i/f */
354 int  sifproxyarp __P((int, u_int32_t));
355                                 /* Add proxy ARP entry for peer */
356 int  cifproxyarp __P((int, u_int32_t));
357                                 /* Delete proxy ARP entry for peer */
358 u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */
359 int  lock __P((char *));        /* Create lock file for device */
360 void unlock __P((void));        /* Delete previously-created lock file */
361 int  daemon __P((int, int));    /* Detach us from terminal session */
362 void logwtmp __P((const char *, const char *, const char *));
363                                 /* Write entry to wtmp file */
364 int  get_host_seed __P((void)); /* Get host-dependent random number seed */
365 int  have_route_to __P((u_int32_t)); /* Check if route to addr exists */
366 #ifdef PPP_FILTER
367 int  set_filters __P((struct bpf_program *pass, struct bpf_program *active));
368                                 /* Set filter programs in kernel */
369 #endif
370 #ifdef IPX_CHANGE
371 int  sipxfaddr __P((int, unsigned long, unsigned char *));
372 int  cipxfaddr __P((int));
373 #endif
374
375 /* Procedures exported from options.c */
376 int  parse_args __P((int argc, char **argv));
377                                 /* Parse options from arguments given */
378 int  options_from_file __P((char *filename, int must_exist, int check_prot,
379                             int privileged));
380                                 /* Parse options from an options file */
381 int  options_from_user __P((void)); /* Parse options from user's .ppprc */
382 int  options_for_tty __P((void)); /* Parse options from /etc/ppp/options.tty */
383 void scan_args __P((int argc, char **argv));
384                                 /* Look for tty name in command-line args */
385 int  getword __P((FILE *f, char *word, int *newlinep, char *filename));
386                                 /* Read a word from a file */
387 void option_error __P((char *fmt, ...));
388                                 /* Print an error message about an option */
389 int int_option __P((char *, int *));
390                                 /* Simplified number_option for decimal ints */
391
392 /*
393  * This structure is used to store information about certain
394  * options, such as where the option value came from (/etc/ppp/options,
395  * command line, etc.) and whether it came from a privileged source.
396  */
397
398 struct option_info {
399     int     priv;               /* was value set by sysadmin? */
400     char    *source;            /* where option came from */
401 };
402
403 extern struct option_info devnam_info;
404 extern struct option_info connector_info;
405 extern struct option_info disconnector_info;
406 extern struct option_info welcomer_info;
407
408 /*
409  * Inline versions of get/put char/short/long.
410  * Pointer is advanced; we assume that both arguments
411  * are lvalues and will already be in registers.
412  * cp MUST be u_char *.
413  */
414 #define GETCHAR(c, cp) { \
415         (c) = *(cp)++; \
416 }
417 #define PUTCHAR(c, cp) { \
418         *(cp)++ = (u_char) (c); \
419 }
420
421
422 #define GETSHORT(s, cp) { \
423         (s) = *(cp)++ << 8; \
424         (s) |= *(cp)++; \
425 }
426 #define PUTSHORT(s, cp) { \
427         *(cp)++ = (u_char) ((s) >> 8); \
428         *(cp)++ = (u_char) (s); \
429 }
430
431 #define GETLONG(l, cp) { \
432         (l) = *(cp)++ << 8; \
433         (l) |= *(cp)++; (l) <<= 8; \
434         (l) |= *(cp)++; (l) <<= 8; \
435         (l) |= *(cp)++; \
436 }
437 #define PUTLONG(l, cp) { \
438         *(cp)++ = (u_char) ((l) >> 24); \
439         *(cp)++ = (u_char) ((l) >> 16); \
440         *(cp)++ = (u_char) ((l) >> 8); \
441         *(cp)++ = (u_char) (l); \
442 }
443
444 #define INCPTR(n, cp)   ((cp) += (n))
445 #define DECPTR(n, cp)   ((cp) -= (n))
446
447 /*
448  * System dependent definitions for user-level 4.3BSD UNIX implementation.
449  */
450
451 #define TIMEOUT(r, f, t)        timeout((r), (f), (t))
452 #define UNTIMEOUT(r, f)         untimeout((r), (f))
453
454 #define BCOPY(s, d, l)          memcpy(d, s, l)
455 #define BZERO(s, n)             memset(s, 0, n)
456
457 #define PRINTMSG(m, l)          { info("Remote message: %0.*v", l, m); }
458
459 /*
460  * MAKEHEADER - Add Header fields to a packet.
461  */
462 #define MAKEHEADER(p, t) { \
463     PUTCHAR(PPP_ALLSTATIONS, p); \
464     PUTCHAR(PPP_UI, p); \
465     PUTSHORT(t, p); }
466
467
468 #ifdef DEBUGALL
469 #define DEBUGMAIN       1
470 #define DEBUGFSM        1
471 #define DEBUGLCP        1
472 #define DEBUGIPCP       1
473 #define DEBUGUPAP       1
474 #define DEBUGCHAP       1
475 #endif
476
477 #ifndef LOG_PPP                 /* we use LOG_LOCAL2 for syslog by default */
478 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
479   || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
480   || defined(DEBUGCHAP) || defined(DEBUG)
481 #define LOG_PPP LOG_LOCAL2
482 #else
483 #define LOG_PPP LOG_DAEMON
484 #endif
485 #endif /* LOG_PPP */
486
487 #ifdef DEBUGMAIN
488 #define MAINDEBUG(x)    if (debug) dbglog x
489 #else
490 #define MAINDEBUG(x)
491 #endif
492
493 #ifdef DEBUGSYS
494 #define SYSDEBUG(x)     if (debug) dbglog x
495 #else
496 #define SYSDEBUG(x)
497 #endif
498
499 #ifdef DEBUGFSM
500 #define FSMDEBUG(x)     if (debug) dbglog x
501 #else
502 #define FSMDEBUG(x)
503 #endif
504
505 #ifdef DEBUGLCP
506 #define LCPDEBUG(x)     if (debug) dbglog x
507 #else
508 #define LCPDEBUG(x)
509 #endif
510
511 #ifdef DEBUGIPCP
512 #define IPCPDEBUG(x)    if (debug) dbglog x
513 #else
514 #define IPCPDEBUG(x)
515 #endif
516
517 #ifdef DEBUGUPAP
518 #define UPAPDEBUG(x)    if (debug) dbglog x
519 #else
520 #define UPAPDEBUG(x)
521 #endif
522
523 #ifdef DEBUGCHAP
524 #define CHAPDEBUG(x)    if (debug) dbglog x
525 #else
526 #define CHAPDEBUG(x)
527 #endif
528
529 #ifdef DEBUGIPXCP
530 #define IPXCPDEBUG(x)   if (debug) dbglog x
531 #else
532 #define IPXCPDEBUG(x)
533 #endif
534
535 #ifndef SIGTYPE
536 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
537 #define SIGTYPE void
538 #else
539 #define SIGTYPE int
540 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
541 #endif /* SIGTYPE */
542
543 #ifndef MIN
544 #define MIN(a, b)       ((a) < (b)? (a): (b))
545 #endif
546 #ifndef MAX
547 #define MAX(a, b)       ((a) > (b)? (a): (b))
548 #endif
549
550 #endif /* __PPP_H__ */