Commit | Line | Data |
---|---|---|
0e6fbc5b PS |
1 | /* |
2 | * Copyright (c) 2013 Nicira, Inc. | |
3 | * | |
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. | |
7 | * | |
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. | |
12 | * | |
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 | |
16 | * 02110-1301, USA | |
17 | */ | |
18 | ||
19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
20 | ||
21 | #include <linux/types.h> | |
22 | #include <linux/kernel.h> | |
23 | #include <linux/skbuff.h> | |
24 | #include <linux/netdevice.h> | |
25 | #include <linux/in.h> | |
26 | #include <linux/if_arp.h> | |
27 | #include <linux/mroute.h> | |
28 | #include <linux/init.h> | |
29 | #include <linux/in6.h> | |
30 | #include <linux/inetdevice.h> | |
31 | #include <linux/netfilter_ipv4.h> | |
32 | #include <linux/etherdevice.h> | |
33 | #include <linux/if_ether.h> | |
34 | #include <linux/if_vlan.h> | |
35 | ||
36 | #include <net/ip.h> | |
37 | #include <net/icmp.h> | |
38 | #include <net/protocol.h> | |
39 | #include <net/ip_tunnels.h> | |
40 | #include <net/arp.h> | |
41 | #include <net/checksum.h> | |
42 | #include <net/dsfield.h> | |
43 | #include <net/inet_ecn.h> | |
44 | #include <net/xfrm.h> | |
45 | #include <net/net_namespace.h> | |
46 | #include <net/netns/generic.h> | |
47 | #include <net/rtnetlink.h> | |
48 | ||
49 | int iptunnel_xmit(struct net *net, struct rtable *rt, | |
50 | struct sk_buff *skb, | |
51 | __be32 src, __be32 dst, __u8 proto, | |
52 | __u8 tos, __u8 ttl, __be16 df) | |
53 | { | |
54 | int pkt_len = skb->len; | |
55 | struct iphdr *iph; | |
56 | int err; | |
57 | ||
58 | nf_reset(skb); | |
59 | secpath_reset(skb); | |
60 | skb->rxhash = 0; | |
61 | skb_dst_drop(skb); | |
62 | skb_dst_set(skb, &rt->dst); | |
63 | memset(IPCB(skb), 0, sizeof(*IPCB(skb))); | |
64 | ||
65 | /* Push down and install the IP header. */ | |
66 | __skb_push(skb, sizeof(struct iphdr)); | |
67 | skb_reset_network_header(skb); | |
68 | ||
69 | iph = ip_hdr(skb); | |
70 | ||
71 | iph->version = 4; | |
72 | iph->ihl = sizeof(struct iphdr) >> 2; | |
73 | iph->frag_off = df; | |
74 | iph->protocol = proto; | |
75 | iph->tos = tos; | |
76 | iph->daddr = dst; | |
77 | iph->saddr = src; | |
78 | iph->ttl = ttl; | |
79 | tunnel_ip_select_ident(skb, | |
80 | (const struct iphdr *)skb_inner_network_header(skb), | |
81 | &rt->dst); | |
82 | ||
83 | err = ip_local_out(skb); | |
84 | if (unlikely(net_xmit_eval(err))) | |
85 | pkt_len = 0; | |
86 | return pkt_len; | |
87 | } | |
88 | EXPORT_SYMBOL_GPL(iptunnel_xmit); |