1 /*	$OpenBSD: pppd.h,v 1.15 2003/04/25 23:24:32 deraadt Exp $	*/
2 
3 /*
4  * pppd.h - PPP daemon global declarations.
5  *
6  * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. The name "Carnegie Mellon University" must not be used to
21  *    endorse or promote products derived from this software without
22  *    prior written permission. For permission or any legal
23  *    details, please contact
24  *      Office of Technology Transfer
25  *      Carnegie Mellon University
26  *      5000 Forbes Avenue
27  *      Pittsburgh, PA  15213-3890
28  *      (412) 268-4387, fax: (412) 268-7395
29  *      tech-transfer@andrew.cmu.edu
30  *
31  * 4. Redistributions of any form whatsoever must retain the following
32  *    acknowledgment:
33  *    "This product includes software developed by Computing Services
34  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
35  *
36  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
37  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
38  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
39  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
41  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
42  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43  */
44 
45 /*
46  * TODO:
47  */
48 
49 #ifndef __PPPD_H__
50 #define __PPPD_H__
51 
52 #include <stdio.h>		/* for FILE */
53 #include <stdarg.h>
54 #include <sys/param.h>		/* for MAXPATHLEN and BSD4_4, if defined */
55 #include <sys/types.h>		/* for u_int32_t, if defined */
56 #include <sys/time.h>		/* for struct timeval */
57 #include <net/ppp_defs.h>
58 
59 /*
60  * Limits.
61  */
62 
63 #define NUM_PPP		1	/* One PPP interface supported (per process) */
64 #define MAXWORDLEN	1024	/* max length of word in file (incl null) */
65 #define MAXARGS		1	/* max # args to a command */
66 #define MAXNAMELEN	256	/* max length of hostname or name for auth */
67 #define MAXSECRETLEN	256	/* max length of password or secret */
68 
69 /*
70  * Global variables.
71  */
72 
73 extern int	hungup;		/* Physical layer has disconnected */
74 extern int	ifunit;		/* Interface unit number */
75 extern char	ifname[];	/* Interface name */
76 extern int	ttyfd;		/* Serial device file descriptor */
77 extern char	hostname[];	/* Our hostname */
78 extern u_char	outpacket_buf[]; /* Buffer for outgoing packets */
79 extern int	phase;		/* Current state of link - see values below */
80 extern int	baud_rate;	/* Current link speed in bits/sec */
81 extern char	*progname;	/* Name of this program */
82 extern int	redirect_stderr;/* Connector's stderr should go to file */
83 extern char	peer_authname[];/* Authenticated name of peer */
84 extern int	privileged;	/* We were run by real-uid root */
85 extern int	need_holdoff;	/* Need holdoff period after link terminates */
86 extern char	**script_env;	/* Environment variables for scripts */
87 extern int	detached;	/* Have detached from controlling tty */
88 
89 /*
90  * Variables set by command-line options.
91  */
92 
93 extern int	debug;		/* Debug flag */
94 extern int	kdebugflag;	/* Tell kernel to print debug messages */
95 extern int	default_device;	/* Using /dev/tty or equivalent */
96 extern char	devnam[];	/* Device name */
97 extern int	crtscts;	/* Use hardware flow control */
98 extern int	modem;		/* Use modem control lines */
99 extern int	modem_chat;	/* Watch carrier detect in chat script */
100 extern int	inspeed;	/* Input/Output speed requested */
101 extern u_int32_t netmask;	/* IP netmask to set on interface */
102 extern int	lockflag;	/* Create lock file to lock the serial dev */
103 extern int	nodetach;	/* Don't detach from controlling tty */
104 extern char	*connector;	/* Script to establish physical link */
105 extern char	*disconnector;	/* Script to disestablish physical link */
106 extern char	*welcomer;	/* Script to welcome client after connection */
107 extern int	maxconnect;	/* Maximum connect time (seconds) */
108 extern char	user[];		/* Our name for authenticating ourselves */
109 extern char	passwd[];	/* Password for PAP */
110 extern int	auth_required;	/* Peer is required to authenticate */
111 extern int	proxyarp;	/* Set up proxy ARP entry for peer */
112 extern int	persist;	/* Reopen link after it goes down */
113 extern int	uselogin;	/* Use /etc/passwd for checking PAP */
114 extern int	lcp_echo_interval; /* Interval between LCP echo-requests */
115 extern int	lcp_echo_fails;	/* Tolerance to unanswered echo-requests */
116 extern char	our_name[];	/* Our name for authentication purposes */
117 extern char	remote_name[];	/* Peer's name for authentication */
118 extern int	explicit_remote;/* remote_name specified with remotename opt */
119 extern int	usehostname;	/* Use hostname for our_name */
120 extern int	disable_defaultip; /* Don't use hostname for default IP adrs */
121 extern int	demand;		/* Do dial-on-demand */
122 extern char	*ipparam;	/* Extra parameter for ip up/down scripts */
123 extern int	cryptpap;	/* Others' PAP passwords are encrypted */
124 extern int	idle_time_limit;/* Shut down link if idle for this long */
125 extern int	holdoff;	/* Dead time before restarting */
126 extern int	refuse_pap;	/* Don't wanna auth. ourselves with PAP */
127 extern int	refuse_chap;	/* Don't wanna auth. ourselves with CHAP */
128 #ifdef PPP_FILTER
129 extern struct	bpf_program pass_filter;   /* Filter for pkts to pass */
130 extern struct	bpf_program active_filter; /* Filter for link-active pkts */
131 #endif
132 
133 #ifdef MSLANMAN
134 extern int	ms_lanman;	/* Nonzero if use LanMan password instead of NT */
135 				/* Has meaning only with MS-CHAP challenges */
136 #endif
137 
138 /*
139  * Values for phase.
140  */
141 #define PHASE_DEAD		0
142 #define PHASE_INITIALIZE	1
143 #define PHASE_DORMANT		2
144 #define PHASE_ESTABLISH		3
145 #define PHASE_AUTHENTICATE	4
146 #define PHASE_CALLBACK		5
147 #define PHASE_NETWORK		6
148 #define PHASE_TERMINATE		7
149 #define PHASE_HOLDOFF		8
150 
151 /*
152  * The following struct gives the addresses of procedures to call
153  * for a particular protocol.
154  */
155 struct protent {
156     u_short protocol;		/* PPP protocol number */
157     /* Initialization procedure */
158     void (*init)(int unit);
159     /* Process a received packet */
160     void (*input)(int unit, u_char *pkt, int len);
161     /* Process a received protocol-reject */
162     void (*protrej)(int unit);
163     /* Lower layer has come up */
164     void (*lowerup)(int unit);
165     /* Lower layer has gone down */
166     void (*lowerdown)(int unit);
167     /* Open the protocol */
168     void (*open)(int unit);
169     /* Close the protocol */
170     void (*close)(int unit, char *reason);
171     /* Print a packet in readable form */
172     int  (*printpkt)(u_char *pkt, int len,
173 	void (*printer)(void *, char *, ...), void *arg);
174     /* Process a received data packet */
175     void (*datainput)(int unit, u_char *pkt, int len);
176     int  enabled_flag;		/* 0 iff protocol is disabled */
177     char *name;			/* Text name of protocol */
178     /* Check requested options, assign defaults */
179     void (*check_options)(void);
180     /* Configure interface for demand-dial */
181     int  (*demand_conf)(int unit);
182     /* Say whether to bring up link for this pkt */
183     int  (*active_pkt)(u_char *pkt, int len);
184 };
185 
186 /* Table of pointers to supported protocols */
187 extern struct protent *protocols[];
188 
189 /*
190  * Prototypes.
191  */
192 
193 /* Procedures exported from main.c. */
194 void detach(void);		/* Detach from controlling tty */
195 void die(int);			/* Cleanup and exit */
196 void quit(void);		/* like die(1) */
197 void novm(char *);		/* Say we ran out of memory, and die */
198 void timeout(void (*func)(void *), void *arg, int t);
199 				/* Call func(arg) after t seconds */
200 void untimeout(void (*func)(void *), void *arg);
201 				/* Cancel call to func(arg) */
202 int run_program(char *prog, char **args, int must_exist);
203 				/* Run program prog with args in child */
204 void demuxprotrej(int, int);
205 				/* Demultiplex a Protocol-Reject */
206 void format_packet(u_char *, int, void (*) (void *, char *, ...), void *);
207 				/* Format a packet in human-readable form */
208 void log_packet(u_char *, int, char *, int);
209 				/* Format a packet and log it with syslog */
210 void print_string(char *, int,  void (*) (void *, char *, ...), void *);
211 				/* Format a string for output */
212 int fmtmsg(char *, int, char *, ...);		/* snprintf++ */
213 int vfmtmsg(char *, int, char *, va_list);	/* vsnprintf++ */
214 void script_setenv(char *, char *);	/* set script env var */
215 void script_unsetenv(char *);		/* unset script env var */
216 
217 /* Procedures exported from auth.c */
218 void link_required(int);	/* we are starting to use the link */
219 void link_terminated(int);	/* we are finished with the link */
220 void link_down(int);		/* the LCP layer has left the Opened state */
221 void link_established(int);	/* the link is up; authenticate now */
222 void np_up(int, int);		/* a network protocol has come up */
223 void np_down(int, int);		/* a network protocol has gone down */
224 void np_finished(int, int);	/* a network protocol no longer needs link */
225 void auth_peer_fail(int, int);
226 				/* peer failed to authenticate itself */
227 void auth_peer_success(int, int, char *, int);
228 				/* peer successfully authenticated itself */
229 void auth_withpeer_fail(int, int);
230 				/* we failed to authenticate ourselves */
231 void auth_withpeer_success(int, int);
232 				/* we successfully authenticated ourselves */
233 void auth_check_options(void);
234 				/* check authentication options supplied */
235 void auth_reset(int);		/* check what secrets we have */
236 int  check_passwd(int, char *, int, char *, int, char **, int *);
237 				/* Check peer-supplied username/password */
238 int  get_secret(int, char *, char *, char *, int *, int);
239 				/* get "secret" for chap */
240 int  auth_ip_addr(int, u_int32_t);
241 				/* check if IP address is authorized */
242 int  bad_ip_adrs(u_int32_t);
243 				/* check if IP address is unreasonable */
244 void check_access(FILE *, char *);
245 				/* check permissions on secrets file */
246 
247 /* Procedures exported from demand.c */
248 void demand_conf(void);		/* config interface(s) for demand-dial */
249 void demand_block(void);	/* set all NPs to queue up packets */
250 void demand_drop(void); 	/* set all NPs to drop packets */
251 void demand_unblock(void);	/* set all NPs to pass packets */
252 void demand_discard(void);	/* set all NPs to discard packets */
253 void demand_rexmit(int);	/* retransmit saved frames for an NP */
254 int  loop_chars(unsigned char *, int); /* process chars from loopback */
255 int  loop_frame(unsigned char *, int); /* process frame from loopback */
256 
257 /* Procedures exported from sys-*.c */
258 void sys_init(void);		/* Do system-dependent initialization */
259 void sys_cleanup(void);		/* Restore system state before exiting */
260 void sys_check_options(void);	/* Check options specified */
261 void sys_close(void);		/* Clean up in a child before execing */
262 int  ppp_available(void);	/* Test whether ppp kernel support exists */
263 void open_ppp_loopback(void);	/* Open loopback for demand-dialling */
264 void establish_ppp(int);	/* Turn serial port into a ppp interface */
265 void restore_loop(void);	/* Transfer ppp unit back to loopback */
266 void disestablish_ppp(int);	/* Restore port to normal operation */
267 void clean_check(void);		/* Check if line was 8-bit clean */
268 void set_up_tty(int, int);	/* Set up port's speed, parameters, etc. */
269 void restore_tty(int);		/* Restore port's original parameters */
270 void setdtr(int, int);		/* Raise or lower port's DTR line */
271 void output(int, u_char *, int); /* Output a PPP packet */
272 void wait_input(struct timeval *);
273 				/* Wait for input, with timeout */
274 void wait_loop_output(struct timeval *);
275 				/* Wait for pkt from loopback, with timeout */
276 void wait_time(struct timeval *); /* Wait for given length of time */
277 int  read_packet(u_char *);	/* Read PPP packet */
278 int  get_loop_output(void);	/* Read pkts from loopback */
279 void ppp_send_config(int, int, u_int32_t, int, int);
280 				/* Configure i/f transmit parameters */
281 void ppp_set_xaccm(int, ext_accm);
282 				/* Set extended transmit ACCM */
283 void ppp_recv_config(int, int, u_int32_t, int, int);
284 				/* Configure i/f receive parameters */
285 int  ccp_test(int, u_char *, int, int);
286 				/* Test support for compression scheme */
287 void ccp_flags_set(int, int, int);
288 				/* Set kernel CCP state */
289 int  ccp_fatal_error(int);	/* Test for fatal decomp error in kernel */
290 int  get_idle_time(int, struct ppp_idle *);
291 				/* Find out how long link has been idle */
292 int  sifvjcomp(int, int, int, int);
293 				/* Configure VJ TCP header compression */
294 int  sifup(int);		/* Configure i/f up (for IP) */
295 int  sifnpmode(int u, int proto, enum NPmode mode);
296 				/* Set mode for handling packets for proto */
297 int  sifdown(int);		/* Configure i/f down (for IP) */
298 int  sifaddr(int, u_int32_t, u_int32_t, u_int32_t);
299 				/* Configure IP addresses for i/f */
300 int  cifaddr(int, u_int32_t, u_int32_t);
301 				/* Reset i/f IP addresses */
302 int  sifdefaultroute(int, u_int32_t, u_int32_t);
303 				/* Create default route through i/f */
304 int  cifdefaultroute(int, u_int32_t, u_int32_t);
305 				/* Delete default route through i/f */
306 int  sifproxyarp(int, u_int32_t);
307 				/* Add proxy ARP entry for peer */
308 int  cifproxyarp(int, u_int32_t);
309 				/* Delete proxy ARP entry for peer */
310 u_int32_t GetMask(u_int32_t);	/* Get appropriate netmask for address */
311 int  lock(char *);		/* Create lock file for device */
312 void unlock(void);		/* Delete previously-created lock file */
313 int  daemon(int, int);		/* Detach us from terminal session */
314 void logwtmp(const char *, const char *, const char *);
315 				/* Write entry to wtmp file */
316 int  get_host_seed(void);	/* Get host-dependent random number seed */
317 #ifdef PPP_FILTER
318 int  set_filters(struct bpf_program *pass, struct bpf_program *active);
319 				/* Set filter programs in kernel */
320 #endif
321 
322 /* Procedures exported from options.c */
323 int  parse_args(int argc, char **argv);
324 				/* Parse options from arguments given */
325 void usage(void);		/* Print a usage message */
326 int  options_from_file(char *filename, int must_exist, int check_prot,
327 		       int privileged);
328 				/* Parse options from an options file */
329 int  options_from_user(void);	/* Parse options from user's .ppprc */
330 int  options_for_tty(void);	/* Parse options from /etc/ppp/options.tty */
331 void scan_args(int argc, char **argv);
332 				/* Look for tty name in command-line args */
333 int  getword(FILE *f, char *word, int *newlinep, char *filename);
334 				/* Read a word from a file */
335 void option_error(char *fmt, ...);
336 				/* Print an error message about an option */
337 
338 /*
339  * This structure is used to store information about certain
340  * options, such as where the option value came from (/etc/ppp/options,
341  * command line, etc.) and whether it came from a privileged source.
342  */
343 
344 struct option_info {
345     int	    priv;		/* was value set by sysadmin? */
346     char    *source;		/* where option came from */
347 };
348 
349 extern struct option_info auth_req_info;
350 extern struct option_info connector_info;
351 extern struct option_info disconnector_info;
352 extern struct option_info welcomer_info;
353 extern struct option_info devnam_info;
354 
355 /*
356  * Inline versions of get/put char/short/long.
357  * Pointer is advanced; we assume that both arguments
358  * are lvalues and will already be in registers.
359  * cp MUST be u_char *.
360  */
361 #define GETCHAR(c, cp) { \
362 	(c) = *(cp)++; \
363 }
364 #define PUTCHAR(c, cp) { \
365 	*(cp)++ = (u_char) (c); \
366 }
367 
368 
369 #define GETSHORT(s, cp) { \
370 	(s) = *(cp)++ << 8; \
371 	(s) |= *(cp)++; \
372 }
373 #define PUTSHORT(s, cp) { \
374 	*(cp)++ = (u_char) ((s) >> 8); \
375 	*(cp)++ = (u_char) (s); \
376 }
377 
378 #define GETLONG(l, cp) { \
379 	(l) = *(cp)++ << 8; \
380 	(l) |= *(cp)++; (l) <<= 8; \
381 	(l) |= *(cp)++; (l) <<= 8; \
382 	(l) |= *(cp)++; \
383 }
384 #define PUTLONG(l, cp) { \
385 	*(cp)++ = (u_char) ((l) >> 24); \
386 	*(cp)++ = (u_char) ((l) >> 16); \
387 	*(cp)++ = (u_char) ((l) >> 8); \
388 	*(cp)++ = (u_char) (l); \
389 }
390 
391 #define INCPTR(n, cp)	((cp) += (n))
392 #define DECPTR(n, cp)	((cp) -= (n))
393 
394 #undef  FALSE
395 #define FALSE	0
396 #undef  TRUE
397 #define TRUE	1
398 
399 /*
400  * System dependent definitions for user-level 4.3BSD UNIX implementation.
401  */
402 
403 #define DEMUXPROTREJ(u, p)	demuxprotrej(u, p)
404 
405 #define TIMEOUT(r, f, t)	timeout((r), (f), (t))
406 #define UNTIMEOUT(r, f)		untimeout((r), (f))
407 
408 #define BCOPY(s, d, l)		memcpy(d, s, l)
409 #define BZERO(s, n)		memset(s, 0, n)
410 #define EXIT(u)			quit()
411 
412 #define PRINTMSG(m, l)	{ m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); }
413 
414 /*
415  * MAKEHEADER - Add Header fields to a packet.
416  */
417 #define MAKEHEADER(p, t) { \
418     PUTCHAR(PPP_ALLSTATIONS, p); \
419     PUTCHAR(PPP_UI, p); \
420     PUTSHORT(t, p); }
421 
422 
423 #ifdef DEBUGALL
424 #define DEBUGMAIN	1
425 #define DEBUGFSM	1
426 #define DEBUGLCP	1
427 #define DEBUGIPCP	1
428 #define DEBUGUPAP	1
429 #define DEBUGCHAP	1
430 #endif
431 
432 #ifndef LOG_PPP			/* we use LOG_LOCAL2 for syslog by default */
433 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
434   || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
435   || defined(DEBUGCHAP) || defined(DEBUG)
436 #define LOG_PPP LOG_LOCAL2
437 #else
438 #define LOG_PPP LOG_DAEMON
439 #endif
440 #endif /* LOG_PPP */
441 
442 #ifdef DEBUGMAIN
443 #define MAINDEBUG(x)	if (debug) syslog x
444 #else
445 #define MAINDEBUG(x)
446 #endif
447 
448 #ifdef DEBUGSYS
449 #define SYSDEBUG(x)	if (debug) syslog x
450 #else
451 #define SYSDEBUG(x)
452 #endif
453 
454 #ifdef DEBUGFSM
455 #define FSMDEBUG(x)	if (debug) syslog x
456 #else
457 #define FSMDEBUG(x)
458 #endif
459 
460 #ifdef DEBUGLCP
461 #define LCPDEBUG(x)	if (debug) syslog x
462 #else
463 #define LCPDEBUG(x)
464 #endif
465 
466 #ifdef DEBUGIPCP
467 #define IPCPDEBUG(x)	if (debug) syslog x
468 #else
469 #define IPCPDEBUG(x)
470 #endif
471 
472 #ifdef DEBUGUPAP
473 #define UPAPDEBUG(x)	if (debug) syslog x
474 #else
475 #define UPAPDEBUG(x)
476 #endif
477 
478 #ifdef DEBUGCHAP
479 #define CHAPDEBUG(x)	if (debug) syslog x
480 #else
481 #define CHAPDEBUG(x)
482 #endif
483 
484 #ifdef DEBUGIPXCP
485 #define IPXCPDEBUG(x)	if (debug) syslog x
486 #else
487 #define IPXCPDEBUG(x)
488 #endif
489 
490 #ifndef SIGTYPE
491 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
492 #define SIGTYPE void
493 #else
494 #define SIGTYPE int
495 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
496 #endif /* SIGTYPE */
497 
498 #ifndef MIN
499 #define MIN(a, b)	((a) < (b)? (a): (b))
500 #endif
501 #ifndef MAX
502 #define MAX(a, b)	((a) > (b)? (a): (b))
503 #endif
504 
505 #endif /* __PPP_H__ */
506