]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - net/openvswitch/vport-vxlan.c
Merge tag 'for-linus-20141215' of git://git.infradead.org/linux-mtd
[karo-tx-linux.git] / net / openvswitch / vport-vxlan.c
index d8b7e247bebff5c5f4c3b83345ca5e4f492be60b..38f95a52241bd53af8de06b76079e403de8413cf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Nicira, Inc.
+ * Copyright (c) 2014 Nicira, Inc.
  * Copyright (c) 2013 Cisco Systems, Inc.
  *
  * This program is free software; you can redistribute it and/or
@@ -24,6 +24,7 @@
 #include <linux/net.h>
 #include <linux/rculist.h>
 #include <linux/udp.h>
+#include <linux/module.h>
 
 #include <net/icmp.h>
 #include <net/ip.h>
@@ -50,6 +51,8 @@ struct vxlan_port {
        char name[IFNAMSIZ];
 };
 
+static struct vport_ops ovs_vxlan_vport_ops;
+
 static inline struct vxlan_port *vxlan_vport(const struct vport *vport)
 {
        return vport_priv(vport);
@@ -58,7 +61,7 @@ static inline struct vxlan_port *vxlan_vport(const struct vport *vport)
 /* Called with rcu_read_lock and BH disabled. */
 static void vxlan_rcv(struct vxlan_sock *vs, struct sk_buff *skb, __be32 vx_vni)
 {
-       struct ovs_key_ipv4_tunnel tun_key;
+       struct ovs_tunnel_info tun_info;
        struct vport *vport = vs->data;
        struct iphdr *iph;
        __be64 key;
@@ -66,9 +69,11 @@ static void vxlan_rcv(struct vxlan_sock *vs, struct sk_buff *skb, __be32 vx_vni)
        /* Save outer tunnel values */
        iph = ip_hdr(skb);
        key = cpu_to_be64(ntohl(vx_vni) >> 8);
-       ovs_flow_tun_key_init(&tun_key, iph, key, TUNNEL_KEY);
+       ovs_flow_tun_info_init(&tun_info, iph,
+                              udp_hdr(skb)->source, udp_hdr(skb)->dest,
+                              key, TUNNEL_KEY, NULL, 0);
 
-       ovs_vport_receive(vport, skb, &tun_key);
+       ovs_vport_receive(vport, skb, &tun_info);
 }
 
 static int vxlan_get_options(const struct vport *vport, struct sk_buff *skb)
@@ -140,22 +145,24 @@ static int vxlan_tnl_send(struct vport *vport, struct sk_buff *skb)
        struct net *net = ovs_dp_get_net(vport->dp);
        struct vxlan_port *vxlan_port = vxlan_vport(vport);
        __be16 dst_port = inet_sk(vxlan_port->vs->sock->sk)->inet_sport;
+       struct ovs_key_ipv4_tunnel *tun_key;
        struct rtable *rt;
        struct flowi4 fl;
        __be16 src_port;
        __be16 df;
        int err;
 
-       if (unlikely(!OVS_CB(skb)->tun_key)) {
+       if (unlikely(!OVS_CB(skb)->egress_tun_info)) {
                err = -EINVAL;
                goto error;
        }
 
+       tun_key = &OVS_CB(skb)->egress_tun_info->tunnel;
        /* Route lookup */
        memset(&fl, 0, sizeof(fl));
-       fl.daddr = OVS_CB(skb)->tun_key->ipv4_dst;
-       fl.saddr = OVS_CB(skb)->tun_key->ipv4_src;
-       fl.flowi4_tos = RT_TOS(OVS_CB(skb)->tun_key->ipv4_tos);
+       fl.daddr = tun_key->ipv4_dst;
+       fl.saddr = tun_key->ipv4_src;
+       fl.flowi4_tos = RT_TOS(tun_key->ipv4_tos);
        fl.flowi4_mark = skb->mark;
        fl.flowi4_proto = IPPROTO_UDP;
 
@@ -165,7 +172,7 @@ static int vxlan_tnl_send(struct vport *vport, struct sk_buff *skb)
                goto error;
        }
 
-       df = OVS_CB(skb)->tun_key->tun_flags & TUNNEL_DONT_FRAGMENT ?
+       df = tun_key->tun_flags & TUNNEL_DONT_FRAGMENT ?
                htons(IP_DF) : 0;
 
        skb->ignore_df = 1;
@@ -173,11 +180,10 @@ static int vxlan_tnl_send(struct vport *vport, struct sk_buff *skb)
        src_port = udp_flow_src_port(net, skb, 0, 0, true);
 
        err = vxlan_xmit_skb(vxlan_port->vs, rt, skb,
-                            fl.saddr, OVS_CB(skb)->tun_key->ipv4_dst,
-                            OVS_CB(skb)->tun_key->ipv4_tos,
-                            OVS_CB(skb)->tun_key->ipv4_ttl, df,
+                            fl.saddr, tun_key->ipv4_dst,
+                            tun_key->ipv4_tos, tun_key->ipv4_ttl, df,
                             src_port, dst_port,
-                            htonl(be64_to_cpu(OVS_CB(skb)->tun_key->tun_id) << 8),
+                            htonl(be64_to_cpu(tun_key->tun_id) << 8),
                             false);
        if (err < 0)
                ip_rt_put(rt);
@@ -185,17 +191,55 @@ error:
        return err;
 }
 
+static int vxlan_get_egress_tun_info(struct vport *vport, struct sk_buff *skb,
+                                    struct ovs_tunnel_info *egress_tun_info)
+{
+       struct net *net = ovs_dp_get_net(vport->dp);
+       struct vxlan_port *vxlan_port = vxlan_vport(vport);
+       __be16 dst_port = inet_sk(vxlan_port->vs->sock->sk)->inet_sport;
+       __be16 src_port;
+       int port_min;
+       int port_max;
+
+       inet_get_local_port_range(net, &port_min, &port_max);
+       src_port = udp_flow_src_port(net, skb, 0, 0, true);
+
+       return ovs_tunnel_get_egress_info(egress_tun_info, net,
+                                         OVS_CB(skb)->egress_tun_info,
+                                         IPPROTO_UDP, skb->mark,
+                                         src_port, dst_port);
+}
+
 static const char *vxlan_get_name(const struct vport *vport)
 {
        struct vxlan_port *vxlan_port = vxlan_vport(vport);
        return vxlan_port->name;
 }
 
-const struct vport_ops ovs_vxlan_vport_ops = {
+static struct vport_ops ovs_vxlan_vport_ops = {
        .type           = OVS_VPORT_TYPE_VXLAN,
        .create         = vxlan_tnl_create,
        .destroy        = vxlan_tnl_destroy,
        .get_name       = vxlan_get_name,
        .get_options    = vxlan_get_options,
        .send           = vxlan_tnl_send,
+       .get_egress_tun_info    = vxlan_get_egress_tun_info,
+       .owner          = THIS_MODULE,
 };
+
+static int __init ovs_vxlan_tnl_init(void)
+{
+       return ovs_vport_ops_register(&ovs_vxlan_vport_ops);
+}
+
+static void __exit ovs_vxlan_tnl_exit(void)
+{
+       ovs_vport_ops_unregister(&ovs_vxlan_vport_ops);
+}
+
+module_init(ovs_vxlan_tnl_init);
+module_exit(ovs_vxlan_tnl_exit);
+
+MODULE_DESCRIPTION("OVS: VXLAN switching port");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("vport-type-4");