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