Skip to content

Commit d5db21a

Browse files
williamtudavem330
authored andcommitted
erspan: auto detect truncated ipv6 packets.
Currently the truncated bit is set only when 1) the mirrored packet is larger than mtu and 2) the ipv4 packet tot_len is larger than the actual skb->len. This patch adds another case for detecting whether ipv6 packet is truncated or not, by checking the ipv6 header payload_len and the skb->len. Reported-by: Xiaoyan Jin <[email protected]> Signed-off-by: William Tu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 755bbc1 commit d5db21a

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
@@ -579,6 +579,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
579579
int version;
580580
__be16 df;
581581
int nhoff;
582+
int thoff;
582583

583584
tun_info = skb_tunnel_info(skb);
584585
if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) ||
@@ -611,6 +612,11 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
611612
(ntohs(ip_hdr(skb)->tot_len) > skb->len - nhoff))
612613
truncate = true;
613614

615+
thoff = skb_transport_header(skb) - skb_mac_header(skb);
616+
if (skb->protocol == htons(ETH_P_IPV6) &&
617+
(ntohs(ipv6_hdr(skb)->payload_len) > skb->len - thoff))
618+
truncate = true;
619+
614620
if (version == 1) {
615621
erspan_build_header(skb, ntohl(tunnel_id_to_key32(key->tun_id)),
616622
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
@@ -897,6 +897,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
897897
int err = -EINVAL;
898898
__u32 mtu;
899899
int nhoff;
900+
int thoff;
900901

901902
if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))
902903
goto tx_err;
@@ -914,6 +915,11 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
914915
(ntohs(ip_hdr(skb)->tot_len) > skb->len - nhoff))
915916
truncate = true;
916917

918+
thoff = skb_transport_header(skb) - skb_mac_header(skb);
919+
if (skb->protocol == htons(ETH_P_IPV6) &&
920+
(ntohs(ipv6_hdr(skb)->payload_len) > skb->len - thoff))
921+
truncate = true;
922+
917923
if (skb_cow_head(skb, dev->needed_headroom))
918924
goto tx_err;
919925

0 commit comments

Comments
 (0)