17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * pppd.h - PPP daemon global declarations.
37c478bd9Sstevel@tonic-gate  *
4f53eecf5SJames Carlson  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
57c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software and its
87c478bd9Sstevel@tonic-gate  * documentation is hereby granted, provided that the above copyright
97c478bd9Sstevel@tonic-gate  * notice appears in all copies.
107c478bd9Sstevel@tonic-gate  *
117c478bd9Sstevel@tonic-gate  * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
127c478bd9Sstevel@tonic-gate  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
137c478bd9Sstevel@tonic-gate  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
147c478bd9Sstevel@tonic-gate  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SUN SHALL NOT BE LIABLE FOR
157c478bd9Sstevel@tonic-gate  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
167c478bd9Sstevel@tonic-gate  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
177c478bd9Sstevel@tonic-gate  *
187c478bd9Sstevel@tonic-gate  * Copyright (c) 1989 Carnegie Mellon University.
197c478bd9Sstevel@tonic-gate  * All rights reserved.
207c478bd9Sstevel@tonic-gate  *
217c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
227c478bd9Sstevel@tonic-gate  * provided that the above copyright notice and this paragraph are
237c478bd9Sstevel@tonic-gate  * duplicated in all such forms and that any documentation,
247c478bd9Sstevel@tonic-gate  * advertising materials, and other materials related to such
257c478bd9Sstevel@tonic-gate  * distribution and use acknowledge that the software was developed
267c478bd9Sstevel@tonic-gate  * by Carnegie Mellon University.  The name of the
277c478bd9Sstevel@tonic-gate  * University may not be used to endorse or promote products derived
287c478bd9Sstevel@tonic-gate  * from this software without specific prior written permission.
297c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
307c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
317c478bd9Sstevel@tonic-gate  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * $Id: pppd.h,v 1.54 2000/04/15 10:10:25 paulus Exp $
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifndef __PPPD_H__
377c478bd9Sstevel@tonic-gate #define __PPPD_H__
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <stdio.h>		/* for FILE */
407c478bd9Sstevel@tonic-gate #include <limits.h>		/* for NGROUPS_MAX */
417c478bd9Sstevel@tonic-gate #include <sys/param.h>		/* for MAXPATHLEN and BSD4_4, if defined */
427c478bd9Sstevel@tonic-gate #include <sys/types.h>		/* for u_int32_t, if defined */
437c478bd9Sstevel@tonic-gate #include <sys/time.h>		/* for struct timeval */
447c478bd9Sstevel@tonic-gate #include <net/ppp_defs.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #if defined(__STDC__)
477c478bd9Sstevel@tonic-gate #include <stdarg.h>
487c478bd9Sstevel@tonic-gate #define __V(x)	x
497c478bd9Sstevel@tonic-gate #else
507c478bd9Sstevel@tonic-gate #include <varargs.h>
517c478bd9Sstevel@tonic-gate #define __V(x)	(va_alist) va_dcl
527c478bd9Sstevel@tonic-gate #define const
537c478bd9Sstevel@tonic-gate #define volatile
547c478bd9Sstevel@tonic-gate #endif /* __STDC__ */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #ifdef INET6
577c478bd9Sstevel@tonic-gate #include "eui64.h"
587c478bd9Sstevel@tonic-gate #endif /* INET6 */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #ifdef HAVE_MULTILINK
617c478bd9Sstevel@tonic-gate #include "tdb.h"
627c478bd9Sstevel@tonic-gate #endif
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
657c478bd9Sstevel@tonic-gate extern "C" {
667c478bd9Sstevel@tonic-gate #endif
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * Limits.
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate #define NUM_PPP		1	/* One PPP interface supported (per process) */
727c478bd9Sstevel@tonic-gate #define MAXWORDLEN	1024	/* max length of word in file (incl null) */
737c478bd9Sstevel@tonic-gate #define MAXARGS		1	/* max # args to a command */
747c478bd9Sstevel@tonic-gate #define MAXNAMELEN	256	/* max length of name for auth */
757c478bd9Sstevel@tonic-gate #define MAXSECRETLEN	256	/* max length of password or secret */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #ifndef MAXHOSTNAMELEN
787c478bd9Sstevel@tonic-gate #define	MAXHOSTNAMELEN	MAXNAMELEN  /* max length of hostname */
797c478bd9Sstevel@tonic-gate #endif /* MAXHOSTNAMELEN */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * If this evaluates non-zero, then sifup() must be called before
837c478bd9Sstevel@tonic-gate  * sifaddr().
847c478bd9Sstevel@tonic-gate  */
85*f6b0cb17SToomas Soome #if (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
86*f6b0cb17SToomas Soome #define SIFUPFIRST (1)
87*f6b0cb17SToomas Soome #else
88*f6b0cb17SToomas Soome #define SIFUPFIRST (0)
89*f6b0cb17SToomas Soome #endif
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * If this evaluates non-zero, then sif6up() must be called before
937c478bd9Sstevel@tonic-gate  * sif6addr().
947c478bd9Sstevel@tonic-gate  */
95*f6b0cb17SToomas Soome #if (defined(__linux__) || \
96*f6b0cb17SToomas Soome 	(defined(SVR4) && (defined(SNI) || defined(__USLC__))))
97*f6b0cb17SToomas Soome #define SIF6UPFIRST (1)
98*f6b0cb17SToomas Soome #else
99*f6b0cb17SToomas Soome #define SIF6UPFIRST (0)
100*f6b0cb17SToomas Soome #endif
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * Option descriptor structure.
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate typedef unsigned char	bool;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate enum opt_type {
1087c478bd9Sstevel@tonic-gate 	o_special_noarg = 0,
1097c478bd9Sstevel@tonic-gate 	o_special = 1,
1107c478bd9Sstevel@tonic-gate 	o_bool,
1117c478bd9Sstevel@tonic-gate 	o_int,
1127c478bd9Sstevel@tonic-gate 	o_uint32,
1137c478bd9Sstevel@tonic-gate 	o_string
1147c478bd9Sstevel@tonic-gate };
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate typedef struct {
1177c478bd9Sstevel@tonic-gate 	char	*name;		/* name of the option */
1187c478bd9Sstevel@tonic-gate 	enum opt_type type;
1197c478bd9Sstevel@tonic-gate 	void	*addr;
1207c478bd9Sstevel@tonic-gate 	char	*description;
1217c478bd9Sstevel@tonic-gate 	int	flags;
1227c478bd9Sstevel@tonic-gate 	void	*addr2;
1237c478bd9Sstevel@tonic-gate 	int	upper_limit;
1247c478bd9Sstevel@tonic-gate 	int	lower_limit;
1257c478bd9Sstevel@tonic-gate } option_t;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * Values for flags.
1297c478bd9Sstevel@tonic-gate  */
1307c478bd9Sstevel@tonic-gate #define OPT_VALUE	0xff	/* mask for presupplied value */
1317c478bd9Sstevel@tonic-gate #define OPT_HEX		0x100	/* int option is in hex */
1327c478bd9Sstevel@tonic-gate #define OPT_NOARG	0x200	/* option doesn't take argument */
1337c478bd9Sstevel@tonic-gate #define OPT_OR		0x400	/* OR in argument to value */
1347c478bd9Sstevel@tonic-gate #define OPT_INC		0x800	/* increment value */
1357c478bd9Sstevel@tonic-gate #define OPT_PRIV	0x1000	/* privileged option */
1367c478bd9Sstevel@tonic-gate #define OPT_STATIC	0x2000	/* string option goes into static array */
1377c478bd9Sstevel@tonic-gate #define OPT_LLIMIT	0x4000	/* check value against lower limit */
1387c478bd9Sstevel@tonic-gate #define OPT_ULIMIT	0x8000	/* check value against upper limit */
1397c478bd9Sstevel@tonic-gate #define OPT_LIMITS	(OPT_LLIMIT|OPT_ULIMIT)
1407c478bd9Sstevel@tonic-gate #define OPT_ZEROOK	0x10000	/* 0 value is OK even if not within limits */
1417c478bd9Sstevel@tonic-gate #define OPT_NOINCR	0x20000	/* value mustn't be increased */
1427c478bd9Sstevel@tonic-gate #define OPT_ZEROINF	0x40000	/* with OPT_NOINCR, 0 == infinity */
1437c478bd9Sstevel@tonic-gate #define	OPT_DISABLE	0x80000	/* ignore option */
1447c478bd9Sstevel@tonic-gate #define OPT_A2INFO	0x100000 /* addr2 -> option_info to update */
1457c478bd9Sstevel@tonic-gate #define OPT_A2COPY	0x200000 /* addr2 -> second location to rcv value */
1467c478bd9Sstevel@tonic-gate #define OPT_ENABLE	0x400000 /* use *addr2 as enable for option */
1477c478bd9Sstevel@tonic-gate #define OPT_PRIVFIX	0x800000 /* can't be overridden if noauth */
1487c478bd9Sstevel@tonic-gate #define OPT_PREPASS	0x1000000 /* do this opt in pre-pass to find device */
1497c478bd9Sstevel@tonic-gate #define OPT_INITONLY	0x2000000 /* option can only be set in init phase */
1507c478bd9Sstevel@tonic-gate #define OPT_DEVEQUIV	0x4000000 /* equiv to device name */
1517c478bd9Sstevel@tonic-gate #define OPT_DEVNAM	(OPT_PREPASS | OPT_INITONLY | OPT_DEVEQUIV)
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #define OPT_VAL(x)	((x) & OPT_VALUE)
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate #ifndef GIDSET_TYPE
1567c478bd9Sstevel@tonic-gate #define GIDSET_TYPE	gid_t
1577c478bd9Sstevel@tonic-gate #endif /* GIDSET_TYPE */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /*
1607c478bd9Sstevel@tonic-gate  * Structure representing a list of permitted IP addresses.
1617c478bd9Sstevel@tonic-gate  */
1627c478bd9Sstevel@tonic-gate struct permitted_ip {
1637c478bd9Sstevel@tonic-gate     int		permit;		/* 1 = permit, 0 = forbid */
1647c478bd9Sstevel@tonic-gate     u_int32_t	base;		/* match if (addr & mask) == base */
1657c478bd9Sstevel@tonic-gate     u_int32_t	mask;		/* base and mask are in network byte order */
1667c478bd9Sstevel@tonic-gate };
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * Unfortunately, the linux kernel driver uses a different structure
1707c478bd9Sstevel@tonic-gate  * for statistics from the rest of the ports.
1717c478bd9Sstevel@tonic-gate  * This structure serves as a common representation for the bits
1727c478bd9Sstevel@tonic-gate  * pppd needs.
1737c478bd9Sstevel@tonic-gate  */
1747c478bd9Sstevel@tonic-gate struct pppd_stats {
1757c478bd9Sstevel@tonic-gate     ppp_counter_t	bytes_in;
1767c478bd9Sstevel@tonic-gate     ppp_counter_t	bytes_out;
1777c478bd9Sstevel@tonic-gate     ppp_counter_t	pkts_in;
1787c478bd9Sstevel@tonic-gate     ppp_counter_t	pkts_out;
1797c478bd9Sstevel@tonic-gate };
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate /*
1827c478bd9Sstevel@tonic-gate  * Used for storing a sequence of words.  Usually malloced.
1837c478bd9Sstevel@tonic-gate  */
1847c478bd9Sstevel@tonic-gate struct wordlist {
1857c478bd9Sstevel@tonic-gate     struct wordlist	*next;
1867c478bd9Sstevel@tonic-gate     char		*word;
1877c478bd9Sstevel@tonic-gate };
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate /*
1907c478bd9Sstevel@tonic-gate  * Global variables.
1917c478bd9Sstevel@tonic-gate  */
1927c478bd9Sstevel@tonic-gate extern bool	hungup;		/* Physical layer has disconnected */
1937c478bd9Sstevel@tonic-gate extern int	ifunit;		/* Interface unit number */
1947c478bd9Sstevel@tonic-gate extern char	ifname[32];	/* Interface name */
1957c478bd9Sstevel@tonic-gate extern int	ttyfd;		/* Serial device file descriptor */
1967c478bd9Sstevel@tonic-gate extern char	hostname[];	/* Our hostname */
1977c478bd9Sstevel@tonic-gate extern u_char	outpacket_buf[]; /* Buffer for outgoing packets */
1987c478bd9Sstevel@tonic-gate extern int	phase;		/* Current state of link - see values below */
1997c478bd9Sstevel@tonic-gate extern int	baud_rate;	/* Current link speed in bits/sec */
2007c478bd9Sstevel@tonic-gate extern char	*progname;	/* Name of this program */
2017c478bd9Sstevel@tonic-gate extern int	redirect_stderr;/* Connector's stderr should go to file */
2027c478bd9Sstevel@tonic-gate extern char	peer_authname[];/* Authenticated name of peer */
2037c478bd9Sstevel@tonic-gate extern bool	privileged;	/* We were run by real-uid root */
2047c478bd9Sstevel@tonic-gate extern bool	need_holdoff;	/* Need holdoff period after link terminates */
2057c478bd9Sstevel@tonic-gate extern char	**script_env;	/* Environment variables for scripts */
2067c478bd9Sstevel@tonic-gate extern bool	detached;	/* Have detached from controlling tty */
2077c478bd9Sstevel@tonic-gate extern GIDSET_TYPE groups[NGROUPS_MAX];	/* groups the user is in */
2087c478bd9Sstevel@tonic-gate extern int	ngroups;	/* How many groups valid in groups */
2097c478bd9Sstevel@tonic-gate extern struct pppd_stats link_stats; /* byte/packet counts etc. for link */
2107c478bd9Sstevel@tonic-gate extern bool	link_stats_valid; /* set if link_stats is valid */
2117c478bd9Sstevel@tonic-gate extern int	link_connect_time; /* time the link was up for */
2127c478bd9Sstevel@tonic-gate extern int	using_pty;	/* using pty as device (notty or pty opt.) */
2137c478bd9Sstevel@tonic-gate extern int	log_to_fd;	/* logging to this fd as well as syslog */
2147c478bd9Sstevel@tonic-gate extern bool	log_to_file;	/* log_to_fd is a file */
2157c478bd9Sstevel@tonic-gate extern bool	log_to_specific_fd;	/* log_to_fd was specified by user */
2167c478bd9Sstevel@tonic-gate extern char	*no_ppp_msg;	/* message to print if ppp not in kernel */
2177c478bd9Sstevel@tonic-gate extern volatile int status;	/* exit status for pppd */
2187c478bd9Sstevel@tonic-gate extern int	devnam_fixed;	/* can no longer change devnam */
2197c478bd9Sstevel@tonic-gate extern int	unsuccess;	/* # unsuccessful connection attempts */
2207c478bd9Sstevel@tonic-gate extern int	do_callback;	/* set if we want to do callback next */
2217c478bd9Sstevel@tonic-gate extern int	doing_callback;	/* set if this is a callback */
2227c478bd9Sstevel@tonic-gate extern u_char	nak_buffer[];	/* where we construct a nak packet */
2237c478bd9Sstevel@tonic-gate extern u_char	inpacket_buf[];	/* buffer for incoming packet */
2247c478bd9Sstevel@tonic-gate extern bool	direct_tty;	/* use standard input directly; not a tty */
2257c478bd9Sstevel@tonic-gate extern int	absmax_mru;	/* absolute maximum link (not i/f) MRU */
2267c478bd9Sstevel@tonic-gate extern int	absmax_mtu;	/* absolute maximum link (not i/f) MTU */
2277c478bd9Sstevel@tonic-gate extern int	pty_slave;	/* slave side of PTY, if any */
2287c478bd9Sstevel@tonic-gate extern bool	early_log;	/* avoid logging to stdout */
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate /*
2317c478bd9Sstevel@tonic-gate  * Values for do_callback and doing_callback.
2327c478bd9Sstevel@tonic-gate  */
2337c478bd9Sstevel@tonic-gate #define CALLBACK_DIALIN		1	/* we are expecting the call back */
2347c478bd9Sstevel@tonic-gate #define CALLBACK_DIALOUT	2	/* we are dialling out to call back */
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate /*
2377c478bd9Sstevel@tonic-gate  * Variables set by command-line options.
2387c478bd9Sstevel@tonic-gate  */
2397c478bd9Sstevel@tonic-gate extern int	debug;		/* Debug flag */
2407c478bd9Sstevel@tonic-gate extern int	kdebugflag;	/* Tell kernel to print debug messages */
2417c478bd9Sstevel@tonic-gate extern int	default_device;	/* Using /dev/tty or equivalent */
2427c478bd9Sstevel@tonic-gate extern char	devnam[MAXPATHLEN];	/* Device name */
2437c478bd9Sstevel@tonic-gate extern char	ppp_devnam[MAXPATHLEN];	/* Device name (might be pty) */
2447c478bd9Sstevel@tonic-gate extern int	crtscts;	/* Use hardware flow control */
2457c478bd9Sstevel@tonic-gate extern bool	modem;		/* Use modem control lines */
2467c478bd9Sstevel@tonic-gate extern int	inspeed;	/* Input/Output speed requested */
2477c478bd9Sstevel@tonic-gate extern u_int32_t netmask;	/* IP netmask to set on interface */
2487c478bd9Sstevel@tonic-gate extern bool	lockflag;	/* Create lock file to lock the serial dev */
2497c478bd9Sstevel@tonic-gate extern bool	nodetach;	/* Don't detach from controlling tty */
2507c478bd9Sstevel@tonic-gate extern bool	updetach;	/* Detach from controlling tty when link up */
2517c478bd9Sstevel@tonic-gate extern char	*initializer;	/* Script to initialize physical link */
2527c478bd9Sstevel@tonic-gate extern char	*connect_script; /* Script to establish physical link */
2537c478bd9Sstevel@tonic-gate extern char	*disconnect_script; /* Script to disestablish physical link */
2547c478bd9Sstevel@tonic-gate extern char	*welcomer;	/* Script to welcome client after connection */
2557c478bd9Sstevel@tonic-gate extern char	*ptycommand;	/* Command to run on other side of pty */
2567c478bd9Sstevel@tonic-gate extern int	maxconnect;	/* Maximum connect time (seconds) */
2577c478bd9Sstevel@tonic-gate extern char	user[MAXNAMELEN];/* Our name for authenticating ourselves */
2587c478bd9Sstevel@tonic-gate extern char	passwd[MAXSECRETLEN];	/* Password for PAP or CHAP */
2597c478bd9Sstevel@tonic-gate extern bool	auth_required;	/* Peer is required to authenticate */
2607c478bd9Sstevel@tonic-gate extern bool	persist;	/* Reopen link after it goes down */
2617c478bd9Sstevel@tonic-gate extern bool	uselogin;	/* Use /etc/passwd for checking PAP */
2627c478bd9Sstevel@tonic-gate extern char	our_name[MAXNAMELEN];/* Our name for authentication purposes */
2637c478bd9Sstevel@tonic-gate extern char	remote_name[MAXNAMELEN]; /* Peer's name for authentication */
2647c478bd9Sstevel@tonic-gate extern bool	explicit_remote;/* remote_name specified with remotename opt */
2657c478bd9Sstevel@tonic-gate extern bool	demand;		/* Do dial-on-demand */
2667c478bd9Sstevel@tonic-gate extern char	*ipparam;	/* Extra parameter for ip up/down scripts */
2677c478bd9Sstevel@tonic-gate extern bool	cryptpap;	/* Others' PAP passwords are encrypted */
2687c478bd9Sstevel@tonic-gate extern int	idle_time_limit;/* Shut down link if idle for this long */
2697c478bd9Sstevel@tonic-gate extern int	holdoff;	/* Dead time before restarting */
2707c478bd9Sstevel@tonic-gate extern bool	holdoff_specified; /* true if user gave a holdoff value */
2717c478bd9Sstevel@tonic-gate extern bool	notty;		/* Stdin/out is not a tty */
2727c478bd9Sstevel@tonic-gate extern char	*pty_socket;	/* Socket to connect to pty */
2737c478bd9Sstevel@tonic-gate extern char	*record_file;	/* File to record chars sent/received */
2747c478bd9Sstevel@tonic-gate extern bool	sync_serial;	/* Device is synchronous serial device */
2757c478bd9Sstevel@tonic-gate extern int	maxfail;	/* Max # of unsuccessful connection attempts */
2767c478bd9Sstevel@tonic-gate extern char	linkname[MAXPATHLEN]; /* logical name for link */
2777c478bd9Sstevel@tonic-gate extern bool	tune_kernel;	/* May alter kernel settings as necessary */
2787c478bd9Sstevel@tonic-gate extern int	connect_delay;	/* Time to delay after connect script */
2797c478bd9Sstevel@tonic-gate extern int	max_data_rate;	/* max bytes/sec through charshunt */
2807c478bd9Sstevel@tonic-gate extern int	req_unit;	/* interface unit number to use */
2817c478bd9Sstevel@tonic-gate extern bool	multilink;	/* enable multilink operation */
2827c478bd9Sstevel@tonic-gate extern bool	noendpoint;	/* don't send or accept endpt. discrim. */
2837c478bd9Sstevel@tonic-gate extern char	*bundle_name;	/* bundle name for multilink */
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate #ifdef HAVE_MULTILINK
2867c478bd9Sstevel@tonic-gate extern TDB_CONTEXT *pppdb;	/* handle to multilink database context */
2877c478bd9Sstevel@tonic-gate extern char	db_key[];	/* multilink database key */
2887c478bd9Sstevel@tonic-gate #endif
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate #ifdef PPP_FILTER
2917c478bd9Sstevel@tonic-gate extern struct	bpf_program pass_filter;   /* Filter for pkts to pass */
2927c478bd9Sstevel@tonic-gate extern struct	bpf_program active_filter; /* Filter for link-active pkts */
2937c478bd9Sstevel@tonic-gate #endif /* PPP_FILTER */
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate #ifdef MSLANMAN
2967c478bd9Sstevel@tonic-gate extern bool	ms_lanman;	/* Use LanMan password instead of NT */
2977c478bd9Sstevel@tonic-gate 				/* Has meaning only with MS-CHAP challenges */
2987c478bd9Sstevel@tonic-gate #endif /* MXLANMAN */
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate extern char *current_option;	/* the name of the option being parsed */
3017c478bd9Sstevel@tonic-gate extern bool privileged_option;	/* set iff the current option came from root */
3027c478bd9Sstevel@tonic-gate extern char *option_source;	/* string saying where the option came from */
3037c478bd9Sstevel@tonic-gate extern int option_line;		/*   and from which line in the file */
3047c478bd9Sstevel@tonic-gate extern bool already_ppp;	/* device is already in PPP mode */
3057c478bd9Sstevel@tonic-gate extern bool prepass;		/* Doing pre-pass to find device name */
3067c478bd9Sstevel@tonic-gate extern struct stat devstat;	/* Result of stat() on device */
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate extern bool peer_nak_auth;	/* Peer sent nak for our auth request */
3097c478bd9Sstevel@tonic-gate extern u_short nak_auth_orig;	/* Auth proto peer naked */
3107c478bd9Sstevel@tonic-gate extern u_short nak_auth_proto;	/* Auth proto peer suggested instead */
3117c478bd9Sstevel@tonic-gate extern bool unsolicited_nak_auth; /* Peer asked us to authenticate */
3127c478bd9Sstevel@tonic-gate extern u_short unsolicit_auth_proto; /* Auth proto peer wants */
3137c478bd9Sstevel@tonic-gate extern bool peer_reject_auth;	/* Peer sent reject for auth */
3147c478bd9Sstevel@tonic-gate extern u_short reject_auth_proto; /* Protocol that peer rejected */
3157c478bd9Sstevel@tonic-gate extern bool rejected_peers_auth; /* We sent a reject to the peer */
3167c478bd9Sstevel@tonic-gate extern u_short rejected_auth_proto; /* Protocol that peer wanted to use */
3177c478bd9Sstevel@tonic-gate extern bool naked_peers_auth;	/* We sent a nak to the peer */
3187c478bd9Sstevel@tonic-gate extern u_short naked_auth_orig;	/* Protocol that we wanted to use */
3197c478bd9Sstevel@tonic-gate extern u_short naked_auth_proto; /* Protocol that peer wants us to use */
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate /*
3227c478bd9Sstevel@tonic-gate  * Values for phase.
3237c478bd9Sstevel@tonic-gate  */
3247c478bd9Sstevel@tonic-gate #define PHASE_DEAD		0	/* RFC 1661; link terminated */
3257c478bd9Sstevel@tonic-gate #define PHASE_INITIALIZE	1	/* execution begins */
3267c478bd9Sstevel@tonic-gate #define PHASE_INITIALIZED	2	/* options ok; entering main loop */
3277c478bd9Sstevel@tonic-gate #define PHASE_SERIALCONN	3	/* connecting to peer */
3287c478bd9Sstevel@tonic-gate #define PHASE_CONNECTED		4	/* connecting to peer */
3297c478bd9Sstevel@tonic-gate #define PHASE_DORMANT		5	/* waiting for demand-dial trigger */
3307c478bd9Sstevel@tonic-gate #define PHASE_ESTABLISH		6	/* RFC 1661; LCP negotiation begins */
3317c478bd9Sstevel@tonic-gate #define PHASE_AUTHENTICATE	7	/* RFC 1661; authentication begins */
3327c478bd9Sstevel@tonic-gate #define PHASE_CALLBACK		8	/* negotiating for callback */
3337c478bd9Sstevel@tonic-gate #define PHASE_NETWORK		9	/* RFC 1661; NCP negotiation begins */
3347c478bd9Sstevel@tonic-gate #define PHASE_RUNNING		10	/* first NCP went to Opened state */
3357c478bd9Sstevel@tonic-gate #define PHASE_TERMINATE		11	/* RFC 1661; LCP left Opened state */
3367c478bd9Sstevel@tonic-gate #define PHASE_DISCONNECT	12	/* running disconnect script */
3377c478bd9Sstevel@tonic-gate #define PHASE_HOLDOFF		13	/* waiting before restart */
3387c478bd9Sstevel@tonic-gate #define PHASE_CALLINGBACK	14	/* calling back */
3397c478bd9Sstevel@tonic-gate #define	PHASE_EXIT		15	/* execution ends */
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate #define	PHASE__NAMES \
3427c478bd9Sstevel@tonic-gate 	"Dead", "Initialize", "Initialized", "Serialconn", "Connected", \
3437c478bd9Sstevel@tonic-gate 	"Dormant", "Establish", "Authenticate", "Callback", "Network", \
3447c478bd9Sstevel@tonic-gate 	"Running", "Terminate", "Disconnect", "Holdoff", "Callingback", \
3457c478bd9Sstevel@tonic-gate 	"Exit"
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate /*
3487c478bd9Sstevel@tonic-gate  * The following struct gives the addresses of procedures to call
3497c478bd9Sstevel@tonic-gate  * for a particular protocol.
3507c478bd9Sstevel@tonic-gate  */
3517c478bd9Sstevel@tonic-gate struct protent {
3527c478bd9Sstevel@tonic-gate     u_short protocol;		/* PPP protocol number */
3537c478bd9Sstevel@tonic-gate     /* Initialization procedure */
3547c478bd9Sstevel@tonic-gate     void (*init) __P((int unit));
3557c478bd9Sstevel@tonic-gate     /* Process a received packet */
3567c478bd9Sstevel@tonic-gate     void (*input) __P((int unit, u_char *pkt, int len));
3577c478bd9Sstevel@tonic-gate     /* Process a received protocol-reject */
3587c478bd9Sstevel@tonic-gate     void (*protrej) __P((int unit));
3597c478bd9Sstevel@tonic-gate     /* Lower layer has come up */
3607c478bd9Sstevel@tonic-gate     void (*lowerup) __P((int unit));
3617c478bd9Sstevel@tonic-gate     /* Lower layer has gone down */
3627c478bd9Sstevel@tonic-gate     void (*lowerdown) __P((int unit));
3637c478bd9Sstevel@tonic-gate     /* Open the protocol */
3647c478bd9Sstevel@tonic-gate     void (*open) __P((int unit));
3657c478bd9Sstevel@tonic-gate     /* Close the protocol */
3667c478bd9Sstevel@tonic-gate     void (*close) __P((int unit, char *reason));
3677c478bd9Sstevel@tonic-gate     /* Print a packet in readable form */
3687c478bd9Sstevel@tonic-gate     int  (*printpkt) __P((u_char *pkt, int len,
3697c478bd9Sstevel@tonic-gate 			  void (*printer) __P((void *, const char *, ...)),
3707c478bd9Sstevel@tonic-gate 			  void *arg));
3717c478bd9Sstevel@tonic-gate     /* Process a received data packet */
3727c478bd9Sstevel@tonic-gate     void (*datainput) __P((int unit, u_char *pkt, int len));
3737c478bd9Sstevel@tonic-gate     bool enabled_flag;		/* 0 iff protocol is disabled */
3747c478bd9Sstevel@tonic-gate     char *name;			/* Text name of protocol */
3757c478bd9Sstevel@tonic-gate     char *data_name;		/* Text name of corresponding data protocol */
3767c478bd9Sstevel@tonic-gate     option_t *options;		/* List of command-line options */
3777c478bd9Sstevel@tonic-gate     /* Check requested options, assign defaults */
3787c478bd9Sstevel@tonic-gate     void (*check_options) __P((void));
3797c478bd9Sstevel@tonic-gate     /* Configure interface for demand-dial */
3807c478bd9Sstevel@tonic-gate     int  (*demand_conf) __P((int unit));
3817c478bd9Sstevel@tonic-gate     /* Say whether to bring up link for this pkt */
3827c478bd9Sstevel@tonic-gate     int  (*active_pkt) __P((u_char *pkt, int len));
3837c478bd9Sstevel@tonic-gate     /* Print current status to file or syslog (if strptr == NULL) */
3847c478bd9Sstevel@tonic-gate     void (*print_stat) __P((int unit, FILE *strptr));
3857c478bd9Sstevel@tonic-gate };
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate /*
3887c478bd9Sstevel@tonic-gate  * This structure is used to store information about certain
3897c478bd9Sstevel@tonic-gate  * options, such as where the option value came from (/etc/ppp/options,
3907c478bd9Sstevel@tonic-gate  * command line, etc.) and whether it came from a privileged source.
3917c478bd9Sstevel@tonic-gate  */
3927c478bd9Sstevel@tonic-gate struct option_info {
3937c478bd9Sstevel@tonic-gate     bool    priv;		/* was value set by sysadmin? */
3947c478bd9Sstevel@tonic-gate     char    *source;		/* where option came from */
3957c478bd9Sstevel@tonic-gate     int	    line;		/* line number where the option came from */
3967c478bd9Sstevel@tonic-gate };
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate extern struct option_info devnam_info;
3997c478bd9Sstevel@tonic-gate extern struct option_info initializer_info;
4007c478bd9Sstevel@tonic-gate extern struct option_info connect_script_info;
4017c478bd9Sstevel@tonic-gate extern struct option_info disconnect_script_info;
4027c478bd9Sstevel@tonic-gate extern struct option_info welcomer_info;
4037c478bd9Sstevel@tonic-gate extern struct option_info ptycommand_info;
4047c478bd9Sstevel@tonic-gate extern struct option_info ipsrc_info;
4057c478bd9Sstevel@tonic-gate extern struct option_info ipdst_info;
4067c478bd9Sstevel@tonic-gate extern struct option_info speed_info;
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate /*
4097c478bd9Sstevel@tonic-gate  * Table of pointers to supported protocols.
4107c478bd9Sstevel@tonic-gate  */
4117c478bd9Sstevel@tonic-gate extern struct protent *protocols[];
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate /*
4147c478bd9Sstevel@tonic-gate  * Prototypes.
4157c478bd9Sstevel@tonic-gate  */
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate  * Procedures exported from main.c.
4197c478bd9Sstevel@tonic-gate  */
4207c478bd9Sstevel@tonic-gate extern void set_ifunit __P((int));  /* set stuff that depends on ifunit */
4217c478bd9Sstevel@tonic-gate extern void detach __P((void));	    /* Detach from controlling tty */
4227c478bd9Sstevel@tonic-gate extern void die __P((int));	    /* Cleanup and exit */
4237c478bd9Sstevel@tonic-gate extern void quit __P((void));	    /* like die(1) */
4247c478bd9Sstevel@tonic-gate extern void novm __P((char *));	    /* Say we ran out of memory, and die */
4257c478bd9Sstevel@tonic-gate extern void timeout __P((void (*func)(void *), void *arg, int t));
4267c478bd9Sstevel@tonic-gate 				/* Call func(arg) after t seconds */
4277c478bd9Sstevel@tonic-gate extern void untimeout __P((void (*func)(void *), void *arg));
4287c478bd9Sstevel@tonic-gate 				/* Cancel call to func(arg) */
4297c478bd9Sstevel@tonic-gate extern pid_t run_program __P((char *prog, char **args, int must_exist,
4307c478bd9Sstevel@tonic-gate     void (*done)(void *, int), void *arg));
4317c478bd9Sstevel@tonic-gate 				/* Run program prog with args in child */
4327c478bd9Sstevel@tonic-gate extern void reopen_log __P((void)); /* (re)open the connection to syslog */
4337c478bd9Sstevel@tonic-gate extern void update_link_stats __P((int)); /* Get stats at link termination */
4347c478bd9Sstevel@tonic-gate /* set script env var */
4357c478bd9Sstevel@tonic-gate extern void script_setenv __P((const char *, const char *, int));
4367c478bd9Sstevel@tonic-gate extern void script_unsetenv __P((const char *));  /* unset script env var */
4377c478bd9Sstevel@tonic-gate extern const char *script_getenv __P((const char *var));
4387c478bd9Sstevel@tonic-gate extern void new_phase __P((int));   /* signal start of new phase */
4397c478bd9Sstevel@tonic-gate extern void print_ncpstate __P((int, FILE *));	/* prints NCP state */
4407c478bd9Sstevel@tonic-gate extern const char *protocol_name __P((int proto));	/* canonical name */
4417c478bd9Sstevel@tonic-gate extern const char *phase_name __P((int phaseval));
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate /*
4447c478bd9Sstevel@tonic-gate  * Procedures exported from utils.c.
4457c478bd9Sstevel@tonic-gate  */
4467c478bd9Sstevel@tonic-gate extern void log_packet __P((u_char *, int, const char *, int));
4477c478bd9Sstevel@tonic-gate 				/* Format a packet and log it with syslog */
4487c478bd9Sstevel@tonic-gate extern void print_string __P((char *, int, void (*)(void *, const char *, ...),
4497c478bd9Sstevel@tonic-gate     void *));			/* Format a string for output */
4507c478bd9Sstevel@tonic-gate extern int slprintf __P((char *, int, const char *, ...));  /* sprintf++ */
4517c478bd9Sstevel@tonic-gate extern int vslprintf __P((char *, int, const char *, va_list));/* vsprintf++ */
4527c478bd9Sstevel@tonic-gate extern size_t strlcpy __P((char *, const char *, size_t));  /* safe strcpy */
4537c478bd9Sstevel@tonic-gate extern size_t strlcat __P((char *, const char *, size_t));  /* safe strncpy */
4547c478bd9Sstevel@tonic-gate extern void dbglog __P((const char *, ...));/* log a debug message */
4557c478bd9Sstevel@tonic-gate extern void info __P((const char *, ...));  /* log an informational message */
4567c478bd9Sstevel@tonic-gate extern void notice __P((const char *, ...));/* log a notice-level message */
4577c478bd9Sstevel@tonic-gate extern void warn __P((const char *, ...));  /* log a warning message */
4587c478bd9Sstevel@tonic-gate extern void error __P((const char *, ...)); /* log an error message */
4597c478bd9Sstevel@tonic-gate extern void fatal __P((const char *, ...));
4607c478bd9Sstevel@tonic-gate 				/* log an error message and die(1) */
4617c478bd9Sstevel@tonic-gate extern const char *code_name __P((int code, int shortflag));
4627c478bd9Sstevel@tonic-gate 				/* Code to string */
4637c478bd9Sstevel@tonic-gate extern int flprintf __P((FILE *, const char *, ...));  /* fprintf++ */
4647c478bd9Sstevel@tonic-gate extern size_t strllen __P((const char *, size_t)); /* safe strlen */
4657c478bd9Sstevel@tonic-gate extern const char *signal_name __P((int signum));
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate /*
4687c478bd9Sstevel@tonic-gate  * Procedures exported from auth.c
4697c478bd9Sstevel@tonic-gate  */
4707c478bd9Sstevel@tonic-gate extern void link_required __P((int));	/* we are starting to use the link */
4717c478bd9Sstevel@tonic-gate extern void link_terminated __P((int));	/* we are finished with the link */
4727c478bd9Sstevel@tonic-gate extern void link_down __P((int));
4737c478bd9Sstevel@tonic-gate 				/* the LCP layer has left the Opened state */
4747c478bd9Sstevel@tonic-gate extern void link_established __P((int)); /* the link is up; authenticate now */
4757c478bd9Sstevel@tonic-gate extern void start_networks __P((void));
4767c478bd9Sstevel@tonic-gate 				/* start all the network control protos */
4777c478bd9Sstevel@tonic-gate extern void np_up __P((int, int));	/* a network protocol has come up */
4787c478bd9Sstevel@tonic-gate extern void np_down __P((int, int));	/* a network protocol has gone down */
4797c478bd9Sstevel@tonic-gate extern void np_finished __P((int, int));
4807c478bd9Sstevel@tonic-gate 				/* a network protocol no longer needs link */
4817c478bd9Sstevel@tonic-gate extern void auth_peer_fail __P((int, int));
4827c478bd9Sstevel@tonic-gate 				/* peer failed to authenticate itself */
4837c478bd9Sstevel@tonic-gate extern void auth_peer_success __P((int, int, char *, int));
4847c478bd9Sstevel@tonic-gate 				/* peer successfully authenticated itself */
4857c478bd9Sstevel@tonic-gate extern void auth_withpeer_fail __P((int, int));
4867c478bd9Sstevel@tonic-gate 				/* we failed to authenticate ourselves */
4877c478bd9Sstevel@tonic-gate extern void auth_withpeer_success __P((int, int));
4887c478bd9Sstevel@tonic-gate 				/* we successfully authenticated ourselves */
4897c478bd9Sstevel@tonic-gate extern void auth_check_options __P((void));
4907c478bd9Sstevel@tonic-gate 				/* check authentication options supplied */
4917c478bd9Sstevel@tonic-gate extern void auth_reset __P((int));
4927c478bd9Sstevel@tonic-gate 				/* check what secrets we have */
4937c478bd9Sstevel@tonic-gate extern int  check_passwd __P((int, char *, int, char *, int, char **));
4947c478bd9Sstevel@tonic-gate 				/* Check peer-supplied username/password */
4957c478bd9Sstevel@tonic-gate extern int  get_secret __P((int, char *, char *, char *, int *, int));
4967c478bd9Sstevel@tonic-gate 				/* get "secret" for chap */
4977c478bd9Sstevel@tonic-gate extern int  auth_ip_addr __P((int, u_int32_t));
4987c478bd9Sstevel@tonic-gate 				/* check if IP address is authorized */
4997c478bd9Sstevel@tonic-gate extern int  bad_ip_adrs __P((u_int32_t));
5007c478bd9Sstevel@tonic-gate 				/* check if IP address is unreasonable */
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate /*
5037c478bd9Sstevel@tonic-gate  * Procedures exported from demand.c
5047c478bd9Sstevel@tonic-gate  */
5057c478bd9Sstevel@tonic-gate extern void demand_conf __P((void));
5067c478bd9Sstevel@tonic-gate 				/* config interface(s) for demand-dial */
5077c478bd9Sstevel@tonic-gate extern void demand_block __P((void));	/* set all NPs to queue up packets */
5087c478bd9Sstevel@tonic-gate extern void demand_unblock __P((void)); /* set all NPs to pass packets */
5097c478bd9Sstevel@tonic-gate extern void demand_discard __P((void)); /* set all NPs to discard packets */
5107c478bd9Sstevel@tonic-gate extern void demand_rexmit __P((int));	/* retransmit saved frames for an NP */
5117c478bd9Sstevel@tonic-gate extern int  loop_chars __P((unsigned char *, int));
5127c478bd9Sstevel@tonic-gate 				/* process chars from loopback */
5137c478bd9Sstevel@tonic-gate extern int  loop_frame __P((unsigned char *, int));
5147c478bd9Sstevel@tonic-gate 				/* should we bring link up? */
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate /*
5177c478bd9Sstevel@tonic-gate  * Procedures exported from multilink.c
5187c478bd9Sstevel@tonic-gate  */
5197c478bd9Sstevel@tonic-gate extern void mp_check_options __P((void)); /* Check multilink-related options */
5207c478bd9Sstevel@tonic-gate extern int  mp_join_bundle __P((void));
5217c478bd9Sstevel@tonic-gate 				/* join our link to an appropriate bundle */
5227c478bd9Sstevel@tonic-gate /*
5237c478bd9Sstevel@tonic-gate  * Procedures exported from sys-*.c
5247c478bd9Sstevel@tonic-gate  */
5257c478bd9Sstevel@tonic-gate extern void sys_init __P((bool));   /* Do system-dependent initialization */
5267c478bd9Sstevel@tonic-gate extern void sys_cleanup __P((void)); /* Restore system state before exiting */
5277c478bd9Sstevel@tonic-gate extern int  sys_check_options __P((void)); /* Check options specified */
5287c478bd9Sstevel@tonic-gate extern void sys_options __P((void));	/* add or remove system options */
5297c478bd9Sstevel@tonic-gate extern void sys_close __P((void));  /* Clean up in a child before execing */
5307c478bd9Sstevel@tonic-gate extern int  ppp_available __P((void));
5317c478bd9Sstevel@tonic-gate 				/* Test whether ppp kernel support exists */
5327c478bd9Sstevel@tonic-gate extern int  get_pty __P((int *, int *, char *, int));
5337c478bd9Sstevel@tonic-gate 				/* Get pty master/slave */
5347c478bd9Sstevel@tonic-gate extern int  open_ppp_loopback __P((void));
5357c478bd9Sstevel@tonic-gate 				/* Open loopback for demand-dialling */
5367c478bd9Sstevel@tonic-gate extern int  establish_ppp __P((int));
5377c478bd9Sstevel@tonic-gate 				/* Turn serial port into a ppp interface */
5387c478bd9Sstevel@tonic-gate extern void restore_loop __P((void));
5397c478bd9Sstevel@tonic-gate 				/* Transfer ppp unit back to loopback */
5407c478bd9Sstevel@tonic-gate extern void disestablish_ppp __P((int));
5417c478bd9Sstevel@tonic-gate 				/* Restore port to normal operation */
5427c478bd9Sstevel@tonic-gate extern void make_new_bundle __P((int, int, int, int)); /* Create new bundle */
5437c478bd9Sstevel@tonic-gate extern int  bundle_attach __P((int)); /* Attach link to existing bundle */
5447c478bd9Sstevel@tonic-gate extern void cfg_bundle __P((int, int, int, int));
5457c478bd9Sstevel@tonic-gate 				/* Configure existing bundle */
5467c478bd9Sstevel@tonic-gate extern void clean_check __P((void));	/* Check if line was 8-bit clean */
5477c478bd9Sstevel@tonic-gate extern void set_up_tty __P((int, int));
5487c478bd9Sstevel@tonic-gate 				/* Set up port's speed, parameters, etc. */
5497c478bd9Sstevel@tonic-gate extern void restore_tty __P((int)); /* Restore port's original parameters */
5507c478bd9Sstevel@tonic-gate extern void setdtr __P((int, int)); /* Raise or lower port's DTR line */
5517c478bd9Sstevel@tonic-gate extern void output __P((int, u_char *, int)); /* Output a PPP packet */
5527c478bd9Sstevel@tonic-gate extern void wait_input __P((struct timeval *));
5537c478bd9Sstevel@tonic-gate 				/* Wait for input, with timeout */
5547c478bd9Sstevel@tonic-gate extern void add_fd __P((int));	/* Add fd to set to wait for */
5557c478bd9Sstevel@tonic-gate extern void remove_fd __P((int));   /* Remove fd from set to wait for */
5567c478bd9Sstevel@tonic-gate extern int  read_packet __P((u_char *)); /* Read PPP packet */
5577c478bd9Sstevel@tonic-gate extern int  get_loop_output __P((void)); /* Read pkts from loopback */
5587c478bd9Sstevel@tonic-gate extern void ppp_send_config __P((int, int, u_int32_t, int, int));
5597c478bd9Sstevel@tonic-gate 				/* Configure i/f transmit parameters */
5607c478bd9Sstevel@tonic-gate extern void ppp_set_xaccm __P((int, ext_accm));
5617c478bd9Sstevel@tonic-gate 				/* Set extended transmit ACCM */
5627c478bd9Sstevel@tonic-gate extern void ppp_recv_config __P((int, int, u_int32_t, int, int));
5637c478bd9Sstevel@tonic-gate 				/* Configure i/f receive parameters */
5647c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS
5657c478bd9Sstevel@tonic-gate extern void ppp_send_fcs __P((int unit, int fcstype));
5667c478bd9Sstevel@tonic-gate extern void ppp_recv_fcs __P((int unit, int fcstype));
5677c478bd9Sstevel@tonic-gate #endif /* NEGOTIATE_FCS */
5687c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME
5697c478bd9Sstevel@tonic-gate extern void ppp_send_muxoption __P((int ,u_int32_t));
5707c478bd9Sstevel@tonic-gate extern void ppp_recv_muxoption __P((int ,u_int32_t));
5717c478bd9Sstevel@tonic-gate #endif /* MUX_FRAME */
5727c478bd9Sstevel@tonic-gate extern int  ccp_test __P((int, u_char *, int, int));
5737c478bd9Sstevel@tonic-gate 				/* Test support for compression scheme */
5747c478bd9Sstevel@tonic-gate #ifdef COMP_TUNE
5757c478bd9Sstevel@tonic-gate extern void ccp_tune __P((int, int));	/* Tune compression effort level */
5767c478bd9Sstevel@tonic-gate #endif /* COMP_TUNE */
5777c478bd9Sstevel@tonic-gate extern void ccp_flags_set __P((int, int, int));
5787c478bd9Sstevel@tonic-gate 				/* Set kernel CCP state */
5797c478bd9Sstevel@tonic-gate extern int ccp_fatal_error __P((int));
5807c478bd9Sstevel@tonic-gate 				/* Test for fatal decomp error in kernel */
5817c478bd9Sstevel@tonic-gate extern int get_idle_time __P((int, struct ppp_idle *));
5827c478bd9Sstevel@tonic-gate 				/* Find out how long link has been idle */
5837c478bd9Sstevel@tonic-gate extern int get_ppp_stats __P((int, struct pppd_stats *));
5847c478bd9Sstevel@tonic-gate 				/* Return link statistics */
5857c478bd9Sstevel@tonic-gate extern int sifvjcomp __P((int, int, int, int));
5867c478bd9Sstevel@tonic-gate 				/* Configure VJ TCP header compression */
5877c478bd9Sstevel@tonic-gate extern int sifup __P((int));	/* Configure i/f up for one protocol */
5887c478bd9Sstevel@tonic-gate extern int sifnpmode __P((int u, int proto, enum NPmode mode));
5897c478bd9Sstevel@tonic-gate 				/* Set mode for handling packets for proto */
5907c478bd9Sstevel@tonic-gate extern int sifdown __P((int));	/* Configure i/f down for one protocol */
5917c478bd9Sstevel@tonic-gate extern int sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t));
5927c478bd9Sstevel@tonic-gate 				/* Configure IPv4 addresses for i/f */
5937c478bd9Sstevel@tonic-gate extern int cifaddr __P((int, u_int32_t, u_int32_t));
5947c478bd9Sstevel@tonic-gate 				/* Reset i/f IP addresses */
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate extern void sys_block_proto __P((uint16_t));
5977c478bd9Sstevel@tonic-gate extern void sys_unblock_proto __P((uint16_t));
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate #ifdef INET6
6007c478bd9Sstevel@tonic-gate extern int sif6addr __P((int, eui64_t, eui64_t));
6017c478bd9Sstevel@tonic-gate 				/* Configure IPv6 addresses for i/f */
6027c478bd9Sstevel@tonic-gate extern int cif6addr __P((int, eui64_t, eui64_t));
6037c478bd9Sstevel@tonic-gate 				/* Remove an IPv6 address from i/f */
6047c478bd9Sstevel@tonic-gate #endif /* INET6 */
6057c478bd9Sstevel@tonic-gate extern int sifdefaultroute __P((int, u_int32_t, u_int32_t));
6067c478bd9Sstevel@tonic-gate 				/* Create default route through i/f */
6077c478bd9Sstevel@tonic-gate extern int cifdefaultroute __P((int, u_int32_t, u_int32_t));
6087c478bd9Sstevel@tonic-gate 				/* Delete default route through i/f */
6097c478bd9Sstevel@tonic-gate extern int sifproxyarp __P((int unit, u_int32_t addr, int flag));
6107c478bd9Sstevel@tonic-gate 				/* Add proxy ARP entry for peer */
6117c478bd9Sstevel@tonic-gate extern int cifproxyarp __P((int unit, u_int32_t addr));
6127c478bd9Sstevel@tonic-gate 				/* Delete proxy ARP entry for peer */
6137c478bd9Sstevel@tonic-gate extern u_int32_t GetMask __P((u_int32_t));
6147c478bd9Sstevel@tonic-gate 				/* Get appropriate netmask for address */
6157c478bd9Sstevel@tonic-gate extern int lock __P((char *));	/* Create lock file for device */
6167c478bd9Sstevel@tonic-gate extern int relock __P((int));	/* Rewrite lock file with new pid */
6177c478bd9Sstevel@tonic-gate extern void unlock __P((void));	/* Delete previously-created lock file */
6187c478bd9Sstevel@tonic-gate extern void logwtmp __P((const char *, const char *, const char *));
6197c478bd9Sstevel@tonic-gate 				/* Write entry to wtmp file */
6207c478bd9Sstevel@tonic-gate extern int get_host_seed __P((void));
6217c478bd9Sstevel@tonic-gate 				/* Get host-dependent random number seed */
6227c478bd9Sstevel@tonic-gate extern int have_route_to __P((u_int32_t)); /* Check if route to addr exists */
6237c478bd9Sstevel@tonic-gate #ifdef PPP_FILTER
6247c478bd9Sstevel@tonic-gate extern int set_filters __P((struct bpf_program *pass,
6257c478bd9Sstevel@tonic-gate     struct bpf_program *active));
6267c478bd9Sstevel@tonic-gate 				/* Set filter programs in kernel */
6277c478bd9Sstevel@tonic-gate #endif /* PPP_FILTER */
6287c478bd9Sstevel@tonic-gate #ifdef IPX_CHANGE
6297c478bd9Sstevel@tonic-gate extern int sipxfaddr __P((int, unsigned long, unsigned char *));
6307c478bd9Sstevel@tonic-gate extern int cipxfaddr __P((int));
6317c478bd9Sstevel@tonic-gate #endif /* IPX_CHANGE */
6327c478bd9Sstevel@tonic-gate extern int get_if_hwaddr __P((u_char *addr, int msize, char *name));
6337c478bd9Sstevel@tonic-gate extern int get_first_hwaddr __P((u_char *addr, int msize));
6347c478bd9Sstevel@tonic-gate #if defined(INET6) && defined(SOL2)
6357c478bd9Sstevel@tonic-gate extern int ether_to_eui64 __P((eui64_t *p_eui64));
6367c478bd9Sstevel@tonic-gate extern int sif6up __P((int unit));
6377c478bd9Sstevel@tonic-gate extern int sif6down __P((int unit));
6387c478bd9Sstevel@tonic-gate extern int sif6mtu __P((int mtu));
6397c478bd9Sstevel@tonic-gate extern int sif6flags __P((u_int32_t flags, int set));
6407c478bd9Sstevel@tonic-gate #endif /* INET6 && SOL2*/
6417c478bd9Sstevel@tonic-gate #if defined(INET6) && !defined(SOL2)
6427c478bd9Sstevel@tonic-gate #define sif6up sifup
6437c478bd9Sstevel@tonic-gate #endif
6447c478bd9Sstevel@tonic-gate extern int sifmtu __P((int mtu));
6457c478bd9Sstevel@tonic-gate extern int siflags __P((u_int32_t flags, int set));
6467c478bd9Sstevel@tonic-gate extern void sys_ifname __P((void));
6477c478bd9Sstevel@tonic-gate extern void sys_print_state __P((FILE *strptr));
6487c478bd9Sstevel@tonic-gate extern int sys_extra_fd __P((void));
6497c478bd9Sstevel@tonic-gate 
6507c478bd9Sstevel@tonic-gate /*
6517c478bd9Sstevel@tonic-gate  * Procedures exported from options.c
6527c478bd9Sstevel@tonic-gate  */
6537c478bd9Sstevel@tonic-gate extern int parse_args __P((int argc, char **argv));
6547c478bd9Sstevel@tonic-gate 	/* Parse options from arguments given */
6557c478bd9Sstevel@tonic-gate extern int options_from_file __P((char *filename, bool must_exist,
6567c478bd9Sstevel@tonic-gate     bool check_prot, bool privileged));
6577c478bd9Sstevel@tonic-gate 	/* Parse options from an options file */
6587c478bd9Sstevel@tonic-gate extern int options_from_user __P((void));
6597c478bd9Sstevel@tonic-gate 	/* Parse options from user's .ppprc */
6607c478bd9Sstevel@tonic-gate extern int options_for_tty __P((void));
6617c478bd9Sstevel@tonic-gate 	/* Parse options from /etc/ppp/options.tty */
6627c478bd9Sstevel@tonic-gate extern int options_from_list __P((struct wordlist *, bool privileged));
6637c478bd9Sstevel@tonic-gate 	/* Parse options from a wordlist */
6647c478bd9Sstevel@tonic-gate extern int getword __P((FILE *f, char *word, int *newlinep, char *filename));
6657c478bd9Sstevel@tonic-gate 	/* Read a word from a file */
6667c478bd9Sstevel@tonic-gate extern void option_error __P((char *fmt, ...));
6677c478bd9Sstevel@tonic-gate 	/* Print an error message about an option */
6687c478bd9Sstevel@tonic-gate extern int int_option __P((char *, int *));
6697c478bd9Sstevel@tonic-gate 	/* Simplified number_option for decimal ints */
6707c478bd9Sstevel@tonic-gate extern void add_options __P((option_t *));
6717c478bd9Sstevel@tonic-gate 	/* Add extra options */
6727c478bd9Sstevel@tonic-gate extern int parse_dotted_ip __P((char *, u_int32_t *));
6737c478bd9Sstevel@tonic-gate 	/* Parse dotted IP notation */
6747c478bd9Sstevel@tonic-gate extern option_t *remove_option __P((char *));
6757c478bd9Sstevel@tonic-gate 	/* Remove (disable) an option */
6767c478bd9Sstevel@tonic-gate extern void save_source __P((struct option_info *));
6777c478bd9Sstevel@tonic-gate 	/* Save the source information (where an option comes from) */
6787c478bd9Sstevel@tonic-gate extern void set_source __P((struct option_info *));
6797c478bd9Sstevel@tonic-gate 	/* Set the source (for logging option errors detected after parsing) */
6807c478bd9Sstevel@tonic-gate extern const char *name_source __P((struct option_info *));
6817c478bd9Sstevel@tonic-gate 	/* Return a string containing the option source and line number */
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate /*
6847c478bd9Sstevel@tonic-gate  * Hooks to enable plugins to change various things.
6857c478bd9Sstevel@tonic-gate  */
6867c478bd9Sstevel@tonic-gate extern int (*new_phase_hook) __P((int new, int old));
6877c478bd9Sstevel@tonic-gate extern int (*idle_time_hook) __P((struct ppp_idle *));
6887c478bd9Sstevel@tonic-gate extern int (*holdoff_hook) __P((void));
6897c478bd9Sstevel@tonic-gate extern int (*pap_check_hook) __P((void));
6907c478bd9Sstevel@tonic-gate extern int (*pap_auth_hook) __P((char *user, char *passwd, char **msgp,
6917c478bd9Sstevel@tonic-gate     struct wordlist **paddrs, struct wordlist **popts));
6927c478bd9Sstevel@tonic-gate extern void (*pap_logout_hook) __P((void));
6937c478bd9Sstevel@tonic-gate extern int (*pap_passwd_hook) __P((char *user, char *passwd));
6947c478bd9Sstevel@tonic-gate extern void (*ip_up_hook) __P((void));
6957c478bd9Sstevel@tonic-gate extern void (*ip_down_hook) __P((void));
6967c478bd9Sstevel@tonic-gate extern int (*check_options_hook) __P((uid_t uid));
6977c478bd9Sstevel@tonic-gate /* extern int (*attach_device_hook) __P((uid_t uid, char *devnam)); */
6987c478bd9Sstevel@tonic-gate extern int (*updown_script_hook) __P((const char ***argsp));
6997c478bd9Sstevel@tonic-gate struct strbuf;	/* forward declaration */
7007c478bd9Sstevel@tonic-gate extern int (*sys_read_packet_hook) __P((int retv, struct strbuf *ctrl,
7017c478bd9Sstevel@tonic-gate     struct strbuf *data, int flags));
7027c478bd9Sstevel@tonic-gate extern void (*device_pipe_hook) __P((int pipefd));
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate /*
7057c478bd9Sstevel@tonic-gate  * Inline versions of get/put char/short/long.
7067c478bd9Sstevel@tonic-gate  * Pointer is advanced; we assume that both arguments
7077c478bd9Sstevel@tonic-gate  * are lvalues and will already be in registers.
7087c478bd9Sstevel@tonic-gate  * cp MUST be u_char *.
7097c478bd9Sstevel@tonic-gate  */
7107c478bd9Sstevel@tonic-gate #define GETCHAR(c, cp) { \
7117c478bd9Sstevel@tonic-gate 	(c) = *(cp)++; \
7127c478bd9Sstevel@tonic-gate }
7137c478bd9Sstevel@tonic-gate #define PUTCHAR(c, cp) { \
7147c478bd9Sstevel@tonic-gate 	*(cp)++ = (u_char) (c); \
7157c478bd9Sstevel@tonic-gate }
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate 
7187c478bd9Sstevel@tonic-gate #define GETSHORT(s, cp) { \
7197c478bd9Sstevel@tonic-gate 	(s) = *(cp)++ << 8; \
7207c478bd9Sstevel@tonic-gate 	(s) |= *(cp)++; \
7217c478bd9Sstevel@tonic-gate }
7227c478bd9Sstevel@tonic-gate #define PUTSHORT(s, cp) { \
7237c478bd9Sstevel@tonic-gate 	*(cp)++ = (u_char) ((s) >> 8); \
7247c478bd9Sstevel@tonic-gate 	*(cp)++ = (u_char) (s); \
7257c478bd9Sstevel@tonic-gate }
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate #define GETLONG(l, cp) { \
7287c478bd9Sstevel@tonic-gate 	(l) = *(cp)++ << 8; \
7297c478bd9Sstevel@tonic-gate 	(l) |= *(cp)++; (l) <<= 8; \
7307c478bd9Sstevel@tonic-gate 	(l) |= *(cp)++; (l) <<= 8; \
7317c478bd9Sstevel@tonic-gate 	(l) |= *(cp)++; \
7327c478bd9Sstevel@tonic-gate }
7337c478bd9Sstevel@tonic-gate #define PUTLONG(l, cp) { \
7347c478bd9Sstevel@tonic-gate 	*(cp)++ = (u_char) ((l) >> 24); \
7357c478bd9Sstevel@tonic-gate 	*(cp)++ = (u_char) ((l) >> 16); \
7367c478bd9Sstevel@tonic-gate 	*(cp)++ = (u_char) ((l) >> 8); \
7377c478bd9Sstevel@tonic-gate 	*(cp)++ = (u_char) (l); \
7387c478bd9Sstevel@tonic-gate }
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate /*
7417c478bd9Sstevel@tonic-gate  * For values that are kept internally in network byte order.
7427c478bd9Sstevel@tonic-gate  */
7437c478bd9Sstevel@tonic-gate #define GETNLONG(l, cp) { \
7447c478bd9Sstevel@tonic-gate 	u_int32_t getnlong_val; \
7457c478bd9Sstevel@tonic-gate 	getnlong_val = *(cp)++ << 8; \
7467c478bd9Sstevel@tonic-gate 	getnlong_val |= *(cp)++; getnlong_val <<= 8; \
7477c478bd9Sstevel@tonic-gate 	getnlong_val |= *(cp)++; getnlong_val <<= 8; \
7487c478bd9Sstevel@tonic-gate 	getnlong_val |= *(cp)++; \
7497c478bd9Sstevel@tonic-gate 	(l) = htonl(getnlong_val); \
7507c478bd9Sstevel@tonic-gate }
7517c478bd9Sstevel@tonic-gate #define PUTNLONG(l, cp) { \
7527c478bd9Sstevel@tonic-gate 	u_int32_t putnlong_val = ntohl(l); \
7537c478bd9Sstevel@tonic-gate 	*(cp)++ = (u_char) (putnlong_val >> 24); \
7547c478bd9Sstevel@tonic-gate 	*(cp)++ = (u_char) (putnlong_val >> 16); \
7557c478bd9Sstevel@tonic-gate 	*(cp)++ = (u_char) (putnlong_val >> 8); \
7567c478bd9Sstevel@tonic-gate 	*(cp)++ = (u_char) putnlong_val; \
7577c478bd9Sstevel@tonic-gate }
7587c478bd9Sstevel@tonic-gate 
7597c478bd9Sstevel@tonic-gate #define INCPTR(n, cp)	((cp) += (n))
7607c478bd9Sstevel@tonic-gate #define DECPTR(n, cp)	((cp) -= (n))
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate /*
7637c478bd9Sstevel@tonic-gate  * System dependent definitions for user-level 4.3BSD UNIX implementation.
7647c478bd9Sstevel@tonic-gate  */
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate #define TIMEOUT(r, f, t)	timeout((r), (f), (t))
7677c478bd9Sstevel@tonic-gate #define UNTIMEOUT(r, f)		untimeout((r), (f))
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate #ifndef SOL2
7707c478bd9Sstevel@tonic-gate #define BCOPY(s, d, l)		memcpy(d, s, l)
7717c478bd9Sstevel@tonic-gate #define BZERO(s, n)		memset(s, 0, n)
7727c478bd9Sstevel@tonic-gate #else
7737c478bd9Sstevel@tonic-gate #include <strings.h>
7747c478bd9Sstevel@tonic-gate #define BCOPY			bcopy
7757c478bd9Sstevel@tonic-gate #define BZERO			bzero
7767c478bd9Sstevel@tonic-gate #endif
7777c478bd9Sstevel@tonic-gate 
7787c478bd9Sstevel@tonic-gate #define PRINTMSG(m, l)		{ info("Remote message: %0.*v", l, m); }
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate /*
7817c478bd9Sstevel@tonic-gate  * MAKEHEADER - Add Header fields to a packet.
7827c478bd9Sstevel@tonic-gate  */
7837c478bd9Sstevel@tonic-gate #define MAKEHEADER(p, t) { \
7847c478bd9Sstevel@tonic-gate     PUTCHAR(PPP_ALLSTATIONS, p); \
7857c478bd9Sstevel@tonic-gate     PUTCHAR(PPP_UI, p); \
7867c478bd9Sstevel@tonic-gate     PUTSHORT(t, p); }
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate /*
7897c478bd9Sstevel@tonic-gate  * Exit status values.
7907c478bd9Sstevel@tonic-gate  */
7917c478bd9Sstevel@tonic-gate #define EXIT_OK			0
7927c478bd9Sstevel@tonic-gate #define EXIT_FATAL_ERROR	1
7937c478bd9Sstevel@tonic-gate #define EXIT_OPTION_ERROR	2
7947c478bd9Sstevel@tonic-gate #define EXIT_NOT_ROOT		3
7957c478bd9Sstevel@tonic-gate #define EXIT_NO_KERNEL_SUPPORT	4
7967c478bd9Sstevel@tonic-gate #define EXIT_USER_REQUEST	5
7977c478bd9Sstevel@tonic-gate #define EXIT_LOCK_FAILED	6
7987c478bd9Sstevel@tonic-gate #define EXIT_OPEN_FAILED	7
7997c478bd9Sstevel@tonic-gate #define EXIT_CONNECT_FAILED	8
8007c478bd9Sstevel@tonic-gate #define EXIT_PTYCMD_FAILED	9
8017c478bd9Sstevel@tonic-gate #define EXIT_NEGOTIATION_FAILED	10
8027c478bd9Sstevel@tonic-gate #define EXIT_PEER_AUTH_FAILED	11
8037c478bd9Sstevel@tonic-gate #define EXIT_IDLE_TIMEOUT	12
8047c478bd9Sstevel@tonic-gate #define EXIT_CONNECT_TIME	13
8057c478bd9Sstevel@tonic-gate #define EXIT_CALLBACK		14
8067c478bd9Sstevel@tonic-gate #define EXIT_PEER_DEAD		15
8077c478bd9Sstevel@tonic-gate #define EXIT_HANGUP		16
8087c478bd9Sstevel@tonic-gate #define EXIT_LOOPBACK		17
8097c478bd9Sstevel@tonic-gate #define EXIT_INIT_FAILED	18
8107c478bd9Sstevel@tonic-gate #define EXIT_AUTH_TOPEER_FAILED	19
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate /*
8137c478bd9Sstevel@tonic-gate  * Character shunt constants.
8147c478bd9Sstevel@tonic-gate  */
8157c478bd9Sstevel@tonic-gate #define	MAXLEVELMINSIZE		100
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate /*
8187c478bd9Sstevel@tonic-gate  * Debug macros.  Slightly useful for finding bugs in pppd, not particularly
8197c478bd9Sstevel@tonic-gate  * useful for finding out why your connection isn't being established.
8207c478bd9Sstevel@tonic-gate  */
8217c478bd9Sstevel@tonic-gate #ifdef DEBUGALL
8227c478bd9Sstevel@tonic-gate #define DEBUGMAIN	1
8237c478bd9Sstevel@tonic-gate #define DEBUGSYS	1
8247c478bd9Sstevel@tonic-gate #define DEBUGLCP	1
8257c478bd9Sstevel@tonic-gate #define DEBUGIPCP	1
8267c478bd9Sstevel@tonic-gate #define DEBUGIPV6CP	1
8277c478bd9Sstevel@tonic-gate #define DEBUGCHAP	1
8287c478bd9Sstevel@tonic-gate #define DEBUGIPXCP	1
8297c478bd9Sstevel@tonic-gate #define LOG_PPP		LOG_LOCAL2	/* Log here when debugging all */
8307c478bd9Sstevel@tonic-gate #endif /* DEBUGALL */
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate #ifndef LOG_PPP			/* we use LOG_DAEMON for syslog by default */
8337c478bd9Sstevel@tonic-gate #define LOG_PPP LOG_DAEMON
8347c478bd9Sstevel@tonic-gate #endif /* LOG_PPP */
8357c478bd9Sstevel@tonic-gate 
8367c478bd9Sstevel@tonic-gate #ifdef DEBUGMAIN
8377c478bd9Sstevel@tonic-gate #define MAINDEBUG(x)	if (debug) dbglog x
8387c478bd9Sstevel@tonic-gate #else
8397c478bd9Sstevel@tonic-gate #define MAINDEBUG(x)	((void) 0)
8407c478bd9Sstevel@tonic-gate #endif /* DEBUGMAIN */
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate #ifdef DEBUGSYS
8437c478bd9Sstevel@tonic-gate #define SYSDEBUG(x)	if (debug) dbglog x
8447c478bd9Sstevel@tonic-gate #else
8457c478bd9Sstevel@tonic-gate #define SYSDEBUG(x)	((void) 0)
8467c478bd9Sstevel@tonic-gate #endif /* DEBUGSYS */
8477c478bd9Sstevel@tonic-gate 
8487c478bd9Sstevel@tonic-gate #ifdef DEBUGLCP
8497c478bd9Sstevel@tonic-gate #define LCPDEBUG(x)	if (debug) dbglog x
8507c478bd9Sstevel@tonic-gate #else
8517c478bd9Sstevel@tonic-gate #define LCPDEBUG(x)	((void) 0)
8527c478bd9Sstevel@tonic-gate #endif /* DEBUGLCP */
8537c478bd9Sstevel@tonic-gate 
8547c478bd9Sstevel@tonic-gate #ifdef DEBUGIPCP
8557c478bd9Sstevel@tonic-gate #define IPCPDEBUG(x)	if (debug) dbglog x
8567c478bd9Sstevel@tonic-gate #else
8577c478bd9Sstevel@tonic-gate #define IPCPDEBUG(x)	((void) 0)
8587c478bd9Sstevel@tonic-gate #endif /* DEBUGIPCP */
8597c478bd9Sstevel@tonic-gate 
8607c478bd9Sstevel@tonic-gate #ifdef DEBUGIPV6CP
8617c478bd9Sstevel@tonic-gate #define IPV6CPDEBUG(x)  if (debug) dbglog x
8627c478bd9Sstevel@tonic-gate #else
8637c478bd9Sstevel@tonic-gate #define IPV6CPDEBUG(x)	((void) 0)
8647c478bd9Sstevel@tonic-gate #endif /* DEBUGIPV6CP */
8657c478bd9Sstevel@tonic-gate 
8667c478bd9Sstevel@tonic-gate #ifdef DEBUGCHAP
8677c478bd9Sstevel@tonic-gate #define CHAPDEBUG(x)	if (debug) dbglog x
8687c478bd9Sstevel@tonic-gate #else
8697c478bd9Sstevel@tonic-gate #define CHAPDEBUG(x)	((void) 0)
8707c478bd9Sstevel@tonic-gate #endif /* DEBUGCHAP */
8717c478bd9Sstevel@tonic-gate 
8727c478bd9Sstevel@tonic-gate #ifdef DEBUGIPXCP
8737c478bd9Sstevel@tonic-gate #define IPXCPDEBUG(x)	if (debug) dbglog x
8747c478bd9Sstevel@tonic-gate #else
8757c478bd9Sstevel@tonic-gate #define IPXCPDEBUG(x)	((void) 0)
8767c478bd9Sstevel@tonic-gate #endif /* DEBUGIPXCP */
8777c478bd9Sstevel@tonic-gate 
8787c478bd9Sstevel@tonic-gate #ifndef SIGTYPE
8797c478bd9Sstevel@tonic-gate #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
8807c478bd9Sstevel@tonic-gate #define SIGTYPE void
8817c478bd9Sstevel@tonic-gate #else
8827c478bd9Sstevel@tonic-gate #define SIGTYPE int
8837c478bd9Sstevel@tonic-gate #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
8847c478bd9Sstevel@tonic-gate #endif /* SIGTYPE */
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate #ifndef MIN
8877c478bd9Sstevel@tonic-gate #define MIN(a, b)	((a) < (b)? (a): (b))
8887c478bd9Sstevel@tonic-gate #endif /* MIN */
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate #ifndef MAX
8917c478bd9Sstevel@tonic-gate #define MAX(a, b)	((a) > (b)? (a): (b))
8927c478bd9Sstevel@tonic-gate #endif /* MAX */
8937c478bd9Sstevel@tonic-gate 
8947c478bd9Sstevel@tonic-gate #ifndef Dim
8957c478bd9Sstevel@tonic-gate #define Dim(x)		(sizeof (x) / sizeof (*(x)))
8967c478bd9Sstevel@tonic-gate #endif /* Dim */
8977c478bd9Sstevel@tonic-gate 
8987c478bd9Sstevel@tonic-gate #ifndef NBBY
8997c478bd9Sstevel@tonic-gate #define NBBY 8
9007c478bd9Sstevel@tonic-gate #endif /* NBBY */
9017c478bd9Sstevel@tonic-gate 
9027c478bd9Sstevel@tonic-gate #ifndef isset
9037c478bd9Sstevel@tonic-gate #define isset(arr, val)	(((u_char *)(arr))[(val)/NBBY] & (1<<((val)%NBBY)))
9047c478bd9Sstevel@tonic-gate #endif /* isset */
9057c478bd9Sstevel@tonic-gate 
9067c478bd9Sstevel@tonic-gate #ifndef setbit
9077c478bd9Sstevel@tonic-gate #define setbit(arr, val) (((u_char *)(arr))[(val)/NBBY] |= (1<<((val)%NBBY)))
9087c478bd9Sstevel@tonic-gate #endif /* setbit */
9097c478bd9Sstevel@tonic-gate 
9107c478bd9Sstevel@tonic-gate #define IP_HDRLEN	20	/* bytes */
9117c478bd9Sstevel@tonic-gate #define IP_OFFMASK	0x1fff
9127c478bd9Sstevel@tonic-gate #define TCP_HDRLEN	20
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate /*
9157c478bd9Sstevel@tonic-gate  * We use these macros because the IP header may be at an odd address,
9167c478bd9Sstevel@tonic-gate  * and some compilers might use word loads to get th_off or ip_hl.
9177c478bd9Sstevel@tonic-gate  */
9187c478bd9Sstevel@tonic-gate 
9197c478bd9Sstevel@tonic-gate #define net_short(x)	(((x)[0] << 8) + (x)[1])
920f53eecf5SJames Carlson #define	native_long(x)	(htonl((net_short(x) << 16) + \
921f53eecf5SJames Carlson 			net_short((unsigned char *)(x) + 2)))
9227c478bd9Sstevel@tonic-gate #define get_ipv(x)	((((unsigned char *)(x))[0] >> 4) & 0xF)
9237c478bd9Sstevel@tonic-gate #define get_iphl(x)	(((unsigned char *)(x))[0] & 0xF)
9247c478bd9Sstevel@tonic-gate #define	get_iplen(x)	net_short((unsigned char *)(x) + 2)
9257c478bd9Sstevel@tonic-gate #define get_ipoff(x)	net_short((unsigned char *)(x) + 6)
9267c478bd9Sstevel@tonic-gate #define get_ipproto(x)	(((unsigned char *)(x))[9])
927f53eecf5SJames Carlson #define	get_ipsrc(x)	native_long((unsigned char *)(x) + 12)
928f53eecf5SJames Carlson #define	get_ipdst(x)	native_long((unsigned char *)(x) + 16)
929f53eecf5SJames Carlson #define get_ip6nh(x)	(((unsigned char *)(x))[6])
930f53eecf5SJames Carlson #define get_ip6src(x)	(((unsigned char *)(x))+8)
931f53eecf5SJames Carlson #define get_ip6dst(x)	(((unsigned char *)(x))+24)
9327c478bd9Sstevel@tonic-gate /* Ports for both UDP and TCP are first */
9337c478bd9Sstevel@tonic-gate #define	get_sport(x)	net_short(x)
9347c478bd9Sstevel@tonic-gate #define	get_dport(x)	net_short((unsigned char *)(x) + 2)
9357c478bd9Sstevel@tonic-gate #define get_tcpoff(x)	(((unsigned char *)(x))[12] >> 4)
9367c478bd9Sstevel@tonic-gate #define get_tcpflags(x)	(((unsigned char *)(x))[13])
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate /* Check for RFC 1918 (local use) addresses */
9397c478bd9Sstevel@tonic-gate #define LOCAL_IP_ADDR(addr)						  \
9407c478bd9Sstevel@tonic-gate 	(((addr) & 0xff000000) == 0x0a000000 ||		/* 10.x.x.x */	  \
9417c478bd9Sstevel@tonic-gate 	 ((addr) & 0xfff00000) == 0xac100000 ||		/* 172.16.x.x */  \
9427c478bd9Sstevel@tonic-gate 	 ((addr) & 0xffff0000) == 0xc0a80000)		/* 192.168.x.x */
9437c478bd9Sstevel@tonic-gate 
9447c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
9457c478bd9Sstevel@tonic-gate }
9467c478bd9Sstevel@tonic-gate #endif
9477c478bd9Sstevel@tonic-gate 
9487c478bd9Sstevel@tonic-gate #endif /* __PPPD_H__ */
949