]> git.ozlabs.org Git - ppp.git/blob - pppd/pppd.h
mods from Al Longyear
[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.9 1995/10/27 03:40:12 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      fd;             /* 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     user[];         /* Username for PAP */
77 extern char     passwd[];       /* Password for PAP */
78 extern int      auth_required;  /* Peer is required to authenticate */
79 extern int      proxyarp;       /* Set up proxy ARP entry for peer */
80 extern int      persist;        /* Reopen link after it goes down */
81 extern int      uselogin;       /* Use /etc/passwd for checking PAP */
82 extern int      lcp_echo_interval; /* Interval between LCP echo-requests */
83 extern int      lcp_echo_fails; /* Tolerance to unanswered echo-requests */
84 extern char     our_name[];     /* Our name for authentication purposes */
85 extern char     remote_name[];  /* Peer's name for authentication */
86 extern int      usehostname;    /* Use hostname for our_name */
87 extern int      disable_defaultip; /* Don't use hostname for default IP adrs */
88 extern char     *ipparam;       /* Extra parameter for ip up/down scripts */
89 extern int      cryptpap;       /* Others' PAP passwords are encrypted */
90
91 /*
92  * Values for phase.
93  */
94 #define PHASE_DEAD              0
95 #define PHASE_ESTABLISH         1
96 #define PHASE_AUTHENTICATE      2
97 #define PHASE_NETWORK           3
98 #define PHASE_TERMINATE         4
99
100 /*
101  * Prototypes.
102  */
103
104 /* Procedures exported from main.c. */
105 void die __P((int));            /* Cleanup and exit */
106 void quit __P((void));          /* like die(1) */
107 void novm __P((char *));        /* Say we ran out of memory, and die */
108 void timeout __P((void (*func)(), caddr_t arg, int t));
109                                 /* Call func(arg) after t seconds */
110 void untimeout __P((void (*func)(), caddr_t arg));
111                                 /* Cancel call to func(arg) */
112 int run_program __P((char *prog, char **args, int must_exist));
113                                 /* Run program prog with args in child */
114 void demuxprotrej __P((int, int));
115                                 /* Demultiplex a Protocol-Reject */
116 void format_packet __P((u_char *, int, void (*) (void *, char *, ...),
117                 void *));       /* Format a packet in human-readable form */
118 void log_packet __P((u_char *, int, char *));
119                                 /* Format a packet and log it with syslog */
120 void print_string __P((char *, int,  void (*) (void *, char *, ...),
121                 void *));       /* Format a string for output */
122
123 /* Procedures exported from auth.c */
124 void link_required __P((int));    /* we are starting to use the link */
125 void link_terminated __P((int));  /* we are finished with the link */
126 void link_down __P((int));        /* the LCP layer has left the Opened state */
127 void link_established __P((int)); /* the link is up; authenticate now */
128 void auth_peer_fail __P((int, int));
129                                 /* peer failed to authenticate itself */
130 void auth_peer_success __P((int, int));
131                                 /* peer successfully authenticated itself */
132 void auth_withpeer_fail __P((int, int));
133                                 /* we failed to authenticate ourselves */
134 void auth_withpeer_success __P((int, int));
135                                 /* we successfully authenticated ourselves */
136 void check_auth_options __P((void));
137                                 /* check authentication options supplied */
138 int  check_passwd __P((int, char *, int, char *, int, char **, int *));
139                                 /* Check peer-supplied username/password */
140 int  get_secret __P((int, char *, char *, char *, int *, int));
141                                 /* get "secret" for chap */
142 int  auth_ip_addr __P((int, u_int32_t));
143                                 /* check if IP address is authorized */
144 int  bad_ip_adrs __P((u_int32_t));
145                                 /* check if IP address is unreasonable */
146 void check_access __P((FILE *, char *));
147                                 /* check permissions on secrets file */
148
149 /* Procedures exported from sys-*.c */
150 void sys_init __P((void));      /* Do system-dependent initialization */
151 void sys_cleanup __P((void));   /* Restore system state before exiting */
152 void note_debug_level __P((void)); /* Note change in debug level */
153 int  ppp_available __P((void)); /* Test whether ppp kernel support exists */
154 void establish_ppp __P((void)); /* Turn serial port into a ppp interface */
155 void disestablish_ppp __P((void)); /* Restore port to normal operation */
156 void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */
157 void restore_tty __P((void));   /* Restore port's original parameters */
158 void setdtr __P((int, int));    /* Raise or lower port's DTR line */
159 void output __P((int, u_char *, int)); /* Output a PPP packet */
160 void wait_input __P((struct timeval *));
161                                 /* Wait for input, with timeout */
162 int  read_packet __P((u_char *)); /* Read PPP packet */
163 void ppp_send_config __P((int, int, u_int32_t, int, int));
164                                 /* Configure i/f transmit parameters */
165 void ppp_set_xaccm __P((int, ext_accm));
166                                 /* Set extended transmit ACCM */
167 void ppp_recv_config __P((int, int, u_int32_t, int, int));
168                                 /* Configure i/f receive parameters */
169 int  ccp_test __P((int, u_char *, int, int));
170                                 /* Test support for compression scheme */
171 void ccp_flags_set __P((int, int, int));
172                                 /* Set kernel CCP state */
173 int  ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */
174 int  sifvjcomp __P((int, int, int, int));
175                                 /* Configure VJ TCP header compression */
176 int  sifup __P((int));          /* Configure i/f up (for IP) */
177 int  sifdown __P((int));        /* Configure i/f down (for IP) */
178 int  sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t));
179                                 /* Configure IP addresses for i/f */
180 int  cifaddr __P((int, u_int32_t, u_int32_t));
181                                 /* Reset i/f IP addresses */
182 int  sifdefaultroute __P((int, u_int32_t));
183                                 /* Create default route through i/f */
184 int  cifdefaultroute __P((int, u_int32_t));
185                                 /* Delete default route through i/f */
186 int  sifproxyarp __P((int, u_int32_t));
187                                 /* Add proxy ARP entry for peer */
188 int  cifproxyarp __P((int, u_int32_t));
189                                 /* Delete proxy ARP entry for peer */
190 u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */
191 int  lock __P((char *));        /* Create lock file for device */
192 void unlock __P((void));        /* Delete previously-created lock file */
193 int  daemon __P((int, int));    /* Detach us from terminal session */
194 int  logwtmp __P((char *, char *, char *));
195                                 /* Write entry to wtmp file */
196
197 /*
198  * Inline versions of get/put char/short/long.
199  * Pointer is advanced; we assume that both arguments
200  * are lvalues and will already be in registers.
201  * cp MUST be u_char *.
202  */
203 #define GETCHAR(c, cp) { \
204         (c) = *(cp)++; \
205 }
206 #define PUTCHAR(c, cp) { \
207         *(cp)++ = (u_char) (c); \
208 }
209
210
211 #define GETSHORT(s, cp) { \
212         (s) = *(cp)++ << 8; \
213         (s) |= *(cp)++; \
214 }
215 #define PUTSHORT(s, cp) { \
216         *(cp)++ = (u_char) ((s) >> 8); \
217         *(cp)++ = (u_char) (s); \
218 }
219
220 #define GETLONG(l, cp) { \
221         (l) = *(cp)++ << 8; \
222         (l) |= *(cp)++; (l) <<= 8; \
223         (l) |= *(cp)++; (l) <<= 8; \
224         (l) |= *(cp)++; \
225 }
226 #define PUTLONG(l, cp) { \
227         *(cp)++ = (u_char) ((l) >> 24); \
228         *(cp)++ = (u_char) ((l) >> 16); \
229         *(cp)++ = (u_char) ((l) >> 8); \
230         *(cp)++ = (u_char) (l); \
231 }
232
233 #define INCPTR(n, cp)   ((cp) += (n))
234 #define DECPTR(n, cp)   ((cp) -= (n))
235
236 #undef  FALSE
237 #define FALSE   0
238 #undef  TRUE
239 #define TRUE    1
240
241 /*
242  * System dependent definitions for user-level 4.3BSD UNIX implementation.
243  */
244
245 #define DEMUXPROTREJ(u, p)      demuxprotrej(u, p)
246
247 #define TIMEOUT(r, f, t)        timeout((r), (f), (t))
248 #define UNTIMEOUT(r, f)         untimeout((r), (f))
249
250 #define BCOPY(s, d, l)          memcpy(d, s, l)
251 #define BZERO(s, n)             memset(s, 0, n)
252 #define EXIT(u)                 quit()
253
254 #define PRINTMSG(m, l)  { m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); }
255
256 /*
257  * MAKEHEADER - Add Header fields to a packet.
258  */
259 #define MAKEHEADER(p, t) { \
260     PUTCHAR(PPP_ALLSTATIONS, p); \
261     PUTCHAR(PPP_UI, p); \
262     PUTSHORT(t, p); }
263
264
265 #ifdef DEBUGALL
266 #define DEBUGMAIN       1
267 #define DEBUGFSM        1
268 #define DEBUGLCP        1
269 #define DEBUGIPCP       1
270 #define DEBUGUPAP       1
271 #define DEBUGCHAP       1
272 #endif
273
274 #ifndef LOG_PPP                 /* we use LOG_LOCAL2 for syslog by default */
275 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUG) \
276   || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
277   || defined(DEBUGCHAP) 
278 #define LOG_PPP LOG_LOCAL2
279 #else
280 #define LOG_PPP LOG_DAEMON
281 #endif
282 #endif /* LOG_PPP */
283
284 #ifdef DEBUGMAIN
285 #define MAINDEBUG(x)    if (debug) syslog x
286 #else
287 #define MAINDEBUG(x)
288 #endif
289
290 #ifdef DEBUGFSM
291 #define FSMDEBUG(x)     if (debug) syslog x
292 #else
293 #define FSMDEBUG(x)
294 #endif
295
296 #ifdef DEBUGLCP
297 #define LCPDEBUG(x)     if (debug) syslog x
298 #else
299 #define LCPDEBUG(x)
300 #endif
301
302 #ifdef DEBUGIPCP
303 #define IPCPDEBUG(x)    if (debug) syslog x
304 #else
305 #define IPCPDEBUG(x)
306 #endif
307
308 #ifdef DEBUGUPAP
309 #define UPAPDEBUG(x)    if (debug) syslog x
310 #else
311 #define UPAPDEBUG(x)
312 #endif
313
314 #ifdef DEBUGCHAP
315 #define CHAPDEBUG(x)    if (debug) syslog x
316 #else
317 #define CHAPDEBUG(x)
318 #endif
319
320 #ifndef SIGTYPE
321 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
322 #define SIGTYPE void
323 #else
324 #define SIGTYPE int
325 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
326 #endif /* SIGTYPE */
327
328 #ifndef MIN
329 #define MIN(a, b)       ((a) < (b)? (a): (b))
330 #endif
331 #ifndef MAX
332 #define MAX(a, b)       ((a) > (b)? (a): (b))
333 #endif
334
335 #endif /* __PPP_H__ */