Browse Source

[Settings] Implement simple_settings backed with extensible DHCP options

tags/v0.9.4
Michael Brown 16 years ago
parent
commit
e5cea13e51
4 changed files with 72 additions and 26 deletions
  1. 38
    18
      src/core/settings.c
  2. 2
    2
      src/include/gpxe/netdevice.h
  3. 28
    2
      src/include/gpxe/settings.h
  4. 4
    4
      src/net/netdev_settings.c

+ 38
- 18
src/core/settings.c View File

79
  ******************************************************************************
79
  ******************************************************************************
80
  */
80
  */
81
 
81
 
82
-// Dummy routine just for testing
82
+/**
83
+ * Store value of simple setting
84
+ *
85
+ * @v options		DHCP option block
86
+ * @v tag		Setting tag number
87
+ * @v data		Setting data, or NULL to clear setting
88
+ * @v len		Length of setting data
89
+ * @ret rc		Return status code
90
+ */
83
 int simple_settings_store ( struct settings *settings, unsigned int tag,
91
 int simple_settings_store ( struct settings *settings, unsigned int tag,
84
 			    const void *data, size_t len ) {
92
 			    const void *data, size_t len ) {
85
-	DBGC ( settings, "Settings %p: store %s to:\n",
86
-	       settings, setting_tag_name ( tag ) );
87
-	DBGC_HD ( settings, data, len );
88
-	return 0;
93
+	struct simple_settings *simple =
94
+		container_of ( settings, struct simple_settings, settings );
95
+	return dhcpopt_extensible_store ( &simple->dhcpopts, tag, data, len );
89
 }
96
 }
90
 
97
 
91
-// Dummy routine just for testing
98
+/**
99
+ * Fetch value of simple setting
100
+ *
101
+ * @v options		DHCP option block
102
+ * @v tag		Setting tag number
103
+ * @v data		Buffer to fill with setting data
104
+ * @v len		Length of buffer
105
+ * @ret len		Length of setting data, or negative error
106
+ */
92
 int simple_settings_fetch ( struct settings *settings, unsigned int tag,
107
 int simple_settings_fetch ( struct settings *settings, unsigned int tag,
93
 			    void *data, size_t len ) {
108
 			    void *data, size_t len ) {
94
-	( void ) settings;
95
-	( void ) tag;
96
-	( void ) data;
97
-	( void ) len;
98
-	return -ENOENT;
109
+	struct simple_settings *simple =
110
+		container_of ( settings, struct simple_settings, settings );
111
+	return dhcpopt_fetch ( &simple->dhcpopts, tag, data, len );
99
 }
112
 }
100
 
113
 
101
 /** Simple settings operations */
114
 /** Simple settings operations */
104
 	.fetch = simple_settings_fetch,
117
 	.fetch = simple_settings_fetch,
105
 };
118
 };
106
 
119
 
107
-/** Root settings block */
108
-struct settings settings_root = {
109
-	.refcnt = NULL,
110
-	.name = "",
111
-	.siblings = LIST_HEAD_INIT ( settings_root.siblings ),
112
-	.children = LIST_HEAD_INIT ( settings_root.children ),
113
-	.op = &simple_settings_operations,
120
+/** Root simple settings block */
121
+struct simple_settings simple_settings_root = {
122
+	.settings = {
123
+		.refcnt = NULL,
124
+		.name = "",
125
+		.siblings =
126
+		     LIST_HEAD_INIT ( simple_settings_root.settings.siblings ),
127
+		.children =
128
+		     LIST_HEAD_INIT ( simple_settings_root.settings.children ),
129
+		.op = &simple_settings_operations,
130
+	},
114
 };
131
 };
115
 
132
 
133
+/** Root settings block */
134
+#define settings_root simple_settings_root.settings
135
+
116
 /**
136
 /**
117
  * Apply all settings
137
  * Apply all settings
118
  *
138
  *

+ 2
- 2
src/include/gpxe/netdevice.h View File

245
 	struct net_device_stats stats;
245
 	struct net_device_stats stats;
246
 
246
 
247
 	/** Configuration settings applicable to this device */
247
 	/** Configuration settings applicable to this device */
248
-	struct settings settings;
248
+	struct simple_settings settings;
249
 
249
 
250
 	/** Driver private data */
250
 	/** Driver private data */
251
 	void *priv;
251
 	void *priv;
349
  */
349
  */
350
 static inline __attribute__ (( always_inline )) struct settings *
350
 static inline __attribute__ (( always_inline )) struct settings *
351
 netdev_settings ( struct net_device *netdev ) {
351
 netdev_settings ( struct net_device *netdev ) {
352
-	return &netdev->settings;
352
+	return &netdev->settings.settings;
353
 }
353
 }
354
 
354
 
355
 extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
355
 extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );

+ 28
- 2
src/include/gpxe/settings.h View File

11
 #include <gpxe/tables.h>
11
 #include <gpxe/tables.h>
12
 #include <gpxe/list.h>
12
 #include <gpxe/list.h>
13
 #include <gpxe/refcnt.h>
13
 #include <gpxe/refcnt.h>
14
+#include <gpxe/dhcpopts.h>
14
 
15
 
15
 struct settings;
16
 struct settings;
16
 struct in_addr;
17
 struct in_addr;
138
 #define __settings_applicator \
139
 #define __settings_applicator \
139
 	__table ( struct settings_applicator, settings_applicators, 01 )
140
 	__table ( struct settings_applicator, settings_applicators, 01 )
140
 
141
 
142
+/**
143
+ * A simple settings block
144
+ *
145
+ */
146
+struct simple_settings {
147
+	/** Settings block */
148
+	struct settings settings;
149
+	/** DHCP options */
150
+	struct dhcp_options dhcpopts;
151
+};
152
+
153
+extern struct settings_operations simple_settings_operations;
154
+
141
 extern int simple_settings_store ( struct settings *settings, unsigned int tag,
155
 extern int simple_settings_store ( struct settings *settings, unsigned int tag,
142
 				   const void *data, size_t len );
156
 				   const void *data, size_t len );
143
 extern int simple_settings_fetch ( struct settings *settings, unsigned int tag,
157
 extern int simple_settings_fetch ( struct settings *settings, unsigned int tag,
144
 				   void *data, size_t len );
158
 				   void *data, size_t len );
145
-extern struct settings_operations simple_settings_operations;
146
-
147
 extern int register_settings ( struct settings *settings,
159
 extern int register_settings ( struct settings *settings,
148
 			       struct settings *parent );
160
 			       struct settings *parent );
149
 extern void unregister_settings ( struct settings *settings );
161
 extern void unregister_settings ( struct settings *settings );
205
 	settings->name = name;
217
 	settings->name = name;
206
 }
218
 }
207
 
219
 
220
+/**
221
+ * Initialise a settings block
222
+ *
223
+ * @v simple		Simple settings block
224
+ * @v refcnt		Containing object reference counter, or NULL
225
+ * @v name		Settings block name
226
+ */
227
+static inline void simple_settings_init ( struct simple_settings *simple,
228
+					  struct refcnt *refcnt,
229
+					  const char *name ) {
230
+	settings_init ( &simple->settings, &simple_settings_operations,
231
+			refcnt, name );
232
+}
233
+
208
 /**
234
 /**
209
  * Delete setting
235
  * Delete setting
210
  *
236
  *

+ 4
- 4
src/net/netdev_settings.c View File

39
  */
39
  */
40
 static int netdev_store ( struct settings *settings, unsigned int tag,
40
 static int netdev_store ( struct settings *settings, unsigned int tag,
41
 			  const void *data, size_t len ) {
41
 			  const void *data, size_t len ) {
42
-	struct net_device *netdev =
43
-		container_of ( settings, struct net_device, settings );
42
+	struct net_device *netdev = container_of ( settings, struct net_device,
43
+						   settings.settings );
44
 
44
 
45
 	switch ( tag ) {
45
 	switch ( tag ) {
46
 	case DHCP_EB_MAC:
46
 	case DHCP_EB_MAC:
64
  */
64
  */
65
 static int netdev_fetch ( struct settings *settings, unsigned int tag,
65
 static int netdev_fetch ( struct settings *settings, unsigned int tag,
66
 			  void *data, size_t len ) {
66
 			  void *data, size_t len ) {
67
-	struct net_device *netdev =
68
-		container_of ( settings, struct net_device, settings );
67
+	struct net_device *netdev = container_of ( settings, struct net_device,
68
+						   settings.settings );
69
 
69
 
70
 	switch ( tag ) {
70
 	switch ( tag ) {
71
 	case DHCP_EB_MAC:
71
 	case DHCP_EB_MAC:

Loading…
Cancel
Save