mirror of
https://github.com/xcat2/xNBA.git
synced 2025-01-09 04:55:26 +00:00
[Settings] Implement simple_settings backed with extensible DHCP options
This commit is contained in:
parent
a462c96ffc
commit
e5cea13e51
@ -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
|
||||
*
|
||||
|
@ -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 );
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <gpxe/tables.h>
|
||||
#include <gpxe/list.h>
|
||||
#include <gpxe/refcnt.h>
|
||||
#include <gpxe/dhcpopts.h>
|
||||
|
||||
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
|
||||
*
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user