瀏覽代碼

[netdevice] Allow MTU to be changed at runtime

Provide a settings applicator to modify netdev->max_pkt_len in
response to changes to the "mtu" setting (DHCP option 26).

Note that as with MAC address changes, drivers are permitted to
completely ignore any changes in the MTU value.  The net result will
be that iPXE effectively uses the smaller of either the hardware
default MTU or the software configured MTU.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 年之前
父節點
當前提交
16aed6e5ce
共有 3 個文件被更改,包括 67 次插入3 次删除
  1. 3
    0
      src/include/ipxe/dhcp.h
  2. 61
    0
      src/net/netdev_settings.c
  3. 3
    3
      src/net/udp/dhcp.c

+ 3
- 0
src/include/ipxe/dhcp.h 查看文件

@@ -83,6 +83,9 @@ struct dhcp_packet;
83 83
 /** Root path */
84 84
 #define DHCP_ROOT_PATH 17
85 85
 
86
+/** Maximum transmission unit */
87
+#define DHCP_MTU 26
88
+
86 89
 /** Vendor encapsulated options */
87 90
 #define DHCP_VENDOR_ENCAP 43
88 91
 

+ 61
- 0
src/net/netdev_settings.c 查看文件

@@ -70,6 +70,12 @@ const struct setting ifname_setting __setting ( SETTING_NETDEV, ifname ) = {
70 70
 	.description = "Interface name",
71 71
 	.type = &setting_type_string,
72 72
 };
73
+const struct setting mtu_setting __setting ( SETTING_NETDEV, mtu ) = {
74
+	.name = "mtu",
75
+	.description = "MTU",
76
+	.type = &setting_type_int16,
77
+	.tag = DHCP_MTU,
78
+};
73 79
 
74 80
 /**
75 81
  * Store MAC address setting
@@ -377,3 +383,58 @@ static void netdev_redirect_settings_init ( void ) {
377 383
 struct init_fn netdev_redirect_settings_init_fn __init_fn ( INIT_LATE ) = {
378 384
 	.initialise = netdev_redirect_settings_init,
379 385
 };
386
+
387
+/**
388
+ * Apply network device settings
389
+ *
390
+ * @ret rc		Return status code
391
+ */
392
+static int apply_netdev_settings ( void ) {
393
+	struct net_device *netdev;
394
+	struct settings *settings;
395
+	struct ll_protocol *ll_protocol;
396
+	size_t old_max_pkt_len;
397
+	size_t mtu;
398
+	int rc;
399
+
400
+	/* Process settings for each network device */
401
+	for_each_netdev ( netdev ) {
402
+
403
+		/* Get network device settings */
404
+		settings = netdev_settings ( netdev );
405
+
406
+		/* Get MTU */
407
+		mtu = fetch_uintz_setting ( settings, &mtu_setting );
408
+
409
+		/* Do nothing unless MTU is specified */
410
+		if ( ! mtu )
411
+			continue;
412
+
413
+		/* Update maximum packet length */
414
+		ll_protocol = netdev->ll_protocol;
415
+		old_max_pkt_len = netdev->max_pkt_len;
416
+		netdev->max_pkt_len = ( mtu + ll_protocol->ll_header_len );
417
+		if ( netdev->max_pkt_len != old_max_pkt_len ) {
418
+			DBGC ( netdev, "NETDEV %s MTU is %zd\n",
419
+			       netdev->name, mtu );
420
+		}
421
+
422
+		/* Close and reopen network device if MTU has increased */
423
+		if ( netdev_is_open ( netdev ) &&
424
+		     ( netdev->max_pkt_len > old_max_pkt_len ) ) {
425
+			netdev_close ( netdev );
426
+			if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
427
+				DBGC ( netdev, "NETDEV %s could not reopen: "
428
+				       "%s\n", netdev->name, strerror ( rc ) );
429
+				return rc;
430
+			}
431
+		}
432
+	}
433
+
434
+	return 0;
435
+}
436
+
437
+/** Network device settings applicator */
438
+struct settings_applicator netdev_applicator __settings_applicator = {
439
+	.apply = apply_netdev_settings,
440
+};

+ 3
- 3
src/net/udp/dhcp.c 查看文件

@@ -91,9 +91,9 @@ static uint8_t dhcp_request_options_data[] = {
91 91
 	DHCP_PARAMETER_REQUEST_LIST,
92 92
 	DHCP_OPTION ( DHCP_SUBNET_MASK, DHCP_ROUTERS, DHCP_DNS_SERVERS,
93 93
 		      DHCP_LOG_SERVERS, DHCP_HOST_NAME, DHCP_DOMAIN_NAME,
94
-		      DHCP_ROOT_PATH, DHCP_VENDOR_ENCAP, DHCP_VENDOR_CLASS_ID,
95
-		      DHCP_TFTP_SERVER_NAME, DHCP_BOOTFILE_NAME,
96
-		      DHCP_DOMAIN_SEARCH,
94
+		      DHCP_ROOT_PATH, DHCP_MTU, DHCP_VENDOR_ENCAP,
95
+		      DHCP_VENDOR_CLASS_ID, DHCP_TFTP_SERVER_NAME,
96
+		      DHCP_BOOTFILE_NAME, DHCP_DOMAIN_SEARCH,
97 97
 		      128, 129, 130, 131, 132, 133, 134, 135, /* for PXE */
98 98
 		      DHCP_EB_ENCAP, DHCP_ISCSI_INITIATOR_IQN ),
99 99
 	DHCP_END

Loading…
取消
儲存