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

Commit 9e56e380 authored by David S. Miller's avatar David S. Miller
Browse files

ipv4: Adjust in_dev handling in fib_validate_source()



Checking for in_dev being NULL is pointless.

In fact, all of our callers have in_dev precomputed already,
so just pass it in and remove the NULL checking.

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a207a4b2
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -233,7 +233,7 @@ extern void ip_fib_init(void);
extern __be32 fib_compute_spec_dst(struct sk_buff *skb);
extern __be32 fib_compute_spec_dst(struct sk_buff *skb);
extern int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
extern int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
			       u8 tos, int oif, struct net_device *dev,
			       u8 tos, int oif, struct net_device *dev,
			       u32 *itag);
			       struct in_device *idev, u32 *itag);
extern void fib_select_default(struct fib_result *res);
extern void fib_select_default(struct fib_result *res);


/* Exported by fib_semantics.c */
/* Exported by fib_semantics.c */
+10 −17
Original line number Original line Diff line number Diff line
@@ -226,15 +226,14 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
 * called with rcu_read_lock()
 * called with rcu_read_lock()
 */
 */
int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst, u8 tos,
int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst, u8 tos,
			int oif, struct net_device *dev, u32 *itag)
			int oif, struct net_device *dev, struct in_device *idev,
			u32 *itag)
{
{
	struct in_device *in_dev;
	int ret, no_addr, rpf, accept_local;
	struct flowi4 fl4;
	struct fib_result res;
	struct fib_result res;
	int no_addr, rpf, accept_local;
	struct flowi4 fl4;
	bool dev_match;
	int ret;
	struct net *net;
	struct net *net;
	bool dev_match;


	fl4.flowi4_oif = 0;
	fl4.flowi4_oif = 0;
	fl4.flowi4_iif = oif;
	fl4.flowi4_iif = oif;
@@ -244,19 +243,13 @@ int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst, u8 tos,
	fl4.flowi4_scope = RT_SCOPE_UNIVERSE;
	fl4.flowi4_scope = RT_SCOPE_UNIVERSE;


	no_addr = rpf = accept_local = 0;
	no_addr = rpf = accept_local = 0;
	in_dev = __in_dev_get_rcu(dev);
	no_addr = idev->ifa_list == NULL;
	if (in_dev) {
		no_addr = in_dev->ifa_list == NULL;


	/* Ignore rp_filter for packets protected by IPsec. */
	/* Ignore rp_filter for packets protected by IPsec. */
		rpf = secpath_exists(skb) ? 0 : IN_DEV_RPFILTER(in_dev);
	rpf = secpath_exists(skb) ? 0 : IN_DEV_RPFILTER(idev);


		accept_local = IN_DEV_ACCEPT_LOCAL(in_dev);
	accept_local = IN_DEV_ACCEPT_LOCAL(idev);
		fl4.flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0;
	fl4.flowi4_mark = IN_DEV_SRC_VMARK(idev) ? skb->mark : 0;
	}

	if (in_dev == NULL)
		goto e_inval;


	net = dev_net(dev);
	net = dev_net(dev);
	if (fib_lookup(net, &fl4, &res))
	if (fib_lookup(net, &fl4, &res))
+6 −4
Original line number Original line Diff line number Diff line
@@ -1999,7 +1999,8 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
		if (!ipv4_is_local_multicast(daddr))
		if (!ipv4_is_local_multicast(daddr))
			goto e_inval;
			goto e_inval;
	} else {
	} else {
		err = fib_validate_source(skb, saddr, 0, tos, 0, dev, &itag);
		err = fib_validate_source(skb, saddr, 0, tos, 0, dev,
					  in_dev, &itag);
		if (err < 0)
		if (err < 0)
			goto e_err;
			goto e_err;
	}
	}
@@ -2100,7 +2101,7 @@ static int __mkroute_input(struct sk_buff *skb,




	err = fib_validate_source(skb, saddr, daddr, tos, FIB_RES_OIF(*res),
	err = fib_validate_source(skb, saddr, daddr, tos, FIB_RES_OIF(*res),
				  in_dev->dev, &itag);
				  in_dev->dev, in_dev, &itag);
	if (err < 0) {
	if (err < 0) {
		ip_handle_martian_source(in_dev->dev, in_dev, skb, daddr,
		ip_handle_martian_source(in_dev->dev, in_dev, skb, daddr,
					 saddr);
					 saddr);
@@ -2274,7 +2275,7 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
	if (res.type == RTN_LOCAL) {
	if (res.type == RTN_LOCAL) {
		err = fib_validate_source(skb, saddr, daddr, tos,
		err = fib_validate_source(skb, saddr, daddr, tos,
					  net->loopback_dev->ifindex,
					  net->loopback_dev->ifindex,
					  dev, &itag);
					  dev, in_dev, &itag);
		if (err < 0)
		if (err < 0)
			goto martian_source_keep_err;
			goto martian_source_keep_err;
		if (err)
		if (err)
@@ -2295,7 +2296,8 @@ brd_input:
		goto e_inval;
		goto e_inval;


	if (!ipv4_is_zeronet(saddr)) {
	if (!ipv4_is_zeronet(saddr)) {
		err = fib_validate_source(skb, saddr, 0, tos, 0, dev, &itag);
		err = fib_validate_source(skb, saddr, 0, tos, 0, dev,
					  in_dev, &itag);
		if (err < 0)
		if (err < 0)
			goto martian_source_keep_err;
			goto martian_source_keep_err;
		if (err)
		if (err)