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