remove unneeded devnam_info
[mpls-ppp.git] / pppd / pppd.h
blob6e2ef37d91087b23256f91743ade411af806ab30
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 * $Id: pppd.h,v 1.24 1999/01/20 00:01:00 paulus Exp $
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
45 * Limits.
48 #define NUM_PPP 1 /* One PPP interface supported (per process) */
49 #define MAXWORDLEN 1024 /* max length of word in file (incl null) */
50 #define MAXARGS 1 /* max # args to a command */
51 #define MAXNAMELEN 256 /* max length of hostname or name for auth */
52 #define MAXSECRETLEN 256 /* max length of password or secret */
55 * Option descriptor structure.
58 typedef unsigned char bool;
60 enum opt_type {
61 o_special_noarg = 0,
62 o_special = 1,
63 o_bool,
64 o_int,
65 o_uint32,
66 o_string,
69 typedef struct {
70 char *name; /* name of the option */
71 enum opt_type type;
72 void *addr;
73 char *description;
74 int flags;
75 void *addr2;
76 int upper_limit;
77 int lower_limit;
78 } option_t;
80 /* Values for flags */
81 #define OPT_VALUE 0xff /* mask for presupplied value */
82 #define OPT_HEX 0x100 /* int option is in hex */
83 #define OPT_NOARG 0x200 /* option doesn't take argument */
84 #define OPT_OR 0x400 /* OR in argument to value */
85 #define OPT_INC 0x800 /* increment value */
86 #define OPT_PRIV 0x1000 /* privileged option */
87 #define OPT_STATIC 0x2000 /* string option goes into static array */
88 #define OPT_LLIMIT 0x4000 /* check value against lower limit */
89 #define OPT_ULIMIT 0x8000 /* check value against upper limit */
90 #define OPT_LIMITS (OPT_LLIMIT|OPT_ULIMIT)
91 #define OPT_ZEROOK 0x10000 /* 0 value is OK even if not within limits */
92 #define OPT_NOINCR 0x20000 /* value mustn't be increased */
93 #define OPT_ZEROINF 0x40000 /* with OPT_NOINCR, 0 == infinity */
94 #define OPT_A2INFO 0x100000 /* addr2 -> option_info to update */
95 #define OPT_A2COPY 0x200000 /* addr2 -> second location to rcv value */
96 #define OPT_ENABLE 0x400000 /* use *addr2 as enable for option */
98 #define OPT_VAL(x) ((x) & OPT_VALUE)
101 * Global variables.
104 extern int hungup; /* Physical layer has disconnected */
105 extern int ifunit; /* Interface unit number */
106 extern char ifname[]; /* Interface name */
107 extern int ttyfd; /* Serial device file descriptor */
108 extern char hostname[]; /* Our hostname */
109 extern u_char outpacket_buf[]; /* Buffer for outgoing packets */
110 extern int phase; /* Current state of link - see values below */
111 extern int baud_rate; /* Current link speed in bits/sec */
112 extern char *progname; /* Name of this program */
113 extern int redirect_stderr;/* Connector's stderr should go to file */
114 extern char peer_authname[];/* Authenticated name of peer */
115 extern int privileged; /* We were run by real-uid root */
116 extern int need_holdoff; /* Need holdoff period after link terminates */
117 extern char **script_env; /* Environment variables for scripts */
118 extern int detached; /* Have detached from controlling tty */
121 * Variables set by command-line options.
124 extern int debug; /* Debug flag */
125 extern int kdebugflag; /* Tell kernel to print debug messages */
126 extern int default_device; /* Using /dev/tty or equivalent */
127 extern char devnam[]; /* Device name */
128 extern int crtscts; /* Use hardware flow control */
129 extern bool modem; /* Use modem control lines */
130 extern int inspeed; /* Input/Output speed requested */
131 extern u_int32_t netmask; /* IP netmask to set on interface */
132 extern bool lockflag; /* Create lock file to lock the serial dev */
133 extern bool nodetach; /* Don't detach from controlling tty */
134 extern bool updetach; /* Detach from controlling tty when link up */
135 extern char *connector; /* Script to establish physical link */
136 extern char *disconnector; /* Script to disestablish physical link */
137 extern char *welcomer; /* Script to welcome client after connection */
138 extern int maxconnect; /* Maximum connect time (seconds) */
139 extern char user[]; /* Our name for authenticating ourselves */
140 extern char passwd[]; /* Password for PAP */
141 extern bool auth_required; /* Peer is required to authenticate */
142 extern bool persist; /* Reopen link after it goes down */
143 extern bool uselogin; /* Use /etc/passwd for checking PAP */
144 extern char our_name[]; /* Our name for authentication purposes */
145 extern char remote_name[]; /* Peer's name for authentication */
146 extern int explicit_remote;/* remote_name specified with remotename opt */
147 extern bool demand; /* Do dial-on-demand */
148 extern char *ipparam; /* Extra parameter for ip up/down scripts */
149 extern bool cryptpap; /* Others' PAP passwords are encrypted */
150 extern int idle_time_limit;/* Shut down link if idle for this long */
151 extern int holdoff; /* Dead time before restarting */
152 #ifdef PPP_FILTER
153 extern struct bpf_program pass_filter; /* Filter for pkts to pass */
154 extern struct bpf_program active_filter; /* Filter for link-active pkts */
155 #endif
157 char *current_option; /* the name of the option being parsed */
158 int privileged_option; /* set iff the current option came from root */
159 char *option_source; /* string saying where the option came from */
161 #ifdef MSLANMAN
162 extern bool ms_lanman; /* Use LanMan password instead of NT */
163 /* Has meaning only with MS-CHAP challenges */
164 #endif
167 * Values for phase.
169 #define PHASE_DEAD 0
170 #define PHASE_INITIALIZE 1
171 #define PHASE_DORMANT 2
172 #define PHASE_ESTABLISH 3
173 #define PHASE_AUTHENTICATE 4
174 #define PHASE_CALLBACK 5
175 #define PHASE_NETWORK 6
176 #define PHASE_TERMINATE 7
177 #define PHASE_HOLDOFF 8
180 * The following struct gives the addresses of procedures to call
181 * for a particular protocol.
183 struct protent {
184 u_short protocol; /* PPP protocol number */
185 /* Initialization procedure */
186 void (*init) __P((int unit));
187 /* Process a received packet */
188 void (*input) __P((int unit, u_char *pkt, int len));
189 /* Process a received protocol-reject */
190 void (*protrej) __P((int unit));
191 /* Lower layer has come up */
192 void (*lowerup) __P((int unit));
193 /* Lower layer has gone down */
194 void (*lowerdown) __P((int unit));
195 /* Open the protocol */
196 void (*open) __P((int unit));
197 /* Close the protocol */
198 void (*close) __P((int unit, char *reason));
199 /* Print a packet in readable form */
200 int (*printpkt) __P((u_char *pkt, int len,
201 void (*printer) __P((void *, char *, ...)),
202 void *arg));
203 /* Process a received data packet */
204 void (*datainput) __P((int unit, u_char *pkt, int len));
205 bool enabled_flag; /* 0 iff protocol is disabled */
206 char *name; /* Text name of protocol */
207 option_t *options; /* List of command-line options */
208 /* Check requested options, assign defaults */
209 void (*check_options) __P((void));
210 /* Configure interface for demand-dial */
211 int (*demand_conf) __P((int unit));
212 /* Say whether to bring up link for this pkt */
213 int (*active_pkt) __P((u_char *pkt, int len));
216 /* Table of pointers to supported protocols */
217 extern struct protent *protocols[];
220 * Prototypes.
223 /* Procedures exported from main.c. */
224 void detach __P((void)); /* Detach from controlling tty */
225 void die __P((int)); /* Cleanup and exit */
226 void quit __P((void)); /* like die(1) */
227 void novm __P((char *)); /* Say we ran out of memory, and die */
228 void timeout __P((void (*func)(void *), void *arg, int t));
229 /* Call func(arg) after t seconds */
230 void untimeout __P((void (*func)(void *), void *arg));
231 /* Cancel call to func(arg) */
232 pid_t run_program __P((char *prog, char **args, int must_exist,
233 void (*done)(void *), void *arg));
234 /* Run program prog with args in child */
235 void demuxprotrej __P((int, int));
236 /* Demultiplex a Protocol-Reject */
237 void format_packet __P((u_char *, int, void (*) (void *, char *, ...),
238 void *)); /* Format a packet in human-readable form */
239 void log_packet __P((u_char *, int, char *, int));
240 /* Format a packet and log it with syslog */
241 void print_string __P((char *, int, void (*) (void *, char *, ...),
242 void *)); /* Format a string for output */
243 int fmtmsg __P((char *, int, char *, ...)); /* sprintf++ */
244 int vfmtmsg __P((char *, int, char *, va_list)); /* vsprintf++ */
245 void script_setenv __P((char *, char *)); /* set script env var */
246 void script_unsetenv __P((char *)); /* unset script env var */
248 /* Procedures exported from auth.c */
249 void link_required __P((int)); /* we are starting to use the link */
250 void link_terminated __P((int)); /* we are finished with the link */
251 void link_down __P((int)); /* the LCP layer has left the Opened state */
252 void link_established __P((int)); /* the link is up; authenticate now */
253 void np_up __P((int, int)); /* a network protocol has come up */
254 void np_down __P((int, int)); /* a network protocol has gone down */
255 void np_finished __P((int, int)); /* a network protocol no longer needs link */
256 void auth_peer_fail __P((int, int));
257 /* peer failed to authenticate itself */
258 void auth_peer_success __P((int, int, char *, int));
259 /* peer successfully authenticated itself */
260 void auth_withpeer_fail __P((int, int));
261 /* we failed to authenticate ourselves */
262 void auth_withpeer_success __P((int, int));
263 /* we successfully authenticated ourselves */
264 void auth_check_options __P((void));
265 /* check authentication options supplied */
266 void auth_reset __P((int)); /* check what secrets we have */
267 int check_passwd __P((int, char *, int, char *, int, char **, int *));
268 /* Check peer-supplied username/password */
269 int get_secret __P((int, char *, char *, char *, int *, int));
270 /* get "secret" for chap */
271 int auth_ip_addr __P((int, u_int32_t));
272 /* check if IP address is authorized */
273 int bad_ip_adrs __P((u_int32_t));
274 /* check if IP address is unreasonable */
275 void check_access __P((FILE *, char *));
276 /* check permissions on secrets file */
278 /* Procedures exported from demand.c */
279 void demand_conf __P((void)); /* config interface(s) for demand-dial */
280 void demand_block __P((void)); /* set all NPs to queue up packets */
281 void demand_unblock __P((void)); /* set all NPs to pass packets */
282 void demand_discard __P((void)); /* set all NPs to discard packets */
283 void demand_rexmit __P((int)); /* retransmit saved frames for an NP */
284 int loop_chars __P((unsigned char *, int)); /* process chars from loopback */
285 int loop_frame __P((unsigned char *, int)); /* process frame from loopback */
287 /* Procedures exported from sys-*.c */
288 void sys_init __P((void)); /* Do system-dependent initialization */
289 void sys_cleanup __P((void)); /* Restore system state before exiting */
290 int sys_check_options __P((void)); /* Check options specified */
291 void sys_close __P((void)); /* Clean up in a child before execing */
292 int ppp_available __P((void)); /* Test whether ppp kernel support exists */
293 void open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */
294 void establish_ppp __P((int)); /* Turn serial port into a ppp interface */
295 void restore_loop __P((void)); /* Transfer ppp unit back to loopback */
296 void disestablish_ppp __P((int)); /* Restore port to normal operation */
297 void clean_check __P((void)); /* Check if line was 8-bit clean */
298 void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */
299 void restore_tty __P((int)); /* Restore port's original parameters */
300 void setdtr __P((int, int)); /* Raise or lower port's DTR line */
301 void output __P((int, u_char *, int)); /* Output a PPP packet */
302 void wait_input __P((struct timeval *));
303 /* Wait for input, with timeout */
304 void wait_loop_output __P((struct timeval *));
305 /* Wait for pkt from loopback, with timeout */
306 void wait_time __P((struct timeval *)); /* Wait for given length of time */
307 int read_packet __P((u_char *)); /* Read PPP packet */
308 int get_loop_output __P((void)); /* Read pkts from loopback */
309 void ppp_send_config __P((int, int, u_int32_t, int, int));
310 /* Configure i/f transmit parameters */
311 void ppp_set_xaccm __P((int, ext_accm));
312 /* Set extended transmit ACCM */
313 void ppp_recv_config __P((int, int, u_int32_t, int, int));
314 /* Configure i/f receive parameters */
315 int ccp_test __P((int, u_char *, int, int));
316 /* Test support for compression scheme */
317 void ccp_flags_set __P((int, int, int));
318 /* Set kernel CCP state */
319 int ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */
320 int get_idle_time __P((int, struct ppp_idle *));
321 /* Find out how long link has been idle */
322 int sifvjcomp __P((int, int, int, int));
323 /* Configure VJ TCP header compression */
324 int sifup __P((int)); /* Configure i/f up (for IP) */
325 int sifnpmode __P((int u, int proto, enum NPmode mode));
326 /* Set mode for handling packets for proto */
327 int sifdown __P((int)); /* Configure i/f down (for IP) */
328 int sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t));
329 /* Configure IP addresses for i/f */
330 int cifaddr __P((int, u_int32_t, u_int32_t));
331 /* Reset i/f IP addresses */
332 int sifdefaultroute __P((int, u_int32_t, u_int32_t));
333 /* Create default route through i/f */
334 int cifdefaultroute __P((int, u_int32_t, u_int32_t));
335 /* Delete default route through i/f */
336 int sifproxyarp __P((int, u_int32_t));
337 /* Add proxy ARP entry for peer */
338 int cifproxyarp __P((int, u_int32_t));
339 /* Delete proxy ARP entry for peer */
340 u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */
341 int lock __P((char *)); /* Create lock file for device */
342 void unlock __P((void)); /* Delete previously-created lock file */
343 int daemon __P((int, int)); /* Detach us from terminal session */
344 void logwtmp __P((const char *, const char *, const char *));
345 /* Write entry to wtmp file */
346 int get_host_seed __P((void)); /* Get host-dependent random number seed */
347 int have_route_to __P((u_int32_t)); /* Check if route to addr exists */
348 void hangup_modem __P((int)); /* Make modem hang up */
349 #ifdef PPP_FILTER
350 int set_filters __P((struct bpf_program *pass, struct bpf_program *active));
351 /* Set filter programs in kernel */
352 #endif
353 #ifdef IPX_CHANGE
354 int sipxfaddr __P((int, unsigned long, unsigned char *));
355 int cipxfaddr __P((int));
356 #endif
358 /* Procedures exported from options.c */
359 int parse_args __P((int argc, char **argv));
360 /* Parse options from arguments given */
361 void usage __P((void)); /* Print a usage message */
362 int options_from_file __P((char *filename, int must_exist, int check_prot,
363 int privileged));
364 /* Parse options from an options file */
365 int options_from_user __P((void)); /* Parse options from user's .ppprc */
366 int options_for_tty __P((void)); /* Parse options from /etc/ppp/options.tty */
367 void scan_args __P((int argc, char **argv));
368 /* Look for tty name in command-line args */
369 int getword __P((FILE *f, char *word, int *newlinep, char *filename));
370 /* Read a word from a file */
371 void option_error __P((char *fmt, ...));
372 /* Print an error message about an option */
373 int number_option __P((char *, u_int32_t *, int));
374 /* Parse a numerical option */
375 int int_option __P((char *, int *));
376 /* Simplified number_option for decimal ints */
379 * This structure is used to store information about certain
380 * options, such as where the option value came from (/etc/ppp/options,
381 * command line, etc.) and whether it came from a privileged source.
384 struct option_info {
385 int priv; /* was value set by sysadmin? */
386 char *source; /* where option came from */
389 extern struct option_info auth_req_info;
390 extern struct option_info connector_info;
391 extern struct option_info disconnector_info;
392 extern struct option_info welcomer_info;
395 * Inline versions of get/put char/short/long.
396 * Pointer is advanced; we assume that both arguments
397 * are lvalues and will already be in registers.
398 * cp MUST be u_char *.
400 #define GETCHAR(c, cp) { \
401 (c) = *(cp)++; \
403 #define PUTCHAR(c, cp) { \
404 *(cp)++ = (u_char) (c); \
408 #define GETSHORT(s, cp) { \
409 (s) = *(cp)++ << 8; \
410 (s) |= *(cp)++; \
412 #define PUTSHORT(s, cp) { \
413 *(cp)++ = (u_char) ((s) >> 8); \
414 *(cp)++ = (u_char) (s); \
417 #define GETLONG(l, cp) { \
418 (l) = *(cp)++ << 8; \
419 (l) |= *(cp)++; (l) <<= 8; \
420 (l) |= *(cp)++; (l) <<= 8; \
421 (l) |= *(cp)++; \
423 #define PUTLONG(l, cp) { \
424 *(cp)++ = (u_char) ((l) >> 24); \
425 *(cp)++ = (u_char) ((l) >> 16); \
426 *(cp)++ = (u_char) ((l) >> 8); \
427 *(cp)++ = (u_char) (l); \
430 #define INCPTR(n, cp) ((cp) += (n))
431 #define DECPTR(n, cp) ((cp) -= (n))
433 #undef FALSE
434 #define FALSE 0
435 #undef TRUE
436 #define TRUE 1
439 * System dependent definitions for user-level 4.3BSD UNIX implementation.
442 #define DEMUXPROTREJ(u, p) demuxprotrej(u, p)
444 #define TIMEOUT(r, f, t) timeout((r), (f), (t))
445 #define UNTIMEOUT(r, f) untimeout((r), (f))
447 #define BCOPY(s, d, l) memcpy(d, s, l)
448 #define BZERO(s, n) memset(s, 0, n)
449 #define EXIT(u) quit()
451 #define PRINTMSG(m, l) { m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); }
454 * MAKEHEADER - Add Header fields to a packet.
456 #define MAKEHEADER(p, t) { \
457 PUTCHAR(PPP_ALLSTATIONS, p); \
458 PUTCHAR(PPP_UI, p); \
459 PUTSHORT(t, p); }
462 #ifdef DEBUGALL
463 #define DEBUGMAIN 1
464 #define DEBUGFSM 1
465 #define DEBUGLCP 1
466 #define DEBUGIPCP 1
467 #define DEBUGUPAP 1
468 #define DEBUGCHAP 1
469 #endif
471 #ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */
472 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
473 || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
474 || defined(DEBUGCHAP) || defined(DEBUG)
475 #define LOG_PPP LOG_LOCAL2
476 #else
477 #define LOG_PPP LOG_DAEMON
478 #endif
479 #endif /* LOG_PPP */
481 #ifdef DEBUGMAIN
482 #define MAINDEBUG(x) if (debug) syslog x
483 #else
484 #define MAINDEBUG(x)
485 #endif
487 #ifdef DEBUGSYS
488 #define SYSDEBUG(x) if (debug) syslog x
489 #else
490 #define SYSDEBUG(x)
491 #endif
493 #ifdef DEBUGFSM
494 #define FSMDEBUG(x) if (debug) syslog x
495 #else
496 #define FSMDEBUG(x)
497 #endif
499 #ifdef DEBUGLCP
500 #define LCPDEBUG(x) if (debug) syslog x
501 #else
502 #define LCPDEBUG(x)
503 #endif
505 #ifdef DEBUGIPCP
506 #define IPCPDEBUG(x) if (debug) syslog x
507 #else
508 #define IPCPDEBUG(x)
509 #endif
511 #ifdef DEBUGUPAP
512 #define UPAPDEBUG(x) if (debug) syslog x
513 #else
514 #define UPAPDEBUG(x)
515 #endif
517 #ifdef DEBUGCHAP
518 #define CHAPDEBUG(x) if (debug) syslog x
519 #else
520 #define CHAPDEBUG(x)
521 #endif
523 #ifdef DEBUGIPXCP
524 #define IPXCPDEBUG(x) if (debug) syslog x
525 #else
526 #define IPXCPDEBUG(x)
527 #endif
529 #ifndef SIGTYPE
530 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
531 #define SIGTYPE void
532 #else
533 #define SIGTYPE int
534 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
535 #endif /* SIGTYPE */
537 #ifndef MIN
538 #define MIN(a, b) ((a) < (b)? (a): (b))
539 #endif
540 #ifndef MAX
541 #define MAX(a, b) ((a) > (b)? (a): (b))
542 #endif
544 #endif /* __PPP_H__ */