Skip to content

Commit fc16c42

Browse files
jukkarkartben
authored andcommitted
net: core: Do IPv4/6 packet checks only for those packet types
The check_ip() in net_core.c did not check that the packet Ethernet type is either IPv4 or IPv6. This meant that we for example checked TTL also for ARP packets which is pointless as those are not IPv4 packets. Fix this by checking the link layer protocol type of the packet to be either IPv4 or IPv6 before doing L3 checks. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
1 parent 62e1d4b commit fc16c42

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

subsys/net/ip/net_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ static inline int check_ip(struct net_pkt *pkt)
215215
family = net_pkt_family(pkt);
216216
ret = 0;
217217

218-
if (IS_ENABLED(CONFIG_NET_IPV6) && family == AF_INET6) {
218+
if (IS_ENABLED(CONFIG_NET_IPV6) && family == AF_INET6 &&
219+
net_pkt_ll_proto_type(pkt) == NET_ETH_PTYPE_IPV6) {
219220
/* Drop IPv6 packet if hop limit is 0 */
220221
if (NET_IPV6_HDR(pkt)->hop_limit == 0) {
221222
NET_DBG("DROP: IPv6 hop limit");
@@ -288,7 +289,8 @@ static inline int check_ip(struct net_pkt *pkt)
288289
goto drop;
289290
}
290291

291-
} else if (IS_ENABLED(CONFIG_NET_IPV4) && family == AF_INET) {
292+
} else if (IS_ENABLED(CONFIG_NET_IPV4) && family == AF_INET &&
293+
net_pkt_ll_proto_type(pkt) == NET_ETH_PTYPE_IP) {
292294
/* Drop IPv4 packet if ttl is 0 */
293295
if (NET_IPV4_HDR(pkt)->ttl == 0) {
294296
NET_DBG("DROP: IPv4 ttl");

0 commit comments

Comments
 (0)