summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
authorMichael Brown2008-03-25 21:46:16 +0100
committerMichael Brown2008-03-25 21:46:16 +0100
commit92d15eff30410dcb0ec406e06b131fb7d9179ffd (patch)
tree191d29013372b541d353bbfa55114b8060dd557c /src/include
parent[PXEXT] Avoid returning a false EOF when we have an empty buffer queued (diff)
downloadipxe-92d15eff30410dcb0ec406e06b131fb7d9179ffd.tar.gz
ipxe-92d15eff30410dcb0ec406e06b131fb7d9179ffd.tar.xz
ipxe-92d15eff30410dcb0ec406e06b131fb7d9179ffd.zip
[Settings] Remove assumption that all settings have DHCP tag values
Allow for settings to be described by something other than a DHCP option tag if desirable. Currently used only for the MAC address setting. Separate out fake DHCP packet creation code from dhcp.c to fakedhcp.c. Remove notion of settings from dhcppkt.c. Rationalise dhcp.c to use settings API only for final registration of the DHCP options, rather than using {store,fetch}_setting throughout.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/gpxe/dhcp.h29
-rw-r--r--src/include/gpxe/dhcpopts.h2
-rw-r--r--src/include/gpxe/dhcppkt.h9
-rw-r--r--src/include/gpxe/fakedhcp.h21
-rw-r--r--src/include/gpxe/settings.h148
5 files changed, 122 insertions, 87 deletions
diff --git a/src/include/gpxe/dhcp.h b/src/include/gpxe/dhcp.h
index bc0e9a3b..94cc2010 100644
--- a/src/include/gpxe/dhcp.h
+++ b/src/include/gpxe/dhcp.h
@@ -15,8 +15,8 @@
struct net_device;
struct job_interface;
+struct dhcp_options;
struct dhcp_packet;
-struct settings;
/** BOOTP/DHCP server port */
#define BOOTPS_PORT 67
@@ -179,15 +179,6 @@ struct settings;
*/
#define DHCP_EB_SIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 3 )
-/** MAC address
- *
- * This option is used internally to contain the network device
- * hardware address, in order to provide a consistent approach to
- * storing and processing options. It should never be present in a
- * DHCP packet.
- */
-#define DHCP_EB_MAC DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 4 )
-
/*
* Tags in the range 0x10-0x7f are reserved for feature markers
*
@@ -445,11 +436,19 @@ struct dhcphdr {
/** Maximum time that we will wait for ProxyDHCP offers */
#define PROXYDHCP_WAIT_TIME ( TICKS_PER_SEC * 1 )
-extern int create_dhcpdiscover ( struct net_device *netdev,
- void *data, size_t max_len );
-extern int create_dhcpack ( struct net_device *netdev,
- void *data, size_t max_len );
-extern int create_proxydhcpack ( struct net_device *netdev,
+/** Settings block name used for DHCP responses */
+#define DHCP_SETTINGS_NAME "dhcp"
+
+/** Settings block name used for ProxyDHCP responses */
+#define PROXYDHCP_SETTINGS_NAME "proxydhcp"
+
+extern int create_dhcp_packet ( struct dhcp_packet *dhcppkt,
+ struct net_device *netdev, uint8_t msgtype,
+ struct dhcp_options *options,
+ void *data, size_t max_len );
+extern int create_dhcp_request ( struct dhcp_packet *dhcppkt,
+ struct net_device *netdev,
+ struct dhcp_packet *dhcpoffer,
void *data, size_t max_len );
extern int start_dhcp ( struct job_interface *job, struct net_device *netdev );
diff --git a/src/include/gpxe/dhcpopts.h b/src/include/gpxe/dhcpopts.h
index b16c5f22..8391a9d4 100644
--- a/src/include/gpxe/dhcpopts.h
+++ b/src/include/gpxe/dhcpopts.h
@@ -7,7 +7,7 @@
*
*/
-#include <gpxe/dhcp.h>
+#include <stdint.h>
/** A DHCP options block */
struct dhcp_options {
diff --git a/src/include/gpxe/dhcppkt.h b/src/include/gpxe/dhcppkt.h
index 98b8dad8..179be2f8 100644
--- a/src/include/gpxe/dhcppkt.h
+++ b/src/include/gpxe/dhcppkt.h
@@ -9,15 +9,12 @@
#include <gpxe/dhcp.h>
#include <gpxe/dhcpopts.h>
-#include <gpxe/settings.h>
/**
* A DHCP packet
*
*/
struct dhcp_packet {
- /** Settings block */
- struct settings settings;
/** The DHCP packet contents */
struct dhcphdr *dhcphdr;
/** Maximum length of the DHCP packet buffer */
@@ -28,7 +25,11 @@ struct dhcp_packet {
struct dhcp_options options;
};
-extern void dhcppkt_init ( struct dhcp_packet *dhcppkt, struct refcnt *refcnt,
+extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
+ const void *data, size_t len );
+extern int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,
+ void *data, size_t len );
+extern void dhcppkt_init ( struct dhcp_packet *dhcppkt,
void *data, size_t len );
#endif /* _GPXE_DHCPPKT_H */
diff --git a/src/include/gpxe/fakedhcp.h b/src/include/gpxe/fakedhcp.h
new file mode 100644
index 00000000..990b56af
--- /dev/null
+++ b/src/include/gpxe/fakedhcp.h
@@ -0,0 +1,21 @@
+#ifndef _GPXE_FAKEDHCP_H
+#define _GPXE_FAKEDHCP_H
+
+/** @file
+ *
+ * Fake DHCP packets
+ *
+ */
+
+#include <stdint.h>
+
+struct net_device;
+
+extern int create_fakedhcpdiscover ( struct net_device *netdev,
+ void *data, size_t max_len );
+extern int create_fakedhcpack ( struct net_device *netdev,
+ void *data, size_t max_len );
+extern int create_fakeproxydhcpack ( struct net_device *netdev,
+ void *data, size_t max_len );
+
+#endif /* _GPXE_FAKEDHCP_H */
diff --git a/src/include/gpxe/settings.h b/src/include/gpxe/settings.h
index f32d3ec9..40825698 100644
--- a/src/include/gpxe/settings.h
+++ b/src/include/gpxe/settings.h
@@ -16,22 +16,44 @@
struct settings;
struct in_addr;
+/** A setting */
+struct setting {
+ /** Name
+ *
+ * This is the human-readable name for the setting.
+ */
+ const char *name;
+ /** Description */
+ const char *description;
+ /** Setting type
+ *
+ * This identifies the type of setting (e.g. string, IPv4
+ * address, etc.).
+ */
+ struct setting_type *type;
+ /** DHCP option number, if applicable */
+ unsigned int tag;
+};
+
+/** Declare a configuration setting */
+#define __setting __table ( struct setting, settings, 01 )
+
/** Settings block operations */
struct settings_operations {
/** Store value of setting
*
* @v settings Settings block
- * @v tag Setting tag number
+ * @v setting Setting to store
* @v data Setting data, or NULL to clear setting
* @v len Length of setting data
* @ret rc Return status code
*/
- int ( * store ) ( struct settings *settings, unsigned int tag,
+ int ( * store ) ( struct settings *settings, struct setting *setting,
const void *data, size_t len );
/** Fetch value of setting
*
* @v settings Settings block
- * @v tag Setting tag number
+ * @v setting Setting to fetch
* @v data Buffer to fill with setting data
* @v len Length of buffer
* @ret len Length of setting data, or negative error
@@ -39,7 +61,7 @@ struct settings_operations {
* The actual length of the setting will be returned even if
* the buffer was too small.
*/
- int ( * fetch ) ( struct settings *settings, unsigned int tag,
+ int ( * fetch ) ( struct settings *settings, struct setting *setting,
void *data, size_t len );
};
@@ -74,21 +96,21 @@ struct setting_type {
/** Parse and set value of setting
*
* @v settings Settings block
- * @v tag Setting tag number
+ * @v setting Setting to store
* @v value Formatted setting data
* @ret rc Return status code
*/
- int ( * storef ) ( struct settings *settings, unsigned int tag,
+ int ( * storef ) ( struct settings *settings, struct setting *setting,
const char *value );
/** Fetch and format value of setting
*
- * @v settings Settings block, or NULL to search all blocks
- * @v tag Setting tag number
+ * @v settings Settings block
+ * @v setting Setting to fetch
* @v buf Buffer to contain formatted value
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
- int ( * fetchf ) ( struct settings *settings, unsigned int tag,
+ int ( * fetchf ) ( struct settings *settings, struct setting *setting,
char *buf, size_t len );
};
@@ -97,33 +119,6 @@ struct setting_type {
__table ( struct setting_type, setting_types, 01 )
/**
- * A named setting
- *
- * This represents a single setting (e.g. "hostname"), encapsulating
- * the information about the setting's tag number and type.
- */
-struct named_setting {
- /** Name
- *
- * This is the human-readable name for the setting.
- */
- const char *name;
- /** Description */
- const char *description;
- /** Setting tag number */
- unsigned int tag;
- /** Setting type
- *
- * This identifies the type of setting (e.g. string, IPv4
- * address, etc.).
- */
- struct setting_type *type;
-};
-
-/** Declare a configuration setting */
-#define __named_setting __table ( struct named_setting, named_settings, 01 )
-
-/**
* A settings applicator
*
*/
@@ -151,41 +146,49 @@ struct simple_settings {
};
extern struct settings_operations simple_settings_operations;
-
-extern int simple_settings_store ( struct settings *settings, unsigned int tag,
+extern int simple_settings_store ( struct settings *settings,
+ struct setting *setting,
const void *data, size_t len );
-extern int simple_settings_fetch ( struct settings *settings, unsigned int tag,
+extern int simple_settings_fetch ( struct settings *settings,
+ struct setting *setting,
void *data, size_t len );
+
extern int register_settings ( struct settings *settings,
struct settings *parent );
extern void unregister_settings ( struct settings *settings );
-extern int store_setting ( struct settings *settings, unsigned int tag,
+
+extern int store_setting ( struct settings *settings, struct setting *setting,
const void *data, size_t len );
-extern int fetch_setting ( struct settings *settings, unsigned int tag,
+extern int fetch_setting ( struct settings *settings, struct setting *setting,
void *data, size_t len );
-extern int copy_settings ( struct settings *dest, struct settings *source );
-extern int fetch_setting_len ( struct settings *settings, unsigned int tag );
-extern int fetch_string_setting ( struct settings *settings, unsigned int tag,
+extern int fetch_setting_len ( struct settings *settings,
+ struct setting *setting );
+extern int fetch_string_setting ( struct settings *settings,
+ struct setting *setting,
char *data, size_t len );
-extern int fetch_ipv4_setting ( struct settings *settings, unsigned int tag,
- struct in_addr *inp );
-extern int fetch_int_setting ( struct settings *settings, unsigned int tag,
- long *value );
-extern int fetch_uint_setting ( struct settings *settings, unsigned int tag,
+extern int fetch_ipv4_setting ( struct settings *settings,
+ struct setting *setting, struct in_addr *inp );
+extern int fetch_int_setting ( struct settings *settings,
+ struct setting *setting, long *value );
+extern int fetch_uint_setting ( struct settings *settings,
+ struct setting *setting,
unsigned long *value );
-extern long fetch_intz_setting ( struct settings *settings, unsigned int tag );
+extern long fetch_intz_setting ( struct settings *settings,
+ struct setting *setting );
extern unsigned long fetch_uintz_setting ( struct settings *settings,
- unsigned int tag );
+ struct setting *setting );
+extern int setting_cmp ( struct setting *a, struct setting *b );
+
extern struct settings * find_child_settings ( struct settings *parent,
const char *name );
extern struct settings * find_settings ( const char *name );
-extern int store_typed_setting ( struct settings *settings,
- unsigned int tag, struct setting_type *type,
- const char *value );
-extern int store_named_setting ( const char *name, const char *value );
-extern int fetch_named_setting ( const char *name, char *buf, size_t len );
-extern struct setting_type setting_type_ __setting_type;
+extern int storef_setting ( struct settings *settings,
+ struct setting *setting,
+ const char *value );
+extern int storef_named_setting ( const char *name, const char *value );
+extern int fetchf_named_setting ( const char *name, char *buf, size_t len );
+
extern struct setting_type setting_type_string __setting_type;
extern struct setting_type setting_type_ipv4 __setting_type;
extern struct setting_type setting_type_int8 __setting_type;
@@ -196,6 +199,18 @@ extern struct setting_type setting_type_uint16 __setting_type;
extern struct setting_type setting_type_uint32 __setting_type;
extern struct setting_type setting_type_hex __setting_type;
+extern struct setting ip_setting __setting;
+extern struct setting netmask_setting __setting;
+extern struct setting gateway_setting __setting;
+extern struct setting dns_setting __setting;
+extern struct setting hostname_setting __setting;
+extern struct setting filename_setting __setting;
+extern struct setting root_path_setting __setting;
+extern struct setting username_setting __setting;
+extern struct setting password_setting __setting;
+extern struct setting priority_setting __setting;
+extern struct setting bios_drive_setting __setting;
+
/**
* Initialise a settings block
*
@@ -233,29 +248,28 @@ static inline void simple_settings_init ( struct simple_settings *simple,
* Delete setting
*
* @v settings Settings block
- * @v tag Setting tag number
+ * @v setting Setting to delete
* @ret rc Return status code
*/
static inline int delete_setting ( struct settings *settings,
- unsigned int tag ) {
- return store_setting ( settings, tag, NULL, 0 );
+ struct setting *setting ) {
+ return store_setting ( settings, setting, NULL, 0 );
}
/**
* Fetch and format value of setting
*
* @v settings Settings block, or NULL to search all blocks
- * @v tag Setting tag number
+ * @v setting Setting to fetch
* @v type Settings type
* @v buf Buffer to contain formatted value
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static inline int fetch_typed_setting ( struct settings *settings,
- unsigned int tag,
- struct setting_type *type,
- char *buf, size_t len ) {
- return type->fetchf ( settings, tag, buf, len );
+static inline int fetchf_setting ( struct settings *settings,
+ struct setting *setting,
+ char *buf, size_t len ) {
+ return setting->type->fetchf ( settings, setting, buf, len );
}
/**
@@ -265,7 +279,7 @@ static inline int fetch_typed_setting ( struct settings *settings,
* @ret rc Return status code
*/
static inline int delete_named_setting ( const char *name ) {
- return store_named_setting ( name, NULL );
+ return storef_named_setting ( name, NULL );
}
#endif /* _GPXE_SETTINGS_H */