Ver código fonte

[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>
tags/v1.20.1
Andrew Widdersheim 8 anos atrás
pai
commit
3fd81799ba
1 arquivos alterados com 22 adições e 0 exclusões
  1. 22
    0
      src/net/netdev_settings.c

+ 22
- 0
src/net/netdev_settings.c Ver arquivo

@@ -65,6 +65,11 @@ const struct setting chip_setting __setting ( SETTING_NETDEV, chip ) = {
65 65
 	.description = "Chip",
66 66
 	.type = &setting_type_string,
67 67
 };
68
+const struct setting ifname_setting __setting ( SETTING_NETDEV, ifname ) = {
69
+	.name = "ifname",
70
+	.description = "Interface name",
71
+	.type = &setting_type_string,
72
+};
68 73
 
69 74
 /**
70 75
  * Store MAC address setting
@@ -199,6 +204,22 @@ static int netdev_fetch_chip ( struct net_device *netdev, void *data,
199 204
 	return strlen ( chip );
200 205
 }
201 206
 
207
+/**
208
+ * Fetch ifname setting
209
+ *
210
+ * @v netdev		Network device
211
+ * @v data		Buffer to fill with setting data
212
+ * @v len		Length of buffer
213
+ * @ret len		Length of setting data, or negative error
214
+ */
215
+static int netdev_fetch_ifname ( struct net_device *netdev, void *data,
216
+				 size_t len ) {
217
+	const char *ifname = netdev->name;
218
+
219
+	strncpy ( data, ifname, len );
220
+	return strlen ( ifname );
221
+}
222
+
202 223
 /** A network device setting operation */
203 224
 struct netdev_setting_operation {
204 225
 	/** Setting */
@@ -229,6 +250,7 @@ static struct netdev_setting_operation netdev_setting_operations[] = {
229 250
 	{ &busloc_setting, NULL, netdev_fetch_busloc },
230 251
 	{ &busid_setting, NULL, netdev_fetch_busid },
231 252
 	{ &chip_setting, NULL, netdev_fetch_chip },
253
+	{ &ifname_setting, NULL, netdev_fetch_ifname },
232 254
 };
233 255
 
234 256
 /**

Carregando…
Cancelar
Salvar