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