Commit | Line | Data |
---|---|---|
2a905848 RG |
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 | ||
20 | /* | |
21 | * TODO: | |
22 | */ | |
23 | ||
24 | #ifndef __PPPD_H__ | |
25 | #define __PPPD_H__ | |
26 | #include "args.h" | |
27 | #define NPPP 1 /* One PPP interface supported (per process) */ | |
28 | ||
29 | extern int debug; /* Debug flag */ | |
30 | extern char ifname[]; /* Interface name */ | |
31 | extern int fd; /* Device file descriptor */ | |
32 | extern int s; /* socket descriptor */ | |
33 | extern char hostname[]; /* hostname */ | |
34 | extern u_char hostname_len; /* and its length */ | |
35 | extern u_char outpacket_buf[]; /* buffer for outgoing packets */ | |
36 | ||
37 | #define MAX_HOSTNAME_LEN 128 /* should be 255 - MAX_CHALLENGE_LEN + 1 */ | |
38 | ||
39 | void quit __ARGS((void)); /* Cleanup and exit */ | |
40 | void timeout __ARGS((void (*)(), caddr_t, int)); | |
41 | /* Look-alike of kernel's timeout() */ | |
42 | void untimeout __ARGS((void (*)(), caddr_t)); | |
43 | /* Look-alike of kernel's untimeout() */ | |
44 | void output __ARGS((int, u_char *, int)); /* Output a PPP packet */ | |
45 | void demuxprotrej __ARGS((int, int)); /* Demultiplex a Protocol-Reject */ | |
46 | u_char login __ARGS((char *, int, char *, int, char **, int *)); /* Login user */ | |
47 | void logout __ARGS((void)); /* Logout user */ | |
48 | void get_secret __ARGS((u_char *, u_char *, int *)); /* get "secret" for chap */ | |
49 | u_long GetMask __ARGS((u_long)); /* get netmask for address */ | |
50 | extern int errno; | |
51 | ||
52 | ||
53 | /* | |
54 | * Inline versions of get/put char/short/long. | |
55 | * Pointer is advanced; we assume that both arguments | |
56 | * are lvalues and will already be in registers. | |
57 | * cp MUST be u_char *. | |
58 | */ | |
59 | #define GETCHAR(c, cp) { \ | |
60 | (c) = *(cp)++; \ | |
61 | } | |
62 | #define PUTCHAR(c, cp) { \ | |
63 | *(cp)++ = (c); \ | |
64 | } | |
65 | ||
66 | ||
67 | #define GETSHORT(s, cp) { \ | |
68 | (s) = *(cp)++ << 8; \ | |
69 | (s) |= *(cp)++; \ | |
70 | } | |
71 | #define PUTSHORT(s, cp) { \ | |
72 | *(cp)++ = (s) >> 8; \ | |
73 | *(cp)++ = (s); \ | |
74 | } | |
75 | ||
76 | #define GETLONG(l, cp) { \ | |
77 | (l) = *(cp)++ << 8; \ | |
78 | (l) |= *(cp)++; (l) <<= 8; \ | |
79 | (l) |= *(cp)++; (l) <<= 8; \ | |
80 | (l) |= *(cp)++; \ | |
81 | } | |
82 | #define PUTLONG(l, cp) { \ | |
83 | *(cp)++ = (l) >> 24; \ | |
84 | *(cp)++ = (l) >> 16; \ | |
85 | *(cp)++ = (l) >> 8; \ | |
86 | *(cp)++ = (l); \ | |
87 | } | |
88 | ||
89 | #define INCPTR(n, cp) ((cp) += (n)) | |
90 | #define DECPTR(n, cp) ((cp) -= (n)) | |
91 | ||
92 | /* | |
93 | * System dependent definitions for user-level 4.3BSD UNIX implementation. | |
94 | */ | |
95 | ||
96 | #define DEMUXPROTREJ(u, p) demuxprotrej(u, p) | |
97 | ||
98 | #define TIMEOUT(r, f, t) timeout((r), (f), (t)) | |
99 | #define UNTIMEOUT(r, f) untimeout((r), (f)) | |
100 | ||
101 | #define BCOPY(s, d, l) bcopy(s, d, l) | |
102 | #define EXIT(u) quit() | |
103 | ||
104 | #define GETUSERPASSWD(u) | |
105 | #define LOGIN(n, u, ul, p, pl, m, ml) login(u, ul, p, pl, m, ml); | |
106 | #define LOGOUT(n) logout() | |
107 | #define GETSECRET(n, s, sl) get_secret(n, s, sl) | |
108 | #define PRINTMSG(m, l) { m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); } | |
109 | ||
110 | /* | |
111 | * return a pointer to the beginning of the data part of a packet. | |
112 | */ | |
113 | ||
114 | #define PACKET_DATA(p) (p + DLLHEADERLEN) | |
115 | ||
116 | /* | |
117 | * MAKEHEADER - Add Header fields to a packet. (Should we do | |
118 | * AC compression here?) | |
119 | */ | |
120 | #define MAKEHEADER(p, t) { \ | |
121 | PUTCHAR(ALLSTATIONS, p); \ | |
122 | PUTCHAR(UI, p); \ | |
123 | PUTSHORT(t, p); } | |
124 | ||
125 | /* | |
126 | * SIFASYNCMAP - Config the interface async map. | |
127 | */ | |
128 | #ifdef STREAMS | |
129 | #define SIFASYNCMAP(u, a) { \ | |
130 | u_long x = a; \ | |
131 | if(ioctl(fd, SIOCSIFASYNCMAP, (caddr_t) &x) < 0) { \ | |
132 | syslog(LOG_ERR, "ioctl(SIOCSIFASYNCMAP): %m"); \ | |
133 | } } | |
134 | #else | |
135 | #define SIFASYNCMAP(u, a) { \ | |
136 | u_long x = a; \ | |
137 | if (ioctl(fd, PPPIOCSASYNCMAP, (caddr_t) &x) < 0) { \ | |
138 | syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m"); \ | |
139 | quit(); \ | |
140 | } } | |
141 | #endif | |
142 | ||
143 | /* | |
144 | * SIFPCOMPRESSION - Config the interface for protocol compression. | |
145 | */ | |
146 | #ifdef STREAMS | |
147 | #define SIFPCOMPRESSION(u) { \ | |
148 | char c = 1; \ | |
149 | if(ioctl(fd, SIOCSIFCOMPPROT, &c) < 0) { \ | |
150 | syslog(LOG_ERR, "ioctl(SIOCSIFCOMPPROT): %m"); \ | |
151 | }} | |
152 | #else | |
153 | #define SIFPCOMPRESSION(u) { \ | |
154 | u_int x; \ | |
155 | if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { \ | |
156 | syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m"); \ | |
157 | quit(); \ | |
158 | } \ | |
159 | x |= SC_COMP_PROT; \ | |
160 | if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { \ | |
161 | syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); \ | |
162 | quit(); \ | |
163 | } } | |
164 | #endif | |
165 | ||
166 | /* | |
167 | * CIFPCOMPRESSION - Config the interface for no protocol compression. | |
168 | */ | |
169 | #ifdef STREAMS | |
170 | #define CIFPCOMPRESSION(u) { \ | |
171 | char c = 0; \ | |
172 | if(ioctl(fd, SIOCSIFCOMPPROT, &c) < 0) { \ | |
173 | syslog(LOG_ERR, "ioctl(SIOCSIFCOMPPROT): %m"); \ | |
174 | quit(); \ | |
175 | }} | |
176 | #else | |
177 | #define CIFPCOMPRESSION(u) { \ | |
178 | u_int x; \ | |
179 | if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { \ | |
180 | syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m"); \ | |
181 | quit(); \ | |
182 | } \ | |
183 | x &= ~SC_COMP_PROT; \ | |
184 | if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { \ | |
185 | syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); \ | |
186 | quit(); \ | |
187 | } } | |
188 | #endif | |
189 | ||
190 | /* | |
191 | * SIFACCOMPRESSION - Config the interface for address/control compression. | |
192 | */ | |
193 | #ifdef STREAMS | |
194 | #define SIFACCOMPRESSION(u) { \ | |
195 | char c = 1; \ | |
196 | if(ioctl(fd, SIOCSIFCOMPAC, &c) < 0) { \ | |
197 | syslog(LOG_ERR, "ioctl(SIOCSIFCOMPAC): %m"); \ | |
198 | quit(); \ | |
199 | }} | |
200 | #else | |
201 | #define SIFACCOMPRESSION(u) { \ | |
202 | u_int x; \ | |
203 | if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { \ | |
204 | syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m"); \ | |
205 | quit(); \ | |
206 | } \ | |
207 | x |= SC_COMP_AC; \ | |
208 | if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { \ | |
209 | syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); \ | |
210 | quit(); \ | |
211 | } } | |
212 | #endif | |
213 | ||
214 | /* | |
215 | * CIFACCOMPRESSION - Config the interface for no address/control compression. | |
216 | */ | |
217 | #ifdef STREAMS | |
218 | #define CIFACCOMPRESSION(u) { \ | |
219 | char c = 0; \ | |
220 | if(ioctl(fd, SIOCSIFCOMPAC, &c) < 0) { \ | |
221 | syslog(LOG_ERR, "ioctl(SIOCSIFCOMPAC): %m"); \ | |
222 | quit(); \ | |
223 | }} | |
224 | #else | |
225 | #define CIFACCOMPRESSION(u) { \ | |
226 | u_int x; \ | |
227 | if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { \ | |
228 | syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m"); \ | |
229 | quit(); \ | |
230 | } \ | |
231 | x &= ~SC_COMP_AC; \ | |
232 | if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { \ | |
233 | syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); \ | |
234 | quit(); \ | |
235 | } } | |
236 | #endif | |
237 | ||
238 | /* | |
239 | * SIFVJCOMP - config tcp header compression | |
240 | */ | |
241 | #ifdef STREAMS | |
242 | #define SIFVJCOMP(u, a) { \ | |
243 | char x = a; \ | |
244 | if (debug) syslog(LOG_DEBUG, "SIFVJCOMP unit %d to value %d\n",u,x); \ | |
245 | if(ioctl(fd, SIOCSIFVJCOMP, (caddr_t) &x) < 0) { \ | |
246 | syslog(LOG_ERR, "ioctl(SIOCSIFVJCOMP): %m"); \ | |
247 | quit(); \ | |
248 | } \ | |
249 | } | |
250 | #else | |
251 | #define SIFVJCOMP(u, a) { \ | |
252 | u_int x; \ | |
253 | if (debug) \ | |
254 | syslog(LOG_DEBUG, "PPPIOCSFLAGS unit %d set %s\n",u,a?"on":"off"); \ | |
255 | if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { \ | |
256 | syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m"); \ | |
257 | quit(); \ | |
258 | } \ | |
259 | x = (x & ~SC_COMP_TCP) | ((a) ? SC_COMP_TCP : 0); \ | |
260 | if(ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { \ | |
261 | syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); \ | |
262 | quit(); \ | |
263 | } } | |
264 | #endif | |
265 | ||
266 | /* | |
267 | * SIFUP - Config the interface up. | |
268 | */ | |
269 | #define SIFUP(u) { \ | |
270 | struct ifreq ifr; \ | |
271 | strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \ | |
272 | if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { \ | |
273 | syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m"); \ | |
274 | quit(); \ | |
275 | } \ | |
276 | ifr.ifr_flags |= IFF_UP; \ | |
277 | if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { \ | |
278 | syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m"); \ | |
279 | quit(); \ | |
280 | } } | |
281 | ||
282 | /* | |
283 | * SIFDOWN - Config the interface down. | |
284 | */ | |
285 | #define SIFDOWN(u) { \ | |
286 | struct ifreq ifr; \ | |
287 | strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \ | |
288 | if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { \ | |
289 | syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m"); \ | |
290 | quit(); \ | |
291 | } \ | |
292 | ifr.ifr_flags &= ~IFF_UP; \ | |
293 | if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { \ | |
294 | syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m"); \ | |
295 | quit(); \ | |
296 | } } | |
297 | ||
298 | /* | |
299 | * SIFMTU - Config the interface MTU. | |
300 | */ | |
301 | #define SIFMTU(u, m) { \ | |
302 | struct ifreq ifr; \ | |
303 | strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \ | |
304 | ifr.ifr_mtu = m; \ | |
305 | if (ioctl(s, SIOCSIFMTU, (caddr_t) &ifr) < 0) { \ | |
306 | syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m"); \ | |
307 | quit(); \ | |
308 | } } | |
309 | ||
310 | ||
311 | #ifdef __386BSD__ /* BSD >= 44 ? */ | |
312 | #define SET_SA_FAMILY(addr, family) \ | |
313 | bzero((char *) &(addr), sizeof(addr)); \ | |
314 | addr.sa_family = (family); \ | |
315 | addr.sa_len = sizeof(addr); | |
316 | #else | |
317 | #define SET_SA_FAMILY(addr, family) \ | |
318 | bzero((char *) &(addr), sizeof(addr)); \ | |
319 | addr.sa_family = (family); | |
320 | #endif | |
321 | ||
322 | /* | |
323 | * SIFADDR - Config the interface IP addresses. | |
324 | */ | |
325 | #define SIFADDR(u, o, h) { \ | |
326 | struct ifreq ifr; \ | |
327 | strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \ | |
328 | SET_SA_FAMILY(ifr.ifr_addr, AF_INET); \ | |
329 | ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o; \ | |
330 | if (ioctl(s, SIOCSIFADDR, (caddr_t) &ifr) < 0) { \ | |
331 | syslog(LOG_ERR, "ioctl(SIOCSIFADDR): %m"); \ | |
332 | } \ | |
333 | ((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h; \ | |
334 | if (ioctl(s, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) { \ | |
335 | syslog(LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m"); \ | |
336 | quit(); \ | |
337 | } } | |
338 | ||
339 | /* | |
340 | * CIFADDR - Clear the interface IP addresses. | |
341 | */ | |
342 | #if BSD > 43 | |
343 | #define CIFADDR(u, o, h) { \ | |
344 | struct ortentry rt; \ | |
345 | SET_SA_FAMILY(rt.rt_dst, AF_INET); \ | |
346 | ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = h; \ | |
347 | SET_SA_FAMILY(rt.rt_gateway, AF_INET); \ | |
348 | ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o; \ | |
349 | rt.rt_flags |= RTF_HOST; \ | |
350 | syslog(LOG_INFO, "Deleting host route from %s to %s\n", \ | |
351 | ip_ntoa(h), ip_ntoa(o)); \ | |
352 | if (ioctl(s, SIOCDELRT, (caddr_t) &rt) < 0) { \ | |
353 | syslog(LOG_ERR, "ioctl(SIOCDELRT): %m"); \ | |
354 | } } | |
355 | #else | |
356 | #define CIFADDR(u, o, h) { \ | |
357 | struct rtentry rt; \ | |
358 | SET_SA_FAMILY(rt.rt_dst, AF_INET); \ | |
359 | ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = h; \ | |
360 | SET_SA_FAMILY(rt.rt_gateway, AF_INET); \ | |
361 | ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o; \ | |
362 | rt.rt_flags |= RTF_HOST; \ | |
363 | syslog(LOG_INFO, "Deleting host route from %s to %s\n", \ | |
364 | ip_ntoa(h), ip_ntoa(o)); \ | |
365 | if (ioctl(s, SIOCDELRT, (caddr_t) &rt) < 0) { \ | |
366 | syslog(LOG_ERR, "ioctl(SIOCDELRT): %m"); \ | |
367 | } } | |
368 | #endif | |
369 | ||
370 | /* | |
371 | * SIFMASK - Config the interface net mask | |
372 | */ | |
373 | #define SIFMASK(u, m) { \ | |
374 | struct ifreq ifr; \ | |
375 | strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \ | |
376 | SET_SA_FAMILY(ifr.ifr_addr, AF_INET); \ | |
377 | ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m; \ | |
378 | syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m)); \ | |
379 | if (ioctl(s, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) { \ | |
380 | syslog(LOG_ERR, "ioctl(SIOCSIFADDR): %m"); \ | |
381 | } } | |
382 | ||
383 | #ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */ | |
384 | #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUG) \ | |
385 | || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \ | |
386 | || defined(DEBUGCHAP) | |
387 | #define LOG_PPP LOG_LOCAL2 | |
388 | #else | |
389 | #define LOG_PPP LOG_DAEMON | |
390 | #endif | |
391 | #endif /* LOG_PPP */ | |
392 | ||
393 | #ifdef DEBUGMAIN | |
394 | #define MAINDEBUG(x) if (debug) syslog x; | |
395 | #else | |
396 | #define MAINDEBUG(x) | |
397 | #endif | |
398 | ||
399 | #ifdef DEBUGFSM | |
400 | #define FSMDEBUG(x) if (debug) syslog x; | |
401 | #else | |
402 | #define FSMDEBUG(x) | |
403 | #endif | |
404 | ||
405 | #ifdef DEBUGLCP | |
406 | #define LCPDEBUG(x) if (debug) syslog x; | |
407 | #else | |
408 | #define LCPDEBUG(x) | |
409 | #endif | |
410 | ||
411 | #ifdef DEBUGIPCP | |
412 | #define IPCPDEBUG(x) if (debug) syslog x; | |
413 | #else | |
414 | #define IPCPDEBUG(x) | |
415 | #endif | |
416 | ||
417 | #ifdef DEBUGUPAP | |
418 | #define UPAPDEBUG(x) if (debug) syslog x; | |
419 | #else | |
420 | #define UPAPDEBUG(x) | |
421 | #endif | |
422 | ||
423 | #ifdef DEBUGCHAP | |
424 | #define CHAPDEBUG(x) if (debug) syslog x; | |
425 | #else | |
426 | #define CHAPDEBUG(x) | |
427 | #endif | |
428 | ||
429 | #ifndef SIGTYPE | |
430 | #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) | |
431 | #define SIGTYPE void | |
432 | #else | |
433 | #define SIGTYPE int | |
434 | #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */ | |
435 | #endif /* SIGTYPE */ | |
436 | #endif /* __PPP_H__ */ |