소스 검색

[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 년 전
부모
커밋
3fd81799ba
1개의 변경된 파일22개의 추가작업 그리고 0개의 파일을 삭제
  1. 22
    0
      src/net/netdev_settings.c

+ 22
- 0
src/net/netdev_settings.c 파일 보기

@@ -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
 /**

Loading…
취소
저장