summaryrefslogtreecommitdiffstats
path: root/src/net/dhcpopts.c
diff options
context:
space:
mode:
authorMichael Brown2006-07-20 04:49:59 +0200
committerMichael Brown2006-07-20 04:49:59 +0200
commit00a1f000b192f277e52b1d2ac63b2a066a9814a3 (patch)
tree25bf2441524fe96cf46e99032143f71acfeb2c68 /src/net/dhcpopts.c
parentFree up any allocated options if we fail (diff)
downloadipxe-00a1f000b192f277e52b1d2ac63b2a066a9814a3.tar.gz
ipxe-00a1f000b192f277e52b1d2ac63b2a066a9814a3.tar.xz
ipxe-00a1f000b192f277e52b1d2ac63b2a066a9814a3.zip
Added dhcp_ipv4_option() and friends.
Added test code to configure the interface for IPv4 after DHCP.
Diffstat (limited to 'src/net/dhcpopts.c')
-rw-r--r--src/net/dhcpopts.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/net/dhcpopts.c b/src/net/dhcpopts.c
index 4f67f846..ebd6de75 100644
--- a/src/net/dhcpopts.c
+++ b/src/net/dhcpopts.c
@@ -24,6 +24,7 @@
#include <assert.h>
#include <vsprintf.h>
#include <gpxe/list.h>
+#include <gpxe/in.h>
#include <gpxe/dhcp.h>
/** @file
@@ -86,6 +87,21 @@ unsigned long dhcp_num_option ( struct dhcp_option *option ) {
}
/**
+ * Obtain value of an IPv4-address DHCP option
+ *
+ * @v option DHCP option, or NULL
+ * @v inp IPv4 address to fill in
+ *
+ * Parses the IPv4 address value from a DHCP option, if present. It
+ * is permitted to call dhcp_ipv4_option() with @c option set to NULL;
+ * in this case the address will be set to 0.0.0.0.
+ */
+void dhcp_ipv4_option ( struct dhcp_option *option, struct in_addr *inp ) {
+ if ( option )
+ *inp = option->data.in;
+}
+
+/**
* Calculate length of a normal DHCP option
*
* @v option DHCP option
@@ -461,6 +477,45 @@ unsigned long find_global_dhcp_num_option ( unsigned int tag ) {
}
/**
+ * Find DHCP IPv4-address option, and return its value
+ *
+ * @v options DHCP options block
+ * @v tag DHCP option tag to search for
+ * @v inp IPv4 address to fill in
+ * @ret value Numerical value of the option, or 0 if not found
+ *
+ * This function exists merely as a notational shorthand for a call to
+ * find_dhcp_option() followed by a call to dhcp_ipv4_option(). It is
+ * not possible to distinguish between the cases "option not found"
+ * and "option has a value of 0.0.0.0" using this function; if this
+ * matters to you then issue the two constituent calls directly and
+ * check that find_dhcp_option() returns a non-NULL value.
+ */
+void find_dhcp_ipv4_option ( struct dhcp_option_block *options,
+ unsigned int tag, struct in_addr *inp ) {
+ dhcp_ipv4_option ( find_dhcp_option ( options, tag ), inp );
+}
+
+/**
+ * Find DHCP IPv4-address option, and return its value
+ *
+ * @v options DHCP options block
+ * @v tag DHCP option tag to search for
+ * @v inp IPv4 address to fill in
+ * @ret value Numerical value of the option, or 0 if not found
+ *
+ * This function exists merely as a notational shorthand for a call to
+ * find_dhcp_option() followed by a call to dhcp_ipv4_option(). It is
+ * not possible to distinguish between the cases "option not found"
+ * and "option has a value of 0.0.0.0" using this function; if this
+ * matters to you then issue the two constituent calls directly and
+ * check that find_dhcp_option() returns a non-NULL value.
+ */
+void find_global_dhcp_ipv4_option ( unsigned int tag, struct in_addr *inp ) {
+ dhcp_ipv4_option ( find_global_dhcp_option ( tag ), inp );
+}
+
+/**
* Delete DHCP option
*
* @v options DHCP options block