mirror of
https://github.com/ipxe/ipxe
synced 2026-05-22 00:03:42 +03:00
[netdevice] Add "ifname" setting
Expose the network interface name (e.g. "net0") as a setting. This
allows a script to obtain the name of the most recently opened network
interface via ${netX/ifname}.
Signed-off-by: Andrew Widdersheim <amwiddersheim@gmail.com>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
committed by
Michael Brown
parent
cc252605ce
commit
3fd81799ba
@@ -65,6 +65,11 @@ const struct setting chip_setting __setting ( SETTING_NETDEV, chip ) = {
|
|||||||
.description = "Chip",
|
.description = "Chip",
|
||||||
.type = &setting_type_string,
|
.type = &setting_type_string,
|
||||||
};
|
};
|
||||||
|
const struct setting ifname_setting __setting ( SETTING_NETDEV, ifname ) = {
|
||||||
|
.name = "ifname",
|
||||||
|
.description = "Interface name",
|
||||||
|
.type = &setting_type_string,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store MAC address setting
|
* Store MAC address setting
|
||||||
@@ -199,6 +204,22 @@ static int netdev_fetch_chip ( struct net_device *netdev, void *data,
|
|||||||
return strlen ( chip );
|
return strlen ( chip );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch ifname setting
|
||||||
|
*
|
||||||
|
* @v netdev Network device
|
||||||
|
* @v data Buffer to fill with setting data
|
||||||
|
* @v len Length of buffer
|
||||||
|
* @ret len Length of setting data, or negative error
|
||||||
|
*/
|
||||||
|
static int netdev_fetch_ifname ( struct net_device *netdev, void *data,
|
||||||
|
size_t len ) {
|
||||||
|
const char *ifname = netdev->name;
|
||||||
|
|
||||||
|
strncpy ( data, ifname, len );
|
||||||
|
return strlen ( ifname );
|
||||||
|
}
|
||||||
|
|
||||||
/** A network device setting operation */
|
/** A network device setting operation */
|
||||||
struct netdev_setting_operation {
|
struct netdev_setting_operation {
|
||||||
/** Setting */
|
/** Setting */
|
||||||
@@ -229,6 +250,7 @@ static struct netdev_setting_operation netdev_setting_operations[] = {
|
|||||||
{ &busloc_setting, NULL, netdev_fetch_busloc },
|
{ &busloc_setting, NULL, netdev_fetch_busloc },
|
||||||
{ &busid_setting, NULL, netdev_fetch_busid },
|
{ &busid_setting, NULL, netdev_fetch_busid },
|
||||||
{ &chip_setting, NULL, netdev_fetch_chip },
|
{ &chip_setting, NULL, netdev_fetch_chip },
|
||||||
|
{ &ifname_setting, NULL, netdev_fetch_ifname },
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user