From e5cea13e51f5226987048275499314c6f15d526f Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sat, 22 Mar 2008 00:24:50 +0000 Subject: [PATCH] [Settings] Implement simple_settings backed with extensible DHCP options --- src/core/settings.c | 56 ++++++++++++++++++++++++------------ src/include/gpxe/netdevice.h | 4 +-- src/include/gpxe/settings.h | 30 +++++++++++++++++-- src/net/netdev_settings.c | 8 +++--- 4 files changed, 72 insertions(+), 26 deletions(-) diff --git a/src/core/settings.c b/src/core/settings.c index 7dd697ed..eb54ad73 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -79,23 +79,36 @@ static inline char * setting_tag_name ( unsigned int tag ) { ****************************************************************************** */ -// Dummy routine just for testing +/** + * Store value of simple setting + * + * @v options DHCP option block + * @v tag Setting tag number + * @v data Setting data, or NULL to clear setting + * @v len Length of setting data + * @ret rc Return status code + */ int simple_settings_store ( struct settings *settings, unsigned int tag, const void *data, size_t len ) { - DBGC ( settings, "Settings %p: store %s to:\n", - settings, setting_tag_name ( tag ) ); - DBGC_HD ( settings, data, len ); - return 0; + struct simple_settings *simple = + container_of ( settings, struct simple_settings, settings ); + return dhcpopt_extensible_store ( &simple->dhcpopts, tag, data, len ); } -// Dummy routine just for testing +/** + * Fetch value of simple setting + * + * @v options DHCP option block + * @v tag Setting tag number + * @v data Buffer to fill with setting data + * @v len Length of buffer + * @ret len Length of setting data, or negative error + */ int simple_settings_fetch ( struct settings *settings, unsigned int tag, void *data, size_t len ) { - ( void ) settings; - ( void ) tag; - ( void ) data; - ( void ) len; - return -ENOENT; + struct simple_settings *simple = + container_of ( settings, struct simple_settings, settings ); + return dhcpopt_fetch ( &simple->dhcpopts, tag, data, len ); } /** Simple settings operations */ @@ -104,15 +117,22 @@ struct settings_operations simple_settings_operations = { .fetch = simple_settings_fetch, }; -/** Root settings block */ -struct settings settings_root = { - .refcnt = NULL, - .name = "", - .siblings = LIST_HEAD_INIT ( settings_root.siblings ), - .children = LIST_HEAD_INIT ( settings_root.children ), - .op = &simple_settings_operations, +/** Root simple settings block */ +struct simple_settings simple_settings_root = { + .settings = { + .refcnt = NULL, + .name = "", + .siblings = + LIST_HEAD_INIT ( simple_settings_root.settings.siblings ), + .children = + LIST_HEAD_INIT ( simple_settings_root.settings.children ), + .op = &simple_settings_operations, + }, }; +/** Root settings block */ +#define settings_root simple_settings_root.settings + /** * Apply all settings * diff --git a/src/include/gpxe/netdevice.h b/src/include/gpxe/netdevice.h index 4abada7a..d8cb84d0 100644 --- a/src/include/gpxe/netdevice.h +++ b/src/include/gpxe/netdevice.h @@ -245,7 +245,7 @@ struct net_device { struct net_device_stats stats; /** Configuration settings applicable to this device */ - struct settings settings; + struct simple_settings settings; /** Driver private data */ void *priv; @@ -349,7 +349,7 @@ netdev_priv ( struct net_device *netdev ) { */ static inline __attribute__ (( always_inline )) struct settings * netdev_settings ( struct net_device *netdev ) { - return &netdev->settings; + return &netdev->settings.settings; } extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf ); diff --git a/src/include/gpxe/settings.h b/src/include/gpxe/settings.h index f20c412b..643bd05b 100644 --- a/src/include/gpxe/settings.h +++ b/src/include/gpxe/settings.h @@ -11,6 +11,7 @@ #include #include #include +#include struct settings; struct in_addr; @@ -138,12 +139,23 @@ struct settings_applicator { #define __settings_applicator \ __table ( struct settings_applicator, settings_applicators, 01 ) +/** + * A simple settings block + * + */ +struct simple_settings { + /** Settings block */ + struct settings settings; + /** DHCP options */ + struct dhcp_options dhcpopts; +}; + +extern struct settings_operations simple_settings_operations; + extern int simple_settings_store ( struct settings *settings, unsigned int tag, const void *data, size_t len ); extern int simple_settings_fetch ( struct settings *settings, unsigned int tag, void *data, size_t len ); -extern struct settings_operations simple_settings_operations; - extern int register_settings ( struct settings *settings, struct settings *parent ); extern void unregister_settings ( struct settings *settings ); @@ -205,6 +217,20 @@ static inline void settings_init ( struct settings *settings, settings->name = name; } +/** + * Initialise a settings block + * + * @v simple Simple settings block + * @v refcnt Containing object reference counter, or NULL + * @v name Settings block name + */ +static inline void simple_settings_init ( struct simple_settings *simple, + struct refcnt *refcnt, + const char *name ) { + settings_init ( &simple->settings, &simple_settings_operations, + refcnt, name ); +} + /** * Delete setting * diff --git a/src/net/netdev_settings.c b/src/net/netdev_settings.c index 9baad888..c8e630a9 100644 --- a/src/net/netdev_settings.c +++ b/src/net/netdev_settings.c @@ -39,8 +39,8 @@ */ static int netdev_store ( struct settings *settings, unsigned int tag, const void *data, size_t len ) { - struct net_device *netdev = - container_of ( settings, struct net_device, settings ); + struct net_device *netdev = container_of ( settings, struct net_device, + settings.settings ); switch ( tag ) { case DHCP_EB_MAC: @@ -64,8 +64,8 @@ static int netdev_store ( struct settings *settings, unsigned int tag, */ static int netdev_fetch ( struct settings *settings, unsigned int tag, void *data, size_t len ) { - struct net_device *netdev = - container_of ( settings, struct net_device, settings ); + struct net_device *netdev = container_of ( settings, struct net_device, + settings.settings ); switch ( tag ) { case DHCP_EB_MAC: