2 * pppd.h - PPP daemon global declarations.
4 * Copyright (c) 1989 Carnegie Mellon University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by Carnegie Mellon University. The name of the
13 * University may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 * $Id: pppd.h,v 1.33 1999/03/19 04:23:45 paulus Exp $
29 #include <stdio.h> /* for FILE */
30 #include <limits.h> /* for NGROUPS_MAX */
31 #include <sys/param.h> /* for MAXPATHLEN and BSD4_4, if defined */
32 #include <sys/types.h> /* for u_int32_t, if defined */
33 #include <sys/time.h> /* for struct timeval */
34 #include <net/ppp_defs.h>
41 #define __V(x) (va_alist) va_dcl
49 #define NUM_PPP 1 /* One PPP interface supported (per process) */
50 #define MAXWORDLEN 1024 /* max length of word in file (incl null) */
51 #define MAXARGS 1 /* max # args to a command */
52 #define MAXNAMELEN 256 /* max length of hostname or name for auth */
53 #define MAXSECRETLEN 256 /* max length of password or secret */
56 * Option descriptor structure.
59 typedef unsigned char bool;
71 char *name; /* name of the option */
81 /* Values for flags */
82 #define OPT_VALUE 0xff /* mask for presupplied value */
83 #define OPT_HEX 0x100 /* int option is in hex */
84 #define OPT_NOARG 0x200 /* option doesn't take argument */
85 #define OPT_OR 0x400 /* OR in argument to value */
86 #define OPT_INC 0x800 /* increment value */
87 #define OPT_PRIV 0x1000 /* privileged option */
88 #define OPT_STATIC 0x2000 /* string option goes into static array */
89 #define OPT_LLIMIT 0x4000 /* check value against lower limit */
90 #define OPT_ULIMIT 0x8000 /* check value against upper limit */
91 #define OPT_LIMITS (OPT_LLIMIT|OPT_ULIMIT)
92 #define OPT_ZEROOK 0x10000 /* 0 value is OK even if not within limits */
93 #define OPT_NOINCR 0x20000 /* value mustn't be increased */
94 #define OPT_ZEROINF 0x40000 /* with OPT_NOINCR, 0 == infinity */
95 #define OPT_A2INFO 0x100000 /* addr2 -> option_info to update */
96 #define OPT_A2COPY 0x200000 /* addr2 -> second location to rcv value */
97 #define OPT_ENABLE 0x400000 /* use *addr2 as enable for option */
98 #define OPT_PRIVFIX 0x800000 /* can't be overridden if noauth */
100 #define OPT_VAL(x) ((x) & OPT_VALUE)
103 #define GIDSET_TYPE gid_t
106 /* Structure representing a list of permitted IP addresses. */
107 struct permitted_ip {
108 int permit; /* 1 = permit, 0 = forbid */
109 u_int32_t base; /* match if (addr & mask) == base */
110 u_int32_t mask; /* base and mask are in network byte order */
117 extern int hungup; /* Physical layer has disconnected */
118 extern int ifunit; /* Interface unit number */
119 extern char ifname[]; /* Interface name */
120 extern int ttyfd; /* Serial device file descriptor */
121 extern char hostname[]; /* Our hostname */
122 extern u_char outpacket_buf[]; /* Buffer for outgoing packets */
123 extern int phase; /* Current state of link - see values below */
124 extern int baud_rate; /* Current link speed in bits/sec */
125 extern char *progname; /* Name of this program */
126 extern int redirect_stderr;/* Connector's stderr should go to file */
127 extern char peer_authname[];/* Authenticated name of peer */
128 extern int privileged; /* We were run by real-uid root */
129 extern int need_holdoff; /* Need holdoff period after link terminates */
130 extern char **script_env; /* Environment variables for scripts */
131 extern int detached; /* Have detached from controlling tty */
132 extern GIDSET_TYPE groups[NGROUPS_MAX]; /* groups the user is in */
133 extern int ngroups; /* How many groups valid in groups */
134 extern struct ppp_stats link_stats; /* byte/packet counts etc. for link */
135 extern int link_stats_valid; /* set if link_stats is valid */
138 * Variables set by command-line options.
141 extern int debug; /* Debug flag */
142 extern int kdebugflag; /* Tell kernel to print debug messages */
143 extern int default_device; /* Using /dev/tty or equivalent */
144 extern char devnam[MAXPATHLEN]; /* Device name */
145 extern int crtscts; /* Use hardware flow control */
146 extern bool modem; /* Use modem control lines */
147 extern int inspeed; /* Input/Output speed requested */
148 extern u_int32_t netmask; /* IP netmask to set on interface */
149 extern bool lockflag; /* Create lock file to lock the serial dev */
150 extern bool nodetach; /* Don't detach from controlling tty */
151 extern bool updetach; /* Detach from controlling tty when link up */
152 extern char *connector; /* Script to establish physical link */
153 extern char *disconnector; /* Script to disestablish physical link */
154 extern char *welcomer; /* Script to welcome client after connection */
155 extern int maxconnect; /* Maximum connect time (seconds) */
156 extern char user[MAXNAMELEN];/* Our name for authenticating ourselves */
157 extern char passwd[MAXSECRETLEN]; /* Password for PAP */
158 extern bool auth_required; /* Peer is required to authenticate */
159 extern bool persist; /* Reopen link after it goes down */
160 extern bool uselogin; /* Use /etc/passwd for checking PAP */
161 extern char our_name[MAXNAMELEN];/* Our name for authentication purposes */
162 extern char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
163 extern bool explicit_remote;/* remote_name specified with remotename opt */
164 extern bool demand; /* Do dial-on-demand */
165 extern char *ipparam; /* Extra parameter for ip up/down scripts */
166 extern bool cryptpap; /* Others' PAP passwords are encrypted */
167 extern int idle_time_limit;/* Shut down link if idle for this long */
168 extern int holdoff; /* Dead time before restarting */
171 extern struct bpf_program pass_filter; /* Filter for pkts to pass */
172 extern struct bpf_program active_filter; /* Filter for link-active pkts */
175 char *current_option; /* the name of the option being parsed */
176 int privileged_option; /* set iff the current option came from root */
177 char *option_source; /* string saying where the option came from */
180 extern bool ms_lanman; /* Use LanMan password instead of NT */
181 /* Has meaning only with MS-CHAP challenges */
188 #define PHASE_INITIALIZE 1
189 #define PHASE_DORMANT 2
190 #define PHASE_ESTABLISH 3
191 #define PHASE_AUTHENTICATE 4
192 #define PHASE_CALLBACK 5
193 #define PHASE_NETWORK 6
194 #define PHASE_TERMINATE 7
195 #define PHASE_HOLDOFF 8
198 * The following struct gives the addresses of procedures to call
199 * for a particular protocol.
202 u_short protocol; /* PPP protocol number */
203 /* Initialization procedure */
204 void (*init) __P((int unit));
205 /* Process a received packet */
206 void (*input) __P((int unit, u_char *pkt, int len));
207 /* Process a received protocol-reject */
208 void (*protrej) __P((int unit));
209 /* Lower layer has come up */
210 void (*lowerup) __P((int unit));
211 /* Lower layer has gone down */
212 void (*lowerdown) __P((int unit));
213 /* Open the protocol */
214 void (*open) __P((int unit));
215 /* Close the protocol */
216 void (*close) __P((int unit, char *reason));
217 /* Print a packet in readable form */
218 int (*printpkt) __P((u_char *pkt, int len,
219 void (*printer) __P((void *, char *, ...)),
221 /* Process a received data packet */
222 void (*datainput) __P((int unit, u_char *pkt, int len));
223 bool enabled_flag; /* 0 iff protocol is disabled */
224 char *name; /* Text name of protocol */
225 char *data_name; /* Text name of corresponding data protocol */
226 option_t *options; /* List of command-line options */
227 /* Check requested options, assign defaults */
228 void (*check_options) __P((void));
229 /* Configure interface for demand-dial */
230 int (*demand_conf) __P((int unit));
231 /* Say whether to bring up link for this pkt */
232 int (*active_pkt) __P((u_char *pkt, int len));
235 /* Table of pointers to supported protocols */
236 extern struct protent *protocols[];
242 /* Procedures exported from main.c. */
243 void detach __P((void)); /* Detach from controlling tty */
244 void die __P((int)); /* Cleanup and exit */
245 void quit __P((void)); /* like die(1) */
246 void novm __P((char *)); /* Say we ran out of memory, and die */
247 void timeout __P((void (*func)(void *), void *arg, int t));
248 /* Call func(arg) after t seconds */
249 void untimeout __P((void (*func)(void *), void *arg));
250 /* Cancel call to func(arg) */
251 pid_t run_program __P((char *prog, char **args, int must_exist,
252 void (*done)(void *), void *arg));
253 /* Run program prog with args in child */
254 void demuxprotrej __P((int, int));
255 /* Demultiplex a Protocol-Reject */
256 void log_packet __P((u_char *, int, char *, int));
257 /* Format a packet and log it with syslog */
258 void print_string __P((char *, int, void (*) (void *, char *, ...),
259 void *)); /* Format a string for output */
260 int slprintf __P((char *, int, char *, ...)); /* sprintf++ */
261 int vslprintf __P((char *, int, char *, va_list)); /* vsprintf++ */
262 void script_setenv __P((char *, char *)); /* set script env var */
263 void script_unsetenv __P((char *)); /* unset script env var */
264 size_t strlcpy __P((char *, const char *, size_t)); /* safe strcpy */
265 size_t strlcat __P((char *, const char *, size_t)); /* safe strncpy */
266 void dbglog __P((char *, ...)); /* log a debug message */
267 void info __P((char *, ...)); /* log an informational message */
268 void notice __P((char *, ...)); /* log a notice-level message */
269 void warn __P((char *, ...)); /* log a warning message */
270 void error __P((char *, ...)); /* log an error message */
271 void fatal __P((char *, ...)); /* log an error message and die(1) */
273 /* Procedures exported from auth.c */
274 void link_required __P((int)); /* we are starting to use the link */
275 void link_terminated __P((int)); /* we are finished with the link */
276 void link_down __P((int)); /* the LCP layer has left the Opened state */
277 void link_established __P((int)); /* the link is up; authenticate now */
278 void np_up __P((int, int)); /* a network protocol has come up */
279 void np_down __P((int, int)); /* a network protocol has gone down */
280 void np_finished __P((int, int)); /* a network protocol no longer needs link */
281 void auth_peer_fail __P((int, int));
282 /* peer failed to authenticate itself */
283 void auth_peer_success __P((int, int, char *, int));
284 /* peer successfully authenticated itself */
285 void auth_withpeer_fail __P((int, int));
286 /* we failed to authenticate ourselves */
287 void auth_withpeer_success __P((int, int));
288 /* we successfully authenticated ourselves */
289 void auth_check_options __P((void));
290 /* check authentication options supplied */
291 void auth_reset __P((int)); /* check what secrets we have */
292 int check_passwd __P((int, char *, int, char *, int, char **, int *));
293 /* Check peer-supplied username/password */
294 int get_secret __P((int, char *, char *, char *, int *, int));
295 /* get "secret" for chap */
296 int auth_ip_addr __P((int, u_int32_t));
297 /* check if IP address is authorized */
298 int bad_ip_adrs __P((u_int32_t));
299 /* check if IP address is unreasonable */
301 /* Procedures exported from demand.c */
302 void demand_conf __P((void)); /* config interface(s) for demand-dial */
303 void demand_block __P((void)); /* set all NPs to queue up packets */
304 void demand_unblock __P((void)); /* set all NPs to pass packets */
305 void demand_discard __P((void)); /* set all NPs to discard packets */
306 void demand_rexmit __P((int)); /* retransmit saved frames for an NP */
307 int loop_chars __P((unsigned char *, int)); /* process chars from loopback */
308 int loop_frame __P((unsigned char *, int)); /* should we bring link up? */
310 /* Procedures exported from sys-*.c */
311 void sys_init __P((void)); /* Do system-dependent initialization */
312 void sys_cleanup __P((void)); /* Restore system state before exiting */
313 int sys_check_options __P((void)); /* Check options specified */
314 void sys_close __P((void)); /* Clean up in a child before execing */
315 int ppp_available __P((void)); /* Test whether ppp kernel support exists */
316 int open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */
317 int establish_ppp __P((int)); /* Turn serial port into a ppp interface */
318 void restore_loop __P((void)); /* Transfer ppp unit back to loopback */
319 void disestablish_ppp __P((int)); /* Restore port to normal operation */
320 void clean_check __P((void)); /* Check if line was 8-bit clean */
321 void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */
322 void restore_tty __P((int)); /* Restore port's original parameters */
323 void setdtr __P((int, int)); /* Raise or lower port's DTR line */
324 void output __P((int, u_char *, int)); /* Output a PPP packet */
325 void wait_input __P((struct timeval *));
326 /* Wait for input, with timeout */
327 void add_fd __P((int)); /* Add fd to set to wait for */
328 void remove_fd __P((int)); /* Remove fd from set to wait for */
329 int read_packet __P((u_char *)); /* Read PPP packet */
330 int get_loop_output __P((void)); /* Read pkts from loopback */
331 void ppp_send_config __P((int, int, u_int32_t, int, int));
332 /* Configure i/f transmit parameters */
333 void ppp_set_xaccm __P((int, ext_accm));
334 /* Set extended transmit ACCM */
335 void ppp_recv_config __P((int, int, u_int32_t, int, int));
336 /* Configure i/f receive parameters */
337 int ccp_test __P((int, u_char *, int, int));
338 /* Test support for compression scheme */
339 void ccp_flags_set __P((int, int, int));
340 /* Set kernel CCP state */
341 int ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */
342 int get_idle_time __P((int, struct ppp_idle *));
343 /* Find out how long link has been idle */
344 int get_ppp_stats __P((int, struct ppp_stats *));
345 /* Return link statistics */
346 int sifvjcomp __P((int, int, int, int));
347 /* Configure VJ TCP header compression */
348 int sifup __P((int)); /* Configure i/f up (for IP) */
349 int sifnpmode __P((int u, int proto, enum NPmode mode));
350 /* Set mode for handling packets for proto */
351 int sifdown __P((int)); /* Configure i/f down (for IP) */
352 int sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t));
353 /* Configure IP addresses for i/f */
354 int cifaddr __P((int, u_int32_t, u_int32_t));
355 /* Reset i/f IP addresses */
356 int sifdefaultroute __P((int, u_int32_t, u_int32_t));
357 /* Create default route through i/f */
358 int cifdefaultroute __P((int, u_int32_t, u_int32_t));
359 /* Delete default route through i/f */
360 int sifproxyarp __P((int, u_int32_t));
361 /* Add proxy ARP entry for peer */
362 int cifproxyarp __P((int, u_int32_t));
363 /* Delete proxy ARP entry for peer */
364 u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */
365 int lock __P((char *)); /* Create lock file for device */
366 void unlock __P((void)); /* Delete previously-created lock file */
367 int daemon __P((int, int)); /* Detach us from terminal session */
368 void logwtmp __P((const char *, const char *, const char *));
369 /* Write entry to wtmp file */
370 int get_host_seed __P((void)); /* Get host-dependent random number seed */
371 int have_route_to __P((u_int32_t)); /* Check if route to addr exists */
373 int set_filters __P((struct bpf_program *pass, struct bpf_program *active));
374 /* Set filter programs in kernel */
377 int sipxfaddr __P((int, unsigned long, unsigned char *));
378 int cipxfaddr __P((int));
381 /* Procedures exported from options.c */
382 int parse_args __P((int argc, char **argv));
383 /* Parse options from arguments given */
384 int options_from_file __P((char *filename, int must_exist, int check_prot,
386 /* Parse options from an options file */
387 int options_from_user __P((void)); /* Parse options from user's .ppprc */
388 int options_for_tty __P((void)); /* Parse options from /etc/ppp/options.tty */
389 void scan_args __P((int argc, char **argv));
390 /* Look for tty name in command-line args */
391 int getword __P((FILE *f, char *word, int *newlinep, char *filename));
392 /* Read a word from a file */
393 void option_error __P((char *fmt, ...));
394 /* Print an error message about an option */
395 int int_option __P((char *, int *));
396 /* Simplified number_option for decimal ints */
399 * This structure is used to store information about certain
400 * options, such as where the option value came from (/etc/ppp/options,
401 * command line, etc.) and whether it came from a privileged source.
405 int priv; /* was value set by sysadmin? */
406 char *source; /* where option came from */
409 extern struct option_info devnam_info;
410 extern struct option_info connector_info;
411 extern struct option_info disconnector_info;
412 extern struct option_info welcomer_info;
415 * Inline versions of get/put char/short/long.
416 * Pointer is advanced; we assume that both arguments
417 * are lvalues and will already be in registers.
418 * cp MUST be u_char *.
420 #define GETCHAR(c, cp) { \
423 #define PUTCHAR(c, cp) { \
424 *(cp)++ = (u_char) (c); \
428 #define GETSHORT(s, cp) { \
429 (s) = *(cp)++ << 8; \
432 #define PUTSHORT(s, cp) { \
433 *(cp)++ = (u_char) ((s) >> 8); \
434 *(cp)++ = (u_char) (s); \
437 #define GETLONG(l, cp) { \
438 (l) = *(cp)++ << 8; \
439 (l) |= *(cp)++; (l) <<= 8; \
440 (l) |= *(cp)++; (l) <<= 8; \
443 #define PUTLONG(l, cp) { \
444 *(cp)++ = (u_char) ((l) >> 24); \
445 *(cp)++ = (u_char) ((l) >> 16); \
446 *(cp)++ = (u_char) ((l) >> 8); \
447 *(cp)++ = (u_char) (l); \
450 #define INCPTR(n, cp) ((cp) += (n))
451 #define DECPTR(n, cp) ((cp) -= (n))
454 * System dependent definitions for user-level 4.3BSD UNIX implementation.
457 #define TIMEOUT(r, f, t) timeout((r), (f), (t))
458 #define UNTIMEOUT(r, f) untimeout((r), (f))
460 #define BCOPY(s, d, l) memcpy(d, s, l)
461 #define BZERO(s, n) memset(s, 0, n)
463 #define PRINTMSG(m, l) { info("Remote message: %0.*v", l, m); }
466 * MAKEHEADER - Add Header fields to a packet.
468 #define MAKEHEADER(p, t) { \
469 PUTCHAR(PPP_ALLSTATIONS, p); \
470 PUTCHAR(PPP_UI, p); \
483 #ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */
484 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
485 || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
486 || defined(DEBUGCHAP) || defined(DEBUG)
487 #define LOG_PPP LOG_LOCAL2
489 #define LOG_PPP LOG_DAEMON
494 #define MAINDEBUG(x) if (debug) dbglog x
500 #define SYSDEBUG(x) if (debug) dbglog x
506 #define FSMDEBUG(x) if (debug) dbglog x
512 #define LCPDEBUG(x) if (debug) dbglog x
518 #define IPCPDEBUG(x) if (debug) dbglog x
524 #define UPAPDEBUG(x) if (debug) dbglog x
530 #define CHAPDEBUG(x) if (debug) dbglog x
536 #define IPXCPDEBUG(x) if (debug) dbglog x
538 #define IPXCPDEBUG(x)
542 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
546 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
550 #define MIN(a, b) ((a) < (b)? (a): (b))
553 #define MAX(a, b) ((a) > (b)? (a): (b))
556 #endif /* __PPP_H__ */