summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Oreman2009-12-08 09:48:15 +0100
committerMarty Connor2010-01-20 23:16:37 +0100
commit9e9cc8c60ff573e02615889a4b7fa469c42fe425 (patch)
tree13a23d6b289f4d299d508aef1931c28c6b07acaf
parent[dhcp] Add generic facility for using cached network settings (diff)
downloadipxe-9e9cc8c60ff573e02615889a4b7fa469c42fe425.tar.gz
ipxe-9e9cc8c60ff573e02615889a4b7fa469c42fe425.tar.xz
ipxe-9e9cc8c60ff573e02615889a4b7fa469c42fe425.zip
[pxe] Support cached DHCP packets in .kkpxe images
If we don't unload the PXE stack before executing gPXE, automatically take advantage of the cached DHCPACK that the underlying/parent PXE stack can provide. If that cached DHCPACK contains option 175.178, or the user sets the use-cached setting before invoking DHCP, the real DHCP request will be skipped and the cached DHCPACK will be used for network configuration. Otherwise, the cached settings block is thrown away as soon as a fresh one is acquired. Signed-off-by: Marty Connor <mdc@etherboot.org>
-rw-r--r--src/arch/i386/interface/pxeparent/pxeparent_dhcp.c69
-rw-r--r--src/arch/i386/prefix/kkpxeprefix.S3
2 files changed, 72 insertions, 0 deletions
diff --git a/src/arch/i386/interface/pxeparent/pxeparent_dhcp.c b/src/arch/i386/interface/pxeparent/pxeparent_dhcp.c
new file mode 100644
index 00000000..66059437
--- /dev/null
+++ b/src/arch/i386/interface/pxeparent/pxeparent_dhcp.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2009 Joshua Oreman <oremanj@rwcr.net>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <string.h>
+#include <gpxe/dhcp.h>
+#include <gpxe/netdevice.h>
+#include <undipreload.h>
+#include <pxeparent.h>
+#include <realmode.h>
+#include <pxe_api.h>
+
+/**
+ * Present cached DHCP packet if it exists
+ */
+void __weak_impl ( get_cached_dhcpack ) ( void ) {
+ struct undi_device *undi;
+ struct s_PXENV_GET_CACHED_INFO get_cached_info;
+ int rc;
+
+ /* Use preloaded UNDI device to get at PXE entry point */
+ undi = &preloaded_undi;
+ if ( ! undi->entry.segment ) {
+ DBG ( "PXEDHCP no preloaded UNDI device found\n" );
+ return;
+ }
+
+ /* Check that stack is available to get cached info */
+ if ( ! ( undi->flags & UNDI_FL_KEEP_ALL ) ) {
+ DBG ( "PXEDHCP stack was unloaded, no cache available\n" );
+ return;
+ }
+
+ /* Obtain cached DHCP packet */
+ memset ( &get_cached_info, 0, sizeof ( get_cached_info ) );
+ get_cached_info.PacketType = PXENV_PACKET_TYPE_DHCP_ACK;
+
+ if ( ( rc = pxeparent_call ( undi->entry, PXENV_GET_CACHED_INFO,
+ &get_cached_info,
+ sizeof ( get_cached_info ) ) ) != 0 ) {
+ DBG ( "PXEDHCP GET_CACHED_INFO failed: %s\n", strerror ( rc ) );
+ return;
+ }
+
+ DBG ( "PXEDHCP got cached info at %04x:%04x length %d\n",
+ get_cached_info.Buffer.segment, get_cached_info.Buffer.offset,
+ get_cached_info.BufferSize );
+
+ /* Present cached DHCP packet */
+ store_cached_dhcpack ( real_to_user ( get_cached_info.Buffer.segment,
+ get_cached_info.Buffer.offset ),
+ get_cached_info.BufferSize );
+}
diff --git a/src/arch/i386/prefix/kkpxeprefix.S b/src/arch/i386/prefix/kkpxeprefix.S
index 4d13f404..02cc6fee 100644
--- a/src/arch/i386/prefix/kkpxeprefix.S
+++ b/src/arch/i386/prefix/kkpxeprefix.S
@@ -5,6 +5,9 @@
FILE_LICENCE ( GPL2_OR_LATER )
+/* Since we have the whole stack, we can use cached DHCP information */
+REQUEST_OBJECT ( pxeparent_dhcp )
+
#define PXELOADER_KEEP_UNDI
#define PXELOADER_KEEP_PXE
#include "pxeprefix.S"