2 * Copyright (c) 2007-2013 Nicira, Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 #include <linux/version.h>
20 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,12,0)
22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/in_route.h>
26 #include <linux/inetdevice.h>
27 #include <linux/jhash.h>
28 #include <linux/list.h>
29 #include <linux/kernel.h>
30 #include <linux/version.h>
31 #include <linux/workqueue.h>
32 #include <linux/rculist.h>
33 #include <net/ip_tunnels.h>
34 #include <net/route.h>
40 int iptunnel_xmit(struct rtable *rt,
42 __be32 src, __be32 dst, __u8 proto,
43 __u8 tos, __u8 ttl, __be16 df, bool xnet)
45 int pkt_len = skb->len;
53 skb_dst_set(skb, &rt_dst(rt));
55 /* Do not clear ovs_skb_cb. It will be done in gso code. */
56 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
59 /* Push down and install the IP header. */
60 __skb_push(skb, sizeof(struct iphdr));
61 skb_reset_network_header(skb);
66 iph->ihl = sizeof(struct iphdr) >> 2;
68 iph->protocol = proto;
73 __ip_select_ident(iph, &rt_dst(rt), (skb_shinfo(skb)->gso_segs ?: 1) - 1);
75 err = ip_local_out(skb);
76 if (unlikely(net_xmit_eval(err)))
81 int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto)
83 if (unlikely(!pskb_may_pull(skb, hdr_len)))
86 skb_pull_rcsum(skb, hdr_len);
88 if (inner_proto == htons(ETH_P_TEB)) {
91 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
94 eh = (struct ethhdr *)skb->data;
96 if (likely(ntohs(eh->h_proto) >= ETH_P_802_3_MIN))
97 skb->protocol = eh->h_proto;
99 skb->protocol = htons(ETH_P_802_2);
102 skb->protocol = inner_proto;
109 vlan_set_tci(skb, 0);
110 skb_set_queue_mapping(skb, 0);
111 skb->pkt_type = PACKET_HOST;