2 * pppd.h - PPP daemon global declarations.
4 * Copyright (c) 1989 Carnegie Mellon University.
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.47 1999/09/08 01:13:45 masputra Exp $
29 #include <stdio.h> /* for FILE */
30 #include <limits.h> /* for NGROUPS_MAX */
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_defs.h>
41 #define __V(x) (va_alist) va_dcl
54 #define NUM_PPP 1 /* One PPP interface supported (per process) */
55 #define MAXWORDLEN 1024 /* max length of word in file (incl null) */
56 #define MAXARGS 1 /* max # args to a command */
57 #define MAXNAMELEN 256 /* max length of hostname or name for auth */
58 #define MAXSECRETLEN 256 /* max length of password or secret */
61 * Option descriptor structure.
64 typedef unsigned char bool;
76 char *name; /* name of the option */
86 /* Values for flags */
87 #define OPT_VALUE 0xff /* mask for presupplied value */
88 #define OPT_HEX 0x100 /* int option is in hex */
89 #define OPT_NOARG 0x200 /* option doesn't take argument */
90 #define OPT_OR 0x400 /* OR in argument to value */
91 #define OPT_INC 0x800 /* increment value */
92 #define OPT_PRIV 0x1000 /* privileged option */
93 #define OPT_STATIC 0x2000 /* string option goes into static array */
94 #define OPT_LLIMIT 0x4000 /* check value against lower limit */
95 #define OPT_ULIMIT 0x8000 /* check value against upper limit */
96 #define OPT_LIMITS (OPT_LLIMIT|OPT_ULIMIT)
97 #define OPT_ZEROOK 0x10000 /* 0 value is OK even if not within limits */
98 #define OPT_NOINCR 0x20000 /* value mustn't be increased */
99 #define OPT_ZEROINF 0x40000 /* with OPT_NOINCR, 0 == infinity */
100 #define OPT_A2INFO 0x100000 /* addr2 -> option_info to update */
101 #define OPT_A2COPY 0x200000 /* addr2 -> second location to rcv value */
102 #define OPT_ENABLE 0x400000 /* use *addr2 as enable for option */
103 #define OPT_PRIVFIX 0x800000 /* can't be overridden if noauth */
104 #define OPT_PREPASS 0x1000000 /* do this opt in pre-pass to find device */
105 #define OPT_INITONLY 0x2000000 /* option can only be set in init phase */
106 #define OPT_DEVEQUIV 0x4000000 /* equiv to device name */
107 #define OPT_DEVNAM (OPT_PREPASS | OPT_INITONLY | OPT_DEVEQUIV)
109 #define OPT_VAL(x) ((x) & OPT_VALUE)
112 #define GIDSET_TYPE gid_t
115 /* Structure representing a list of permitted IP addresses. */
116 struct permitted_ip {
117 int permit; /* 1 = permit, 0 = forbid */
118 u_int32_t base; /* match if (addr & mask) == base */
119 u_int32_t mask; /* base and mask are in network byte order */
123 * Unfortunately, the linux kernel driver uses a different structure
124 * for statistics from the rest of the ports.
125 * This structure serves as a common representation for the bits
129 unsigned int bytes_in;
130 unsigned int bytes_out;
133 /* Used for storing a sequence of words. Usually malloced. */
135 struct wordlist *next;
143 extern int hungup; /* Physical layer has disconnected */
144 extern int ifunit; /* Interface unit number */
145 extern char ifname[]; /* Interface name */
146 extern int ttyfd; /* Serial device file descriptor */
147 extern char hostname[]; /* Our hostname */
148 extern u_char outpacket_buf[]; /* Buffer for outgoing packets */
149 extern int phase; /* Current state of link - see values below */
150 extern int baud_rate; /* Current link speed in bits/sec */
151 extern char *progname; /* Name of this program */
152 extern int redirect_stderr;/* Connector's stderr should go to file */
153 extern char peer_authname[];/* Authenticated name of peer */
154 extern int privileged; /* We were run by real-uid root */
155 extern int need_holdoff; /* Need holdoff period after link terminates */
156 extern char **script_env; /* Environment variables for scripts */
157 extern int detached; /* Have detached from controlling tty */
158 extern GIDSET_TYPE groups[NGROUPS_MAX]; /* groups the user is in */
159 extern int ngroups; /* How many groups valid in groups */
160 extern struct pppd_stats link_stats; /* byte/packet counts etc. for link */
161 extern int link_stats_valid; /* set if link_stats is valid */
162 extern int using_pty; /* using pty as device (notty or pty opt.) */
163 extern int log_to_fd; /* logging to this fd as well as syslog */
164 extern char *no_ppp_msg; /* message to print if ppp not in kernel */
165 extern volatile int status; /* exit status for pppd */
166 extern int devnam_fixed; /* can no longer change devnam */
167 extern int unsuccess; /* # unsuccessful connection attempts */
170 * Variables set by command-line options.
173 extern int debug; /* Debug flag */
174 extern int kdebugflag; /* Tell kernel to print debug messages */
175 extern int default_device; /* Using /dev/tty or equivalent */
176 extern char devnam[MAXPATHLEN]; /* Device name */
177 extern int crtscts; /* Use hardware flow control */
178 extern bool modem; /* Use modem control lines */
179 extern int inspeed; /* Input/Output speed requested */
180 extern u_int32_t netmask; /* IP netmask to set on interface */
181 extern bool lockflag; /* Create lock file to lock the serial dev */
182 extern bool nodetach; /* Don't detach from controlling tty */
183 extern bool updetach; /* Detach from controlling tty when link up */
184 extern char *initializer; /* Script to initialize physical link */
185 extern char *connector; /* Script to establish physical link */
186 extern char *disconnector; /* Script to disestablish physical link */
187 extern char *welcomer; /* Script to welcome client after connection */
188 extern char *ptycommand; /* Command to run on other side of pty */
189 extern int maxconnect; /* Maximum connect time (seconds) */
190 extern char user[MAXNAMELEN];/* Our name for authenticating ourselves */
191 extern char passwd[MAXSECRETLEN]; /* Password for PAP or CHAP */
192 extern bool auth_required; /* Peer is required to authenticate */
193 extern bool persist; /* Reopen link after it goes down */
194 extern bool uselogin; /* Use /etc/passwd for checking PAP */
195 extern char our_name[MAXNAMELEN];/* Our name for authentication purposes */
196 extern char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
197 extern bool explicit_remote;/* remote_name specified with remotename opt */
198 extern bool demand; /* Do dial-on-demand */
199 extern char *ipparam; /* Extra parameter for ip up/down scripts */
200 extern bool cryptpap; /* Others' PAP passwords are encrypted */
201 extern int idle_time_limit;/* Shut down link if idle for this long */
202 extern int holdoff; /* Dead time before restarting */
203 extern bool notty; /* Stdin/out is not a tty */
204 extern char *record_file; /* File to record chars sent/received */
205 extern bool sync_serial; /* Device is synchronous serial device */
206 extern int maxfail; /* Max # of unsuccessful connection attempts */
207 extern char linkname[MAXPATHLEN]; /* logical name for link */
210 extern struct bpf_program pass_filter; /* Filter for pkts to pass */
211 extern struct bpf_program active_filter; /* Filter for link-active pkts */
215 extern bool ms_lanman; /* Use LanMan password instead of NT */
216 /* Has meaning only with MS-CHAP challenges */
219 extern char *current_option; /* the name of the option being parsed */
220 extern int privileged_option; /* set iff the current option came from root */
221 extern char *option_source; /* string saying where the option came from */
227 #define PHASE_INITIALIZE 1
228 #define PHASE_SERIALCONN 2
229 #define PHASE_DORMANT 3
230 #define PHASE_ESTABLISH 4
231 #define PHASE_AUTHENTICATE 5
232 #define PHASE_CALLBACK 6
233 #define PHASE_NETWORK 7
234 #define PHASE_TERMINATE 8
235 #define PHASE_HOLDOFF 9
238 * The following struct gives the addresses of procedures to call
239 * for a particular protocol.
242 u_short protocol; /* PPP protocol number */
243 /* Initialization procedure */
244 void (*init) __P((int unit));
245 /* Process a received packet */
246 void (*input) __P((int unit, u_char *pkt, int len));
247 /* Process a received protocol-reject */
248 void (*protrej) __P((int unit));
249 /* Lower layer has come up */
250 void (*lowerup) __P((int unit));
251 /* Lower layer has gone down */
252 void (*lowerdown) __P((int unit));
253 /* Open the protocol */
254 void (*open) __P((int unit));
255 /* Close the protocol */
256 void (*close) __P((int unit, char *reason));
257 /* Print a packet in readable form */
258 int (*printpkt) __P((u_char *pkt, int len,
259 void (*printer) __P((void *, char *, ...)),
261 /* Process a received data packet */
262 void (*datainput) __P((int unit, u_char *pkt, int len));
263 bool enabled_flag; /* 0 iff protocol is disabled */
264 char *name; /* Text name of protocol */
265 char *data_name; /* Text name of corresponding data protocol */
266 option_t *options; /* List of command-line options */
267 /* Check requested options, assign defaults */
268 void (*check_options) __P((void));
269 /* Configure interface for demand-dial */
270 int (*demand_conf) __P((int unit));
271 /* Say whether to bring up link for this pkt */
272 int (*active_pkt) __P((u_char *pkt, int len));
275 /* Table of pointers to supported protocols */
276 extern struct protent *protocols[];
282 /* Procedures exported from main.c. */
283 void detach __P((void)); /* Detach from controlling tty */
284 void die __P((int)); /* Cleanup and exit */
285 void quit __P((void)); /* like die(1) */
286 void novm __P((char *)); /* Say we ran out of memory, and die */
287 void timeout __P((void (*func)(void *), void *arg, int t));
288 /* Call func(arg) after t seconds */
289 void untimeout __P((void (*func)(void *), void *arg));
290 /* Cancel call to func(arg) */
291 pid_t run_program __P((char *prog, char **args, int must_exist,
292 void (*done)(void *), void *arg));
293 /* Run program prog with args in child */
294 void reopen_log __P((void)); /* (re)open the connection to syslog */
295 void update_link_stats __P((int)); /* Get stats at link termination */
296 void script_setenv __P((char *, char *)); /* set script env var */
297 void script_unsetenv __P((char *)); /* unset script env var */
299 /* Procedures exported from utils.c. */
300 void log_packet __P((u_char *, int, char *, int));
301 /* Format a packet and log it with syslog */
302 void print_string __P((char *, int, void (*) (void *, char *, ...),
303 void *)); /* Format a string for output */
304 int slprintf __P((char *, int, char *, ...)); /* sprintf++ */
305 int vslprintf __P((char *, int, char *, va_list)); /* vsprintf++ */
306 size_t strlcpy __P((char *, const char *, size_t)); /* safe strcpy */
307 size_t strlcat __P((char *, const char *, size_t)); /* safe strncpy */
308 void dbglog __P((char *, ...)); /* log a debug message */
309 void info __P((char *, ...)); /* log an informational message */
310 void notice __P((char *, ...)); /* log a notice-level message */
311 void warn __P((char *, ...)); /* log a warning message */
312 void error __P((char *, ...)); /* log an error message */
313 void fatal __P((char *, ...)); /* log an error message and die(1) */
315 /* Procedures exported from auth.c */
316 void link_required __P((int)); /* we are starting to use the link */
317 void link_terminated __P((int)); /* we are finished with the link */
318 void link_down __P((int)); /* the LCP layer has left the Opened state */
319 void link_established __P((int)); /* the link is up; authenticate now */
320 void start_networks __P((void)); /* start all the network control protos */
321 void np_up __P((int, int)); /* a network protocol has come up */
322 void np_down __P((int, int)); /* a network protocol has gone down */
323 void np_finished __P((int, int)); /* a network protocol no longer needs link */
324 void auth_peer_fail __P((int, int));
325 /* peer failed to authenticate itself */
326 void auth_peer_success __P((int, int, char *, int));
327 /* peer successfully authenticated itself */
328 void auth_withpeer_fail __P((int, int));
329 /* we failed to authenticate ourselves */
330 void auth_withpeer_success __P((int, int));
331 /* we successfully authenticated ourselves */
332 void auth_check_options __P((void));
333 /* check authentication options supplied */
334 void auth_reset __P((int)); /* check what secrets we have */
335 int check_passwd __P((int, char *, int, char *, int, char **, int *));
336 /* Check peer-supplied username/password */
337 int get_secret __P((int, char *, char *, char *, int *, int));
338 /* get "secret" for chap */
339 int auth_ip_addr __P((int, u_int32_t));
340 /* check if IP address is authorized */
341 int bad_ip_adrs __P((u_int32_t));
342 /* check if IP address is unreasonable */
344 /* Procedures exported from demand.c */
345 void demand_conf __P((void)); /* config interface(s) for demand-dial */
346 void demand_block __P((void)); /* set all NPs to queue up packets */
347 void demand_unblock __P((void)); /* set all NPs to pass packets */
348 void demand_discard __P((void)); /* set all NPs to discard packets */
349 void demand_rexmit __P((int)); /* retransmit saved frames for an NP */
350 int loop_chars __P((unsigned char *, int)); /* process chars from loopback */
351 int loop_frame __P((unsigned char *, int)); /* should we bring link up? */
353 /* Procedures exported from sys-*.c */
354 void sys_init __P((void)); /* Do system-dependent initialization */
355 void sys_cleanup __P((void)); /* Restore system state before exiting */
356 int sys_check_options __P((void)); /* Check options specified */
357 void sys_close __P((void)); /* Clean up in a child before execing */
358 int ppp_available __P((void)); /* Test whether ppp kernel support exists */
359 int get_pty __P((int *, int *, char *, int)); /* Get pty master/slave */
360 int open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */
361 int establish_ppp __P((int)); /* Turn serial port into a ppp interface */
362 void restore_loop __P((void)); /* Transfer ppp unit back to loopback */
363 void disestablish_ppp __P((int)); /* Restore port to normal operation */
364 void clean_check __P((void)); /* Check if line was 8-bit clean */
365 void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */
366 void restore_tty __P((int)); /* Restore port's original parameters */
367 void setdtr __P((int, int)); /* Raise or lower port's DTR line */
368 void output __P((int, u_char *, int)); /* Output a PPP packet */
369 void wait_input __P((struct timeval *));
370 /* Wait for input, with timeout */
371 void add_fd __P((int)); /* Add fd to set to wait for */
372 void remove_fd __P((int)); /* Remove fd from set to wait for */
373 int read_packet __P((u_char *)); /* Read PPP packet */
374 int get_loop_output __P((void)); /* Read pkts from loopback */
375 void ppp_send_config __P((int, int, u_int32_t, int, int));
376 /* Configure i/f transmit parameters */
377 void ppp_set_xaccm __P((int, ext_accm));
378 /* Set extended transmit ACCM */
379 void ppp_recv_config __P((int, int, u_int32_t, int, int));
380 /* Configure i/f receive parameters */
381 int ccp_test __P((int, u_char *, int, int));
382 /* Test support for compression scheme */
383 void ccp_flags_set __P((int, int, int));
384 /* Set kernel CCP state */
385 int ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */
386 int get_idle_time __P((int, struct ppp_idle *));
387 /* Find out how long link has been idle */
388 int get_ppp_stats __P((int, struct pppd_stats *));
389 /* Return link statistics */
390 int sifvjcomp __P((int, int, int, int));
391 /* Configure VJ TCP header compression */
392 int sifup __P((int)); /* Configure i/f up for one protocol */
393 int sifnpmode __P((int u, int proto, enum NPmode mode));
394 /* Set mode for handling packets for proto */
395 int sifdown __P((int)); /* Configure i/f down for one protocol */
396 int sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t));
397 /* Configure IPv4 addresses for i/f */
398 int cifaddr __P((int, u_int32_t, u_int32_t));
399 /* Reset i/f IP addresses */
401 int sif6addr __P((int, eui64_t, eui64_t));
402 /* Configure IPv6 addresses for i/f */
403 int cif6addr __P((int, eui64_t, eui64_t));
404 /* Remove an IPv6 address from i/f */
406 int sifdefaultroute __P((int, u_int32_t, u_int32_t));
407 /* Create default route through i/f */
408 int cifdefaultroute __P((int, u_int32_t, u_int32_t));
409 /* Delete default route through i/f */
410 int sifproxyarp __P((int, u_int32_t));
411 /* Add proxy ARP entry for peer */
412 int cifproxyarp __P((int, u_int32_t));
413 /* Delete proxy ARP entry for peer */
414 u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */
415 int lock __P((char *)); /* Create lock file for device */
416 int relock __P((int)); /* Rewrite lock file with new pid */
417 void unlock __P((void)); /* Delete previously-created lock file */
418 void logwtmp __P((const char *, const char *, const char *));
419 /* Write entry to wtmp file */
420 int get_host_seed __P((void)); /* Get host-dependent random number seed */
421 int have_route_to __P((u_int32_t)); /* Check if route to addr exists */
423 int set_filters __P((struct bpf_program *pass, struct bpf_program *active));
424 /* Set filter programs in kernel */
427 int sipxfaddr __P((int, unsigned long, unsigned char *));
428 int cipxfaddr __P((int));
431 /* Procedures exported from options.c */
432 int parse_args __P((int argc, char **argv));
433 /* Parse options from arguments given */
434 int options_from_file __P((char *filename, int must_exist, int check_prot,
436 /* Parse options from an options file */
437 int options_from_user __P((void)); /* Parse options from user's .ppprc */
438 int options_for_tty __P((void)); /* Parse options from /etc/ppp/options.tty */
439 int options_from_list __P((struct wordlist *, int privileged));
440 /* Parse options from a wordlist */
441 int getword __P((FILE *f, char *word, int *newlinep, char *filename));
442 /* Read a word from a file */
443 void option_error __P((char *fmt, ...));
444 /* Print an error message about an option */
445 int int_option __P((char *, int *));
446 /* Simplified number_option for decimal ints */
449 * This structure is used to store information about certain
450 * options, such as where the option value came from (/etc/ppp/options,
451 * command line, etc.) and whether it came from a privileged source.
455 int priv; /* was value set by sysadmin? */
456 char *source; /* where option came from */
459 extern struct option_info devnam_info;
460 extern struct option_info initializer_info;
461 extern struct option_info connector_info;
462 extern struct option_info disconnector_info;
463 extern struct option_info welcomer_info;
464 extern struct option_info ptycommand_info;
467 * Inline versions of get/put char/short/long.
468 * Pointer is advanced; we assume that both arguments
469 * are lvalues and will already be in registers.
470 * cp MUST be u_char *.
472 #define GETCHAR(c, cp) { \
475 #define PUTCHAR(c, cp) { \
476 *(cp)++ = (u_char) (c); \
480 #define GETSHORT(s, cp) { \
481 (s) = *(cp)++ << 8; \
484 #define PUTSHORT(s, cp) { \
485 *(cp)++ = (u_char) ((s) >> 8); \
486 *(cp)++ = (u_char) (s); \
489 #define GETLONG(l, cp) { \
490 (l) = *(cp)++ << 8; \
491 (l) |= *(cp)++; (l) <<= 8; \
492 (l) |= *(cp)++; (l) <<= 8; \
495 #define PUTLONG(l, cp) { \
496 *(cp)++ = (u_char) ((l) >> 24); \
497 *(cp)++ = (u_char) ((l) >> 16); \
498 *(cp)++ = (u_char) ((l) >> 8); \
499 *(cp)++ = (u_char) (l); \
502 #define INCPTR(n, cp) ((cp) += (n))
503 #define DECPTR(n, cp) ((cp) -= (n))
506 * System dependent definitions for user-level 4.3BSD UNIX implementation.
509 #define TIMEOUT(r, f, t) timeout((r), (f), (t))
510 #define UNTIMEOUT(r, f) untimeout((r), (f))
512 #define BCOPY(s, d, l) memcpy(d, s, l)
513 #define BZERO(s, n) memset(s, 0, n)
515 #define PRINTMSG(m, l) { info("Remote message: %0.*v", l, m); }
518 * MAKEHEADER - Add Header fields to a packet.
520 #define MAKEHEADER(p, t) { \
521 PUTCHAR(PPP_ALLSTATIONS, p); \
522 PUTCHAR(PPP_UI, p); \
526 * Exit status values.
529 #define EXIT_FATAL_ERROR 1
530 #define EXIT_OPTION_ERROR 2
531 #define EXIT_NOT_ROOT 3
532 #define EXIT_NO_KERNEL_SUPPORT 4
533 #define EXIT_USER_REQUEST 5
534 #define EXIT_LOCK_FAILED 6
535 #define EXIT_OPEN_FAILED 7
536 #define EXIT_CONNECT_FAILED 8
537 #define EXIT_PTYCMD_FAILED 9
538 #define EXIT_NEGOTIATION_FAILED 10
539 #define EXIT_PEER_AUTH_FAILED 11
540 #define EXIT_IDLE_TIMEOUT 12
541 #define EXIT_CONNECT_TIME 13
542 #define EXIT_CALLBACK 14
543 #define EXIT_PEER_DEAD 15
544 #define EXIT_HANGUP 16
545 #define EXIT_LOOPBACK 17
546 #define EXIT_INIT_FAILED 18
547 #define EXIT_AUTH_TOPEER_FAILED 19
550 * Debug macros. Slightly useful for finding bugs in pppd, not particularly
551 * useful for finding out why your connection isn't being established.
558 #define DEBUGIPV6CP 1
563 #ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */
564 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
565 || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
566 || defined(DEBUGCHAP) || defined(DEBUG) || defined(DEBUGIPV6CP)
567 #define LOG_PPP LOG_LOCAL2
569 #define LOG_PPP LOG_DAEMON
574 #define MAINDEBUG(x) if (debug) dbglog x
580 #define SYSDEBUG(x) if (debug) dbglog x
586 #define FSMDEBUG(x) if (debug) dbglog x
592 #define LCPDEBUG(x) if (debug) dbglog x
598 #define IPCPDEBUG(x) if (debug) dbglog x
604 #define IPV6CPDEBUG(x) if (debug) dbglog x
606 #define IPV6CPDEBUG(x)
610 #define UPAPDEBUG(x) if (debug) dbglog x
616 #define CHAPDEBUG(x) if (debug) dbglog x
622 #define IPXCPDEBUG(x) if (debug) dbglog x
624 #define IPXCPDEBUG(x)
628 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
632 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
636 #define MIN(a, b) ((a) < (b)? (a): (b))
639 #define MAX(a, b) ((a) > (b)? (a): (b))
642 #endif /* __PPP_H__ */