]> git.ozlabs.org Git - ppp.git/blob - pppd/pppd-private.h
Makefile.am: Add explicit openssl directory to pppd include path
[ppp.git] / pppd / pppd-private.h
1 /*
2  * pppd-private.h - PPP daemon private declarations.
3  *
4  * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * 3. The name "Carnegie Mellon University" must not be used to
19  *    endorse or promote products derived from this software without
20  *    prior written permission. For permission or any legal
21  *    details, please contact
22  *      Office of Technology Transfer
23  *      Carnegie Mellon University
24  *      5000 Forbes Avenue
25  *      Pittsburgh, PA  15213-3890
26  *      (412) 268-4387, fax: (412) 268-7395
27  *      tech-transfer@andrew.cmu.edu
28  *
29  * 4. Redistributions of any form whatsoever must retain the following
30  *    acknowledgment:
31  *    "This product includes software developed by Computing Services
32  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
33  *
34  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
41  *
42  * $Id: pppd.h,v 1.96 2008/06/23 11:47:18 paulus Exp $
43  */
44
45 #ifndef PPP_PPPD_PRIVATE_H
46 #define PPP_PPPD_PRIVATE_H
47
48 #include <stdio.h>              /* for FILE */
49 #include <stdlib.h>             /* for encrypt */
50 #include <unistd.h>             /* for setkey */
51 #if defined(SOL2)
52 #include <net/ppp_defs.h>
53 #else
54 #include <linux/ppp_defs.h>
55 #endif
56
57 #include "pppd.h"
58
59 #ifdef PPP_WITH_IPV6CP
60 #include "eui64.h"
61 #endif
62
63 /*
64  * If PPP_DRV_NAME is not defined, use the default "ppp" as the device name.
65  * Where should PPP_DRV_NAME come from? Do we include it here?
66  */
67 #if !defined(PPP_DRV_NAME)
68 #define PPP_DRV_NAME    "ppp"
69 #endif /* !defined(PPP_DRV_NAME) */
70
71
72 #ifndef GIDSET_TYPE
73 #define GIDSET_TYPE     gid_t
74 #endif
75
76 /* Structure representing a list of permitted IP addresses. */
77 struct permitted_ip {
78     int         permit;         /* 1 = permit, 0 = forbid */
79     u_int32_t   base;           /* match if (addr & mask) == base */
80     u_int32_t   mask;           /* base and mask are in network byte order */
81 };
82
83 struct notifier {
84     struct notifier *next;
85     ppp_notify_fn *func;
86     void *arg;
87 };
88
89 /*
90  * Global variables.
91  */
92
93 extern int      hungup;         /* Physical layer has disconnected */
94 extern int      ifunit;         /* Interface unit number */
95 extern char     ifname[];       /* Interface name (IFNAMSIZ) */
96 extern char     hostname[];     /* Our hostname */
97 extern unsigned char    outpacket_buf[]; /* Buffer for outgoing packets */
98 extern int      devfd;          /* fd of underlying device */
99 extern int      fd_ppp;         /* fd for talking PPP */
100 extern int      baud_rate;      /* Current link speed in bits/sec */
101 extern char     *progname;      /* Name of this program */
102 extern int      redirect_stderr;/* Connector's stderr should go to file */
103 extern char     peer_authname[];/* Authenticated name of peer */
104 extern int      auth_done[NUM_PPP]; /* Methods actually used for auth */
105 extern int      privileged;     /* We were run by real-uid root */
106 extern int      need_holdoff;   /* Need holdoff period after link terminates */
107 extern char     **script_env;   /* Environment variables for scripts */
108 extern int      detached;       /* Have detached from controlling tty */
109 extern GIDSET_TYPE groups[];    /* groups the user is in */
110 extern int      ngroups;        /* How many groups valid in groups */
111 extern int      link_stats_valid; /* set if link_stats is valid */
112 extern int      link_stats_print; /* set if link_stats is to be printed on link termination */
113 extern int      log_to_fd;      /* logging to this fd as well as syslog */
114 extern bool     log_default;    /* log_to_fd is default (stdout) */
115 extern char     *no_ppp_msg;    /* message to print if ppp not in kernel */
116 extern bool     devnam_fixed;   /* can no longer change devnam */
117 extern int      unsuccess;      /* # unsuccessful connection attempts */
118 extern int      do_callback;    /* set if we want to do callback next */
119 extern int      doing_callback; /* set if this is a callback */
120 extern int      error_count;    /* # of times error() has been called */
121 extern char     ppp_devname[];  /* name of PPP tty (maybe ttypx) */
122 extern int      fd_devnull;     /* fd open to /dev/null */
123
124 extern int      listen_time;    /* time to listen first (ms) */
125 extern bool     bundle_eof;
126 extern bool     bundle_terminating;
127
128 extern struct notifier *pidchange;   /* for notifications of pid changing */
129 extern struct notifier *phasechange; /* for notifications of phase changes */
130 extern struct notifier *exitnotify;  /* for notification that we're exiting */
131 extern struct notifier *sigreceived; /* notification of received signal */
132 extern struct notifier *ip_up_notifier;     /* IPCP has come up */
133 extern struct notifier *ip_down_notifier;   /* IPCP has gone down */
134 extern struct notifier *ipv6_up_notifier;   /* IPV6CP has come up */
135 extern struct notifier *ipv6_down_notifier; /* IPV6CP has gone down */
136 extern struct notifier *auth_up_notifier; /* peer has authenticated */
137 extern struct notifier *link_down_notifier; /* link has gone down */
138 extern struct notifier *fork_notifier;  /* we are a new child process */
139
140
141 /* Values for do_callback and doing_callback */
142 #define CALLBACK_DIALIN         1       /* we are expecting the call back */
143 #define CALLBACK_DIALOUT        2       /* we are dialling out to call back */
144
145 /*
146  * Variables set by command-line options.
147  */
148
149 extern int      debug;          /* Debug flag */
150 extern int      kdebugflag;     /* Tell kernel to print debug messages */
151 extern int      default_device; /* Using /dev/tty or equivalent */
152 extern char     devnam[];       /* Device name */
153 extern char remote_number[MAXNAMELEN]; /* Remote telephone number, if avail. */
154 extern int  ppp_session_number; /* Session number (eg PPPoE session) */
155 extern int      crtscts;        /* Use hardware flow control */
156 extern int      stop_bits;      /* Number of serial port stop bits */
157 extern bool     modem;          /* Use modem control lines */
158 extern int      inspeed;        /* Input/Output speed requested */
159 extern u_int32_t netmask;       /* IP netmask to set on interface */
160 extern bool     lockflag;       /* Create lock file to lock the serial dev */
161 extern bool     nodetach;       /* Don't detach from controlling tty */
162 #ifdef SYSTEMD
163 extern bool     up_sdnotify;    /* Notify systemd once link is up (implies nodetach) */
164 #endif
165 extern bool     updetach;       /* Detach from controlling tty when link up */
166 extern bool     master_detach;  /* Detach when multilink master without link (options.c) */
167 extern char     *initializer;   /* Script to initialize physical link */
168 extern char     *connect_script; /* Script to establish physical link */
169 extern char     *disconnect_script; /* Script to disestablish physical link */
170 extern char     *welcomer;      /* Script to welcome client after connection */
171 extern char     *ptycommand;    /* Command to run on other side of pty */
172 extern char     user[MAXNAMELEN];/* Our name for authenticating ourselves */
173 extern char     passwd[MAXSECRETLEN];   /* Password for PAP or CHAP */
174 extern bool     auth_required;  /* Peer is required to authenticate */
175 extern bool     persist;        /* Reopen link after it goes down */
176 extern bool     uselogin;       /* Use /etc/passwd for checking PAP */
177 extern bool     session_mgmt;   /* Do session management (login records) */
178 extern char     our_name[MAXNAMELEN];/* Our name for authentication purposes */
179 extern char     remote_name[MAXNAMELEN]; /* Peer's name for authentication */
180 extern bool     explicit_remote;/* remote_name specified with remotename opt */
181 extern bool     demand;         /* Do dial-on-demand */
182 extern char     *ipparam;       /* Extra parameter for ip up/down scripts */
183 extern bool     cryptpap;       /* Others' PAP passwords are encrypted */
184 extern int      holdoff;        /* Dead time before restarting */
185 extern bool     holdoff_specified; /* true if user gave a holdoff value */
186 extern bool     notty;          /* Stdin/out is not a tty */
187 extern char     *pty_socket;    /* Socket to connect to pty */
188 extern char     *record_file;   /* File to record chars sent/received */
189 extern int      maxfail;        /* Max # of unsuccessful connection attempts */
190 extern char     linkname[];     /* logical name for link */
191 extern bool     tune_kernel;    /* May alter kernel settings as necessary */
192 extern int      connect_delay;  /* Time to delay after connect script */
193 extern int      max_data_rate;  /* max bytes/sec through charshunt */
194 extern int      req_unit;       /* interface unit number to use */
195 extern char     path_ipup[];    /* pathname of ip-up script */
196 extern char     path_ipdown[];  /* pathname of ip-down script */
197 extern char     req_ifname[]; /* interface name to use (IFNAMSIZ) */
198 extern bool     multilink;      /* enable multilink operation (options.c) */
199 extern bool     noendpoint;     /* don't send or accept endpt. discrim. */
200 extern char     *bundle_name;   /* bundle name for multilink */
201 extern bool     dump_options;   /* print out option values */
202 extern bool     show_options;   /* show all option names and descriptions */
203 extern bool     dryrun;         /* check everything, print options, exit */
204 extern int      child_wait;     /* # seconds to wait for children at end */
205 extern char *current_option;    /* the name of the option being parsed */
206 extern int  privileged_option;  /* set iff the current option came from root */
207 extern char *option_source;     /* string saying where the option came from */
208 extern int  option_priority;    /* priority of current options */
209
210 #ifdef PPP_WITH_IPV6CP
211 extern char     path_ipv6up[]; /* pathname of ipv6-up script */
212 extern char     path_ipv6down[]; /* pathname of ipv6-down script */
213 #endif
214
215 #if defined(PPP_WITH_EAPTLS) || defined(PPP_WITH_PEAP)
216 #define TLS_VERIFY_NONE     "none"
217 #define TLS_VERIFY_NAME     "name"
218 #define TLS_VERIFY_SUBJECT  "subject"
219 #define TLS_VERIFY_SUFFIX   "suffix"
220
221 extern char *crl_dir;
222 extern char *crl_file;
223 extern char *ca_path;
224 extern char *cacert_file;
225
226 extern char *max_tls_version;
227 extern bool tls_verify_key_usage;
228 extern char *tls_verify_method;
229 #endif /* PPP_WITH_EAPTLS || PPP_WITH_PEAP */
230
231 #ifdef PPP_WITH_EAPTLS
232 extern char *pkcs12_file;
233 #endif /* PPP_WITH_EAPTLS */
234
235 typedef enum {
236     PPP_OCTETS_DIRECTION_SUM,
237     PPP_OCTETS_DIRECTION_IN,
238     PPP_OCTETS_DIRECTION_OUT,
239     PPP_OCTETS_DIRECTION_MAXOVERAL,
240     PPP_OCTETS_DIRECTION_MAXSESSION             /* Same as MAXOVERALL, but a little different for RADIUS */
241 } session_limit_dir_t;
242
243 extern unsigned int        maxoctets;           /* Maximum octetes per session (in bytes) */
244 extern session_limit_dir_t maxoctets_dir;       /* Direction */
245 extern int                 maxoctets_timeout;   /* Timeout for check of octets limit */
246
247 #ifdef PPP_WITH_FILTER
248 extern struct   bpf_program pass_filter;   /* Filter for pkts to pass */
249 extern struct   bpf_program active_filter; /* Filter for link-active pkts */
250 #endif
251
252 #ifdef PPP_WITH_MSLANMAN
253 extern bool     ms_lanman;      /* Use LanMan password instead of NT */
254                                 /* Has meaning only with MS-CHAP challenges */
255 #endif
256
257 /* Values for auth_pending, auth_done */
258 #define PAP_WITHPEER    0x1
259 #define PAP_PEER        0x2
260 #define CHAP_WITHPEER   0x4
261 #define CHAP_PEER       0x8
262 #define EAP_WITHPEER    0x10
263 #define EAP_PEER        0x20
264
265 /* Values for auth_done only */
266 #define CHAP_MD5_WITHPEER       0x40
267 #define CHAP_MD5_PEER           0x80
268 #define CHAP_MS_SHIFT           8       /* LSB position for MS auths */
269 #define CHAP_MS_WITHPEER        0x100
270 #define CHAP_MS_PEER            0x200
271 #define CHAP_MS2_WITHPEER       0x400
272 #define CHAP_MS2_PEER           0x800
273
274
275 /*
276  * This structure contains environment variables that are set or unset
277  * by the user.
278  */
279 struct userenv {
280         struct userenv *ue_next;
281         char *ue_value;         /* value (set only) */
282         bool ue_isset;          /* 1 for set, 0 for unset */
283         bool ue_priv;           /* from privileged source */
284         const char *ue_source;  /* source name */
285         char ue_name[1];        /* variable name */
286 };
287
288 extern struct userenv *userenv_list;
289
290 /*
291  * Prototypes.
292  */
293
294 /* Procedures exported from main.c. */
295 void set_ifunit(int);   /* set stuff that depends on ifunit */
296 void detach(void);      /* Detach from controlling tty */
297 void die(int);          /* Cleanup and exit */
298 void quit(void);                /* like die(1) */
299
300 void record_child(int, char *, void (*) (void *), void *, int);
301 int  device_script(char *cmd, int in, int out, int dont_wait);
302                                 /* Run `cmd' with given stdin and stdout */
303 pid_t run_program(char *prog, char * const * args, int must_exist,
304                   void (*done)(void *), void *arg, int wait);
305                                 /* Run program prog with args in child */
306 void reopen_log(void);  /* (re)open the connection to syslog */
307 void print_link_stats(void); /* Print stats, if available */
308 void reset_link_stats(int); /* Reset (init) stats when link goes up */
309 void new_phase(ppp_phase_t);    /* signal start of new phase */
310 bool in_phase(ppp_phase_t);
311 void notify(struct notifier *, int);
312 int  ppp_send_config(int, int, u_int32_t, int, int);
313 int  ppp_recv_config(int, int, u_int32_t, int, int);
314 const char *protocol_name(int);
315 void remove_pidfiles(void);
316 void lock_db(void);
317 void unlock_db(void);
318
319 /* Procedures exported from tty.c. */
320 void tty_init(void);
321
322 void print_string(char *, int,  printer_func, void *);
323                                 /* Format a string for output */
324 ssize_t complete_read(int, void *, size_t);
325                                 /* read a complete buffer */
326
327 /* Procedures exported from auth.c */
328 void link_required(int);          /* we are starting to use the link */
329 void start_link(int);     /* bring the link up now */
330 void link_terminated(int);  /* we are finished with the link */
331 void link_down(int);      /* the LCP layer has left the Opened state */
332 void upper_layers_down(int);/* take all NCPs down */
333 void link_established(int); /* the link is up; authenticate now */
334 void start_networks(int);   /* start all the network control protos */
335 void continue_networks(int); /* start network [ip, etc] control protos */
336 void np_up(int, int);     /* a network protocol has come up */
337 void np_down(int, int);   /* a network protocol has gone down */
338 void np_finished(int, int); /* a network protocol no longer needs link */
339 void auth_peer_fail(int, int);
340                                 /* peer failed to authenticate itself */
341 void auth_peer_success(int, int, int, char *, int);
342                                 /* peer successfully authenticated itself */
343 void auth_withpeer_fail(int, int);
344                                 /* we failed to authenticate ourselves */
345 void auth_withpeer_success(int, int, int);
346                                 /* we successfully authenticated ourselves */
347 void auth_check_options(void);
348                                 /* check authentication options supplied */
349 void auth_reset(int);   /* check what secrets we have */
350 int  check_passwd(int, char *, int, char *, int, char **);
351                                 /* Check peer-supplied username/password */
352 int  get_secret(int, char *, char *, char *, int *, int);
353                                 /* get "secret" for chap */
354 int  get_srp_secret(int unit, char *client, char *server, char *secret,
355     int am_server);
356 int  auth_ip_addr(int, u_int32_t);
357                                 /* check if IP address is authorized */
358 int  auth_number(void); /* check if remote number is authorized */
359
360 /* Procedures exported from demand.c */
361 void demand_conf(void); /* config interface(s) for demand-dial */
362 void demand_block(void);        /* set all NPs to queue up packets */
363 void demand_unblock(void); /* set all NPs to pass packets */
364 void demand_discard(void); /* set all NPs to discard packets */
365 void demand_rexmit(int);        /* retransmit saved frames for an NP */
366 int  loop_chars(unsigned char *, int); /* process chars from loopback */
367 int  loop_frame(unsigned char *, int); /* should we bring link up? */
368
369 /* Procedures exported from sys-*.c */
370 void sys_init(void);    /* Do system-dependent initialization */
371 void sys_cleanup(void); /* Restore system state before exiting */
372 int  sys_check_options(void); /* Check options specified */
373 int  get_pty(int *, int *, char *, int);        /* Get pty master/slave */
374 int  open_ppp_loopback(void); /* Open loopback for demand-dialling */
375 int  tty_establish_ppp(int);  /* Turn serial port into a ppp interface */
376 void tty_disestablish_ppp(int); /* Restore port to normal operation */
377 void make_new_bundle(int, int, int, int); /* Create new bundle */
378 int  bundle_attach(int);        /* Attach link to existing bundle */
379 void cfg_bundle(int, int, int, int); /* Configure existing bundle */
380 void destroy_bundle(void); /* Tell driver to destroy bundle */
381 void clean_check(void); /* Check if line was 8-bit clean */
382 void set_up_tty(int, int); /* Set up port's speed, parameters, etc. */
383 void restore_tty(int);  /* Restore port's original parameters */
384 void setdtr(int, int);  /* Raise or lower port's DTR line */
385 void output(int, unsigned char *, int); /* Output a PPP packet */
386 void wait_input(struct timeval *);
387                                 /* Wait for input, with timeout */
388 void add_fd(int);               /* Add fd to set to wait for */
389 void remove_fd(int);    /* Remove fd from set to wait for */
390 int  read_packet(unsigned char *); /* Read PPP packet */
391 int  get_loop_output(void); /* Read pkts from loopback */
392 void tty_send_config(int, u_int32_t, int, int);
393                                 /* Configure i/f transmit parameters */
394 void tty_set_xaccm(ext_accm);
395                                 /* Set extended transmit ACCM */
396 void tty_recv_config(int, u_int32_t, int, int);
397                                 /* Configure i/f receive parameters */
398 int  ccp_test(int, unsigned char *, int, int);
399                                 /* Test support for compression scheme */
400 void ccp_flags_set(int, int, int);
401                                 /* Set kernel CCP state */
402 int  ccp_fatal_error(int); /* Test for fatal decomp error in kernel */
403 int  get_idle_time(int, struct ppp_idle *);
404                                 /* Find out how long link has been idle */
405 int  get_ppp_stats(int, struct pppd_stats *);
406                                 /* Return link statistics */
407 int  sifvjcomp(int, int, int, int);
408                                 /* Configure VJ TCP header compression */
409 int  sifup(int);                /* Configure i/f up for one protocol */
410 int  sifnpmode(int u, int proto, enum NPmode mode);
411                                 /* Set mode for handling packets for proto */
412 int  sifdown(int);      /* Configure i/f down for one protocol */
413 int  sifaddr(int, u_int32_t, u_int32_t, u_int32_t);
414                                 /* Configure IPv4 addresses for i/f */
415 int  cifaddr(int, u_int32_t, u_int32_t);
416                                 /* Reset i/f IP addresses */
417 #ifdef PPP_WITH_IPV6CP
418 int  sif6up(int);               /* Configure i/f up for IPv6 */
419 int  sif6down(int);     /* Configure i/f down for IPv6 */
420 int  sif6addr(int, eui64_t, eui64_t);
421                                 /* Configure IPv6 addresses for i/f */
422 int  cif6addr(int, eui64_t, eui64_t);
423                                 /* Remove an IPv6 address from i/f */
424 #endif
425 int  sifdefaultroute(int, u_int32_t, u_int32_t, bool replace_default_rt);
426                                 /* Create default route through i/f */
427 int  cifdefaultroute(int, u_int32_t, u_int32_t);
428                                 /* Delete default route through i/f */
429 #ifdef PPP_WITH_IPV6CP
430 int  sif6defaultroute(int, eui64_t, eui64_t);
431                                 /* Create default IPv6 route through i/f */
432 int  cif6defaultroute(int, eui64_t, eui64_t);
433                                 /* Delete default IPv6 route through i/f */
434 #endif
435 int  sifproxyarp(int, u_int32_t);
436                                 /* Add proxy ARP entry for peer */
437 int  cifproxyarp(int, u_int32_t);
438                                 /* Delete proxy ARP entry for peer */
439 u_int32_t GetMask(u_int32_t); /* Get appropriate netmask for address */
440 int  lock(char *);      /* Create lock file for device */
441 int  relock(int);               /* Rewrite lock file with new pid */
442 void unlock(void);      /* Delete previously-created lock file */
443 void logwtmp(const char *, const char *, const char *);
444                                 /* Write entry to wtmp file */
445 int  get_host_seed(void);       /* Get host-dependent random number seed */
446 int  have_route_to(u_int32_t); /* Check if route to addr exists */
447 #ifdef PPP_WITH_FILTER
448 int  set_filters(struct bpf_program *pass, struct bpf_program *active);
449                                 /* Set filter programs in kernel */
450 #endif
451 int  get_if_hwaddr(unsigned char *addr, char *name);
452 int  get_first_ether_hwaddr(unsigned char *addr);
453
454 /* Procedures exported from options.c */
455 int setipaddr(char *, char **, int); /* Set local/remote ip addresses */
456 int  parse_args(int argc, char **argv);
457                                 /* Parse options from arguments given */
458 int  getword(FILE *f, char *word, int *newlinep, char *filename);
459                                 /* Read a word from a file */
460 int  options_from_user(void); /* Parse options from user's .ppprc */
461 int  options_for_tty(void); /* Parse options from /etc/ppp/options.tty */
462 struct wordlist;
463 int  options_from_list(struct wordlist *, int privileged);
464                                 /* Parse options from a wordlist */
465 void check_options(void);       /* check values after all options parsed */
466 int  override_value(char *, int, const char *);
467                                 /* override value if permitted by priority */
468 void print_options(printer_func, void *);
469                                 /* print out values of all options */
470 void showopts(void);
471                 /* show all option names and description */
472 int parse_dotted_ip(char *, u_int32_t *);
473
474 /*
475  * Inline versions of get/put char/short/long.
476  * Pointer is advanced; we assume that both arguments
477  * are lvalues and will already be in registers.
478  * cp MUST be unsigned char *.
479  */
480 #define GETCHAR(c, cp) { \
481         (c) = *(cp)++; \
482 }
483 #define PUTCHAR(c, cp) { \
484         *(cp)++ = (unsigned char) (c); \
485 }
486
487
488 #define GETSHORT(s, cp) { \
489         (s) = *(cp)++ << 8; \
490         (s) |= *(cp)++; \
491 }
492 #define PUTSHORT(s, cp) { \
493         *(cp)++ = (unsigned char) ((s) >> 8); \
494         *(cp)++ = (unsigned char) (s); \
495 }
496
497 #define GETLONG(l, cp) { \
498         (l) = *(cp)++ << 8; \
499         (l) |= *(cp)++; (l) <<= 8; \
500         (l) |= *(cp)++; (l) <<= 8; \
501         (l) |= *(cp)++; \
502 }
503 #define PUTLONG(l, cp) { \
504         *(cp)++ = (unsigned char) ((l) >> 24); \
505         *(cp)++ = (unsigned char) ((l) >> 16); \
506         *(cp)++ = (unsigned char) ((l) >> 8); \
507         *(cp)++ = (unsigned char) (l); \
508 }
509
510 #define INCPTR(n, cp)   ((cp) += (n))
511 #define DECPTR(n, cp)   ((cp) -= (n))
512
513 /*
514  * System dependent definitions for user-level 4.3BSD UNIX implementation.
515  */
516
517 #define TIMEOUT(r, f, t)        ppp_timeout((r), (f), (t), 0)
518 #define UNTIMEOUT(r, f)         ppp_untimeout((r), (f))
519
520 #define BCOPY(s, d, l)          memcpy(d, s, l)
521 #define BZERO(s, n)             memset(s, 0, n)
522 #define BCMP(s1, s2, l)         memcmp(s1, s2, l)
523
524 #define PRINTMSG(m, l)          { info("Remote message: %0.*v", l, m); }
525
526 /*
527  * MAKEHEADER - Add Header fields to a packet.
528  */
529 #define MAKEHEADER(p, t) { \
530     PUTCHAR(PPP_ALLSTATIONS, p); \
531     PUTCHAR(PPP_UI, p); \
532     PUTSHORT(t, p); }
533
534 /*
535  * Debug macros.  Slightly useful for finding bugs in pppd, not particularly
536  * useful for finding out why your connection isn't being established.
537  */
538 #ifdef DEBUGALL
539 #define DEBUGMAIN       1
540 #define DEBUGFSM        1
541 #define DEBUGLCP        1
542 #define DEBUGIPCP       1
543 #define DEBUGIPV6CP     1
544 #define DEBUGUPAP       1
545 #define DEBUGCHAP       1
546 #endif
547
548 #ifndef LOG_PPP                 /* we use LOG_LOCAL2 for syslog by default */
549 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
550   || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
551   || defined(DEBUGCHAP) || defined(DEBUG) || defined(DEBUGIPV6CP)
552 #define LOG_PPP LOG_LOCAL2
553 #else
554 #define LOG_PPP LOG_DAEMON
555 #endif
556 #endif /* LOG_PPP */
557
558 #ifdef DEBUGMAIN
559 #define MAINDEBUG(x)    if (debug) dbglog x
560 #else
561 #define MAINDEBUG(x)
562 #endif
563
564 #ifdef DEBUGSYS
565 #define SYSDEBUG(x)     if (debug) dbglog x
566 #else
567 #define SYSDEBUG(x)
568 #endif
569
570 #ifdef DEBUGFSM
571 #define FSMDEBUG(x)     if (debug) dbglog x
572 #else
573 #define FSMDEBUG(x)
574 #endif
575
576 #ifdef DEBUGLCP
577 #define LCPDEBUG(x)     if (debug) dbglog x
578 #else
579 #define LCPDEBUG(x)
580 #endif
581
582 #ifdef DEBUGIPCP
583 #define IPCPDEBUG(x)    if (debug) dbglog x
584 #else
585 #define IPCPDEBUG(x)
586 #endif
587
588 #ifdef DEBUGIPV6CP
589 #define IPV6CPDEBUG(x)  if (debug) dbglog x
590 #else
591 #define IPV6CPDEBUG(x)
592 #endif
593
594 #ifdef DEBUGUPAP
595 #define UPAPDEBUG(x)    if (debug) dbglog x
596 #else
597 #define UPAPDEBUG(x)
598 #endif
599
600 #ifdef DEBUGCHAP
601 #define CHAPDEBUG(x)    if (debug) dbglog x
602 #else
603 #define CHAPDEBUG(x)
604 #endif
605
606 #ifndef SIGTYPE
607 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
608 #define SIGTYPE void
609 #else
610 #define SIGTYPE int
611 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
612 #endif /* SIGTYPE */
613
614 #ifndef MIN
615 #define MIN(a, b)       ((a) < (b)? (a): (b))
616 #endif
617 #ifndef MAX
618 #define MAX(a, b)       ((a) > (b)? (a): (b))
619 #endif
620
621 #ifndef offsetof
622 #define offsetof(type, member) ((size_t) &((type *)0)->member)
623 #endif
624
625 #endif