Skip to content

Commit 4724676

Browse files
dsaherndavem330
authored andcommitted
net: Add struct for fib dump filter
Add struct fib_dump_filter for options on limiting which routes are returned in a dump request. The current list is table id, protocol, route type, rtm_flags and nexthop device index. struct net is needed to lookup the net_device from the index. Declare the filter for each route dump handler and plumb the new arguments from dump handlers to ip_valid_fib_dump_req. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 22e6c58 commit 4724676

File tree

7 files changed

+37
-11
lines changed

7 files changed

+37
-11
lines changed

include/net/ip6_route.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ struct rt6_rtnl_dump_arg {
174174
struct sk_buff *skb;
175175
struct netlink_callback *cb;
176176
struct net *net;
177+
struct fib_dump_filter filter;
177178
};
178179

179180
int rt6_dump_route(struct fib6_info *f6i, void *p_arg);

include/net/ip_fib.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ struct fib_table {
222222
unsigned long __data[0];
223223
};
224224

225+
struct fib_dump_filter {
226+
u32 table_id;
227+
/* filter_set is an optimization that an entry is set */
228+
bool filter_set;
229+
unsigned char protocol;
230+
unsigned char rt_type;
231+
unsigned int flags;
232+
struct net_device *dev;
233+
};
234+
225235
int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
226236
struct fib_result *res, int fib_flags);
227237
int fib_table_insert(struct net *, struct fib_table *, struct fib_config *,
@@ -453,6 +463,7 @@ static inline void fib_proc_exit(struct net *net)
453463

454464
u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr);
455465

456-
int ip_valid_fib_dump_req(const struct nlmsghdr *nlh,
466+
int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
467+
struct fib_dump_filter *filter,
457468
struct netlink_ext_ack *extack);
458469
#endif /* _NET_FIB_H */

net/ipv4/fib_frontend.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,8 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
802802
return err;
803803
}
804804

805-
int ip_valid_fib_dump_req(const struct nlmsghdr *nlh,
805+
int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
806+
struct fib_dump_filter *filter,
806807
struct netlink_ext_ack *extack)
807808
{
808809
struct rtmsg *rtm;
@@ -837,14 +838,15 @@ static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
837838
{
838839
const struct nlmsghdr *nlh = cb->nlh;
839840
struct net *net = sock_net(skb->sk);
841+
struct fib_dump_filter filter = {};
840842
unsigned int h, s_h;
841843
unsigned int e = 0, s_e;
842844
struct fib_table *tb;
843845
struct hlist_head *head;
844846
int dumped = 0, err;
845847

846848
if (cb->strict_check) {
847-
err = ip_valid_fib_dump_req(nlh, cb->extack);
849+
err = ip_valid_fib_dump_req(net, nlh, &filter, cb->extack);
848850
if (err < 0)
849851
return err;
850852
}

net/ipv4/ipmr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2527,9 +2527,13 @@ static int ipmr_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
25272527

25282528
static int ipmr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb)
25292529
{
2530+
struct fib_dump_filter filter = {};
2531+
25302532
if (cb->strict_check) {
2531-
int err = ip_valid_fib_dump_req(cb->nlh, cb->extack);
2533+
int err;
25322534

2535+
err = ip_valid_fib_dump_req(sock_net(skb->sk), cb->nlh,
2536+
&filter, cb->extack);
25332537
if (err < 0)
25342538
return err;
25352539
}

net/ipv6/ip6_fib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,17 +569,18 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
569569
{
570570
const struct nlmsghdr *nlh = cb->nlh;
571571
struct net *net = sock_net(skb->sk);
572+
struct rt6_rtnl_dump_arg arg = {};
572573
unsigned int h, s_h;
573574
unsigned int e = 0, s_e;
574-
struct rt6_rtnl_dump_arg arg;
575575
struct fib6_walker *w;
576576
struct fib6_table *tb;
577577
struct hlist_head *head;
578578
int res = 0;
579579

580580
if (cb->strict_check) {
581-
int err = ip_valid_fib_dump_req(nlh, cb->extack);
581+
int err;
582582

583+
err = ip_valid_fib_dump_req(net, nlh, &arg.filter, cb->extack);
583584
if (err < 0)
584585
return err;
585586
}

net/ipv6/ip6mr.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2458,10 +2458,13 @@ static void mrt6msg_netlink_event(struct mr_table *mrt, struct sk_buff *pkt)
24582458
static int ip6mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb)
24592459
{
24602460
const struct nlmsghdr *nlh = cb->nlh;
2461+
struct fib_dump_filter filter = {};
24612462

24622463
if (cb->strict_check) {
2463-
int err = ip_valid_fib_dump_req(nlh, cb->extack);
2464+
int err;
24642465

2466+
err = ip_valid_fib_dump_req(sock_net(skb->sk), nlh,
2467+
&filter, cb->extack);
24652468
if (err < 0)
24662469
return err;
24672470
}

net/mpls/af_mpls.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,13 +2032,15 @@ static int mpls_dump_route(struct sk_buff *skb, u32 portid, u32 seq, int event,
20322032
}
20332033

20342034
#if IS_ENABLED(CONFIG_INET)
2035-
static int mpls_valid_fib_dump_req(const struct nlmsghdr *nlh,
2035+
static int mpls_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
2036+
struct fib_dump_filter *filter,
20362037
struct netlink_ext_ack *extack)
20372038
{
2038-
return ip_valid_fib_dump_req(nlh, extack);
2039+
return ip_valid_fib_dump_req(net, nlh, filter, extack);
20392040
}
20402041
#else
2041-
static int mpls_valid_fib_dump_req(const struct nlmsghdr *nlh,
2042+
static int mpls_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
2043+
struct fib_dump_filter *filter,
20422044
struct netlink_ext_ack *extack)
20432045
{
20442046
struct rtmsg *rtm;
@@ -2070,14 +2072,16 @@ static int mpls_dump_routes(struct sk_buff *skb, struct netlink_callback *cb)
20702072
const struct nlmsghdr *nlh = cb->nlh;
20712073
struct net *net = sock_net(skb->sk);
20722074
struct mpls_route __rcu **platform_label;
2075+
struct fib_dump_filter filter = {};
20732076
size_t platform_labels;
20742077
unsigned int index;
20752078

20762079
ASSERT_RTNL();
20772080

20782081
if (cb->strict_check) {
2079-
int err = mpls_valid_fib_dump_req(nlh, cb->extack);
2082+
int err;
20802083

2084+
err = mpls_valid_fib_dump_req(net, nlh, &filter, cb->extack);
20812085
if (err < 0)
20822086
return err;
20832087
}

0 commit comments

Comments
 (0)