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