1 /* $OpenBSD: pppd.h,v 1.23 2024/08/09 05:16:13 deraadt Exp $ */ 2 3 /* 4 * pppd.h - PPP daemon global declarations. 5 * 6 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * 3. The name "Carnegie Mellon University" must not be used to 21 * endorse or promote products derived from this software without 22 * prior written permission. For permission or any legal 23 * details, please contact 24 * Office of Technology Transfer 25 * Carnegie Mellon University 26 * 5000 Forbes Avenue 27 * Pittsburgh, PA 15213-3890 28 * (412) 268-4387, fax: (412) 268-7395 29 * tech-transfer@andrew.cmu.edu 30 * 31 * 4. Redistributions of any form whatsoever must retain the following 32 * acknowledgment: 33 * "This product includes software developed by Computing Services 34 * at Carnegie Mellon University (http://www.cmu.edu/computing/)." 35 * 36 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO 37 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 38 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 39 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 40 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 41 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 42 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 43 */ 44 45 /* 46 * TODO: 47 */ 48 49 #ifndef __PPPD_H__ 50 #define __PPPD_H__ 51 52 #include <sys/types.h> /* for u_int32_t, if defined */ 53 #include <sys/time.h> /* for struct timeval */ 54 #include <net/ppp_defs.h> 55 #include <stdio.h> /* for FILE */ 56 #include <stdarg.h> 57 #include <signal.h> 58 59 /* 60 * Limits. 61 */ 62 63 #define NUM_PPP 1 /* One PPP interface supported (per process) */ 64 #define MAXWORDLEN 1024 /* max length of word in file (incl null) */ 65 #define MAXARGS 1 /* max # args to a command */ 66 #define MAXNAMELEN 256 /* max length of hostname or name for auth */ 67 #define MAXSECRETLEN 256 /* max length of password or secret */ 68 69 /* 70 * Global variables. 71 */ 72 73 extern int hungup; /* Physical layer has disconnected */ 74 extern int ifunit; /* Interface unit number */ 75 extern char ifname[]; /* Interface name */ 76 extern int ttyfd; /* Serial device file descriptor */ 77 extern char hostname[]; /* Our hostname */ 78 extern u_char outpacket_buf[]; /* Buffer for outgoing packets */ 79 extern int phase; /* Current state of link - see values below */ 80 extern int baud_rate; /* Current link speed in bits/sec */ 81 extern char *__progname; /* Name of this program */ 82 extern int redirect_stderr;/* Connector's stderr should go to file */ 83 extern char peer_authname[];/* Authenticated name of peer */ 84 extern int privileged; /* We were run by real-uid root */ 85 extern int need_holdoff; /* Need holdoff period after link terminates */ 86 extern char **script_env; /* Environment variables for scripts */ 87 extern int detached; /* Have detached from controlling tty */ 88 89 /* 90 * Variables set by command-line options. 91 */ 92 93 extern int debug; /* Debug flag */ 94 extern int kdebugflag; /* Tell kernel to print debug messages */ 95 extern int default_device; /* Using /dev/tty or equivalent */ 96 extern char devnam[]; /* Device name */ 97 extern int crtscts; /* Use hardware flow control */ 98 extern int modem; /* Use modem control lines */ 99 extern int modem_chat; /* Watch carrier detect in chat script */ 100 extern int inspeed; /* Input/Output speed requested */ 101 extern u_int32_t netmask; /* IP netmask to set on interface */ 102 extern int lockflag; /* Create lock file to lock the serial dev */ 103 extern int nodetach; /* Don't detach from controlling tty */ 104 extern char *connector; /* Script to establish physical link */ 105 extern char *disconnector; /* Script to disestablish physical link */ 106 extern char *welcomer; /* Script to welcome client after connection */ 107 extern int maxconnect; /* Maximum connect time (seconds) */ 108 extern char user[]; /* Our name for authenticating ourselves */ 109 extern char passwd[]; /* Password for PAP */ 110 extern int auth_required; /* Peer is required to authenticate */ 111 extern int proxyarp; /* Set up proxy ARP entry for peer */ 112 extern volatile sig_atomic_t persist; /* Reopen link after it goes down */ 113 extern int uselogin; /* Use /etc/passwd for checking PAP */ 114 extern int lcp_echo_interval; /* Interval between LCP echo-requests */ 115 extern int lcp_echo_fails; /* Tolerance to unanswered echo-requests */ 116 extern char our_name[]; /* Our name for authentication purposes */ 117 extern char remote_name[]; /* Peer's name for authentication */ 118 extern int explicit_remote;/* remote_name specified with remotename opt */ 119 extern int usehostname; /* Use hostname for our_name */ 120 extern int disable_defaultip; /* Don't use hostname for default IP adrs */ 121 extern int demand; /* Do dial-on-demand */ 122 extern char *ipparam; /* Extra parameter for ip up/down scripts */ 123 extern int cryptpap; /* Others' PAP passwords are encrypted */ 124 extern int idle_time_limit;/* Shut down link if idle for this long */ 125 extern int holdoff; /* Dead time before restarting */ 126 extern int refuse_pap; /* Don't wanna auth. ourselves with PAP */ 127 extern int refuse_chap; /* Don't wanna auth. ourselves with CHAP */ 128 #ifdef PPP_FILTER 129 extern struct bpf_program pass_filter; /* Filter for pkts to pass */ 130 extern struct bpf_program active_filter; /* Filter for link-active pkts */ 131 #endif 132 133 #ifdef MSLANMAN 134 extern int ms_lanman; /* Nonzero if use LanMan password instead of NT */ 135 /* Has meaning only with MS-CHAP challenges */ 136 #endif 137 138 /* 139 * Values for phase. 140 */ 141 #define PHASE_DEAD 0 142 #define PHASE_INITIALIZE 1 143 #define PHASE_DORMANT 2 144 #define PHASE_ESTABLISH 3 145 #define PHASE_AUTHENTICATE 4 146 #define PHASE_CALLBACK 5 147 #define PHASE_NETWORK 6 148 #define PHASE_TERMINATE 7 149 #define PHASE_HOLDOFF 8 150 151 /* 152 * The following struct gives the addresses of procedures to call 153 * for a particular protocol. 154 */ 155 struct protent { 156 u_short protocol; /* PPP protocol number */ 157 /* Initialization procedure */ 158 void (*init)(int unit); 159 /* Process a received packet */ 160 void (*input)(int unit, u_char *pkt, int len); 161 /* Process a received protocol-reject */ 162 void (*protrej)(int unit); 163 /* Lower layer has come up */ 164 void (*lowerup)(int unit); 165 /* Lower layer has gone down */ 166 void (*lowerdown)(int unit); 167 /* Open the protocol */ 168 void (*open)(int unit); 169 /* Close the protocol */ 170 void (*close)(int unit, char *reason); 171 /* Print a packet in readable form */ 172 int (*printpkt)(u_char *pkt, int len, 173 void (*printer)(void *, char *, ...), void *arg); 174 /* Process a received data packet */ 175 void (*datainput)(int unit, u_char *pkt, int len); 176 int enabled_flag; /* 0 iff protocol is disabled */ 177 char *name; /* Text name of protocol */ 178 /* Check requested options, assign defaults */ 179 void (*check_options)(void); 180 /* Configure interface for demand-dial */ 181 int (*demand_conf)(int unit); 182 /* Say whether to bring up link for this pkt */ 183 int (*active_pkt)(u_char *pkt, int len); 184 }; 185 186 /* Table of pointers to supported protocols */ 187 extern struct protent *protocols[]; 188 189 /* 190 * Prototypes. 191 */ 192 193 /* Procedures exported from main.c. */ 194 void detach(void); /* Detach from controlling tty */ 195 void die(int); /* Cleanup and exit */ 196 void quit(void); /* like die(1) */ 197 void novm(char *); /* Say we ran out of memory, and die */ 198 void timeout(void (*func)(void *), void *arg, int t); 199 /* Call func(arg) after t seconds */ 200 void untimeout(void (*func)(void *), void *arg); 201 /* Cancel call to func(arg) */ 202 int run_program(char *prog, char **args, int must_exist); 203 /* Run program prog with args in child */ 204 void demuxprotrej(int, int); 205 /* Demultiplex a Protocol-Reject */ 206 void format_packet(u_char *, int, void (*) (void *, char *, ...), void *); 207 /* Format a packet in human-readable form */ 208 void log_packet(u_char *, int, char *, int); 209 /* Format a packet and log it with syslog */ 210 void print_string(char *, int, void (*) (void *, char *, ...), void *); 211 /* Format a string for output */ 212 int fmtmsg(char *, int, char *, ...); /* snprintf++ */ 213 int vfmtmsg(char *, int, char *, va_list); /* vsnprintf++ */ 214 void script_setenv(char *, char *); /* set script env var */ 215 216 /* Procedures exported from auth.c */ 217 void link_required(int); /* we are starting to use the link */ 218 void link_terminated(int); /* we are finished with the link */ 219 void link_down(int); /* the LCP layer has left the Opened state */ 220 void link_established(int); /* the link is up; authenticate now */ 221 void np_up(int, int); /* a network protocol has come up */ 222 void np_down(int, int); /* a network protocol has gone down */ 223 void np_finished(int, int); /* a network protocol no longer needs link */ 224 void auth_peer_fail(int, int); 225 /* peer failed to authenticate itself */ 226 void auth_peer_success(int, int, char *, int); 227 /* peer successfully authenticated itself */ 228 void auth_withpeer_fail(int, int); 229 /* we failed to authenticate ourselves */ 230 void auth_withpeer_success(int, int); 231 /* we successfully authenticated ourselves */ 232 void auth_check_options(void); 233 /* check authentication options supplied */ 234 void auth_reset(int); /* check what secrets we have */ 235 int check_passwd(int, char *, int, char *, int, char **, int *); 236 /* Check peer-supplied username/password */ 237 int get_secret(int, char *, char *, char *, int *, int); 238 /* get "secret" for chap */ 239 int auth_ip_addr(int, u_int32_t); 240 /* check if IP address is authorized */ 241 int bad_ip_adrs(u_int32_t); 242 /* check if IP address is unreasonable */ 243 void check_access(FILE *, char *); 244 /* check permissions on secrets file */ 245 246 /* Procedures exported from demand.c */ 247 void demand_conf(void); /* config interface(s) for demand-dial */ 248 void demand_drop(void); /* set all NPs to drop packets */ 249 void demand_unblock(void); /* set all NPs to pass packets */ 250 void demand_rexmit(int); /* retransmit saved frames for an NP */ 251 int loop_chars(unsigned char *, int); /* process chars from loopback */ 252 int loop_frame(unsigned char *, int); /* process frame from loopback */ 253 254 /* Procedures exported from sys-*.c */ 255 void sys_init(void); /* Do system-dependent initialization */ 256 void sys_cleanup(void); /* Restore system state before exiting */ 257 void sys_check_options(void); /* Check options specified */ 258 void sys_close(void); /* Clean up in a child before execing */ 259 int ppp_available(void); /* Test whether ppp kernel support exists */ 260 void open_ppp_loopback(void); /* Open loopback for demand-dialling */ 261 void establish_ppp(int); /* Turn serial port into a ppp interface */ 262 void restore_loop(void); /* Transfer ppp unit back to loopback */ 263 void disestablish_ppp(int); /* Restore port to normal operation */ 264 void clean_check(void); /* Check if line was 8-bit clean */ 265 void set_up_tty(int, int); /* Set up port's speed, parameters, etc. */ 266 void restore_tty(int); /* Restore port's original parameters */ 267 void setdtr(int, int); /* Raise or lower port's DTR line */ 268 void output(int, u_char *, int); /* Output a PPP packet */ 269 void wait_input(struct timeval *); 270 /* Wait for input, with timeout */ 271 void wait_loop_output(struct timeval *); 272 /* Wait for pkt from loopback, with timeout */ 273 void wait_time(struct timeval *); /* Wait for given length of time */ 274 int read_packet(u_char *); /* Read PPP packet */ 275 int get_loop_output(void); /* Read pkts from loopback */ 276 void ppp_send_config(int, int, u_int32_t, int, int); 277 /* Configure i/f transmit parameters */ 278 void ppp_set_xaccm(int, ext_accm); 279 /* Set extended transmit ACCM */ 280 void ppp_recv_config(int, int, u_int32_t, int, int); 281 /* Configure i/f receive parameters */ 282 int ccp_test(int, u_char *, int, int); 283 /* Test support for compression scheme */ 284 void ccp_flags_set(int, int, int); 285 /* Set kernel CCP state */ 286 int ccp_fatal_error(int); /* Test for fatal decomp error in kernel */ 287 int get_idle_time(int, struct ppp_idle *); 288 /* Find out how long link has been idle */ 289 int sifvjcomp(int, int, int, int); 290 /* Configure VJ TCP header compression */ 291 int sifup(int); /* Configure i/f up (for IP) */ 292 int sifnpmode(int u, int proto, enum NPmode mode); 293 /* Set mode for handling packets for proto */ 294 int sifdown(int); /* Configure i/f down (for IP) */ 295 int sifaddr(int, u_int32_t, u_int32_t, u_int32_t); 296 /* Configure IP addresses for i/f */ 297 int cifaddr(int, u_int32_t, u_int32_t); 298 /* Reset i/f IP addresses */ 299 int sifdefaultroute(int, u_int32_t, u_int32_t); 300 /* Create default route through i/f */ 301 int cifdefaultroute(int, u_int32_t, u_int32_t); 302 /* Delete default route through i/f */ 303 int sifproxyarp(int, u_int32_t); 304 /* Add proxy ARP entry for peer */ 305 int cifproxyarp(int, u_int32_t); 306 /* Delete proxy ARP entry for peer */ 307 u_int32_t GetMask(u_int32_t); /* Get appropriate netmask for address */ 308 int lock(char *); /* Create lock file for device */ 309 void unlock(void); /* Delete previously-created lock file */ 310 int daemon(int, int); /* Detach us from terminal session */ 311 void logwtmp(const char *, const char *, const char *); 312 /* Write entry to wtmp file */ 313 #ifdef PPP_FILTER 314 int set_filters(struct bpf_program *pass, struct bpf_program *active); 315 /* Set filter programs in kernel */ 316 #endif 317 318 /* Procedures exported from options.c */ 319 int parse_args(int argc, char **argv); 320 /* Parse options from arguments given */ 321 void usage(void); /* Print a usage message */ 322 int options_from_file(char *filename, int must_exist, int check_prot, 323 int privileged); 324 /* Parse options from an options file */ 325 int options_from_user(void); /* Parse options from user's .ppprc */ 326 int options_for_tty(void); /* Parse options from /etc/ppp/options.tty */ 327 void scan_args(int argc, char **argv); 328 /* Look for tty name in command-line args */ 329 int getword(FILE *f, char *word, int *newlinep, char *filename); 330 /* Read a word from a file */ 331 void option_error(char *fmt, ...); 332 /* Print an error message about an option */ 333 334 /* 335 * This structure is used to store information about certain 336 * options, such as where the option value came from (/etc/ppp/options, 337 * command line, etc.) and whether it came from a privileged source. 338 */ 339 340 struct option_info { 341 int priv; /* was value set by sysadmin? */ 342 char *source; /* where option came from */ 343 }; 344 345 extern struct option_info auth_req_info; 346 extern struct option_info connector_info; 347 extern struct option_info disconnector_info; 348 extern struct option_info welcomer_info; 349 extern struct option_info devnam_info; 350 351 /* 352 * Inline versions of get/put char/short/long. 353 * Pointer is advanced; we assume that both arguments 354 * are lvalues and will already be in registers. 355 * cp MUST be u_char *. 356 */ 357 #define GETCHAR(c, cp) { \ 358 (c) = *(cp)++; \ 359 } 360 #define PUTCHAR(c, cp) { \ 361 *(cp)++ = (u_char) (c); \ 362 } 363 364 365 #define GETSHORT(s, cp) { \ 366 (s) = *(cp)++ << 8; \ 367 (s) |= *(cp)++; \ 368 } 369 #define PUTSHORT(s, cp) { \ 370 *(cp)++ = (u_char) ((s) >> 8); \ 371 *(cp)++ = (u_char) (s); \ 372 } 373 374 #define GETLONG(l, cp) { \ 375 (l) = *(cp)++ << 8; \ 376 (l) |= *(cp)++; (l) <<= 8; \ 377 (l) |= *(cp)++; (l) <<= 8; \ 378 (l) |= *(cp)++; \ 379 } 380 #define PUTLONG(l, cp) { \ 381 *(cp)++ = (u_char) ((l) >> 24); \ 382 *(cp)++ = (u_char) ((l) >> 16); \ 383 *(cp)++ = (u_char) ((l) >> 8); \ 384 *(cp)++ = (u_char) (l); \ 385 } 386 387 #define INCPTR(n, cp) ((cp) += (n)) 388 #define DECPTR(n, cp) ((cp) -= (n)) 389 390 #undef FALSE 391 #define FALSE 0 392 #undef TRUE 393 #define TRUE 1 394 395 /* 396 * System dependent definitions for user-level 4.3BSD UNIX implementation. 397 */ 398 399 #define DEMUXPROTREJ(u, p) demuxprotrej(u, p) 400 401 #define TIMEOUT(r, f, t) timeout((r), (f), (t)) 402 #define UNTIMEOUT(r, f) untimeout((r), (f)) 403 404 #define BCOPY(s, d, l) memcpy(d, s, l) 405 #define BMOVE(s, d, l) memmove(d, s, l) 406 #define BZERO(s, n) memset(s, 0, n) 407 #define EXIT(u) quit() 408 #define EXPLICIT_BZERO(s, n) explicit_bzero(s, n) 409 410 #define PRINTMSG(m, l) { m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); } 411 412 /* 413 * MAKEHEADER - Add Header fields to a packet. 414 */ 415 #define MAKEHEADER(p, t) { \ 416 PUTCHAR(PPP_ALLSTATIONS, p); \ 417 PUTCHAR(PPP_UI, p); \ 418 PUTSHORT(t, p); } 419 420 421 #ifdef DEBUGALL 422 #define DEBUGMAIN 1 423 #define DEBUGFSM 1 424 #define DEBUGLCP 1 425 #define DEBUGIPCP 1 426 #define DEBUGUPAP 1 427 #define DEBUGCHAP 1 428 #endif 429 430 #ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */ 431 #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \ 432 || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \ 433 || defined(DEBUGCHAP) || defined(DEBUG) 434 #define LOG_PPP LOG_LOCAL2 435 #else 436 #define LOG_PPP LOG_DAEMON 437 #endif 438 #endif /* LOG_PPP */ 439 440 #ifdef DEBUGMAIN 441 #define MAINDEBUG(x) if (debug) syslog x 442 #else 443 #define MAINDEBUG(x) 444 #endif 445 446 #ifdef DEBUGSYS 447 #define SYSDEBUG(x) if (debug) syslog x 448 #else 449 #define SYSDEBUG(x) 450 #endif 451 452 #ifdef DEBUGFSM 453 #define FSMDEBUG(x) if (debug) syslog x 454 #else 455 #define FSMDEBUG(x) 456 #endif 457 458 #ifdef DEBUGLCP 459 #define LCPDEBUG(x) if (debug) syslog x 460 #else 461 #define LCPDEBUG(x) 462 #endif 463 464 #ifdef DEBUGIPCP 465 #define IPCPDEBUG(x) if (debug) syslog x 466 #else 467 #define IPCPDEBUG(x) 468 #endif 469 470 #ifdef DEBUGUPAP 471 #define UPAPDEBUG(x) if (debug) syslog x 472 #else 473 #define UPAPDEBUG(x) 474 #endif 475 476 #ifdef DEBUGCHAP 477 #define CHAPDEBUG(x) if (debug) syslog x 478 #else 479 #define CHAPDEBUG(x) 480 #endif 481 482 #ifndef SIGTYPE 483 #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) 484 #define SIGTYPE void 485 #else 486 #define SIGTYPE int 487 #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */ 488 #endif /* SIGTYPE */ 489 490 #ifndef MIN 491 #define MIN(a, b) ((a) < (b)? (a): (b)) 492 #endif 493 #ifndef MAX 494 #define MAX(a, b) ((a) > (b)? (a): (b)) 495 #endif 496 497 #endif /* __PPP_H__ */ 498