Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Feb 2018 19:51:29 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r329132 - in stable/11: lib/libstand sys/boot/libsa sys/boot/libsa/amd64 sys/boot/libsa/i386 sys/boot/libsa/mips sys/boot/libsa/powerpc sys/boot/libsa/sparc64
Message-ID:  <201802111951.w1BJpTWb014816@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Sun Feb 11 19:51:29 2018
New Revision: 329132
URL: https://svnweb.freebsd.org/changeset/base/329132

Log:
  MFC r324551: Move lib/libstand to sys/boot/libsa

Added:
  stable/11/sys/boot/libsa/Makefile.depend
     - copied unchanged from r329131, stable/11/lib/libstand/Makefile.depend
  stable/11/sys/boot/libsa/__main.c
     - copied unchanged from r329131, stable/11/lib/libstand/__main.c
  stable/11/sys/boot/libsa/amd64/
     - copied from r329131, stable/11/lib/libstand/amd64/
  stable/11/sys/boot/libsa/arp.c
     - copied unchanged from r329131, stable/11/lib/libstand/arp.c
  stable/11/sys/boot/libsa/assert.c
     - copied unchanged from r329131, stable/11/lib/libstand/assert.c
  stable/11/sys/boot/libsa/bcd.c
     - copied unchanged from r329131, stable/11/lib/libstand/bcd.c
  stable/11/sys/boot/libsa/bootp.c
     - copied unchanged from r329131, stable/11/lib/libstand/bootp.c
  stable/11/sys/boot/libsa/bootp.h
     - copied unchanged from r329131, stable/11/lib/libstand/bootp.h
  stable/11/sys/boot/libsa/bootparam.c
     - copied unchanged from r329131, stable/11/lib/libstand/bootparam.c
  stable/11/sys/boot/libsa/bootparam.h
     - copied unchanged from r329131, stable/11/lib/libstand/bootparam.h
  stable/11/sys/boot/libsa/bzipfs.c
     - copied unchanged from r329131, stable/11/lib/libstand/bzipfs.c
  stable/11/sys/boot/libsa/cd9660.c
     - copied unchanged from r329131, stable/11/lib/libstand/cd9660.c
  stable/11/sys/boot/libsa/close.c
     - copied unchanged from r329131, stable/11/lib/libstand/close.c
  stable/11/sys/boot/libsa/closeall.c
     - copied unchanged from r329131, stable/11/lib/libstand/closeall.c
  stable/11/sys/boot/libsa/dev.c
     - copied unchanged from r329131, stable/11/lib/libstand/dev.c
  stable/11/sys/boot/libsa/dosfs.c
     - copied unchanged from r329131, stable/11/lib/libstand/dosfs.c
  stable/11/sys/boot/libsa/dosfs.h
     - copied unchanged from r329131, stable/11/lib/libstand/dosfs.h
  stable/11/sys/boot/libsa/environment.c
     - copied unchanged from r329131, stable/11/lib/libstand/environment.c
  stable/11/sys/boot/libsa/ether.c
     - copied unchanged from r329131, stable/11/lib/libstand/ether.c
  stable/11/sys/boot/libsa/ext2fs.c
     - copied unchanged from r329131, stable/11/lib/libstand/ext2fs.c
  stable/11/sys/boot/libsa/fstat.c
     - copied unchanged from r329131, stable/11/lib/libstand/fstat.c
  stable/11/sys/boot/libsa/getopt.c
     - copied unchanged from r329131, stable/11/lib/libstand/getopt.c
  stable/11/sys/boot/libsa/gets.c
     - copied unchanged from r329131, stable/11/lib/libstand/gets.c
  stable/11/sys/boot/libsa/globals.c
     - copied unchanged from r329131, stable/11/lib/libstand/globals.c
  stable/11/sys/boot/libsa/gzipfs.c
     - copied unchanged from r329131, stable/11/lib/libstand/gzipfs.c
  stable/11/sys/boot/libsa/i386/
     - copied from r329131, stable/11/lib/libstand/i386/
  stable/11/sys/boot/libsa/in_cksum.c
     - copied unchanged from r329131, stable/11/lib/libstand/in_cksum.c
  stable/11/sys/boot/libsa/inet_ntoa.c
     - copied unchanged from r329131, stable/11/lib/libstand/inet_ntoa.c
  stable/11/sys/boot/libsa/ioctl.c
     - copied unchanged from r329131, stable/11/lib/libstand/ioctl.c
  stable/11/sys/boot/libsa/iodesc.h
     - copied unchanged from r329131, stable/11/lib/libstand/iodesc.h
  stable/11/sys/boot/libsa/ip.c
     - copied unchanged from r329131, stable/11/lib/libstand/ip.c
  stable/11/sys/boot/libsa/libstand.3
     - copied unchanged from r329131, stable/11/lib/libstand/libstand.3
  stable/11/sys/boot/libsa/lseek.c
     - copied unchanged from r329131, stable/11/lib/libstand/lseek.c
  stable/11/sys/boot/libsa/mips/
     - copied from r329131, stable/11/lib/libstand/mips/
  stable/11/sys/boot/libsa/nandfs.c
     - copied unchanged from r329131, stable/11/lib/libstand/nandfs.c
  stable/11/sys/boot/libsa/net.c
     - copied unchanged from r329131, stable/11/lib/libstand/net.c
  stable/11/sys/boot/libsa/net.h
     - copied unchanged from r329131, stable/11/lib/libstand/net.h
  stable/11/sys/boot/libsa/netif.c
     - copied unchanged from r329131, stable/11/lib/libstand/netif.c
  stable/11/sys/boot/libsa/netif.h
     - copied unchanged from r329131, stable/11/lib/libstand/netif.h
  stable/11/sys/boot/libsa/nfs.c
     - copied unchanged from r329131, stable/11/lib/libstand/nfs.c
  stable/11/sys/boot/libsa/nfsv2.h
     - copied unchanged from r329131, stable/11/lib/libstand/nfsv2.h
  stable/11/sys/boot/libsa/nullfs.c
     - copied unchanged from r329131, stable/11/lib/libstand/nullfs.c
  stable/11/sys/boot/libsa/open.c
     - copied unchanged from r329131, stable/11/lib/libstand/open.c
  stable/11/sys/boot/libsa/pager.c
     - copied unchanged from r329131, stable/11/lib/libstand/pager.c
  stable/11/sys/boot/libsa/pkgfs.c
     - copied unchanged from r329131, stable/11/lib/libstand/pkgfs.c
  stable/11/sys/boot/libsa/powerpc/
     - copied from r329131, stable/11/lib/libstand/powerpc/
  stable/11/sys/boot/libsa/printf.c
     - copied unchanged from r329131, stable/11/lib/libstand/printf.c
  stable/11/sys/boot/libsa/qdivrem.c
     - copied unchanged from r329131, stable/11/lib/libstand/qdivrem.c
  stable/11/sys/boot/libsa/quad.h
     - copied unchanged from r329131, stable/11/lib/libstand/quad.h
  stable/11/sys/boot/libsa/random.c
     - copied unchanged from r329131, stable/11/lib/libstand/random.c
  stable/11/sys/boot/libsa/rarp.c
     - copied unchanged from r329131, stable/11/lib/libstand/rarp.c
  stable/11/sys/boot/libsa/read.c
     - copied unchanged from r329131, stable/11/lib/libstand/read.c
  stable/11/sys/boot/libsa/readdir.c
     - copied unchanged from r329131, stable/11/lib/libstand/readdir.c
  stable/11/sys/boot/libsa/rpc.c
     - copied unchanged from r329131, stable/11/lib/libstand/rpc.c
  stable/11/sys/boot/libsa/rpc.h
     - copied unchanged from r329131, stable/11/lib/libstand/rpc.h
  stable/11/sys/boot/libsa/rpcv2.h
     - copied unchanged from r329131, stable/11/lib/libstand/rpcv2.h
  stable/11/sys/boot/libsa/saioctl.h
     - copied unchanged from r329131, stable/11/lib/libstand/saioctl.h
  stable/11/sys/boot/libsa/sbrk.c
     - copied unchanged from r329131, stable/11/lib/libstand/sbrk.c
  stable/11/sys/boot/libsa/sparc64/
     - copied from r329131, stable/11/lib/libstand/sparc64/
  stable/11/sys/boot/libsa/splitfs.c
     - copied unchanged from r329131, stable/11/lib/libstand/splitfs.c
  stable/11/sys/boot/libsa/stand.h
     - copied unchanged from r329131, stable/11/lib/libstand/stand.h
  stable/11/sys/boot/libsa/stat.c
     - copied unchanged from r329131, stable/11/lib/libstand/stat.c
  stable/11/sys/boot/libsa/strcasecmp.c
     - copied unchanged from r329131, stable/11/lib/libstand/strcasecmp.c
  stable/11/sys/boot/libsa/strdup.c
     - copied unchanged from r329131, stable/11/lib/libstand/strdup.c
  stable/11/sys/boot/libsa/strerror.c
     - copied unchanged from r329131, stable/11/lib/libstand/strerror.c
  stable/11/sys/boot/libsa/strtol.c
     - copied unchanged from r329131, stable/11/lib/libstand/strtol.c
  stable/11/sys/boot/libsa/strtoul.c
     - copied unchanged from r329131, stable/11/lib/libstand/strtoul.c
  stable/11/sys/boot/libsa/tftp.c
     - copied unchanged from r329131, stable/11/lib/libstand/tftp.c
  stable/11/sys/boot/libsa/tftp.h
     - copied unchanged from r329131, stable/11/lib/libstand/tftp.h
  stable/11/sys/boot/libsa/twiddle.c
     - copied unchanged from r329131, stable/11/lib/libstand/twiddle.c
  stable/11/sys/boot/libsa/udp.c
     - copied unchanged from r329131, stable/11/lib/libstand/udp.c
  stable/11/sys/boot/libsa/ufs.c
     - copied unchanged from r329131, stable/11/lib/libstand/ufs.c
  stable/11/sys/boot/libsa/uuid_from_string.c
     - copied unchanged from r329131, stable/11/lib/libstand/uuid_from_string.c
  stable/11/sys/boot/libsa/uuid_to_string.c
     - copied unchanged from r329131, stable/11/lib/libstand/uuid_to_string.c
  stable/11/sys/boot/libsa/write.c
     - copied unchanged from r329131, stable/11/lib/libstand/write.c
  stable/11/sys/boot/libsa/zalloc.c
     - copied unchanged from r329131, stable/11/lib/libstand/zalloc.c
  stable/11/sys/boot/libsa/zalloc_defs.h
     - copied unchanged from r329131, stable/11/lib/libstand/zalloc_defs.h
  stable/11/sys/boot/libsa/zalloc_malloc.c
     - copied unchanged from r329131, stable/11/lib/libstand/zalloc_malloc.c
  stable/11/sys/boot/libsa/zalloc_mem.h
     - copied unchanged from r329131, stable/11/lib/libstand/zalloc_mem.h
  stable/11/sys/boot/libsa/zalloc_protos.h
     - copied unchanged from r329131, stable/11/lib/libstand/zalloc_protos.h
Deleted:
  stable/11/lib/libstand/
Modified:
  stable/11/sys/boot/libsa/Makefile

Modified: stable/11/sys/boot/libsa/Makefile
==============================================================================
--- stable/11/sys/boot/libsa/Makefile	Sun Feb 11 19:35:42 2018	(r329131)
+++ stable/11/sys/boot/libsa/Makefile	Sun Feb 11 19:51:29 2018	(r329132)
@@ -1,14 +1,163 @@
 # $FreeBSD$
+# Originally from	$NetBSD: Makefile,v 1.21 1997/10/26 22:08:38 lukem Exp $
+#
+# Notes:
+# - We don't use the libc strerror/sys_errlist because the string table is
+#   quite large.
+#
 
+PACKAGE=lib${LIB}
+MK_PROFILE=	no
+MK_SSP=		no
+
 .include <src.opts.mk>
 
-.include "../Makefile.inc"
+LIBSTAND_SRC?=	${.CURDIR}
+LIBSTAND_CPUARCH?=${MACHINE_CPUARCH}
+LIBC_SRC=	${LIBSTAND_SRC}/../libc
 
-LIBSTAND_SRC=	${SASRC}
-LIBC_SRC=	${SRCTOP}/lib/libc
-INTERNALLIB=
-INCS=
-MAN=
-.PATH:	${SASRC}
+LIB=		stand
+NO_PIC=
+INCS?=		stand.h
+MAN?=		libstand.3
 
-.include "${SASRC}/Makefile"
+WARNS?=		0
+
+CFLAGS+= -I${LIBSTAND_SRC}
+
+# standalone components and stuff we have modified locally
+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
+
+# private (pruned) versions of libc string functions
+SRCS+=	strcasecmp.c
+
+.PATH: ${LIBC_SRC}/net
+
+SRCS+= ntoh.c
+
+# string functions from libc
+.PATH: ${LIBC_SRC}/string
+SRCS+=	bcmp.c bcopy.c bzero.c ffs.c fls.c \
+	memccpy.c memchr.c memcmp.c memcpy.c memmove.c memset.c \
+	qdivrem.c strcat.c strchr.c strcmp.c strcpy.c stpcpy.c stpncpy.c \
+	strcspn.c strlcat.c strlcpy.c strlen.c strncat.c strncmp.c strncpy.c \
+	strnlen.c strpbrk.c strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c
+.if ${MACHINE_CPUARCH} == "arm"
+.PATH: ${LIBC_SRC}/arm/gen
+
+# Do not generate movt/movw, because the relocation fixup for them does not
+# translate to the -Bsymbolic -pie format required by self_reloc() in loader(8).
+# Also, the fpu is not available in a standalone environment.
+.if ${COMPILER_VERSION} < 30800
+CFLAGS.clang+=	-mllvm -arm-use-movt=0
+.else
+CFLAGS.clang+=	-mno-movt
+.endif
+CFLAGS.clang+=	-mfpu=none
+
+# Compiler support functions
+.PATH: ${LIBSTAND_SRC}/../../contrib/compiler-rt/lib/builtins/
+# __clzsi2 and ctzsi2 for various builtin functions
+SRCS+=	clzsi2.c ctzsi2.c
+# Divide and modulus functions called by the compiler
+SRCS+=	 divmoddi4.c  divmodsi4.c  divdi3.c  divsi3.c  moddi3.c  modsi3.c
+SRCS+=	udivmoddi4.c udivmodsi4.c udivdi3.c udivsi3.c umoddi3.c umodsi3.c
+
+.PATH: ${LIBSTAND_SRC}/../../contrib/compiler-rt/lib/builtins/arm/
+SRCS+=	aeabi_idivmod.S aeabi_ldivmod.S aeabi_uidivmod.S aeabi_uldivmod.S
+SRCS+=	aeabi_memcmp.S aeabi_memcpy.S aeabi_memmove.S aeabi_memset.S
+.endif
+
+.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "riscv"
+.PATH: ${LIBC_SRC}/${MACHINE_CPUARCH}/gen
+.endif
+
+.if ${MACHINE_CPUARCH} == "powerpc"
+.PATH: ${LIBC_SRC}/quad
+SRCS+=	ashldi3.c ashrdi3.c
+SRCS+=	syncicache.c
+.endif
+
+# uuid functions from libc
+.PATH: ${LIBC_SRC}/uuid
+SRCS+= uuid_create_nil.c uuid_equal.c uuid_from_string.c uuid_is_nil.c uuid_to_string.c
+
+# _setjmp/_longjmp
+.PATH: ${LIBSTAND_SRC}/${LIBSTAND_CPUARCH}
+SRCS+=	_setjmp.S
+
+# decompression functionality from libbz2
+# NOTE: to actually test this functionality after libbz2 upgrade compile
+# loader(8) with LOADER_BZIP2_SUPPORT defined
+.PATH: ${LIBSTAND_SRC}/../../contrib/bzip2
+CFLAGS+= -DBZ_NO_STDIO -DBZ_NO_COMPRESS
+SRCS+=	libstand_bzlib_private.h
+
+.for file in bzlib.c crctable.c decompress.c huffman.c randtable.c
+SRCS+=	_${file}
+CLEANFILES+=	_${file}
+
+_${file}: ${file}
+	sed "s|bzlib_private\.h|libstand_bzlib_private.h|" \
+	    ${.ALLSRC} > ${.TARGET}
+.endfor
+
+CLEANFILES+= libstand_bzlib_private.h
+libstand_bzlib_private.h: bzlib_private.h
+	sed -e 's|<stdlib.h>|"stand.h"|' \
+		${.ALLSRC} > ${.TARGET}
+
+# decompression functionality from zlib
+.PATH: ${LIBSTAND_SRC}/../../contrib/zlib
+CFLAGS+=-DHAVE_MEMCPY -I${LIBSTAND_SRC}/../../contrib/zlib
+SRCS+=	adler32.c crc32.c libstand_zutil.h libstand_gzguts.h
+
+.for file in infback.c inffast.c inflate.c inftrees.c zutil.c
+SRCS+=	_${file}
+CLEANFILES+=	_${file}
+
+_${file}: ${file}
+	sed -e "s|zutil\.h|libstand_zutil.h|" \
+	    -e "s|gzguts\.h|libstand_gzguts.h|" \
+	    ${.ALLSRC} > ${.TARGET}
+.endfor
+
+# depend on stand.h being able to be included multiple times
+.for file in zutil.h gzguts.h
+CLEANFILES+= libstand_${file}
+libstand_${file}: ${file}
+	sed -e 's|<fcntl.h>|"stand.h"|' \
+	    -e 's|<stddef.h>|"stand.h"|' \
+	    -e 's|<string.h>|"stand.h"|' \
+	    -e 's|<stdio.h>|"stand.h"|' \
+	    -e 's|<stdlib.h>|"stand.h"|' \
+	    ${.ALLSRC} > ${.TARGET}
+.endfor
+
+# io routines
+SRCS+=	closeall.c dev.c ioctl.c nullfs.c stat.c \
+	fstat.c close.c lseek.c open.c read.c write.c readdir.c
+
+# network routines
+SRCS+=	arp.c ether.c ip.c inet_ntoa.c in_cksum.c net.c udp.c netif.c rpc.c
+
+# network info services:
+SRCS+=	bootp.c rarp.c bootparam.c
+
+# boot filesystems
+SRCS+=	ufs.c nfs.c cd9660.c tftp.c gzipfs.c bzipfs.c
+SRCS+=	dosfs.c ext2fs.c
+SRCS+=	splitfs.c
+SRCS+=	pkgfs.c
+.if ${MK_NAND} != "no"
+SRCS+=	nandfs.c
+.endif
+
+# explicit_bzero
+.PATH: ${SRCTOP}/sys/libkern
+SRCS+=  explicit_bzero.c
+
+.include <bsd.stand.mk>
+.include <bsd.lib.mk>

Copied: stable/11/sys/boot/libsa/Makefile.depend (from r329131, stable/11/lib/libstand/Makefile.depend)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/boot/libsa/Makefile.depend	Sun Feb 11 19:51:29 2018	(r329132, copy of r329131, stable/11/lib/libstand/Makefile.depend)
@@ -0,0 +1,15 @@
+# $FreeBSD$
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+	include \
+	include/arpa \
+	include/xlocale \
+	lib/libbz2 \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif

Copied: stable/11/sys/boot/libsa/__main.c (from r329131, stable/11/lib/libstand/__main.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/boot/libsa/__main.c	Sun Feb 11 19:51:29 2018	(r329132, copy of r329131, stable/11/lib/libstand/__main.c)
@@ -0,0 +1,43 @@
+/*	$NetBSD: __main.c,v 1.4 1996/03/14 18:52:03 christos Exp $	*/
+
+/*
+ * Copyright (c) 1993 Christopher G. Demetriou
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Christopher G. Demetriou.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+
+void __main(void);
+
+void
+__main(void)
+{
+}

Copied: stable/11/sys/boot/libsa/arp.c (from r329131, stable/11/lib/libstand/arp.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/boot/libsa/arp.c	Sun Feb 11 19:51:29 2018	(r329132, copy of r329131, stable/11/lib/libstand/arp.c)
@@ -0,0 +1,305 @@
+/*	$NetBSD: arp.c,v 1.18 1997/07/07 15:52:49 drochner Exp $	*/
+
+/*
+ * Copyright (c) 1992 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * 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.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
+ *
+ * @(#) Header: arp.c,v 1.5 93/07/15 05:52:26 leres Exp  (LBL)
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+
+#include <netinet/in_systm.h>
+
+#include <string.h>
+
+#include "stand.h"
+#include "net.h"
+
+/* Cache stuff */
+#define ARP_NUM 8			/* need at most 3 arp entries */
+
+struct arp_list {
+	struct in_addr	addr;
+	u_char		ea[6];
+} arp_list[ARP_NUM] = {
+	/* XXX - net order `INADDR_BROADCAST' must be a constant */
+	{ {0xffffffff}, BA }
+};
+int arp_num = 1;
+
+/* Local forwards */
+static	ssize_t arpsend(struct iodesc *, void *, size_t);
+static	ssize_t arprecv(struct iodesc *, void **, void **, time_t);
+
+/* Broadcast an ARP packet, asking who has addr on interface d */
+u_char *
+arpwhohas(struct iodesc *d, struct in_addr addr)
+{
+	int i;
+	struct ether_arp *ah;
+	struct arp_list *al;
+	void *pkt;
+	struct {
+		struct ether_header eh;
+		struct {
+			struct ether_arp arp;
+			u_char pad[18]; 	/* 60 - sizeof(...) */
+		} data;
+	} wbuf;
+
+	/* Try for cached answer first */
+	for (i = 0, al = arp_list; i < arp_num; ++i, ++al)
+		if (addr.s_addr == al->addr.s_addr)
+			return (al->ea);
+
+	/* Don't overflow cache */
+	if (arp_num > ARP_NUM - 1) {
+		arp_num = 1;	/* recycle */
+		printf("arpwhohas: overflowed arp_list!\n");
+	}
+
+#ifdef ARP_DEBUG
+ 	if (debug)
+ 	    printf("arpwhohas: send request for %s\n", inet_ntoa(addr));
+#endif
+
+	bzero((char*)&wbuf.data, sizeof(wbuf.data));
+	ah = &wbuf.data.arp;
+	ah->arp_hrd = htons(ARPHRD_ETHER);
+	ah->arp_pro = htons(ETHERTYPE_IP);
+	ah->arp_hln = sizeof(ah->arp_sha); /* hardware address length */
+	ah->arp_pln = sizeof(ah->arp_spa); /* protocol address length */
+	ah->arp_op = htons(ARPOP_REQUEST);
+	MACPY(d->myea, ah->arp_sha);
+	bcopy(&d->myip, ah->arp_spa, sizeof(ah->arp_spa));
+	/* Leave zeros in arp_tha */
+	bcopy(&addr, ah->arp_tpa, sizeof(ah->arp_tpa));
+
+	/* Store ip address in cache (incomplete entry). */
+	al->addr = addr;
+
+	pkt = NULL;
+	ah = NULL;
+	i = sendrecv(d,
+	    arpsend, &wbuf.data, sizeof(wbuf.data),
+	    arprecv, &pkt, (void **)&ah);
+	if (i == -1) {
+		panic("arp: no response for %s\n",
+			  inet_ntoa(addr));
+	}
+
+	/* Store ethernet address in cache */
+#ifdef ARP_DEBUG
+ 	if (debug) {
+		struct ether_header *eh;
+
+		eh = (struct ether_header *)((uintptr_t)pkt + ETHER_ALIGN);
+		printf("arp: response from %s\n",
+		    ether_sprintf(eh->ether_shost));
+		printf("arp: cacheing %s --> %s\n",
+		    inet_ntoa(addr), ether_sprintf(ah->arp_sha));
+	}
+#endif
+	MACPY(ah->arp_sha, al->ea);
+	++arp_num;
+
+	free(pkt);
+	return (al->ea);
+}
+
+static ssize_t
+arpsend(struct iodesc *d, void *pkt, size_t len)
+{
+
+#ifdef ARP_DEBUG
+ 	if (debug)
+		printf("arpsend: called\n");
+#endif
+
+	return (sendether(d, pkt, len, bcea, ETHERTYPE_ARP));
+}
+
+/*
+ * Returns 0 if this is the packet we're waiting for
+ * else -1 (and errno == 0)
+ */
+static ssize_t
+arprecv(struct iodesc *d, void **pkt, void **payload, time_t tleft)
+{
+	ssize_t n;
+	struct ether_arp *ah;
+	u_int16_t etype;	/* host order */
+	void *ptr;
+
+#ifdef ARP_DEBUG
+ 	if (debug)
+		printf("arprecv: ");
+#endif
+
+	ptr = NULL;
+	n = readether(d, &ptr, (void **)&ah, tleft, &etype);
+	errno = 0;	/* XXX */
+	if (n == -1 || n < sizeof(struct ether_arp)) {
+#ifdef ARP_DEBUG
+		if (debug)
+			printf("bad len=%d\n", n);
+#endif
+		free(ptr);
+		return (-1);
+	}
+
+	if (etype != ETHERTYPE_ARP) {
+#ifdef ARP_DEBUG
+		if (debug)
+			printf("not arp type=%d\n", etype);
+#endif
+		free(ptr);
+		return (-1);
+	}
+
+	/* Ethernet address now checked in readether() */
+	if (ah->arp_hrd != htons(ARPHRD_ETHER) ||
+	    ah->arp_pro != htons(ETHERTYPE_IP) ||
+	    ah->arp_hln != sizeof(ah->arp_sha) ||
+	    ah->arp_pln != sizeof(ah->arp_spa) )
+	{
+#ifdef ARP_DEBUG
+		if (debug)
+			printf("bad hrd/pro/hln/pln\n");
+#endif
+		free(ptr);
+		return (-1);
+	}
+
+	if (ah->arp_op == htons(ARPOP_REQUEST)) {
+#ifdef ARP_DEBUG
+		if (debug)
+			printf("is request\n");
+#endif
+		arp_reply(d, ah);
+		free(ptr);
+		return (-1);
+	}
+
+	if (ah->arp_op != htons(ARPOP_REPLY)) {
+#ifdef ARP_DEBUG
+		if (debug)
+			printf("not ARP reply\n");
+#endif
+		free(ptr);
+		return (-1);
+	}
+
+	/* Is the reply from the source we want? */
+	if (bcmp(&arp_list[arp_num].addr,
+			 ah->arp_spa, sizeof(ah->arp_spa)))
+	{
+#ifdef ARP_DEBUG
+		if (debug)
+			printf("unwanted address\n");
+#endif
+		free(ptr);
+		return (-1);
+	}
+	/* We don't care who the reply was sent to. */
+
+	/* We have our answer. */
+#ifdef ARP_DEBUG
+ 	if (debug)
+		printf("got it\n");
+#endif
+	*pkt = ptr;
+	*payload = ah;
+	return (n);
+}
+
+/*
+ * Convert an ARP request into a reply and send it.
+ * Notes:  Re-uses buffer.  Pad to length = 46.
+ */
+void
+arp_reply(struct iodesc *d, void *pkt)
+{
+	struct ether_arp *arp = pkt;
+
+	if (arp->arp_hrd != htons(ARPHRD_ETHER) ||
+	    arp->arp_pro != htons(ETHERTYPE_IP) ||
+	    arp->arp_hln != sizeof(arp->arp_sha) ||
+	    arp->arp_pln != sizeof(arp->arp_spa) )
+	{
+#ifdef ARP_DEBUG
+		if (debug)
+			printf("arp_reply: bad hrd/pro/hln/pln\n");
+#endif
+		return;
+	}
+
+	if (arp->arp_op != htons(ARPOP_REQUEST)) {
+#ifdef ARP_DEBUG
+		if (debug)
+			printf("arp_reply: not request!\n");
+#endif
+		return;
+	}
+
+	/* If we are not the target, ignore the request. */
+	if (bcmp(arp->arp_tpa, &d->myip, sizeof(arp->arp_tpa)))
+		return;
+
+#ifdef ARP_DEBUG
+	if (debug) {
+		printf("arp_reply: to %s\n", ether_sprintf(arp->arp_sha));
+	}
+#endif
+
+	arp->arp_op = htons(ARPOP_REPLY);
+	/* source becomes target */
+	bcopy(arp->arp_sha, arp->arp_tha, sizeof(arp->arp_tha));
+	bcopy(arp->arp_spa, arp->arp_tpa, sizeof(arp->arp_tpa));
+	/* here becomes source */
+	bcopy(d->myea,  arp->arp_sha, sizeof(arp->arp_sha));
+	bcopy(&d->myip, arp->arp_spa, sizeof(arp->arp_spa));
+
+	/*
+	 * No need to get fancy here.  If the send fails, the
+	 * requestor will just ask again.
+	 */
+	(void) sendether(d, pkt, sizeof(*arp) + 18,
+	                 arp->arp_tha, ETHERTYPE_ARP);
+}

Copied: stable/11/sys/boot/libsa/assert.c (from r329131, stable/11/lib/libstand/assert.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/boot/libsa/assert.c	Sun Feb 11 19:51:29 2018	(r329132, copy of r329131, stable/11/lib/libstand/assert.c)
@@ -0,0 +1,44 @@
+/*-
+ * Copyright (c) 1998 Michael Smith.
+ * 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 AUTHOR AND CONTRIBUTORS ``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 AUTHOR OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <assert.h>
+
+#include "stand.h"
+
+void
+__assert(const char *func, const char *file, int line, const char *expression)
+{
+	if (func == NULL)
+		panic("Assertion failed: (%s), file %s, line %d.\n",
+		    expression, file, line);
+	else
+		panic(
+		    "Assertion failed: (%s), function %s, file %s, line %d.\n",
+		    expression, func, file, line);
+}

Copied: stable/11/sys/boot/libsa/bcd.c (from r329131, stable/11/lib/libstand/bcd.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/boot/libsa/bcd.c	Sun Feb 11 19:51:29 2018	(r329132, copy of r329131, stable/11/lib/libstand/bcd.c)
@@ -0,0 +1,38 @@
+/*
+ * Some data-tables that are often used.
+ * Cannot be copyrighted.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+
+u_char const bcd2bin_data[] = {
+	 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 0, 0, 0, 0, 0, 0,
+	10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 0, 0, 0, 0, 0,
+	20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0, 0, 0, 0, 0, 0,
+	30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0, 0, 0, 0, 0, 0,
+	40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 0, 0, 0, 0, 0, 0,
+	50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 0, 0, 0, 0, 0, 0,
+	60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 0, 0, 0, 0, 0, 0,
+	70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 0, 0, 0, 0, 0, 0,
+	80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 0, 0, 0, 0, 0, 0,
+	90, 91, 92, 93, 94, 95, 96, 97, 98, 99
+};
+
+u_char const bin2bcd_data[] = {
+	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
+	0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,
+	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+	0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
+	0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
+	0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+	0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
+	0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
+	0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99
+};
+
+/* This is actually used with radix [2..36] */
+char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz";

Copied: stable/11/sys/boot/libsa/bootp.c (from r329131, stable/11/lib/libstand/bootp.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/boot/libsa/bootp.c	Sun Feb 11 19:51:29 2018	(r329132, copy of r329131, stable/11/lib/libstand/bootp.c)
@@ -0,0 +1,791 @@
+/*	$NetBSD: bootp.c,v 1.14 1998/02/16 11:10:54 drochner Exp $	*/
+
+/*
+ * Copyright (c) 1992 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * 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.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
+ *
+ * @(#) Header: bootp.c,v 1.4 93/09/11 03:13:51 leres Exp  (LBL)
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <stddef.h>
+#include <sys/types.h>
+#include <sys/limits.h>
+#include <sys/endian.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+
+#include <string.h>
+
+#define BOOTP_DEBUGxx
+#define SUPPORT_DHCP
+
+#define	DHCP_ENV_NOVENDOR	1	/* do not parse vendor options */
+#define	DHCP_ENV_PXE		10	/* assume pxe vendor options */
+#define	DHCP_ENV_FREEBSD	11	/* assume freebsd vendor options */
+/* set DHCP_ENV to one of the values above to export dhcp options to kenv */
+#define DHCP_ENV		DHCP_ENV_NO_VENDOR
+
+#include "stand.h"
+#include "net.h"
+#include "netif.h"
+#include "bootp.h"
+
+
+struct in_addr servip;
+
+static time_t	bot;
+
+static	char vm_rfc1048[4] = VM_RFC1048;
+#ifdef BOOTP_VEND_CMU
+static	char vm_cmu[4] = VM_CMU;
+#endif
+
+/* Local forwards */
+static	ssize_t bootpsend(struct iodesc *, void *, size_t);
+static	ssize_t bootprecv(struct iodesc *, void **, void **, time_t);
+static	int vend_rfc1048(u_char *, u_int);
+#ifdef BOOTP_VEND_CMU
+static	void vend_cmu(u_char *);
+#endif
+
+#ifdef DHCP_ENV		/* export the dhcp response to kenv */
+struct dhcp_opt;
+static void setenv_(u_char *cp,  u_char *ep, struct dhcp_opt *opts);
+#else
+#define setenv_(a, b, c)
+#endif
+
+#ifdef SUPPORT_DHCP
+static char expected_dhcpmsgtype = -1, dhcp_ok;
+struct in_addr dhcp_serverip;
+#endif
+struct bootp *bootp_response;
+size_t bootp_response_size;
+
+static void
+bootp_fill_request(unsigned char *bp_vend)
+{
+	/*
+	 * We are booting from PXE, we want to send the string
+	 * 'PXEClient' to the DHCP server so you have the option of
+	 * only responding to PXE aware dhcp requests.
+	 */
+	bp_vend[0] = TAG_CLASSID;
+	bp_vend[1] = 9;
+	bcopy("PXEClient", &bp_vend[2], 9);
+	bp_vend[11] = TAG_USER_CLASS;
+	/* len of each user class + number of user class */
+	bp_vend[12] = 8;
+	/* len of the first user class */
+	bp_vend[13] = 7;
+	bcopy("FreeBSD", &bp_vend[14], 7);
+	bp_vend[21] = TAG_PARAM_REQ;
+	bp_vend[22] = 7;
+	bp_vend[23] = TAG_ROOTPATH;
+	bp_vend[24] = TAG_HOSTNAME;
+	bp_vend[25] = TAG_SWAPSERVER;
+	bp_vend[26] = TAG_GATEWAY;
+	bp_vend[27] = TAG_SUBNET_MASK;
+	bp_vend[28] = TAG_INTF_MTU;
+	bp_vend[29] = TAG_SERVERID;
+	bp_vend[30] = TAG_END;
+}
+
+/* Fetch required bootp infomation */
+void
+bootp(int sock)
+{
+	void *pkt;
+	struct iodesc *d;
+	struct bootp *bp;
+	struct {
+		u_char header[HEADER_SIZE];
+		struct bootp wbootp;
+	} wbuf;
+	struct bootp *rbootp;
+
+#ifdef BOOTP_DEBUG
+ 	if (debug)
+		printf("bootp: socket=%d\n", sock);
+#endif
+	if (!bot)
+		bot = getsecs();
+	
+	if (!(d = socktodesc(sock))) {
+		printf("bootp: bad socket. %d\n", sock);
+		return;
+	}
+#ifdef BOOTP_DEBUG
+ 	if (debug)
+		printf("bootp: d=%lx\n", (long)d);
+#endif
+
+	bp = &wbuf.wbootp;
+	bzero(bp, sizeof(*bp));
+
+	bp->bp_op = BOOTREQUEST;
+	bp->bp_htype = 1;		/* 10Mb Ethernet (48 bits) */
+	bp->bp_hlen = 6;
+	bp->bp_xid = htonl(d->xid);
+	MACPY(d->myea, bp->bp_chaddr);
+	strncpy(bp->bp_file, bootfile, sizeof(bp->bp_file));
+	bcopy(vm_rfc1048, bp->bp_vend, sizeof(vm_rfc1048));
+#ifdef SUPPORT_DHCP
+	bp->bp_vend[4] = TAG_DHCP_MSGTYPE;
+	bp->bp_vend[5] = 1;
+	bp->bp_vend[6] = DHCPDISCOVER;
+	bootp_fill_request(&bp->bp_vend[7]);
+
+#else
+	bp->bp_vend[4] = TAG_END;
+#endif
+
+	d->myip.s_addr = INADDR_ANY;
+	d->myport = htons(IPPORT_BOOTPC);
+	d->destip.s_addr = INADDR_BROADCAST;
+	d->destport = htons(IPPORT_BOOTPS);
+
+#ifdef SUPPORT_DHCP
+	expected_dhcpmsgtype = DHCPOFFER;
+	dhcp_ok = 0;
+#endif
+
+	if(sendrecv(d,
+		    bootpsend, bp, sizeof(*bp),
+		    bootprecv, &pkt, (void **)&rbootp) == -1) {
+	    printf("bootp: no reply\n");
+	    return;
+	}
+
+#ifdef SUPPORT_DHCP
+	if(dhcp_ok) {
+		u_int32_t leasetime;
+		bp->bp_vend[6] = DHCPREQUEST;
+		bp->bp_vend[7] = TAG_REQ_ADDR;
+		bp->bp_vend[8] = 4;
+		bcopy(&rbootp->bp_yiaddr, &bp->bp_vend[9], 4);
+		bp->bp_vend[13] = TAG_SERVERID;
+		bp->bp_vend[14] = 4;
+		bcopy(&dhcp_serverip.s_addr, &bp->bp_vend[15], 4);
+		bp->bp_vend[19] = TAG_LEASETIME;
+		bp->bp_vend[20] = 4;
+		leasetime = htonl(300);
+		bcopy(&leasetime, &bp->bp_vend[21], 4);
+		bootp_fill_request(&bp->bp_vend[25]);
+
+		expected_dhcpmsgtype = DHCPACK;
+
+		free(pkt);
+		if(sendrecv(d,
+			    bootpsend, bp, sizeof(*bp),
+			    bootprecv, &pkt, (void **)&rbootp) == -1) {
+			printf("DHCPREQUEST failed\n");
+			return;
+		}
+	}
+#endif
+
+	myip = d->myip = rbootp->bp_yiaddr;
+	servip = rbootp->bp_siaddr;
+	if (rootip.s_addr == INADDR_ANY)
+		rootip = servip;
+	bcopy(rbootp->bp_file, bootfile, sizeof(bootfile));
+	bootfile[sizeof(bootfile) - 1] = '\0';
+
+	if (!netmask) {
+		if (IN_CLASSA(ntohl(myip.s_addr)))
+			netmask = htonl(IN_CLASSA_NET);
+		else if (IN_CLASSB(ntohl(myip.s_addr)))
+			netmask = htonl(IN_CLASSB_NET);
+		else
+			netmask = htonl(IN_CLASSC_NET);
+#ifdef BOOTP_DEBUG
+		if (debug)
+			printf("'native netmask' is %s\n", intoa(netmask));
+#endif
+	}
+
+#ifdef BOOTP_DEBUG
+	if (debug)
+		printf("mask: %s\n", intoa(netmask));
+#endif
+
+	/* We need a gateway if root is on a different net */
+	if (!SAMENET(myip, rootip, netmask)) {
+#ifdef BOOTP_DEBUG
+		if (debug)
+			printf("need gateway for root ip\n");
+#endif
+	}
+
+	/* Toss gateway if on a different net */
+	if (!SAMENET(myip, gateip, netmask)) {
+#ifdef BOOTP_DEBUG
+		if (debug)
+			printf("gateway ip (%s) bad\n", inet_ntoa(gateip));
+#endif
+		gateip.s_addr = 0;
+	}
+
+	/* Bump xid so next request will be unique. */
+	++d->xid;
+	free(pkt);
+}
+
+/* Transmit a bootp request */
+static ssize_t
+bootpsend(struct iodesc *d, void *pkt, size_t len)
+{
+	struct bootp *bp;
+
+#ifdef BOOTP_DEBUG
+	if (debug)
+		printf("bootpsend: d=%lx called.\n", (long)d);
+#endif
+
+	bp = pkt;
+	bp->bp_secs = htons((u_short)(getsecs() - bot));
+
+#ifdef BOOTP_DEBUG
+	if (debug)
+		printf("bootpsend: calling sendudp\n");
+#endif
+
+	return (sendudp(d, pkt, len));
+}
+
+static ssize_t
+bootprecv(struct iodesc *d, void **pkt, void **payload, time_t tleft)
+{
+	ssize_t n;
+	struct bootp *bp;
+	void *ptr;
+
+#ifdef BOOTP_DEBUG
+	if (debug)
+		printf("bootp_recvoffer: called\n");
+#endif
+
+	ptr = NULL;
+	n = readudp(d, &ptr, (void **)&bp, tleft);
+	if (n == -1 || n < sizeof(struct bootp) - BOOTP_VENDSIZE)
+		goto bad;
+
+#ifdef BOOTP_DEBUG
+	if (debug)
+		printf("bootprecv: checked.  bp = %p, n = %zd\n", bp, n);
+#endif
+	if (bp->bp_xid != htonl(d->xid)) {
+#ifdef BOOTP_DEBUG
+		if (debug) {
+			printf("bootprecv: expected xid 0x%lx, got 0x%x\n",
+			    d->xid, ntohl(bp->bp_xid));
+		}
+#endif
+		goto bad;
+	}
+
+#ifdef BOOTP_DEBUG
+	if (debug)
+		printf("bootprecv: got one!\n");
+#endif
+
+	/* Suck out vendor info */
+	if (bcmp(vm_rfc1048, bp->bp_vend, sizeof(vm_rfc1048)) == 0) {
+		int vsize = n - offsetof(struct bootp, bp_vend);
+		if (vend_rfc1048(bp->bp_vend, vsize) != 0)
+		    goto bad;
+
+		/* Save copy of bootp reply or DHCP ACK message */
+		if (bp->bp_op == BOOTREPLY &&
+		    ((dhcp_ok == 1 && expected_dhcpmsgtype == DHCPACK) ||
+		    dhcp_ok == 0)) {
+			free(bootp_response);
+			bootp_response = malloc(n);
+			if (bootp_response != NULL) {
+				bootp_response_size = n;
+				bcopy(bp, bootp_response, bootp_response_size);
+			}
+		}
+	}
+#ifdef BOOTP_VEND_CMU
+	else if (bcmp(vm_cmu, bp->bp_vend, sizeof(vm_cmu)) == 0)
+		vend_cmu(bp->bp_vend);
+#endif
+	else
+		printf("bootprecv: unknown vendor 0x%lx\n", (long)bp->bp_vend);
+
+	*pkt = ptr;
+	*payload = bp;
+	return (n);
+bad:
+	free(ptr);
+	errno = 0;
+	return (-1);
+}
+
+int
+dhcp_try_rfc1048(u_char *cp, u_int len)
+{
+
+	expected_dhcpmsgtype = DHCPACK;
+	if (bcmp(vm_rfc1048, cp, sizeof(vm_rfc1048)) == 0) {

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802111951.w1BJpTWb014816>