summaryrefslogtreecommitdiffstats
path: root/src/net/netdev_settings.c
diff options
context:
space:
mode:
authorMichael Brown2017-01-25 15:48:24 +0100
committerMichael Brown2017-01-25 15:55:09 +0100
commit70fc25ad6e71a99b5802eb92b95c26407acbe990 (patch)
treeb5b399a427584f7a78258601fa3d645b3a7ae16d /src/net/netdev_settings.c
parent[interface] Unplug interface before calling intf_close() in intf_shutdown() (diff)
downloadipxe-70fc25ad6e71a99b5802eb92b95c26407acbe990.tar.gz
ipxe-70fc25ad6e71a99b5802eb92b95c26407acbe990.tar.xz
ipxe-70fc25ad6e71a99b5802eb92b95c26407acbe990.zip
[netdevice] Limit MTU by hardware maximum frame length
Separate out the concept of "hardware maximum supported frame length" and "configured link MTU", and limit the latter according to the former. In networks where the DHCP-supplied link MTU is inconsistent with the hardware or driver capabilities (e.g. a network using jumbo frames), this will result in iPXE advertising a TCP MSS consistent with a size that can actually be received. Note that the term "MTU" is typically used to refer to the maximum length excluding the link-layer headers; we adopt this usage. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net/netdev_settings.c')
-rw-r--r--src/net/netdev_settings.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/net/netdev_settings.c b/src/net/netdev_settings.c
index 67a45bed..c54288d4 100644
--- a/src/net/netdev_settings.c
+++ b/src/net/netdev_settings.c
@@ -393,7 +393,8 @@ static int apply_netdev_settings ( void ) {
struct net_device *netdev;
struct settings *settings;
struct ll_protocol *ll_protocol;
- size_t old_max_pkt_len;
+ size_t max_mtu;
+ size_t old_mtu;
size_t mtu;
int rc;
@@ -410,18 +411,25 @@ static int apply_netdev_settings ( void ) {
if ( ! mtu )
continue;
- /* Update maximum packet length */
+ /* Limit MTU to maximum supported by hardware */
ll_protocol = netdev->ll_protocol;
- old_max_pkt_len = netdev->max_pkt_len;
- netdev->max_pkt_len = ( mtu + ll_protocol->ll_header_len );
- if ( netdev->max_pkt_len != old_max_pkt_len ) {
+ max_mtu = ( netdev->max_pkt_len - ll_protocol->ll_header_len );
+ if ( mtu > max_mtu ) {
+ DBGC ( netdev, "NETDEV %s cannot support MTU %zd (max "
+ "%zd)\n", netdev->name, mtu, max_mtu );
+ mtu = max_mtu;
+ }
+
+ /* Update maximum packet length */
+ old_mtu = netdev->mtu;
+ netdev->mtu = mtu;
+ if ( mtu != old_mtu ) {
DBGC ( netdev, "NETDEV %s MTU is %zd\n",
netdev->name, mtu );
}
/* Close and reopen network device if MTU has increased */
- if ( netdev_is_open ( netdev ) &&
- ( netdev->max_pkt_len > old_max_pkt_len ) ) {
+ if ( netdev_is_open ( netdev ) && ( mtu > old_mtu ) ) {
netdev_close ( netdev );
if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
DBGC ( netdev, "NETDEV %s could not reopen: "