summaryrefslogtreecommitdiffstats
path: root/src/net/tcpip.c
diff options
context:
space:
mode:
authorMichael Brown2014-03-04 14:10:07 +0100
committerMichael Brown2014-03-04 14:13:54 +0100
commit6414b5ca036ade7545eb0c309c66731fced6e055 (patch)
treedd73109b6fbbff5e176b87c30df744665595cafb /src/net/tcpip.c
parent[tcpip] Provide tcpip_netdev() to determine the transmitting network device (diff)
downloadipxe-6414b5ca036ade7545eb0c309c66731fced6e055.tar.gz
ipxe-6414b5ca036ade7545eb0c309c66731fced6e055.tar.xz
ipxe-6414b5ca036ade7545eb0c309c66731fced6e055.zip
[tcpip] Provide tcpip_mtu() to determine the maximum transmission unit
Provide the function tcpip_mtu() to allow external code to determine the (transport-layer) maximum transmission unit for a given socket address. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net/tcpip.c')
-rw-r--r--src/net/tcpip.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/net/tcpip.c b/src/net/tcpip.c
index 6fac8c52..4bcbe64b 100644
--- a/src/net/tcpip.c
+++ b/src/net/tcpip.c
@@ -6,6 +6,7 @@
#include <ipxe/iobuf.h>
#include <ipxe/tables.h>
#include <ipxe/ipstat.h>
+#include <ipxe/netdevice.h>
#include <ipxe/tcpip.h>
/** @file
@@ -123,6 +124,34 @@ struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest ) {
}
/**
+ * Determine maximum transmission unit
+ *
+ * @v st_dest Destination address
+ * @ret mtu Maximum transmission unit
+ */
+size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest ) {
+ struct tcpip_net_protocol *tcpip_net;
+ struct net_device *netdev;
+ size_t mtu;
+
+ /* Find appropriate network-layer protocol */
+ tcpip_net = tcpip_net_protocol ( st_dest );
+ if ( ! tcpip_net )
+ return 0;
+
+ /* Find transmitting network device */
+ netdev = tcpip_net->netdev ( st_dest );
+ if ( ! netdev )
+ return 0;
+
+ /* Calculate MTU */
+ mtu = ( netdev->max_pkt_len - netdev->ll_protocol->ll_header_len -
+ tcpip_net->header_len );
+
+ return mtu;
+}
+
+/**
* Calculate continued TCP/IP checkum
*
* @v partial Checksum of already-summed data, in network byte order