From owner-svn-src-head@freebsd.org Thu Mar 9 06:01:25 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 936C1D04F15; Thu, 9 Mar 2017 06:01:25 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6BA4F13BF; Thu, 9 Mar 2017 06:01:25 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2961Osa077856; Thu, 9 Mar 2017 06:01:24 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2961OJx077853; Thu, 9 Mar 2017 06:01:24 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201703090601.v2961OJx077853@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Thu, 9 Mar 2017 06:01:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r314948 - in head: lib/libstand sys/boot/i386/libi386 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Mar 2017 06:01:25 -0000 Author: oshogbo Date: Thu Mar 9 06:01:24 2017 New Revision: 314948 URL: https://svnweb.freebsd.org/changeset/base/314948 Log: Try to extract the RFC1048 data from PXE. If we get enough info we can skip the bootp(). It removes unnecessary DHCP request from pxeloader. Submitted by: kczekirda Sponsored by: Oktawave Initiated by: Matthew Dillon Reviewed by: smh, gnn, bapt, oshogbo MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D9847 Modified: head/lib/libstand/bootp.c head/lib/libstand/bootp.h head/sys/boot/i386/libi386/pxe.c Modified: head/lib/libstand/bootp.c ============================================================================== --- head/lib/libstand/bootp.c Thu Mar 9 05:30:05 2017 (r314947) +++ head/lib/libstand/bootp.c Thu Mar 9 06:01:24 2017 (r314948) @@ -344,6 +344,17 @@ bad: return (-1); } +int +dhcp_try_rfc1048(u_char *cp, u_int len) +{ + + expected_dhcpmsgtype = DHCPACK; + if (bcmp(vm_rfc1048, cp, sizeof(vm_rfc1048)) == 0) { + return (vend_rfc1048(cp, len)); + } + return (-1); +} + static int vend_rfc1048(cp, len) u_char *cp; Modified: head/lib/libstand/bootp.h ============================================================================== --- head/lib/libstand/bootp.h Thu Mar 9 05:30:05 2017 (r314947) +++ head/lib/libstand/bootp.h Thu Mar 9 06:01:24 2017 (r314948) @@ -22,6 +22,8 @@ * $FreeBSD$ */ +#ifndef _BOOTP_H_ +#define _BOOTP_H_ struct bootp { unsigned char bp_op; /* packet opcode type */ @@ -145,3 +147,7 @@ struct cmu_vend { /* v_flags values */ #define VF_SMASK 1 /* Subnet mask field contains valid data */ + +int dhcp_try_rfc1048(u_char *cp, u_int len); + +#endif /* _BOOTP_H_ */ Modified: head/sys/boot/i386/libi386/pxe.c ============================================================================== --- head/sys/boot/i386/libi386/pxe.c Thu Mar 9 05:30:05 2017 (r314947) +++ head/sys/boot/i386/libi386/pxe.c Thu Mar 9 06:01:24 2017 (r314948) @@ -101,6 +101,7 @@ extern void __bangpxeentry(void); extern u_int16_t __pxenvseg; extern u_int16_t __pxenvoff; extern void __pxenventry(void); +extern struct in_addr servip; struct netif_dif pxe_ifs[] = { /* dif_unit dif_nsel dif_stats dif_private */ @@ -276,17 +277,38 @@ pxe_open(struct open_file *f, ...) } if (pxe_debug) printf("pxe_open: netif_open() succeeded\n"); + + if (socktodesc(pxe_sock) == NULL) { + printf("pxe_open: bad socket %d\n", pxe_sock); + return (ENXIO); + } + } if (rootip.s_addr == 0) { /* - * Do a bootp/dhcp request to find out where our + * Try to extract the RFC1048 data from PXE. + * If fail do a bootp/dhcp request to find out where our * NFS/TFTP server is. Even if we dont get back * the proper information, fall back to the server * which brought us to life and a default rootpath. */ - bootp(pxe_sock, BOOTP_PXE); + + if (dhcp_try_rfc1048(bootplayer.vendor.d, BOOTP_DHCPVEND) < 0) { + if (pxe_debug) + printf("pxe_open: no RFC1048 data in PXE Cache\n"); + bootp(pxe_sock, BOOTP_PXE); + } else if (pxe_debug) { + printf("pxe_open: loaded RFC1048 data from PXE Cache\n"); + } + if (rootip.s_addr == 0) rootip.s_addr = bootplayer.sip; + if (gateip.s_addr == 0) + gateip.s_addr = bootplayer.gip; + if (myip.s_addr == 0) + myip.s_addr = bootplayer.yip; + if (servip.s_addr == 0) + servip = rootip; netproto = NET_NFS; if (tftpip.s_addr != 0) { @@ -323,6 +345,9 @@ pxe_open(struct open_file *f, ...) printf("pxe_open: server addr: %s\n", inet_ntoa(rootip)); printf("pxe_open: server path: %s\n", rootpath); printf("pxe_open: gateway ip: %s\n", inet_ntoa(gateip)); + printf("pxe_open: my ip: %s\n", inet_ntoa(myip)); + printf("pxe_open: netmask: %s\n", intoa(netmask)); + printf("pxe_open: servip: %s\n", inet_ntoa(servip)); if (netproto == NET_TFTP) { setenv("boot.tftproot.server", inet_ntoa(rootip), 1);