Browse Source

[netdevice] Add "hwaddr" setting

Expose the underlying hardware address as a setting.  For IPoIB
devices, this provides scripts with access to the Infiniband GUID.

Requested-by: Allen, Benjamin S. <bsallen@alcf.anl.gov>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 years ago
parent
commit
8047baf7c6
1 changed files with 30 additions and 5 deletions
  1. 30
    5
      src/net/netdev_settings.c

+ 30
- 5
src/net/netdev_settings.c View File

@@ -45,6 +45,11 @@ const struct setting mac_setting __setting ( SETTING_NETDEV, mac ) = {
45 45
 	.description = "MAC address",
46 46
 	.type = &setting_type_hex,
47 47
 };
48
+const struct setting hwaddr_setting __setting ( SETTING_NETDEV, hwaddr ) = {
49
+	.name = "hwaddr",
50
+	.description = "Hardware address",
51
+	.type = &setting_type_hex,
52
+};
48 53
 const struct setting bustype_setting __setting ( SETTING_NETDEV, bustype ) = {
49 54
 	.name = "bustype",
50 55
 	.description = "Bus type",
@@ -78,7 +83,7 @@ const struct setting mtu_setting __setting ( SETTING_NETDEV, mtu ) = {
78 83
 };
79 84
 
80 85
 /**
81
- * Store MAC address setting
86
+ * Store link-layer address setting
82 87
  *
83 88
  * @v netdev		Network device
84 89
  * @v data		Setting data, or NULL to clear setting
@@ -103,7 +108,7 @@ static int netdev_store_mac ( struct net_device *netdev,
103 108
 }
104 109
 
105 110
 /**
106
- * Fetch MAC address setting
111
+ * Fetch link-layer address setting
107 112
  *
108 113
  * @v netdev		Network device
109 114
  * @v data		Buffer to fill with setting data
@@ -112,11 +117,30 @@ static int netdev_store_mac ( struct net_device *netdev,
112 117
  */
113 118
 static int netdev_fetch_mac ( struct net_device *netdev, void *data,
114 119
 			      size_t len ) {
120
+	size_t max_len = netdev->ll_protocol->ll_addr_len;
115 121
 
116
-	if ( len > netdev->ll_protocol->ll_addr_len )
117
-		len = netdev->ll_protocol->ll_addr_len;
122
+	if ( len > max_len )
123
+		len = max_len;
118 124
 	memcpy ( data, netdev->ll_addr, len );
119
-	return netdev->ll_protocol->ll_addr_len;
125
+	return max_len;
126
+}
127
+
128
+/**
129
+ * Fetch hardware address setting
130
+ *
131
+ * @v netdev		Network device
132
+ * @v data		Buffer to fill with setting data
133
+ * @v len		Length of buffer
134
+ * @ret len		Length of setting data, or negative error
135
+ */
136
+static int netdev_fetch_hwaddr ( struct net_device *netdev, void *data,
137
+				 size_t len ) {
138
+	size_t max_len = netdev->ll_protocol->hw_addr_len;
139
+
140
+	if ( len > max_len )
141
+		len = max_len;
142
+	memcpy ( data, netdev->hw_addr, len );
143
+	return max_len;
120 144
 }
121 145
 
122 146
 /**
@@ -253,6 +277,7 @@ struct netdev_setting_operation {
253 277
 /** Network device settings */
254 278
 static struct netdev_setting_operation netdev_setting_operations[] = {
255 279
 	{ &mac_setting, netdev_store_mac, netdev_fetch_mac },
280
+	{ &hwaddr_setting, NULL, netdev_fetch_hwaddr },
256 281
 	{ &bustype_setting, NULL, netdev_fetch_bustype },
257 282
 	{ &busloc_setting, NULL, netdev_fetch_busloc },
258 283
 	{ &busid_setting, NULL, netdev_fetch_busid },

Loading…
Cancel
Save