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 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0)
39 int rpl_iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
40 __be32 src, __be32 dst, __u8 proto, __u8 tos, __u8 ttl,
43 int pkt_len = skb->len;
51 skb_dst_set(skb, &rt_dst(rt));
53 /* Do not clear ovs_skb_cb. It will be done in gso code. */
54 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
57 /* Push down and install the IP header. */
58 __skb_push(skb, sizeof(struct iphdr));
59 skb_reset_network_header(skb);
64 iph->ihl = sizeof(struct iphdr) >> 2;
66 iph->protocol = proto;
72 #ifdef HAVE_IP_SELECT_IDENT_USING_DST_ENTRY
73 __ip_select_ident(iph, &rt_dst(rt), (skb_shinfo(skb)->gso_segs ?: 1) - 1);
75 __ip_select_ident(iph, skb_shinfo(skb)->gso_segs ?: 1);
78 err = ip_local_out(skb);
79 if (unlikely(net_xmit_eval(err)))
83 EXPORT_SYMBOL_GPL(rpl_iptunnel_xmit);
85 struct sk_buff *ovs_iptunnel_handle_offloads(struct sk_buff *skb,
86 bool csum_help, int gso_type_mask,
87 void (*fix_segment)(struct sk_buff *))
91 if (likely(!skb_is_encapsulated(skb))) {
92 skb_reset_inner_headers(skb);
93 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
94 skb->encapsulation = 1;
96 } else if (skb_is_gso(skb)) {
104 OVS_GSO_CB(skb)->fix_segment = fix_segment;
106 if (skb_is_gso(skb)) {
107 err = skb_unclone(skb, GFP_ATOMIC);
110 skb_shinfo(skb)->gso_type |= gso_type_mask;
114 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
115 /* If packet is not gso and we are resolving any partial checksum,
116 * clear encapsulation flag. This allows setting CHECKSUM_PARTIAL
117 * on the outer header without confusing devices that implement
118 * NETIF_F_IP_CSUM with encapsulation.
121 skb->encapsulation = 0;
124 if (skb->ip_summed == CHECKSUM_PARTIAL && csum_help) {
125 err = skb_checksum_help(skb);
128 } else if (skb->ip_summed != CHECKSUM_PARTIAL)
129 skb->ip_summed = CHECKSUM_NONE;
136 EXPORT_SYMBOL_GPL(ovs_iptunnel_handle_offloads);
138 int rpl_iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto)
140 if (unlikely(!pskb_may_pull(skb, hdr_len)))
143 skb_pull_rcsum(skb, hdr_len);
145 if (inner_proto == htons(ETH_P_TEB)) {
148 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
151 eh = (struct ethhdr *)skb->data;
153 if (likely(ntohs(eh->h_proto) >= ETH_P_802_3_MIN))
154 skb->protocol = eh->h_proto;
156 skb->protocol = htons(ETH_P_802_2);
159 skb->protocol = inner_proto;
166 vlan_set_tci(skb, 0);
167 skb_set_queue_mapping(skb, 0);
168 skb->pkt_type = PACKET_HOST;
171 EXPORT_SYMBOL_GPL(rpl_iptunnel_pull_header);
175 bool ovs_skb_is_encapsulated(struct sk_buff *skb)
177 /* checking for inner protocol should be sufficient on newer kernel, but
178 * old kernel just set encapsulation bit.
180 return ovs_skb_get_inner_protocol(skb) || skb_encapsulation(skb);
182 EXPORT_SYMBOL_GPL(ovs_skb_is_encapsulated);