aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>2022-10-14 19:43:40 +0200
committerTom Rini <trini@konsulko.com>2022-11-28 10:25:18 -0500
commit06653c701040f34e05d587bf14c2600f8cb3460f (patch)
treef46f2a556b8419d51097b7e6791ce99280d7dc16
parent1817c3824a08bbad7fd2fbae1a6e73be896e8e5e (diff)
downloadu-boot-06653c701040f34e05d587bf14c2600f8cb3460f.zip
u-boot-06653c701040f34e05d587bf14c2600f8cb3460f.tar.gz
u-boot-06653c701040f34e05d587bf14c2600f8cb3460f.tar.bz2
net: fix ip_len in reassembled IP datagram
For some reason, the ip_len field in a reassembled IP datagram is set to just the size of the payload, but it should be set to the value it would have had if the datagram had never been fragmented in the first place, i.e. size of payload plus size of IP header. That latter value is currently returned correctly via the "len" variable. And before entering net_defragment(), len does have the value ntohs(ip->ip_len), so if we're not dealing with a fragment (so net_defragment leaves *len alone), that relationship of course also holds after the net_defragment() call. The only use I can find of ip->ip_len after the net_defragment call is the ntohs(ip->udp_len) > ntohs(ip->ip_len) sanity check - none of the functions that are passed the "ip" pointer themselves inspect ->ip_len but instead use the passed len. But that sanity check is a bit odd, since the RHS really should be "ntohs(ip->ip_len) - 20", i.e. the IP payload size. Now that we've fixed things so that len == ntohs(ip->ip_len) in all cases, change that sanity check to use len-20 as the RHS. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
-rw-r--r--net/net.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/net/net.c b/net/net.c
index 987c259..073fb68 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1040,8 +1040,8 @@ static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
if (!done)
return NULL;
- localip->ip_len = htons(total_len);
*lenp = total_len + IP_HDR_SIZE;
+ localip->ip_len = htons(*lenp);
return localip;
}
@@ -1289,7 +1289,7 @@ void net_process_received_packet(uchar *in_packet, int len)
return;
}
- if (ntohs(ip->udp_len) < UDP_HDR_SIZE || ntohs(ip->udp_len) > ntohs(ip->ip_len))
+ if (ntohs(ip->udp_len) < UDP_HDR_SIZE || ntohs(ip->udp_len) > len - IP_HDR_SIZE)
return;
debug_cond(DEBUG_DEV_PKT,