mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-27 09:12:44 +00:00
MFC r297147, r297148, r297149, r297150, r297151:
Make both the loader and kernel use the interface-mtu option if the dhcp server provides it. Made up of these (semi-)related changes... [kernel...] If the dhcp server provides an interface-mtu option, parse the value and set that mtu on the interface. [libstand...] Garbage collect the bswap routines from libstand, use sys/endian.h. If the dhcp server delivers an interface-mtu option, parse it and store the value in a new global intf_mtu for use by the application. [loader...] If the dhcp server provided an interface-mtu option, transcribe the value to the boot.netif.mtu env var, which will be picked up by pre-existing code in nfs_mountroot() and used to configure the interface accordingly. PR: 187094
This commit is contained in:
parent
bb678412ec
commit
f50fad6455
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/stable/10/; revision=301056
@ -43,7 +43,7 @@ CFLAGS+= -G0 -fno-pic -mno-abicalls
|
||||
.endif
|
||||
|
||||
# standalone components and stuff we have modified locally
|
||||
SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c bswap.c environment.c getopt.c gets.c \
|
||||
SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c environment.c getopt.c gets.c \
|
||||
globals.c pager.c printf.c strdup.c strerror.c strtol.c strtoul.c random.c \
|
||||
sbrk.c twiddle.c zalloc.c zalloc_malloc.c
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/endian.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
|
||||
@ -393,6 +394,13 @@ vend_rfc1048(cp, len)
|
||||
val = (const char *)cp;
|
||||
strlcpy(hostname, val, sizeof(hostname));
|
||||
}
|
||||
if (tag == TAG_INTF_MTU) {
|
||||
if ((val = getenv("dhcp.interface-mtu")) != NULL) {
|
||||
intf_mtu = (u_int)strtoul(val, NULL, 0);
|
||||
} else {
|
||||
intf_mtu = be16dec(cp);
|
||||
}
|
||||
}
|
||||
#ifdef SUPPORT_DHCP
|
||||
if (tag == TAG_DHCP_MSGTYPE) {
|
||||
if(*cp != expected_dhcpmsgtype)
|
||||
|
@ -91,6 +91,7 @@ struct bootp {
|
||||
#define TAG_DOMAINNAME ((unsigned char) 15)
|
||||
#define TAG_SWAPSERVER ((unsigned char) 16)
|
||||
#define TAG_ROOTPATH ((unsigned char) 17)
|
||||
#define TAG_INTF_MTU ((unsigned char) 26)
|
||||
|
||||
#ifdef SUPPORT_DHCP
|
||||
#define TAG_REQ_ADDR ((unsigned char) 50)
|
||||
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Written by Manuel Bouyer <bouyer@netbsd.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *rcsid = "$NetBSD: bswap32.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $";
|
||||
static char *rcsid = "$NetBSD: bswap64.c,v 1.3 2009/03/16 05:59:21 cegger Exp $";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#undef bswap32
|
||||
#undef bswap64
|
||||
|
||||
u_int32_t bswap32(u_int32_t x);
|
||||
u_int64_t bswap64(u_int64_t x);
|
||||
|
||||
u_int32_t
|
||||
bswap32(u_int32_t x)
|
||||
{
|
||||
return ((x << 24) & 0xff000000 ) |
|
||||
((x << 8) & 0x00ff0000 ) |
|
||||
((x >> 8) & 0x0000ff00 ) |
|
||||
((x >> 24) & 0x000000ff );
|
||||
}
|
||||
|
||||
u_int64_t
|
||||
bswap64(u_int64_t x)
|
||||
{
|
||||
#ifdef __LP64__
|
||||
/*
|
||||
* Assume we have wide enough registers to do it without touching
|
||||
* memory.
|
||||
*/
|
||||
return ( (x << 56) & 0xff00000000000000UL ) |
|
||||
( (x << 40) & 0x00ff000000000000UL ) |
|
||||
( (x << 24) & 0x0000ff0000000000UL ) |
|
||||
( (x << 8) & 0x000000ff00000000UL ) |
|
||||
( (x >> 8) & 0x00000000ff000000UL ) |
|
||||
( (x >> 24) & 0x0000000000ff0000UL ) |
|
||||
( (x >> 40) & 0x000000000000ff00UL ) |
|
||||
( (x >> 56) & 0x00000000000000ffUL );
|
||||
#else
|
||||
/*
|
||||
* Split the operation in two 32bit steps.
|
||||
*/
|
||||
u_int32_t tl, th;
|
||||
|
||||
th = bswap32((u_int32_t)(x & 0x00000000ffffffffULL));
|
||||
tl = bswap32((u_int32_t)((x >> 32) & 0x00000000ffffffffULL));
|
||||
return ((u_int64_t)th << 32) | tl;
|
||||
#endif
|
||||
}
|
@ -32,5 +32,6 @@ struct in_addr rootip; /* root ip address */
|
||||
struct in_addr swapip; /* swap ip address */
|
||||
struct in_addr gateip; /* swap ip address */
|
||||
n_long netmask = 0xffffff00; /* subnet or net mask */
|
||||
u_int intf_mtu; /* interface mtu from bootp/dhcp */
|
||||
int errno; /* our old friend */
|
||||
|
||||
|
@ -83,6 +83,7 @@ extern struct in_addr swapip;
|
||||
extern struct in_addr gateip;
|
||||
extern struct in_addr nameip;
|
||||
extern n_long netmask;
|
||||
extern u_int intf_mtu;
|
||||
|
||||
extern int debug; /* defined in the machdep sources */
|
||||
|
||||
|
@ -334,11 +334,6 @@ static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
|
||||
static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
|
||||
static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
|
||||
|
||||
/* swaps (undocumented, useful?) */
|
||||
#ifdef __i386__
|
||||
extern u_int32_t bswap32(u_int32_t x);
|
||||
extern u_int64_t bswap64(u_int64_t x);
|
||||
#endif
|
||||
|
||||
/* null functions for device/filesystem switches (undocumented) */
|
||||
extern int nodev(void);
|
||||
|
@ -171,6 +171,12 @@ net_open(struct open_file *f, ...)
|
||||
setenv("boot.netif.gateway", inet_ntoa(gateip), 1);
|
||||
setenv("boot.nfsroot.server", inet_ntoa(rootip), 1);
|
||||
setenv("boot.nfsroot.path", rootpath, 1);
|
||||
if (intf_mtu != 0) {
|
||||
char mtu[16];
|
||||
sprintf(mtu, "%u", intf_mtu);
|
||||
setenv("boot.netif.mtu", mtu, 1);
|
||||
}
|
||||
|
||||
}
|
||||
netdev_opens++;
|
||||
f->f_devdata = &netdev_sock;
|
||||
|
@ -312,6 +312,11 @@ pxe_open(struct open_file *f, ...)
|
||||
sprintf(temp, "%6D", bootplayer.CAddr, ":");
|
||||
setenv("boot.netif.hwaddr", temp, 1);
|
||||
}
|
||||
if (intf_mtu != 0) {
|
||||
char mtu[16];
|
||||
sprintf(mtu, "%u", intf_mtu);
|
||||
setenv("boot.netif.mtu", mtu, 1);
|
||||
}
|
||||
setenv("boot.nfsroot.server", inet_ntoa(rootip), 1);
|
||||
setenv("boot.nfsroot.path", rootpath, 1);
|
||||
setenv("dhcp.host-name", hostname, 1);
|
||||
|
@ -45,7 +45,7 @@ CFLAGS+= -G0 -fno-pic -mno-abicalls
|
||||
.endif
|
||||
|
||||
# standalone components and stuff we have modified locally
|
||||
SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c bswap.c environment.c getopt.c gets.c \
|
||||
SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c environment.c getopt.c gets.c \
|
||||
globals.c pager.c printf.c strdup.c strerror.c strtol.c strtoul.c random.c \
|
||||
sbrk.c twiddle.c zalloc.c zalloc_malloc.c
|
||||
|
||||
|
@ -42,7 +42,7 @@ CFLAGS+= -msoft-float -D_STANDALONE
|
||||
.endif
|
||||
|
||||
# standalone components and stuff we have modified locally
|
||||
SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c bswap.c environment.c getopt.c gets.c \
|
||||
SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c environment.c getopt.c gets.c \
|
||||
globals.c pager.c printf.c strdup.c strerror.c strtol.c random.c \
|
||||
sbrk.c twiddle.c zalloc.c zalloc_malloc.c
|
||||
|
||||
|
@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/endian.h>
|
||||
#include <sys/jail.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/sockio.h>
|
||||
@ -154,6 +155,7 @@ struct bootpc_ifcontext {
|
||||
int dhcpquerytype; /* dhcp type sent */
|
||||
struct in_addr dhcpserver;
|
||||
int gotdhcpserver;
|
||||
uint16_t mtu;
|
||||
};
|
||||
|
||||
#define TAG_MAXLEN 1024
|
||||
@ -195,6 +197,7 @@ struct bootpc_globalcontext {
|
||||
#define TAG_ROUTERS 3 /* Routers (in order of preference) */
|
||||
#define TAG_HOSTNAME 12 /* Client host name */
|
||||
#define TAG_ROOT 17 /* Root path */
|
||||
#define TAG_INTF_MTU 26 /* Interface MTU Size (RFC2132) */
|
||||
|
||||
/* DHCP specific tags */
|
||||
#define TAG_OVERLOAD 52 /* Option Overload */
|
||||
@ -1030,7 +1033,19 @@ bootpc_adjust_interface(struct bootpc_ifcontext *ifctx,
|
||||
return (0);
|
||||
}
|
||||
|
||||
printf("Adjusted interface %s\n", ifctx->ireq.ifr_name);
|
||||
printf("Adjusted interface %s", ifctx->ireq.ifr_name);
|
||||
|
||||
/* Do BOOTP interface options */
|
||||
if (ifctx->mtu != 0) {
|
||||
printf(" (MTU=%d%s)", ifctx->mtu,
|
||||
(ifctx->mtu > 1514) ? "/JUMBO" : "");
|
||||
ifr->ifr_mtu = ifctx->mtu;
|
||||
error = ifioctl(bootp_so, SIOCSIFMTU, (caddr_t) ifr, td);
|
||||
if (error != 0)
|
||||
panic("%s: SIOCSIFMTU, error=%d", __func__, error);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
/*
|
||||
* Do enough of ifconfig(8) so that the chosen interface
|
||||
* can talk to the servers. (just set the address)
|
||||
@ -1518,6 +1533,11 @@ bootpc_decode_reply(struct nfsv3_diskless *nd, struct bootpc_ifcontext *ifctx,
|
||||
p[i] = '\0';
|
||||
}
|
||||
|
||||
p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
|
||||
TAG_INTF_MTU);
|
||||
if (p != NULL) {
|
||||
ifctx->mtu = be16dec(p);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user