* [PATCH net-next 0/8] net: extend RTM_GETROUTE to return fib result
@ 2017-05-24 18:19 Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash Roopa Prabhu
` (7 more replies)
0 siblings, 8 replies; 18+ messages in thread
From: Roopa Prabhu @ 2017-05-24 18:19 UTC (permalink / raw)
To: davem; +Cc: netdev, dsahern, nikolay
From: Roopa Prabhu <roopa@cumulusnetworks.com>
This series adds a new RTM_F_FIB_MATCH flag to return matched fib result
with RTM_GETROUTE. This is useful for applications and protocols in
userspace wanting to query the selected route.
examples (with patched iproute2):
ipv4:
----
$ip route show
default via 192.168.0.2 dev eth0
10.0.14.0/24
nexthop via 172.16.0.3 dev dummy0 weight 1
nexthop via 172.16.1.3 dev dummy1 weight 1
$ip route get 10.0.14.2
10.0.14.2 via 172.16.1.3 dev dummy1 src 172.16.1.1
cache
$ip route get fibmatch 10.0.14.2
10.0.14.0/24
nexthop via 172.16.0.3 dev dummy0 weight 1
nexthop via 172.16.1.3 dev dummy1 weight 1
ipv6:
----
$ip -6 route show
2001:db9:100::/120 metric 1024
nexthop via 2001:db8:2::2 dev dummy0 weight 1
nexthop via 2001:db8:12::2 dev dummy1 weight 1
$ip -6 route get 2001:db9:100::1
2001:db9:100::1 from :: via 2001:db8:12::2 dev dummy1 src 2001:db8:12::1 metric 1024 pref medium
$ip -6 route get fibmatch 2001:db9:100::1
2001:db9:100::/120 metric 1024
nexthop via 2001:db8:12::2 dev dummy1 weight 1
nexthop via 2001:db8:2::2 dev dummy0 weight 1
David Ahern (5):
net: ipv4: refactor __ip_route_output_key_hash
net: ipv4: refactor ip_route_input_noref
net: ipv4: Remove event arg to rt_fill_info
net: ipv4: Convert inet_rtm_getroute to rcu versions of route lookup
net: ipv4: Save trie prefix to fib lookup result
Roopa Prabhu (3):
net: ipv4: add new RTM_F_FIB_MATCH flag for use with RTM_GETROUTE
net: ipv4: RTM_GETROUTE: return matched fib result when requested
net: ipv6: RTM_GETROUTE: return matched fib result when requested
include/net/ip_fib.h | 1 +
include/net/route.h | 10 ++-
include/uapi/linux/rtnetlink.h | 1 +
net/ipv4/fib_trie.c | 1 +
net/ipv4/icmp.c | 2 +-
net/ipv4/route.c | 160 ++++++++++++++++++++++++-----------------
net/ipv6/route.c | 11 ++-
7 files changed, 116 insertions(+), 70 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash
2017-05-24 18:19 [PATCH net-next 0/8] net: extend RTM_GETROUTE to return fib result Roopa Prabhu
@ 2017-05-24 18:19 ` Roopa Prabhu
2017-05-24 19:33 ` Rosen, Rami
` (2 more replies)
2017-05-24 18:19 ` [PATCH net-next 2/8] net: ipv4: refactor ip_route_input_noref Roopa Prabhu
` (6 subsequent siblings)
7 siblings, 3 replies; 18+ messages in thread
From: Roopa Prabhu @ 2017-05-24 18:19 UTC (permalink / raw)
To: davem; +Cc: netdev, dsahern, nikolay
From: David Ahern <dsahern@gmail.com>
A later patch wants access to the fib result on an output route lookup
with the rcu lock held. Refactor __ip_route_output_key_hash, pushing
the logic between rcu_read_lock ... rcu_read_unlock into a new helper
that takes the fib_result as an input arg.
To keep the name length under control remove the leading underscores
from the name. _rcu is added to the name of the new helper indicating
it is called with the rcu read lock held.
Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
---
include/net/route.h | 7 ++++++-
net/ipv4/icmp.c | 2 +-
net/ipv4/route.c | 57 +++++++++++++++++++++++++++++++----------------------
3 files changed, 40 insertions(+), 26 deletions(-)
diff --git a/include/net/route.h b/include/net/route.h
index 2cc0e14..5a92347 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -115,11 +115,16 @@ struct rt_cache_stat {
void rt_flush_dev(struct net_device *dev);
struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *flp,
const struct sk_buff *skb);
+struct rtable *ip_route_output_key_hash(struct net *net, struct flowi4 *flp,
+ const struct sk_buff *skb);
+struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *flp,
+ const struct sk_buff *skb,
+ struct fib_result *res);
static inline struct rtable *__ip_route_output_key(struct net *net,
struct flowi4 *flp)
{
- return __ip_route_output_key_hash(net, flp, NULL);
+ return ip_route_output_key_hash(net, flp, NULL);
}
struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 43318b5..5610971 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -489,7 +489,7 @@ static struct rtable *icmp_route_lookup(struct net *net,
fl4->flowi4_oif = l3mdev_master_ifindex(skb_dst(skb_in)->dev);
security_skb_classify_flow(skb_in, flowi4_to_flowi(fl4));
- rt = __ip_route_output_key_hash(net, fl4, skb_in);
+ rt = ip_route_output_key_hash(net, fl4, skb_in);
if (IS_ERR(rt))
return rt;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 655d9ee..f787208 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2246,29 +2246,22 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
* Major route resolver routine.
*/
-struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
- const struct sk_buff *skb)
+struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
+ const struct sk_buff *skb,
+ struct fib_result *res)
{
struct net_device *dev_out = NULL;
+ int orig_oif = fl4->flowi4_oif;
__u8 tos = RT_FL_TOS(fl4);
unsigned int flags = 0;
- struct fib_result res;
- struct rtable *rth;
- int orig_oif;
int err = -ENETUNREACH;
-
- res.tclassid = 0;
- res.fi = NULL;
- res.table = NULL;
-
- orig_oif = fl4->flowi4_oif;
+ struct rtable *rth;
fl4->flowi4_iif = LOOPBACK_IFINDEX;
fl4->flowi4_tos = tos & IPTOS_RT_MASK;
fl4->flowi4_scope = ((tos & RTO_ONLINK) ?
RT_SCOPE_LINK : RT_SCOPE_UNIVERSE);
- rcu_read_lock();
if (fl4->saddr) {
rth = ERR_PTR(-EINVAL);
if (ipv4_is_multicast(fl4->saddr) ||
@@ -2354,15 +2347,15 @@ struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
fl4->daddr = fl4->saddr = htonl(INADDR_LOOPBACK);
dev_out = net->loopback_dev;
fl4->flowi4_oif = LOOPBACK_IFINDEX;
- res.type = RTN_LOCAL;
+ res->type = RTN_LOCAL;
flags |= RTCF_LOCAL;
goto make_route;
}
- err = fib_lookup(net, fl4, &res, 0);
+ err = fib_lookup(net, fl4, res, 0);
if (err) {
- res.fi = NULL;
- res.table = NULL;
+ res->fi = NULL;
+ res->table = NULL;
if (fl4->flowi4_oif &&
(ipv4_is_multicast(fl4->daddr) ||
!netif_index_is_l3_master(net, fl4->flowi4_oif))) {
@@ -2387,17 +2380,17 @@ struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
if (fl4->saddr == 0)
fl4->saddr = inet_select_addr(dev_out, 0,
RT_SCOPE_LINK);
- res.type = RTN_UNICAST;
+ res->type = RTN_UNICAST;
goto make_route;
}
rth = ERR_PTR(err);
goto out;
}
- if (res.type == RTN_LOCAL) {
+ if (res->type == RTN_LOCAL) {
if (!fl4->saddr) {
- if (res.fi->fib_prefsrc)
- fl4->saddr = res.fi->fib_prefsrc;
+ if (res->fi->fib_prefsrc)
+ fl4->saddr = res->fi->fib_prefsrc;
else
fl4->saddr = fl4->daddr;
}
@@ -2410,20 +2403,36 @@ struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
goto make_route;
}
- fib_select_path(net, &res, fl4, skb);
+ fib_select_path(net, res, fl4, skb);
- dev_out = FIB_RES_DEV(res);
+ dev_out = FIB_RES_DEV(*res);
fl4->flowi4_oif = dev_out->ifindex;
make_route:
- rth = __mkroute_output(&res, fl4, orig_oif, dev_out, flags);
+ rth = __mkroute_output(res, fl4, orig_oif, dev_out, flags);
out:
+ return rth;
+}
+
+struct rtable *ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
+ const struct sk_buff *skb)
+{
+ struct fib_result res;
+ struct rtable *rth;
+
+ res.tclassid = 0;
+ res.fi = NULL;
+ res.table = NULL;
+
+ rcu_read_lock();
+ rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
rcu_read_unlock();
+
return rth;
}
-EXPORT_SYMBOL_GPL(__ip_route_output_key_hash);
+EXPORT_SYMBOL_GPL(ip_route_output_key_hash);
static struct dst_entry *ipv4_blackhole_dst_check(struct dst_entry *dst, u32 cookie)
{
--
1.9.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next 2/8] net: ipv4: refactor ip_route_input_noref
2017-05-24 18:19 [PATCH net-next 0/8] net: extend RTM_GETROUTE to return fib result Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash Roopa Prabhu
@ 2017-05-24 18:19 ` Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 3/8] net: ipv4: Remove event arg to rt_fill_info Roopa Prabhu
` (5 subsequent siblings)
7 siblings, 0 replies; 18+ messages in thread
From: Roopa Prabhu @ 2017-05-24 18:19 UTC (permalink / raw)
To: davem; +Cc: netdev, dsahern, nikolay
From: David Ahern <dsahern@gmail.com>
A later patch wants access to the fib result on an input route lookup
with the rcu lock held. Refactor ip_route_input_noref pushing the logic
between rcu_read_lock ... rcu_read_unlock into a new helper that takes
the fib_result as an input arg.
Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
---
include/net/route.h | 3 +++
net/ipv4/route.c | 66 ++++++++++++++++++++++++++++++-----------------------
2 files changed, 40 insertions(+), 29 deletions(-)
diff --git a/include/net/route.h b/include/net/route.h
index 5a92347..8d209ad 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -180,6 +180,9 @@ static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4
int ip_route_input_noref(struct sk_buff *skb, __be32 dst, __be32 src,
u8 tos, struct net_device *devin);
+int ip_route_input_rcu(struct sk_buff *skb, __be32 dst, __be32 src,
+ u8 tos, struct net_device *devin,
+ struct fib_result *res);
static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src,
u8 tos, struct net_device *devin)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index f787208..fe7b765 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1852,9 +1852,9 @@ static int ip_mkroute_input(struct sk_buff *skb,
*/
static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
- u8 tos, struct net_device *dev)
+ u8 tos, struct net_device *dev,
+ struct fib_result *res)
{
- struct fib_result res;
struct in_device *in_dev = __in_dev_get_rcu(dev);
struct ip_tunnel_info *tun_info;
struct flowi4 fl4;
@@ -1884,8 +1884,8 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr))
goto martian_source;
- res.fi = NULL;
- res.table = NULL;
+ res->fi = NULL;
+ res->table = NULL;
if (ipv4_is_lbcast(daddr) || (saddr == 0 && daddr == 0))
goto brd_input;
@@ -1921,17 +1921,17 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
fl4.daddr = daddr;
fl4.saddr = saddr;
fl4.flowi4_uid = sock_net_uid(net, NULL);
- err = fib_lookup(net, &fl4, &res, 0);
+ err = fib_lookup(net, &fl4, res, 0);
if (err != 0) {
if (!IN_DEV_FORWARD(in_dev))
err = -EHOSTUNREACH;
goto no_route;
}
- if (res.type == RTN_BROADCAST)
+ if (res->type == RTN_BROADCAST)
goto brd_input;
- if (res.type == RTN_LOCAL) {
+ if (res->type == RTN_LOCAL) {
err = fib_validate_source(skb, saddr, daddr, tos,
0, dev, in_dev, &itag);
if (err < 0)
@@ -1943,10 +1943,10 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
err = -EHOSTUNREACH;
goto no_route;
}
- if (res.type != RTN_UNICAST)
+ if (res->type != RTN_UNICAST)
goto martian_destination;
- err = ip_mkroute_input(skb, &res, in_dev, daddr, saddr, tos);
+ err = ip_mkroute_input(skb, res, in_dev, daddr, saddr, tos);
out: return err;
brd_input:
@@ -1960,14 +1960,14 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
goto martian_source;
}
flags |= RTCF_BROADCAST;
- res.type = RTN_BROADCAST;
+ res->type = RTN_BROADCAST;
RT_CACHE_STAT_INC(in_brd);
local_input:
do_cache = false;
- if (res.fi) {
+ if (res->fi) {
if (!itag) {
- rth = rcu_dereference(FIB_RES_NH(res).nh_rth_input);
+ rth = rcu_dereference(FIB_RES_NH(*res).nh_rth_input);
if (rt_cache_valid(rth)) {
skb_dst_set_noref(skb, &rth->dst);
err = 0;
@@ -1978,7 +1978,7 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
}
rth = rt_dst_alloc(l3mdev_master_dev_rcu(dev) ? : net->loopback_dev,
- flags | RTCF_LOCAL, res.type,
+ flags | RTCF_LOCAL, res->type,
IN_DEV_CONF_GET(in_dev, NOPOLICY), false, do_cache);
if (!rth)
goto e_nobufs;
@@ -1988,18 +1988,18 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
rth->dst.tclassid = itag;
#endif
rth->rt_is_input = 1;
- if (res.table)
- rth->rt_table_id = res.table->tb_id;
+ if (res->table)
+ rth->rt_table_id = res->table->tb_id;
RT_CACHE_STAT_INC(in_slow_tot);
- if (res.type == RTN_UNREACHABLE) {
+ if (res->type == RTN_UNREACHABLE) {
rth->dst.input= ip_error;
rth->dst.error= -err;
rth->rt_flags &= ~RTCF_LOCAL;
}
if (do_cache) {
- struct fib_nh *nh = &FIB_RES_NH(res);
+ struct fib_nh *nh = &FIB_RES_NH(*res);
rth->dst.lwtstate = lwtstate_get(nh->nh_lwtstate);
if (lwtunnel_input_redirect(rth->dst.lwtstate)) {
@@ -2019,9 +2019,9 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
no_route:
RT_CACHE_STAT_INC(in_no_route);
- res.type = RTN_UNREACHABLE;
- res.fi = NULL;
- res.table = NULL;
+ res->type = RTN_UNREACHABLE;
+ res->fi = NULL;
+ res->table = NULL;
goto local_input;
/*
@@ -2051,11 +2051,22 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
u8 tos, struct net_device *dev)
{
- int res;
+ struct fib_result res;
+ int err;
tos &= IPTOS_RT_MASK;
rcu_read_lock();
+ err = ip_route_input_rcu(skb, daddr, saddr, tos, dev, &res);
+ rcu_read_unlock();
+ return err;
+}
+EXPORT_SYMBOL(ip_route_input_noref);
+
+/* called with rcu_read_lock held */
+int ip_route_input_rcu(struct sk_buff *skb, __be32 daddr, __be32 saddr,
+ u8 tos, struct net_device *dev, struct fib_result *res)
+{
/* Multicast recognition logic is moved from route cache to here.
The problem was that too many Ethernet cards have broken/missing
hardware multicast filters :-( As result the host on multicasting
@@ -2070,6 +2081,7 @@ int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
if (ipv4_is_multicast(daddr)) {
struct in_device *in_dev = __in_dev_get_rcu(dev);
int our = 0;
+ int err = -EINVAL;
if (in_dev)
our = ip_check_mc_rcu(in_dev, daddr, saddr,
@@ -2085,7 +2097,6 @@ int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
ip_hdr(skb)->protocol);
}
- res = -EINVAL;
if (our
#ifdef CONFIG_IP_MROUTE
||
@@ -2093,17 +2104,14 @@ int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
IN_DEV_MFORWARD(in_dev))
#endif
) {
- res = ip_route_input_mc(skb, daddr, saddr,
+ err = ip_route_input_mc(skb, daddr, saddr,
tos, dev, our);
}
- rcu_read_unlock();
- return res;
+ return err;
}
- res = ip_route_input_slow(skb, daddr, saddr, tos, dev);
- rcu_read_unlock();
- return res;
+
+ return ip_route_input_slow(skb, daddr, saddr, tos, dev, res);
}
-EXPORT_SYMBOL(ip_route_input_noref);
/* called with rcu_read_lock() */
static struct rtable *__mkroute_output(const struct fib_result *res,
--
1.9.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next 3/8] net: ipv4: Remove event arg to rt_fill_info
2017-05-24 18:19 [PATCH net-next 0/8] net: extend RTM_GETROUTE to return fib result Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 2/8] net: ipv4: refactor ip_route_input_noref Roopa Prabhu
@ 2017-05-24 18:19 ` Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 4/8] net: ipv4: Convert inet_rtm_getroute to rcu versions of route lookup Roopa Prabhu
` (4 subsequent siblings)
7 siblings, 0 replies; 18+ messages in thread
From: Roopa Prabhu @ 2017-05-24 18:19 UTC (permalink / raw)
To: davem; +Cc: netdev, dsahern, nikolay
From: David Ahern <dsahern@gmail.com>
rt_fill_info has 1 caller with the event set to RTM_NEWROUTE. Given that
remove the arg and use RTM_NEWROUTE directly in rt_fill_info.
Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
---
net/ipv4/route.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index fe7b765..9699e9b 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2536,7 +2536,7 @@ struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4,
static int rt_fill_info(struct net *net, __be32 dst, __be32 src, u32 table_id,
struct flowi4 *fl4, struct sk_buff *skb, u32 portid,
- u32 seq, int event)
+ u32 seq)
{
struct rtable *rt = skb_rtable(skb);
struct rtmsg *r;
@@ -2545,7 +2545,7 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src, u32 table_id,
u32 error;
u32 metrics[RTAX_MAX];
- nlh = nlmsg_put(skb, portid, seq, event, sizeof(*r), 0);
+ nlh = nlmsg_put(skb, portid, seq, RTM_NEWROUTE, sizeof(*r), 0);
if (!nlh)
return -EMSGSIZE;
@@ -2745,8 +2745,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
table_id = rt->rt_table_id;
err = rt_fill_info(net, dst, src, table_id, &fl4, skb,
- NETLINK_CB(in_skb).portid, nlh->nlmsg_seq,
- RTM_NEWROUTE);
+ NETLINK_CB(in_skb).portid, nlh->nlmsg_seq);
if (err < 0)
goto errout_free;
--
1.9.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next 4/8] net: ipv4: Convert inet_rtm_getroute to rcu versions of route lookup
2017-05-24 18:19 [PATCH net-next 0/8] net: extend RTM_GETROUTE to return fib result Roopa Prabhu
` (2 preceding siblings ...)
2017-05-24 18:19 ` [PATCH net-next 3/8] net: ipv4: Remove event arg to rt_fill_info Roopa Prabhu
@ 2017-05-24 18:19 ` Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 5/8] net: ipv4: Save trie prefix to fib lookup result Roopa Prabhu
` (3 subsequent siblings)
7 siblings, 0 replies; 18+ messages in thread
From: Roopa Prabhu @ 2017-05-24 18:19 UTC (permalink / raw)
To: davem; +Cc: netdev, dsahern, nikolay
From: David Ahern <dsahern@gmail.com>
Convert inet_rtm_getroute to use ip_route_input_rcu and
ip_route_output_key_hash_rcu passing the fib_result arg to both.
The rcu lock is held through the creation of the response, so the
rtable/dst does not need to be attached to the skb and is passed
to rt_fill_info directly.
In converting from ip_route_output_key to ip_route_output_key_hash_rcu
the xfrm_lookup_route in ip_route_output_flow is dropped since
flowi4_proto is not set for a route get request.
Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
---
net/ipv4/route.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 9699e9b..6e0bd40 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2404,7 +2404,7 @@ struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
}
/* L3 master device is the loopback for that domain */
- dev_out = l3mdev_master_dev_rcu(FIB_RES_DEV(res)) ? :
+ dev_out = l3mdev_master_dev_rcu(FIB_RES_DEV(*res)) ? :
net->loopback_dev;
fl4->flowi4_oif = dev_out->ifindex;
flags |= RTCF_LOCAL;
@@ -2435,7 +2435,7 @@ struct rtable *ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
res.table = NULL;
rcu_read_lock();
- rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
+ rth = ip_route_output_key_hash_rcu(net, fl4, skb, &res);
rcu_read_unlock();
return rth;
@@ -2534,11 +2534,11 @@ struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4,
}
EXPORT_SYMBOL_GPL(ip_route_output_flow);
+/* called with rcu_read_lock held */
static int rt_fill_info(struct net *net, __be32 dst, __be32 src, u32 table_id,
struct flowi4 *fl4, struct sk_buff *skb, u32 portid,
- u32 seq)
+ u32 seq, struct rtable *rt)
{
- struct rtable *rt = skb_rtable(skb);
struct rtmsg *r;
struct nlmsghdr *nlh;
unsigned long expires = 0;
@@ -2653,6 +2653,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
struct net *net = sock_net(in_skb->sk);
struct rtmsg *rtm;
struct nlattr *tb[RTA_MAX+1];
+ struct fib_result res = {};
struct rtable *rt = NULL;
struct flowi4 fl4;
__be32 dst = 0;
@@ -2709,10 +2710,12 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
fl4.flowi4_mark = mark;
fl4.flowi4_uid = uid;
+ rcu_read_lock();
+
if (iif) {
struct net_device *dev;
- dev = __dev_get_by_index(net, iif);
+ dev = dev_get_by_index_rcu(net, iif);
if (!dev) {
err = -ENODEV;
goto errout_free;
@@ -2721,14 +2724,14 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
skb->protocol = htons(ETH_P_IP);
skb->dev = dev;
skb->mark = mark;
- err = ip_route_input(skb, dst, src, rtm->rtm_tos, dev);
+ err = ip_route_input_rcu(skb, dst, src, rtm->rtm_tos,
+ dev, &res);
rt = skb_rtable(skb);
if (err == 0 && rt->dst.error)
err = -rt->dst.error;
} else {
- rt = ip_route_output_key(net, &fl4);
-
+ rt = ip_route_output_key_hash_rcu(net, &fl4, skb, &res);
err = 0;
if (IS_ERR(rt))
err = PTR_ERR(rt);
@@ -2737,7 +2740,6 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
if (err)
goto errout_free;
- skb_dst_set(skb, &rt->dst);
if (rtm->rtm_flags & RTM_F_NOTIFY)
rt->rt_flags |= RTCF_NOTIFY;
@@ -2745,15 +2747,18 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
table_id = rt->rt_table_id;
err = rt_fill_info(net, dst, src, table_id, &fl4, skb,
- NETLINK_CB(in_skb).portid, nlh->nlmsg_seq);
+ NETLINK_CB(in_skb).portid, nlh->nlmsg_seq, rt);
if (err < 0)
goto errout_free;
+ rcu_read_unlock();
+
err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid);
errout:
return err;
errout_free:
+ rcu_read_unlock();
kfree_skb(skb);
goto errout;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next 5/8] net: ipv4: Save trie prefix to fib lookup result
2017-05-24 18:19 [PATCH net-next 0/8] net: extend RTM_GETROUTE to return fib result Roopa Prabhu
` (3 preceding siblings ...)
2017-05-24 18:19 ` [PATCH net-next 4/8] net: ipv4: Convert inet_rtm_getroute to rcu versions of route lookup Roopa Prabhu
@ 2017-05-24 18:19 ` Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 6/8] net: ipv4: add new RTM_F_FIB_MATCH flag for use with RTM_GETROUTE Roopa Prabhu
` (2 subsequent siblings)
7 siblings, 0 replies; 18+ messages in thread
From: Roopa Prabhu @ 2017-05-24 18:19 UTC (permalink / raw)
To: davem; +Cc: netdev, dsahern, nikolay
From: David Ahern <dsahern@gmail.com>
Prefix is needed for returning matching route spec on get route request.
Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
---
include/net/ip_fib.h | 1 +
net/ipv4/fib_trie.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 42e8b8f..25f5c51 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -136,6 +136,7 @@ struct fib_info {
struct fib_table;
struct fib_result {
+ __be32 prefix;
unsigned char prefixlen;
unsigned char nh_sel;
unsigned char type;
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 6d0f6c79..6e9df7d 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1452,6 +1452,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
if (!(fib_flags & FIB_LOOKUP_NOREF))
atomic_inc(&fi->fib_clntref);
+ res->prefix = htonl(n->key);
res->prefixlen = KEYLENGTH - fa->fa_slen;
res->nh_sel = nhsel;
res->type = fa->fa_type;
--
1.9.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next 6/8] net: ipv4: add new RTM_F_FIB_MATCH flag for use with RTM_GETROUTE
2017-05-24 18:19 [PATCH net-next 0/8] net: extend RTM_GETROUTE to return fib result Roopa Prabhu
` (4 preceding siblings ...)
2017-05-24 18:19 ` [PATCH net-next 5/8] net: ipv4: Save trie prefix to fib lookup result Roopa Prabhu
@ 2017-05-24 18:19 ` Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 7/8] net: ipv4: RTM_GETROUTE: return matched fib result when requested Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 8/8] net: ipv6: " Roopa Prabhu
7 siblings, 0 replies; 18+ messages in thread
From: Roopa Prabhu @ 2017-05-24 18:19 UTC (permalink / raw)
To: davem; +Cc: netdev, dsahern, nikolay
From: Roopa Prabhu <roopa@cumulusnetworks.com>
This flag when specified will return matched fib result in
response to a RTM_GETROUTE query.
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
---
include/uapi/linux/rtnetlink.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index 6487b21..564790e 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -278,6 +278,7 @@ enum rt_scope_t {
#define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
#define RTM_F_PREFIX 0x800 /* Prefix addresses */
#define RTM_F_LOOKUP_TABLE 0x1000 /* set rtm_table to FIB lookup result */
+#define RTM_F_FIB_MATCH 0x2000 /* return full fib lookup match */
/* Reserved table identifiers */
--
1.9.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next 7/8] net: ipv4: RTM_GETROUTE: return matched fib result when requested
2017-05-24 18:19 [PATCH net-next 0/8] net: extend RTM_GETROUTE to return fib result Roopa Prabhu
` (5 preceding siblings ...)
2017-05-24 18:19 ` [PATCH net-next 6/8] net: ipv4: add new RTM_F_FIB_MATCH flag for use with RTM_GETROUTE Roopa Prabhu
@ 2017-05-24 18:19 ` Roopa Prabhu
2017-05-25 2:16 ` David Ahern
2017-05-24 18:19 ` [PATCH net-next 8/8] net: ipv6: " Roopa Prabhu
7 siblings, 1 reply; 18+ messages in thread
From: Roopa Prabhu @ 2017-05-24 18:19 UTC (permalink / raw)
To: davem; +Cc: netdev, dsahern, nikolay
From: Roopa Prabhu <roopa@cumulusnetworks.com>
This patch adds support to return matched fib result when RTM_F_FIB_MATCH
flag is specified in RTM_GETROUTE request. This is useful for user-space
applications/controllers wanting to query a matching route.
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
---
net/ipv4/route.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 6e0bd40..419bdba 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -114,6 +114,8 @@
#include <net/ip_tunnels.h>
#include <net/l3mdev.h>
+#include "fib_lookup.h"
+
#define RT_FL_TOS(oldflp4) \
((oldflp4)->flowi4_tos & (IPTOS_RT_MASK | RTO_ONLINK))
@@ -2746,8 +2748,15 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
if (rtm->rtm_flags & RTM_F_LOOKUP_TABLE)
table_id = rt->rt_table_id;
- err = rt_fill_info(net, dst, src, table_id, &fl4, skb,
- NETLINK_CB(in_skb).portid, nlh->nlmsg_seq, rt);
+ if (rtm->rtm_flags & RTM_F_FIB_MATCH)
+ err = fib_dump_info(skb, NETLINK_CB(in_skb).portid,
+ nlh->nlmsg_seq, RTM_NEWROUTE, table_id,
+ rt->rt_type, res.prefix, res.prefixlen,
+ fl4.flowi4_tos, res.fi, 0);
+ else
+ err = rt_fill_info(net, dst, src, table_id, &fl4, skb,
+ NETLINK_CB(in_skb).portid, nlh->nlmsg_seq,
+ rt);
if (err < 0)
goto errout_free;
--
1.9.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next 8/8] net: ipv6: RTM_GETROUTE: return matched fib result when requested
2017-05-24 18:19 [PATCH net-next 0/8] net: extend RTM_GETROUTE to return fib result Roopa Prabhu
` (6 preceding siblings ...)
2017-05-24 18:19 ` [PATCH net-next 7/8] net: ipv4: RTM_GETROUTE: return matched fib result when requested Roopa Prabhu
@ 2017-05-24 18:19 ` Roopa Prabhu
2017-05-25 2:35 ` David Ahern
7 siblings, 1 reply; 18+ messages in thread
From: Roopa Prabhu @ 2017-05-24 18:19 UTC (permalink / raw)
To: davem; +Cc: netdev, dsahern, nikolay
From: Roopa Prabhu <roopa@cumulusnetworks.com>
This patch adds support to return matched fib result when RTM_F_FIB_MATCH
flag is specified in RTM_GETROUTE request. This is useful for user-space
applications/controllers wanting to query a matching route.
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
---
net/ipv6/route.c | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 80bda31..c4d6da9 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -3612,6 +3612,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
struct rtmsg *rtm;
struct flowi6 fl6;
int err, iif = 0, oif = 0;
+ bool fibmatch;
err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy,
extack);
@@ -3622,6 +3623,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
memset(&fl6, 0, sizeof(fl6));
rtm = nlmsg_data(nlh);
fl6.flowlabel = ip6_make_flowinfo(rtm->rtm_tos, 0);
+ fibmatch = (rtm->rtm_flags & RTM_F_FIB_MATCH) ? true : false;
if (tb[RTA_SRC]) {
if (nla_len(tb[RTA_SRC]) < sizeof(struct in6_addr))
@@ -3667,12 +3669,27 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
if (!ipv6_addr_any(&fl6.saddr))
flags |= RT6_LOOKUP_F_HAS_SADDR;
- rt = (struct rt6_info *)ip6_route_input_lookup(net, dev, &fl6,
- flags);
+ if (!fibmatch)
+ rt = (struct rt6_info *)ip6_route_input_lookup(net, dev,
+ &fl6,
+ flags);
} else {
fl6.flowi6_oif = oif;
- rt = (struct rt6_info *)ip6_route_output(net, NULL, &fl6);
+ if (!fibmatch)
+ rt = (struct rt6_info *)ip6_route_output_flags(net,
+ NULL,
+ &fl6, 0);
+ }
+
+ if (fibmatch) {
+ rt = (struct rt6_info *)ip6_route_lookup(net, &fl6, 0);
+ if (rt->dst.error) {
+ err = rt->dst.error;
+ ip6_rt_put(rt);
+ goto errout;
+ }
+
}
if (rt == net->ipv6.ip6_null_entry) {
@@ -3689,10 +3706,15 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
}
skb_dst_set(skb, &rt->dst);
-
- err = rt6_fill_node(net, skb, rt, &fl6.daddr, &fl6.saddr, iif,
- RTM_NEWROUTE, NETLINK_CB(in_skb).portid,
- nlh->nlmsg_seq, 0);
+ if (fibmatch) {
+ err = rt6_fill_node(net, skb, rt, NULL, NULL, iif,
+ RTM_NEWROUTE, NETLINK_CB(in_skb).portid,
+ nlh->nlmsg_seq, 0);
+ } else {
+ err = rt6_fill_node(net, skb, rt, &fl6.daddr, &fl6.saddr, iif,
+ RTM_NEWROUTE, NETLINK_CB(in_skb).portid,
+ nlh->nlmsg_seq, 0);
+ }
if (err < 0) {
kfree_skb(skb);
goto errout;
--
1.9.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* RE: [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash
2017-05-24 18:19 ` [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash Roopa Prabhu
@ 2017-05-24 19:33 ` Rosen, Rami
2017-05-25 1:10 ` David Ahern
2017-05-25 1:30 ` kbuild test robot
2017-05-25 2:38 ` kbuild test robot
2 siblings, 1 reply; 18+ messages in thread
From: Rosen, Rami @ 2017-05-24 19:33 UTC (permalink / raw)
To: Roopa Prabhu, davem; +Cc: netdev, dsahern, nikolay
Hi, Rupa /David Ahern,
First, thanks for this patch set!
Second, it seems to me that something might be incorrect here.
You have these additions in this patch (1/8):
...
+struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *flp,
+ const struct sk_buff *skb,
+ struct fib_result *res);
...
+struct rtable *ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
+ const struct sk_buff *skb)
+{
+ struct fib_result res;
+ struct rtable *rth;
+
+ res.tclassid = 0;
+ res.fi = NULL;
+ res.table = NULL;
+
+ rcu_read_lock();
+ rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
rcu_read_unlock();
+
return rth;
}
-EXPORT_SYMBOL_GPL(__ip_route_output_key_hash);
+EXPORT_SYMBOL_GPL(ip_route_output_key_hash);
So the third parameter to ip_route_output_key_hash_rcu() should be skb*, and the fourth parameter should be fib_result *. However, you do not pass the skb parameter
when calling ip_route_output_key_hash_rcu() in
ip_route_output_key_hash() (in fact you don't use it at all), and you pass mp_hash as the fourth parameter.
Regards,
Rami Rosen
Intel Corporation
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash
2017-05-24 19:33 ` Rosen, Rami
@ 2017-05-25 1:10 ` David Ahern
2017-05-25 3:05 ` Roopa Prabhu
0 siblings, 1 reply; 18+ messages in thread
From: David Ahern @ 2017-05-25 1:10 UTC (permalink / raw)
To: Rosen, Rami, Roopa Prabhu, davem; +Cc: netdev, nikolay
On 5/24/17 1:33 PM, Rosen, Rami wrote:
> Hi, Rupa /David Ahern,
>
> First, thanks for this patch set!
>
> Second, it seems to me that something might be incorrect here.
>
> You have these additions in this patch (1/8):
> ...
> +struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *flp,
> + const struct sk_buff *skb,
> + struct fib_result *res);
> ...
> +struct rtable *ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
> + const struct sk_buff *skb)
> +{
> + struct fib_result res;
> + struct rtable *rth;
> +
> + res.tclassid = 0;
> + res.fi = NULL;
> + res.table = NULL;
> +
> + rcu_read_lock();
> + rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
> rcu_read_unlock();
> +
> return rth;
> }
> -EXPORT_SYMBOL_GPL(__ip_route_output_key_hash);
> +EXPORT_SYMBOL_GPL(ip_route_output_key_hash);
>
>
> So the third parameter to ip_route_output_key_hash_rcu() should be skb*, and the fourth parameter should be fib_result *. However, you do not pass the skb parameter
> when calling ip_route_output_key_hash_rcu() in
> ip_route_output_key_hash() (in fact you don't use it at all), and you pass mp_hash as the fourth parameter.
Yep, it's a problem with the forward port of the first round of patches.
Roopa: in include/net/route.h, __ip_route_output_key_hash should be
removed as well.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash
2017-05-24 18:19 ` [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash Roopa Prabhu
2017-05-24 19:33 ` Rosen, Rami
@ 2017-05-25 1:30 ` kbuild test robot
2017-05-25 2:38 ` kbuild test robot
2 siblings, 0 replies; 18+ messages in thread
From: kbuild test robot @ 2017-05-25 1:30 UTC (permalink / raw)
To: Roopa Prabhu; +Cc: kbuild-all, davem, netdev, dsahern, nikolay
[-- Attachment #1: Type: text/plain, Size: 5778 bytes --]
Hi David,
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Roopa-Prabhu/net-extend-RTM_GETROUTE-to-return-fib-result/20170525-053253
config: cris-etrax-100lx_v2_defconfig (attached as .config)
compiler: cris-linux-gcc (GCC) 6.2.0
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=cris
Note: the linux-review/Roopa-Prabhu/net-extend-RTM_GETROUTE-to-return-fib-result/20170525-053253 HEAD 083c4ee9e124d0acf29d159ced8a22cb41665a7a builds fine.
It only hurts bisectibility.
All error/warnings (new ones prefixed by >>):
In file included from include/net/route.h:31:0,
from include/net/lwtunnel.h:8,
from include/net/ip_tunnels.h:17,
from include/net/dst_metadata.h:5,
from net/ipv4/route.c:94:
net/ipv4/route.c: In function 'ip_route_output_key_hash_rcu':
>> include/net/ip_fib.h:167:32: error: 'res' is a pointer; did you mean to use '->'?
#define FIB_RES_NH(res) ((res).fi->fib_nh[0])
^
->
>> include/net/ip_fib.h:196:28: note: in expansion of macro 'FIB_RES_NH'
#define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
^~~~~~~~~~
>> net/ipv4/route.c:2399:35: note: in expansion of macro 'FIB_RES_DEV'
dev_out = l3mdev_master_dev_rcu(FIB_RES_DEV(res)) ? :
^~~~~~~~~~~
net/ipv4/route.c: In function 'ip_route_output_key_hash':
>> net/ipv4/route.c:2430:53: error: 'mp_hash' undeclared (first use in this function)
rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
^~~~~~~
net/ipv4/route.c:2430:53: note: each undeclared identifier is reported only once for each function it appears in
>> net/ipv4/route.c:2430:47: error: passing argument 3 of 'ip_route_output_key_hash_rcu' from incompatible pointer type [-Werror=incompatible-pointer-types]
rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
^
net/ipv4/route.c:2249:16: note: expected 'const struct sk_buff *' but argument is of type 'struct fib_result *'
struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
--
In file included from include/net/route.h:31:0,
from include/net/lwtunnel.h:8,
from include/net/ip_tunnels.h:17,
from include/net/dst_metadata.h:5,
from net//ipv4/route.c:94:
net//ipv4/route.c: In function 'ip_route_output_key_hash_rcu':
>> include/net/ip_fib.h:167:32: error: 'res' is a pointer; did you mean to use '->'?
#define FIB_RES_NH(res) ((res).fi->fib_nh[0])
^
->
>> include/net/ip_fib.h:196:28: note: in expansion of macro 'FIB_RES_NH'
#define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
^~~~~~~~~~
net//ipv4/route.c:2399:35: note: in expansion of macro 'FIB_RES_DEV'
dev_out = l3mdev_master_dev_rcu(FIB_RES_DEV(res)) ? :
^~~~~~~~~~~
net//ipv4/route.c: In function 'ip_route_output_key_hash':
net//ipv4/route.c:2430:53: error: 'mp_hash' undeclared (first use in this function)
rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
^~~~~~~
net//ipv4/route.c:2430:53: note: each undeclared identifier is reported only once for each function it appears in
net//ipv4/route.c:2430:47: error: passing argument 3 of 'ip_route_output_key_hash_rcu' from incompatible pointer type [-Werror=incompatible-pointer-types]
rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
^
net//ipv4/route.c:2249:16: note: expected 'const struct sk_buff *' but argument is of type 'struct fib_result *'
struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/mp_hash +2430 net/ipv4/route.c
2393 fl4->saddr = res->fi->fib_prefsrc;
2394 else
2395 fl4->saddr = fl4->daddr;
2396 }
2397
2398 /* L3 master device is the loopback for that domain */
> 2399 dev_out = l3mdev_master_dev_rcu(FIB_RES_DEV(res)) ? :
2400 net->loopback_dev;
2401 fl4->flowi4_oif = dev_out->ifindex;
2402 flags |= RTCF_LOCAL;
2403 goto make_route;
2404 }
2405
2406 fib_select_path(net, res, fl4, skb);
2407
2408 dev_out = FIB_RES_DEV(*res);
2409 fl4->flowi4_oif = dev_out->ifindex;
2410
2411
2412 make_route:
2413 rth = __mkroute_output(res, fl4, orig_oif, dev_out, flags);
2414
2415 out:
2416 return rth;
2417 }
2418
2419 struct rtable *ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
2420 const struct sk_buff *skb)
2421 {
2422 struct fib_result res;
2423 struct rtable *rth;
2424
2425 res.tclassid = 0;
2426 res.fi = NULL;
2427 res.table = NULL;
2428
2429 rcu_read_lock();
> 2430 rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
2431 rcu_read_unlock();
2432
2433 return rth;
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 8682 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next 7/8] net: ipv4: RTM_GETROUTE: return matched fib result when requested
2017-05-24 18:19 ` [PATCH net-next 7/8] net: ipv4: RTM_GETROUTE: return matched fib result when requested Roopa Prabhu
@ 2017-05-25 2:16 ` David Ahern
0 siblings, 0 replies; 18+ messages in thread
From: David Ahern @ 2017-05-25 2:16 UTC (permalink / raw)
To: Roopa Prabhu, davem; +Cc: netdev, nikolay
On 5/24/17 12:19 PM, Roopa Prabhu wrote:
> @@ -2746,8 +2748,15 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
> if (rtm->rtm_flags & RTM_F_LOOKUP_TABLE)
> table_id = rt->rt_table_id;
>
> - err = rt_fill_info(net, dst, src, table_id, &fl4, skb,
> - NETLINK_CB(in_skb).portid, nlh->nlmsg_seq, rt);
> + if (rtm->rtm_flags & RTM_F_FIB_MATCH)
> + err = fib_dump_info(skb, NETLINK_CB(in_skb).portid,
> + nlh->nlmsg_seq, RTM_NEWROUTE, table_id,
> + rt->rt_type, res.prefix, res.prefixlen,
> + fl4.flowi4_tos, res.fi, 0);
I like this part -- much simpler than duplicating the attributes which
is where I was headed.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next 8/8] net: ipv6: RTM_GETROUTE: return matched fib result when requested
2017-05-24 18:19 ` [PATCH net-next 8/8] net: ipv6: " Roopa Prabhu
@ 2017-05-25 2:35 ` David Ahern
2017-05-25 15:54 ` Roopa Prabhu
0 siblings, 1 reply; 18+ messages in thread
From: David Ahern @ 2017-05-25 2:35 UTC (permalink / raw)
To: Roopa Prabhu, davem; +Cc: netdev, nikolay
Since you have to do a v2 ...
On 5/24/17 12:19 PM, Roopa Prabhu wrote:
> @@ -3622,6 +3623,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
> memset(&fl6, 0, sizeof(fl6));
> rtm = nlmsg_data(nlh);
> fl6.flowlabel = ip6_make_flowinfo(rtm->rtm_tos, 0);
> + fibmatch = (rtm->rtm_flags & RTM_F_FIB_MATCH) ? true : false;
this is typically done as !!(rtm->rtm_flags & RTM_F_FIB_MATCH)
>
> if (tb[RTA_SRC]) {
> if (nla_len(tb[RTA_SRC]) < sizeof(struct in6_addr))
> @@ -3667,12 +3669,27 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
> if (!ipv6_addr_any(&fl6.saddr))
> flags |= RT6_LOOKUP_F_HAS_SADDR;
>
> - rt = (struct rt6_info *)ip6_route_input_lookup(net, dev, &fl6,
> - flags);
> + if (!fibmatch)
> + rt = (struct rt6_info *)ip6_route_input_lookup(net, dev,
> + &fl6,
> + flags);
> } else {
> fl6.flowi6_oif = oif;
>
> - rt = (struct rt6_info *)ip6_route_output(net, NULL, &fl6);
> + if (!fibmatch)
> + rt = (struct rt6_info *)ip6_route_output_flags(net,
> + NULL,
> + &fl6, 0);
> + }
> +
> + if (fibmatch) {
> + rt = (struct rt6_info *)ip6_route_lookup(net, &fl6, 0);
> + if (rt->dst.error) {
> + err = rt->dst.error;
> + ip6_rt_put(rt);
> + goto errout;
> + }
> +
I'd prefer to see the typecasts go away and use container_of to go from
dst_entry to rt6_info. I realize some of this is movement of existing
code, but better to clean up as we go.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash
2017-05-24 18:19 ` [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash Roopa Prabhu
2017-05-24 19:33 ` Rosen, Rami
2017-05-25 1:30 ` kbuild test robot
@ 2017-05-25 2:38 ` kbuild test robot
2 siblings, 0 replies; 18+ messages in thread
From: kbuild test robot @ 2017-05-25 2:38 UTC (permalink / raw)
To: Roopa Prabhu; +Cc: kbuild-all, davem, netdev, dsahern, nikolay
[-- Attachment #1: Type: text/plain, Size: 6359 bytes --]
Hi David,
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Roopa-Prabhu/net-extend-RTM_GETROUTE-to-return-fib-result/20170525-053253
config: openrisc-or1ksim_defconfig (attached as .config)
compiler: or1k-linux-gcc (GCC) 5.4.0
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=openrisc
Note: the linux-review/Roopa-Prabhu/net-extend-RTM_GETROUTE-to-return-fib-result/20170525-053253 HEAD 083c4ee9e124d0acf29d159ced8a22cb41665a7a builds fine.
It only hurts bisectibility.
All errors (new ones prefixed by >>):
In file included from include/net/route.h:31:0,
from include/net/lwtunnel.h:8,
from include/net/ip_tunnels.h:17,
from include/net/dst_metadata.h:5,
from net/ipv4/route.c:94:
net/ipv4/route.c: In function 'ip_route_output_key_hash_rcu':
>> include/net/ip_fib.h:167:32: error: request for member 'fi' in something not a structure or union
#define FIB_RES_NH(res) ((res).fi->fib_nh[0])
^
include/net/ip_fib.h:196:28: note: in expansion of macro 'FIB_RES_NH'
#define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
^
net/ipv4/route.c:2399:35: note: in expansion of macro 'FIB_RES_DEV'
dev_out = l3mdev_master_dev_rcu(FIB_RES_DEV(res)) ? :
^
net/ipv4/route.c: In function 'ip_route_output_key_hash':
net/ipv4/route.c:2430:53: error: 'mp_hash' undeclared (first use in this function)
rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
^
net/ipv4/route.c:2430:53: note: each undeclared identifier is reported only once for each function it appears in
net/ipv4/route.c:2430:47: error: passing argument 3 of 'ip_route_output_key_hash_rcu' from incompatible pointer type [-Werror=incompatible-pointer-types]
rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
^
net/ipv4/route.c:2249:16: note: expected 'const struct sk_buff *' but argument is of type 'struct fib_result *'
struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
^
cc1: some warnings being treated as errors
--
In file included from include/net/route.h:31:0,
from include/net/lwtunnel.h:8,
from include/net/ip_tunnels.h:17,
from include/net/dst_metadata.h:5,
from net//ipv4/route.c:94:
net//ipv4/route.c: In function 'ip_route_output_key_hash_rcu':
>> include/net/ip_fib.h:167:32: error: request for member 'fi' in something not a structure or union
#define FIB_RES_NH(res) ((res).fi->fib_nh[0])
^
include/net/ip_fib.h:196:28: note: in expansion of macro 'FIB_RES_NH'
#define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
^
net//ipv4/route.c:2399:35: note: in expansion of macro 'FIB_RES_DEV'
dev_out = l3mdev_master_dev_rcu(FIB_RES_DEV(res)) ? :
^
net//ipv4/route.c: In function 'ip_route_output_key_hash':
net//ipv4/route.c:2430:53: error: 'mp_hash' undeclared (first use in this function)
rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
^
net//ipv4/route.c:2430:53: note: each undeclared identifier is reported only once for each function it appears in
net//ipv4/route.c:2430:47: error: passing argument 3 of 'ip_route_output_key_hash_rcu' from incompatible pointer type [-Werror=incompatible-pointer-types]
rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
^
net//ipv4/route.c:2249:16: note: expected 'const struct sk_buff *' but argument is of type 'struct fib_result *'
struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
^
cc1: some warnings being treated as errors
vim +/fi +167 include/net/ip_fib.h
5f300893f Thomas Graf 2006-11-09 151 u32 fl_mark;
246955fe4 Robert Olsson 2005-06-20 152 unsigned char fl_tos;
246955fe4 Robert Olsson 2005-06-20 153 unsigned char fl_scope;
246955fe4 Robert Olsson 2005-06-20 154 unsigned char tb_id_in;
246955fe4 Robert Olsson 2005-06-20 155
246955fe4 Robert Olsson 2005-06-20 156 unsigned char tb_id; /* Results */
246955fe4 Robert Olsson 2005-06-20 157 unsigned char prefixlen;
246955fe4 Robert Olsson 2005-06-20 158 unsigned char nh_sel;
246955fe4 Robert Olsson 2005-06-20 159 unsigned char type;
246955fe4 Robert Olsson 2005-06-20 160 unsigned char scope;
246955fe4 Robert Olsson 2005-06-20 161 int err;
246955fe4 Robert Olsson 2005-06-20 162 };
^1da177e4 Linus Torvalds 2005-04-16 163
^1da177e4 Linus Torvalds 2005-04-16 164 #ifdef CONFIG_IP_ROUTE_MULTIPATH
^1da177e4 Linus Torvalds 2005-04-16 165 #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
^1da177e4 Linus Torvalds 2005-04-16 166 #else /* CONFIG_IP_ROUTE_MULTIPATH */
^1da177e4 Linus Torvalds 2005-04-16 @167 #define FIB_RES_NH(res) ((res).fi->fib_nh[0])
5b9e12dbf Denis V. Lunev 2013-03-13 168 #endif /* CONFIG_IP_ROUTE_MULTIPATH */
^1da177e4 Linus Torvalds 2005-04-16 169
5b9e12dbf Denis V. Lunev 2013-03-13 170 #ifdef CONFIG_IP_MULTIPLE_TABLES
93456b6d7 Denis V. Lunev 2008-01-10 171 #define FIB_TABLE_HASHSZ 256
5b9e12dbf Denis V. Lunev 2013-03-13 172 #else
5b9e12dbf Denis V. Lunev 2013-03-13 173 #define FIB_TABLE_HASHSZ 2
5b9e12dbf Denis V. Lunev 2013-03-13 174 #endif
^1da177e4 Linus Torvalds 2005-04-16 175
:::::: The code at line 167 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2
:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 7551 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash
2017-05-25 1:10 ` David Ahern
@ 2017-05-25 3:05 ` Roopa Prabhu
0 siblings, 0 replies; 18+ messages in thread
From: Roopa Prabhu @ 2017-05-25 3:05 UTC (permalink / raw)
To: David Ahern; +Cc: Rosen, Rami, davem, netdev, nikolay
On Wed, May 24, 2017 at 6:10 PM, David Ahern <dsahern@gmail.com> wrote:
> On 5/24/17 1:33 PM, Rosen, Rami wrote:
>> Hi, Rupa /David Ahern,
>>
>> First, thanks for this patch set!
>>
>> Second, it seems to me that something might be incorrect here.
>>
>> You have these additions in this patch (1/8):
>> ...
>> +struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *flp,
>> + const struct sk_buff *skb,
>> + struct fib_result *res);
>> ...
>> +struct rtable *ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
>> + const struct sk_buff *skb)
>> +{
>> + struct fib_result res;
>> + struct rtable *rth;
>> +
>> + res.tclassid = 0;
>> + res.fi = NULL;
>> + res.table = NULL;
>> +
>> + rcu_read_lock();
>> + rth = ip_route_output_key_hash_rcu(net, fl4, &res, mp_hash);
>> rcu_read_unlock();
>> +
>> return rth;
>> }
>> -EXPORT_SYMBOL_GPL(__ip_route_output_key_hash);
>> +EXPORT_SYMBOL_GPL(ip_route_output_key_hash);
>>
>>
>> So the third parameter to ip_route_output_key_hash_rcu() should be skb*, and the fourth parameter should be fib_result *. However, you do not pass the skb parameter
>> when calling ip_route_output_key_hash_rcu() in
>> ip_route_output_key_hash() (in fact you don't use it at all), and you pass mp_hash as the fourth parameter.
>
> Yep, it's a problem with the forward port of the first round of patches.
yep,
>
> Roopa: in include/net/route.h, __ip_route_output_key_hash should be
> removed as well.
ack, thanks Rami and david.
will fix it in v2.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next 8/8] net: ipv6: RTM_GETROUTE: return matched fib result when requested
2017-05-25 2:35 ` David Ahern
@ 2017-05-25 15:54 ` Roopa Prabhu
2017-05-25 16:00 ` David Ahern
0 siblings, 1 reply; 18+ messages in thread
From: Roopa Prabhu @ 2017-05-25 15:54 UTC (permalink / raw)
To: David Ahern; +Cc: davem, netdev, Nikolay Aleksandrov
On Wed, May 24, 2017 at 7:35 PM, David Ahern <dsahern@gmail.com> wrote:
> Since you have to do a v2 ...
>
> On 5/24/17 12:19 PM, Roopa Prabhu wrote:
>> @@ -3622,6 +3623,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
>> memset(&fl6, 0, sizeof(fl6));
>> rtm = nlmsg_data(nlh);
>> fl6.flowlabel = ip6_make_flowinfo(rtm->rtm_tos, 0);
>> + fibmatch = (rtm->rtm_flags & RTM_F_FIB_MATCH) ? true : false;
> this is typically done as !!(rtm->rtm_flags & RTM_F_FIB_MATCH)
ack,
>>
>> if (tb[RTA_SRC]) {
>> if (nla_len(tb[RTA_SRC]) < sizeof(struct in6_addr))
>> @@ -3667,12 +3669,27 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
>> if (!ipv6_addr_any(&fl6.saddr))
>> flags |= RT6_LOOKUP_F_HAS_SADDR;
>>
>> - rt = (struct rt6_info *)ip6_route_input_lookup(net, dev, &fl6,
>> - flags);
>> + if (!fibmatch)
>> + rt = (struct rt6_info *)ip6_route_input_lookup(net, dev,
>> + &fl6,
>> + flags);
>> } else {
>> fl6.flowi6_oif = oif;
>>
>> - rt = (struct rt6_info *)ip6_route_output(net, NULL, &fl6);
>> + if (!fibmatch)
>> + rt = (struct rt6_info *)ip6_route_output_flags(net,
>> + NULL,
>> + &fl6, 0);
>> + }
>> +
>> + if (fibmatch) {
>> + rt = (struct rt6_info *)ip6_route_lookup(net, &fl6, 0);
>> + if (rt->dst.error) {
>> + err = rt->dst.error;
>> + ip6_rt_put(rt);
>> + goto errout;
>> + }
>> +
>
> I'd prefer to see the typecasts go away and use container_of to go from
> dst_entry to rt6_info. I realize some of this is movement of existing
> code, but better to clean up as we go.
>
ack. But that is pretty much all of ipv6 code. so, seems better done
with an incremental cleanup patch.
thanks for the review.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next 8/8] net: ipv6: RTM_GETROUTE: return matched fib result when requested
2017-05-25 15:54 ` Roopa Prabhu
@ 2017-05-25 16:00 ` David Ahern
0 siblings, 0 replies; 18+ messages in thread
From: David Ahern @ 2017-05-25 16:00 UTC (permalink / raw)
To: Roopa Prabhu; +Cc: davem, netdev, Nikolay Aleksandrov
> On May 25, 2017, at 9:54 AM, Roopa Prabhu <roopa@cumulusnetworks.com> wrote:
>
>>
>> I'd prefer to see the typecasts go away and use container_of to go from
>> dst_entry to rt6_info. I realize some of this is movement of existing
>> code, but better to clean up as we go.
>>
>
> ack. But that is pretty much all of ipv6 code. so, seems better done
> with an incremental cleanup patch.
>
For the rest of the ipv6 code, yes. We can do the right thing now for new code and changes to existing code.
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2017-05-25 16:00 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-24 18:19 [PATCH net-next 0/8] net: extend RTM_GETROUTE to return fib result Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 1/8] net: ipv4: refactor __ip_route_output_key_hash Roopa Prabhu
2017-05-24 19:33 ` Rosen, Rami
2017-05-25 1:10 ` David Ahern
2017-05-25 3:05 ` Roopa Prabhu
2017-05-25 1:30 ` kbuild test robot
2017-05-25 2:38 ` kbuild test robot
2017-05-24 18:19 ` [PATCH net-next 2/8] net: ipv4: refactor ip_route_input_noref Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 3/8] net: ipv4: Remove event arg to rt_fill_info Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 4/8] net: ipv4: Convert inet_rtm_getroute to rcu versions of route lookup Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 5/8] net: ipv4: Save trie prefix to fib lookup result Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 6/8] net: ipv4: add new RTM_F_FIB_MATCH flag for use with RTM_GETROUTE Roopa Prabhu
2017-05-24 18:19 ` [PATCH net-next 7/8] net: ipv4: RTM_GETROUTE: return matched fib result when requested Roopa Prabhu
2017-05-25 2:16 ` David Ahern
2017-05-24 18:19 ` [PATCH net-next 8/8] net: ipv6: " Roopa Prabhu
2017-05-25 2:35 ` David Ahern
2017-05-25 15:54 ` Roopa Prabhu
2017-05-25 16:00 ` David Ahern
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.