diff options
Diffstat (limited to 'net/ipv4/ip_tunnel_core.c')
| -rw-r--r-- | net/ipv4/ip_tunnel_core.c | 98 | 
1 files changed, 92 insertions, 6 deletions
diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c index c31e3ad98ef..f4c987bb7e9 100644 --- a/net/ipv4/ip_tunnel_core.c +++ b/net/ipv4/ip_tunnel_core.c @@ -46,7 +46,7 @@  #include <net/netns/generic.h>  #include <net/rtnetlink.h> -int iptunnel_xmit(struct rtable *rt, struct sk_buff *skb, +int iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,  		  __be32 src, __be32 dst, __u8 proto,  		  __u8 tos, __u8 ttl, __be16 df, bool xnet)  { @@ -56,7 +56,7 @@ int iptunnel_xmit(struct rtable *rt, struct sk_buff *skb,  	skb_scrub_packet(skb, xnet); -	skb->rxhash = 0; +	skb_clear_hash(skb);  	skb_dst_set(skb, &rt->dst);  	memset(IPCB(skb), 0, sizeof(*IPCB(skb))); @@ -74,9 +74,9 @@ int iptunnel_xmit(struct rtable *rt, struct sk_buff *skb,  	iph->daddr	=	dst;  	iph->saddr	=	src;  	iph->ttl	=	ttl; -	__ip_select_ident(iph, &rt->dst, (skb_shinfo(skb)->gso_segs ?: 1) - 1); +	__ip_select_ident(iph, skb_shinfo(skb)->gso_segs ?: 1); -	err = ip_local_out(skb); +	err = ip_local_out_sk(sk, skb);  	if (unlikely(net_xmit_eval(err)))  		pkt_len = 0;  	return pkt_len; @@ -107,8 +107,7 @@ int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto)  	nf_reset(skb);  	secpath_reset(skb); -	if (!skb->l4_rxhash) -		skb->rxhash = 0; +	skb_clear_hash_if_not_l4(skb);  	skb_dst_drop(skb);  	skb->vlan_tci = 0;  	skb_set_queue_mapping(skb, 0); @@ -116,3 +115,90 @@ int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto)  	return 0;  }  EXPORT_SYMBOL_GPL(iptunnel_pull_header); + +struct sk_buff *iptunnel_handle_offloads(struct sk_buff *skb, +					 bool csum_help, +					 int gso_type_mask) +{ +	int err; + +	if (likely(!skb->encapsulation)) { +		skb_reset_inner_headers(skb); +		skb->encapsulation = 1; +	} + +	if (skb_is_gso(skb)) { +		err = skb_unclone(skb, GFP_ATOMIC); +		if (unlikely(err)) +			goto error; +		skb_shinfo(skb)->gso_type |= gso_type_mask; +		return skb; +	} + +	/* If packet is not gso and we are resolving any partial checksum, +	 * clear encapsulation flag. This allows setting CHECKSUM_PARTIAL +	 * on the outer header without confusing devices that implement +	 * NETIF_F_IP_CSUM with encapsulation. +	 */ +	if (csum_help) +		skb->encapsulation = 0; + +	if (skb->ip_summed == CHECKSUM_PARTIAL && csum_help) { +		err = skb_checksum_help(skb); +		if (unlikely(err)) +			goto error; +	} else if (skb->ip_summed != CHECKSUM_PARTIAL) +		skb->ip_summed = CHECKSUM_NONE; + +	return skb; +error: +	kfree_skb(skb); +	return ERR_PTR(err); +} +EXPORT_SYMBOL_GPL(iptunnel_handle_offloads); + +/* Often modified stats are per cpu, other are shared (netdev->stats) */ +struct rtnl_link_stats64 *ip_tunnel_get_stats64(struct net_device *dev, +						struct rtnl_link_stats64 *tot) +{ +	int i; + +	for_each_possible_cpu(i) { +		const struct pcpu_sw_netstats *tstats = +						   per_cpu_ptr(dev->tstats, i); +		u64 rx_packets, rx_bytes, tx_packets, tx_bytes; +		unsigned int start; + +		do { +			start = u64_stats_fetch_begin_irq(&tstats->syncp); +			rx_packets = tstats->rx_packets; +			tx_packets = tstats->tx_packets; +			rx_bytes = tstats->rx_bytes; +			tx_bytes = tstats->tx_bytes; +		} while (u64_stats_fetch_retry_irq(&tstats->syncp, start)); + +		tot->rx_packets += rx_packets; +		tot->tx_packets += tx_packets; +		tot->rx_bytes   += rx_bytes; +		tot->tx_bytes   += tx_bytes; +	} + +	tot->multicast = dev->stats.multicast; + +	tot->rx_crc_errors = dev->stats.rx_crc_errors; +	tot->rx_fifo_errors = dev->stats.rx_fifo_errors; +	tot->rx_length_errors = dev->stats.rx_length_errors; +	tot->rx_frame_errors = dev->stats.rx_frame_errors; +	tot->rx_errors = dev->stats.rx_errors; + +	tot->tx_fifo_errors = dev->stats.tx_fifo_errors; +	tot->tx_carrier_errors = dev->stats.tx_carrier_errors; +	tot->tx_dropped = dev->stats.tx_dropped; +	tot->tx_aborted_errors = dev->stats.tx_aborted_errors; +	tot->tx_errors = dev->stats.tx_errors; + +	tot->collisions  = dev->stats.collisions; + +	return tot; +} +EXPORT_SYMBOL_GPL(ip_tunnel_get_stats64);  | 
