1 /* $NetBSD: pppoectl.c,v 1.25 2016/01/23 15:41:47 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1997 Joerg Wunsch 5 * 6 * 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 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * From: spppcontrol.c,v 1.3 1998/01/07 07:55:26 charnier Exp 29 * From: ispppcontrol 30 */ 31 #include <sys/cdefs.h> 32 33 #ifndef lint 34 __RCSID("$NetBSD: pppoectl.c,v 1.25 2016/01/23 15:41:47 christos Exp $"); 35 #endif 36 37 38 #include <sys/param.h> 39 #include <sys/callout.h> 40 #include <sys/ioctl.h> 41 #include <sys/socket.h> 42 #include <sys/time.h> 43 #include <sys/sysctl.h> 44 #include <net/if.h> 45 #include <net/if_sppp.h> 46 #include <net/if_pppoe.h> 47 #include <err.h> 48 #include <stdio.h> 49 #include <stdlib.h> 50 #include <string.h> 51 #include <sysexits.h> 52 #include <unistd.h> 53 54 __dead static void usage(void); 55 __dead static void print_error(const char *ifname, int error, const char * str); 56 static void print_vals(const char *ifname, int phase, struct spppauthcfg *sp, 57 int lcp_timeout, time_t idle_timeout, int authfailures, 58 int max_auth_failures, u_int maxalive, time_t max_noreceive); 59 static const char *phase_name(int phase); 60 static const char *proto_name(int proto); 61 static const char *authflags(int flags); 62 static void pppoectl_argument(char *arg); 63 64 static int hz = 0; 65 66 static int set_auth, set_lcp, set_idle_to, set_auth_failure, set_dns, 67 clear_auth_failure_count, set_keepalive; 68 static int maxalive = -1; 69 static int max_noreceive = -1; 70 static struct spppauthcfg spr; 71 static struct sppplcpcfg lcp; 72 static struct spppstatus status; 73 static struct spppidletimeout timeout; 74 static struct spppauthfailurestats authfailstats; 75 static struct spppauthfailuresettings authfailset; 76 static struct spppdnssettings dnssettings; 77 static struct spppkeepalivesettings keepalivesettings; 78 79 int 80 main(int argc, char **argv) 81 { 82 FILE *fp; 83 int s, c; 84 int errs = 0, verbose = 0, dump = 0, dns1 = 0, dns2 = 0; 85 size_t len; 86 const char *eth_if_name, *access_concentrator, *service; 87 const char *ifname, *configname; 88 char *line; 89 int mib[2]; 90 struct clockinfo clockinfo; 91 setprogname(argv[0]); 92 93 eth_if_name = NULL; 94 access_concentrator = NULL; 95 service = NULL; 96 configname = NULL; 97 while ((c = getopt(argc, argv, "vde:f:s:a:n:")) != -1) 98 switch (c) { 99 case 'v': 100 verbose++; 101 break; 102 103 case 'd': 104 dump++; 105 break; 106 107 case 'e': 108 eth_if_name = optarg; 109 break; 110 111 case 'f': 112 configname = optarg; 113 break; 114 115 case 's': 116 service = optarg; 117 break; 118 119 case 'a': 120 access_concentrator = optarg; 121 break; 122 123 case 'n': 124 if (strcmp(optarg, "1") == 0) 125 dns1 = 1; 126 else if (strcmp(optarg, "2") == 0) 127 dns2 = 1; 128 else { 129 fprintf(stderr, "bad argument \"%s\" to -n (only 1 or two allowed)\n", 130 optarg); 131 errs++; 132 } 133 break; 134 135 default: 136 errs++; 137 break; 138 } 139 argv += optind; 140 argc -= optind; 141 142 if (errs || argc < 1) 143 usage(); 144 145 ifname = argv[0]; 146 147 /* use a random AF to create the socket */ 148 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) 149 err(EX_UNAVAILABLE, "ifconfig: socket"); 150 151 argc--; 152 argv++; 153 154 if (eth_if_name) { 155 struct pppoediscparms parms; 156 int e; 157 158 memset(&parms, 0, sizeof parms); 159 strncpy(parms.ifname, ifname, sizeof(parms.ifname)); 160 strncpy(parms.eth_ifname, eth_if_name, sizeof(parms.eth_ifname)); 161 if (access_concentrator) { 162 parms.ac_name = access_concentrator; 163 parms.ac_name_len = strlen(access_concentrator); 164 } 165 if (service) { 166 parms.service_name = service; 167 parms.service_name_len = strlen(service); 168 } 169 170 e = ioctl(s, PPPOESETPARMS, &parms); 171 if (e) 172 print_error(ifname, e, "PPPOESETPARMS"); 173 return 0; 174 } 175 176 if (dns1 || dns2) { 177 /* print DNS addresses */ 178 int e; 179 struct spppdnsaddrs addrs; 180 memset(&addrs, 0, sizeof addrs); 181 strncpy(addrs.ifname, ifname, sizeof addrs.ifname); 182 e = ioctl(s, SPPPGETDNSADDRS, &addrs); 183 if (e) 184 print_error(ifname, e, "SPPPGETDNSADDRS"); 185 if (dns1) 186 printf("%d.%d.%d.%d\n", 187 (addrs.dns[0] >> 24) & 0xff, 188 (addrs.dns[0] >> 16) & 0xff, 189 (addrs.dns[0] >> 8) & 0xff, 190 addrs.dns[0] & 0xff); 191 if (dns2) 192 printf("%d.%d.%d.%d\n", 193 (addrs.dns[1] >> 24) & 0xff, 194 (addrs.dns[1] >> 16) & 0xff, 195 (addrs.dns[1] >> 8) & 0xff, 196 addrs.dns[1] & 0xff); 197 } 198 199 if (dump) { 200 /* dump PPPoE session state */ 201 struct pppoeconnectionstate state; 202 int e; 203 204 memset(&state, 0, sizeof state); 205 strncpy(state.ifname, ifname, sizeof state.ifname); 206 e = ioctl(s, PPPOEGETSESSION, &state); 207 if (e) 208 print_error(ifname, e, "PPPOEGETSESSION"); 209 210 printf("%s:\tstate = ", ifname); 211 switch(state.state) { 212 case PPPOE_STATE_INITIAL: 213 printf("initial\n"); break; 214 case PPPOE_STATE_PADI_SENT: 215 printf("PADI sent\n"); break; 216 case PPPOE_STATE_PADR_SENT: 217 printf("PADR sent\n"); break; 218 case PPPOE_STATE_SESSION: 219 printf("session\n"); break; 220 case PPPOE_STATE_CLOSING: 221 printf("closing\n"); break; 222 } 223 printf("\tSession ID: 0x%x\n", state.session_id); 224 printf("\tPADI retries: %d\n", state.padi_retry_no); 225 printf("\tPADR retries: %d\n", state.padr_retry_no); 226 227 return 0; 228 } 229 230 231 memset(&spr, 0, sizeof spr); 232 strncpy(spr.ifname, ifname, sizeof spr.ifname); 233 memset(&lcp, 0, sizeof lcp); 234 strncpy(lcp.ifname, ifname, sizeof lcp.ifname); 235 memset(&status, 0, sizeof status); 236 strncpy(status.ifname, ifname, sizeof status.ifname); 237 memset(&timeout, 0, sizeof timeout); 238 strncpy(timeout.ifname, ifname, sizeof timeout.ifname); 239 memset(&authfailstats, 0, sizeof authfailstats); 240 strncpy(authfailstats.ifname, ifname, sizeof authfailstats.ifname); 241 memset(&authfailset, 0, sizeof authfailset); 242 strncpy(authfailset.ifname, ifname, sizeof authfailset.ifname); 243 memset(&dnssettings, 0, sizeof dnssettings); 244 strncpy(dnssettings.ifname, ifname, sizeof dnssettings.ifname); 245 memset(&keepalivesettings, 0, sizeof keepalivesettings); 246 strncpy(keepalivesettings.ifname, ifname, sizeof keepalivesettings.ifname); 247 248 mib[0] = CTL_KERN; 249 mib[1] = KERN_CLOCKRATE; 250 len = sizeof(clockinfo); 251 if(sysctl(mib, 2, &clockinfo, &len, NULL, 0) == -1) 252 { 253 fprintf(stderr, "error, cannot sysctl kern.clockrate!\n"); 254 exit(1); 255 } 256 257 hz = clockinfo.hz; 258 259 if (argc == 0 && !(dns1||dns2) && !configname) { 260 /* list only mode */ 261 262 /* first pass, get name lengths */ 263 if (ioctl(s, SPPPGETAUTHCFG, &spr) == -1) 264 err(EX_OSERR, "SPPPGETAUTHCFG"); 265 /* now allocate buffers for strings */ 266 if (spr.myname_length) 267 if ((spr.myname = malloc(spr.myname_length)) == NULL) 268 err(1, NULL); 269 if (spr.hisname_length) 270 if ((spr.hisname = malloc(spr.hisname_length)) == NULL) 271 err(1, NULL); 272 /* second pass: get names too */ 273 if (ioctl(s, SPPPGETAUTHCFG, &spr) == -1) 274 err(EX_OSERR, "SPPPGETAUTHCFG"); 275 276 if (ioctl(s, SPPPGETLCPCFG, &lcp) == -1) 277 err(EX_OSERR, "SPPPGETLCPCFG"); 278 if (ioctl(s, SPPPGETSTATUS, &status) == -1) 279 err(EX_OSERR, "SPPPGETSTATUS"); 280 if (ioctl(s, SPPPGETIDLETO, &timeout) == -1) 281 err(EX_OSERR, "SPPPGETIDLETO"); 282 if (ioctl(s, SPPPGETAUTHFAILURES, &authfailstats) == -1) 283 err(EX_OSERR, "SPPPGETAUTHFAILURES"); 284 if (ioctl(s, SPPPGETKEEPALIVE, &keepalivesettings) == -1) 285 err(EX_OSERR, "SPPPGETKEEPALIVE"); 286 287 print_vals(ifname, status.phase, &spr, lcp.lcp_timeout, 288 timeout.idle_seconds, authfailstats.auth_failures, 289 authfailstats.max_failures, 290 keepalivesettings.maxalive, 291 keepalivesettings.max_noreceive); 292 293 if (spr.hisname) free(spr.hisname); 294 if (spr.myname) free(spr.myname); 295 return 0; 296 } 297 298 /* first load the config file, then parse command line args */ 299 if (configname && (fp = fopen(configname, "r"))) 300 while ((line = fparseln(fp, NULL, NULL, NULL, 301 FPARSELN_UNESCALL)) != NULL) { 302 if (line[0] != '\0') 303 pppoectl_argument(line); 304 /* 305 * We do not free(line) here, because we 306 * still have references to parts of the 307 * string collected in the various ioctl 308 * argument structures (and need those). 309 * Yes, this is a memory leak. 310 * We could copy the partial strings instead, 311 * and free those later - but this is a one-shot 312 * program and memory will be freed at process 313 * exit time anyway. 314 */ 315 } 316 317 318 while (argc > 0) { 319 pppoectl_argument(argv[0]); 320 321 argv++; 322 argc--; 323 } 324 325 if (set_auth) { 326 if (ioctl(s, SPPPSETAUTHCFG, &spr) == -1) 327 err(EX_OSERR, "SPPPSETAUTHCFG"); 328 } 329 if (set_lcp) { 330 if (ioctl(s, SPPPSETLCPCFG, &lcp) == -1) 331 err(EX_OSERR, "SPPPSETLCPCFG"); 332 } 333 if (set_idle_to) { 334 if (ioctl(s, SPPPSETIDLETO, &timeout) == -1) 335 err(EX_OSERR, "SPPPSETIDLETO"); 336 } 337 if (set_auth_failure) { 338 if (ioctl(s, SPPPSETAUTHFAILURE, &authfailset) == -1) 339 err(EX_OSERR, "SPPPSETAUTHFAILURE"); 340 } 341 if (clear_auth_failure_count && !(set_auth || set_auth_failure)) { 342 /* 343 * We want to clear the auth failure count, but did not 344 * do that implicitly by setting authentication - so 345 * do a zero-effect auth setting change 346 */ 347 if (ioctl(s, SPPPGETAUTHFAILURES, &authfailstats) == -1) 348 err(EX_OSERR, "SPPPGETAUTHFAILURES"); 349 authfailset.max_failures = authfailstats.max_failures; 350 if (ioctl(s, SPPPSETAUTHFAILURE, &authfailset) == -1) 351 err(EX_OSERR, "SPPPSETAUTHFAILURE"); 352 } 353 if (set_dns) { 354 if (ioctl(s, SPPPSETDNSOPTS, &dnssettings) == -1) 355 err(EX_OSERR, "SPPPSETDNSOPTS"); 356 } 357 if (set_keepalive) { 358 if (ioctl(s, SPPPGETKEEPALIVE, &keepalivesettings) == -1) 359 err(EX_OSERR, "SPPPGETKEEPALIVE"); 360 if (max_noreceive >= 0) 361 keepalivesettings.max_noreceive = max_noreceive; 362 if (maxalive >= 0) 363 keepalivesettings.maxalive = maxalive; 364 if (ioctl(s, SPPPSETKEEPALIVE, &keepalivesettings) == -1) 365 err(EX_OSERR, "SPPPSETKEEPALIVE"); 366 } 367 368 if (verbose) { 369 if (ioctl(s, SPPPGETAUTHFAILURES, &authfailstats) == -1) 370 err(EX_OSERR, "SPPPGETAUTHFAILURES"); 371 if (ioctl(s, SPPPGETKEEPALIVE, &keepalivesettings) == -1) 372 err(EX_OSERR, "SPPPGETKEEPALIVE"); 373 print_vals(ifname, status.phase, &spr, lcp.lcp_timeout, 374 timeout.idle_seconds, authfailstats.auth_failures, 375 authfailstats.max_failures, 376 keepalivesettings.maxalive, 377 keepalivesettings.max_noreceive); 378 } 379 380 return 0; 381 } 382 383 static void 384 pppoectl_argument(char *arg) 385 { 386 size_t off; 387 const char *cp; 388 389 #define startswith(a,s) strncmp(a, s, (off = strlen(s))) == 0 390 if (startswith(arg, "authproto=")) { 391 cp = arg + off; 392 if (strcmp(cp, "pap") == 0) 393 spr.myauth = 394 spr.hisauth = SPPP_AUTHPROTO_PAP; 395 else if (strcmp(cp, "chap") == 0) 396 spr.myauth = spr.hisauth = SPPP_AUTHPROTO_CHAP; 397 else if (strcmp(cp, "none") == 0) 398 spr.myauth = spr.hisauth = SPPP_AUTHPROTO_NONE; 399 else 400 errx(EX_DATAERR, "bad auth proto: %s", cp); 401 set_auth = 1; 402 } else if (startswith(arg, "myauthproto=")) { 403 cp = arg + off; 404 if (strcmp(cp, "pap") == 0) 405 spr.myauth = SPPP_AUTHPROTO_PAP; 406 else if (strcmp(cp, "chap") == 0) 407 spr.myauth = SPPP_AUTHPROTO_CHAP; 408 else if (strcmp(cp, "none") == 0) 409 spr.myauth = SPPP_AUTHPROTO_NONE; 410 else 411 errx(EX_DATAERR, "bad auth proto: %s", cp); 412 set_auth = 1; 413 } else if (startswith(arg, "myauthname=")) { 414 spr.myname = arg + off; 415 spr.myname_length = strlen(spr.myname)+1; 416 set_auth = 1; 417 } else if (startswith(arg, "myauthsecret=") || startswith(arg, "myauthkey=")) { 418 spr.mysecret = arg + off; 419 spr.mysecret_length = strlen(spr.mysecret)+1; 420 set_auth = 1; 421 } else if (startswith(arg, "hisauthproto=")) { 422 cp = arg + off; 423 if (strcmp(cp, "pap") == 0) 424 spr.hisauth = SPPP_AUTHPROTO_PAP; 425 else if (strcmp(cp, "chap") == 0) 426 spr.hisauth = SPPP_AUTHPROTO_CHAP; 427 else if (strcmp(cp, "none") == 0) 428 spr.hisauth = SPPP_AUTHPROTO_NONE; 429 else 430 errx(EX_DATAERR, "bad auth proto: %s", cp); 431 set_auth = 1; 432 } else if (startswith(arg, "hisauthname=")) { 433 spr.hisname = arg + off; 434 spr.hisname_length = strlen(spr.hisname)+1; 435 set_auth = 1; 436 } else if (startswith(arg, "hisauthsecret=") || startswith(arg, "hisauthkey=")) { 437 spr.hissecret = arg + off; 438 spr.hissecret_length = strlen(spr.hissecret)+1; 439 set_auth = 1; 440 } else if (startswith(arg, "max-noreceive=")) { 441 max_noreceive = atoi(arg+off); 442 if (max_noreceive < 0) { 443 fprintf(stderr, 444 "max-noreceive value must be at least 0\n"); 445 max_noreceive = -1; 446 } else { 447 set_keepalive = 1; 448 } 449 } else if (startswith(arg, "max-alive-missed=")) { 450 maxalive = atoi(arg+off); 451 if (maxalive < 0) { 452 fprintf(stderr, 453 "max-alive-missed value must be at least 0\n"); 454 maxalive = -1; 455 } else { 456 set_keepalive = 1; 457 } 458 } else if (strcmp(arg, "callin") == 0) 459 spr.hisauthflags |= SPPP_AUTHFLAG_NOCALLOUT; 460 else if (strcmp(arg, "always") == 0) 461 spr.hisauthflags &= ~SPPP_AUTHFLAG_NOCALLOUT; 462 else if (strcmp(arg, "norechallenge") == 0) 463 spr.hisauthflags |= SPPP_AUTHFLAG_NORECHALLENGE; 464 else if (strcmp(arg, "rechallenge") == 0) 465 spr.hisauthflags &= ~SPPP_AUTHFLAG_NORECHALLENGE; 466 #ifndef __NetBSD__ 467 else if (strcmp(arg, "enable-vj") == 0) 468 spr.defs.enable_vj = 1; 469 else if (strcmp(arg, "disable-vj") == 0) 470 spr.defs.enable_vj = 0; 471 #endif 472 else if (startswith(arg, "lcp-timeout=")) { 473 int timeout_arg = atoi(arg+off); 474 if ((timeout_arg > 20000) || (timeout_arg <= 0)) 475 errx(EX_DATAERR, "bad lcp timeout value: %s", 476 arg+off); 477 lcp.lcp_timeout = timeout_arg * hz / 1000; 478 set_lcp = 1; 479 } else if (startswith(arg, "idle-timeout=")) { 480 timeout.idle_seconds = (time_t)atol(arg+off); 481 set_idle_to = 1; 482 } else if (startswith(arg, "max-auth-failure=")) { 483 authfailset.max_failures = atoi(arg+off); 484 set_auth_failure = 1; 485 } else if (strcmp(arg, "clear-auth-failure") == 0) { 486 clear_auth_failure_count = 1; 487 } else if (startswith(arg, "query-dns=")) { 488 dnssettings.query_dns = atoi(arg+off); 489 set_dns = 1; 490 } else 491 errx(EX_DATAERR, "bad parameter: \"%s\"", arg); 492 } 493 494 static void 495 usage(void) 496 { 497 const char * prog = getprogname(); 498 fprintf(stderr, 499 "usage:\n" 500 " %s [-f config] ifname [...]\n" 501 " %s [-v] ifname [{my|his}auth{proto|name|secret}=...] \\\n" 502 " [callin] [always] [{no}rechallenge]\n" 503 " [query-dns=3]\n" 504 " to set authentication names, passwords\n" 505 " and (optional) paramaters\n" 506 " %s [-v] ifname lcp-timeout=ms|idle-timeout=s|\n" 507 " max-noreceive=s|max-alive-missed=cnt|\n" 508 " max-auth-failure=count|clear-auth-failure\n" 509 " to set general parameters\n" 510 " or\n" 511 " %s -e ethernet-ifname ifname\n" 512 " to connect an ethernet interface for PPPoE\n" 513 " %s [-a access-concentrator-name] [-s service-name] ifname\n" 514 " to specify (optional) data for PPPoE sessions\n" 515 " %s -d ifname\n" 516 " to dump the current PPPoE session state\n" 517 " %s -n (1|2) ifname\n" 518 " to print DNS addresses retrieved via query-dns\n" 519 , prog, prog, prog, prog, prog, prog, prog); 520 exit(EX_USAGE); 521 } 522 523 static void 524 print_vals(const char *ifname, int phase, struct spppauthcfg *sp, int lcp_timeout, 525 time_t idle_timeout, int authfailures, int max_auth_failures, 526 u_int maxalive_cnt, time_t max_noreceive_time) 527 { 528 #ifndef __NetBSD__ 529 time_t send, recv; 530 #endif 531 532 printf("%s:\tphase=%s\n", ifname, phase_name(phase)); 533 if (sp->myauth) { 534 printf("\tmyauthproto=%s myauthname=\"%s\"\n", 535 proto_name(sp->myauth), 536 sp->myname); 537 } 538 if (sp->hisauth) { 539 printf("\thisauthproto=%s hisauthname=\"%s\"%s\n", 540 proto_name(sp->hisauth), 541 sp->hisname, 542 authflags(sp->hisauthflags)); 543 } 544 #ifndef __NetBSD__ 545 if (sp->defs.pp_phase > PHASE_DEAD) { 546 send = time(NULL) - sp->defs.pp_last_sent; 547 recv = time(NULL) - sp->defs.pp_last_recv; 548 printf("\tidle_time=%ld\n", (send<recv)? send : recv); 549 } 550 #endif 551 552 printf("\tlcp timeout: %.3f s\n", 553 (double)lcp_timeout / hz); 554 555 if (idle_timeout != 0) 556 printf("\tidle timeout = %lu s\n", (unsigned long)idle_timeout); 557 else 558 printf("\tidle timeout = disabled\n"); 559 560 if (authfailures != 0) 561 printf("\tauthentication failures = %d\n", authfailures); 562 printf("\tmax-auth-failure = %d\n", max_auth_failures); 563 564 printf("\tmax-noreceive = %ld seconds\n", (long)max_noreceive_time); 565 printf("\tmax-alive-missed = %u unanswered echo requests\n", maxalive_cnt); 566 567 #ifndef __NetBSD__ 568 printf("\tenable_vj: %s\n", 569 sp->defs.enable_vj ? "on" : "off"); 570 #endif 571 } 572 573 static const char * 574 phase_name(int phase) 575 { 576 switch (phase) { 577 case SPPP_PHASE_DEAD: return "dead"; 578 case SPPP_PHASE_ESTABLISH: return "establish"; 579 case SPPP_PHASE_TERMINATE: return "terminate"; 580 case SPPP_PHASE_AUTHENTICATE: return "authenticate"; 581 case SPPP_PHASE_NETWORK: return "network"; 582 } 583 return "illegal"; 584 } 585 586 static const char * 587 proto_name(int proto) 588 { 589 static char buf[12]; 590 switch (proto) { 591 case SPPP_AUTHPROTO_PAP: return "pap"; 592 case SPPP_AUTHPROTO_CHAP: return "chap"; 593 case SPPP_AUTHPROTO_NONE: return "none"; 594 } 595 snprintf(buf, sizeof(buf), "0x%x", (unsigned)proto); 596 return buf; 597 } 598 599 static const char * 600 authflags(int flags) 601 { 602 static char buf[32]; 603 buf[0] = '\0'; 604 if (flags & SPPP_AUTHFLAG_NOCALLOUT) 605 strlcat(buf, " callin", sizeof(buf)); 606 if (flags & SPPP_AUTHFLAG_NORECHALLENGE) 607 strlcat(buf, " norechallenge", sizeof(buf)); 608 return buf; 609 } 610 611 static void 612 print_error(const char *ifname, int error, const char * str) 613 { 614 if (error == -1) 615 fprintf(stderr, "%s: interface not found\n", ifname); 616 else 617 fprintf(stderr, "%s: %s: %s\n", ifname, str, strerror(error)); 618 exit(EX_DATAERR); 619 } 620 621 622