net: pkt: Add explicit flag to indicate packet is IP reassembled

The current logic to determine whether a packet is IP reassembled is
flawed, as it only worked in certain conditions (which was ok, as the
conditions were satisfied for the current use case, but now it's a
public function). Therefore, add an explicit flag that indicates whether
a packet is IP reassembled or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2023-11-08 10:18:01 +01:00 committed by Fabio Baltieri
parent f505dc528e
commit c724cf99f4
4 changed files with 27 additions and 9 deletions

View file

@ -197,7 +197,9 @@ struct net_pkt {
uint8_t chksum_done : 1; /* Checksum has already been computed for
* the packet.
*/
#if defined(CONFIG_NET_IPV4_FRAGMENT) || defined(CONFIG_NET_IPV6_FRAGMENT)
uint8_t ip_reassembled : 1; /* Packet is a reassembled IP packet. */
#endif
/* bitfield byte alignment boundary */
#if defined(CONFIG_NET_IP)
@ -836,20 +838,33 @@ static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
}
#endif /* CONFIG_NET_IPV6_FRAGMENT */
#if defined(CONFIG_NET_IPV4_FRAGMENT) || defined(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 !!(pkt->ip_reassembled);
}
static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
bool reassembled)
{
pkt->ip_reassembled = reassembled;
}
#else /* CONFIG_NET_IPV4_FRAGMENT || CONFIG_NET_IPV6_FRAGMENT */
static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return false;
}
static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
bool reassembled)
{
ARG_UNUSED(pkt);
ARG_UNUSED(reassembled);
}
#endif /* CONFIG_NET_IPV4_FRAGMENT || CONFIG_NET_IPV6_FRAGMENT */
static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
{
return pkt->priority;

View file

@ -203,6 +203,7 @@ static void reassemble_packet(struct net_ipv4_reassembly *reass)
ipv4_hdr->chksum = net_calc_chksum_ipv4(pkt);
net_pkt_set_data(pkt, &ipv4_access);
net_pkt_set_ip_reassembled(pkt, true);
LOG_DBG("New pkt %p IPv4 len is %d bytes", pkt, net_pkt_get_len(pkt));

View file

@ -338,6 +338,7 @@ static void reassemble_packet(struct net_ipv6_reassembly *reass)
ipv6.hdr->len = htons(len);
net_pkt_set_data(pkt, &ipv6_access);
net_pkt_set_ip_reassembled(pkt, true);
NET_DBG("New pkt %p IPv6 len is %d bytes", pkt,
len + NET_IPV6H_LEN);

View file

@ -1813,6 +1813,7 @@ static void clone_pkt_attributes(struct net_pkt *pkt, struct net_pkt *clone_pkt)
net_pkt_set_ptp(clone_pkt, net_pkt_is_ptp(pkt));
net_pkt_set_forwarding(clone_pkt, net_pkt_forwarding(pkt));
net_pkt_set_chksum_done(clone_pkt, net_pkt_is_chksum_done(pkt));
net_pkt_set_ip_reassembled(pkt, net_pkt_is_ip_reassembled(pkt));
net_pkt_set_l2_bridged(clone_pkt, net_pkt_is_l2_bridged(pkt));
net_pkt_set_l2_processed(clone_pkt, net_pkt_is_l2_processed(pkt));