aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorPravin B Shelar <pshelar@nicira.com>2013-06-17 20:49:56 -0400
committerDavid S. Miller <davem@davemloft.net>2013-06-19 21:07:41 -0400
commit0e6fbc5b6c6218987c93b8c7ca60cf786062899d (patch)
tree5b1241cdd4e43148cd09bc2f6b33d92990680909 /net
parent45f2e9976cb6fc3f1cc533fd53fe74da5a9dbce4 (diff)
ip_tunnels: extend iptunnel_xmit()
Refactor various ip tunnels xmit functions and extend iptunnel_xmit() so that there is more code sharing. Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-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
4 files changed, 108 insertions, 59 deletions
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: