Skip to content

Commit 6870de4

Browse files
tehnerdborkmann
authored andcommitted
bpf: make virtio compatible w/ bpf_xdp_adjust_tail
w/ bpf_xdp_adjust_tail helper xdp's data_end pointer could be changed as well (only "decrease" of pointer's location is going to be supported). changing of this pointer will change packet's size. for virtio driver we need to adjust XDP_PASS handling by recalculating length of the packet if it was passed to the TCP/IP stack Reviewed-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 8fb58f1 commit 6870de4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/net/virtio_net.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ static struct sk_buff *receive_small(struct net_device *dev,
606606
case XDP_PASS:
607607
/* Recalculate length in case bpf program changed it */
608608
delta = orig_data - xdp.data;
609+
len = xdp.data_end - xdp.data;
609610
break;
610611
case XDP_TX:
611612
xdpf = convert_to_xdp_frame(&xdp);
@@ -642,7 +643,7 @@ static struct sk_buff *receive_small(struct net_device *dev,
642643
goto err;
643644
}
644645
skb_reserve(skb, headroom - delta);
645-
skb_put(skb, len + delta);
646+
skb_put(skb, len);
646647
if (!delta) {
647648
buf += header_offset;
648649
memcpy(skb_vnet_hdr(skb), buf, vi->hdr_len);
@@ -757,6 +758,10 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
757758
offset = xdp.data -
758759
page_address(xdp_page) - vi->hdr_len;
759760

761+
/* recalculate len if xdp.data or xdp.data_end were
762+
* adjusted
763+
*/
764+
len = xdp.data_end - xdp.data;
760765
/* We can only create skb based on xdp_page. */
761766
if (unlikely(xdp_page != page)) {
762767
rcu_read_unlock();

0 commit comments

Comments
 (0)