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