Add support to query the peer for DNS addreses when negotiating IPCP.

Add ioctls to retrieve the results.

While here remove a malloc()/free() of an unused buffer.
This commit is contained in:
martin 2002-03-02 16:23:42 +00:00
parent a973797a7a
commit 493d3dde20
3 changed files with 77 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_sppp.h,v 1.15 2002/01/15 12:28:08 martin Exp $ */
/* $NetBSD: if_sppp.h,v 1.16 2002/03/02 16:23:42 martin Exp $ */
/*
* Copyright (c) 2002 Martin Husemann. All rights reserved.
@ -103,3 +103,19 @@ struct spppauthfailuresettings {
int max_failures; /* max. allowed authorization failures */
};
#define SPPPSETAUTHFAILURE _IOW('i', 128, struct spppauthfailuresettings)
/* set the DNS options we would like to query during PPP negotiation */
struct spppdnssettings {
char ifname[IFNAMSIZ]; /* pppoe interface name */
int query_dns; /* bitmask (bits 0 and 1) for DNS options to query in IPCP */
};
#define SPPPSETDNSOPTS _IOW('i', 129, struct spppdnssettings)
#define SPPPGETDNSOPTS _IOWR('i', 130, struct spppdnssettings)
/* get the DNS addresses we received from the peer */
struct spppdnsaddrs {
char ifname[IFNAMSIZ]; /* pppoe interface name */
u_int32_t dns[2]; /* IP addresses */
};
#define SPPPGETDNSADDRS _IOWR('i', 131, struct spppdnsaddrs)

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_spppsubr.c,v 1.44 2002/02/10 15:17:21 martin Exp $ */
/* $NetBSD: if_spppsubr.c,v 1.45 2002/03/02 16:23:42 martin Exp $ */
/*
* Synchronous PPP/Cisco link level subroutines.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.44 2002/02/10 15:17:21 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.45 2002/03/02 16:23:42 martin Exp $");
#include "opt_inet.h"
#include "opt_ipx.h"
@ -1137,6 +1137,7 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd, void *data)
case SPPPSETLCPCFG:
case SPPPSETIDLETO:
case SPPPSETAUTHFAILURE:
case SPPPSETDNSOPTS:
{
struct proc *p = curproc; /* XXX */
@ -1149,6 +1150,8 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd, void *data)
case SPPPGETSTATUS:
case SPPPGETIDLETO:
case SPPPGETAUTHFAILURES:
case SPPPGETDNSOPTS:
case SPPPGETDNSADDRS:
error = sppp_params(sp, cmd, data);
break;
@ -2714,6 +2717,7 @@ sppp_ipcp_open(struct sppp *sp)
sp->ipcp.flags &= ~(IPCP_HISADDR_SEEN|IPCP_MYADDR_SEEN|IPCP_MYADDR_DYN|IPCP_HISADDR_DYN);
sp->ipcp.req_myaddr = 0;
sp->ipcp.req_hisaddr = 0;
memset(&sp->dns_addrs, 0, sizeof sp->dns_addrs);
sppp_get_ip_addrs(sp, &myaddr, &hisaddr, 0);
/*
@ -2989,15 +2993,12 @@ sppp_ipcp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len)
static void
sppp_ipcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len)
{
u_char *buf, *p;
u_char *p;
struct ifnet *ifp = &sp->pp_if;
int debug = ifp->if_flags & IFF_DEBUG;
u_int32_t wantaddr;
len -= 4;
buf = malloc (len, M_TEMP, M_NOWAIT);
if (!buf)
return;
if (debug)
log(LOG_DEBUG, SPP_FMT "ipcp nak opts:",
@ -3035,6 +3036,20 @@ sppp_ipcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len)
}
}
break;
case IPCP_OPT_PRIMDNS:
if (len >= 6 && p[1] == 6) {
sp->dns_addrs[0] = p[2] << 24 | p[3] << 16 |
p[4] << 8 | p[5];
}
break;
case IPCP_OPT_SECDNS:
if (len >= 6 && p[1] == 6) {
sp->dns_addrs[1] = p[2] << 24 | p[3] << 16 |
p[4] << 8 | p[5];
}
break;
#ifdef notyet
case IPCP_OPT_COMPRESS:
/*
@ -3046,7 +3061,6 @@ sppp_ipcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len)
}
if (debug)
addlog("\n");
free (buf, M_TEMP);
return;
}
@ -3087,7 +3101,7 @@ sppp_ipcp_tlf(struct sppp *sp)
static void
sppp_ipcp_scr(struct sppp *sp)
{
char opt[6 /* compression */ + 6 /* address */];
char opt[6 /* compression */ + 6 /* address */ + 12 /* dns addresses */];
u_int32_t ouraddr;
int i = 0;
@ -3115,6 +3129,23 @@ sppp_ipcp_scr(struct sppp *sp)
opt[i++] = ouraddr;
}
if (sp->query_dns & 1) {
opt[i++] = IPCP_OPT_PRIMDNS;
opt[i++] = 6;
opt[i++] = sp->dns_addrs[0] >> 24;
opt[i++] = sp->dns_addrs[0] >> 16;
opt[i++] = sp->dns_addrs[0] >> 8;
opt[i++] = sp->dns_addrs[0];
}
if (sp->query_dns & 2) {
opt[i++] = IPCP_OPT_SECDNS;
opt[i++] = 6;
opt[i++] = sp->dns_addrs[1] >> 24;
opt[i++] = sp->dns_addrs[1] >> 16;
opt[i++] = sp->dns_addrs[1] >> 8;
opt[i++] = sp->dns_addrs[1];
}
sp->confid[IDX_IPCP] = ++sp->pp_seq[IDX_IPCP];
sppp_cp_send(sp, PPP_IPCP, CONF_REQ, sp->confid[IDX_IPCP], i, &opt);
}
@ -5077,6 +5108,24 @@ sppp_params(struct sppp *sp, int cmd, void *data)
stats->max_failures = sp->pp_max_auth_fail;
}
break;
case SPPPSETDNSOPTS:
{
struct spppdnssettings *req = (struct spppdnssettings*)data;
sp->query_dns = req->query_dns & 3;
}
break;
case SPPPGETDNSOPTS:
{
struct spppdnssettings *req = (struct spppdnssettings*)data;
req->query_dns = sp->query_dns;
}
break;
case SPPPGETDNSADDRS:
{
struct spppdnsaddrs *addrs = (struct spppdnsaddrs*)data;
memcpy(&addrs->dns, &sp->dns_addrs, sizeof addrs->dns);
}
break;
default:
return (EINVAL);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_spppvar.h,v 1.3 2002/01/07 10:49:03 martin Exp $ */
/* $NetBSD: if_spppvar.h,v 1.4 2002/03/02 16:23:42 martin Exp $ */
/*
* Defines for synchronous PPP/Cisco link level subroutines.
@ -89,6 +89,8 @@ struct sppp {
int pp_auth_failures; /* authorization failures */
int pp_max_auth_fail; /* max. allowed authorization failures */
int pp_phase; /* phase we're currently in */
int query_dns; /* 1 if we want to know the dns addresses */
u_int32_t dns_addrs[2];
int state[IDX_COUNT]; /* state machine */
u_char confid[IDX_COUNT]; /* id of last configuration request */
int rst_counter[IDX_COUNT]; /* restart counter */