]> git.ozlabs.org Git - ppp.git/blob - pppd/pppd.h
59b98d023bd111d4786711e5434b74cf5aaced31
[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.18 1997/03/04 03:42:48 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  * Global variables.
56  */
57
58 extern int      hungup;         /* Physical layer has disconnected */
59 extern int      ifunit;         /* Interface unit number */
60 extern char     ifname[];       /* Interface name */
61 extern int      ttyfd;          /* Serial device file descriptor */
62 extern char     hostname[];     /* Our hostname */
63 extern u_char   outpacket_buf[]; /* Buffer for outgoing packets */
64 extern int      phase;          /* Current state of link - see values below */
65 extern int      baud_rate;      /* Current link speed in bits/sec */
66 extern char     *progname;      /* Name of this program */
67 extern int      redirect_stderr;/* Connector's stderr should go to file */
68 extern char     peer_authname[];/* Authenticated name of peer */
69 extern int      privileged;     /* We were run by real-uid root */
70 extern int      need_holdoff;   /* Need holdoff period after link terminates */
71
72 /*
73  * Variables set by command-line options.
74  */
75
76 extern int      debug;          /* Debug flag */
77 extern int      kdebugflag;     /* Tell kernel to print debug messages */
78 extern int      default_device; /* Using /dev/tty or equivalent */
79 extern char     devnam[];       /* Device name */
80 extern int      crtscts;        /* Use hardware flow control */
81 extern int      modem;          /* Use modem control lines */
82 extern int      inspeed;        /* Input/Output speed requested */
83 extern u_int32_t netmask;       /* IP netmask to set on interface */
84 extern int      lockflag;       /* Create lock file to lock the serial dev */
85 extern int      nodetach;       /* Don't detach from controlling tty */
86 extern char     *connector;     /* Script to establish physical link */
87 extern char     *disconnector;  /* Script to disestablish physical link */
88 extern char     *welcomer;      /* Script to welcome client after connection */
89 extern int      maxconnect;     /* Maximum connect time (seconds) */
90 extern char     user[];         /* Our name for authenticating ourselves */
91 extern char     passwd[];       /* Password for PAP */
92 extern int      auth_required;  /* Peer is required to authenticate */
93 extern int      proxyarp;       /* Set up proxy ARP entry for peer */
94 extern int      persist;        /* Reopen link after it goes down */
95 extern int      uselogin;       /* Use /etc/passwd for checking PAP */
96 extern int      lcp_echo_interval; /* Interval between LCP echo-requests */
97 extern int      lcp_echo_fails; /* Tolerance to unanswered echo-requests */
98 extern char     our_name[];     /* Our name for authentication purposes */
99 extern char     remote_name[];  /* Peer's name for authentication */
100 extern int      usehostname;    /* Use hostname for our_name */
101 extern int      disable_defaultip; /* Don't use hostname for default IP adrs */
102 extern int      demand;         /* Do dial-on-demand */
103 extern char     *ipparam;       /* Extra parameter for ip up/down scripts */
104 extern int      cryptpap;       /* Others' PAP passwords are encrypted */
105 extern int      idle_time_limit;/* Shut down link if idle for this long */
106 extern int      holdoff;        /* Dead time before restarting */
107 extern int      refuse_pap;     /* Don't wanna auth. ourselves with PAP */
108 extern int      refuse_chap;    /* Don't wanna auth. ourselves with CHAP */
109
110 /*
111  * Values for phase.
112  */
113 #define PHASE_DEAD              0
114 #define PHASE_INITIALIZE        1
115 #define PHASE_DORMANT           2
116 #define PHASE_ESTABLISH         3
117 #define PHASE_AUTHENTICATE      4
118 #define PHASE_CALLBACK          5
119 #define PHASE_NETWORK           6
120 #define PHASE_TERMINATE         7
121 #define PHASE_HOLDOFF           8
122
123 /*
124  * The following struct gives the addresses of procedures to call
125  * for a particular protocol.
126  */
127 struct protent {
128     u_short protocol;           /* PPP protocol number */
129     /* Initialization procedure */
130     void (*init) __P((int unit));
131     /* Process a received packet */
132     void (*input) __P((int unit, u_char *pkt, int len));
133     /* Process a received protocol-reject */
134     void (*protrej) __P((int unit));
135     /* Lower layer has come up */
136     void (*lowerup) __P((int unit));
137     /* Lower layer has gone down */
138     void (*lowerdown) __P((int unit));
139     /* Open the protocol */
140     void (*open) __P((int unit));
141     /* Close the protocol */
142     void (*close) __P((int unit, char *reason));
143     /* Print a packet in readable form */
144     int  (*printpkt) __P((u_char *pkt, int len,
145                           void (*printer) __P((void *, char *, ...)),
146                           void *arg));
147     /* Process a received data packet */
148     void (*datainput) __P((int unit, u_char *pkt, int len));
149     int  enabled_flag;          /* 0 iff protocol is disabled */
150     char *name;                 /* Text name of protocol */
151     /* Check requested options, assign defaults */
152     void (*check_options) __P((void));
153     /* Configure interface for demand-dial */
154     int  (*demand_conf) __P((int unit));
155     /* Say whether to bring up link for this pkt */
156     int  (*active_pkt) __P((u_char *pkt, int len));
157 };
158
159 /* Table of pointers to supported protocols */
160 extern struct protent *protocols[];
161
162 /*
163  * Prototypes.
164  */
165
166 /* Procedures exported from main.c. */
167 void die __P((int));            /* Cleanup and exit */
168 void quit __P((void));          /* like die(1) */
169 void novm __P((char *));        /* Say we ran out of memory, and die */
170 void timeout __P((void (*func)(), caddr_t arg, int t));
171                                 /* Call func(arg) after t seconds */
172 void untimeout __P((void (*func)(), caddr_t arg));
173                                 /* Cancel call to func(arg) */
174 int run_program __P((char *prog, char **args, int must_exist));
175                                 /* Run program prog with args in child */
176 void demuxprotrej __P((int, int));
177                                 /* Demultiplex a Protocol-Reject */
178 void format_packet __P((u_char *, int, void (*) (void *, char *, ...),
179                 void *));       /* Format a packet in human-readable form */
180 void log_packet __P((u_char *, int, char *));
181                                 /* Format a packet and log it with syslog */
182 void print_string __P((char *, int,  void (*) (void *, char *, ...),
183                 void *));       /* Format a string for output */
184 int fmtmsg __P((char *, int, char *, ...));             /* sprintf++ */
185 int vfmtmsg __P((char *, int, char *, va_list));        /* vsprintf++ */
186
187 /* Procedures exported from auth.c */
188 void link_required __P((int));    /* we are starting to use the link */
189 void link_terminated __P((int));  /* we are finished with the link */
190 void link_down __P((int));        /* the LCP layer has left the Opened state */
191 void link_established __P((int)); /* the link is up; authenticate now */
192 void np_up __P((int, int));       /* a network protocol has come up */
193 void np_down __P((int, int));     /* a network protocol has gone down */
194 void np_finished __P((int, int)); /* a network protocol no longer needs link */
195 void auth_peer_fail __P((int, int));
196                                 /* peer failed to authenticate itself */
197 void auth_peer_success __P((int, int, char *, int));
198                                 /* peer successfully authenticated itself */
199 void auth_withpeer_fail __P((int, int));
200                                 /* we failed to authenticate ourselves */
201 void auth_withpeer_success __P((int, int));
202                                 /* we successfully authenticated ourselves */
203 void auth_check_options __P((void));
204                                 /* check authentication options supplied */
205 void auth_reset __P((int));     /* check what secrets we have */
206 int  check_passwd __P((int, char *, int, char *, int, char **, int *));
207                                 /* Check peer-supplied username/password */
208 int  get_secret __P((int, char *, char *, char *, int *, int));
209                                 /* get "secret" for chap */
210 int  auth_ip_addr __P((int, u_int32_t));
211                                 /* check if IP address is authorized */
212 int  bad_ip_adrs __P((u_int32_t));
213                                 /* check if IP address is unreasonable */
214 void check_access __P((FILE *, char *));
215                                 /* check permissions on secrets file */
216
217 /* Procedures exported from demand.c */
218 void demand_conf __P((void));   /* config interface(s) for demand-dial */
219 void demand_block __P((void));  /* set all NPs to queue up packets */
220 void demand_unblock __P((void)); /* set all NPs to pass packets */
221 void demand_discard __P((void)); /* set all NPs to discard packets */
222 void demand_rexmit __P((int));  /* retransmit saved frames for an NP */
223 int  loop_chars __P((unsigned char *, int)); /* process chars from loopback */
224 int  loop_frame __P((unsigned char *, int)); /* process frame from loopback */
225
226 /* Procedures exported from sys-*.c */
227 void sys_init __P((void));      /* Do system-dependent initialization */
228 void sys_cleanup __P((void));   /* Restore system state before exiting */
229 void sys_check_options __P((void)); /* Check options specified */
230 void sys_close __P((void));     /* Clean up in a child before execing */
231 int  ppp_available __P((void)); /* Test whether ppp kernel support exists */
232 void open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */
233 void establish_ppp __P((int));  /* Turn serial port into a ppp interface */
234 void restore_loop __P((void));  /* Transfer ppp unit back to loopback */
235 void disestablish_ppp __P((int)); /* Restore port to normal operation */
236 void clean_check __P((void));   /* Check if line was 8-bit clean */
237 void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */
238 void restore_tty __P((int));    /* Restore port's original parameters */
239 void setdtr __P((int, int));    /* Raise or lower port's DTR line */
240 void output __P((int, u_char *, int)); /* Output a PPP packet */
241 void wait_input __P((struct timeval *));
242                                 /* Wait for input, with timeout */
243 void wait_loop_output __P((struct timeval *));
244                                 /* Wait for pkt from loopback, with timeout */
245 void wait_time __P((struct timeval *)); /* Wait for given length of time */
246 int  read_packet __P((u_char *)); /* Read PPP packet */
247 int  get_loop_output __P((void)); /* Read pkts from loopback */
248 void ppp_send_config __P((int, int, u_int32_t, int, int));
249                                 /* Configure i/f transmit parameters */
250 void ppp_set_xaccm __P((int, ext_accm));
251                                 /* Set extended transmit ACCM */
252 void ppp_recv_config __P((int, int, u_int32_t, int, int));
253                                 /* Configure i/f receive parameters */
254 int  ccp_test __P((int, u_char *, int, int));
255                                 /* Test support for compression scheme */
256 void ccp_flags_set __P((int, int, int));
257                                 /* Set kernel CCP state */
258 int  ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */
259 int  get_idle_time __P((int, struct ppp_idle *));
260                                 /* Find out how long link has been idle */
261 int  sifvjcomp __P((int, int, int, int));
262                                 /* Configure VJ TCP header compression */
263 int  sifup __P((int));          /* Configure i/f up (for IP) */
264 int  sifnpmode __P((int u, int proto, enum NPmode mode));
265                                 /* Set mode for handling packets for proto */
266 int  sifdown __P((int));        /* Configure i/f down (for IP) */
267 int  sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t));
268                                 /* Configure IP addresses for i/f */
269 int  cifaddr __P((int, u_int32_t, u_int32_t));
270                                 /* Reset i/f IP addresses */
271 int  sifdefaultroute __P((int, u_int32_t, u_int32_t));
272                                 /* Create default route through i/f */
273 int  cifdefaultroute __P((int, u_int32_t, u_int32_t));
274                                 /* Delete default route through i/f */
275 int  sifproxyarp __P((int, u_int32_t));
276                                 /* Add proxy ARP entry for peer */
277 int  cifproxyarp __P((int, u_int32_t));
278                                 /* Delete proxy ARP entry for peer */
279 u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */
280 int  lock __P((char *));        /* Create lock file for device */
281 void unlock __P((void));        /* Delete previously-created lock file */
282 int  daemon __P((int, int));    /* Detach us from terminal session */
283 void logwtmp __P((const char *, const char *, const char *));
284                                 /* Write entry to wtmp file */
285
286 /* Procedures exported from options.c */
287 int  parse_args __P((int argc, char **argv));
288                                 /* Parse options from arguments given */
289 void usage __P((void));         /* Print a usage message */
290 int  options_from_file __P((char *filename, int must_exist, int check_prot,
291                             int privileged));
292                                 /* Parse options from an options file */
293 int  options_from_user __P((void)); /* Parse options from user's .ppprc */
294 int  options_for_tty __P((void)); /* Parse options from /etc/ppp/options.tty */
295 void scan_args __P((int argc, char **argv));
296                                 /* Look for tty name in command-line args */
297 int  getword __P((FILE *f, char *word, int *newlinep, char *filename));
298                                 /* Read a word from a file */
299 void option_error __P((char *fmt, ...));
300                                 /* Print an error message about an option */
301
302 /*
303  * This structure is used to store information about certain
304  * options, such as where the option value came from (/etc/ppp/options,
305  * command line, etc.) and whether it came from a privileged source.
306  */
307
308 struct option_info {
309     int     priv;               /* was value set by sysadmin? */
310     char    *source;            /* where option came from */
311 };
312
313 extern struct option_info auth_req_info;
314 extern struct option_info connector_info;
315 extern struct option_info disconnector_info;
316 extern struct option_info welcomer_info;
317 extern struct option_info devnam_info;
318
319 /*
320  * Inline versions of get/put char/short/long.
321  * Pointer is advanced; we assume that both arguments
322  * are lvalues and will already be in registers.
323  * cp MUST be u_char *.
324  */
325 #define GETCHAR(c, cp) { \
326         (c) = *(cp)++; \
327 }
328 #define PUTCHAR(c, cp) { \
329         *(cp)++ = (u_char) (c); \
330 }
331
332
333 #define GETSHORT(s, cp) { \
334         (s) = *(cp)++ << 8; \
335         (s) |= *(cp)++; \
336 }
337 #define PUTSHORT(s, cp) { \
338         *(cp)++ = (u_char) ((s) >> 8); \
339         *(cp)++ = (u_char) (s); \
340 }
341
342 #define GETLONG(l, cp) { \
343         (l) = *(cp)++ << 8; \
344         (l) |= *(cp)++; (l) <<= 8; \
345         (l) |= *(cp)++; (l) <<= 8; \
346         (l) |= *(cp)++; \
347 }
348 #define PUTLONG(l, cp) { \
349         *(cp)++ = (u_char) ((l) >> 24); \
350         *(cp)++ = (u_char) ((l) >> 16); \
351         *(cp)++ = (u_char) ((l) >> 8); \
352         *(cp)++ = (u_char) (l); \
353 }
354
355 #define INCPTR(n, cp)   ((cp) += (n))
356 #define DECPTR(n, cp)   ((cp) -= (n))
357
358 #undef  FALSE
359 #define FALSE   0
360 #undef  TRUE
361 #define TRUE    1
362
363 /*
364  * System dependent definitions for user-level 4.3BSD UNIX implementation.
365  */
366
367 #define DEMUXPROTREJ(u, p)      demuxprotrej(u, p)
368
369 #define TIMEOUT(r, f, t)        timeout((r), (f), (t))
370 #define UNTIMEOUT(r, f)         untimeout((r), (f))
371
372 #define BCOPY(s, d, l)          memcpy(d, s, l)
373 #define BZERO(s, n)             memset(s, 0, n)
374 #define EXIT(u)                 quit()
375
376 #define PRINTMSG(m, l)  { m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); }
377
378 /*
379  * MAKEHEADER - Add Header fields to a packet.
380  */
381 #define MAKEHEADER(p, t) { \
382     PUTCHAR(PPP_ALLSTATIONS, p); \
383     PUTCHAR(PPP_UI, p); \
384     PUTSHORT(t, p); }
385
386
387 #ifdef DEBUGALL
388 #define DEBUGMAIN       1
389 #define DEBUGFSM        1
390 #define DEBUGLCP        1
391 #define DEBUGIPCP       1
392 #define DEBUGUPAP       1
393 #define DEBUGCHAP       1
394 #endif
395
396 #ifndef LOG_PPP                 /* we use LOG_LOCAL2 for syslog by default */
397 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
398   || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
399   || defined(DEBUGCHAP) || defined(DEBUG)
400 #define LOG_PPP LOG_LOCAL2
401 #else
402 #define LOG_PPP LOG_DAEMON
403 #endif
404 #endif /* LOG_PPP */
405
406 #ifdef DEBUGMAIN
407 #define MAINDEBUG(x)    if (debug) syslog x
408 #else
409 #define MAINDEBUG(x)
410 #endif
411
412 #ifdef DEBUGSYS
413 #define SYSDEBUG(x)     if (debug) syslog x
414 #else
415 #define SYSDEBUG(x)
416 #endif
417
418 #ifdef DEBUGFSM
419 #define FSMDEBUG(x)     if (debug) syslog x
420 #else
421 #define FSMDEBUG(x)
422 #endif
423
424 #ifdef DEBUGLCP
425 #define LCPDEBUG(x)     if (debug) syslog x
426 #else
427 #define LCPDEBUG(x)
428 #endif
429
430 #ifdef DEBUGIPCP
431 #define IPCPDEBUG(x)    if (debug) syslog x
432 #else
433 #define IPCPDEBUG(x)
434 #endif
435
436 #ifdef DEBUGUPAP
437 #define UPAPDEBUG(x)    if (debug) syslog x
438 #else
439 #define UPAPDEBUG(x)
440 #endif
441
442 #ifdef DEBUGCHAP
443 #define CHAPDEBUG(x)    if (debug) syslog x
444 #else
445 #define CHAPDEBUG(x)
446 #endif
447
448 #ifdef DEBUGIPXCP
449 #define IPXCPDEBUG(x)   if (debug) syslog x
450 #else
451 #define IPXCPDEBUG(x)
452 #endif
453
454 #ifndef SIGTYPE
455 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
456 #define SIGTYPE void
457 #else
458 #define SIGTYPE int
459 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
460 #endif /* SIGTYPE */
461
462 #ifndef MIN
463 #define MIN(a, b)       ((a) < (b)? (a): (b))
464 #endif
465 #ifndef MAX
466 #define MAX(a, b)       ((a) > (b)? (a): (b))
467 #endif
468
469 #endif /* __PPP_H__ */