Browse Source

[settings] Add Bus ID setting

Users can find the bus type and PCI IDs for a network interface with:

netX/busid

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
tags/v1.0.0-rc1
Shao Miller 15 years ago
parent
commit
177389fb73
3 changed files with 21 additions and 4 deletions
  1. 1
    0
      src/include/gpxe/settings.h
  2. 18
    0
      src/net/netdev_settings.c
  3. 2
    4
      src/net/udp/dhcp.c

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

242
 extern struct setting uuid_setting __setting;
242
 extern struct setting uuid_setting __setting;
243
 extern struct setting next_server_setting __setting;
243
 extern struct setting next_server_setting __setting;
244
 extern struct setting mac_setting __setting;
244
 extern struct setting mac_setting __setting;
245
+extern struct setting busid_setting __setting;
245
 extern struct setting user_class_setting __setting;
246
 extern struct setting user_class_setting __setting;
246
 
247
 
247
 /**
248
 /**

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

20
 
20
 
21
 #include <string.h>
21
 #include <string.h>
22
 #include <errno.h>
22
 #include <errno.h>
23
+#include <byteswap.h>
23
 #include <gpxe/dhcp.h>
24
 #include <gpxe/dhcp.h>
24
 #include <gpxe/settings.h>
25
 #include <gpxe/settings.h>
26
+#include <gpxe/device.h>
25
 #include <gpxe/netdevice.h>
27
 #include <gpxe/netdevice.h>
26
 
28
 
27
 /** @file
29
 /** @file
36
 	.description = "MAC address",
38
 	.description = "MAC address",
37
 	.type = &setting_type_hex,
39
 	.type = &setting_type_hex,
38
 };
40
 };
41
+struct setting busid_setting __setting = {
42
+	.name = "busid",
43
+	.description = "Bus ID",
44
+	.type = &setting_type_hex,
45
+};
39
 
46
 
40
 /**
47
 /**
41
  * Store value of network device setting
48
  * Store value of network device setting
74
 			  void *data, size_t len ) {
81
 			  void *data, size_t len ) {
75
 	struct net_device *netdev = container_of ( settings, struct net_device,
82
 	struct net_device *netdev = container_of ( settings, struct net_device,
76
 						   settings.settings );
83
 						   settings.settings );
84
+	struct device_description *desc = &netdev->dev->desc;
85
+	struct dhcp_netdev_desc dhcp_desc;
77
 
86
 
78
 	if ( setting_cmp ( setting, &mac_setting ) == 0 ) {
87
 	if ( setting_cmp ( setting, &mac_setting ) == 0 ) {
79
 		if ( len > netdev->ll_protocol->ll_addr_len )
88
 		if ( len > netdev->ll_protocol->ll_addr_len )
81
 		memcpy ( data, netdev->ll_addr, len );
90
 		memcpy ( data, netdev->ll_addr, len );
82
 		return netdev->ll_protocol->ll_addr_len;
91
 		return netdev->ll_protocol->ll_addr_len;
83
 	}
92
 	}
93
+	if ( setting_cmp ( setting, &busid_setting ) == 0 ) {
94
+		dhcp_desc.type = desc->bus_type;
95
+		dhcp_desc.vendor = htons ( desc->vendor );
96
+		dhcp_desc.device = htons ( desc->device );
97
+		if ( len > sizeof ( dhcp_desc ) )
98
+			len = sizeof ( dhcp_desc );
99
+		memcpy ( data, &dhcp_desc, len );
100
+		return sizeof ( dhcp_desc );
101
+	}
84
 
102
 
85
 	return generic_settings_fetch ( settings, setting, data, len );
103
 	return generic_settings_fetch ( settings, setting, data, len );
86
 }
104
 }

+ 2
- 4
src/net/udp/dhcp.c View File

932
 int dhcp_create_request ( struct dhcp_packet *dhcppkt,
932
 int dhcp_create_request ( struct dhcp_packet *dhcppkt,
933
 			  struct net_device *netdev, unsigned int msgtype,
933
 			  struct net_device *netdev, unsigned int msgtype,
934
 			  struct in_addr ciaddr, void *data, size_t max_len ) {
934
 			  struct in_addr ciaddr, void *data, size_t max_len ) {
935
-	struct device_description *desc = &netdev->dev->desc;
936
 	struct dhcp_netdev_desc dhcp_desc;
935
 	struct dhcp_netdev_desc dhcp_desc;
937
 	struct dhcp_client_id client_id;
936
 	struct dhcp_client_id client_id;
938
 	struct dhcp_client_uuid client_uuid;
937
 	struct dhcp_client_uuid client_uuid;
966
 	}
965
 	}
967
 
966
 
968
 	/* Add options to identify the network device */
967
 	/* Add options to identify the network device */
969
-	dhcp_desc.type = desc->bus_type;
970
-	dhcp_desc.vendor = htons ( desc->vendor );
971
-	dhcp_desc.device = htons ( desc->device );
968
+	fetch_setting ( &netdev->settings.settings, &busid_setting, &dhcp_desc,
969
+		sizeof ( dhcp_desc ) );
972
 	if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_BUS_ID, &dhcp_desc,
970
 	if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_BUS_ID, &dhcp_desc,
973
 				    sizeof ( dhcp_desc ) ) ) != 0 ) {
971
 				    sizeof ( dhcp_desc ) ) ) != 0 ) {
974
 		DBG ( "DHCP could not set bus ID option: %s\n",
972
 		DBG ( "DHCP could not set bus ID option: %s\n",

Loading…
Cancel
Save