Skip to content

Commit 1baf5eb

Browse files
williamtudavem330
authored andcommitted
erspan: auto detect truncated packets.
Currently the truncated bit is set only when the mirrored packet is larger than mtu. For certain cases, the packet might already been truncated before sending to the erspan tunnel. In this case, the patch detect whether the IP header's total length is larger than the actual skb->len. If true, this indicated that the mirrored packet is truncated and set the erspan truncate bit. I tested the patch using bpf_skb_change_tail helper function to shrink the packet size and send to erspan tunnel. Reported-by: Xiaoyan Jin <[email protected]> Signed-off-by: William Tu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 65245d8 commit 1baf5eb

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

net/ipv4/ip_gre.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
578578
int tunnel_hlen;
579579
int version;
580580
__be16 df;
581+
int nhoff;
581582

582583
tun_info = skb_tunnel_info(skb);
583584
if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) ||
@@ -605,6 +606,11 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
605606
truncate = true;
606607
}
607608

609+
nhoff = skb_network_header(skb) - skb_mac_header(skb);
610+
if (skb->protocol == htons(ETH_P_IP) &&
611+
(ntohs(ip_hdr(skb)->tot_len) > skb->len - nhoff))
612+
truncate = true;
613+
608614
if (version == 1) {
609615
erspan_build_header(skb, ntohl(tunnel_id_to_key32(key->tun_id)),
610616
ntohl(md->u.index), truncate, true);

net/ipv6/ip6_gre.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
896896
struct flowi6 fl6;
897897
int err = -EINVAL;
898898
__u32 mtu;
899+
int nhoff;
899900

900901
if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))
901902
goto tx_err;
@@ -908,6 +909,11 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
908909
truncate = true;
909910
}
910911

912+
nhoff = skb_network_header(skb) - skb_mac_header(skb);
913+
if (skb->protocol == htons(ETH_P_IP) &&
914+
(ntohs(ip_hdr(skb)->tot_len) > skb->len - nhoff))
915+
truncate = true;
916+
911917
if (skb_cow_head(skb, dev->needed_headroom))
912918
goto tx_err;
913919

0 commit comments

Comments
 (0)