Browse Source

[Settings] Add per-netdevice settings block

Add a configuration settings block for each net device.  This will
provide the parent scope for settings applicable only to that network
device (e.g. non-volatile options stored on the NIC, options obtained via
DHCP, etc.).

Expose the MAC address as a setting.
tags/v0.9.4
Michael Brown 17 years ago
parent
commit
acfa14423e

+ 9
- 0
src/include/gpxe/dhcp.h View File

177
  */
177
  */
178
 #define DHCP_EB_SIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 3 )
178
 #define DHCP_EB_SIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 3 )
179
 
179
 
180
+/** MAC address
181
+ *
182
+ * This option is used internally to contain the network device
183
+ * hardware address, in order to provide a consistent approach to
184
+ * storing and processing options.  It should never be present in a
185
+ * DHCP packet.
186
+ */
187
+#define DHCP_EB_MAC DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 4 )
188
+
180
 /*
189
 /*
181
  * Tags in the range 0x10-0x7f are reserved for feature markers
190
  * Tags in the range 0x10-0x7f are reserved for feature markers
182
  *
191
  *

+ 1
- 0
src/include/gpxe/errfile.h View File

129
 #define ERRFILE_dns			( ERRFILE_NET | 0x00110000 )
129
 #define ERRFILE_dns			( ERRFILE_NET | 0x00110000 )
130
 #define ERRFILE_tftp			( ERRFILE_NET | 0x00120000 )
130
 #define ERRFILE_tftp			( ERRFILE_NET | 0x00120000 )
131
 #define ERRFILE_infiniband		( ERRFILE_NET | 0x00130000 )
131
 #define ERRFILE_infiniband		( ERRFILE_NET | 0x00130000 )
132
+#define ERRFILE_netdev_settings		( ERRFILE_NET | 0x00140000 )
132
 
133
 
133
 #define ERRFILE_image		      ( ERRFILE_IMAGE | 0x00000000 )
134
 #define ERRFILE_image		      ( ERRFILE_IMAGE | 0x00000000 )
134
 #define ERRFILE_elf		      ( ERRFILE_IMAGE | 0x00010000 )
135
 #define ERRFILE_elf		      ( ERRFILE_IMAGE | 0x00010000 )

+ 6
- 0
src/include/gpxe/netdevice.h View File

11
 #include <gpxe/list.h>
11
 #include <gpxe/list.h>
12
 #include <gpxe/tables.h>
12
 #include <gpxe/tables.h>
13
 #include <gpxe/refcnt.h>
13
 #include <gpxe/refcnt.h>
14
+#include <gpxe/settings.h>
14
 
15
 
15
 struct io_buffer;
16
 struct io_buffer;
16
 struct net_device;
17
 struct net_device;
243
 	/** Device statistics */
244
 	/** Device statistics */
244
 	struct net_device_stats stats;
245
 	struct net_device_stats stats;
245
 
246
 
247
+	/** Configuration settings applicable to this device */
248
+	struct settings settings;
249
+
246
 	/** Driver private data */
250
 	/** Driver private data */
247
 	void *priv;
251
 	void *priv;
248
 };
252
 };
360
 extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
364
 extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
361
 		    uint16_t net_proto, const void *ll_source );
365
 		    uint16_t net_proto, const void *ll_source );
362
 
366
 
367
+extern struct settings_operations netdev_settings_operations;
368
+
363
 /**
369
 /**
364
  * Complete network transmission
370
  * Complete network transmission
365
  *
371
  *

+ 1
- 1
src/include/gpxe/settings.h View File

17
 
17
 
18
 /** Settings block operations */
18
 /** Settings block operations */
19
 struct settings_operations {
19
 struct settings_operations {
20
-	/** Set value of setting
20
+	/** Store value of setting
21
 	 *
21
 	 *
22
 	 * @v settings		Settings block
22
 	 * @v settings		Settings block
23
 	 * @v tag		Setting tag number
23
 	 * @v tag		Setting tag number

+ 95
- 0
src/net/netdev_settings.c View File

1
+/*
2
+ * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#include <string.h>
20
+#include <errno.h>
21
+#include <gpxe/dhcp.h>
22
+#include <gpxe/settings.h>
23
+#include <gpxe/netdevice.h>
24
+
25
+/** @file
26
+ *
27
+ * Network device configuration settings
28
+ *
29
+ */
30
+
31
+/**
32
+ * Store value of network device setting
33
+ *
34
+ * @v settings		Settings block
35
+ * @v tag		Setting tag number
36
+ * @v data		Setting data, or NULL to clear setting
37
+ * @v len		Length of setting data
38
+ * @ret rc		Return status code
39
+ */
40
+static int netdev_store ( struct settings *settings, unsigned int tag,
41
+			  const void *data, size_t len ) {
42
+	struct net_device *netdev =
43
+		container_of ( settings, struct net_device, settings );
44
+
45
+	switch ( tag ) {
46
+	case DHCP_EB_MAC:
47
+		if ( len != netdev->ll_protocol->ll_addr_len )
48
+			return -EINVAL;
49
+		memcpy ( netdev->ll_addr, data, len );
50
+		return 0;
51
+	default :
52
+		return simple_settings_store ( settings, tag, data, len );
53
+	}
54
+}
55
+
56
+/**
57
+ * Fetch value of network device setting
58
+ *
59
+ * @v settings		Settings block
60
+ * @v tag		Setting tag number
61
+ * @v data		Setting data, or NULL to clear setting
62
+ * @v len		Length of setting data
63
+ * @ret rc		Return status code
64
+ */
65
+static int netdev_fetch ( struct settings *settings, unsigned int tag,
66
+			  void *data, size_t len ) {
67
+	struct net_device *netdev =
68
+		container_of ( settings, struct net_device, settings );
69
+
70
+	switch ( tag ) {
71
+	case DHCP_EB_MAC:
72
+		if ( len > netdev->ll_protocol->ll_addr_len )
73
+			len = netdev->ll_protocol->ll_addr_len;
74
+		memcpy ( data, netdev->ll_addr, len );
75
+		return netdev->ll_protocol->ll_addr_len;
76
+	default :
77
+		return simple_settings_fetch ( settings, tag, data, len );
78
+	}
79
+}
80
+
81
+/** Network device configuration settings operations */
82
+struct settings_operations netdev_settings_operations = {
83
+	.store = netdev_store,
84
+	.fetch = netdev_fetch,
85
+};
86
+
87
+/** Network device named settings */
88
+struct named_setting netdev_named_settings[] __named_setting = {
89
+	{
90
+		.name = "mac",
91
+		.description = "MAC address",
92
+		.tag = DHCP_EB_MAC,
93
+		.type = &setting_type_hex,
94
+	},
95
+};

+ 14
- 0
src/net/netdevice.c View File

266
 		netdev->refcnt.free = free_netdev;
266
 		netdev->refcnt.free = free_netdev;
267
 		INIT_LIST_HEAD ( &netdev->tx_queue );
267
 		INIT_LIST_HEAD ( &netdev->tx_queue );
268
 		INIT_LIST_HEAD ( &netdev->rx_queue );
268
 		INIT_LIST_HEAD ( &netdev->rx_queue );
269
+		settings_init ( &netdev->settings,
270
+				&netdev_settings_operations, &netdev->refcnt,
271
+				netdev->name );
269
 		netdev->priv = ( ( ( void * ) netdev ) + sizeof ( *netdev ) );
272
 		netdev->priv = ( ( ( void * ) netdev ) + sizeof ( *netdev ) );
270
 	}
273
 	}
271
 	return netdev;
274
 	return netdev;
282
  */
285
  */
283
 int register_netdev ( struct net_device *netdev ) {
286
 int register_netdev ( struct net_device *netdev ) {
284
 	static unsigned int ifindex = 0;
287
 	static unsigned int ifindex = 0;
288
+	int rc;
285
 
289
 
286
 	/* Create device name */
290
 	/* Create device name */
287
 	snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
291
 	snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
288
 		   ifindex++ );
292
 		   ifindex++ );
289
 
293
 
294
+	/* Register per-netdev configuration settings */
295
+	if ( ( rc = register_settings ( &netdev->settings, NULL ) ) != 0 ) {
296
+		DBGC ( netdev, "NETDEV %p could not register settings: %s\n",
297
+		       netdev, strerror ( rc ) );
298
+		return rc;
299
+	}
300
+
290
 	/* Add to device list */
301
 	/* Add to device list */
291
 	netdev_get ( netdev );
302
 	netdev_get ( netdev );
292
 	list_add_tail ( &netdev->list, &net_devices );
303
 	list_add_tail ( &netdev->list, &net_devices );
357
 	/* Ensure device is closed */
368
 	/* Ensure device is closed */
358
 	netdev_close ( netdev );
369
 	netdev_close ( netdev );
359
 
370
 
371
+	/* Unregister per-netdev configuration settings */
372
+	unregister_settings ( &netdev->settings );
373
+
360
 	/* Remove from device list */
374
 	/* Remove from device list */
361
 	list_del ( &netdev->list );
375
 	list_del ( &netdev->list );
362
 	netdev_put ( netdev );
376
 	netdev_put ( netdev );

Loading…
Cancel
Save