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