Przeglądaj źródła

[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>
tags/v1.20.1
Michael Brown 10 lat temu
rodzic
commit
6414b5ca03
4 zmienionych plików z 34 dodań i 0 usunięć
  1. 3
    0
      src/include/ipxe/tcpip.h
  2. 1
    0
      src/net/ipv4.c
  3. 1
    0
      src/net/ipv6.c
  4. 29
    0
      src/net/tcpip.c

+ 3
- 0
src/include/ipxe/tcpip.h Wyświetl plik

@@ -97,6 +97,8 @@ struct tcpip_net_protocol {
97 97
 	const char *name;
98 98
 	/** Network address family */
99 99
 	sa_family_t sa_family;
100
+	/** Fixed header length */
101
+	size_t header_len;
100 102
 	/**
101 103
 	 * Transmit packet
102 104
 	 *
@@ -148,6 +150,7 @@ extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip,
148 150
 		      struct net_device *netdev,
149 151
 		      uint16_t *trans_csum );
150 152
 extern struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest );
153
+extern size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest );
151 154
 extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial,
152 155
 						const void *data, size_t len );
153 156
 extern uint16_t tcpip_chksum ( const void *data, size_t len );

+ 1
- 0
src/net/ipv4.c Wyświetl plik

@@ -621,6 +621,7 @@ struct net_protocol ipv4_protocol __net_protocol = {
621 621
 struct tcpip_net_protocol ipv4_tcpip_protocol __tcpip_net_protocol = {
622 622
 	.name = "IPv4",
623 623
 	.sa_family = AF_INET,
624
+	.header_len = sizeof ( struct iphdr ),
624 625
 	.tx = ipv4_tx,
625 626
 	.netdev = ipv4_netdev,
626 627
 };

+ 1
- 0
src/net/ipv6.c Wyświetl plik

@@ -988,6 +988,7 @@ struct net_protocol ipv6_protocol __net_protocol = {
988 988
 struct tcpip_net_protocol ipv6_tcpip_protocol __tcpip_net_protocol = {
989 989
 	.name = "IPv6",
990 990
 	.sa_family = AF_INET6,
991
+	.header_len = sizeof ( struct ipv6_header ),
991 992
 	.tx = ipv6_tx,
992 993
 	.netdev = ipv6_netdev,
993 994
 };

+ 29
- 0
src/net/tcpip.c Wyświetl plik

@@ -6,6 +6,7 @@
6 6
 #include <ipxe/iobuf.h>
7 7
 #include <ipxe/tables.h>
8 8
 #include <ipxe/ipstat.h>
9
+#include <ipxe/netdevice.h>
9 10
 #include <ipxe/tcpip.h>
10 11
 
11 12
 /** @file
@@ -122,6 +123,34 @@ struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest ) {
122 123
 	return NULL;
123 124
 }
124 125
 
126
+/**
127
+ * Determine maximum transmission unit
128
+ *
129
+ * @v st_dest		Destination address
130
+ * @ret mtu		Maximum transmission unit
131
+ */
132
+size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest ) {
133
+	struct tcpip_net_protocol *tcpip_net;
134
+	struct net_device *netdev;
135
+	size_t mtu;
136
+
137
+	/* Find appropriate network-layer protocol */
138
+	tcpip_net = tcpip_net_protocol ( st_dest );
139
+	if ( ! tcpip_net )
140
+		return 0;
141
+
142
+	/* Find transmitting network device */
143
+	netdev = tcpip_net->netdev ( st_dest );
144
+	if ( ! netdev )
145
+		return 0;
146
+
147
+	/* Calculate MTU */
148
+	mtu = ( netdev->max_pkt_len - netdev->ll_protocol->ll_header_len -
149
+		tcpip_net->header_len );
150
+
151
+	return mtu;
152
+}
153
+
125 154
 /**
126 155
  * Calculate continued TCP/IP checkum
127 156
  *

Ładowanie…
Anuluj
Zapisz