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/module.h>
21 #include <linux/if_tunnel.h>
22 #include <linux/icmp.h>
25 #include <linux/kernel.h>
26 #include <linux/kmod.h>
27 #include <linux/netdevice.h>
28 #include <linux/skbuff.h>
29 #include <linux/spinlock.h>
33 #include <net/protocol.h>
34 #include <net/route.h>
39 static __be16 __skb_network_protocol(struct sk_buff *skb)
41 __be16 type = skb->protocol;
42 int vlan_depth = ETH_HLEN;
44 while (type == htons(ETH_P_8021Q) || type == htons(ETH_P_8021AD)) {
47 if (unlikely(!pskb_may_pull(skb, vlan_depth + VLAN_HLEN)))
50 vh = (struct vlan_hdr *)(skb->data + vlan_depth);
51 type = vh->h_vlan_encapsulated_proto;
52 vlan_depth += VLAN_HLEN;
58 static struct sk_buff *tnl_skb_gso_segment(struct sk_buff *skb,
59 netdev_features_t features,
62 struct iphdr *iph = ip_hdr(skb);
63 int pkt_hlen = skb_inner_network_offset(skb); /* inner l2 + tunnel hdr. */
64 int mac_offset = skb_inner_mac_offset(skb);
65 struct sk_buff *skb1 = skb;
67 __be16 proto = skb->protocol;
69 /* setup whole inner packet to get protocol. */
70 __skb_pull(skb, mac_offset);
71 skb->protocol = __skb_network_protocol(skb);
73 /* setup l3 packet to gso, to get around segmentation bug on older kernel.*/
74 __skb_pull(skb, (pkt_hlen - mac_offset));
75 skb_reset_mac_header(skb);
76 skb_reset_network_header(skb);
77 skb_reset_transport_header(skb);
79 segs = __skb_gso_segment(skb, 0, tx_path);
80 if (!segs || IS_ERR(segs))
85 __skb_push(skb, pkt_hlen);
86 skb_reset_mac_header(skb);
87 skb_reset_network_header(skb);
88 skb_set_transport_header(skb, sizeof(struct iphdr));
91 memcpy(ip_hdr(skb), iph, pkt_hlen);
92 if (OVS_GSO_CB(skb)->fix_segment)
93 OVS_GSO_CB(skb)->fix_segment(skb);
95 skb->protocol = proto;
103 int rpl_ip_local_out(struct sk_buff *skb)
105 int ret = NETDEV_TX_OK;
108 if (skb_is_gso(skb)) {
113 skb = tnl_skb_gso_segment(skb, 0, false);
114 if (!skb || IS_ERR(skb))
116 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
119 err = skb_checksum_help(skb);
125 struct sk_buff *next_skb = skb->next;
133 iph->id = htons(id++);
135 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
138 err = ip_local_out(skb);
139 if (unlikely(net_xmit_eval(err)))