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