#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/version.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
#include <linux/in.h>
#include <linux/ip.h>
#include <net/icmp.h>
#include <net/ip.h>
+#include <net/route.h>
#include <net/udp.h>
+#include <net/xfrm.h>
#include "datapath.h"
-#include "tunnel.h"
+#include "gso.h"
#include "vport.h"
-
/*
* LISP encapsulation header:
*
#endif
}
+/* Compute source UDP port for outgoing packet.
+ * Currently we use the flow hash.
+ */
+static u16 get_src_port(struct sk_buff *skb)
+{
+ u32 hash = skb_get_rxhash(skb);
+ unsigned int range;
+ int high;
+ int low;
+
+ if (!hash) {
+ struct sw_flow_key *pkt_key = OVS_CB(skb)->pkt_key;
+
+ hash = jhash2((const u32 *)pkt_key,
+ sizeof(*pkt_key) / sizeof(u32), 0);
+ }
+
+ inet_get_local_port_range(&low, &high);
+ range = (high - low) + 1;
+ return (((u64) hash * range) >> 32) + low;
+}
+
static void lisp_build_header(const struct vport *vport,
- struct sk_buff *skb,
- int tunnel_hlen)
+ struct sk_buff *skb)
{
struct lisp_port *lisp_port = lisp_vport(vport);
struct udphdr *udph = udp_hdr(skb);
const struct ovs_key_ipv4_tunnel *tun_key = OVS_CB(skb)->tun_key;
udph->dest = lisp_port->dst_port;
- udph->source = htons(ovs_tnl_get_src_port(skb));
+ udph->source = htons(get_src_port(skb));
udph->check = 0;
udph->len = htons(skb->len - skb_transport_offset(skb));
if (unlikely(!lisp_port))
goto error;
- if (unlikely(!pskb_may_pull(skb, LISP_HLEN)))
+ if (iptunnel_pull_header(skb, LISP_HLEN, 0))
goto error;
lisph = lisp_hdr(skb);
- skb_pull_rcsum(skb, LISP_HLEN);
-
if (lisph->instance_id_present != 1)
key = 0;
else
/* Save outer tunnel values */
iph = ip_hdr(skb);
- tnl_tun_key_init(&tun_key, iph, key, OVS_TNL_F_KEY);
+ ovs_flow_tun_key_init(&tun_key, iph, key, TUNNEL_KEY);
/* Drop non-IP inner packets */
inner_iph = (struct iphdr *)(lisph + 1);
default:
goto error;
}
+ skb->protocol = protocol;
/* Add Ethernet header */
ethh = (struct ethhdr *)skb_push(skb, ETH_HLEN);
ethh->h_source[0] = 0x02;
ethh->h_proto = protocol;
- ovs_tnl_rcv(vport_from_priv(lisp_port), skb, &tun_key);
+ ovs_skb_postpush_rcsum(skb, skb->data, ETH_HLEN);
+
+ ovs_vport_receive(vport_from_priv(lisp_port), skb, &tun_key);
goto out;
error:
return ERR_PTR(err);
}
-static int lisp_tnl_send(struct vport *vport, struct sk_buff *skb)
+static void lisp_fix_segment(struct sk_buff *skb)
+{
+ struct udphdr *udph = udp_hdr(skb);
+
+ udph->len = htons(skb->len - skb_transport_offset(skb));
+}
+
+static void handle_offloads(struct sk_buff *skb)
+{
+ if (skb_is_gso(skb))
+ OVS_GSO_CB(skb)->fix_segment = lisp_fix_segment;
+ else if (skb->ip_summed != CHECKSUM_PARTIAL)
+ skb->ip_summed = CHECKSUM_NONE;
+}
+
+static int lisp_send(struct vport *vport, struct sk_buff *skb)
{
- int tnl_len;
int network_offset = skb_network_offset(skb);
+ struct rtable *rt;
+ int min_headroom;
+ __be32 saddr;
+ __be16 df;
+ int sent_len;
+ int err;
if (unlikely(!OVS_CB(skb)->tun_key))
return -EINVAL;
- /* We only encapsulate IPv4 and IPv6 packets */
- switch (skb->protocol) {
- case htons(ETH_P_IP):
- case htons(ETH_P_IPV6):
- /* Pop off "inner" Ethernet header */
- skb_pull(skb, network_offset);
- tnl_len = ovs_tnl_send(vport, skb, IPPROTO_UDP,
- LISP_HLEN, lisp_build_header);
- return tnl_len > 0 ? tnl_len + network_offset : tnl_len;
- default:
+ if (skb->protocol != htons(ETH_P_IP) &&
+ skb->protocol != htons(ETH_P_IPV6)) {
kfree_skb(skb);
return 0;
}
+
+ /* Route lookup */
+ saddr = OVS_CB(skb)->tun_key->ipv4_src;
+ rt = find_route(ovs_dp_get_net(vport->dp),
+ &saddr,
+ OVS_CB(skb)->tun_key->ipv4_dst,
+ IPPROTO_UDP,
+ OVS_CB(skb)->tun_key->ipv4_tos,
+ skb->mark);
+ if (IS_ERR(rt)) {
+ err = PTR_ERR(rt);
+ goto error;
+ }
+
+ min_headroom = LL_RESERVED_SPACE(rt_dst(rt).dev) + rt_dst(rt).header_len
+ + sizeof(struct iphdr) + LISP_HLEN;
+
+ if (skb_headroom(skb) < min_headroom || skb_header_cloned(skb)) {
+ int head_delta = SKB_DATA_ALIGN(min_headroom -
+ skb_headroom(skb) +
+ 16);
+
+ err = pskb_expand_head(skb, max_t(int, head_delta, 0),
+ 0, GFP_ATOMIC);
+ if (unlikely(err))
+ goto err_free_rt;
+ }
+
+ /* Reset l2 headers. */
+ skb_pull(skb, network_offset);
+ skb_reset_mac_header(skb);
+ vlan_set_tci(skb, 0);
+
+ skb_reset_inner_headers(skb);
+
+ __skb_push(skb, LISP_HLEN);
+ skb_reset_transport_header(skb);
+
+ lisp_build_header(vport, skb);
+
+ /* Offloading */
+ handle_offloads(skb);
+ skb->local_df = 1;
+
+ df = OVS_CB(skb)->tun_key->tun_flags &
+ TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
+ sent_len = iptunnel_xmit(rt, skb,
+ saddr, OVS_CB(skb)->tun_key->ipv4_dst,
+ IPPROTO_UDP, OVS_CB(skb)->tun_key->ipv4_tos,
+ OVS_CB(skb)->tun_key->ipv4_ttl, df);
+
+ return sent_len > 0 ? sent_len + network_offset : sent_len;
+
+err_free_rt:
+ ip_rt_put(rt);
+error:
+ return err;
}
static const char *lisp_get_name(const struct vport *vport)
.destroy = lisp_tnl_destroy,
.get_name = lisp_get_name,
.get_options = lisp_get_options,
- .send = lisp_tnl_send,
+ .send = lisp_send,
};
-#else
-#warning LISP tunneling will not be available on kernels before 2.6.26
-#endif /* Linux kernel < 2.6.26 */