summaryrefslogtreecommitdiffstats
path: root/src/net/dhcpopts.c
diff options
context:
space:
mode:
authorMichael Brown2007-07-05 19:38:14 +0200
committerMichael Brown2007-07-05 19:38:14 +0200
commit1567b698958cccde4c32e554ef56df7add3a06f6 (patch)
tree208ea71016215b02fab90b835428568543619302 /src/net/dhcpopts.c
parentFirst draft of PXE extensions API. (diff)
downloadipxe-1567b698958cccde4c32e554ef56df7add3a06f6.tar.gz
ipxe-1567b698958cccde4c32e554ef56df7add3a06f6.tar.xz
ipxe-1567b698958cccde4c32e554ef56df7add3a06f6.zip
Add concept of DHCP option applicators.
Diffstat (limited to 'src/net/dhcpopts.c')
-rw-r--r--src/net/dhcpopts.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/net/dhcpopts.c b/src/net/dhcpopts.c
index bb977317..6038709b 100644
--- a/src/net/dhcpopts.c
+++ b/src/net/dhcpopts.c
@@ -25,6 +25,7 @@
#include <assert.h>
#include <gpxe/list.h>
#include <gpxe/in.h>
+#include <gpxe/uri.h>
#include <gpxe/dhcp.h>
/** @file
@@ -36,6 +37,12 @@
/** List of registered DHCP option blocks */
static LIST_HEAD ( option_blocks );
+/** Registered DHCP option applicators */
+static struct dhcp_option_applicator dhcp_option_applicators[0]
+ __table_start ( struct dhcp_option_applicator, dhcp_applicators );
+static struct dhcp_option_applicator dhcp_option_applicators_end[0]
+ __table_end ( struct dhcp_option_applicator, dhcp_applicators );
+
/**
* Obtain printable version of a DHCP option tag
*
@@ -560,3 +567,45 @@ void delete_dhcp_option ( struct dhcp_option_block *options,
unsigned int tag ) {
set_dhcp_option ( options, tag, NULL, 0 );
}
+
+/**
+ * Apply DHCP options
+ *
+ * @v options DHCP options block, or NULL
+ * @ret rc Return status code
+ */
+int apply_dhcp_options ( struct dhcp_option_block *options ) {
+ struct dhcp_option_applicator *applicator;
+ struct dhcp_option *option;
+ struct in_addr tftp_server;
+ struct uri *uri;
+ char uri_string[32];
+ unsigned int tag;
+ int rc;
+
+ /* Set current working URI based on TFTP server */
+ find_dhcp_ipv4_option ( options, DHCP_EB_SIADDR, &tftp_server );
+ snprintf ( uri_string, sizeof ( uri_string ),
+ "tftp://%s/", inet_ntoa ( tftp_server ) );
+ uri = parse_uri ( uri_string );
+ if ( ! uri )
+ return -ENOMEM;
+ churi ( uri );
+ uri_put ( uri );
+
+ /* Call all registered DHCP option applicators */
+ for ( applicator = dhcp_option_applicators ;
+ applicator < dhcp_option_applicators_end ; applicator++ ) {
+ tag = applicator->tag;
+ option = find_dhcp_option ( options, tag );
+ if ( ! option )
+ continue;
+ if ( ( rc = applicator->apply ( tag, option ) ) != 0 ) {
+ DBG ( "Could not apply DHCP option %s: %s\n",
+ dhcp_tag_name ( tag ), strerror ( rc ) );
+ return rc;
+ }
+ }
+
+ return 0;
+}