xref: /titanic_41/usr/src/cmd/cmd-inet/usr.bin/pppd/pppd.h (revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e)
1 /*
2  * pppd.h - PPP daemon global declarations.
3  *
4  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation is hereby granted, provided that the above copyright
9  * notice appears in all copies.
10  *
11  * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
12  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
13  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SUN SHALL NOT BE LIABLE FOR
15  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
16  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
17  *
18  * Copyright (c) 1989 Carnegie Mellon University.
19  * All rights reserved.
20  *
21  * Redistribution and use in source and binary forms are permitted
22  * provided that the above copyright notice and this paragraph are
23  * duplicated in all such forms and that any documentation,
24  * advertising materials, and other materials related to such
25  * distribution and use acknowledge that the software was developed
26  * by Carnegie Mellon University.  The name of the
27  * University may not be used to endorse or promote products derived
28  * from this software without specific prior written permission.
29  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
30  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
31  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * $Id: pppd.h,v 1.54 2000/04/15 10:10:25 paulus Exp $
34  */
35 
36 #pragma ident	"%Z%%M%	%I%	%E% SMI"
37 
38 #ifndef __PPPD_H__
39 #define __PPPD_H__
40 
41 #include <stdio.h>		/* for FILE */
42 #include <limits.h>		/* for NGROUPS_MAX */
43 #include <sys/param.h>		/* for MAXPATHLEN and BSD4_4, if defined */
44 #include <sys/types.h>		/* for u_int32_t, if defined */
45 #include <sys/time.h>		/* for struct timeval */
46 #include <net/ppp_defs.h>
47 
48 #if defined(__STDC__)
49 #include <stdarg.h>
50 #define __V(x)	x
51 #else
52 #include <varargs.h>
53 #define __V(x)	(va_alist) va_dcl
54 #define const
55 #define volatile
56 #endif /* __STDC__ */
57 
58 #ifdef INET6
59 #include "eui64.h"
60 #endif /* INET6 */
61 
62 #ifdef HAVE_MULTILINK
63 #include "tdb.h"
64 #endif
65 
66 #ifdef	__cplusplus
67 extern "C" {
68 #endif
69 
70 /*
71  * Limits.
72  */
73 #define NUM_PPP		1	/* One PPP interface supported (per process) */
74 #define MAXWORDLEN	1024	/* max length of word in file (incl null) */
75 #define MAXARGS		1	/* max # args to a command */
76 #define MAXNAMELEN	256	/* max length of name for auth */
77 #define MAXSECRETLEN	256	/* max length of password or secret */
78 
79 #ifndef MAXHOSTNAMELEN
80 #define	MAXHOSTNAMELEN	MAXNAMELEN  /* max length of hostname */
81 #endif /* MAXHOSTNAMELEN */
82 
83 /*
84  * If this evaluates non-zero, then sifup() must be called before
85  * sifaddr().
86  */
87 #define SIFUPFIRST \
88  (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
89 
90 /*
91  * If this evaluates non-zero, then sif6up() must be called before
92  * sif6addr().
93  */
94 #define SIF6UPFIRST \
95  (defined(__linux__) || (defined(SVR4) && (defined(SNI) || defined(__USLC__))))
96 
97 /*
98  * Option descriptor structure.
99  */
100 typedef unsigned char	bool;
101 
102 enum opt_type {
103 	o_special_noarg = 0,
104 	o_special = 1,
105 	o_bool,
106 	o_int,
107 	o_uint32,
108 	o_string
109 };
110 
111 typedef struct {
112 	char	*name;		/* name of the option */
113 	enum opt_type type;
114 	void	*addr;
115 	char	*description;
116 	int	flags;
117 	void	*addr2;
118 	int	upper_limit;
119 	int	lower_limit;
120 } option_t;
121 
122 /*
123  * Values for flags.
124  */
125 #define OPT_VALUE	0xff	/* mask for presupplied value */
126 #define OPT_HEX		0x100	/* int option is in hex */
127 #define OPT_NOARG	0x200	/* option doesn't take argument */
128 #define OPT_OR		0x400	/* OR in argument to value */
129 #define OPT_INC		0x800	/* increment value */
130 #define OPT_PRIV	0x1000	/* privileged option */
131 #define OPT_STATIC	0x2000	/* string option goes into static array */
132 #define OPT_LLIMIT	0x4000	/* check value against lower limit */
133 #define OPT_ULIMIT	0x8000	/* check value against upper limit */
134 #define OPT_LIMITS	(OPT_LLIMIT|OPT_ULIMIT)
135 #define OPT_ZEROOK	0x10000	/* 0 value is OK even if not within limits */
136 #define OPT_NOINCR	0x20000	/* value mustn't be increased */
137 #define OPT_ZEROINF	0x40000	/* with OPT_NOINCR, 0 == infinity */
138 #define	OPT_DISABLE	0x80000	/* ignore option */
139 #define OPT_A2INFO	0x100000 /* addr2 -> option_info to update */
140 #define OPT_A2COPY	0x200000 /* addr2 -> second location to rcv value */
141 #define OPT_ENABLE	0x400000 /* use *addr2 as enable for option */
142 #define OPT_PRIVFIX	0x800000 /* can't be overridden if noauth */
143 #define OPT_PREPASS	0x1000000 /* do this opt in pre-pass to find device */
144 #define OPT_INITONLY	0x2000000 /* option can only be set in init phase */
145 #define OPT_DEVEQUIV	0x4000000 /* equiv to device name */
146 #define OPT_DEVNAM	(OPT_PREPASS | OPT_INITONLY | OPT_DEVEQUIV)
147 
148 #define OPT_VAL(x)	((x) & OPT_VALUE)
149 
150 #ifndef GIDSET_TYPE
151 #define GIDSET_TYPE	gid_t
152 #endif /* GIDSET_TYPE */
153 
154 /*
155  * Structure representing a list of permitted IP addresses.
156  */
157 struct permitted_ip {
158     int		permit;		/* 1 = permit, 0 = forbid */
159     u_int32_t	base;		/* match if (addr & mask) == base */
160     u_int32_t	mask;		/* base and mask are in network byte order */
161 };
162 
163 /*
164  * Unfortunately, the linux kernel driver uses a different structure
165  * for statistics from the rest of the ports.
166  * This structure serves as a common representation for the bits
167  * pppd needs.
168  */
169 struct pppd_stats {
170     ppp_counter_t	bytes_in;
171     ppp_counter_t	bytes_out;
172     ppp_counter_t	pkts_in;
173     ppp_counter_t	pkts_out;
174 };
175 
176 /*
177  * Used for storing a sequence of words.  Usually malloced.
178  */
179 struct wordlist {
180     struct wordlist	*next;
181     char		*word;
182 };
183 
184 /*
185  * Global variables.
186  */
187 extern bool	hungup;		/* Physical layer has disconnected */
188 extern int	ifunit;		/* Interface unit number */
189 extern char	ifname[32];	/* Interface name */
190 extern int	ttyfd;		/* Serial device file descriptor */
191 extern char	hostname[];	/* Our hostname */
192 extern u_char	outpacket_buf[]; /* Buffer for outgoing packets */
193 extern int	phase;		/* Current state of link - see values below */
194 extern int	baud_rate;	/* Current link speed in bits/sec */
195 extern char	*progname;	/* Name of this program */
196 extern int	redirect_stderr;/* Connector's stderr should go to file */
197 extern char	peer_authname[];/* Authenticated name of peer */
198 extern bool	privileged;	/* We were run by real-uid root */
199 extern bool	need_holdoff;	/* Need holdoff period after link terminates */
200 extern char	**script_env;	/* Environment variables for scripts */
201 extern bool	detached;	/* Have detached from controlling tty */
202 extern GIDSET_TYPE groups[NGROUPS_MAX];	/* groups the user is in */
203 extern int	ngroups;	/* How many groups valid in groups */
204 extern struct pppd_stats link_stats; /* byte/packet counts etc. for link */
205 extern bool	link_stats_valid; /* set if link_stats is valid */
206 extern int	link_connect_time; /* time the link was up for */
207 extern int	using_pty;	/* using pty as device (notty or pty opt.) */
208 extern int	log_to_fd;	/* logging to this fd as well as syslog */
209 extern bool	log_to_file;	/* log_to_fd is a file */
210 extern bool	log_to_specific_fd;	/* log_to_fd was specified by user */
211 extern char	*no_ppp_msg;	/* message to print if ppp not in kernel */
212 extern volatile int status;	/* exit status for pppd */
213 extern int	devnam_fixed;	/* can no longer change devnam */
214 extern int	unsuccess;	/* # unsuccessful connection attempts */
215 extern int	do_callback;	/* set if we want to do callback next */
216 extern int	doing_callback;	/* set if this is a callback */
217 extern u_char	nak_buffer[];	/* where we construct a nak packet */
218 extern u_char	inpacket_buf[];	/* buffer for incoming packet */
219 extern bool	direct_tty;	/* use standard input directly; not a tty */
220 extern int	absmax_mru;	/* absolute maximum link (not i/f) MRU */
221 extern int	absmax_mtu;	/* absolute maximum link (not i/f) MTU */
222 extern int	pty_slave;	/* slave side of PTY, if any */
223 extern bool	early_log;	/* avoid logging to stdout */
224 
225 /*
226  * Values for do_callback and doing_callback.
227  */
228 #define CALLBACK_DIALIN		1	/* we are expecting the call back */
229 #define CALLBACK_DIALOUT	2	/* we are dialling out to call back */
230 
231 /*
232  * Variables set by command-line options.
233  */
234 extern int	debug;		/* Debug flag */
235 extern int	kdebugflag;	/* Tell kernel to print debug messages */
236 extern int	default_device;	/* Using /dev/tty or equivalent */
237 extern char	devnam[MAXPATHLEN];	/* Device name */
238 extern char	ppp_devnam[MAXPATHLEN];	/* Device name (might be pty) */
239 extern int	crtscts;	/* Use hardware flow control */
240 extern bool	modem;		/* Use modem control lines */
241 extern int	inspeed;	/* Input/Output speed requested */
242 extern u_int32_t netmask;	/* IP netmask to set on interface */
243 extern bool	lockflag;	/* Create lock file to lock the serial dev */
244 extern bool	nodetach;	/* Don't detach from controlling tty */
245 extern bool	updetach;	/* Detach from controlling tty when link up */
246 extern char	*initializer;	/* Script to initialize physical link */
247 extern char	*connect_script; /* Script to establish physical link */
248 extern char	*disconnect_script; /* Script to disestablish physical link */
249 extern char	*welcomer;	/* Script to welcome client after connection */
250 extern char	*ptycommand;	/* Command to run on other side of pty */
251 extern int	maxconnect;	/* Maximum connect time (seconds) */
252 extern char	user[MAXNAMELEN];/* Our name for authenticating ourselves */
253 extern char	passwd[MAXSECRETLEN];	/* Password for PAP or CHAP */
254 extern bool	auth_required;	/* Peer is required to authenticate */
255 extern bool	persist;	/* Reopen link after it goes down */
256 extern bool	uselogin;	/* Use /etc/passwd for checking PAP */
257 extern char	our_name[MAXNAMELEN];/* Our name for authentication purposes */
258 extern char	remote_name[MAXNAMELEN]; /* Peer's name for authentication */
259 extern bool	explicit_remote;/* remote_name specified with remotename opt */
260 extern bool	demand;		/* Do dial-on-demand */
261 extern char	*ipparam;	/* Extra parameter for ip up/down scripts */
262 extern bool	cryptpap;	/* Others' PAP passwords are encrypted */
263 extern int	idle_time_limit;/* Shut down link if idle for this long */
264 extern int	holdoff;	/* Dead time before restarting */
265 extern bool	holdoff_specified; /* true if user gave a holdoff value */
266 extern bool	notty;		/* Stdin/out is not a tty */
267 extern char	*pty_socket;	/* Socket to connect to pty */
268 extern char	*record_file;	/* File to record chars sent/received */
269 extern bool	sync_serial;	/* Device is synchronous serial device */
270 extern int	maxfail;	/* Max # of unsuccessful connection attempts */
271 extern char	linkname[MAXPATHLEN]; /* logical name for link */
272 extern bool	tune_kernel;	/* May alter kernel settings as necessary */
273 extern int	connect_delay;	/* Time to delay after connect script */
274 extern int	max_data_rate;	/* max bytes/sec through charshunt */
275 extern int	req_unit;	/* interface unit number to use */
276 extern bool	multilink;	/* enable multilink operation */
277 extern bool	noendpoint;	/* don't send or accept endpt. discrim. */
278 extern char	*bundle_name;	/* bundle name for multilink */
279 
280 #ifdef HAVE_MULTILINK
281 extern TDB_CONTEXT *pppdb;	/* handle to multilink database context */
282 extern char	db_key[];	/* multilink database key */
283 #endif
284 
285 #ifdef PPP_FILTER
286 extern struct	bpf_program pass_filter;   /* Filter for pkts to pass */
287 extern struct	bpf_program active_filter; /* Filter for link-active pkts */
288 #endif /* PPP_FILTER */
289 
290 #ifdef MSLANMAN
291 extern bool	ms_lanman;	/* Use LanMan password instead of NT */
292 				/* Has meaning only with MS-CHAP challenges */
293 #endif /* MXLANMAN */
294 
295 extern char *current_option;	/* the name of the option being parsed */
296 extern bool privileged_option;	/* set iff the current option came from root */
297 extern char *option_source;	/* string saying where the option came from */
298 extern int option_line;		/*   and from which line in the file */
299 extern bool already_ppp;	/* device is already in PPP mode */
300 extern bool prepass;		/* Doing pre-pass to find device name */
301 extern struct stat devstat;	/* Result of stat() on device */
302 
303 extern bool peer_nak_auth;	/* Peer sent nak for our auth request */
304 extern u_short nak_auth_orig;	/* Auth proto peer naked */
305 extern u_short nak_auth_proto;	/* Auth proto peer suggested instead */
306 extern bool unsolicited_nak_auth; /* Peer asked us to authenticate */
307 extern u_short unsolicit_auth_proto; /* Auth proto peer wants */
308 extern bool peer_reject_auth;	/* Peer sent reject for auth */
309 extern u_short reject_auth_proto; /* Protocol that peer rejected */
310 extern bool rejected_peers_auth; /* We sent a reject to the peer */
311 extern u_short rejected_auth_proto; /* Protocol that peer wanted to use */
312 extern bool naked_peers_auth;	/* We sent a nak to the peer */
313 extern u_short naked_auth_orig;	/* Protocol that we wanted to use */
314 extern u_short naked_auth_proto; /* Protocol that peer wants us to use */
315 
316 /*
317  * Values for phase.
318  */
319 #define PHASE_DEAD		0	/* RFC 1661; link terminated */
320 #define PHASE_INITIALIZE	1	/* execution begins */
321 #define PHASE_INITIALIZED	2	/* options ok; entering main loop */
322 #define PHASE_SERIALCONN	3	/* connecting to peer */
323 #define PHASE_CONNECTED		4	/* connecting to peer */
324 #define PHASE_DORMANT		5	/* waiting for demand-dial trigger */
325 #define PHASE_ESTABLISH		6	/* RFC 1661; LCP negotiation begins */
326 #define PHASE_AUTHENTICATE	7	/* RFC 1661; authentication begins */
327 #define PHASE_CALLBACK		8	/* negotiating for callback */
328 #define PHASE_NETWORK		9	/* RFC 1661; NCP negotiation begins */
329 #define PHASE_RUNNING		10	/* first NCP went to Opened state */
330 #define PHASE_TERMINATE		11	/* RFC 1661; LCP left Opened state */
331 #define PHASE_DISCONNECT	12	/* running disconnect script */
332 #define PHASE_HOLDOFF		13	/* waiting before restart */
333 #define PHASE_CALLINGBACK	14	/* calling back */
334 #define	PHASE_EXIT		15	/* execution ends */
335 
336 #define	PHASE__NAMES \
337 	"Dead", "Initialize", "Initialized", "Serialconn", "Connected", \
338 	"Dormant", "Establish", "Authenticate", "Callback", "Network", \
339 	"Running", "Terminate", "Disconnect", "Holdoff", "Callingback", \
340 	"Exit"
341 
342 /*
343  * The following struct gives the addresses of procedures to call
344  * for a particular protocol.
345  */
346 struct protent {
347     u_short protocol;		/* PPP protocol number */
348     /* Initialization procedure */
349     void (*init) __P((int unit));
350     /* Process a received packet */
351     void (*input) __P((int unit, u_char *pkt, int len));
352     /* Process a received protocol-reject */
353     void (*protrej) __P((int unit));
354     /* Lower layer has come up */
355     void (*lowerup) __P((int unit));
356     /* Lower layer has gone down */
357     void (*lowerdown) __P((int unit));
358     /* Open the protocol */
359     void (*open) __P((int unit));
360     /* Close the protocol */
361     void (*close) __P((int unit, char *reason));
362     /* Print a packet in readable form */
363     int  (*printpkt) __P((u_char *pkt, int len,
364 			  void (*printer) __P((void *, const char *, ...)),
365 			  void *arg));
366     /* Process a received data packet */
367     void (*datainput) __P((int unit, u_char *pkt, int len));
368     bool enabled_flag;		/* 0 iff protocol is disabled */
369     char *name;			/* Text name of protocol */
370     char *data_name;		/* Text name of corresponding data protocol */
371     option_t *options;		/* List of command-line options */
372     /* Check requested options, assign defaults */
373     void (*check_options) __P((void));
374     /* Configure interface for demand-dial */
375     int  (*demand_conf) __P((int unit));
376     /* Say whether to bring up link for this pkt */
377     int  (*active_pkt) __P((u_char *pkt, int len));
378     /* Print current status to file or syslog (if strptr == NULL) */
379     void (*print_stat) __P((int unit, FILE *strptr));
380 };
381 
382 /*
383  * This structure is used to store information about certain
384  * options, such as where the option value came from (/etc/ppp/options,
385  * command line, etc.) and whether it came from a privileged source.
386  */
387 struct option_info {
388     bool    priv;		/* was value set by sysadmin? */
389     char    *source;		/* where option came from */
390     int	    line;		/* line number where the option came from */
391 };
392 
393 extern struct option_info devnam_info;
394 extern struct option_info initializer_info;
395 extern struct option_info connect_script_info;
396 extern struct option_info disconnect_script_info;
397 extern struct option_info welcomer_info;
398 extern struct option_info ptycommand_info;
399 extern struct option_info ipsrc_info;
400 extern struct option_info ipdst_info;
401 extern struct option_info speed_info;
402 
403 /*
404  * Table of pointers to supported protocols.
405  */
406 extern struct protent *protocols[];
407 
408 /*
409  * Prototypes.
410  */
411 
412 /*
413  * Procedures exported from main.c.
414  */
415 extern void set_ifunit __P((int));  /* set stuff that depends on ifunit */
416 extern void detach __P((void));	    /* Detach from controlling tty */
417 extern void die __P((int));	    /* Cleanup and exit */
418 extern void quit __P((void));	    /* like die(1) */
419 extern void novm __P((char *));	    /* Say we ran out of memory, and die */
420 extern void timeout __P((void (*func)(void *), void *arg, int t));
421 				/* Call func(arg) after t seconds */
422 extern void untimeout __P((void (*func)(void *), void *arg));
423 				/* Cancel call to func(arg) */
424 extern pid_t run_program __P((char *prog, char **args, int must_exist,
425     void (*done)(void *, int), void *arg));
426 				/* Run program prog with args in child */
427 extern void reopen_log __P((void)); /* (re)open the connection to syslog */
428 extern void update_link_stats __P((int)); /* Get stats at link termination */
429 /* set script env var */
430 extern void script_setenv __P((const char *, const char *, int));
431 extern void script_unsetenv __P((const char *));  /* unset script env var */
432 extern const char *script_getenv __P((const char *var));
433 extern void new_phase __P((int));   /* signal start of new phase */
434 extern void print_ncpstate __P((int, FILE *));	/* prints NCP state */
435 extern const char *protocol_name __P((int proto));	/* canonical name */
436 extern const char *phase_name __P((int phaseval));
437 
438 /*
439  * Procedures exported from utils.c.
440  */
441 extern void log_packet __P((u_char *, int, const char *, int));
442 				/* Format a packet and log it with syslog */
443 extern void print_string __P((char *, int, void (*)(void *, const char *, ...),
444     void *));			/* Format a string for output */
445 extern int slprintf __P((char *, int, const char *, ...));  /* sprintf++ */
446 extern int vslprintf __P((char *, int, const char *, va_list));/* vsprintf++ */
447 extern size_t strlcpy __P((char *, const char *, size_t));  /* safe strcpy */
448 extern size_t strlcat __P((char *, const char *, size_t));  /* safe strncpy */
449 extern void dbglog __P((const char *, ...));/* log a debug message */
450 extern void info __P((const char *, ...));  /* log an informational message */
451 extern void notice __P((const char *, ...));/* log a notice-level message */
452 extern void warn __P((const char *, ...));  /* log a warning message */
453 extern void error __P((const char *, ...)); /* log an error message */
454 extern void fatal __P((const char *, ...));
455 				/* log an error message and die(1) */
456 extern const char *code_name __P((int code, int shortflag));
457 				/* Code to string */
458 extern int flprintf __P((FILE *, const char *, ...));  /* fprintf++ */
459 extern size_t strllen __P((const char *, size_t)); /* safe strlen */
460 extern const char *signal_name __P((int signum));
461 
462 /*
463  * Procedures exported from auth.c
464  */
465 extern void link_required __P((int));	/* we are starting to use the link */
466 extern void link_terminated __P((int));	/* we are finished with the link */
467 extern void link_down __P((int));
468 				/* the LCP layer has left the Opened state */
469 extern void link_established __P((int)); /* the link is up; authenticate now */
470 extern void start_networks __P((void));
471 				/* start all the network control protos */
472 extern void np_up __P((int, int));	/* a network protocol has come up */
473 extern void np_down __P((int, int));	/* a network protocol has gone down */
474 extern void np_finished __P((int, int));
475 				/* a network protocol no longer needs link */
476 extern void auth_peer_fail __P((int, int));
477 				/* peer failed to authenticate itself */
478 extern void auth_peer_success __P((int, int, char *, int));
479 				/* peer successfully authenticated itself */
480 extern void auth_withpeer_fail __P((int, int));
481 				/* we failed to authenticate ourselves */
482 extern void auth_withpeer_success __P((int, int));
483 				/* we successfully authenticated ourselves */
484 extern void auth_check_options __P((void));
485 				/* check authentication options supplied */
486 extern void auth_reset __P((int));
487 				/* check what secrets we have */
488 extern int  check_passwd __P((int, char *, int, char *, int, char **));
489 				/* Check peer-supplied username/password */
490 extern int  get_secret __P((int, char *, char *, char *, int *, int));
491 				/* get "secret" for chap */
492 extern int  auth_ip_addr __P((int, u_int32_t));
493 				/* check if IP address is authorized */
494 extern int  bad_ip_adrs __P((u_int32_t));
495 				/* check if IP address is unreasonable */
496 
497 /*
498  * Procedures exported from demand.c
499  */
500 extern void demand_conf __P((void));
501 				/* config interface(s) for demand-dial */
502 extern void demand_block __P((void));	/* set all NPs to queue up packets */
503 extern void demand_unblock __P((void)); /* set all NPs to pass packets */
504 extern void demand_discard __P((void)); /* set all NPs to discard packets */
505 extern void demand_rexmit __P((int));	/* retransmit saved frames for an NP */
506 extern int  loop_chars __P((unsigned char *, int));
507 				/* process chars from loopback */
508 extern int  loop_frame __P((unsigned char *, int));
509 				/* should we bring link up? */
510 
511 /*
512  * Procedures exported from multilink.c
513  */
514 extern void mp_check_options __P((void)); /* Check multilink-related options */
515 extern int  mp_join_bundle __P((void));
516 				/* join our link to an appropriate bundle */
517 /*
518  * Procedures exported from sys-*.c
519  */
520 extern void sys_init __P((bool));   /* Do system-dependent initialization */
521 extern void sys_cleanup __P((void)); /* Restore system state before exiting */
522 extern int  sys_check_options __P((void)); /* Check options specified */
523 extern void sys_options __P((void));	/* add or remove system options */
524 extern void sys_close __P((void));  /* Clean up in a child before execing */
525 extern int  ppp_available __P((void));
526 				/* Test whether ppp kernel support exists */
527 extern int  get_pty __P((int *, int *, char *, int));
528 				/* Get pty master/slave */
529 extern int  open_ppp_loopback __P((void));
530 				/* Open loopback for demand-dialling */
531 extern int  establish_ppp __P((int));
532 				/* Turn serial port into a ppp interface */
533 extern void restore_loop __P((void));
534 				/* Transfer ppp unit back to loopback */
535 extern void disestablish_ppp __P((int));
536 				/* Restore port to normal operation */
537 extern void make_new_bundle __P((int, int, int, int)); /* Create new bundle */
538 extern int  bundle_attach __P((int)); /* Attach link to existing bundle */
539 extern void cfg_bundle __P((int, int, int, int));
540 				/* Configure existing bundle */
541 extern void clean_check __P((void));	/* Check if line was 8-bit clean */
542 extern void set_up_tty __P((int, int));
543 				/* Set up port's speed, parameters, etc. */
544 extern void restore_tty __P((int)); /* Restore port's original parameters */
545 extern void setdtr __P((int, int)); /* Raise or lower port's DTR line */
546 extern void output __P((int, u_char *, int)); /* Output a PPP packet */
547 extern void wait_input __P((struct timeval *));
548 				/* Wait for input, with timeout */
549 extern void add_fd __P((int));	/* Add fd to set to wait for */
550 extern void remove_fd __P((int));   /* Remove fd from set to wait for */
551 extern int  read_packet __P((u_char *)); /* Read PPP packet */
552 extern int  get_loop_output __P((void)); /* Read pkts from loopback */
553 extern void ppp_send_config __P((int, int, u_int32_t, int, int));
554 				/* Configure i/f transmit parameters */
555 extern void ppp_set_xaccm __P((int, ext_accm));
556 				/* Set extended transmit ACCM */
557 extern void ppp_recv_config __P((int, int, u_int32_t, int, int));
558 				/* Configure i/f receive parameters */
559 #ifdef NEGOTIATE_FCS
560 extern void ppp_send_fcs __P((int unit, int fcstype));
561 extern void ppp_recv_fcs __P((int unit, int fcstype));
562 #endif /* NEGOTIATE_FCS */
563 #ifdef MUX_FRAME
564 extern void ppp_send_muxoption __P((int ,u_int32_t));
565 extern void ppp_recv_muxoption __P((int ,u_int32_t));
566 #endif /* MUX_FRAME */
567 extern int  ccp_test __P((int, u_char *, int, int));
568 				/* Test support for compression scheme */
569 #ifdef COMP_TUNE
570 extern void ccp_tune __P((int, int));	/* Tune compression effort level */
571 #endif /* COMP_TUNE */
572 extern void ccp_flags_set __P((int, int, int));
573 				/* Set kernel CCP state */
574 extern int ccp_fatal_error __P((int));
575 				/* Test for fatal decomp error in kernel */
576 extern int get_idle_time __P((int, struct ppp_idle *));
577 				/* Find out how long link has been idle */
578 extern int get_ppp_stats __P((int, struct pppd_stats *));
579 				/* Return link statistics */
580 extern int sifvjcomp __P((int, int, int, int));
581 				/* Configure VJ TCP header compression */
582 extern int sifup __P((int));	/* Configure i/f up for one protocol */
583 extern int sifnpmode __P((int u, int proto, enum NPmode mode));
584 				/* Set mode for handling packets for proto */
585 extern int sifdown __P((int));	/* Configure i/f down for one protocol */
586 extern int sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t));
587 				/* Configure IPv4 addresses for i/f */
588 extern int cifaddr __P((int, u_int32_t, u_int32_t));
589 				/* Reset i/f IP addresses */
590 
591 extern void sys_block_proto __P((uint16_t));
592 extern void sys_unblock_proto __P((uint16_t));
593 
594 #ifdef INET6
595 extern int sif6addr __P((int, eui64_t, eui64_t));
596 				/* Configure IPv6 addresses for i/f */
597 extern int cif6addr __P((int, eui64_t, eui64_t));
598 				/* Remove an IPv6 address from i/f */
599 #endif /* INET6 */
600 extern int sifdefaultroute __P((int, u_int32_t, u_int32_t));
601 				/* Create default route through i/f */
602 extern int cifdefaultroute __P((int, u_int32_t, u_int32_t));
603 				/* Delete default route through i/f */
604 extern int sifproxyarp __P((int unit, u_int32_t addr, int flag));
605 				/* Add proxy ARP entry for peer */
606 extern int cifproxyarp __P((int unit, u_int32_t addr));
607 				/* Delete proxy ARP entry for peer */
608 extern u_int32_t GetMask __P((u_int32_t));
609 				/* Get appropriate netmask for address */
610 extern int lock __P((char *));	/* Create lock file for device */
611 extern int relock __P((int));	/* Rewrite lock file with new pid */
612 extern void unlock __P((void));	/* Delete previously-created lock file */
613 extern void logwtmp __P((const char *, const char *, const char *));
614 				/* Write entry to wtmp file */
615 extern int get_host_seed __P((void));
616 				/* Get host-dependent random number seed */
617 extern int have_route_to __P((u_int32_t)); /* Check if route to addr exists */
618 #ifdef PPP_FILTER
619 extern int set_filters __P((struct bpf_program *pass,
620     struct bpf_program *active));
621 				/* Set filter programs in kernel */
622 #endif /* PPP_FILTER */
623 #ifdef IPX_CHANGE
624 extern int sipxfaddr __P((int, unsigned long, unsigned char *));
625 extern int cipxfaddr __P((int));
626 #endif /* IPX_CHANGE */
627 extern int get_if_hwaddr __P((u_char *addr, int msize, char *name));
628 extern int get_first_hwaddr __P((u_char *addr, int msize));
629 #if defined(INET6) && defined(SOL2)
630 extern int ether_to_eui64 __P((eui64_t *p_eui64));
631 extern int sif6up __P((int unit));
632 extern int sif6down __P((int unit));
633 extern int sif6mtu __P((int mtu));
634 extern int sif6flags __P((u_int32_t flags, int set));
635 #endif /* INET6 && SOL2*/
636 #if defined(INET6) && !defined(SOL2)
637 #define sif6up sifup
638 #endif
639 extern int sifmtu __P((int mtu));
640 extern int siflags __P((u_int32_t flags, int set));
641 extern void sys_ifname __P((void));
642 extern void sys_print_state __P((FILE *strptr));
643 extern int sys_extra_fd __P((void));
644 
645 /*
646  * Procedures exported from options.c
647  */
648 extern int parse_args __P((int argc, char **argv));
649 	/* Parse options from arguments given */
650 extern int options_from_file __P((char *filename, bool must_exist,
651     bool check_prot, bool privileged));
652 	/* Parse options from an options file */
653 extern int options_from_user __P((void));
654 	/* Parse options from user's .ppprc */
655 extern int options_for_tty __P((void));
656 	/* Parse options from /etc/ppp/options.tty */
657 extern int options_from_list __P((struct wordlist *, bool privileged));
658 	/* Parse options from a wordlist */
659 extern int getword __P((FILE *f, char *word, int *newlinep, char *filename));
660 	/* Read a word from a file */
661 extern void option_error __P((char *fmt, ...));
662 	/* Print an error message about an option */
663 extern int int_option __P((char *, int *));
664 	/* Simplified number_option for decimal ints */
665 extern void add_options __P((option_t *));
666 	/* Add extra options */
667 extern int parse_dotted_ip __P((char *, u_int32_t *));
668 	/* Parse dotted IP notation */
669 extern option_t *remove_option __P((char *));
670 	/* Remove (disable) an option */
671 extern void save_source __P((struct option_info *));
672 	/* Save the source information (where an option comes from) */
673 extern void set_source __P((struct option_info *));
674 	/* Set the source (for logging option errors detected after parsing) */
675 extern const char *name_source __P((struct option_info *));
676 	/* Return a string containing the option source and line number */
677 
678 /*
679  * Hooks to enable plugins to change various things.
680  */
681 extern int (*new_phase_hook) __P((int new, int old));
682 extern int (*idle_time_hook) __P((struct ppp_idle *));
683 extern int (*holdoff_hook) __P((void));
684 extern int (*pap_check_hook) __P((void));
685 extern int (*pap_auth_hook) __P((char *user, char *passwd, char **msgp,
686     struct wordlist **paddrs, struct wordlist **popts));
687 extern void (*pap_logout_hook) __P((void));
688 extern int (*pap_passwd_hook) __P((char *user, char *passwd));
689 extern void (*ip_up_hook) __P((void));
690 extern void (*ip_down_hook) __P((void));
691 extern int (*check_options_hook) __P((uid_t uid));
692 /* extern int (*attach_device_hook) __P((uid_t uid, char *devnam)); */
693 extern int (*updown_script_hook) __P((const char ***argsp));
694 struct strbuf;	/* forward declaration */
695 extern int (*sys_read_packet_hook) __P((int retv, struct strbuf *ctrl,
696     struct strbuf *data, int flags));
697 extern void (*device_pipe_hook) __P((int pipefd));
698 
699 /*
700  * Inline versions of get/put char/short/long.
701  * Pointer is advanced; we assume that both arguments
702  * are lvalues and will already be in registers.
703  * cp MUST be u_char *.
704  */
705 #define GETCHAR(c, cp) { \
706 	(c) = *(cp)++; \
707 }
708 #define PUTCHAR(c, cp) { \
709 	*(cp)++ = (u_char) (c); \
710 }
711 
712 
713 #define GETSHORT(s, cp) { \
714 	(s) = *(cp)++ << 8; \
715 	(s) |= *(cp)++; \
716 }
717 #define PUTSHORT(s, cp) { \
718 	*(cp)++ = (u_char) ((s) >> 8); \
719 	*(cp)++ = (u_char) (s); \
720 }
721 
722 #define GETLONG(l, cp) { \
723 	(l) = *(cp)++ << 8; \
724 	(l) |= *(cp)++; (l) <<= 8; \
725 	(l) |= *(cp)++; (l) <<= 8; \
726 	(l) |= *(cp)++; \
727 }
728 #define PUTLONG(l, cp) { \
729 	*(cp)++ = (u_char) ((l) >> 24); \
730 	*(cp)++ = (u_char) ((l) >> 16); \
731 	*(cp)++ = (u_char) ((l) >> 8); \
732 	*(cp)++ = (u_char) (l); \
733 }
734 
735 /*
736  * For values that are kept internally in network byte order.
737  */
738 #define GETNLONG(l, cp) { \
739 	u_int32_t getnlong_val; \
740 	getnlong_val = *(cp)++ << 8; \
741 	getnlong_val |= *(cp)++; getnlong_val <<= 8; \
742 	getnlong_val |= *(cp)++; getnlong_val <<= 8; \
743 	getnlong_val |= *(cp)++; \
744 	(l) = htonl(getnlong_val); \
745 }
746 #define PUTNLONG(l, cp) { \
747 	u_int32_t putnlong_val = ntohl(l); \
748 	*(cp)++ = (u_char) (putnlong_val >> 24); \
749 	*(cp)++ = (u_char) (putnlong_val >> 16); \
750 	*(cp)++ = (u_char) (putnlong_val >> 8); \
751 	*(cp)++ = (u_char) putnlong_val; \
752 }
753 
754 #define INCPTR(n, cp)	((cp) += (n))
755 #define DECPTR(n, cp)	((cp) -= (n))
756 
757 /*
758  * System dependent definitions for user-level 4.3BSD UNIX implementation.
759  */
760 
761 #define TIMEOUT(r, f, t)	timeout((r), (f), (t))
762 #define UNTIMEOUT(r, f)		untimeout((r), (f))
763 
764 #ifndef SOL2
765 #define BCOPY(s, d, l)		memcpy(d, s, l)
766 #define BZERO(s, n)		memset(s, 0, n)
767 #else
768 #include <strings.h>
769 #define BCOPY			bcopy
770 #define BZERO			bzero
771 #endif
772 
773 #define PRINTMSG(m, l)		{ info("Remote message: %0.*v", l, m); }
774 
775 /*
776  * MAKEHEADER - Add Header fields to a packet.
777  */
778 #define MAKEHEADER(p, t) { \
779     PUTCHAR(PPP_ALLSTATIONS, p); \
780     PUTCHAR(PPP_UI, p); \
781     PUTSHORT(t, p); }
782 
783 /*
784  * Exit status values.
785  */
786 #define EXIT_OK			0
787 #define EXIT_FATAL_ERROR	1
788 #define EXIT_OPTION_ERROR	2
789 #define EXIT_NOT_ROOT		3
790 #define EXIT_NO_KERNEL_SUPPORT	4
791 #define EXIT_USER_REQUEST	5
792 #define EXIT_LOCK_FAILED	6
793 #define EXIT_OPEN_FAILED	7
794 #define EXIT_CONNECT_FAILED	8
795 #define EXIT_PTYCMD_FAILED	9
796 #define EXIT_NEGOTIATION_FAILED	10
797 #define EXIT_PEER_AUTH_FAILED	11
798 #define EXIT_IDLE_TIMEOUT	12
799 #define EXIT_CONNECT_TIME	13
800 #define EXIT_CALLBACK		14
801 #define EXIT_PEER_DEAD		15
802 #define EXIT_HANGUP		16
803 #define EXIT_LOOPBACK		17
804 #define EXIT_INIT_FAILED	18
805 #define EXIT_AUTH_TOPEER_FAILED	19
806 
807 /*
808  * Character shunt constants.
809  */
810 #define	MAXLEVELMINSIZE		100
811 
812 /*
813  * Debug macros.  Slightly useful for finding bugs in pppd, not particularly
814  * useful for finding out why your connection isn't being established.
815  */
816 #ifdef DEBUGALL
817 #define DEBUGMAIN	1
818 #define DEBUGSYS	1
819 #define DEBUGLCP	1
820 #define DEBUGIPCP	1
821 #define DEBUGIPV6CP	1
822 #define DEBUGCHAP	1
823 #define DEBUGIPXCP	1
824 #define LOG_PPP		LOG_LOCAL2	/* Log here when debugging all */
825 #endif /* DEBUGALL */
826 
827 #ifndef LOG_PPP			/* we use LOG_DAEMON for syslog by default */
828 #define LOG_PPP LOG_DAEMON
829 #endif /* LOG_PPP */
830 
831 #ifdef DEBUGMAIN
832 #define MAINDEBUG(x)	if (debug) dbglog x
833 #else
834 #define MAINDEBUG(x)	((void) 0)
835 #endif /* DEBUGMAIN */
836 
837 #ifdef DEBUGSYS
838 #define SYSDEBUG(x)	if (debug) dbglog x
839 #else
840 #define SYSDEBUG(x)	((void) 0)
841 #endif /* DEBUGSYS */
842 
843 #ifdef DEBUGLCP
844 #define LCPDEBUG(x)	if (debug) dbglog x
845 #else
846 #define LCPDEBUG(x)	((void) 0)
847 #endif /* DEBUGLCP */
848 
849 #ifdef DEBUGIPCP
850 #define IPCPDEBUG(x)	if (debug) dbglog x
851 #else
852 #define IPCPDEBUG(x)	((void) 0)
853 #endif /* DEBUGIPCP */
854 
855 #ifdef DEBUGIPV6CP
856 #define IPV6CPDEBUG(x)  if (debug) dbglog x
857 #else
858 #define IPV6CPDEBUG(x)	((void) 0)
859 #endif /* DEBUGIPV6CP */
860 
861 #ifdef DEBUGCHAP
862 #define CHAPDEBUG(x)	if (debug) dbglog x
863 #else
864 #define CHAPDEBUG(x)	((void) 0)
865 #endif /* DEBUGCHAP */
866 
867 #ifdef DEBUGIPXCP
868 #define IPXCPDEBUG(x)	if (debug) dbglog x
869 #else
870 #define IPXCPDEBUG(x)	((void) 0)
871 #endif /* DEBUGIPXCP */
872 
873 #ifndef SIGTYPE
874 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
875 #define SIGTYPE void
876 #else
877 #define SIGTYPE int
878 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
879 #endif /* SIGTYPE */
880 
881 #ifndef MIN
882 #define MIN(a, b)	((a) < (b)? (a): (b))
883 #endif /* MIN */
884 
885 #ifndef MAX
886 #define MAX(a, b)	((a) > (b)? (a): (b))
887 #endif /* MAX */
888 
889 #ifndef Dim
890 #define Dim(x)		(sizeof (x) / sizeof (*(x)))
891 #endif /* Dim */
892 
893 #ifndef NBBY
894 #define NBBY 8
895 #endif /* NBBY */
896 
897 #ifndef isset
898 #define isset(arr, val)	(((u_char *)(arr))[(val)/NBBY] & (1<<((val)%NBBY)))
899 #endif /* isset */
900 
901 #ifndef setbit
902 #define setbit(arr, val) (((u_char *)(arr))[(val)/NBBY] |= (1<<((val)%NBBY)))
903 #endif /* setbit */
904 
905 #define IP_HDRLEN	20	/* bytes */
906 #define IP_OFFMASK	0x1fff
907 #define TCP_HDRLEN	20
908 
909 /*
910  * We use these macros because the IP header may be at an odd address,
911  * and some compilers might use word loads to get th_off or ip_hl.
912  */
913 
914 #define net_short(x)	(((x)[0] << 8) + (x)[1])
915 #define	net_long(x)	((net_short(x) << 16) + \
916 			net_short((unsigned char *)(x) + 2))
917 #define get_ipv(x)	((((unsigned char *)(x))[0] >> 4) & 0xF)
918 #define get_iphl(x)	(((unsigned char *)(x))[0] & 0xF)
919 #define	get_iplen(x)	net_short((unsigned char *)(x) + 2)
920 #define get_ipoff(x)	net_short((unsigned char *)(x) + 6)
921 #define get_ipproto(x)	(((unsigned char *)(x))[9])
922 #define	get_ipsrc(x)	net_long((unsigned char *)(x) + 12)
923 #define	get_ipdst(x)	net_long((unsigned char *)(x) + 16)
924 /* Ports for both UDP and TCP are first */
925 #define	get_sport(x)	net_short(x)
926 #define	get_dport(x)	net_short((unsigned char *)(x) + 2)
927 #define get_tcpoff(x)	(((unsigned char *)(x))[12] >> 4)
928 #define get_tcpflags(x)	(((unsigned char *)(x))[13])
929 
930 /* Check for RFC 1918 (local use) addresses */
931 #define LOCAL_IP_ADDR(addr)						  \
932 	(((addr) & 0xff000000) == 0x0a000000 ||		/* 10.x.x.x */	  \
933 	 ((addr) & 0xfff00000) == 0xac100000 ||		/* 172.16.x.x */  \
934 	 ((addr) & 0xffff0000) == 0xc0a80000)		/* 192.168.x.x */
935 
936 #ifdef	__cplusplus
937 }
938 #endif
939 
940 #endif /* __PPPD_H__ */
941