]> git.ozlabs.org Git - ppp.git/blob - pppd/pppd.h
Initial revision
[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.4 1994/09/01 00:36:05 paulus Exp $
20  */
21
22 /*
23  * TODO:
24  */
25
26 #ifndef __PPPD_H__
27 #define __PPPD_H__
28 #include "args.h"
29
30 #include <sys/param.h>          /* for MAXPATHLEN and BSD4_4, if defined */
31
32 #define NPPP    1               /* One PPP interface supported (per process) */
33
34 /*
35  * A 32-bit unsigned integral type.
36  */
37
38 #ifdef UINT32
39 typedef UINT32          uint32;
40 #else
41 typedef unsigned long   uint32;
42 #endif
43
44 /*
45  * Limits.
46  */
47
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      fd;             /* Serial device file descriptor */
61 extern int      s;              /* Socket descriptor */
62 extern char     hostname[];     /* Our hostname */
63 extern u_char   outpacket_buf[]; /* Buffer for outgoing packets */
64 extern int      phase;          /* Current state of link - see values below */
65 extern int      baud_rate;      /* Current link speed in bits/sec */
66 extern char     *progname;      /* Name of this program */
67
68 /*
69  * Variables set by command-line options.
70  */
71
72 extern int      debug;          /* Debug flag */
73 extern int      kdebugflag;     /* Tell kernel to print debug messages */
74 extern int      default_device; /* Using /dev/tty or equivalent */
75 extern char     devnam[];       /* Device name */
76 extern int      crtscts;        /* Use hardware flow control */
77 extern int      modem;          /* Use modem control lines */
78 extern int      inspeed;        /* Input/Output speed requested */
79 extern uint32   netmask;        /* IP netmask to set on interface */
80 extern int      lockflag;       /* Create lock file to lock the serial dev */
81 extern int      nodetach;       /* Don't detach from controlling tty */
82 extern char     *connector;     /* Script to establish physical link */
83 extern char     *disconnector;  /* Script to disestablish physical link */
84 extern char     user[];         /* Username for PAP */
85 extern char     passwd[];       /* Password for PAP */
86 extern int      auth_required;  /* Peer is required to authenticate */
87 extern int      proxyarp;       /* Set up proxy ARP entry for peer */
88 extern int      persist;        /* Reopen link after it goes down */
89 extern int      uselogin;       /* Use /etc/passwd for checking PAP */
90 extern int      lcp_echo_interval; /* Interval between LCP echo-requests */
91 extern int      lcp_echo_fails; /* Tolerance to unanswered echo-requests */
92 extern char     our_name[];     /* Our name for authentication purposes */
93 extern char     remote_name[];  /* Peer's name for authentication */
94 extern int      usehostname;    /* Use hostname for our_name */
95 extern int      disable_defaultip; /* Don't use hostname for default IP adrs */
96
97 /*
98  * Values for phase.
99  */
100 #define PHASE_DEAD              0
101 #define PHASE_ESTABLISH         1
102 #define PHASE_AUTHENTICATE      2
103 #define PHASE_NETWORK           3
104 #define PHASE_TERMINATE         4
105
106 /*
107  * Prototypes.
108  */
109 void quit __ARGS((void));       /* Cleanup and exit */
110 void timeout __ARGS((void (*)(), caddr_t, int));
111                                 /* Look-alike of kernel's timeout() */
112 void untimeout __ARGS((void (*)(), caddr_t));
113                                 /* Look-alike of kernel's untimeout() */
114 void output __ARGS((int, u_char *, int));
115                                 /* Output a PPP packet */
116 void demuxprotrej __ARGS((int, int));
117                                 /* Demultiplex a Protocol-Reject */
118 int  check_passwd __ARGS((int, char *, int, char *, int, char **, int *));
119                                 /* Check peer-supplied username/password */
120 int  get_secret __ARGS((int, char *, char *, char *, int *, int));
121                                 /* get "secret" for chap */
122 uint32 GetMask __ARGS((uint32)); /* get netmask for address */
123 void die __ARGS((int));
124
125 /*
126  * Inline versions of get/put char/short/long.
127  * Pointer is advanced; we assume that both arguments
128  * are lvalues and will already be in registers.
129  * cp MUST be u_char *.
130  */
131 #define GETCHAR(c, cp) { \
132         (c) = *(cp)++; \
133 }
134 #define PUTCHAR(c, cp) { \
135         *(cp)++ = (u_char) (c); \
136 }
137
138
139 #define GETSHORT(s, cp) { \
140         (s) = *(cp)++ << 8; \
141         (s) |= *(cp)++; \
142 }
143 #define PUTSHORT(s, cp) { \
144         *(cp)++ = (u_char) ((s) >> 8); \
145         *(cp)++ = (u_char) (s); \
146 }
147
148 #define GETLONG(l, cp) { \
149         (l) = *(cp)++ << 8; \
150         (l) |= *(cp)++; (l) <<= 8; \
151         (l) |= *(cp)++; (l) <<= 8; \
152         (l) |= *(cp)++; \
153 }
154 #define PUTLONG(l, cp) { \
155         *(cp)++ = (u_char) ((l) >> 24); \
156         *(cp)++ = (u_char) ((l) >> 16); \
157         *(cp)++ = (u_char) ((l) >> 8); \
158         *(cp)++ = (u_char) (l); \
159 }
160
161 #define INCPTR(n, cp)   ((cp) += (n))
162 #define DECPTR(n, cp)   ((cp) -= (n))
163
164 #define FALSE   0
165 #define TRUE    1
166
167 /*
168  * System dependent definitions for user-level 4.3BSD UNIX implementation.
169  */
170
171 #define DEMUXPROTREJ(u, p)      demuxprotrej(u, p)
172
173 #define TIMEOUT(r, f, t)        timeout((r), (f), (t))
174 #define UNTIMEOUT(r, f)         untimeout((r), (f))
175
176 #define BCOPY(s, d, l)          memcpy(d, s, l)
177 #define BZERO(s, n)             memset(s, 0, n)
178 #define EXIT(u)                 quit()
179
180 #define PRINTMSG(m, l)  { m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); }
181
182 /*
183  * MAKEHEADER - Add Header fields to a packet.
184  */
185 #define MAKEHEADER(p, t) { \
186     PUTCHAR(ALLSTATIONS, p); \
187     PUTCHAR(UI, p); \
188     PUTSHORT(t, p); }
189
190
191 #ifdef DEBUGALL
192 #define DEBUGMAIN       1
193 #define DEBUGFSM        1
194 #define DEBUGLCP        1
195 #define DEBUGIPCP       1
196 #define DEBUGUPAP       1
197 #define DEBUGCHAP       1
198 #endif
199
200 #ifndef LOG_PPP                 /* we use LOG_LOCAL2 for syslog by default */
201 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUG) \
202   || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
203   || defined(DEBUGCHAP) 
204 #define LOG_PPP LOG_LOCAL2
205 #else
206 #define LOG_PPP LOG_DAEMON
207 #endif
208 #endif /* LOG_PPP */
209
210 #ifdef DEBUGMAIN
211 #define MAINDEBUG(x)    if (debug) syslog x
212 #else
213 #define MAINDEBUG(x)
214 #endif
215
216 #ifdef DEBUGFSM
217 #define FSMDEBUG(x)     if (debug) syslog x
218 #else
219 #define FSMDEBUG(x)
220 #endif
221
222 #ifdef DEBUGLCP
223 #define LCPDEBUG(x)     if (debug) syslog x
224 #else
225 #define LCPDEBUG(x)
226 #endif
227
228 #ifdef DEBUGIPCP
229 #define IPCPDEBUG(x)    if (debug) syslog x
230 #else
231 #define IPCPDEBUG(x)
232 #endif
233
234 #ifdef DEBUGUPAP
235 #define UPAPDEBUG(x)    if (debug) syslog x
236 #else
237 #define UPAPDEBUG(x)
238 #endif
239
240 #ifdef DEBUGCHAP
241 #define CHAPDEBUG(x)    if (debug) syslog x
242 #else
243 #define CHAPDEBUG(x)
244 #endif
245
246 #ifndef SIGTYPE
247 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
248 #define SIGTYPE void
249 #else
250 #define SIGTYPE int
251 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
252 #endif /* SIGTYPE */
253
254 #ifndef MIN
255 #define MIN(a, b)       ((a) < (b)? (a): (b))
256 #endif
257 #ifndef MAX
258 #define MAX(a, b)       ((a) > (b)? (a): (b))
259 #endif
260
261 #endif /* __PPP_H__ */