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