Skip to content

Commit 8047baf

Browse files
committedSep 6, 2017
[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>
1 parent 7e673a6 commit 8047baf

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed
 

‎src/net/netdev_settings.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ const struct setting mac_setting __setting ( SETTING_NETDEV, mac ) = {
4545
.description = "MAC address",
4646
.type = &setting_type_hex,
4747
};
48+
const struct setting hwaddr_setting __setting ( SETTING_NETDEV, hwaddr ) = {
49+
.name = "hwaddr",
50+
.description = "Hardware address",
51+
.type = &setting_type_hex,
52+
};
4853
const struct setting bustype_setting __setting ( SETTING_NETDEV, bustype ) = {
4954
.name = "bustype",
5055
.description = "Bus type",
@@ -78,7 +83,7 @@ const struct setting mtu_setting __setting ( SETTING_NETDEV, mtu ) = {
7883
};
7984

8085
/**
81-
* Store MAC address setting
86+
* Store link-layer address setting
8287
*
8388
* @v netdev Network device
8489
* @v data Setting data, or NULL to clear setting
@@ -103,7 +108,7 @@ static int netdev_store_mac ( struct net_device *netdev,
103108
}
104109

105110
/**
106-
* Fetch MAC address setting
111+
* Fetch link-layer address setting
107112
*
108113
* @v netdev Network device
109114
* @v data Buffer to fill with setting data
@@ -112,11 +117,30 @@ static int netdev_store_mac ( struct net_device *netdev,
112117
*/
113118
static int netdev_fetch_mac ( struct net_device *netdev, void *data,
114119
size_t len ) {
120+
size_t max_len = netdev->ll_protocol->ll_addr_len;
115121

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;
118124
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;
120144
}
121145

122146
/**
@@ -253,6 +277,7 @@ struct netdev_setting_operation {
253277
/** Network device settings */
254278
static struct netdev_setting_operation netdev_setting_operations[] = {
255279
{ &mac_setting, netdev_store_mac, netdev_fetch_mac },
280+
{ &hwaddr_setting, NULL, netdev_fetch_hwaddr },
256281
{ &bustype_setting, NULL, netdev_fetch_bustype },
257282
{ &busloc_setting, NULL, netdev_fetch_busloc },
258283
{ &busid_setting, NULL, netdev_fetch_busid },

0 commit comments

Comments
 (0)