Skip to content

Commit b8cb3f4

Browse files
Cyril Strejcgregkh
authored andcommitted
net: multicast: calculate csum of looped-back and forwarded packets
[ Upstream commit 9122a70 ] During a testing of an user-space application which transmits UDP multicast datagrams and utilizes multicast routing to send the UDP datagrams out of defined network interfaces, I've found a multicast router does not fill-in UDP checksum into locally produced, looped-back and forwarded UDP datagrams, if an original output NIC the datagrams are sent to has UDP TX checksum offload enabled. The datagrams are sent malformed out of the NIC the datagrams have been forwarded to. It is because: 1. If TX checksum offload is enabled on the output NIC, UDP checksum is not calculated by kernel and is not filled into skb data. 2. dev_loopback_xmit(), which is called solely by ip_mc_finish_output(), sets skb->ip_summed = CHECKSUM_UNNECESSARY unconditionally. 3. Since 35fc92a ("[NET]: Allow forwarding of ip_summed except CHECKSUM_COMPLETE"), the ip_summed value is preserved during forwarding. 4. If ip_summed != CHECKSUM_PARTIAL, checksum is not calculated during a packet egress. The minimum fix in dev_loopback_xmit(): 1. Preserves skb->ip_summed CHECKSUM_PARTIAL. This is the case when the original output NIC has TX checksum offload enabled. The effects are: a) If the forwarding destination interface supports TX checksum offloading, the NIC driver is responsible to fill-in the checksum. b) If the forwarding destination interface does NOT support TX checksum offloading, checksums are filled-in by kernel before skb is submitted to the NIC driver. c) For local delivery, checksum validation is skipped as in the case of CHECKSUM_UNNECESSARY, thanks to skb_csum_unnecessary(). 2. Translates ip_summed CHECKSUM_NONE to CHECKSUM_UNNECESSARY. It means, for CHECKSUM_NONE, the behavior is unmodified and is there to skip a looped-back packet local delivery checksum validation. Signed-off-by: Cyril Strejc <cyril.strejc@skoda.cz> Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 07f7a18 commit b8cb3f4

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎include/net/udp.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,9 @@ static inline struct sk_buff *udp_rcv_segment(struct sock *sk,
488488
* CHECKSUM_NONE in __udp_gso_segment. UDP GRO indeed builds partial
489489
* packets in udp_gro_complete_segment. As does UDP GSO, verified by
490490
* udp_send_skb. But when those packets are looped in dev_loopback_xmit
491-
* their ip_summed is set to CHECKSUM_UNNECESSARY. Reset in this
492-
* specific case, where PARTIAL is both correct and required.
491+
* their ip_summed CHECKSUM_NONE is changed to CHECKSUM_UNNECESSARY.
492+
* Reset in this specific case, where PARTIAL is both correct and
493+
* required.
493494
*/
494495
if (skb->pkt_type == PACKET_LOOPBACK)
495496
skb->ip_summed = CHECKSUM_PARTIAL;

‎net/core/dev.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3867,7 +3867,8 @@ int dev_loopback_xmit(struct net *net, struct sock *sk, struct sk_buff *skb)
38673867
skb_reset_mac_header(skb);
38683868
__skb_pull(skb, skb_network_offset(skb));
38693869
skb->pkt_type = PACKET_LOOPBACK;
3870-
skb->ip_summed = CHECKSUM_UNNECESSARY;
3870+
if (skb->ip_summed == CHECKSUM_NONE)
3871+
skb->ip_summed = CHECKSUM_UNNECESSARY;
38713872
WARN_ON(!skb_dst(skb));
38723873
skb_dst_force(skb);
38733874
netif_rx_ni(skb);

0 commit comments

Comments
 (0)