Skip to content

Commit 20704bd

Browse files
lxindavem330
authored andcommitted
erspan: build the header with the right proto according to erspan_ver
As said in draft-foschiano-erspan-03#section4: Different frame variants known as "ERSPAN Types" can be distinguished based on the GRE "Protocol Type" field value: Type I and II's value is 0x88BE while Type III's is 0x22EB [ETYPES]. So set it properly in erspan_xmit() according to erspan_ver. While at it, also remove the unused parameter 'proto' in erspan_fb_xmit(). Fixes: 94d7d8f ("ip6_gre: add erspan v2 support") Reported-by: Jianlin Shi <[email protected]> Signed-off-by: Xin Long <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 04a4af3 commit 20704bd

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

net/ipv4/ip_gre.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -569,19 +569,18 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev,
569569
dev->stats.tx_dropped++;
570570
}
571571

572-
static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
573-
__be16 proto)
572+
static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
574573
{
575574
struct ip_tunnel *tunnel = netdev_priv(dev);
576575
struct ip_tunnel_info *tun_info;
577576
const struct ip_tunnel_key *key;
578577
struct erspan_metadata *md;
579578
struct rtable *rt = NULL;
580579
bool truncate = false;
580+
__be16 df, proto;
581581
struct flowi4 fl;
582582
int tunnel_hlen;
583583
int version;
584-
__be16 df;
585584
int nhoff;
586585
int thoff;
587586

@@ -626,18 +625,20 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
626625
if (version == 1) {
627626
erspan_build_header(skb, ntohl(tunnel_id_to_key32(key->tun_id)),
628627
ntohl(md->u.index), truncate, true);
628+
proto = htons(ETH_P_ERSPAN);
629629
} else if (version == 2) {
630630
erspan_build_header_v2(skb,
631631
ntohl(tunnel_id_to_key32(key->tun_id)),
632632
md->u.md2.dir,
633633
get_hwid(&md->u.md2),
634634
truncate, true);
635+
proto = htons(ETH_P_ERSPAN2);
635636
} else {
636637
goto err_free_rt;
637638
}
638639

639640
gre_build_header(skb, 8, TUNNEL_SEQ,
640-
htons(ETH_P_ERSPAN), 0, htonl(tunnel->o_seqno++));
641+
proto, 0, htonl(tunnel->o_seqno++));
641642

642643
df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
643644

@@ -721,12 +722,13 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
721722
{
722723
struct ip_tunnel *tunnel = netdev_priv(dev);
723724
bool truncate = false;
725+
__be16 proto;
724726

725727
if (!pskb_inet_may_pull(skb))
726728
goto free_skb;
727729

728730
if (tunnel->collect_md) {
729-
erspan_fb_xmit(skb, dev, skb->protocol);
731+
erspan_fb_xmit(skb, dev);
730732
return NETDEV_TX_OK;
731733
}
732734

@@ -742,19 +744,22 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
742744
}
743745

744746
/* Push ERSPAN header */
745-
if (tunnel->erspan_ver == 1)
747+
if (tunnel->erspan_ver == 1) {
746748
erspan_build_header(skb, ntohl(tunnel->parms.o_key),
747749
tunnel->index,
748750
truncate, true);
749-
else if (tunnel->erspan_ver == 2)
751+
proto = htons(ETH_P_ERSPAN);
752+
} else if (tunnel->erspan_ver == 2) {
750753
erspan_build_header_v2(skb, ntohl(tunnel->parms.o_key),
751754
tunnel->dir, tunnel->hwid,
752755
truncate, true);
753-
else
756+
proto = htons(ETH_P_ERSPAN2);
757+
} else {
754758
goto free_skb;
759+
}
755760

756761
tunnel->parms.o_flags &= ~TUNNEL_KEY;
757-
__gre_xmit(skb, dev, &tunnel->parms.iph, htons(ETH_P_ERSPAN));
762+
__gre_xmit(skb, dev, &tunnel->parms.iph, proto);
758763
return NETDEV_TX_OK;
759764

760765
free_skb:

net/ipv6/ip6_gre.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
922922
__u8 dsfield = false;
923923
struct flowi6 fl6;
924924
int err = -EINVAL;
925+
__be16 proto;
925926
__u32 mtu;
926927
int nhoff;
927928
int thoff;
@@ -1035,8 +1036,9 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
10351036
}
10361037

10371038
/* Push GRE header. */
1038-
gre_build_header(skb, 8, TUNNEL_SEQ,
1039-
htons(ETH_P_ERSPAN), 0, htonl(t->o_seqno++));
1039+
proto = (t->parms.erspan_ver == 1) ? htons(ETH_P_ERSPAN)
1040+
: htons(ETH_P_ERSPAN2);
1041+
gre_build_header(skb, 8, TUNNEL_SEQ, proto, 0, htonl(t->o_seqno++));
10401042

10411043
/* TooBig packet may have updated dst->dev's mtu */
10421044
if (!t->parms.collect_md && dst && dst_mtu(dst) > dst->dev->mtu)

0 commit comments

Comments
 (0)