2005-06-27 05:00:04 +04:00
|
|
|
/* $NetBSD: pppoectl.c,v 1.20 2005/06/27 01:00:06 christos Exp $ */
|
2001-04-29 14:30:41 +04:00
|
|
|
|
2001-01-06 16:00:10 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1997 Joerg Wunsch
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* From: spppcontrol.c,v 1.3 1998/01/07 07:55:26 charnier Exp
|
2001-04-29 14:30:41 +04:00
|
|
|
* From: ispppcontrol
|
2001-01-06 16:00:10 +03:00
|
|
|
*/
|
2003-06-23 15:53:35 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
#ifndef lint
|
2005-06-27 05:00:04 +04:00
|
|
|
__RCSID("$NetBSD: pppoectl.c,v 1.20 2005/06/27 01:00:06 christos Exp $");
|
2003-06-23 15:53:35 +04:00
|
|
|
#endif
|
|
|
|
|
2001-01-06 16:00:10 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/callout.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_sppp.h>
|
2001-04-29 14:30:41 +04:00
|
|
|
#include <net/if_pppoe.h>
|
2001-01-06 16:00:10 +03:00
|
|
|
#include <err.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sysexits.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
static void usage(void);
|
2002-01-04 15:23:00 +03:00
|
|
|
static void print_error(const char *ifname, int error, const char * str);
|
2002-01-07 14:10:25 +03:00
|
|
|
static void print_vals(const char *ifname, int phase, struct spppauthcfg *sp,
|
|
|
|
int lcp_timeout, time_t idle_timeout, int authfailures,
|
2003-09-06 23:35:34 +04:00
|
|
|
int max_auth_failures, u_int maxalive, time_t max_noreceive);
|
2002-01-04 15:23:00 +03:00
|
|
|
const char *phase_name(int phase);
|
|
|
|
const char *proto_name(int proto);
|
|
|
|
const char *authflags(int flags);
|
2003-03-22 17:38:15 +03:00
|
|
|
static void pppoectl_argument(char *arg);
|
2001-01-06 16:00:10 +03:00
|
|
|
|
|
|
|
int hz = 0;
|
|
|
|
|
2003-03-22 17:38:15 +03:00
|
|
|
int set_auth, set_lcp, set_idle_to, set_auth_failure, set_dns,
|
2003-09-06 23:35:34 +04:00
|
|
|
clear_auth_failure_count, set_keepalive;
|
|
|
|
int maxalive = -1;
|
|
|
|
int max_noreceive = -1;
|
2003-03-22 17:38:15 +03:00
|
|
|
struct spppauthcfg spr;
|
|
|
|
struct sppplcpcfg lcp;
|
|
|
|
struct spppstatus status;
|
|
|
|
struct spppidletimeout timeout;
|
|
|
|
struct spppauthfailurestats authfailstats;
|
|
|
|
struct spppauthfailuresettings authfailset;
|
|
|
|
struct spppdnssettings dnssettings;
|
2003-09-06 23:35:34 +04:00
|
|
|
struct spppkeepalivesettings keepalivesettings;
|
2003-03-22 17:38:15 +03:00
|
|
|
|
2001-01-06 16:00:10 +03:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2003-03-22 17:38:15 +03:00
|
|
|
FILE *fp;
|
2001-01-06 16:00:10 +03:00
|
|
|
int s, c;
|
2002-03-02 19:27:02 +03:00
|
|
|
int errs = 0, verbose = 0, dump = 0, dns1 = 0, dns2 = 0;
|
2003-03-22 17:38:15 +03:00
|
|
|
size_t len;
|
2001-04-29 14:30:41 +04:00
|
|
|
const char *eth_if_name, *access_concentrator, *service;
|
2003-03-22 17:38:15 +03:00
|
|
|
const char *ifname, *configname;
|
|
|
|
char *line;
|
2001-01-06 16:00:10 +03:00
|
|
|
int mib[2];
|
|
|
|
struct clockinfo clockinfo;
|
2002-01-07 15:22:02 +03:00
|
|
|
setprogname(argv[0]);
|
|
|
|
|
2001-04-29 14:30:41 +04:00
|
|
|
eth_if_name = NULL;
|
|
|
|
access_concentrator = NULL;
|
|
|
|
service = NULL;
|
2003-03-22 17:38:15 +03:00
|
|
|
configname = NULL;
|
|
|
|
while ((c = getopt(argc, argv, "vde:f:s:a:n:")) != -1)
|
2001-01-06 16:00:10 +03:00
|
|
|
switch (c) {
|
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
|
|
|
|
2002-01-04 15:23:00 +03:00
|
|
|
case 'd':
|
|
|
|
dump++;
|
|
|
|
break;
|
|
|
|
|
2001-04-29 14:30:41 +04:00
|
|
|
case 'e':
|
|
|
|
eth_if_name = optarg;
|
|
|
|
break;
|
|
|
|
|
2003-03-22 17:38:15 +03:00
|
|
|
case 'f':
|
|
|
|
configname = optarg;
|
|
|
|
break;
|
|
|
|
|
2001-04-29 14:30:41 +04:00
|
|
|
case 's':
|
|
|
|
service = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'a':
|
|
|
|
access_concentrator = optarg;
|
|
|
|
break;
|
|
|
|
|
2002-03-02 19:27:02 +03:00
|
|
|
case 'n':
|
|
|
|
if (strcmp(optarg, "1") == 0)
|
|
|
|
dns1 = 1;
|
|
|
|
else if (strcmp(optarg, "2") == 0)
|
|
|
|
dns2 = 1;
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "bad argument \"%s\" to -n (only 1 or two allowed)\n",
|
|
|
|
optarg);
|
|
|
|
errs++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-01-06 16:00:10 +03:00
|
|
|
default:
|
|
|
|
errs++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
argv += optind;
|
|
|
|
argc -= optind;
|
|
|
|
|
|
|
|
if (errs || argc < 1)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
ifname = argv[0];
|
|
|
|
|
|
|
|
/* use a random AF to create the socket */
|
|
|
|
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
|
|
|
|
err(EX_UNAVAILABLE, "ifconfig: socket");
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
|
2001-04-29 14:30:41 +04:00
|
|
|
if (eth_if_name) {
|
|
|
|
struct pppoediscparms parms;
|
|
|
|
int e;
|
|
|
|
|
|
|
|
memset(&parms, 0, sizeof parms);
|
|
|
|
strncpy(parms.ifname, ifname, sizeof(parms.ifname));
|
|
|
|
strncpy(parms.eth_ifname, eth_if_name, sizeof(parms.eth_ifname));
|
|
|
|
if (access_concentrator) {
|
2005-06-27 05:00:04 +04:00
|
|
|
parms.ac_name = access_concentrator;
|
2001-04-29 14:30:41 +04:00
|
|
|
parms.ac_name_len = strlen(access_concentrator);
|
|
|
|
}
|
|
|
|
if (service) {
|
2005-06-27 05:00:04 +04:00
|
|
|
parms.service_name = service;
|
2001-04-29 14:30:41 +04:00
|
|
|
parms.service_name_len = strlen(service);
|
|
|
|
}
|
|
|
|
|
|
|
|
e = ioctl(s, PPPOESETPARMS, &parms);
|
2002-01-04 15:23:00 +03:00
|
|
|
if (e)
|
|
|
|
print_error(ifname, e, "PPPOESETPARMS");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-03-02 19:27:02 +03:00
|
|
|
if (dns1 || dns2) {
|
|
|
|
/* print DNS addresses */
|
|
|
|
int e;
|
|
|
|
struct spppdnsaddrs addrs;
|
|
|
|
memset(&addrs, 0, sizeof addrs);
|
|
|
|
strncpy(addrs.ifname, ifname, sizeof addrs.ifname);
|
|
|
|
e = ioctl(s, SPPPGETDNSADDRS, &addrs);
|
|
|
|
if (e)
|
|
|
|
print_error(ifname, e, "SPPPGETDNSADDRS");
|
|
|
|
if (dns1)
|
|
|
|
printf("%d.%d.%d.%d\n",
|
|
|
|
(addrs.dns[0] >> 24) & 0xff,
|
|
|
|
(addrs.dns[0] >> 16) & 0xff,
|
|
|
|
(addrs.dns[0] >> 8) & 0xff,
|
|
|
|
addrs.dns[0] & 0xff);
|
|
|
|
if (dns2)
|
|
|
|
printf("%d.%d.%d.%d\n",
|
|
|
|
(addrs.dns[1] >> 24) & 0xff,
|
|
|
|
(addrs.dns[1] >> 16) & 0xff,
|
|
|
|
(addrs.dns[1] >> 8) & 0xff,
|
|
|
|
addrs.dns[1] & 0xff);
|
|
|
|
}
|
|
|
|
|
2002-01-04 15:23:00 +03:00
|
|
|
if (dump) {
|
|
|
|
/* dump PPPoE session state */
|
|
|
|
struct pppoeconnectionstate state;
|
|
|
|
int e;
|
|
|
|
|
|
|
|
memset(&state, 0, sizeof state);
|
|
|
|
strncpy(state.ifname, ifname, sizeof state.ifname);
|
|
|
|
e = ioctl(s, PPPOEGETSESSION, &state);
|
|
|
|
if (e)
|
2002-03-02 19:27:02 +03:00
|
|
|
print_error(ifname, e, "PPPOEGETSESSION");
|
2002-01-04 15:23:00 +03:00
|
|
|
|
|
|
|
printf("%s:\tstate = ", ifname);
|
|
|
|
switch(state.state) {
|
|
|
|
case PPPOE_STATE_INITIAL:
|
|
|
|
printf("initial\n"); break;
|
|
|
|
case PPPOE_STATE_PADI_SENT:
|
|
|
|
printf("PADI sent\n"); break;
|
|
|
|
case PPPOE_STATE_PADR_SENT:
|
|
|
|
printf("PADR sent\n"); break;
|
|
|
|
case PPPOE_STATE_SESSION:
|
|
|
|
printf("session\n"); break;
|
|
|
|
case PPPOE_STATE_CLOSING:
|
|
|
|
printf("closing\n"); break;
|
2001-04-29 14:30:41 +04:00
|
|
|
}
|
2002-01-04 15:23:00 +03:00
|
|
|
printf("\tSession ID: 0x%x\n", state.session_id);
|
|
|
|
printf("\tPADI retries: %d\n", state.padi_retry_no);
|
|
|
|
printf("\tPADR retries: %d\n", state.padr_retry_no);
|
|
|
|
|
2001-04-29 14:30:41 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-06 16:00:10 +03:00
|
|
|
|
2002-01-04 15:23:00 +03:00
|
|
|
memset(&spr, 0, sizeof spr);
|
|
|
|
strncpy(spr.ifname, ifname, sizeof spr.ifname);
|
|
|
|
memset(&lcp, 0, sizeof lcp);
|
|
|
|
strncpy(lcp.ifname, ifname, sizeof lcp.ifname);
|
|
|
|
memset(&status, 0, sizeof status);
|
|
|
|
strncpy(status.ifname, ifname, sizeof status.ifname);
|
2002-01-06 23:23:55 +03:00
|
|
|
memset(&timeout, 0, sizeof timeout);
|
|
|
|
strncpy(timeout.ifname, ifname, sizeof timeout.ifname);
|
2002-01-07 14:10:25 +03:00
|
|
|
memset(&authfailstats, 0, sizeof &authfailstats);
|
|
|
|
strncpy(authfailstats.ifname, ifname, sizeof authfailstats.ifname);
|
|
|
|
memset(&authfailset, 0, sizeof authfailset);
|
|
|
|
strncpy(authfailset.ifname, ifname, sizeof authfailset.ifname);
|
2002-03-02 19:27:02 +03:00
|
|
|
memset(&dnssettings, 0, sizeof dnssettings);
|
|
|
|
strncpy(dnssettings.ifname, ifname, sizeof dnssettings.ifname);
|
2003-09-06 23:35:34 +04:00
|
|
|
memset(&keepalivesettings, 0, sizeof keepalivesettings);
|
|
|
|
strncpy(keepalivesettings.ifname, ifname, sizeof keepalivesettings.ifname);
|
2001-01-06 16:00:10 +03:00
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_CLOCKRATE;
|
|
|
|
len = sizeof(clockinfo);
|
|
|
|
if(sysctl(mib, 2, &clockinfo, &len, NULL, 0) == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "error, cannot sysctl kern.clockrate!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
hz = clockinfo.hz;
|
|
|
|
|
2003-03-22 17:38:15 +03:00
|
|
|
if (argc == 0 && !(dns1||dns2) && !configname) {
|
2001-01-06 16:00:10 +03:00
|
|
|
/* list only mode */
|
2002-01-04 15:23:00 +03:00
|
|
|
|
2004-02-13 21:02:05 +03:00
|
|
|
/* first pass, get name lengths */
|
2002-01-04 15:23:00 +03:00
|
|
|
if (ioctl(s, SPPPGETAUTHCFG, &spr) == -1)
|
|
|
|
err(EX_OSERR, "SPPPGETAUTHCFG");
|
|
|
|
/* now allocate buffers for strings */
|
|
|
|
if (spr.myname_length)
|
|
|
|
spr.myname = malloc(spr.myname_length);
|
|
|
|
if (spr.hisname_length)
|
|
|
|
spr.hisname = malloc(spr.hisname_length);
|
|
|
|
/* second pass: get names too */
|
|
|
|
if (ioctl(s, SPPPGETAUTHCFG, &spr) == -1)
|
|
|
|
err(EX_OSERR, "SPPPGETAUTHCFG");
|
|
|
|
|
|
|
|
if (ioctl(s, SPPPGETLCPCFG, &lcp) == -1)
|
|
|
|
err(EX_OSERR, "SPPPGETLCPCFG");
|
|
|
|
if (ioctl(s, SPPPGETSTATUS, &status) == -1)
|
|
|
|
err(EX_OSERR, "SPPPGETSTATUS");
|
2002-01-06 23:23:55 +03:00
|
|
|
if (ioctl(s, SPPPGETIDLETO, &timeout) == -1)
|
|
|
|
err(EX_OSERR, "SPPPGETIDLETO");
|
2002-01-07 14:10:25 +03:00
|
|
|
if (ioctl(s, SPPPGETAUTHFAILURES, &authfailstats) == -1)
|
|
|
|
err(EX_OSERR, "SPPPGETAUTHFAILURES");
|
2003-09-06 23:35:34 +04:00
|
|
|
if (ioctl(s, SPPPGETKEEPALIVE, &keepalivesettings) == -1)
|
|
|
|
err(EX_OSERR, "SPPPGETKEEPALIVE");
|
2002-01-04 15:23:00 +03:00
|
|
|
|
2003-09-06 23:35:34 +04:00
|
|
|
print_vals(ifname, status.phase, &spr, lcp.lcp_timeout,
|
|
|
|
timeout.idle_seconds, authfailstats.auth_failures,
|
|
|
|
authfailstats.max_failures,
|
|
|
|
keepalivesettings.maxalive,
|
|
|
|
keepalivesettings.max_noreceive);
|
2002-01-04 15:23:00 +03:00
|
|
|
|
|
|
|
if (spr.hisname) free(spr.hisname);
|
|
|
|
if (spr.myname) free(spr.myname);
|
2001-01-06 16:00:10 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-22 17:38:15 +03:00
|
|
|
/* first load the config file, then parse command line args */
|
|
|
|
if (configname && (fp = fopen(configname, "r")))
|
2005-02-19 21:26:09 +03:00
|
|
|
while ((line = fparseln(fp, NULL, NULL, NULL,
|
2005-02-19 23:50:26 +03:00
|
|
|
FPARSELN_UNESCALL)) != NULL) {
|
|
|
|
if (line[0] != '\0')
|
|
|
|
pppoectl_argument(line);
|
2005-05-10 10:49:10 +04:00
|
|
|
/*
|
|
|
|
* We do not free(line) here, because we
|
|
|
|
* still have references to parts of the
|
|
|
|
* string collected in the various ioctl
|
|
|
|
* argument structures (and need those).
|
|
|
|
* Yes, this is a memory leak.
|
|
|
|
* We could copy the partial strings instead,
|
|
|
|
* and free those later - but this is a one-shot
|
|
|
|
* program and memory will be freed at process
|
|
|
|
* exit time anyway.
|
|
|
|
*/
|
2005-02-19 23:50:26 +03:00
|
|
|
}
|
|
|
|
|
2003-03-22 17:38:15 +03:00
|
|
|
|
2001-01-06 16:00:10 +03:00
|
|
|
while (argc > 0) {
|
2003-03-22 17:38:15 +03:00
|
|
|
pppoectl_argument(argv[0]);
|
2001-01-06 16:00:10 +03:00
|
|
|
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
|
2002-01-06 23:23:55 +03:00
|
|
|
if (set_auth) {
|
|
|
|
if (ioctl(s, SPPPSETAUTHCFG, &spr) == -1)
|
|
|
|
err(EX_OSERR, "SPPPSETAUTHCFG");
|
|
|
|
}
|
2002-01-04 15:23:00 +03:00
|
|
|
if (set_lcp) {
|
|
|
|
if (ioctl(s, SPPPSETLCPCFG, &lcp) == -1)
|
|
|
|
err(EX_OSERR, "SPPPSETLCPCFG");
|
|
|
|
}
|
2002-01-06 23:23:55 +03:00
|
|
|
if (set_idle_to) {
|
|
|
|
if (ioctl(s, SPPPSETIDLETO, &timeout) == -1)
|
|
|
|
err(EX_OSERR, "SPPPSETIDLETO");
|
|
|
|
}
|
2002-01-07 14:10:25 +03:00
|
|
|
if (set_auth_failure) {
|
|
|
|
if (ioctl(s, SPPPSETAUTHFAILURE, &authfailset) == -1)
|
|
|
|
err(EX_OSERR, "SPPPSETAUTHFAILURE");
|
|
|
|
}
|
2002-09-01 13:42:05 +04:00
|
|
|
if (clear_auth_failure_count && !(set_auth || set_auth_failure)) {
|
|
|
|
/*
|
|
|
|
* We want to clear the auth failure count, but did not
|
|
|
|
* do that implicitly by setting authentication - so
|
|
|
|
* do a zero-effect auth setting change
|
|
|
|
*/
|
|
|
|
if (ioctl(s, SPPPGETAUTHFAILURES, &authfailstats) == -1)
|
|
|
|
err(EX_OSERR, "SPPPGETAUTHFAILURES");
|
|
|
|
authfailset.max_failures = authfailstats.max_failures;
|
|
|
|
if (ioctl(s, SPPPSETAUTHFAILURE, &authfailset) == -1)
|
|
|
|
err(EX_OSERR, "SPPPSETAUTHFAILURE");
|
|
|
|
}
|
2002-03-02 19:27:02 +03:00
|
|
|
if (set_dns) {
|
|
|
|
if (ioctl(s, SPPPSETDNSOPTS, &dnssettings) == -1)
|
|
|
|
err(EX_OSERR, "SPPPSETDNSOPTS");
|
|
|
|
}
|
2003-09-06 23:35:34 +04:00
|
|
|
if (set_keepalive) {
|
|
|
|
if (ioctl(s, SPPPGETKEEPALIVE, &keepalivesettings) == -1)
|
|
|
|
err(EX_OSERR, "SPPPGETKEEPALIVE");
|
|
|
|
if (max_noreceive >= 0)
|
|
|
|
keepalivesettings.max_noreceive = max_noreceive;
|
|
|
|
if (maxalive >= 0)
|
|
|
|
keepalivesettings.maxalive = maxalive;
|
|
|
|
if (ioctl(s, SPPPSETKEEPALIVE, &keepalivesettings) == -1)
|
|
|
|
err(EX_OSERR, "SPPPSETKEEPALIVE");
|
|
|
|
}
|
2001-01-06 16:00:10 +03:00
|
|
|
|
2002-01-07 14:10:25 +03:00
|
|
|
if (verbose) {
|
|
|
|
if (ioctl(s, SPPPGETAUTHFAILURES, &authfailstats) == -1)
|
|
|
|
err(EX_OSERR, "SPPPGETAUTHFAILURES");
|
2003-09-06 23:35:34 +04:00
|
|
|
if (ioctl(s, SPPPGETKEEPALIVE, &keepalivesettings) == -1)
|
|
|
|
err(EX_OSERR, "SPPPGETKEEPALIVE");
|
|
|
|
print_vals(ifname, status.phase, &spr, lcp.lcp_timeout,
|
|
|
|
timeout.idle_seconds, authfailstats.auth_failures,
|
|
|
|
authfailstats.max_failures,
|
|
|
|
keepalivesettings.maxalive,
|
|
|
|
keepalivesettings.max_noreceive);
|
2002-01-07 14:10:25 +03:00
|
|
|
}
|
2001-01-06 16:00:10 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-22 17:38:15 +03:00
|
|
|
static void
|
|
|
|
pppoectl_argument(char *arg)
|
|
|
|
{
|
|
|
|
size_t off;
|
|
|
|
const char *cp;
|
|
|
|
|
|
|
|
#define startswith(a,s) strncmp(a, s, (off = strlen(s))) == 0
|
|
|
|
if (startswith(arg, "authproto=")) {
|
|
|
|
cp = arg + off;
|
|
|
|
if (strcmp(cp, "pap") == 0)
|
|
|
|
spr.myauth =
|
|
|
|
spr.hisauth = SPPP_AUTHPROTO_PAP;
|
|
|
|
else if (strcmp(cp, "chap") == 0)
|
|
|
|
spr.myauth = spr.hisauth = SPPP_AUTHPROTO_CHAP;
|
|
|
|
else if (strcmp(cp, "none") == 0)
|
|
|
|
spr.myauth = spr.hisauth = SPPP_AUTHPROTO_NONE;
|
|
|
|
else
|
|
|
|
errx(EX_DATAERR, "bad auth proto: %s", cp);
|
|
|
|
set_auth = 1;
|
|
|
|
} else if (startswith(arg, "myauthproto=")) {
|
|
|
|
cp = arg + off;
|
|
|
|
if (strcmp(cp, "pap") == 0)
|
|
|
|
spr.myauth = SPPP_AUTHPROTO_PAP;
|
|
|
|
else if (strcmp(cp, "chap") == 0)
|
|
|
|
spr.myauth = SPPP_AUTHPROTO_CHAP;
|
|
|
|
else if (strcmp(cp, "none") == 0)
|
|
|
|
spr.myauth = SPPP_AUTHPROTO_NONE;
|
|
|
|
else
|
|
|
|
errx(EX_DATAERR, "bad auth proto: %s", cp);
|
|
|
|
set_auth = 1;
|
|
|
|
} else if (startswith(arg, "myauthname=")) {
|
|
|
|
spr.myname = arg + off;
|
|
|
|
spr.myname_length = strlen(spr.myname)+1;
|
|
|
|
set_auth = 1;
|
|
|
|
} else if (startswith(arg, "myauthsecret=") || startswith(arg, "myauthkey=")) {
|
|
|
|
spr.mysecret = arg + off;
|
|
|
|
spr.mysecret_length = strlen(spr.mysecret)+1;
|
|
|
|
set_auth = 1;
|
|
|
|
} else if (startswith(arg, "hisauthproto=")) {
|
|
|
|
cp = arg + off;
|
|
|
|
if (strcmp(cp, "pap") == 0)
|
|
|
|
spr.hisauth = SPPP_AUTHPROTO_PAP;
|
|
|
|
else if (strcmp(cp, "chap") == 0)
|
|
|
|
spr.hisauth = SPPP_AUTHPROTO_CHAP;
|
|
|
|
else if (strcmp(cp, "none") == 0)
|
|
|
|
spr.hisauth = SPPP_AUTHPROTO_NONE;
|
|
|
|
else
|
|
|
|
errx(EX_DATAERR, "bad auth proto: %s", cp);
|
|
|
|
set_auth = 1;
|
|
|
|
} else if (startswith(arg, "hisauthname=")) {
|
|
|
|
spr.hisname = arg + off;
|
|
|
|
spr.hisname_length = strlen(spr.hisname)+1;
|
|
|
|
set_auth = 1;
|
|
|
|
} else if (startswith(arg, "hisauthsecret=") || startswith(arg, "hisauthkey=")) {
|
|
|
|
spr.hissecret = arg + off;
|
|
|
|
spr.hissecret_length = strlen(spr.hissecret)+1;
|
|
|
|
set_auth = 1;
|
2003-09-06 23:35:34 +04:00
|
|
|
} else if (startswith(arg, "max-noreceive=")) {
|
|
|
|
max_noreceive = atoi(arg+off);
|
|
|
|
if (max_noreceive < 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"max-noreceive value must be at least 0\n");
|
|
|
|
max_noreceive = -1;
|
|
|
|
} else {
|
|
|
|
set_keepalive = 1;
|
|
|
|
}
|
|
|
|
} else if (startswith(arg, "max-alive-missed=")) {
|
|
|
|
maxalive = atoi(arg+off);
|
|
|
|
if (maxalive < 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"max-alive-missed value must be at least 0\n");
|
|
|
|
maxalive = -1;
|
|
|
|
} else {
|
|
|
|
set_keepalive = 1;
|
|
|
|
}
|
2003-03-22 17:38:15 +03:00
|
|
|
} else if (strcmp(arg, "callin") == 0)
|
|
|
|
spr.hisauthflags |= SPPP_AUTHFLAG_NOCALLOUT;
|
|
|
|
else if (strcmp(arg, "always") == 0)
|
|
|
|
spr.hisauthflags &= ~SPPP_AUTHFLAG_NOCALLOUT;
|
|
|
|
else if (strcmp(arg, "norechallenge") == 0)
|
|
|
|
spr.hisauthflags |= SPPP_AUTHFLAG_NORECHALLENGE;
|
|
|
|
else if (strcmp(arg, "rechallenge") == 0)
|
|
|
|
spr.hisauthflags &= ~SPPP_AUTHFLAG_NORECHALLENGE;
|
|
|
|
#ifndef __NetBSD__
|
|
|
|
else if (strcmp(arg, "enable-vj") == 0)
|
|
|
|
spr.defs.enable_vj = 1;
|
|
|
|
else if (strcmp(arg, "disable-vj") == 0)
|
|
|
|
spr.defs.enable_vj = 0;
|
|
|
|
#endif
|
|
|
|
else if (startswith(arg, "lcp-timeout=")) {
|
|
|
|
int timeout_arg = atoi(arg+off);
|
|
|
|
if ((timeout_arg > 20000) || (timeout_arg <= 0))
|
|
|
|
errx(EX_DATAERR, "bad lcp timeout value: %s",
|
|
|
|
arg+off);
|
|
|
|
lcp.lcp_timeout = timeout_arg * hz / 1000;
|
|
|
|
set_lcp = 1;
|
|
|
|
} else if (startswith(arg, "idle-timeout=")) {
|
|
|
|
timeout.idle_seconds = (time_t)atol(arg+off);
|
|
|
|
set_idle_to = 1;
|
|
|
|
} else if (startswith(arg, "max-auth-failure=")) {
|
|
|
|
authfailset.max_failures = atoi(arg+off);
|
|
|
|
set_auth_failure = 1;
|
|
|
|
} else if (strcmp(arg, "clear-auth-failure") == 0) {
|
|
|
|
clear_auth_failure_count = 1;
|
|
|
|
} else if (startswith(arg, "query-dns=")) {
|
|
|
|
dnssettings.query_dns = atoi(arg+off);
|
|
|
|
set_dns = 1;
|
|
|
|
} else
|
|
|
|
errx(EX_DATAERR, "bad parameter: \"%s\"", arg);
|
|
|
|
}
|
|
|
|
|
2001-01-06 16:00:10 +03:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2002-01-07 15:22:02 +03:00
|
|
|
const char * prog = getprogname();
|
|
|
|
fprintf(stderr,
|
|
|
|
"usage:\n"
|
2003-03-22 17:38:15 +03:00
|
|
|
" %s [-f config] ifname [...]\n"
|
2002-01-07 15:22:02 +03:00
|
|
|
" %s [-v] ifname [{my|his}auth{proto|name|secret}=...] \\\n"
|
|
|
|
" [callin] [always] [{no}rechallenge]\n"
|
2002-03-02 19:27:02 +03:00
|
|
|
" [query-dns=3]\n"
|
2002-01-07 15:22:02 +03:00
|
|
|
" to set authentication names, passwords\n"
|
|
|
|
" and (optional) paramaters\n"
|
2002-09-01 15:28:07 +04:00
|
|
|
" %s [-v] ifname lcp-timeout=ms|idle-timeout=s|\n"
|
2003-09-06 23:35:34 +04:00
|
|
|
" max-noreceive=s|max-alive-missed=cnt|\n"
|
2002-09-01 15:28:07 +04:00
|
|
|
" max-auth-failure=count|clear-auth-failure\n"
|
2002-01-07 15:22:02 +03:00
|
|
|
" to set general parameters\n"
|
|
|
|
" or\n"
|
|
|
|
" %s -e ethernet-ifname ifname\n"
|
|
|
|
" to connect an ethernet interface for PPPoE\n"
|
|
|
|
" %s [-a access-concentrator-name] [-s service-name] ifname\n"
|
|
|
|
" to specify (optional) data for PPPoE sessions\n"
|
|
|
|
" %s -d ifname\n"
|
|
|
|
" to dump the current PPPoE session state\n"
|
2002-06-21 11:48:53 +04:00
|
|
|
" %s -n (1|2) ifname\n"
|
2002-03-02 19:27:02 +03:00
|
|
|
" to print DNS addresses retrieved via query-dns\n"
|
2003-03-22 17:38:15 +03:00
|
|
|
, prog, prog, prog, prog, prog, prog, prog);
|
2001-01-06 16:00:10 +03:00
|
|
|
exit(EX_USAGE);
|
|
|
|
}
|
|
|
|
|
2002-01-04 15:23:00 +03:00
|
|
|
static void
|
2002-01-07 14:10:25 +03:00
|
|
|
print_vals(const char *ifname, int phase, struct spppauthcfg *sp, int lcp_timeout,
|
2003-09-06 23:35:34 +04:00
|
|
|
time_t idle_timeout, int authfailures, int max_auth_failures,
|
|
|
|
u_int maxalive_cnt, time_t max_noreceive_time)
|
2001-01-06 16:00:10 +03:00
|
|
|
{
|
|
|
|
#ifndef __NetBSD__
|
|
|
|
time_t send, recv;
|
|
|
|
#endif
|
|
|
|
|
2002-01-04 15:23:00 +03:00
|
|
|
printf("%s:\tphase=%s\n", ifname, phase_name(phase));
|
|
|
|
if (sp->myauth) {
|
|
|
|
printf("\tmyauthproto=%s myauthname=\"%s\"\n",
|
|
|
|
proto_name(sp->myauth),
|
|
|
|
sp->myname);
|
2001-01-06 16:00:10 +03:00
|
|
|
}
|
2002-01-04 15:23:00 +03:00
|
|
|
if (sp->hisauth) {
|
|
|
|
printf("\thisauthproto=%s hisauthname=\"%s\"%s\n",
|
|
|
|
proto_name(sp->hisauth),
|
|
|
|
sp->hisname,
|
|
|
|
authflags(sp->hisauthflags));
|
2001-01-06 16:00:10 +03:00
|
|
|
}
|
|
|
|
#ifndef __NetBSD__
|
|
|
|
if (sp->defs.pp_phase > PHASE_DEAD) {
|
|
|
|
send = time(NULL) - sp->defs.pp_last_sent;
|
|
|
|
recv = time(NULL) - sp->defs.pp_last_recv;
|
|
|
|
printf("\tidle_time=%ld\n", (send<recv)? send : recv);
|
|
|
|
}
|
|
|
|
#endif
|
2002-01-04 15:23:00 +03:00
|
|
|
|
2001-01-06 16:00:10 +03:00
|
|
|
printf("\tlcp timeout: %.3f s\n",
|
2002-01-04 15:23:00 +03:00
|
|
|
(double)lcp_timeout / hz);
|
|
|
|
|
2002-01-06 23:23:55 +03:00
|
|
|
if (idle_timeout != 0)
|
|
|
|
printf("\tidle timeout = %lu s\n", (unsigned long)idle_timeout);
|
|
|
|
else
|
|
|
|
printf("\tidle timeout = disabled\n");
|
|
|
|
|
2002-01-07 14:10:25 +03:00
|
|
|
if (authfailures != 0)
|
|
|
|
printf("\tauthentication failures = %d\n", authfailures);
|
|
|
|
printf("\tmax-auth-failure = %d\n", max_auth_failures);
|
2003-09-06 23:35:34 +04:00
|
|
|
|
|
|
|
printf("\tmax-noreceive = %ld seconds\n", (long)max_noreceive_time);
|
2004-09-01 23:38:09 +04:00
|
|
|
printf("\tmax-alive-missed = %u unanswered echo requests\n", maxalive_cnt);
|
2003-09-06 23:35:34 +04:00
|
|
|
|
2001-01-06 16:00:10 +03:00
|
|
|
#ifndef __NetBSD__
|
|
|
|
printf("\tenable_vj: %s\n",
|
|
|
|
sp->defs.enable_vj ? "on" : "off");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-01-04 15:23:00 +03:00
|
|
|
phase_name(int phase)
|
2001-01-06 16:00:10 +03:00
|
|
|
{
|
|
|
|
switch (phase) {
|
2002-01-04 15:23:00 +03:00
|
|
|
case SPPP_PHASE_DEAD: return "dead";
|
|
|
|
case SPPP_PHASE_ESTABLISH: return "establish";
|
|
|
|
case SPPP_PHASE_TERMINATE: return "terminate";
|
|
|
|
case SPPP_PHASE_AUTHENTICATE: return "authenticate";
|
|
|
|
case SPPP_PHASE_NETWORK: return "network";
|
2001-01-06 16:00:10 +03:00
|
|
|
}
|
|
|
|
return "illegal";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-01-04 15:23:00 +03:00
|
|
|
proto_name(int proto)
|
2001-01-06 16:00:10 +03:00
|
|
|
{
|
|
|
|
static char buf[12];
|
|
|
|
switch (proto) {
|
2002-01-04 15:23:00 +03:00
|
|
|
case SPPP_AUTHPROTO_PAP: return "pap";
|
|
|
|
case SPPP_AUTHPROTO_CHAP: return "chap";
|
|
|
|
case SPPP_AUTHPROTO_NONE: return "none";
|
2001-01-06 16:00:10 +03:00
|
|
|
}
|
2003-07-12 18:48:10 +04:00
|
|
|
snprintf(buf, sizeof(buf), "0x%x", (unsigned)proto);
|
2001-01-06 16:00:10 +03:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-01-04 15:23:00 +03:00
|
|
|
authflags(int flags)
|
2001-01-06 16:00:10 +03:00
|
|
|
{
|
|
|
|
static char buf[32];
|
|
|
|
buf[0] = '\0';
|
2002-01-04 15:23:00 +03:00
|
|
|
if (flags & SPPP_AUTHFLAG_NOCALLOUT)
|
2003-07-12 18:48:10 +04:00
|
|
|
strlcat(buf, " callin", sizeof(buf));
|
2002-01-04 15:23:00 +03:00
|
|
|
if (flags & SPPP_AUTHFLAG_NORECHALLENGE)
|
2003-07-12 18:48:10 +04:00
|
|
|
strlcat(buf, " norechallenge", sizeof(buf));
|
2001-01-06 16:00:10 +03:00
|
|
|
return buf;
|
|
|
|
}
|
2002-01-04 15:23:00 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
print_error(const char *ifname, int error, const char * str)
|
|
|
|
{
|
|
|
|
if (error == -1)
|
|
|
|
fprintf(stderr, "%s: interface not found\n", ifname);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "%s: %s: %s\n", ifname, str, strerror(error));
|
|
|
|
exit(EX_DATAERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
|