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