Просмотр исходного кода

[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 лет назад
Родитель
Сommit
177389fb73
3 измененных файлов: 21 добавлений и 4 удалений
  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 Просмотреть файл

@@ -242,6 +242,7 @@ extern struct setting priority_setting __setting;
242 242
 extern struct setting uuid_setting __setting;
243 243
 extern struct setting next_server_setting __setting;
244 244
 extern struct setting mac_setting __setting;
245
+extern struct setting busid_setting __setting;
245 246
 extern struct setting user_class_setting __setting;
246 247
 
247 248
 /**

+ 18
- 0
src/net/netdev_settings.c Просмотреть файл

@@ -20,8 +20,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
20 20
 
21 21
 #include <string.h>
22 22
 #include <errno.h>
23
+#include <byteswap.h>
23 24
 #include <gpxe/dhcp.h>
24 25
 #include <gpxe/settings.h>
26
+#include <gpxe/device.h>
25 27
 #include <gpxe/netdevice.h>
26 28
 
27 29
 /** @file
@@ -36,6 +38,11 @@ struct setting mac_setting __setting = {
36 38
 	.description = "MAC address",
37 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 48
  * Store value of network device setting
@@ -74,6 +81,8 @@ static int netdev_fetch ( struct settings *settings, struct setting *setting,
74 81
 			  void *data, size_t len ) {
75 82
 	struct net_device *netdev = container_of ( settings, struct net_device,
76 83
 						   settings.settings );
84
+	struct device_description *desc = &netdev->dev->desc;
85
+	struct dhcp_netdev_desc dhcp_desc;
77 86
 
78 87
 	if ( setting_cmp ( setting, &mac_setting ) == 0 ) {
79 88
 		if ( len > netdev->ll_protocol->ll_addr_len )
@@ -81,6 +90,15 @@ static int netdev_fetch ( struct settings *settings, struct setting *setting,
81 90
 		memcpy ( data, netdev->ll_addr, len );
82 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 103
 	return generic_settings_fetch ( settings, setting, data, len );
86 104
 }

+ 2
- 4
src/net/udp/dhcp.c Просмотреть файл

@@ -932,7 +932,6 @@ int dhcp_create_packet ( struct dhcp_packet *dhcppkt,
932 932
 int dhcp_create_request ( struct dhcp_packet *dhcppkt,
933 933
 			  struct net_device *netdev, unsigned int msgtype,
934 934
 			  struct in_addr ciaddr, void *data, size_t max_len ) {
935
-	struct device_description *desc = &netdev->dev->desc;
936 935
 	struct dhcp_netdev_desc dhcp_desc;
937 936
 	struct dhcp_client_id client_id;
938 937
 	struct dhcp_client_uuid client_uuid;
@@ -966,9 +965,8 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
966 965
 	}
967 966
 
968 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 970
 	if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_BUS_ID, &dhcp_desc,
973 971
 				    sizeof ( dhcp_desc ) ) ) != 0 ) {
974 972
 		DBG ( "DHCP could not set bus ID option: %s\n",

Загрузка…
Отмена
Сохранить