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