1 //==========================================================================
5 //==========================================================================
6 //####ECOSGPLCOPYRIGHTBEGIN####
7 // -------------------------------------------
8 // This file is part of eCos, the Embedded Configurable Operating System.
9 // Portions created by Nick Garnett are
10 // Copyright (C) 2003 eCosCentric Ltd.
12 // eCos is free software; you can redistribute it and/or modify it under
13 // the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 2 or (at your option) any later version.
16 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 // You should have received a copy of the GNU General Public License along
22 // with eCos; if not, write to the Free Software Foundation, Inc.,
23 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 // As a special exception, if other files instantiate templates or use macros
26 // or inline functions from this file, or you compile this file and link it
27 // with other works to produce a work based on this file, this file does not
28 // by itself cause the resulting work to be covered by the GNU General Public
29 // License. However the source code for this file must still be made available
30 // in accordance with section (3) of the GNU General Public License.
32 // This exception does not invalidate any other reasons why a work based on
33 // this file might be covered by the GNU General Public License.
35 // -------------------------------------------
36 //####ECOSGPLCOPYRIGHTEND####
37 //####BSDCOPYRIGHTBEGIN####
39 // -------------------------------------------
41 // Portions of this software may have been derived from OpenBSD,
42 // FreeBSD or other sources, and are covered by the appropriate
43 // copyright disclaimers included herein.
45 // -------------------------------------------
47 //####BSDCOPYRIGHTEND####
48 //==========================================================================
51 * pppd.h - PPP daemon global declarations.
53 * Copyright (c) 1989 Carnegie Mellon University.
54 * All rights reserved.
56 * Redistribution and use in source and binary forms are permitted
57 * provided that the above copyright notice and this paragraph are
58 * duplicated in all such forms and that any documentation,
59 * advertising materials, and other materials related to such
60 * distribution and use acknowledge that the software was developed
61 * by Carnegie Mellon University. The name of the
62 * University may not be used to endorse or promote products derived
63 * from this software without specific prior written permission.
64 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
65 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
66 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
68 * $FreeBSD: src/usr.sbin/pppd/pppd.h,v 1.13 1999/08/28 01:19:08 peter Exp $
78 #include <cyg/io/io.h>
79 #include <cyg/io/serialio.h>
81 #include <cyg/ppp/names.h>
83 #include <stdio.h> /* for FILE */
84 #include <sys/param.h> /* for MAXPATHLEN and BSD4_4, if defined */
85 #include <sys/types.h> /* for u_int32_t, if defined */
86 #include <sys/time.h> /* for struct timeval */
87 #include <cyg/ppp/net/ppp_defs.h>
88 #include <cyg/ppp/ppp.h>
95 #define __V(x) (va_alist) va_dcl
103 #define NUM_PPP 1 /* One PPP interface supported (per process) */
104 #define MAXWORDLEN 1024 /* max length of word in file (incl null) */
105 #define MAXARGS 1 /* max # args to a command */
106 #define MAXNAMELEN 256 /* max length of hostname or name for auth */
107 #define MAXSECRETLEN 256 /* max length of password or secret */
113 extern int hungup; /* Physical layer has disconnected */
114 extern char ifname[]; /* Interface name */
115 extern int ttyfd; /* Serial device file descriptor */
116 extern char cyg_ppp_hostname[]; /* Our hostname */
117 extern u_char outpacket_buf[]; /* Buffer for outgoing packets */
118 extern int phase; /* Current state of link - see values below */
119 extern int baud_rate; /* Current link speed in bits/sec */
120 extern char *progname; /* Name of this program */
121 extern int redirect_stderr;/* Connector's stderr should go to file */
122 extern char peer_authname[];/* Authenticated name of peer */
123 extern int privileged; /* We were run by real-uid root */
124 extern int need_holdoff; /* Need holdoff period after link terminates */
125 extern char **script_env; /* Environment variables for scripts */
126 extern int detached; /* Have detached from controlling tty */
129 * Variables set by command-line options.
132 extern int debug; /* Debug flag */
133 extern int kdebugflag; /* Tell kernel to print debug messages */
134 extern int default_device; /* Using /dev/tty or equivalent */
135 extern char devnam[]; /* Device name */
136 extern int flowctl; /* Flow control */
137 extern int modem; /* Use modem control lines */
138 extern cyg_serial_baud_rate_t inspeed; /* Input/Output speed requested */
139 extern u_int32_t netmask; /* IP netmask to set on interface */
140 extern int lockflag; /* Create lock file to lock the serial dev */
141 extern int nodetach; /* Don't detach from controlling tty */
142 extern char *connector; /* Script to establish physical link */
143 extern char *disconnector; /* Script to disestablish physical link */
144 extern char *welcomer; /* Script to welcome client after connection */
145 extern int max_con_attempts;/* Maximum number of times to try dialing */
146 extern int maxconnect; /* Maximum connect time (seconds) */
147 extern char user[]; /* Our name for authenticating ourselves */
148 extern char passwd[]; /* Password for PAP */
149 extern int auth_required; /* Peer is required to authenticate */
150 extern int neg_accm; /* Flag to enable ACCM negotiation */
151 extern int conf_accm; /* Configurable value of ACCM */
152 extern int proxyarp; /* Set up proxy ARP entry for peer */
153 extern int persist; /* Reopen link after it goes down */
154 extern int uselogin; /* Use /etc/passwd for checking PAP */
155 extern int lcp_echo_interval; /* Interval between LCP echo-requests */
156 extern int lcp_echo_fails; /* Tolerance to unanswered echo-requests */
157 extern char our_name[]; /* Our name for authentication purposes */
158 extern char remote_name[]; /* Peer's name for authentication */
159 extern int explicit_remote;/* remote_name specified with remotename opt */
160 extern int usehostname; /* Use hostname for our_name */
161 extern int disable_defaultip; /* Don't use hostname for default IP adrs */
162 //extern int demand; /* Do dial-on-demand */
164 extern char *ipparam; /* Extra parameter for ip up/down scripts */
165 extern int cryptpap; /* Others' PAP passwords are encrypted */
166 extern int idle_time_limit;/* Shut down link if idle for this long */
167 extern int holdoff; /* Dead time before restarting */
168 extern int refuse_pap; /* Don't wanna auth. ourselves with PAP */
169 extern int refuse_chap; /* Don't wanna auth. ourselves with CHAP */
171 extern struct bpf_program pass_filter; /* Filter for pkts to pass */
172 extern struct bpf_program active_filter; /* Filter for link-active pkts */
177 extern int ms_lanman; /* Nonzero if use LanMan password instead of NT */
178 /* Has meaning only with MS-CHAP challenges */
185 #define PHASE_INITIALIZE 1
186 #define PHASE_DORMANT 2
187 #define PHASE_ESTABLISH 3
188 #define PHASE_AUTHENTICATE 4
189 #define PHASE_CALLBACK 5
190 #define PHASE_NETWORK 6
191 #define PHASE_TERMINATE 7
192 #define PHASE_HOLDOFF 8
195 * The following struct gives the addresses of procedures to call
196 * for a particular protocol.
199 u_short protocol; /* PPP protocol number */
200 /* Initialization procedure */
201 void (*init) __P((int unit));
202 /* Process a received packet */
203 void (*input) __P((int unit, u_char *pkt, int len));
204 /* Process a received protocol-reject */
205 void (*protrej) __P((int unit));
206 /* Lower layer has come up */
207 void (*lowerup) __P((int unit));
208 /* Lower layer has gone down */
209 void (*lowerdown) __P((int unit));
210 /* Open the protocol */
211 void (*open) __P((int unit));
212 /* Close the protocol */
213 void (*close) __P((int unit, char *reason));
214 /* Print a packet in readable form */
215 int (*printpkt) __P((u_char *pkt, int len,
216 void (*printer) __P((void *, char *, ...)),
218 /* Process a received data packet */
219 void (*datainput) __P((int unit, u_char *pkt, int len));
220 int enabled_flag; /* 0 iff protocol is disabled */
221 char *name; /* Text name of protocol */
222 /* Check requested options, assign defaults */
223 void (*check_options) __P((void));
224 /* Configure interface for demand-dial */
225 int (*demand_conf) __P((int unit));
226 /* Say whether to bring up link for this pkt */
227 int (*active_pkt) __P((u_char *pkt, int len));
230 /* Table of pointers to supported protocols */
231 extern struct protent *protocols[];
237 /* Procedures exported from main.c. */
238 void detach __P((void)); /* Detach from controlling tty */
239 void die __P((int)); /* Cleanup and exit */
240 void quit __P((void)); /* like die(1) */
241 void novm __P((char *)); /* Say we ran out of memory, and die */
242 void cyg_ppp_timeout __P((void (*func)(void *), void *arg, int t));
243 /* Call func(arg) after t seconds */
244 void cyg_ppp_untimeout __P((void (*func)(void *), void *arg));
245 /* Cancel call to func(arg) */
246 int run_program __P((char *prog, char **args, int must_exist));
247 /* Run program prog with args in child */
248 void demuxprotrej __P((int, int));
249 /* Demultiplex a Protocol-Reject */
250 void format_packet __P((u_char *, int, void (*) (void *, char *, ...),
251 void *)); /* Format a packet in human-readable form */
252 void log_packet __P((u_char *, int, char *, int));
253 /* Format a packet and log it with syslog */
254 void print_string __P((unsigned char *, int, void (*) (void *, char *, ...),
255 void *)); /* Format a string for output */
256 int fmtmsg __P((char *, int, char *, ...)); /* sprintf++ */
257 int vfmtmsg __P((char *, int, char *, va_list)); /* vsprintf++ */
258 void script_setenv __P((char *, char *)); /* set script env var */
259 void script_unsetenv __P((char *)); /* unset script env var */
261 /* Procedures exported from auth.c */
262 void link_required __P((int)); /* we are starting to use the link */
263 void link_terminated __P((int)); /* we are finished with the link */
264 void link_down __P((int)); /* the LCP layer has left the Opened state */
265 void link_established __P((int)); /* the link is up; authenticate now */
266 void np_up __P((int, int)); /* a network protocol has come up */
267 void np_down __P((int, int)); /* a network protocol has gone down */
268 void np_finished __P((int, int)); /* a network protocol no longer needs link */
269 void auth_peer_fail __P((int, int));
270 /* peer failed to authenticate itself */
271 void auth_peer_success __P((int, int, char *, int));
272 /* peer successfully authenticated itself */
273 void auth_withpeer_fail __P((int, int));
274 /* we failed to authenticate ourselves */
275 void auth_withpeer_success __P((int, int));
276 /* we successfully authenticated ourselves */
277 void auth_check_options __P((void));
278 /* check authentication options supplied */
279 void auth_reset __P((int)); /* check what secrets we have */
280 int check_passwd __P((int, char *, int, char *, int, char **, int *));
281 /* Check peer-supplied username/password */
282 int get_secret __P((int, char *, char *, char *, int *, int));
283 /* get "secret" for chap */
284 int auth_ip_addr __P((int, u_int32_t));
285 /* check if IP address is authorized */
286 int bad_ip_adrs __P((u_int32_t));
287 /* check if IP address is unreasonable */
288 void check_access __P((FILE *, char *));
289 /* check permissions on secrets file */
291 /* Procedures exported from demand.c */
292 void demand_conf __P((void)); /* config interface(s) for demand-dial */
293 void demand_block __P((void)); /* set all NPs to queue up packets */
294 void demand_unblock __P((void)); /* set all NPs to pass packets */
295 void demand_discard __P((void)); /* set all NPs to discard packets */
296 void demand_rexmit __P((int)); /* retransmit saved frames for an NP */
297 int loop_chars __P((unsigned char *, int)); /* process chars from loopback */
298 int loop_frame __P((unsigned char *, int)); /* process frame from loopback */
300 /* Procedures exported from sys-*.c */
301 void sys_init __P((void)); /* Do system-dependent initialization */
302 void sys_cleanup __P((void)); /* Restore system state before exiting */
303 void sys_check_options __P((void)); /* Check options specified */
304 void sys_close __P((void)); /* Clean up in a child before execing */
305 int ppp_available __P((void)); /* Test whether ppp kernel support exists */
306 void open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */
307 void establish_ppp __P((cyg_io_handle_t)); /* Turn serial port into a ppp interface */
308 void restore_loop __P((void)); /* Transfer ppp unit back to loopback */
309 void disestablish_ppp __P((cyg_io_handle_t)); /* Restore port to normal operation */
310 void clean_check __P((void)); /* Check if line was 8-bit clean */
311 void set_up_tty __P((cyg_io_handle_t, int)); /* Set up port's speed, parameters, etc. */
312 void restore_tty __P((cyg_io_handle_t)); /* Restore port's original parameters */
313 void setdtr __P((int, int)); /* Raise or lower port's DTR line */
314 void output __P((int, u_char *, int)); /* Output a PPP packet */
315 void wait_input __P((struct timeval *));
316 /* Wait for input, with timeout */
317 void wait_loop_output __P((struct timeval *));
318 /* Wait for pkt from loopback, with timeout */
319 void wait_time __P((struct timeval *)); /* Wait for given length of time */
320 int read_packet __P((u_char *)); /* Read PPP packet */
321 int get_loop_output __P((void)); /* Read pkts from loopback */
322 void ppp_send_config __P((int, int, u_int32_t, int, int));
323 /* Configure i/f transmit parameters */
324 void ppp_set_xaccm __P((int, ext_accm));
325 /* Set extended transmit ACCM */
326 void ppp_recv_config __P((int, int, u_int32_t, int, int));
327 /* Configure i/f receive parameters */
328 int ccp_test __P((int, u_char *, int, int));
329 /* Test support for compression scheme */
330 void ccp_flags_set __P((int, int, int));
331 /* Set kernel CCP state */
332 int ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */
333 int get_idle_time __P((int, struct ppp_idle *));
334 /* Find out how long link has been idle */
335 int sifvjcomp __P((int, int, int, int));
336 /* Configure VJ TCP header compression */
337 int sifup __P((int)); /* Configure i/f up (for IP) */
338 int sifnpmode __P((int u, int proto, enum NPmode mode));
339 /* Set mode for handling packets for proto */
340 int sifdown __P((int)); /* Configure i/f down (for IP) */
341 int sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t));
342 /* Configure IP addresses for i/f */
343 int cifaddr __P((int, u_int32_t, u_int32_t));
344 /* Reset i/f IP addresses */
345 int sifdefaultroute __P((int, u_int32_t, u_int32_t));
346 /* Create default route through i/f */
347 int cifdefaultroute __P((int, u_int32_t, u_int32_t));
348 /* Delete default route through i/f */
349 int sifproxyarp __P((int, u_int32_t));
350 /* Add proxy ARP entry for peer */
351 int cifproxyarp __P((int, u_int32_t));
352 /* Delete proxy ARP entry for peer */
353 u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */
354 int lock __P((char *)); /* Create lock file for device */
355 void unlock __P((void)); /* Delete previously-created lock file */
356 int daemon __P((int, int)); /* Detach us from terminal session */
357 void logwtmp __P((const char *, const char *, const char *));
358 /* Write entry to wtmp file */
359 int get_host_seed __P((void)); /* Get host-dependent random number seed */
361 int set_filters __P((struct bpf_program *pass, struct bpf_program *active));
362 /* Set filter programs in kernel */
365 /* Procedures exported from options.c */
366 int parse_args __P((int argc, char **argv));
367 /* Parse options from arguments given */
368 void usage __P((void)); /* Print a usage message */
369 int options_from_file __P((char *filename, int must_exist, int check_prot,
371 /* Parse options from an options file */
372 int options_from_user __P((void)); /* Parse options from user's .ppprc */
373 int options_for_tty __P((void)); /* Parse options from /etc/ppp/options.tty */
374 void scan_args __P((int argc, char **argv));
375 /* Look for tty name in command-line args */
376 int getword __P((FILE *f, char *word, int *newlinep, char *filename));
377 /* Read a word from a file */
378 void option_error __P((char *fmt, ...));
379 /* Print an error message about an option */
380 int setipaddr __P((char *)); /* set IP addresses */
381 int gettimeofday __P((struct timeval *tv, struct timezone *tz));
385 * This structure is used to store information about certain
386 * options, such as where the option value came from (/etc/ppp/options,
387 * command line, etc.) and whether it came from a privileged source.
391 int priv; /* was value set by sysadmin? */
392 char *source; /* where option came from */
395 extern struct option_info auth_req_info;
396 extern struct option_info connector_info;
397 extern struct option_info disconnector_info;
398 extern struct option_info welcomer_info;
399 extern struct option_info devnam_info;
402 * Inline versions of get/put char/short/long.
403 * Pointer is advanced; we assume that both arguments
404 * are lvalues and will already be in registers.
405 * cp MUST be u_char *.
407 #define GETCHAR(c, cp) { \
410 #define PUTCHAR(c, cp) { \
411 *(cp)++ = (u_char) (c); \
415 #define GETSHORT(s, cp) { \
416 (s) = *(cp)++ << 8; \
419 #define PUTSHORT(s, cp) { \
420 *(cp)++ = (u_char) ((s) >> 8); \
421 *(cp)++ = (u_char) (s); \
424 #define GETLONG(l, cp) { \
425 (l) = *(cp)++ << 8; \
426 (l) |= *(cp)++; (l) <<= 8; \
427 (l) |= *(cp)++; (l) <<= 8; \
430 #define PUTLONG(l, cp) { \
431 *(cp)++ = (u_char) ((l) >> 24); \
432 *(cp)++ = (u_char) ((l) >> 16); \
433 *(cp)++ = (u_char) ((l) >> 8); \
434 *(cp)++ = (u_char) (l); \
437 #define INCPTR(n, cp) ((cp) += (n))
438 #define DECPTR(n, cp) ((cp) -= (n))
446 * System dependent definitions for user-level 4.3BSD UNIX implementation.
449 #define DEMUXPROTREJ(u, p) demuxprotrej(u, p)
451 #define TIMEOUT(r, f, t) cyg_ppp_timeout((r), (f), (t))
452 #define UNTIMEOUT(r, f) cyg_ppp_untimeout((r), (f))
454 #define BCOPY(s, d, l) memcpy(d, s, l)
455 #define BZERO(s, n) memset(s, 0, n)
456 #define EXIT(u) quit()
458 #define PRINTMSG(m, l) { m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); }
461 * MAKEHEADER - Add Header fields to a packet.
463 #define MAKEHEADER(p, t) { \
464 PUTCHAR(PPP_ALLSTATIONS, p); \
465 PUTCHAR(PPP_UI, p); \
479 #ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */
480 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
481 || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
482 || defined(DEBUGCHAP) || defined(DEBUG)
483 #define LOG_PPP LOG_LOCAL2
485 #define LOG_PPP LOG_DAEMON
490 #define MAINDEBUG(x) if (debug) syslog x
496 #define SYSDEBUG(x) if (debug) syslog x
502 #define FSMDEBUG(x) if (debug) syslog x
508 #define LCPDEBUG(x) if (debug) syslog x
514 #define IPCPDEBUG(x) if (debug) syslog x
520 #define UPAPDEBUG(x) if (debug) syslog x
526 #define CHAPDEBUG(x) if (debug) syslog x
532 #define IPXCPDEBUG(x) if (debug) syslog x
534 #define IPXCPDEBUG(x)
538 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
542 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
546 #define MIN(a, b) ((a) < (b)? (a): (b))
549 #define MAX(a, b) ((a) > (b)? (a): (b))
552 #endif /* __PPP_H__ */