datapath: Use tun_info only for egress tunnel path.
[cascardo/ovs.git] / datapath / vport-gre.c
index 9bba42a..70fce58 100644 (file)
@@ -26,8 +26,6 @@
 #include <linux/if_tunnel.h>
 #include <linux/if_vlan.h>
 #include <linux/in.h>
-#include <linux/if_vlan.h>
-#include <linux/in.h>
 #include <linux/in_route.h>
 #include <linux/inetdevice.h>
 #include <linux/jhash.h>
 #include <linux/kernel.h>
 #include <linux/workqueue.h>
 #include <linux/rculist.h>
+#include <net/net_namespace.h>
+#include <net/netns/generic.h>
 #include <net/route.h>
 #include <net/xfrm.h>
 
-
 #include <net/icmp.h>
 #include <net/ip.h>
 #include <net/ip_tunnels.h>
@@ -46,7 +45,6 @@
 #include <net/protocol.h>
 
 #include "datapath.h"
-#include "tunnel.h"
 #include "vport.h"
 
 /* Returns the least-significant 32 bits of a __be64. */
@@ -68,9 +66,10 @@ static struct sk_buff *__build_header(struct sk_buff *skb,
                                      int tunnel_hlen,
                                      __be32 seq, __be16 gre64_flag)
 {
-       const struct ovs_key_ipv4_tunnel *tun_key = OVS_CB(skb)->tun_key;
+       const struct ovs_key_ipv4_tunnel *tun_key;
        struct tnl_ptk_info tpi;
 
+       tun_key = &OVS_CB(skb)->egress_tun_info->tunnel;
        skb = gre_handle_offloads(skb, !!(tun_key->tun_flags & TUNNEL_CSUM));
        if (IS_ERR(skb))
                return NULL;
@@ -98,7 +97,7 @@ static __be64 key_to_tunnel_id(__be32 key, __be32 seq)
 static int gre_rcv(struct sk_buff *skb,
                   const struct tnl_ptk_info *tpi)
 {
-       struct ovs_key_ipv4_tunnel tun_key;
+       struct ovs_tunnel_info tun_info;
        struct ovs_net *ovs_net;
        struct vport *vport;
        __be64 key;
@@ -112,33 +111,50 @@ static int gre_rcv(struct sk_buff *skb,
                return PACKET_REJECT;
 
        key = key_to_tunnel_id(tpi->key, tpi->seq);
-       ovs_flow_tun_key_init(&tun_key, ip_hdr(skb), key, filter_tnl_flags(tpi->flags));
+       ovs_flow_tun_info_init(&tun_info, ip_hdr(skb), key,
+                              filter_tnl_flags(tpi->flags), NULL, 0);
 
-       ovs_vport_receive(vport, skb, &tun_key);
+       ovs_vport_receive(vport, skb, &tun_info);
        return PACKET_RCVD;
 }
 
+/* Called with rcu_read_lock and BH disabled. */
+static int gre_err(struct sk_buff *skb, u32 info,
+                  const struct tnl_ptk_info *tpi)
+{
+       struct ovs_net *ovs_net;
+       struct vport *vport;
+
+       ovs_net = net_generic(dev_net(skb->dev), ovs_net_id);
+       if ((tpi->flags & TUNNEL_KEY) && (tpi->flags & TUNNEL_SEQ))
+               vport = rcu_dereference(ovs_net->vport_net.gre64_vport);
+       else
+               vport = rcu_dereference(ovs_net->vport_net.gre_vport);
+
+       if (unlikely(!vport))
+               return PACKET_REJECT;
+       else
+               return PACKET_RCVD;
+}
+
 static int __send(struct vport *vport, struct sk_buff *skb,
                  int tunnel_hlen,
                  __be32 seq, __be16 gre64_flag)
 {
-       struct net *net = ovs_dp_get_net(vport->dp);
+       struct ovs_key_ipv4_tunnel *tun_key;
        struct rtable *rt;
        int min_headroom;
        __be16 df;
        __be32 saddr;
        int err;
 
-       forward_ip_summed(skb, true);
-
        /* Route lookup */
-       saddr = OVS_CB(skb)->tun_key->ipv4_src;
+       tun_key = &OVS_CB(skb)->egress_tun_info->tunnel;
+       saddr = tun_key->ipv4_src;
        rt = find_route(ovs_dp_get_net(vport->dp),
-                       &saddr,
-                       OVS_CB(skb)->tun_key->ipv4_dst,
-                       IPPROTO_GRE,
-                       OVS_CB(skb)->tun_key->ipv4_tos,
-                       skb_get_mark(skb));
+                       &saddr, tun_key->ipv4_dst,
+                       IPPROTO_GRE, tun_key->ipv4_tos,
+                       skb->mark);
        if (IS_ERR(rt)) {
                err = PTR_ERR(rt);
                goto error;
@@ -158,9 +174,14 @@ static int __send(struct vport *vport, struct sk_buff *skb,
                        goto err_free_rt;
        }
 
-       if (unlikely(vlan_deaccel_tag(skb))) {
-               err = -ENOMEM;
-               goto err_free_rt;
+       if (vlan_tx_tag_present(skb)) {
+               if (unlikely(!__vlan_put_tag(skb,
+                                            skb->vlan_proto,
+                                            vlan_tx_tag_get(skb)))) {
+                       err = -ENOMEM;
+                       goto err_free_rt;
+               }
+               vlan_set_tci(skb, 0);
        }
 
        /* Push Tunnel header. */
@@ -170,15 +191,13 @@ static int __send(struct vport *vport, struct sk_buff *skb,
                goto err_free_rt;
        }
 
-       df = OVS_CB(skb)->tun_key->tun_flags & TUNNEL_DONT_FRAGMENT ?
-               htons(IP_DF) : 0;
-
+       df = tun_key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
        skb->local_df = 1;
 
-       return iptunnel_xmit(net, rt, skb, saddr,
-                            OVS_CB(skb)->tun_key->ipv4_dst, IPPROTO_GRE,
-                            OVS_CB(skb)->tun_key->ipv4_tos,
-                            OVS_CB(skb)->tun_key->ipv4_ttl, df);
+       return iptunnel_xmit(rt, skb, saddr,
+                            tun_key->ipv4_dst, IPPROTO_GRE,
+                            tun_key->ipv4_tos,
+                            tun_key->ipv4_ttl, df, false);
 err_free_rt:
        ip_rt_put(rt);
 error:
@@ -187,6 +206,7 @@ error:
 
 static struct gre_cisco_protocol gre_protocol = {
        .handler        = gre_rcv,
+       .err_handler    = gre_err,
        .priority       = 1,
 };
 
@@ -257,7 +277,7 @@ static void gre_tnl_destroy(struct vport *vport)
 
        ovs_net = net_generic(net, ovs_net_id);
 
-       rcu_assign_pointer(ovs_net->vport_net.gre_vport, NULL);
+       RCU_INIT_POINTER(ovs_net->vport_net.gre_vport, NULL);
        ovs_vport_deferred_free(vport);
        gre_exit();
 }
@@ -266,10 +286,10 @@ static int gre_send(struct vport *vport, struct sk_buff *skb)
 {
        int hlen;
 
-       if (unlikely(!OVS_CB(skb)->tun_key))
+       if (unlikely(!OVS_CB(skb)->egress_tun_info))
                return -EINVAL;
 
-       hlen = ip_gre_calc_hlen(OVS_CB(skb)->tun_key->tun_flags);
+       hlen = ip_gre_calc_hlen(OVS_CB(skb)->egress_tun_info->tunnel.tun_flags);
 
        return __send(vport, skb, hlen, 0, 0);
 }
@@ -340,13 +360,13 @@ static int gre64_send(struct vport *vport, struct sk_buff *skb)
                   GRE_HEADER_SECTION;          /* GRE SEQ */
        __be32 seq;
 
-       if (unlikely(!OVS_CB(skb)->tun_key))
+       if (unlikely(!OVS_CB(skb)->egress_tun_info))
                return -EINVAL;
 
-       if (OVS_CB(skb)->tun_key->tun_flags & TUNNEL_CSUM)
+       if (OVS_CB(skb)->egress_tun_info->tunnel.tun_flags & TUNNEL_CSUM)
                hlen += GRE_HEADER_SECTION;
 
-       seq = be64_get_high32(OVS_CB(skb)->tun_key->tun_id);
+       seq = be64_get_high32(OVS_CB(skb)->egress_tun_info->tunnel.tun_id);
        return __send(vport, skb, hlen, seq, (TUNNEL_KEY|TUNNEL_SEQ));
 }