aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/net/vxlan.c32
-rw-r--r--include/net/ip_tunnels.h26
-rw-r--r--net/ipv4/Makefile2
-rw-r--r--net/ipv4/ip_tunnel.c38
-rw-r--r--net/ipv4/ip_tunnel_core.c88
-rw-r--r--net/ipv6/sit.c39
6 files changed, 131 insertions, 94 deletions
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index f6dce13c8f89..284c6c00c353 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -1021,7 +1021,6 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1021 struct vxlan_dev *vxlan = netdev_priv(dev); 1021 struct vxlan_dev *vxlan = netdev_priv(dev);
1022 struct rtable *rt; 1022 struct rtable *rt;
1023 const struct iphdr *old_iph; 1023 const struct iphdr *old_iph;
1024 struct iphdr *iph;
1025 struct vxlanhdr *vxh; 1024 struct vxlanhdr *vxh;
1026 struct udphdr *uh; 1025 struct udphdr *uh;
1027 struct flowi4 fl4; 1026 struct flowi4 fl4;
@@ -1030,6 +1029,7 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1030 u32 vni; 1029 u32 vni;
1031 __be16 df = 0; 1030 __be16 df = 0;
1032 __u8 tos, ttl; 1031 __u8 tos, ttl;
1032 int err;
1033 1033
1034 dst_port = rdst->remote_port ? rdst->remote_port : vxlan->dst_port; 1034 dst_port = rdst->remote_port ? rdst->remote_port : vxlan->dst_port;
1035 vni = rdst->remote_vni; 1035 vni = rdst->remote_vni;
@@ -1097,13 +1097,6 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1097 vxlan_encap_bypass(skb, vxlan, dst_vxlan); 1097 vxlan_encap_bypass(skb, vxlan, dst_vxlan);
1098 return NETDEV_TX_OK; 1098 return NETDEV_TX_OK;
1099 } 1099 }
1100
1101 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
1102 IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
1103 IPSKB_REROUTED);
1104 skb_dst_drop(skb);
1105 skb_dst_set(skb, &rt->dst);
1106
1107 vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh)); 1100 vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
1108 vxh->vx_flags = htonl(VXLAN_FLAGS); 1101 vxh->vx_flags = htonl(VXLAN_FLAGS);
1109 vxh->vx_vni = htonl(vni << 8); 1102 vxh->vx_vni = htonl(vni << 8);
@@ -1118,27 +1111,18 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1118 uh->len = htons(skb->len); 1111 uh->len = htons(skb->len);
1119 uh->check = 0; 1112 uh->check = 0;
1120 1113
1121 __skb_push(skb, sizeof(*iph));
1122 skb_reset_network_header(skb);
1123 iph = ip_hdr(skb);
1124 iph->version = 4;
1125 iph->ihl = sizeof(struct iphdr) >> 2;
1126 iph->frag_off = df;
1127 iph->protocol = IPPROTO_UDP;
1128 iph->tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
1129 iph->daddr = dst;
1130 iph->saddr = fl4.saddr;
1131 iph->ttl = ttl ? : ip4_dst_hoplimit(&rt->dst);
1132 tunnel_ip_select_ident(skb, old_iph, &rt->dst);
1133
1134 nf_reset(skb);
1135
1136 vxlan_set_owner(dev, skb); 1114 vxlan_set_owner(dev, skb);
1137 1115
1138 if (handle_offloads(skb)) 1116 if (handle_offloads(skb))
1139 goto drop; 1117 goto drop;
1140 1118
1141 iptunnel_xmit(skb, dev); 1119 tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
1120 ttl = ttl ? : ip4_dst_hoplimit(&rt->dst);
1121
1122 err = iptunnel_xmit(dev_net(dev), rt, skb, fl4.saddr, dst,
1123 IPPROTO_UDP, tos, ttl, df);
1124 iptunnel_xmit_stats(err, &dev->stats, dev->tstats);
1125
1142 return NETDEV_TX_OK; 1126 return NETDEV_TX_OK;
1143 1127
1144drop: 1128drop:
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 1be442f89406..b84f1ab09d78 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -155,23 +155,27 @@ static inline void tunnel_ip_select_ident(struct sk_buff *skb,
155 (skb_shinfo(skb)->gso_segs ?: 1) - 1); 155 (skb_shinfo(skb)->gso_segs ?: 1) - 1);
156} 156}
157 157
158static inline void iptunnel_xmit(struct sk_buff *skb, struct net_device *dev) 158int iptunnel_xmit(struct net *net, struct rtable *rt,
159 struct sk_buff *skb,
160 __be32 src, __be32 dst, __u8 proto,
161 __u8 tos, __u8 ttl, __be16 df);
162
163static inline void iptunnel_xmit_stats(int err,
164 struct net_device_stats *err_stats,
165 struct pcpu_tstats __percpu *stats)
159{ 166{
160 int err; 167 if (err > 0) {
161 int pkt_len = skb->len - skb_transport_offset(skb); 168 struct pcpu_tstats *tstats = this_cpu_ptr(stats);
162 struct pcpu_tstats *tstats = this_cpu_ptr(dev->tstats);
163 169
164 nf_reset(skb);
165
166 err = ip_local_out(skb);
167 if (likely(net_xmit_eval(err) == 0)) {
168 u64_stats_update_begin(&tstats->syncp); 170 u64_stats_update_begin(&tstats->syncp);
169 tstats->tx_bytes += pkt_len; 171 tstats->tx_bytes += err;
170 tstats->tx_packets++; 172 tstats->tx_packets++;
171 u64_stats_update_end(&tstats->syncp); 173 u64_stats_update_end(&tstats->syncp);
174 } else if (err < 0) {
175 err_stats->tx_errors++;
176 err_stats->tx_aborted_errors++;
172 } else { 177 } else {
173 dev->stats.tx_errors++; 178 err_stats->tx_dropped++;
174 dev->stats.tx_aborted_errors++;
175 } 179 }
176} 180}
177#endif /* __NET_IP_TUNNELS_H */ 181#endif /* __NET_IP_TUNNELS_H */
diff --git a/net/ipv4/Makefile b/net/ipv4/Makefile
index 7fcf8101d85f..86ded0bac9c7 100644
--- a/net/ipv4/Makefile
+++ b/net/ipv4/Makefile
@@ -11,7 +11,7 @@ obj-y := route.o inetpeer.o protocol.o \
11 tcp_offload.o datagram.o raw.o udp.o udplite.o \ 11 tcp_offload.o datagram.o raw.o udp.o udplite.o \
12 udp_offload.o arp.o icmp.o devinet.o af_inet.o igmp.o \ 12 udp_offload.o arp.o icmp.o devinet.o af_inet.o igmp.o \
13 fib_frontend.o fib_semantics.o fib_trie.o \ 13 fib_frontend.o fib_semantics.o fib_trie.o \
14 inet_fragment.o ping.o 14 inet_fragment.o ping.o ip_tunnel_core.o
15 15
16obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o 16obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o
17obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o 17obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index e189db409b0e..a06a2ed49597 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -491,19 +491,17 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
491{ 491{
492 struct ip_tunnel *tunnel = netdev_priv(dev); 492 struct ip_tunnel *tunnel = netdev_priv(dev);
493 const struct iphdr *inner_iph; 493 const struct iphdr *inner_iph;
494 struct iphdr *iph;
495 struct flowi4 fl4; 494 struct flowi4 fl4;
496 u8 tos, ttl; 495 u8 tos, ttl;
497 __be16 df; 496 __be16 df;
498 struct rtable *rt; /* Route to the other host */ 497 struct rtable *rt; /* Route to the other host */
499 struct net_device *tdev; /* Device to other host */
500 unsigned int max_headroom; /* The extra header space needed */ 498 unsigned int max_headroom; /* The extra header space needed */
501 __be32 dst; 499 __be32 dst;
502 int mtu; 500 int mtu;
501 int err;
503 502
504 inner_iph = (const struct iphdr *)skb_inner_network_header(skb); 503 inner_iph = (const struct iphdr *)skb_inner_network_header(skb);
505 504
506 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
507 dst = tnl_params->daddr; 505 dst = tnl_params->daddr;
508 if (dst == 0) { 506 if (dst == 0) {
509 /* NBMA tunnel */ 507 /* NBMA tunnel */
@@ -571,14 +569,11 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
571 dev->stats.tx_carrier_errors++; 569 dev->stats.tx_carrier_errors++;
572 goto tx_error; 570 goto tx_error;
573 } 571 }
574 tdev = rt->dst.dev; 572 if (rt->dst.dev == dev) {
575
576 if (tdev == dev) {
577 ip_rt_put(rt); 573 ip_rt_put(rt);
578 dev->stats.collisions++; 574 dev->stats.collisions++;
579 goto tx_error; 575 goto tx_error;
580 } 576 }
581
582 df = tnl_params->frag_off; 577 df = tnl_params->frag_off;
583 578
584 if (df) 579 if (df)
@@ -596,6 +591,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
596 if (!skb_is_gso(skb) && 591 if (!skb_is_gso(skb) &&
597 (inner_iph->frag_off&htons(IP_DF)) && 592 (inner_iph->frag_off&htons(IP_DF)) &&
598 mtu < ntohs(inner_iph->tot_len)) { 593 mtu < ntohs(inner_iph->tot_len)) {
594 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
599 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu)); 595 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
600 ip_rt_put(rt); 596 ip_rt_put(rt);
601 goto tx_error; 597 goto tx_error;
@@ -646,8 +642,8 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
646 ttl = ip4_dst_hoplimit(&rt->dst); 642 ttl = ip4_dst_hoplimit(&rt->dst);
647 } 643 }
648 644
649 max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct iphdr) 645 max_headroom = LL_RESERVED_SPACE(rt->dst.dev) + sizeof(struct iphdr)
650 + rt->dst.header_len; 646 + rt->dst.header_len;
651 if (max_headroom > dev->needed_headroom) { 647 if (max_headroom > dev->needed_headroom) {
652 dev->needed_headroom = max_headroom; 648 dev->needed_headroom = max_headroom;
653 if (skb_cow_head(skb, dev->needed_headroom)) { 649 if (skb_cow_head(skb, dev->needed_headroom)) {
@@ -657,27 +653,11 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
657 } 653 }
658 } 654 }
659 655
660 skb_dst_drop(skb); 656 err = iptunnel_xmit(dev_net(dev), rt, skb,
661 skb_dst_set(skb, &rt->dst); 657 fl4.saddr, fl4.daddr, protocol,
662 658 ip_tunnel_ecn_encap(tos, inner_iph, skb), ttl, df);
663 /* Push down and install the IP header. */ 659 iptunnel_xmit_stats(err, &dev->stats, dev->tstats);
664 skb_push(skb, sizeof(struct iphdr));
665 skb_reset_network_header(skb);
666
667 iph = ip_hdr(skb);
668 inner_iph = (const struct iphdr *)skb_inner_network_header(skb);
669 660
670 iph->version = 4;
671 iph->ihl = sizeof(struct iphdr) >> 2;
672 iph->frag_off = df;
673 iph->protocol = protocol;
674 iph->tos = ip_tunnel_ecn_encap(tos, inner_iph, skb);
675 iph->daddr = fl4.daddr;
676 iph->saddr = fl4.saddr;
677 iph->ttl = ttl;
678 tunnel_ip_select_ident(skb, inner_iph, &rt->dst);
679
680 iptunnel_xmit(skb, dev);
681 return; 661 return;
682 662
683#if IS_ENABLED(CONFIG_IPV6) 663#if IS_ENABLED(CONFIG_IPV6)
diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
new file mode 100644
index 000000000000..927687e83f18
--- /dev/null
+++ b/net/ipv4/ip_tunnel_core.c
@@ -0,0 +1,88 @@
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
49int 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}
88EXPORT_SYMBOL_GPL(iptunnel_xmit);
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 6b9c1f128eaf..76bb8de435b2 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -723,13 +723,14 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
723 __be16 df = tiph->frag_off; 723 __be16 df = tiph->frag_off;
724 struct rtable *rt; /* Route to the other host */ 724 struct rtable *rt; /* Route to the other host */
725 struct net_device *tdev; /* Device to other host */ 725 struct net_device *tdev; /* Device to other host */
726 struct iphdr *iph; /* Our new IP header */
727 unsigned int max_headroom; /* The extra header space needed */ 726 unsigned int max_headroom; /* The extra header space needed */
728 __be32 dst = tiph->daddr; 727 __be32 dst = tiph->daddr;
729 struct flowi4 fl4; 728 struct flowi4 fl4;
730 int mtu; 729 int mtu;
731 const struct in6_addr *addr6; 730 const struct in6_addr *addr6;
732 int addr_type; 731 int addr_type;
732 u8 ttl;
733 int err;
733 734
734 if (skb->protocol != htons(ETH_P_IPV6)) 735 if (skb->protocol != htons(ETH_P_IPV6))
735 goto tx_error; 736 goto tx_error;
@@ -872,34 +873,14 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
872 skb = new_skb; 873 skb = new_skb;
873 iph6 = ipv6_hdr(skb); 874 iph6 = ipv6_hdr(skb);
874 } 875 }
875 876 ttl = tiph->ttl;
876 skb->transport_header = skb->network_header; 877 if (ttl == 0)
877 skb_push(skb, sizeof(struct iphdr)); 878 ttl = iph6->hop_limit;
878 skb_reset_network_header(skb); 879 tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6));
879 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); 880
880 IPCB(skb)->flags = 0; 881 err = iptunnel_xmit(dev_net(dev), rt, skb, fl4.saddr, fl4.daddr,
881 skb_dst_drop(skb); 882 IPPROTO_IPV6, tos, ttl, df);
882 skb_dst_set(skb, &rt->dst); 883 iptunnel_xmit_stats(err, &dev->stats, dev->tstats);
883
884 /*
885 * Push down and install the IPIP header.
886 */
887
888 iph = ip_hdr(skb);
889 iph->version = 4;
890 iph->ihl = sizeof(struct iphdr)>>2;
891 iph->frag_off = df;
892 iph->protocol = IPPROTO_IPV6;
893 iph->tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6));
894 iph->daddr = fl4.daddr;
895 iph->saddr = fl4.saddr;
896
897 if ((iph->ttl = tiph->ttl) == 0)
898 iph->ttl = iph6->hop_limit;
899
900 skb->ip_summed = CHECKSUM_NONE;
901 ip_select_ident(iph, skb_dst(skb), NULL);
902 iptunnel_xmit(skb, dev);
903 return NETDEV_TX_OK; 884 return NETDEV_TX_OK;
904 885
905tx_error_icmp: 886tx_error_icmp: