Skip to content

Commit 9226976

Browse files
committed
Merge branch 'RTM_GETROUTE--return-fib-result'
Roopa Prabhu says: ==================== net: extend RTM_GETROUTE to return fib result 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 v2: - pick up new forward port of patch-01 from david - inet6_rtm_getroute: use container_of for rt6_info to dst conversion ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 5dafc87 + 18c3a61 commit 9226976

File tree

7 files changed

+131
-74
lines changed

7 files changed

+131
-74
lines changed

include/net/ip_fib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct fib_rule;
136136

137137
struct fib_table;
138138
struct fib_result {
139+
__be32 prefix;
139140
unsigned char prefixlen;
140141
unsigned char nh_sel;
141142
unsigned char type;

include/net/route.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,16 @@ struct in_device;
113113
int ip_rt_init(void);
114114
void rt_cache_flush(struct net *net);
115115
void rt_flush_dev(struct net_device *dev);
116-
struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *flp,
117-
const struct sk_buff *skb);
116+
struct rtable *ip_route_output_key_hash(struct net *net, struct flowi4 *flp,
117+
const struct sk_buff *skb);
118+
struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *flp,
119+
struct fib_result *res,
120+
const struct sk_buff *skb);
118121

119122
static inline struct rtable *__ip_route_output_key(struct net *net,
120123
struct flowi4 *flp)
121124
{
122-
return __ip_route_output_key_hash(net, flp, NULL);
125+
return ip_route_output_key_hash(net, flp, NULL);
123126
}
124127

125128
struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
@@ -175,6 +178,9 @@ static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4
175178

176179
int ip_route_input_noref(struct sk_buff *skb, __be32 dst, __be32 src,
177180
u8 tos, struct net_device *devin);
181+
int ip_route_input_rcu(struct sk_buff *skb, __be32 dst, __be32 src,
182+
u8 tos, struct net_device *devin,
183+
struct fib_result *res);
178184

179185
static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src,
180186
u8 tos, struct net_device *devin)

include/uapi/linux/rtnetlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ enum rt_scope_t {
278278
#define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
279279
#define RTM_F_PREFIX 0x800 /* Prefix addresses */
280280
#define RTM_F_LOOKUP_TABLE 0x1000 /* set rtm_table to FIB lookup result */
281+
#define RTM_F_FIB_MATCH 0x2000 /* return full fib lookup match */
281282

282283
/* Reserved table identifiers */
283284

net/ipv4/fib_trie.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
14521452
if (!(fib_flags & FIB_LOOKUP_NOREF))
14531453
atomic_inc(&fi->fib_clntref);
14541454

1455+
res->prefix = htonl(n->key);
14551456
res->prefixlen = KEYLENGTH - fa->fa_slen;
14561457
res->nh_sel = nhsel;
14571458
res->type = fa->fa_type;

net/ipv4/icmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ static struct rtable *icmp_route_lookup(struct net *net,
489489
fl4->flowi4_oif = l3mdev_master_ifindex(skb_dst(skb_in)->dev);
490490

491491
security_skb_classify_flow(skb_in, flowi4_to_flowi(fl4));
492-
rt = __ip_route_output_key_hash(net, fl4, skb_in);
492+
rt = ip_route_output_key_hash(net, fl4, skb_in);
493493
if (IS_ERR(rt))
494494
return rt;
495495

0 commit comments

Comments
 (0)