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