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