Browse Source

[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 years ago
parent
commit
3fd81799ba
1 changed files with 22 additions and 0 deletions
  1. 22
    0
      src/net/netdev_settings.c

+ 22
- 0
src/net/netdev_settings.c View File

65
 	.description = "Chip",
65
 	.description = "Chip",
66
 	.type = &setting_type_string,
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
  * Store MAC address setting
75
  * Store MAC address setting
199
 	return strlen ( chip );
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
 /** A network device setting operation */
223
 /** A network device setting operation */
203
 struct netdev_setting_operation {
224
 struct netdev_setting_operation {
204
 	/** Setting */
225
 	/** Setting */
229
 	{ &busloc_setting, NULL, netdev_fetch_busloc },
250
 	{ &busloc_setting, NULL, netdev_fetch_busloc },
230
 	{ &busid_setting, NULL, netdev_fetch_busid },
251
 	{ &busid_setting, NULL, netdev_fetch_busid },
231
 	{ &chip_setting, NULL, netdev_fetch_chip },
252
 	{ &chip_setting, NULL, netdev_fetch_chip },
253
+	{ &ifname_setting, NULL, netdev_fetch_ifname },
232
 };
254
 };
233
 
255
 
234
 /**
256
 /**

Loading…
Cancel
Save