Change the format of the bootparam "gateway" parameter string to

gateway=server:255.255.255.0 because that is the perferred format,
and the sys/libsa code already knows how to parse that format.
(Copied ip_convert here from the libsa code.)
This commit is contained in:
gwr 1997-12-10 20:22:37 +00:00
parent ecd43c7870
commit 0aa79a60f4

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_bootparam.c,v 1.2 1997/09/09 21:36:35 gwr Exp $ */
/* $NetBSD: nfs_bootparam.c,v 1.3 1997/12/10 20:22:37 gwr Exp $ */
/*-
* Copyright (c) 1995, 1997 The NetBSD Foundation, Inc.
@ -88,6 +88,10 @@ static int bp_whoami __P((struct sockaddr_in *bpsin,
static int bp_getfile __P((struct sockaddr_in *bpsin, char *key,
struct nfs_dlmount *ndm));
/* helpers... */
static char * number __P((char *s, int *n));
static u_int32_t ip_convertaddr __P((char *));
/*
* Get client name, gateway address, then
@ -112,7 +116,7 @@ nfs_bootparam(ifp, nd, procp)
struct socket *so;
struct nfs_dlmount *gw_ndm;
char *p;
u_int32_t mask, x;
u_int32_t mask;
int error;
gw_ndm = 0;
@ -224,7 +228,7 @@ nfs_bootparam(ifp, nd, procp)
* parameter "gateway" is requested, and if its returned,
* we use the "server" part of the reply as the gateway,
* and use the "pathname" part of the reply as the mask.
* (The mask comes to us as a string: "0x%x")
* (The mask comes to us as a string: "%d.%d.%d.%d")
*/
if (gw_ip.s_addr) {
/* Our caller will add the route. */
@ -247,34 +251,13 @@ nfs_bootparam(ifp, nd, procp)
if (p == 0)
goto out;
/* have pathname */
/* XXX - Inline: sscanf(p, ":0x%x", &mask) */
mask = 0;
while (*p) {
switch (*p) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
x = (*p - '0');
break;
case 'A': case 'B': case 'C':
case 'D': case 'E': case 'F':
x = (*p - ('A' - 10));
break;
case 'a': case 'b': case 'c':
case 'd': case 'e': case 'f':
x = (*p - ('a' - 10));
break;
default:
mask = x = 0;
break;
}
mask = (mask << 4) + x;
p++;
}
p++; /* skip ':' */
mask = ip_convertaddr(p);
if (mask == 0)
goto out;
/* Save our netmask and update the network interface. */
nd->nd_mask.s_addr = htonl(mask);
nd->nd_mask.s_addr = mask;
sin = (struct sockaddr_in *)&ireq.ifr_addr;
sin->sin_len = sizeof(*sin);
sin->sin_family = AF_INET;
@ -501,3 +484,43 @@ out:
}
/* helpers... */
static char *
number(s, n)
char *s;
int *n;
{
for (*n = 0; ((*s) >= '0' && (*s) <= '9'); s++)
*n = (*n * 10) + *s - '0';
return s;
}
static u_int32_t
ip_convertaddr(p)
char *p;
{
u_int32_t addr = 0, n;
if (p == (char *)0 || *p == '\0')
return 0;
p = number(p, &n);
addr |= (n << 24) & 0xff000000;
if (*p == '\0' || *p++ != '.')
return 0;
p = number(p, &n);
addr |= (n << 16) & 0xff0000;
if (*p == '\0' || *p++ != '.')
return 0;
p = number(p, &n);
addr |= (n << 8) & 0xff00;
if (*p == '\0' || *p++ != '.')
return 0;
p = number(p, &n);
addr |= n & 0xff;
if (*p != '\0')
return 0;
return htonl(addr);
}