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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <linux/in_route.h>
23 #include <linux/inetdevice.h>
24 #include <linux/jhash.h>
25 #include <linux/list.h>
26 #include <linux/kernel.h>
27 #include <linux/version.h>
28 #include <linux/workqueue.h>
29 #include <linux/rculist.h>
30 #include <net/ip_tunnels.h>
31 #include <net/route.h>
37 int iptunnel_xmit(struct net *net, struct rtable *rt,
39 __be32 src, __be32 dst, __u8 proto,
40 __u8 tos, __u8 ttl, __be16 df)
42 int pkt_len = skb->len;
48 skb_clear_rxhash(skb);
50 skb_dst_set(skb, &rt_dst(rt));
52 /* Do not clear ovs_skb_cb. It will be done in gso code. */
53 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
56 /* Push down and install the IP header. */
57 __skb_push(skb, sizeof(struct iphdr));
58 skb_reset_network_header(skb);
63 iph->ihl = sizeof(struct iphdr) >> 2;
65 iph->protocol = proto;
70 __ip_select_ident(iph, &rt_dst(rt), (skb_shinfo(skb)->gso_segs ?: 1) - 1);
72 err = ip_local_out(skb);
73 if (unlikely(net_xmit_eval(err)))
78 int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto)
80 if (unlikely(!pskb_may_pull(skb, hdr_len)))
83 skb_pull_rcsum(skb, hdr_len);
85 if (inner_proto == htons(ETH_P_TEB)) {
88 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
91 eh = (struct ethhdr *)skb->data;
93 if (likely(ntohs(eh->h_proto) >= ETH_P_802_3_MIN))
94 skb->protocol = eh->h_proto;
96 skb->protocol = htons(ETH_P_802_2);
99 skb->protocol = inner_proto;
104 skb_clear_rxhash(skb);
106 vlan_set_tci(skb, 0);
107 skb_set_queue_mapping(skb, 0);
108 skb->pkt_type = PACKET_HOST;