|
@@ -19,6 +19,7 @@
|
19
|
19
|
#include <stdint.h>
|
20
|
20
|
#include <stdlib.h>
|
21
|
21
|
#include <string.h>
|
|
22
|
+#include <byteswap.h>
|
22
|
23
|
#include <errno.h>
|
23
|
24
|
#include <assert.h>
|
24
|
25
|
#include <vsprintf.h>
|
|
@@ -172,7 +173,8 @@ static int show_string ( struct config_context *context,
|
172
|
173
|
return 0;
|
173
|
174
|
}
|
174
|
175
|
|
175
|
|
-/** Set value of string setting
|
|
176
|
+/**
|
|
177
|
+ * Set value of string setting
|
176
|
178
|
*
|
177
|
179
|
* @v context Configuration context
|
178
|
180
|
* @v setting Configuration setting
|
|
@@ -221,7 +223,8 @@ static int show_ipv4 ( struct config_context *context,
|
221
|
223
|
return 0;
|
222
|
224
|
}
|
223
|
225
|
|
224
|
|
-/** Set value of IPV4 setting
|
|
226
|
+/**
|
|
227
|
+ * Set value of IPV4 setting
|
225
|
228
|
*
|
226
|
229
|
* @v context Configuration context
|
227
|
230
|
* @v setting Configuration setting
|
|
@@ -251,6 +254,85 @@ struct config_setting_type config_setting_type_ipv4 __config_setting_type = {
|
251
|
254
|
.set = set_ipv4,
|
252
|
255
|
};
|
253
|
256
|
|
|
257
|
+/**
|
|
258
|
+ * Show value of integer setting
|
|
259
|
+ *
|
|
260
|
+ * @v context Configuration context
|
|
261
|
+ * @v setting Configuration setting
|
|
262
|
+ * @v buf Buffer to contain value
|
|
263
|
+ * @v len Length of buffer
|
|
264
|
+ * @ret rc Return status code
|
|
265
|
+ */
|
|
266
|
+static int show_int ( struct config_context *context,
|
|
267
|
+ struct config_setting *setting,
|
|
268
|
+ char *buf, size_t len ) {
|
|
269
|
+ struct dhcp_option *option;
|
|
270
|
+ long num;
|
|
271
|
+
|
|
272
|
+ option = find_dhcp_option ( context->options, setting->tag );
|
|
273
|
+ if ( ! option )
|
|
274
|
+ return -ENODATA;
|
|
275
|
+ num = dhcp_num_option ( option );
|
|
276
|
+ snprintf ( buf, len, "%ld", num );
|
|
277
|
+ return 0;
|
|
278
|
+}
|
|
279
|
+
|
|
280
|
+/**
|
|
281
|
+ * Set value of integer setting
|
|
282
|
+ *
|
|
283
|
+ * @v context Configuration context
|
|
284
|
+ * @v setting Configuration setting
|
|
285
|
+ * @v value Setting value (as a string)
|
|
286
|
+ * @v size Size of integer (in bytes)
|
|
287
|
+ * @ret rc Return status code
|
|
288
|
+ */
|
|
289
|
+static int set_int ( struct config_context *context,
|
|
290
|
+ struct config_setting *setting,
|
|
291
|
+ const char *value, unsigned int size ) {
|
|
292
|
+ struct dhcp_option *option;
|
|
293
|
+ union {
|
|
294
|
+ uint32_t num;
|
|
295
|
+ uint8_t bytes[4];
|
|
296
|
+ } u;
|
|
297
|
+ char *endp;
|
|
298
|
+
|
|
299
|
+ /* Parse number */
|
|
300
|
+ if ( ! *value )
|
|
301
|
+ return -EINVAL;
|
|
302
|
+ u.num = htonl ( strtoul ( value, &endp, 0 ) );
|
|
303
|
+ if ( *endp )
|
|
304
|
+ return -EINVAL;
|
|
305
|
+
|
|
306
|
+ /* Set option */
|
|
307
|
+ option = set_dhcp_option ( context->options, setting->tag,
|
|
308
|
+ &u.bytes[ sizeof ( u ) - size ], size );
|
|
309
|
+ if ( ! option )
|
|
310
|
+ return -ENOMEM;
|
|
311
|
+ return 0;
|
|
312
|
+}
|
|
313
|
+
|
|
314
|
+/**
|
|
315
|
+ * Set value of 8-bit integer setting
|
|
316
|
+ *
|
|
317
|
+ * @v context Configuration context
|
|
318
|
+ * @v setting Configuration setting
|
|
319
|
+ * @v value Setting value (as a string)
|
|
320
|
+ * @v size Size of integer (in bytes)
|
|
321
|
+ * @ret rc Return status code
|
|
322
|
+ */
|
|
323
|
+static int set_int8 ( struct config_context *context,
|
|
324
|
+ struct config_setting *setting,
|
|
325
|
+ const char *value ) {
|
|
326
|
+ return set_int ( context, setting, value, 8 );
|
|
327
|
+}
|
|
328
|
+
|
|
329
|
+/** An 8-bit integer configuration setting */
|
|
330
|
+struct config_setting_type config_setting_type_int8 __config_setting_type = {
|
|
331
|
+ .name = "int8",
|
|
332
|
+ .show = show_int,
|
|
333
|
+ .set = set_int8,
|
|
334
|
+};
|
|
335
|
+
|
254
|
336
|
/** Some basic setting definitions */
|
255
|
337
|
struct config_setting ip_config_setting __config_setting = {
|
256
|
338
|
.name = "ip",
|
|
@@ -272,3 +354,13 @@ struct config_setting password_config_setting __config_setting = {
|
272
|
354
|
.tag = DHCP_EB_PASSWORD,
|
273
|
355
|
.type = &config_setting_type_string,
|
274
|
356
|
};
|
|
357
|
+struct config_setting root_path_config_setting __config_setting = {
|
|
358
|
+ .name = "root-path",
|
|
359
|
+ .tag = DHCP_ROOT_PATH,
|
|
360
|
+ .type = &config_setting_type_string,
|
|
361
|
+};
|
|
362
|
+struct config_setting priority_config_setting __config_setting = {
|
|
363
|
+ .name = "priority",
|
|
364
|
+ .tag = DHCP_EB_PRIORITY,
|
|
365
|
+ .type = &config_setting_type_int8,
|
|
366
|
+};
|