Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b7d0ff2 authored by Jeremy Sowden's avatar Jeremy Sowden Committed by Greg Kroah-Hartman
Browse files

vti4: eliminated some duplicate code.



commit f981c57ffd2d7cf2dd4b6d6f8fcb3965df42f54c upstream.

The ipip tunnel introduced in commit dd9ee3444014 ("vti4: Fix a ipip
packet processing bug in 'IPCOMP' virtual tunnel") largely duplicated
the existing vti_input and vti_recv functions.  Refactored to
deduplicate the common code.

Signed-off-by: default avatarJeremy Sowden <jeremy@azazel.net>
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e6194d4a
Loading
Loading
Loading
Loading
+22 −38
Original line number Original line Diff line number Diff line
@@ -50,7 +50,7 @@ static unsigned int vti_net_id __read_mostly;
static int vti_tunnel_init(struct net_device *dev);
static int vti_tunnel_init(struct net_device *dev);


static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,
static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,
		     int encap_type)
		     int encap_type, bool update_skb_dev)
{
{
	struct ip_tunnel *tunnel;
	struct ip_tunnel *tunnel;
	const struct iphdr *iph = ip_hdr(skb);
	const struct iphdr *iph = ip_hdr(skb);
@@ -65,6 +65,9 @@ static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,


		XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel;
		XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel;


		if (update_skb_dev)
			skb->dev = tunnel->dev;

		return xfrm_input(skb, nexthdr, spi, encap_type);
		return xfrm_input(skb, nexthdr, spi, encap_type);
	}
	}


@@ -74,47 +77,28 @@ static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,
	return 0;
	return 0;
}
}


static int vti_input_ipip(struct sk_buff *skb, int nexthdr, __be32 spi,
static int vti_input_proto(struct sk_buff *skb, int nexthdr, __be32 spi,
			   int encap_type)
			   int encap_type)
{
{
	struct ip_tunnel *tunnel;
	return vti_input(skb, nexthdr, spi, encap_type, false);
	const struct iphdr *iph = ip_hdr(skb);
	struct net *net = dev_net(skb->dev);
	struct ip_tunnel_net *itn = net_generic(net, vti_net_id);

	tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
				  iph->saddr, iph->daddr, 0);
	if (tunnel) {
		if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
			goto drop;

		XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel;

		skb->dev = tunnel->dev;

		return xfrm_input(skb, nexthdr, spi, encap_type);
	}

	return -EINVAL;
drop:
	kfree_skb(skb);
	return 0;
}
}


static int vti_rcv(struct sk_buff *skb)
static int vti_rcv(struct sk_buff *skb, __be32 spi, bool update_skb_dev)
{
{
	XFRM_SPI_SKB_CB(skb)->family = AF_INET;
	XFRM_SPI_SKB_CB(skb)->family = AF_INET;
	XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
	XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);


	return vti_input(skb, ip_hdr(skb)->protocol, 0, 0);
	return vti_input(skb, ip_hdr(skb)->protocol, spi, 0, update_skb_dev);
}
}


static int vti_rcv_ipip(struct sk_buff *skb)
static int vti_rcv_proto(struct sk_buff *skb)
{
{
	XFRM_SPI_SKB_CB(skb)->family = AF_INET;
	return vti_rcv(skb, 0, false);
	XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
}


	return vti_input_ipip(skb, ip_hdr(skb)->protocol, ip_hdr(skb)->saddr, 0);
static int vti_rcv_tunnel(struct sk_buff *skb)
{
	return vti_rcv(skb, ip_hdr(skb)->saddr, true);
}
}


static int vti_rcv_cb(struct sk_buff *skb, int err)
static int vti_rcv_cb(struct sk_buff *skb, int err)
@@ -478,31 +462,31 @@ static void __net_init vti_fb_tunnel_init(struct net_device *dev)
}
}


static struct xfrm4_protocol vti_esp4_protocol __read_mostly = {
static struct xfrm4_protocol vti_esp4_protocol __read_mostly = {
	.handler	=	vti_rcv,
	.handler	=	vti_rcv_proto,
	.input_handler	=	vti_input,
	.input_handler	=	vti_input_proto,
	.cb_handler	=	vti_rcv_cb,
	.cb_handler	=	vti_rcv_cb,
	.err_handler	=	vti4_err,
	.err_handler	=	vti4_err,
	.priority	=	100,
	.priority	=	100,
};
};


static struct xfrm4_protocol vti_ah4_protocol __read_mostly = {
static struct xfrm4_protocol vti_ah4_protocol __read_mostly = {
	.handler	=	vti_rcv,
	.handler	=	vti_rcv_proto,
	.input_handler	=	vti_input,
	.input_handler	=	vti_input_proto,
	.cb_handler	=	vti_rcv_cb,
	.cb_handler	=	vti_rcv_cb,
	.err_handler	=	vti4_err,
	.err_handler	=	vti4_err,
	.priority	=	100,
	.priority	=	100,
};
};


static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = {
static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = {
	.handler	=	vti_rcv,
	.handler	=	vti_rcv_proto,
	.input_handler	=	vti_input,
	.input_handler	=	vti_input_proto,
	.cb_handler	=	vti_rcv_cb,
	.cb_handler	=	vti_rcv_cb,
	.err_handler	=	vti4_err,
	.err_handler	=	vti4_err,
	.priority	=	100,
	.priority	=	100,
};
};


static struct xfrm_tunnel ipip_handler __read_mostly = {
static struct xfrm_tunnel ipip_handler __read_mostly = {
	.handler	=	vti_rcv_ipip,
	.handler	=	vti_rcv_tunnel,
	.err_handler	=	vti4_err,
	.err_handler	=	vti4_err,
	.priority	=	0,
	.priority	=	0,
};
};