Add a "query-dns" parameter to tell the interface we would like to get

DNS settings from the peer and a "-n" option to retrieve the results
after the PPP connection is established.
This commit is contained in:
martin 2002-03-02 16:27:02 +00:00
parent 493d3dde20
commit 8c33bf88e8
2 changed files with 81 additions and 9 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pppoectl.8,v 1.6 2002/01/09 20:20:54 martin Exp $
.\" $NetBSD: pppoectl.8,v 1.7 2002/03/02 16:27:02 martin Exp $
.\" Copyright (C) 1997 by Joerg Wunsch, Dresden
.\" All rights reserved.
.\"
@ -25,7 +25,7 @@
.\"
.\" From: spppcontrol.1,v 1.1.1.1 1997/10/11 11:30:30 joerg Exp
.\"
.\" $Id: pppoectl.8,v 1.6 2002/01/09 20:20:54 martin Exp $
.\" $Id: pppoectl.8,v 1.7 2002/03/02 16:27:02 martin Exp $
.\"
.\" last edit-date: [Thu Aug 31 10:47:33 2000]
.\"
@ -48,6 +48,7 @@
.Op Fl s Ar service-name
.Op Fl a Ar access-concentrator-name
.Op Fl d
.Op Fl n Ar 1 \&| 2
.Ar ifname
.Sh DESCRIPTION
There are two basic modes of operation: configuring security related
@ -69,6 +70,10 @@ specifies the name of the service connected to.
.It Fl d
dump the current connection state information (this parameter is typically
used alone, for informational purposes, not during interface configuration).
.It Fl n Ar 1 \&| 2
print the IP address of the primary or secondary DNS name server for this
PPP connection. This is only available if DNS query is enabled, see
.Ar query-dns .
.El
.Pp
Typically, not both the access concentrator name and the service name are
@ -223,6 +228,25 @@ retry count. If
is set to
.Em 0
this feature is disabled.
.It Ar query-dns Ns \&= Ns Em flags
During PPP protocol negotiation we can query the peer for addreses of two name
servers. If
.Ar flags
is
.Em 1
only the first server address will be requested, if
.Ar flags
is
.Em 2
the second will be requested. Setting
.Ar flags
to
.Em 3
queries both.
.Pp
The result of the negotiation can be retrieved with the
.Fl n
option.
.El
.Sh EXAMPLES
.Bd -literal

View File

@ -1,4 +1,4 @@
/* $NetBSD: pppoectl.c,v 1.5 2002/01/07 12:22:02 martin Exp $ */
/* $NetBSD: pppoectl.c,v 1.6 2002/03/02 16:27:02 martin Exp $ */
/*
* Copyright (c) 1997 Joerg Wunsch
@ -61,7 +61,7 @@ int
main(int argc, char **argv)
{
int s, c;
int errs = 0, verbose = 0, dump = 0;
int errs = 0, verbose = 0, dump = 0, dns1 = 0, dns2 = 0;
size_t off, len;
const char *ifname, *cp;
const char *eth_if_name, *access_concentrator, *service;
@ -71,8 +71,9 @@ main(int argc, char **argv)
struct spppidletimeout timeout;
struct spppauthfailurestats authfailstats;
struct spppauthfailuresettings authfailset;
struct spppdnssettings dnssettings;
int mib[2];
int set_auth = 0, set_lcp = 0, set_idle_to = 0, set_auth_failure = 0;
int set_auth = 0, set_lcp = 0, set_idle_to = 0, set_auth_failure = 0, set_dns = 0;
struct clockinfo clockinfo;
setprogname(argv[0]);
@ -80,7 +81,7 @@ main(int argc, char **argv)
eth_if_name = NULL;
access_concentrator = NULL;
service = NULL;
while ((c = getopt(argc, argv, "vde:s:a:")) != -1)
while ((c = getopt(argc, argv, "vde:s:a:n:")) != -1)
switch (c) {
case 'v':
verbose++;
@ -102,6 +103,18 @@ main(int argc, char **argv)
access_concentrator = optarg;
break;
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;
default:
errs++;
break;
@ -143,6 +156,29 @@ main(int argc, char **argv)
return 0;
}
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);
}
if (dump) {
/* dump PPPoE session state */
struct pppoeconnectionstate state;
@ -152,7 +188,7 @@ main(int argc, char **argv)
strncpy(state.ifname, ifname, sizeof state.ifname);
e = ioctl(s, PPPOEGETSESSION, &state);
if (e)
print_error(ifname, e, "PPPOEGETSESSION,");
print_error(ifname, e, "PPPOEGETSESSION");
printf("%s:\tstate = ", ifname);
switch(state.state) {
@ -187,6 +223,8 @@ main(int argc, char **argv)
strncpy(authfailstats.ifname, ifname, sizeof authfailstats.ifname);
memset(&authfailset, 0, sizeof authfailset);
strncpy(authfailset.ifname, ifname, sizeof authfailset.ifname);
memset(&dnssettings, 0, sizeof dnssettings);
strncpy(dnssettings.ifname, ifname, sizeof dnssettings.ifname);
mib[0] = CTL_KERN;
mib[1] = KERN_CLOCKRATE;
@ -199,7 +237,7 @@ main(int argc, char **argv)
hz = clockinfo.hz;
if (argc == 0) {
if (argc == 0 && !(dns1||dns2)) {
/* list only mode */
/* first pass, get name lenghts */
@ -310,6 +348,9 @@ main(int argc, char **argv)
} else if (startswith("max-auth-failure=")) {
authfailset.max_failures = atoi(argv[0]+off);
set_auth_failure = 1;
} else if (startswith("query-dns=")) {
dnssettings.query_dns = atoi(argv[0]+off);
set_dns = 1;
} else
errx(EX_DATAERR, "bad parameter: \"%s\"", argv[0]);
@ -333,6 +374,10 @@ main(int argc, char **argv)
if (ioctl(s, SPPPSETAUTHFAILURE, &authfailset) == -1)
err(EX_OSERR, "SPPPSETAUTHFAILURE");
}
if (set_dns) {
if (ioctl(s, SPPPSETDNSOPTS, &dnssettings) == -1)
err(EX_OSERR, "SPPPSETDNSOPTS");
}
if (verbose) {
if (ioctl(s, SPPPGETAUTHFAILURES, &authfailstats) == -1)
@ -351,6 +396,7 @@ usage(void)
"usage:\n"
" %s [-v] ifname [{my|his}auth{proto|name|secret}=...] \\\n"
" [callin] [always] [{no}rechallenge]\n"
" [query-dns=3]\n"
" to set authentication names, passwords\n"
" and (optional) paramaters\n"
" %s [-v] ifname lcp-timeout=ms|idle-timeout=s|max-auth-failure=count\n"
@ -362,7 +408,9 @@ usage(void)
" to specify (optional) data for PPPoE sessions\n"
" %s -d ifname\n"
" to dump the current PPPoE session state\n"
, prog, prog, prog, prog, prog);
" %s -n (1|2)\n"
" to print DNS addresses retrieved via query-dns\n"
, prog, prog, prog, prog, prog, prog);
exit(EX_USAGE);
}