Skip to content

Commit c36ba66

Browse files
David Aherndavem330
authored andcommitted
net: Allow user to get table id from route lookup
rt_fill_info which is called for 'route get' requests hardcodes the table id as RT_TABLE_MAIN which is not correct when multiple tables are used. Use the newly added table id in the rtable to send back the correct table similar to what is done for IPv6. To maintain current ABI a new request flag, RTM_F_LOOKUP_TABLE, is added to indicate the actual table is wanted versus the hardcoded response. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b7503e0 commit c36ba66

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

include/uapi/linux/rtnetlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ enum rt_scope_t {
270270
#define RTM_F_CLONED 0x200 /* This route is cloned */
271271
#define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
272272
#define RTM_F_PREFIX 0x800 /* Prefix addresses */
273+
#define RTM_F_LOOKUP_TABLE 0x1000 /* set rtm_table to FIB lookup result */
273274

274275
/* Reserved table identifiers */
275276

net/ipv4/route.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,7 @@ struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4,
23052305
}
23062306
EXPORT_SYMBOL_GPL(ip_route_output_flow);
23072307

2308-
static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
2308+
static int rt_fill_info(struct net *net, __be32 dst, __be32 src, u32 table_id,
23092309
struct flowi4 *fl4, struct sk_buff *skb, u32 portid,
23102310
u32 seq, int event, int nowait, unsigned int flags)
23112311
{
@@ -2325,8 +2325,8 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
23252325
r->rtm_dst_len = 32;
23262326
r->rtm_src_len = 0;
23272327
r->rtm_tos = fl4->flowi4_tos;
2328-
r->rtm_table = RT_TABLE_MAIN;
2329-
if (nla_put_u32(skb, RTA_TABLE, RT_TABLE_MAIN))
2328+
r->rtm_table = table_id;
2329+
if (nla_put_u32(skb, RTA_TABLE, table_id))
23302330
goto nla_put_failure;
23312331
r->rtm_type = rt->rt_type;
23322332
r->rtm_scope = RT_SCOPE_UNIVERSE;
@@ -2431,6 +2431,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh)
24312431
int err;
24322432
int mark;
24332433
struct sk_buff *skb;
2434+
u32 table_id = RT_TABLE_MAIN;
24342435

24352436
err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv4_policy);
24362437
if (err < 0)
@@ -2500,7 +2501,10 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh)
25002501
if (rtm->rtm_flags & RTM_F_NOTIFY)
25012502
rt->rt_flags |= RTCF_NOTIFY;
25022503

2503-
err = rt_fill_info(net, dst, src, &fl4, skb,
2504+
if (rtm->rtm_flags & RTM_F_LOOKUP_TABLE)
2505+
table_id = rt->rt_table_id;
2506+
2507+
err = rt_fill_info(net, dst, src, table_id, &fl4, skb,
25042508
NETLINK_CB(in_skb).portid, nlh->nlmsg_seq,
25052509
RTM_NEWROUTE, 0, 0);
25062510
if (err < 0)

0 commit comments

Comments
 (0)