mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	gre6: Cleanup GREv6 receive path, call common GRE functions
- Create gre_rcv function. This calls gre_parse_header and ip6gre_rcv.
  - Call ip6_tnl_rcv. Doing this and using gre_parse_header eliminates
    most of the code in ip6gre_rcv.
Signed-off-by: Tom Herbert <tom@herbertland.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
			
			
This commit is contained in:
		
							parent
							
								
									95f5c64c3c
								
							
						
					
					
						commit
						308edfdf15
					
				
					 1 changed files with 28 additions and 122 deletions
				
			
		| 
						 | 
				
			
			@ -54,6 +54,7 @@
 | 
			
		|||
#include <net/ip6_fib.h>
 | 
			
		||||
#include <net/ip6_route.h>
 | 
			
		||||
#include <net/ip6_tunnel.h>
 | 
			
		||||
#include <net/gre.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static bool log_ecn_error = true;
 | 
			
		||||
| 
						 | 
				
			
			@ -443,137 +444,40 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
 | 
			
		|||
	t->err_time = jiffies;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int ip6gre_rcv(struct sk_buff *skb)
 | 
			
		||||
static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
 | 
			
		||||
{
 | 
			
		||||
	const struct ipv6hdr *ipv6h;
 | 
			
		||||
	u8     *h;
 | 
			
		||||
	__be16    flags;
 | 
			
		||||
	__sum16   csum = 0;
 | 
			
		||||
	__be32 key = 0;
 | 
			
		||||
	u32    seqno = 0;
 | 
			
		||||
	struct ip6_tnl *tunnel;
 | 
			
		||||
	int    offset = 4;
 | 
			
		||||
	__be16 gre_proto;
 | 
			
		||||
	int err;
 | 
			
		||||
 | 
			
		||||
	if (!pskb_may_pull(skb, sizeof(struct in6_addr)))
 | 
			
		||||
		goto drop;
 | 
			
		||||
 | 
			
		||||
	ipv6h = ipv6_hdr(skb);
 | 
			
		||||
	h = skb->data;
 | 
			
		||||
	flags = *(__be16 *)h;
 | 
			
		||||
 | 
			
		||||
	if (flags&(GRE_CSUM|GRE_KEY|GRE_ROUTING|GRE_SEQ|GRE_VERSION)) {
 | 
			
		||||
		/* - Version must be 0.
 | 
			
		||||
		   - We do not support routing headers.
 | 
			
		||||
		 */
 | 
			
		||||
		if (flags&(GRE_VERSION|GRE_ROUTING))
 | 
			
		||||
			goto drop;
 | 
			
		||||
 | 
			
		||||
		if (flags&GRE_CSUM) {
 | 
			
		||||
			csum = skb_checksum_simple_validate(skb);
 | 
			
		||||
			offset += 4;
 | 
			
		||||
		}
 | 
			
		||||
		if (flags&GRE_KEY) {
 | 
			
		||||
			key = *(__be32 *)(h + offset);
 | 
			
		||||
			offset += 4;
 | 
			
		||||
		}
 | 
			
		||||
		if (flags&GRE_SEQ) {
 | 
			
		||||
			seqno = ntohl(*(__be32 *)(h + offset));
 | 
			
		||||
			offset += 4;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	gre_proto = *(__be16 *)(h + 2);
 | 
			
		||||
 | 
			
		||||
	tunnel = ip6gre_tunnel_lookup(skb->dev,
 | 
			
		||||
					  &ipv6h->saddr, &ipv6h->daddr, key,
 | 
			
		||||
					  gre_proto);
 | 
			
		||||
				      &ipv6h->saddr, &ipv6h->daddr, tpi->key,
 | 
			
		||||
				      tpi->proto);
 | 
			
		||||
	if (tunnel) {
 | 
			
		||||
		struct pcpu_sw_netstats *tstats;
 | 
			
		||||
		ip6_tnl_rcv(tunnel, skb, tpi, NULL, false);
 | 
			
		||||
 | 
			
		||||
		if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
 | 
			
		||||
			goto drop;
 | 
			
		||||
 | 
			
		||||
		if (!ip6_tnl_rcv_ctl(tunnel, &ipv6h->daddr, &ipv6h->saddr)) {
 | 
			
		||||
			tunnel->dev->stats.rx_dropped++;
 | 
			
		||||
			goto drop;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		skb->protocol = gre_proto;
 | 
			
		||||
		/* WCCP version 1 and 2 protocol decoding.
 | 
			
		||||
		 * - Change protocol to IPv6
 | 
			
		||||
		 * - When dealing with WCCPv2, Skip extra 4 bytes in GRE header
 | 
			
		||||
		 */
 | 
			
		||||
		if (flags == 0 && gre_proto == htons(ETH_P_WCCP)) {
 | 
			
		||||
			skb->protocol = htons(ETH_P_IPV6);
 | 
			
		||||
			if ((*(h + offset) & 0xF0) != 0x40)
 | 
			
		||||
				offset += 4;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		skb->mac_header = skb->network_header;
 | 
			
		||||
		__pskb_pull(skb, offset);
 | 
			
		||||
		skb_postpull_rcsum(skb, skb_transport_header(skb), offset);
 | 
			
		||||
 | 
			
		||||
		if (((flags&GRE_CSUM) && csum) ||
 | 
			
		||||
		    (!(flags&GRE_CSUM) && tunnel->parms.i_flags&GRE_CSUM)) {
 | 
			
		||||
			tunnel->dev->stats.rx_crc_errors++;
 | 
			
		||||
			tunnel->dev->stats.rx_errors++;
 | 
			
		||||
			goto drop;
 | 
			
		||||
		}
 | 
			
		||||
		if (tunnel->parms.i_flags&GRE_SEQ) {
 | 
			
		||||
			if (!(flags&GRE_SEQ) ||
 | 
			
		||||
			    (tunnel->i_seqno &&
 | 
			
		||||
					(s32)(seqno - tunnel->i_seqno) < 0)) {
 | 
			
		||||
				tunnel->dev->stats.rx_fifo_errors++;
 | 
			
		||||
				tunnel->dev->stats.rx_errors++;
 | 
			
		||||
				goto drop;
 | 
			
		||||
			}
 | 
			
		||||
			tunnel->i_seqno = seqno + 1;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/* Warning: All skb pointers will be invalidated! */
 | 
			
		||||
		if (tunnel->dev->type == ARPHRD_ETHER) {
 | 
			
		||||
			if (!pskb_may_pull(skb, ETH_HLEN)) {
 | 
			
		||||
				tunnel->dev->stats.rx_length_errors++;
 | 
			
		||||
				tunnel->dev->stats.rx_errors++;
 | 
			
		||||
				goto drop;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			ipv6h = ipv6_hdr(skb);
 | 
			
		||||
			skb->protocol = eth_type_trans(skb, tunnel->dev);
 | 
			
		||||
			skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		__skb_tunnel_rx(skb, tunnel->dev, tunnel->net);
 | 
			
		||||
 | 
			
		||||
		skb_reset_network_header(skb);
 | 
			
		||||
 | 
			
		||||
		err = IP6_ECN_decapsulate(ipv6h, skb);
 | 
			
		||||
		if (unlikely(err)) {
 | 
			
		||||
			if (log_ecn_error)
 | 
			
		||||
				net_info_ratelimited("non-ECT from %pI6 with dsfield=%#x\n",
 | 
			
		||||
						     &ipv6h->saddr,
 | 
			
		||||
						     ipv6_get_dsfield(ipv6h));
 | 
			
		||||
			if (err > 1) {
 | 
			
		||||
				++tunnel->dev->stats.rx_frame_errors;
 | 
			
		||||
				++tunnel->dev->stats.rx_errors;
 | 
			
		||||
				goto drop;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		tstats = this_cpu_ptr(tunnel->dev->tstats);
 | 
			
		||||
		u64_stats_update_begin(&tstats->syncp);
 | 
			
		||||
		tstats->rx_packets++;
 | 
			
		||||
		tstats->rx_bytes += skb->len;
 | 
			
		||||
		u64_stats_update_end(&tstats->syncp);
 | 
			
		||||
 | 
			
		||||
		netif_rx(skb);
 | 
			
		||||
 | 
			
		||||
		return 0;
 | 
			
		||||
		return PACKET_RCVD;
 | 
			
		||||
	}
 | 
			
		||||
	icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
 | 
			
		||||
 | 
			
		||||
	return PACKET_REJECT;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int gre_rcv(struct sk_buff *skb)
 | 
			
		||||
{
 | 
			
		||||
	struct tnl_ptk_info tpi;
 | 
			
		||||
	bool csum_err = false;
 | 
			
		||||
	int hdr_len;
 | 
			
		||||
 | 
			
		||||
	if (gre_parse_header(skb, &tpi, &csum_err, &hdr_len) < 0)
 | 
			
		||||
		goto drop;
 | 
			
		||||
 | 
			
		||||
	if (iptunnel_pull_header(skb, hdr_len, tpi.proto, false))
 | 
			
		||||
		goto drop;
 | 
			
		||||
 | 
			
		||||
	if (ip6gre_rcv(skb, &tpi) == PACKET_RCVD)
 | 
			
		||||
		return 0;
 | 
			
		||||
 | 
			
		||||
	icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
 | 
			
		||||
drop:
 | 
			
		||||
	kfree_skb(skb);
 | 
			
		||||
	return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -1075,6 +979,8 @@ static int ip6gre_tunnel_ioctl(struct net_device *dev,
 | 
			
		|||
	struct net *net = t->net;
 | 
			
		||||
	struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
 | 
			
		||||
 | 
			
		||||
	memset(&p1, 0, sizeof(p1));
 | 
			
		||||
 | 
			
		||||
	switch (cmd) {
 | 
			
		||||
	case SIOCGETTUNNEL:
 | 
			
		||||
		if (dev == ign->fb_tunnel_dev) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1318,7 +1224,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
static struct inet6_protocol ip6gre_protocol __read_mostly = {
 | 
			
		||||
	.handler     = ip6gre_rcv,
 | 
			
		||||
	.handler     = gre_rcv,
 | 
			
		||||
	.err_handler = ip6gre_err,
 | 
			
		||||
	.flags       = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue