Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

David Ahern and committed by
David S. Miller
4724676d 22e6c58b

+38 -12
+1
include/net/ip6_route.h
··· 174 174 struct sk_buff *skb; 175 175 struct netlink_callback *cb; 176 176 struct net *net; 177 + struct fib_dump_filter filter; 177 178 }; 178 179 179 180 int rt6_dump_route(struct fib6_info *f6i, void *p_arg);
+12 -1
include/net/ip_fib.h
··· 222 222 unsigned long __data[0]; 223 223 }; 224 224 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 + 225 235 int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, 226 236 struct fib_result *res, int fib_flags); 227 237 int fib_table_insert(struct net *, struct fib_table *, struct fib_config *, ··· 463 453 464 454 u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr); 465 455 466 - int ip_valid_fib_dump_req(const struct nlmsghdr *nlh, 456 + int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh, 457 + struct fib_dump_filter *filter, 467 458 struct netlink_ext_ack *extack); 468 459 #endif /* _NET_FIB_H */
+4 -2
net/ipv4/fib_frontend.c
··· 802 802 return err; 803 803 } 804 804 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, 806 807 struct netlink_ext_ack *extack) 807 808 { 808 809 struct rtmsg *rtm; ··· 838 837 { 839 838 const struct nlmsghdr *nlh = cb->nlh; 840 839 struct net *net = sock_net(skb->sk); 840 + struct fib_dump_filter filter = {}; 841 841 unsigned int h, s_h; 842 842 unsigned int e = 0, s_e; 843 843 struct fib_table *tb; ··· 846 844 int dumped = 0, err; 847 845 848 846 if (cb->strict_check) { 849 - err = ip_valid_fib_dump_req(nlh, cb->extack); 847 + err = ip_valid_fib_dump_req(net, nlh, &filter, cb->extack); 850 848 if (err < 0) 851 849 return err; 852 850 }
+6 -2
net/ipv4/ipmr.c
··· 2527 2527 2528 2528 static int ipmr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb) 2529 2529 { 2530 - if (cb->strict_check) { 2531 - int err = ip_valid_fib_dump_req(cb->nlh, cb->extack); 2530 + struct fib_dump_filter filter = {}; 2532 2531 2532 + if (cb->strict_check) { 2533 + int err; 2534 + 2535 + err = ip_valid_fib_dump_req(sock_net(skb->sk), cb->nlh, 2536 + &filter, cb->extack); 2533 2537 if (err < 0) 2534 2538 return err; 2535 2539 }
+3 -2
net/ipv6/ip6_fib.c
··· 569 569 { 570 570 const struct nlmsghdr *nlh = cb->nlh; 571 571 struct net *net = sock_net(skb->sk); 572 + struct rt6_rtnl_dump_arg arg = {}; 572 573 unsigned int h, s_h; 573 574 unsigned int e = 0, s_e; 574 - struct rt6_rtnl_dump_arg arg; 575 575 struct fib6_walker *w; 576 576 struct fib6_table *tb; 577 577 struct hlist_head *head; 578 578 int res = 0; 579 579 580 580 if (cb->strict_check) { 581 - int err = ip_valid_fib_dump_req(nlh, cb->extack); 581 + int err; 582 582 583 + err = ip_valid_fib_dump_req(net, nlh, &arg.filter, cb->extack); 583 584 if (err < 0) 584 585 return err; 585 586 }
+4 -1
net/ipv6/ip6mr.c
··· 2458 2458 static int ip6mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb) 2459 2459 { 2460 2460 const struct nlmsghdr *nlh = cb->nlh; 2461 + struct fib_dump_filter filter = {}; 2461 2462 2462 2463 if (cb->strict_check) { 2463 - int err = ip_valid_fib_dump_req(nlh, cb->extack); 2464 + int err; 2464 2465 2466 + err = ip_valid_fib_dump_req(sock_net(skb->sk), nlh, 2467 + &filter, cb->extack); 2465 2468 if (err < 0) 2466 2469 return err; 2467 2470 }
+8 -4
net/mpls/af_mpls.c
··· 2032 2032 } 2033 2033 2034 2034 #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, 2036 2037 struct netlink_ext_ack *extack) 2037 2038 { 2038 - return ip_valid_fib_dump_req(nlh, extack); 2039 + return ip_valid_fib_dump_req(net, nlh, filter, extack); 2039 2040 } 2040 2041 #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, 2042 2044 struct netlink_ext_ack *extack) 2043 2045 { 2044 2046 struct rtmsg *rtm; ··· 2072 2070 const struct nlmsghdr *nlh = cb->nlh; 2073 2071 struct net *net = sock_net(skb->sk); 2074 2072 struct mpls_route __rcu **platform_label; 2073 + struct fib_dump_filter filter = {}; 2075 2074 size_t platform_labels; 2076 2075 unsigned int index; 2077 2076 2078 2077 ASSERT_RTNL(); 2079 2078 2080 2079 if (cb->strict_check) { 2081 - int err = mpls_valid_fib_dump_req(nlh, cb->extack); 2080 + int err; 2082 2081 2082 + err = mpls_valid_fib_dump_req(net, nlh, &filter, cb->extack); 2083 2083 if (err < 0) 2084 2084 return err; 2085 2085 }