mirror of
https://github.com/ipxe/ipxe
synced 2026-02-14 02:31:26 +03:00
[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>
This commit is contained in:
@@ -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
|
||||
@@ -122,6 +123,34 @@ struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user