gro: fix packet type comparisons
PATCH 1/1 gro: fix packet type comparisons
Identifying packet types requires masking with the mask, not the value, before comparing to the value.
--- lib/gro/rte_gro.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
lib/gro/rte_gro.c +9 -12
@@ -35,26 +35,23 @@ static gro_tbl_pkt_count_fn tbl_pkt_count_fn[RTE_GRO_TYPE_MAX_NUM] = { NULL};#define IS_IPV4_TCP_PKT (ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ - ((ptype & RTE_PTYPE_L4_TCP) == RTE_PTYPE_L4_TCP) && \ - ((ptype & RTE_PTYPE_L4_FRAG) != RTE_PTYPE_L4_FRAG) && \ + ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP) && \ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0))/* GRO with extension headers is not supported */ #define IS_IPV6_TCP_PKT (ptype) (RTE_ETH_IS_IPV6_HDR(ptype) && \ - ((ptype & RTE_PTYPE_L4_TCP) == RTE_PTYPE_L4_TCP) && \ - ((ptype & RTE_PTYPE_L4_FRAG) != RTE_PTYPE_L4_FRAG) && \ + ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP) && \ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0))#define IS_IPV4_UDP_PKT (ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ - ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \ + ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP) && \ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0))#define IS_IPV4_VXLAN_TCP4_PKT (ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ - ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \ - ((ptype & RTE_PTYPE_L4_FRAG) != RTE_PTYPE_L4_FRAG) && \ - ((ptype & RTE_PTYPE_TUNNEL_VXLAN) == \ + ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP) && \ + ((ptype & RTE_PTYPE_TUNNEL_MASK) == \ RTE_PTYPE_TUNNEL_VXLAN) && \ - ((ptype & RTE_PTYPE_INNER_L4_TCP) == \ + ((ptype & RTE_PTYPE_INNER_L4_MASK) == \ RTE_PTYPE_INNER_L4_TCP) && \ (((ptype & RTE_PTYPE_INNER_L3_MASK) == \ RTE_PTYPE_INNER_L3_IPV4) || \
@@ -64,10 +61,10 @@ static gro_tbl_pkt_count_fn tbl_pkt_count_fn[RTE_GRO_TYPE_MAX_NUM] = { RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN)))#define IS_IPV4_VXLAN_UDP4_PKT (ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ - ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \ - ((ptype & RTE_PTYPE_TUNNEL_VXLAN) == \ + ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP) && \ + ((ptype & RTE_PTYPE_TUNNEL_MASK) == \ RTE_PTYPE_TUNNEL_VXLAN) && \ - ((ptype & RTE_PTYPE_INNER_L4_UDP) == \ + ((ptype & RTE_PTYPE_INNER_L4_MASK) == \ RTE_PTYPE_INNER_L4_UDP) && \ (((ptype & RTE_PTYPE_INNER_L3_MASK) == \ RTE_PTYPE_INNER_L3_IPV4) || \
Signature · 1 line
2.43.0
17/10/2026 19:02, Morten Brørup:
Quoted 2 lines
Identifying packet types requires masking with the mask, not the value, before comparing to the value.
[...]
Quoted 4 lines
#define
IS_IPV4_UDP_PKT(ptype)(RTE_ETH_IS_IPV4_HDR(ptype)&& \lib/gro/rte_gro.c +1
-1- ((ptype &RTE_PTYPE_L4_UDP ) ==RTE_PTYPE_L4_UDP ) && \ + ((ptype &RTE_PTYPE_L4_MASK ) ==RTE_PTYPE_L4_UDP ) && \ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0))
[...]
lib/gro/rte_gro.c static gro_tbl_pkt_count_fn tbl_pkt_count_fn[RTE_GRO_TYPE_MAX_NUM] = { · line 68
Quoted 9 lines
#define
IS_IPV4_VXLAN_UDP4_PKT(ptype)(RTE_ETH_IS_IPV4_HDR(ptype)&& \lib/gro/rte_gro.c +3
-3- ((ptype &RTE_PTYPE_L4_UDP ) ==RTE_PTYPE_L4_UDP ) && \ - ((ptype &RTE_PTYPE_TUNNEL_VXLAN ) == \ + ((ptype &RTE_PTYPE_L4_MASK ) ==RTE_PTYPE_L4_UDP ) && \ + ((ptype &RTE_PTYPE_TUNNEL_MASK ) == \RTE_PTYPE_TUNNEL_VXLAN ) && \ - ((ptype &RTE_PTYPE_INNER_L4_UDP ) == \ + ((ptype &RTE_PTYPE_INNER_L4_MASK ) == \ RTE_PTYPE_INNER_L4_UDP) && \
My AI is not happy:
"
The UDP checks introduce a regression.gro_udp4_reassemble() only processes IPv4 fragments, but the new comparison:
(ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP
rejects packets marked RTE_PTYPE_L4_FRAG.
The previous check accepted them because RTE_PTYPE_L4_FRAG is 0x300 and RTE_PTYPE_L4_UDP is 0x200.
The same applies to IS_IPV4_VXLAN_UDP4_PKT():
requiring an exact match against RTE_PTYPE_INNER_L4_UDP excludes inner fragments, which are precisely what gro_vxlan_udp4_reassemble() processes.
Could you preserve fragment handling in both UDP checks and add regression tests? "
Quoted 15 lines
From: Thomas Monjalon [mailto:[email protected]]
Sent: Monday, 2 November 2026 12.2717/10/2026 19:02, Morten Brørup:
Quoted 1 line
Identifying packet types requires masking with the mask, not the
value,
Quoted 1 line
before comparing to the value.
[...]
Quoted 4 lines
#define
IS_IPV4_UDP_PKT(ptype)(RTE_ETH_IS_IPV4_HDR(ptype)&& \lib/gro/rte_gro.c +1
-1- ((ptype &RTE_PTYPE_L4_UDP ) ==RTE_PTYPE_L4_UDP ) && \ + ((ptype &RTE_PTYPE_L4_MASK ) ==RTE_PTYPE_L4_UDP ) && \ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0))[...]
Quoted 1 line
#define
IS_IPV4_VXLAN_UDP4_PKT(ptype)(RTE_ETH_IS_IPV4_HDR(ptype)&&\
Quoted 14 lines
lib/gro/rte_gro.c static gro_tbl_pkt_count_fn tbl_pkt_count_fn[RTE_GRO_TYPE_MAX_NUM] = { · line 68
Quoted 8 lines
lib/gro/rte_gro.c +3
-3- ((ptype &RTE_PTYPE_L4_UDP ) ==RTE_PTYPE_L4_UDP ) && \ - ((ptype &RTE_PTYPE_TUNNEL_VXLAN ) == \ + ((ptype &RTE_PTYPE_L4_MASK ) ==RTE_PTYPE_L4_UDP ) && \ + ((ptype &RTE_PTYPE_TUNNEL_MASK ) == \RTE_PTYPE_TUNNEL_VXLAN ) && \ - ((ptype &RTE_PTYPE_INNER_L4_UDP ) == \ + ((ptype &RTE_PTYPE_INNER_L4_MASK ) == \ RTE_PTYPE_INNER_L4_UDP) && \My AI is not happy:
"
The UDP checks introduce a regression.gro_udp4_reassemble()only processes IPv4 fragments,
Great review feedback!
I'm not using GRO, so I didn't know the expected behavior.
I spotted this by random luck, and it looked completely wrong, so I sent a quick patch.
Quoted 8 lines
but the new comparison:
(ptype &
RTE_PTYPE_L4_MASK) ==RTE_PTYPE_L4_UDPrejects packets marked
RTE_PTYPE_L4_FRAG.The previous check accepted them because
RTE_PTYPE_L4_FRAGis0x300andRTE_PTYPE_L4_UDPis0x200.
Now that I have learned that gro_udp4_reassemble() doesn't want UDP packets, it wants fragments, then the correct comparison is:
#define IS_IPV4_UDP_PKT(ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \
- ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \
+ ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_FRAG) && \
(RTE_ETH_IS_TUNNEL_PKT(ptype) == 0))
But then the macro name seems misleading.
Renaming it to IS_IPV4_FRAG_PKT() might be confusing when used in the code below, so adding a comment to the macro definition is probably better.
Under all circumstances, the formula "((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP)" is wrong:
It not only matches UDP packets (0x200) and IP fragments (0x300), it matches anything with the 0x200 bit set, including RTE_PTYPE_L4_NONFRAG (0x600) and RTE_PTYPE_L4_IGMP (0x700).
Quoted 9 lines
The same applies to
IS_IPV4_VXLAN_UDP4_PKT():
requiring an exact match againstRTE_PTYPE_INNER_L4_UDPexcludes inner fragments,
which are precisely whatgro_vxlan_udp4_reassemble()processes.Could you preserve fragment handling in both UDP checks and add regression tests?
"
I will look into it later, when I have time for it. Marking the patch Changes Requested for now.
Anyone feel free to take over and fix it.
PATCH v2 1/1 gro: fix packet type comparisons
In reply to Morten BrørupIdentifying packet types requires masking with the mask, not the value, before comparing to the value.
The faulty macros were corrected.
Furthermore, GRO for UDP ingests IP fragments, not UDP packets, so compare to IP fragments instead of UDP packets.
The same applies to GRO for inner UDP in VXLAN packets; compare to to inner IP fragments instead of inner UDP packets.
This was not obvious looking at the macros, so they were renamed to reflect what they match, and comments were added to mention what they are used for.
Note:
This bug has not been caught earlier, probably because the faulty formula "((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP)" matched IP fragments by pure luck:RTE_PTYPE_L4_UDP has the value 0x200, andRTE_PTYPE_L4_FRAG has the value 0x300, so the faulty formula evaluates as "((0x300 & 0x200) == 0x200)", which is true.
It also - incorrectly - matched other packet types with the 0x200 bit set, e.g. RTE_PTYPE_L4_IGMP (value 0x700), which it shouldn't match.
---
v2:
* Rebased.
* Updated patch description with many more details.
* UDP offload wants IP fragments, not UDP packets. (Thomas' AI)
* Inner UDP offload of VXLAN wants inner IP fragments, not inner UDP packets. (Thomas' AI)
* Renamed the macros regarding GRO for UDP and VXLAN inner UDP, and added comments to these.
--- lib/gro/rte_gro.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-)
lib/gro/rte_gro.c +18 -19
@@ -35,26 +35,24 @@ static gro_tbl_pkt_count_fn tbl_pkt_count_fn[RTE_GRO_TYPE_MAX_NUM] = { NULL};#define IS_IPV4_TCP_PKT (ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ - ((ptype & RTE_PTYPE_L4_TCP) == RTE_PTYPE_L4_TCP) && \ - ((ptype & RTE_PTYPE_L4_FRAG) != RTE_PTYPE_L4_FRAG) && \ + ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP) && \ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0))/* GRO with extension headers is not supported */ #define IS_IPV6_TCP_PKT (ptype) (RTE_ETH_IS_IPV6_HDR(ptype) && \ - ((ptype & RTE_PTYPE_L4_TCP) == RTE_PTYPE_L4_TCP) && \ - ((ptype & RTE_PTYPE_L4_FRAG) != RTE_PTYPE_L4_FRAG) && \ + ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP) && \ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0)) -#define IS_IPV4_UDP_PKT (ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ - ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \ +/* GRO for UDP ingests IP fragments */ +#define IS_IPV4_FRAG_PKT (ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ + ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_FRAG) && \ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0))#define IS_IPV4_VXLAN_TCP4_PKT (ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ - ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \ - ((ptype & RTE_PTYPE_L4_FRAG) != RTE_PTYPE_L4_FRAG) && \ - ((ptype & RTE_PTYPE_TUNNEL_VXLAN) == \ + ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP) && \ + ((ptype & RTE_PTYPE_TUNNEL_MASK) == \ RTE_PTYPE_TUNNEL_VXLAN) && \ - ((ptype & RTE_PTYPE_INNER_L4_TCP) == \ + ((ptype & RTE_PTYPE_INNER_L4_MASK) == \ RTE_PTYPE_INNER_L4_TCP) && \ (((ptype & RTE_PTYPE_INNER_L3_MASK) == \ RTE_PTYPE_INNER_L3_IPV4) || \
@@ -63,12 +61,13 @@ static gro_tbl_pkt_count_fn tbl_pkt_count_fn[RTE_GRO_TYPE_MAX_NUM] = { ((ptype & RTE_PTYPE_INNER_L3_MASK) == \ RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN))) -#define IS_IPV4_VXLAN_UDP4_PKT (ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ - ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \ - ((ptype & RTE_PTYPE_TUNNEL_VXLAN) == \ +/* GRO for inner UDP of VXLAN ingests inner IP fragments */ +#define IS_IPV4_VXLAN_FRAG4_PKT (ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ + ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP) && \ + ((ptype & RTE_PTYPE_TUNNEL_MASK) == \ RTE_PTYPE_TUNNEL_VXLAN) && \ - ((ptype & RTE_PTYPE_INNER_L4_UDP) == \ - RTE_PTYPE_INNER_L4_UDP) && \ + ((ptype & RTE_PTYPE_INNER_L4_MASK) == \ + RTE_PTYPE_INNER_L4_FRAG) && \ (((ptype & RTE_PTYPE_INNER_L3_MASK) == \ RTE_PTYPE_INNER_L3_IPV4) || \ ((ptype & RTE_PTYPE_INNER_L3_MASK) == \
@@ -279,7 +278,7 @@ rte_gro_reassemble_burst(struct rte_mbuf **pkts, nb_after_gro--; else if (ret < 0) pkts[unprocess_num++] = pkts[i]; - }else if (IS_IPV4_VXLAN_UDP4_PKT (pkts[i]->packet_type) && + }else if (IS_IPV4_VXLAN_FRAG4_PKT (pkts[i]->packet_type) && do_vxlan_udp_gro) { ret =gro_vxlan_udp4_reassemble (pkts[i], &vxlan_udp_tbl,0 );
@@ -296,7 +295,7 @@ rte_gro_reassemble_burst(struct rte_mbuf **pkts, nb_after_gro--; else if (ret < 0) pkts[unprocess_num++] = pkts[i]; - }else if (IS_IPV4_UDP_PKT (pkts[i]->packet_type) && + }else if (IS_IPV4_FRAG_PKT (pkts[i]->packet_type) && do_udp4_gro) { ret =gro_udp4_reassemble (pkts[i], &udp_tbl,0 );if (ret >0 )
@@ -394,7 +393,7 @@ rte_gro_reassemble(struct rte_mbuf **pkts,if (gro_vxlan_tcp4_reassemble (pkts[i], vxlan_tcp_tbl, current_time) <0 ) pkts[unprocess_num++] = pkts[i]; - }else if (IS_IPV4_VXLAN_UDP4_PKT (pkts[i]->packet_type) && + }else if (IS_IPV4_VXLAN_FRAG4_PKT (pkts[i]->packet_type) && do_vxlan_udp_gro) {if (gro_vxlan_udp4_reassemble (pkts[i], vxlan_udp_tbl, current_time) <0 )
@@ -404,7 +403,7 @@ rte_gro_reassemble(struct rte_mbuf **pkts,if (gro_tcp4_reassemble (pkts[i], tcp_tbl, current_time) <0 ) pkts[unprocess_num++] = pkts[i]; - }else if (IS_IPV4_UDP_PKT (pkts[i]->packet_type) && + }else if (IS_IPV4_FRAG_PKT (pkts[i]->packet_type) && do_udp4_gro) {if (gro_udp4_reassemble (pkts[i], udp_tbl, current_time) <0 )
Signature · 1 line
2.43.0
Hi Morten,
We hit the same issue while fuzzing lib/gro: with both RTE_GRO_IPV4_VXLAN_TCP_IPV4 and RTE_GRO_IPV4_VXLAN_UDP_IPV4 enabled, fragments of inner UDP in VXLAN match IS_IPV4_VXLAN_TCP4_PKT() (RTE_PTYPE_INNER_L4_FRAG includes the RTE_PTYPE_INNER_L4_TCP bit), are rejected by gro_vxlan_tcp4_reassemble(), and never reach the VXLAN UDP path, so they are not merged.
With two fragments of one inner UDP datagram, packet_type taken from rte_net_get_ptype(), rte_gro_reassemble_burst() returns:
- without the patch: 2 with both VXLAN types, 1 with VXLAN UDP only;
- with the patch: 1 in both cases.
Tested on 25.11.2 with a standalone program and our fuzzing corpus for gro/gso, no regressions.
Thomas Monjalon
Applied09/11/2026 12:26, Andrey Mokrushin:
Quoted 14 lines
Hi Morten,
We hit the same issue while fuzzing lib/gro: with both
RTE_GRO_IPV4_VXLAN_TCP_IPV4andRTE_GRO_IPV4_VXLAN_UDP_IPV4enabled, fragments of inner UDP in VXLAN matchIS_IPV4_VXLAN_TCP4_PKT()(RTE_PTYPE_INNER_L4_FRAGincludes theRTE_PTYPE_INNER_L4_TCPbit), are rejected bygro_vxlan_tcp4_reassemble(), and never reach the VXLAN UDP path, so they are not merged.With two fragments of one inner UDP datagram,
packet_typetaken fromrte_net_get_ptype(),rte_gro_reassemble_burst()returns:
- without the patch: 2 with both VXLAN types, 1 with VXLAN UDP only;
- with the patch: 1 in both cases.
Quoted 4 lines
Tested on 25.11.2 with a standalone program and our fuzzing corpus for gro/gso, no regressions.
Tested-by Andrey Mokrushin <[email protected]>
Applied, thanks.