net/ipv4: Drop ipv4 packet total length bigger than the actual transmitted data

Derived from RFC 791 s3.1 p13 Internet Header Format.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
This commit is contained in:
wenquan1
2025-07-24 10:38:44 +08:00
committed by Xiang Xiao
parent 291199f833
commit 559c6855f3
+5
View File
@@ -187,6 +187,8 @@ static int ipv4_in(FAR struct net_driver_s *dev)
/* Get the size of the packet minus the size of link layer header */
dev->d_len -= NET_LL_HDRLEN(dev);
if (IPv4_HDRLEN > dev->d_len)
{
nwarn("WARNING: Packet shorter than IPv4 header\n");
@@ -214,6 +216,9 @@ static int ipv4_in(FAR struct net_driver_s *dev)
}
else if (totlen > dev->d_len)
{
#ifdef CONFIG_NET_STATISTICS
g_netstats.ipv4.drop++;
#endif
nwarn("WARNING: IP packet shorter than length in IP header\n");
goto drop;
}