/* BPF_FUNC_skb_set_tunnel_key flags. */
 #define BPF_F_ZERO_CSUM_TX             (1ULL << 1)
 #define BPF_F_DONT_FRAGMENT            (1ULL << 2)
+#define BPF_F_SEQ_NUMBER               (1ULL << 3)
 
 /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
  * BPF_FUNC_perf_event_read_value flags.
 
        struct ip_tunnel_info *info;
 
        if (unlikely(flags & ~(BPF_F_TUNINFO_IPV6 | BPF_F_ZERO_CSUM_TX |
-                              BPF_F_DONT_FRAGMENT)))
+                              BPF_F_DONT_FRAGMENT | BPF_F_SEQ_NUMBER)))
                return -EINVAL;
        if (unlikely(size != sizeof(struct bpf_tunnel_key))) {
                switch (size) {
                info->key.tun_flags |= TUNNEL_DONT_FRAGMENT;
        if (flags & BPF_F_ZERO_CSUM_TX)
                info->key.tun_flags &= ~TUNNEL_CSUM;
+       if (flags & BPF_F_SEQ_NUMBER)
+               info->key.tun_flags |= TUNNEL_SEQ;
 
        info->key.tun_id = cpu_to_be64(from->tunnel_id);
        info->key.tos = from->tunnel_tos;
 
 static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev,
                        __be16 proto)
 {
+       struct ip_tunnel *tunnel = netdev_priv(dev);
        struct ip_tunnel_info *tun_info;
        const struct ip_tunnel_key *key;
        struct rtable *rt = NULL;
        if (gre_handle_offloads(skb, !!(tun_info->key.tun_flags & TUNNEL_CSUM)))
                goto err_free_rt;
 
-       flags = tun_info->key.tun_flags & (TUNNEL_CSUM | TUNNEL_KEY);
+       flags = tun_info->key.tun_flags &
+               (TUNNEL_CSUM | TUNNEL_KEY | TUNNEL_SEQ);
        gre_build_header(skb, tunnel_hlen, flags, proto,
-                        tunnel_id_to_key32(tun_info->key.tun_id), 0);
+                        tunnel_id_to_key32(tun_info->key.tun_id),
+                        (flags | TUNNEL_SEQ) ? htonl(tunnel->o_seqno++) : 0);
 
        df = key->tun_flags & TUNNEL_DONT_FRAGMENT ?  htons(IP_DF) : 0;
 
 
        else
                fl6->daddr = tunnel->parms.raddr;
 
-       if (tunnel->parms.o_flags & TUNNEL_SEQ)
-               tunnel->o_seqno++;
-
        /* Push GRE header. */
        protocol = (dev->type == ARPHRD_ETHER) ? htons(ETH_P_TEB) : proto;
 
                fl6->flowi6_uid = sock_net_uid(dev_net(dev), NULL);
 
                dsfield = key->tos;
-               flags = key->tun_flags & (TUNNEL_CSUM | TUNNEL_KEY);
+               flags = key->tun_flags &
+                       (TUNNEL_CSUM | TUNNEL_KEY | TUNNEL_SEQ);
                tunnel->tun_hlen = gre_calc_hlen(flags);
 
                gre_build_header(skb, tunnel->tun_hlen,
                                 flags, protocol,
-                                tunnel_id_to_key32(tun_info->key.tun_id), 0);
+                                tunnel_id_to_key32(tun_info->key.tun_id),
+                                (flags | TUNNEL_SEQ) ? htonl(tunnel->o_seqno++)
+                                                     : 0);
 
        } else {
+               if (tunnel->parms.o_flags & TUNNEL_SEQ)
+                       tunnel->o_seqno++;
+
                gre_build_header(skb, tunnel->tun_hlen, tunnel->parms.o_flags,
                                 protocol, tunnel->parms.o_key,
                                 htonl(tunnel->o_seqno));