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