Skip to content

Commit 78f2756

Browse files
dsaherndavem330
authored andcommitted
net/ipv4: Move device validation to helper
Move the device matching check in __fib_validate_source to a helper and export it for use by netfilter modules. Code move only; no functional change intended. Signed-off-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5678cb3 commit 78f2756

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

include/net/ip_fib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ static inline bool fib4_rules_early_flow_dissect(struct net *net,
373373
extern const struct nla_policy rtm_ipv4_policy[];
374374
void ip_fib_init(void);
375375
__be32 fib_compute_spec_dst(struct sk_buff *skb);
376+
bool fib_info_nh_uses_dev(struct fib_info *fi, const struct net_device *dev);
376377
int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
377378
u8 tos, int oif, struct net_device *dev,
378379
struct in_device *idev, u32 *itag);

net/ipv4/fib_frontend.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,32 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
315315
return inet_select_addr(dev, ip_hdr(skb)->saddr, scope);
316316
}
317317

318+
bool fib_info_nh_uses_dev(struct fib_info *fi, const struct net_device *dev)
319+
{
320+
bool dev_match = false;
321+
int ret;
322+
323+
#ifdef CONFIG_IP_ROUTE_MULTIPATH
324+
for (ret = 0; ret < fi->fib_nhs; ret++) {
325+
struct fib_nh *nh = &fi->fib_nh[ret];
326+
327+
if (nh->nh_dev == dev) {
328+
dev_match = true;
329+
break;
330+
} else if (l3mdev_master_ifindex_rcu(nh->nh_dev) == dev->ifindex) {
331+
dev_match = true;
332+
break;
333+
}
334+
}
335+
#else
336+
if (fi->fib_nh[0].nh_dev == dev)
337+
dev_match = true;
338+
#endif
339+
340+
return dev_match;
341+
}
342+
EXPORT_SYMBOL_GPL(fib_info_nh_uses_dev);
343+
318344
/* Given (packet source, input interface) and optional (dst, oif, tos):
319345
* - (main) check, that source is valid i.e. not broadcast or our local
320346
* address.
@@ -361,24 +387,8 @@ static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
361387
(res.type != RTN_LOCAL || !IN_DEV_ACCEPT_LOCAL(idev)))
362388
goto e_inval;
363389
fib_combine_itag(itag, &res);
364-
dev_match = false;
365-
366-
#ifdef CONFIG_IP_ROUTE_MULTIPATH
367-
for (ret = 0; ret < res.fi->fib_nhs; ret++) {
368-
struct fib_nh *nh = &res.fi->fib_nh[ret];
369390

370-
if (nh->nh_dev == dev) {
371-
dev_match = true;
372-
break;
373-
} else if (l3mdev_master_ifindex_rcu(nh->nh_dev) == dev->ifindex) {
374-
dev_match = true;
375-
break;
376-
}
377-
}
378-
#else
379-
if (FIB_RES_DEV(res) == dev)
380-
dev_match = true;
381-
#endif
391+
dev_match = fib_info_nh_uses_dev(res.fi, dev);
382392
if (dev_match) {
383393
ret = FIB_RES_NH(res).nh_scope >= RT_SCOPE_HOST;
384394
return ret;

0 commit comments

Comments
 (0)