net: pkt: Add function to check if packet was reassembled at IP level

Move the existing code verifying that the net_pkt was reassembled at IP
level to a helper function, as it will be needed in other places as
well. Additionally, add packet family check before accessing union
fields.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2023-10-30 13:17:51 +01:00 committed by Fabio Baltieri
parent 2836d0701d
commit 76a256ea57
2 changed files with 15 additions and 2 deletions

View File

@ -836,6 +836,20 @@ static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
}
#endif /* CONFIG_NET_IPV6_FRAGMENT */
static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
{
if ((IS_ENABLED(CONFIG_NET_IPV4_FRAGMENT) &&
net_pkt_family(pkt) == AF_INET &&
net_pkt_ipv4_fragment_more(pkt)) ||
(IS_ENABLED(CONFIG_NET_IPV6_FRAGMENT) &&
net_pkt_family(pkt) == AF_INET6 &&
net_pkt_ipv6_fragment_start(pkt))) {
return true;
}
return false;
}
static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
{
return pkt->priority;

View File

@ -76,8 +76,7 @@ static inline enum net_verdict process_data(struct net_pkt *pkt,
/* If the packet is routed back to us when we have reassembled an IPv4 or IPv6 packet,
* then do not pass it to L2 as the packet does not have link layer headers in it.
*/
if ((IS_ENABLED(CONFIG_NET_IPV4_FRAGMENT) && net_pkt_ipv4_fragment_more(pkt)) ||
(IS_ENABLED(CONFIG_NET_IPV6_FRAGMENT) && net_pkt_ipv6_fragment_start(pkt))) {
if (net_pkt_is_ip_reassembled(pkt)) {
locally_routed = true;
}