save/restore cr2, cr3 from vmcb
[freebsd-src/fkvm-freebsd.git] / usr.sbin / pppd / pppd.h
bloba547fb7e776618652e15ba21ea496a5baeae9a80
1 /*
2 * pppd.h - PPP daemon global declarations.
4 * Copyright (c) 1989 Carnegie Mellon University.
5 * All rights reserved.
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.
19 * $FreeBSD$
23 * TODO:
26 #ifndef __PPPD_H__
27 #define __PPPD_H__
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>
35 #if __STDC__
36 #include <stdarg.h>
37 #define __V(x) x
38 #else
39 #include <varargs.h>
40 #define __V(x) (va_alist) va_dcl
41 #define const
42 #endif
44 #ifdef INET6
45 #include "eui64.h"
46 #endif
49 * Limits.
52 #define NUM_PPP 1 /* One PPP interface supported (per process) */
53 #define MAXWORDLEN 1024 /* max length of word in file (incl null) */
54 #define MAXARGS 1 /* max # args to a command */
55 #define MAXNAMELEN 256 /* max length of hostname or name for auth */
56 #define MAXSECRETLEN 256 /* max length of password or secret */
59 * Global variables.
62 extern int hungup; /* Physical layer has disconnected */
63 extern int ifunit; /* Interface unit number */
64 extern char ifname[]; /* Interface name */
65 extern int ttyfd; /* Serial device file descriptor */
66 extern char hostname[]; /* Our hostname */
67 extern u_char outpacket_buf[]; /* Buffer for outgoing packets */
68 extern int phase; /* Current state of link - see values below */
69 extern int baud_rate; /* Current link speed in bits/sec */
70 extern char *progname; /* Name of this program */
71 extern int redirect_stderr;/* Connector's stderr should go to file */
72 extern char peer_authname[];/* Authenticated name of peer */
73 extern int privileged; /* We were run by real-uid root */
74 extern int need_holdoff; /* Need holdoff period after link terminates */
75 extern char **script_env; /* Environment variables for scripts */
76 extern int detached; /* Have detached from controlling tty */
79 * Variables set by command-line options.
82 extern int debug; /* Debug flag */
83 extern int kdebugflag; /* Tell kernel to print debug messages */
84 extern int default_device; /* Using /dev/tty or equivalent */
85 extern char devnam[]; /* Device name */
86 extern int crtscts; /* Use hardware flow control */
87 extern int modem; /* Use modem control lines */
88 extern int inspeed; /* Input/Output speed requested */
89 extern u_int32_t netmask; /* IP netmask to set on interface */
90 extern int lockflag; /* Create lock file to lock the serial dev */
91 extern int nodetach; /* Don't detach from controlling tty */
92 extern char *connector; /* Script to establish physical link */
93 extern char *disconnector; /* Script to disestablish physical link */
94 extern char *welcomer; /* Script to welcome client after connection */
95 extern int max_con_attempts;/* Maximum number of times to try dialing */
96 extern int maxconnect; /* Maximum connect time (seconds) */
97 extern char user[]; /* Our name for authenticating ourselves */
98 extern char passwd[]; /* Password for PAP */
99 extern int auth_required; /* Peer is required to authenticate */
100 extern int proxyarp; /* Set up proxy ARP entry for peer */
101 extern int persist; /* Reopen link after it goes down */
102 extern int uselogin; /* Use /etc/passwd for checking PAP */
103 extern int lcp_echo_interval; /* Interval between LCP echo-requests */
104 extern int lcp_echo_fails; /* Tolerance to unanswered echo-requests */
105 extern char our_name[]; /* Our name for authentication purposes */
106 extern char remote_name[]; /* Peer's name for authentication */
107 extern int explicit_remote;/* remote_name specified with remotename opt */
108 extern int usehostname; /* Use hostname for our_name */
109 extern int disable_defaultip; /* Don't use hostname for default IP adrs */
110 extern int demand; /* Do dial-on-demand */
111 extern char *ipparam; /* Extra parameter for ip up/down scripts */
112 extern int cryptpap; /* Others' PAP passwords are encrypted */
113 extern int idle_time_limit;/* Shut down link if idle for this long */
114 extern int holdoff; /* Dead time before restarting */
115 extern int refuse_pap; /* Don't wanna auth. ourselves with PAP */
116 extern int refuse_chap; /* Don't wanna auth. ourselves with CHAP */
117 #ifdef PPP_FILTER
118 extern struct bpf_program pass_filter; /* Filter for pkts to pass */
119 extern struct bpf_program active_filter; /* Filter for link-active pkts */
120 #endif
123 #ifdef MSLANMAN
124 extern int ms_lanman; /* Nonzero if use LanMan password instead of NT */
125 /* Has meaning only with MS-CHAP challenges */
126 #endif
129 * Values for phase.
131 #define PHASE_DEAD 0
132 #define PHASE_INITIALIZE 1
133 #define PHASE_DORMANT 2
134 #define PHASE_ESTABLISH 3
135 #define PHASE_AUTHENTICATE 4
136 #define PHASE_CALLBACK 5
137 #define PHASE_NETWORK 6
138 #define PHASE_TERMINATE 7
139 #define PHASE_HOLDOFF 8
142 * The following struct gives the addresses of procedures to call
143 * for a particular protocol.
145 struct protent {
146 u_short protocol; /* PPP protocol number */
147 /* Initialization procedure */
148 void (*init)(int unit);
149 /* Process a received packet */
150 void (*input)(int unit, u_char *pkt, int len);
151 /* Process a received protocol-reject */
152 void (*protrej)(int unit);
153 /* Lower layer has come up */
154 void (*lowerup)(int unit);
155 /* Lower layer has gone down */
156 void (*lowerdown)(int unit);
157 /* Open the protocol */
158 void (*open)(int unit);
159 /* Close the protocol */
160 void (*close)(int unit, char *reason);
161 /* Print a packet in readable form */
162 int (*printpkt)(u_char *pkt, int len,
163 void (*printer)(void *, char *, ...),
164 void *arg);
165 /* Process a received data packet */
166 void (*datainput)(int unit, u_char *pkt, int len);
167 int enabled_flag; /* 0 iff protocol is disabled */
168 char *name; /* Text name of protocol */
169 /* Check requested options, assign defaults */
170 void (*check_options)(void);
171 /* Configure interface for demand-dial */
172 int (*demand_conf)(int unit);
173 /* Say whether to bring up link for this pkt */
174 int (*active_pkt)(u_char *pkt, int len);
177 /* Table of pointers to supported protocols */
178 extern struct protent *protocols[];
181 * Prototypes.
184 /* Procedures exported from main.c. */
185 void detach(void); /* Detach from controlling tty */
186 void die(int); /* Cleanup and exit */
187 void quit(void); /* like die(1) */
188 void novm(char *); /* Say we ran out of memory, and die */
189 void timeout(void (*func)(void *), void *arg, int t);
190 /* Call func(arg) after t seconds */
191 void untimeout(void (*func)(void *), void *arg);
192 /* Cancel call to func(arg) */
193 int run_program(char *prog, char **args, int must_exist);
194 /* Run program prog with args in child */
195 void demuxprotrej(int, int);
196 /* Demultiplex a Protocol-Reject */
197 void format_packet(u_char *, int, void (*) (void *, char *, ...),
198 void *); /* Format a packet in human-readable form */
199 void log_packet(u_char *, int, char *, int);
200 /* Format a packet and log it with syslog */
201 void print_string(char *, int, void (*) (void *, char *, ...),
202 void *); /* Format a string for output */
203 int fmtmsg(char *, int, char *, ...); /* sprintf++ */
204 int vfmtmsg(char *, int, char *, va_list); /* vsprintf++ */
205 void script_setenv(char *, char *); /* set script env var */
206 void script_unsetenv(char *); /* unset script env var */
208 /* Procedures exported from auth.c */
209 void link_required(int); /* we are starting to use the link */
210 void link_terminated(int); /* we are finished with the link */
211 void link_down(int); /* the LCP layer has left the Opened state */
212 void link_established(int); /* the link is up; authenticate now */
213 void np_up(int, int); /* a network protocol has come up */
214 void np_down(int, int); /* a network protocol has gone down */
215 void np_finished(int, int); /* a network protocol no longer needs link */
216 void auth_peer_fail(int, int);
217 /* peer failed to authenticate itself */
218 void auth_peer_success(int, int, char *, int);
219 /* peer successfully authenticated itself */
220 void auth_withpeer_fail(int, int);
221 /* we failed to authenticate ourselves */
222 void auth_withpeer_success(int, int);
223 /* we successfully authenticated ourselves */
224 void auth_check_options(void);
225 /* check authentication options supplied */
226 void auth_reset(int); /* check what secrets we have */
227 int check_passwd(int, char *, int, char *, int, char **, int *);
228 /* Check peer-supplied username/password */
229 int get_secret(int, char *, char *, char *, int *, int);
230 /* get "secret" for chap */
231 int auth_ip_addr(int, u_int32_t);
232 /* check if IP address is authorized */
233 int bad_ip_adrs(u_int32_t);
234 /* check if IP address is unreasonable */
235 void check_access(FILE *, char *);
236 /* check permissions on secrets file */
238 /* Procedures exported from demand.c */
239 void demand_conf(void); /* config interface(s) for demand-dial */
240 void demand_block(void); /* set all NPs to queue up packets */
241 void demand_unblock(void); /* set all NPs to pass packets */
242 void demand_discard(void); /* set all NPs to discard packets */
243 void demand_rexmit(int); /* retransmit saved frames for an NP */
244 int loop_chars(unsigned char *, int); /* process chars from loopback */
245 int loop_frame(unsigned char *, int); /* process frame from loopback */
247 /* Procedures exported from sys-*.c */
248 void sys_init(void); /* Do system-dependent initialization */
249 void sys_cleanup(void); /* Restore system state before exiting */
250 void sys_check_options(void); /* Check options specified */
251 void sys_close(void); /* Clean up in a child before execing */
252 int ppp_available(void); /* Test whether ppp kernel support exists */
253 void open_ppp_loopback(void); /* Open loopback for demand-dialling */
254 void establish_ppp(int); /* Turn serial port into a ppp interface */
255 void restore_loop(void); /* Transfer ppp unit back to loopback */
256 void disestablish_ppp(int); /* Restore port to normal operation */
257 void clean_check(void); /* Check if line was 8-bit clean */
258 void set_up_tty(int, int); /* Set up port's speed, parameters, etc. */
259 void restore_tty(int); /* Restore port's original parameters */
260 void setdtr(int, int); /* Raise or lower port's DTR line */
261 void output(int, u_char *, int); /* Output a PPP packet */
262 void wait_input(struct timeval *);
263 /* Wait for input, with timeout */
264 void wait_loop_output(struct timeval *);
265 /* Wait for pkt from loopback, with timeout */
266 void wait_time(struct timeval *); /* Wait for given length of time */
267 int read_packet(u_char *); /* Read PPP packet */
268 int get_loop_output(void); /* Read pkts from loopback */
269 void ppp_send_config(int, int, u_int32_t, int, int);
270 /* Configure i/f transmit parameters */
271 void ppp_set_xaccm(int, ext_accm);
272 /* Set extended transmit ACCM */
273 void ppp_recv_config(int, int, u_int32_t, int, int);
274 /* Configure i/f receive parameters */
275 int ccp_test(int, u_char *, int, int);
276 /* Test support for compression scheme */
277 void ccp_flags_set(int, int, int);
278 /* Set kernel CCP state */
279 int ccp_fatal_error(int); /* Test for fatal decomp error in kernel */
280 int get_idle_time(int, struct ppp_idle *);
281 /* Find out how long link has been idle */
282 int sifvjcomp(int, int, int, int);
283 /* Configure VJ TCP header compression */
284 int sifup(int); /* Configure i/f up (for IP) */
285 int sifnpmode(int u, int proto, enum NPmode mode);
286 /* Set mode for handling packets for proto */
287 int sifdown(int); /* Configure i/f down (for IP) */
288 int sifaddr(int, u_int32_t, u_int32_t, u_int32_t);
289 /* Configure IP addresses for i/f */
290 int cifaddr(int, u_int32_t, u_int32_t);
291 /* Reset i/f IP addresses */
292 #ifdef INET6
293 int sif6addr(int, eui64_t, eui64_t);
294 /* Configure IPv6 addresses for i/f */
295 int cif6addr(int, eui64_t, eui64_t);
296 /* Remove an IPv6 address from i/f */
297 #endif
298 int sifdefaultroute(int, u_int32_t, u_int32_t);
299 /* Create default route through i/f */
300 int cifdefaultroute(int, u_int32_t, u_int32_t);
301 /* Delete default route through i/f */
302 int sifproxyarp(int, u_int32_t);
303 /* Add proxy ARP entry for peer */
304 int cifproxyarp(int, u_int32_t);
305 /* Delete proxy ARP entry for peer */
306 u_int32_t GetMask(u_int32_t); /* Get appropriate netmask for address */
307 int lock(char *); /* Create lock file for device */
308 void unlock(void); /* Delete previously-created lock file */
309 int daemon(int, int); /* Detach us from terminal session */
310 void logwtmp(const char *, const char *, const char *);
311 /* Write entry to wtmp file */
312 int get_host_seed(void); /* Get host-dependent random number seed */
313 #ifdef PPP_FILTER
314 int set_filters(struct bpf_program *pass, struct bpf_program *active);
315 /* Set filter programs in kernel */
316 #endif
318 /* Procedures exported from options.c */
319 int parse_args(int argc, char **argv);
320 /* Parse options from arguments given */
321 void usage(void); /* Print a usage message */
322 int options_from_file(char *filename, int must_exist, int check_prot,
323 int privileged);
324 /* Parse options from an options file */
325 int options_from_user(void); /* Parse options from user's .ppprc */
326 int options_for_tty(void); /* Parse options from /etc/ppp/options.tty */
327 void scan_args(int argc, char **argv);
328 /* Look for tty name in command-line args */
329 int getword(FILE *f, char *word, int *newlinep, char *filename);
330 /* Read a word from a file */
331 void option_error(char *fmt, ...);
332 /* Print an error message about an option */
333 int setipaddr(char *); /* set IP addresses */
337 * This structure is used to store information about certain
338 * options, such as where the option value came from (/etc/ppp/options,
339 * command line, etc.) and whether it came from a privileged source.
342 struct option_info {
343 int priv; /* was value set by sysadmin? */
344 char *source; /* where option came from */
347 extern struct option_info auth_req_info;
348 extern struct option_info connector_info;
349 extern struct option_info disconnector_info;
350 extern struct option_info welcomer_info;
351 extern struct option_info devnam_info;
354 * Inline versions of get/put char/short/long.
355 * Pointer is advanced; we assume that both arguments
356 * are lvalues and will already be in registers.
357 * cp MUST be u_char *.
359 #define GETCHAR(c, cp) { \
360 (c) = *(cp)++; \
362 #define PUTCHAR(c, cp) { \
363 *(cp)++ = (u_char) (c); \
367 #define GETSHORT(s, cp) { \
368 (s) = *(cp)++ << 8; \
369 (s) |= *(cp)++; \
371 #define PUTSHORT(s, cp) { \
372 *(cp)++ = (u_char) ((s) >> 8); \
373 *(cp)++ = (u_char) (s); \
376 #define GETLONG(l, cp) { \
377 (l) = *(cp)++ << 8; \
378 (l) |= *(cp)++; (l) <<= 8; \
379 (l) |= *(cp)++; (l) <<= 8; \
380 (l) |= *(cp)++; \
382 #define PUTLONG(l, cp) { \
383 *(cp)++ = (u_char) ((l) >> 24); \
384 *(cp)++ = (u_char) ((l) >> 16); \
385 *(cp)++ = (u_char) ((l) >> 8); \
386 *(cp)++ = (u_char) (l); \
389 #define INCPTR(n, cp) ((cp) += (n))
390 #define DECPTR(n, cp) ((cp) -= (n))
392 #undef FALSE
393 #define FALSE 0
394 #undef TRUE
395 #define TRUE 1
398 * System dependent definitions for user-level 4.3BSD UNIX implementation.
401 #define DEMUXPROTREJ(u, p) demuxprotrej(u, p)
403 #define TIMEOUT(r, f, t) timeout((r), (f), (t))
404 #define UNTIMEOUT(r, f) untimeout((r), (f))
406 #define BCOPY(s, d, l) memcpy(d, s, l)
407 #define BZERO(s, n) memset(s, 0, n)
408 #define EXIT(u) quit()
410 #define PRINTMSG(m, l) { m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); }
413 * MAKEHEADER - Add Header fields to a packet.
415 #define MAKEHEADER(p, t) { \
416 PUTCHAR(PPP_ALLSTATIONS, p); \
417 PUTCHAR(PPP_UI, p); \
418 PUTSHORT(t, p); }
421 #ifdef DEBUGALL
422 #define DEBUGMAIN 1
423 #define DEBUGFSM 1
424 #define DEBUGLCP 1
425 #define DEBUGIPCP 1
426 #define DEBUGUPAP 1
427 #define DEBUGCHAP 1
428 #endif
430 #ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */
431 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
432 || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
433 || defined(DEBUGCHAP) || defined(DEBUG)
434 #define LOG_PPP LOG_LOCAL2
435 #else
436 #define LOG_PPP LOG_DAEMON
437 #endif
438 #endif /* LOG_PPP */
440 #ifdef DEBUGMAIN
441 #define MAINDEBUG(x) if (debug) syslog x
442 #else
443 #define MAINDEBUG(x)
444 #endif
446 #ifdef DEBUGSYS
447 #define SYSDEBUG(x) if (debug) syslog x
448 #else
449 #define SYSDEBUG(x)
450 #endif
452 #ifdef DEBUGFSM
453 #define FSMDEBUG(x) if (debug) syslog x
454 #else
455 #define FSMDEBUG(x)
456 #endif
458 #ifdef DEBUGLCP
459 #define LCPDEBUG(x) if (debug) syslog x
460 #else
461 #define LCPDEBUG(x)
462 #endif
464 #ifdef DEBUGIPCP
465 #define IPCPDEBUG(x) if (debug) syslog x
466 #else
467 #define IPCPDEBUG(x)
468 #endif
470 #ifdef DEBUGIPV6CP
471 #define IPV6CPDEBUG(x) if (debug) syslog x
472 #else
473 #define IPV6CPDEBUG(x)
474 #endif
476 #ifdef DEBUGUPAP
477 #define UPAPDEBUG(x) if (debug) syslog x
478 #else
479 #define UPAPDEBUG(x)
480 #endif
482 #ifdef DEBUGCHAP
483 #define CHAPDEBUG(x) if (debug) syslog x
484 #else
485 #define CHAPDEBUG(x)
486 #endif
488 #ifdef DEBUGIPXCP
489 #define IPXCPDEBUG(x) if (debug) syslog x
490 #else
491 #define IPXCPDEBUG(x)
492 #endif
494 #ifndef SIGTYPE
495 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
496 #define SIGTYPE void
497 #else
498 #define SIGTYPE int
499 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
500 #endif /* SIGTYPE */
502 #ifndef MIN
503 #define MIN(a, b) ((a) < (b)? (a): (b))
504 #endif
505 #ifndef MAX
506 #define MAX(a, b) ((a) > (b)? (a): (b))
507 #endif
509 #endif /* __PPP_H__ */