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
20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/in_route.h>
24 #include <linux/inetdevice.h>
25 #include <linux/jhash.h>
26 #include <linux/list.h>
27 #include <linux/kernel.h>
28 #include <linux/version.h>
29 #include <linux/workqueue.h>
30 #include <linux/rculist.h>
31 #include <net/ip_tunnels.h>
32 #include <net/route.h>
38 #ifndef GRE_USE_KERNEL_GRE_HANDLE_OFFLOADS
39 int iptunnel_xmit(struct sock *sk, struct rtable *rt,
41 __be32 src, __be32 dst, __u8 proto,
42 __u8 tos, __u8 ttl, __be16 df, bool xnet)
44 int pkt_len = skb->len;
52 skb_dst_set(skb, &rt_dst(rt));
54 /* Do not clear ovs_skb_cb. It will be done in gso code. */
55 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
58 /* Push down and install the IP header. */
59 __skb_push(skb, sizeof(struct iphdr));
60 skb_reset_network_header(skb);
65 iph->ihl = sizeof(struct iphdr) >> 2;
67 iph->protocol = proto;
73 #ifdef HAVE_IP_SELECT_IDENT_USING_DST_ENTRY
74 __ip_select_ident(iph, &rt_dst(rt), (skb_shinfo(skb)->gso_segs ?: 1) - 1);
76 __ip_select_ident(iph, skb_shinfo(skb)->gso_segs ?: 1);
79 err = ip_local_out(skb);
80 if (unlikely(net_xmit_eval(err)))
85 int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto)
87 if (unlikely(!pskb_may_pull(skb, hdr_len)))
90 skb_pull_rcsum(skb, hdr_len);
92 if (inner_proto == htons(ETH_P_TEB)) {
95 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
98 eh = (struct ethhdr *)skb->data;
100 if (likely(ntohs(eh->h_proto) >= ETH_P_802_3_MIN))
101 skb->protocol = eh->h_proto;
103 skb->protocol = htons(ETH_P_802_2);
106 skb->protocol = inner_proto;
113 vlan_set_tci(skb, 0);
114 skb_set_queue_mapping(skb, 0);
115 skb->pkt_type = PACKET_HOST;