carp: add carp_group_demote_adj()
[dragonfly.git] / usr.sbin / pppd / pppd.h
... / ...
CommitLineData
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 * $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 $
21 */
22
23/*
24 * TODO:
25 */
26
27#ifndef __PPPD_H__
28#define __PPPD_H__
29
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>
35
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
44
45/*
46 * Limits.
47 */
48
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 */
54
55/*
56 * Global variables.
57 */
58
59extern int hungup; /* Physical layer has disconnected */
60extern int ifunit; /* Interface unit number */
61extern char ifname[]; /* Interface name */
62extern int ttyfd; /* Serial device file descriptor */
63extern char hostname[]; /* Our hostname */
64extern u_char outpacket_buf[]; /* Buffer for outgoing packets */
65extern int phase; /* Current state of link - see values below */
66extern int baud_rate; /* Current link speed in bits/sec */
67extern char *progname; /* Name of this program */
68extern int redirect_stderr;/* Connector's stderr should go to file */
69extern char peer_authname[];/* Authenticated name of peer */
70extern int privileged; /* We were run by real-uid root */
71extern int need_holdoff; /* Need holdoff period after link terminates */
72extern char **script_env; /* Environment variables for scripts */
73extern int detached; /* Have detached from controlling tty */
74
75/*
76 * Variables set by command-line options.
77 */
78
79extern int debug; /* Debug flag */
80extern int kdebugflag; /* Tell kernel to print debug messages */
81extern int default_device; /* Using /dev/tty or equivalent */
82extern char devnam[]; /* Device name */
83extern int crtscts; /* Use hardware flow control */
84extern int modem; /* Use modem control lines */
85extern int inspeed; /* Input/Output speed requested */
86extern u_int32_t netmask; /* IP netmask to set on interface */
87extern int lockflag; /* Create lock file to lock the serial dev */
88extern int nodetach; /* Don't detach from controlling tty */
89extern char *connector; /* Script to establish physical link */
90extern char *disconnector; /* Script to disestablish physical link */
91extern char *welcomer; /* Script to welcome client after connection */
92extern int max_con_attempts;/* Maximum number of times to try dialing */
93extern int maxconnect; /* Maximum connect time (seconds) */
94extern char user[]; /* Our name for authenticating ourselves */
95extern char passwd[]; /* Password for PAP */
96extern int auth_required; /* Peer is required to authenticate */
97extern int proxyarp; /* Set up proxy ARP entry for peer */
98extern int persist; /* Reopen link after it goes down */
99extern int uselogin; /* Use /etc/passwd for checking PAP */
100extern int lcp_echo_interval; /* Interval between LCP echo-requests */
101extern int lcp_echo_fails; /* Tolerance to unanswered echo-requests */
102extern char our_name[]; /* Our name for authentication purposes */
103extern char remote_name[]; /* Peer's name for authentication */
104extern int explicit_remote;/* remote_name specified with remotename opt */
105extern int usehostname; /* Use hostname for our_name */
106extern int disable_defaultip; /* Don't use hostname for default IP adrs */
107extern int demand; /* Do dial-on-demand */
108extern char *ipparam; /* Extra parameter for ip up/down scripts */
109extern int cryptpap; /* Others' PAP passwords are encrypted */
110extern int idle_time_limit;/* Shut down link if idle for this long */
111extern int holdoff; /* Dead time before restarting */
112extern int refuse_pap; /* Don't wanna auth. ourselves with PAP */
113extern int refuse_chap; /* Don't wanna auth. ourselves with CHAP */
114#ifdef PPP_FILTER
115extern struct bpf_program pass_filter; /* Filter for pkts to pass */
116extern struct bpf_program active_filter; /* Filter for link-active pkts */
117#endif
118
119
120#ifdef MSLANMAN
121extern int ms_lanman; /* Nonzero if use LanMan password instead of NT */
122 /* Has meaning only with MS-CHAP challenges */
123#endif
124
125/*
126 * Values for phase.
127 */
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
137
138/*
139 * The following struct gives the addresses of procedures to call
140 * for a particular protocol.
141 */
142struct 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);
172};
173
174/* Table of pointers to supported protocols */
175extern struct protent *protocols[];
176
177/*
178 * Prototypes.
179 */
180
181/* Procedures exported from main.c. */
182void detach(void); /* Detach from controlling tty */
183void die(int); /* Cleanup and exit */
184void quit(void); /* like die(1) */
185void novm(char *); /* Say we ran out of memory, and die */
186void timeout(void (*func)(void *), void *arg, int t);
187 /* Call func(arg) after t seconds */
188void untimeout(void (*func)(void *), void *arg);
189 /* Cancel call to func(arg) */
190int run_program(char *prog, char **args, int must_exist);
191 /* Run program prog with args in child */
192void demuxprotrej(int, int);
193 /* Demultiplex a Protocol-Reject */
194void format_packet(u_char *, int, void (*) (void *, char *, ...),
195 void *); /* Format a packet in human-readable form */
196void log_packet(u_char *, int, char *, int);
197 /* Format a packet and log it with syslog */
198void print_string(char *, int, void (*) (void *, char *, ...),
199 void *); /* Format a string for output */
200int fmtmsg(char *, int, char *, ...); /* sprintf++ */
201int vfmtmsg(char *, int, char *, va_list); /* vsprintf++ */
202void script_setenv(char *, char *); /* set script env var */
203void script_unsetenv(char *); /* unset script env var */
204
205/* Procedures exported from auth.c */
206void link_required(int); /* we are starting to use the link */
207void link_terminated(int); /* we are finished with the link */
208void link_down(int); /* the LCP layer has left the Opened state */
209void link_established(int); /* the link is up; authenticate now */
210void np_up(int, int); /* a network protocol has come up */
211void np_down(int, int); /* a network protocol has gone down */
212void np_finished(int, int); /* a network protocol no longer needs link */
213void auth_peer_fail(int, int);
214 /* peer failed to authenticate itself */
215void auth_peer_success(int, int, char *, int);
216 /* peer successfully authenticated itself */
217void auth_withpeer_fail(int, int);
218 /* we failed to authenticate ourselves */
219void auth_withpeer_success(int, int);
220 /* we successfully authenticated ourselves */
221void auth_check_options(void);
222 /* check authentication options supplied */
223void auth_reset(int); /* check what secrets we have */
224int check_passwd(int, char *, int, char *, int, char **, int *);
225 /* Check peer-supplied username/password */
226int get_secret(int, char *, char *, char *, int *, int);
227 /* get "secret" for chap */
228int auth_ip_addr(int, u_int32_t);
229 /* check if IP address is authorized */
230int bad_ip_adrs(u_int32_t);
231 /* check if IP address is unreasonable */
232void check_access(FILE *, char *);
233 /* check permissions on secrets file */
234
235/* Procedures exported from demand.c */
236void demand_conf(void); /* config interface(s for demand-dial */
237void demand_block(void); /* set all NPs to queue up packets */
238void demand_unblock(void); /* set all NPs to pass packets */
239void demand_discard(void); /* set all NPs to discard packets */
240void demand_rexmit(int); /* retransmit saved frames for an NP */
241int loop_chars(unsigned char *, int); /* process chars from loopback */
242int loop_frame(unsigned char *, int); /* process frame from loopback */
243
244/* Procedures exported from sys-*.c */
245void sys_init(void); /* Do system-dependent initialization */
246void sys_cleanup(void); /* Restore system state before exiting */
247void sys_check_options(void); /* Check options specified */
248void sys_close(void); /* Clean up in a child before execing */
249int ppp_available(void); /* Test whether ppp kernel support exists */
250void open_ppp_loopback(void); /* Open loopback for demand-dialling */
251void establish_ppp(int); /* Turn serial port into a ppp interface */
252void restore_loop(void); /* Transfer ppp unit back to loopback */
253void disestablish_ppp(int); /* Restore port to normal operation */
254void clean_check(void); /* Check if line was 8-bit clean */
255void set_up_tty(int, int); /* Set up port's speed, parameters, etc. */
256void restore_tty(int); /* Restore port's original parameters */
257void setdtr(int, int); /* Raise or lower port's DTR line */
258void output(int, u_char *, int); /* Output a PPP packet */
259void wait_input(struct timeval *);
260 /* Wait for input, with timeout */
261void wait_loop_output(struct timeval *);
262 /* Wait for pkt from loopback, with timeout */
263void wait_time(struct timeval *); /* Wait for given length of time */
264int read_packet(u_char *); /* Read PPP packet */
265int get_loop_output(void); /* Read pkts from loopback */
266void ppp_send_config(int, int, u_int32_t, int, int);
267 /* Configure i/f transmit parameters */
268void ppp_set_xaccm(int, ext_accm);
269 /* Set extended transmit ACCM */
270void ppp_recv_config(int, int, u_int32_t, int, int);
271 /* Configure i/f receive parameters */
272int ccp_test(int, u_char *, int, int);
273 /* Test support for compression scheme */
274void ccp_flags_set(int, int, int);
275 /* Set kernel CCP state */
276int ccp_fatal_error(int); /* Test for fatal decomp error in kernel */
277int get_idle_time(int, struct ppp_idle *);
278 /* Find out how long link has been idle */
279int sifvjcomp(int, int, int, int);
280 /* Configure VJ TCP header compression */
281int sifup(int); /* Configure i/f up (for IP) */
282int sifnpmode(int u, int proto, enum NPmode mode);
283 /* Set mode for handling packets for proto */
284int sifdown(int); /* Configure i/f down (for IP) */
285int sifaddr(int, u_int32_t, u_int32_t, u_int32_t);
286 /* Configure IP addresses for i/f */
287int cifaddr(int, u_int32_t, u_int32_t);
288 /* Reset i/f IP addresses */
289int sifdefaultroute(int, u_int32_t, u_int32_t);
290 /* Create default route through i/f */
291int cifdefaultroute(int, u_int32_t, u_int32_t);
292 /* Delete default route through i/f */
293int sifproxyarp(int, u_int32_t);
294 /* Add proxy ARP entry for peer */
295int cifproxyarp(int, u_int32_t);
296 /* Delete proxy ARP entry for peer */
297u_int32_t GetMask(u_int32_t); /* Get appropriate netmask for address */
298int lock(char *); /* Create lock file for device */
299void unlock(void); /* Delete previously-created lock file */
300int daemon(int, int); /* Detach us from terminal session */
301void logwtmp(const char *, const char *, const char *);
302 /* Write entry to wtmp file */
303int get_host_seed(void); /* Get host-dependent random number seed */
304#ifdef PPP_FILTER
305int set_filters(struct bpf_program *pass, struct bpf_program *active);
306 /* Set filter programs in kernel */
307#endif
308
309/* Procedures exported from options.c */
310int parse_args(int argc, char **argv);
311 /* Parse options from arguments given */
312void usage(void); /* Print a usage message */
313int options_from_file(char *filename, int must_exist, int check_prot,
314 int privileged);
315 /* Parse options from an options file */
316int options_from_user(void); /* Parse options from user's .ppprc */
317int options_for_tty(void); /* Parse options from /etc/ppp/options.tty */
318void scan_args(int argc, char **argv);
319 /* Look for tty name in command-line args */
320int getword(FILE *f, char *word, int *newlinep, char *filename);
321 /* Read a word from a file */
322void option_error(char *fmt, ...);
323 /* Print an error message about an option */
324int setipaddr(char *); /* set IP addresses */
325
326
327/*
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.
331 */
332
333struct option_info {
334 int priv; /* was value set by sysadmin? */
335 char *source; /* where option came from */
336};
337
338extern struct option_info auth_req_info;
339extern struct option_info connector_info;
340extern struct option_info disconnector_info;
341extern struct option_info welcomer_info;
342extern struct option_info devnam_info;
343
344/*
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 *.
349 */
350#define GETCHAR(c, cp) { \
351 (c) = *(cp)++; \
352}
353#define PUTCHAR(c, cp) { \
354 *(cp)++ = (u_char) (c); \
355}
356
357
358#define GETSHORT(s, cp) { \
359 (s) = *(cp)++ << 8; \
360 (s) |= *(cp)++; \
361}
362#define PUTSHORT(s, cp) { \
363 *(cp)++ = (u_char) ((s) >> 8); \
364 *(cp)++ = (u_char) (s); \
365}
366
367#define GETLONG(l, cp) { \
368 (l) = *(cp)++ << 8; \
369 (l) |= *(cp)++; (l) <<= 8; \
370 (l) |= *(cp)++; (l) <<= 8; \
371 (l) |= *(cp)++; \
372}
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); \
378}
379
380#define INCPTR(n, cp) ((cp) += (n))
381#define DECPTR(n, cp) ((cp) -= (n))
382
383#undef FALSE
384#define FALSE 0
385#undef TRUE
386#define TRUE 1
387
388/*
389 * System dependent definitions for user-level 4.3BSD UNIX implementation.
390 */
391
392#define DEMUXPROTREJ(u, p) demuxprotrej(u, p)
393
394#define TIMEOUT(r, f, t) timeout((r), (f), (t))
395#define UNTIMEOUT(r, f) untimeout((r), (f))
396
397#define BCOPY(s, d, l) memcpy(d, s, l)
398#define BZERO(s, n) memset(s, 0, n)
399#define EXIT(u) quit()
400
401#define PRINTMSG(m, l) { m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); }
402
403/*
404 * MAKEHEADER - Add Header fields to a packet.
405 */
406#define MAKEHEADER(p, t) { \
407 PUTCHAR(PPP_ALLSTATIONS, p); \
408 PUTCHAR(PPP_UI, p); \
409 PUTSHORT(t, p); }
410
411
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
420
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 */
430
431#ifdef DEBUGMAIN
432#define MAINDEBUG(x) if (debug) syslog x
433#else
434#define MAINDEBUG(x)
435#endif
436
437#ifdef DEBUGSYS
438#define SYSDEBUG(x) if (debug) syslog x
439#else
440#define SYSDEBUG(x)
441#endif
442
443#ifdef DEBUGFSM
444#define FSMDEBUG(x) if (debug) syslog x
445#else
446#define FSMDEBUG(x)
447#endif
448
449#ifdef DEBUGLCP
450#define LCPDEBUG(x) if (debug) syslog x
451#else
452#define LCPDEBUG(x)
453#endif
454
455#ifdef DEBUGIPCP
456#define IPCPDEBUG(x) if (debug) syslog x
457#else
458#define IPCPDEBUG(x)
459#endif
460
461#ifdef DEBUGUPAP
462#define UPAPDEBUG(x) if (debug) syslog x
463#else
464#define UPAPDEBUG(x)
465#endif
466
467#ifdef DEBUGCHAP
468#define CHAPDEBUG(x) if (debug) syslog x
469#else
470#define CHAPDEBUG(x)
471#endif
472
473#ifdef DEBUGIPXCP
474#define IPXCPDEBUG(x) if (debug) syslog x
475#else
476#define IPXCPDEBUG(x)
477#endif
478
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 */
486
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
493
494#endif /* __PPP_H__ */