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