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