Skip to content

Commit 15be405

Browse files
David Aherndavem330
authored andcommitted
net: Add inet_addr lookup by table
Currently inet_addr_type and inet_dev_addr_type expect local addresses to be in the local table. With the VRF device local routes for devices associated with a VRF will be in the table associated with the VRF. Provide an alternate inet_addr lookup to use a specific table rather than defaulting to the local table. Signed-off-by: Shrijeet Mukherjee <[email protected]> Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9a24abf commit 15be405

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

include/net/route.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ void ipv4_sk_redirect(struct sk_buff *skb, struct sock *sk);
189189
void ip_rt_send_redirect(struct sk_buff *skb);
190190

191191
unsigned int inet_addr_type(struct net *net, __be32 addr);
192+
unsigned int inet_addr_type_table(struct net *net, __be32 addr, int tb_id);
192193
unsigned int inet_dev_addr_type(struct net *net, const struct net_device *dev,
193194
__be32 addr);
194195
void ip_rt_multicast_event(struct in_device *);

net/ipv4/fib_frontend.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ void fib_flush_external(struct net *net)
212212
*/
213213
static inline unsigned int __inet_dev_addr_type(struct net *net,
214214
const struct net_device *dev,
215-
__be32 addr)
215+
__be32 addr, int tb_id)
216216
{
217217
struct flowi4 fl4 = { .daddr = addr };
218218
struct fib_result res;
219219
unsigned int ret = RTN_BROADCAST;
220-
struct fib_table *local_table;
220+
struct fib_table *table;
221221

222222
if (ipv4_is_zeronet(addr) || ipv4_is_lbcast(addr))
223223
return RTN_BROADCAST;
@@ -226,10 +226,10 @@ static inline unsigned int __inet_dev_addr_type(struct net *net,
226226

227227
rcu_read_lock();
228228

229-
local_table = fib_get_table(net, RT_TABLE_LOCAL);
230-
if (local_table) {
229+
table = fib_get_table(net, tb_id);
230+
if (table) {
231231
ret = RTN_UNICAST;
232-
if (!fib_table_lookup(local_table, &fl4, &res, FIB_LOOKUP_NOREF)) {
232+
if (!fib_table_lookup(table, &fl4, &res, FIB_LOOKUP_NOREF)) {
233233
if (!dev || dev == res.fi->fib_dev)
234234
ret = res.type;
235235
}
@@ -239,16 +239,24 @@ static inline unsigned int __inet_dev_addr_type(struct net *net,
239239
return ret;
240240
}
241241

242+
unsigned int inet_addr_type_table(struct net *net, __be32 addr, int tb_id)
243+
{
244+
return __inet_dev_addr_type(net, NULL, addr, tb_id);
245+
}
246+
EXPORT_SYMBOL(inet_addr_type_table);
247+
242248
unsigned int inet_addr_type(struct net *net, __be32 addr)
243249
{
244-
return __inet_dev_addr_type(net, NULL, addr);
250+
return __inet_dev_addr_type(net, NULL, addr, RT_TABLE_LOCAL);
245251
}
246252
EXPORT_SYMBOL(inet_addr_type);
247253

248254
unsigned int inet_dev_addr_type(struct net *net, const struct net_device *dev,
249255
__be32 addr)
250256
{
251-
return __inet_dev_addr_type(net, dev, addr);
257+
int rt_table = vrf_dev_table(dev) ? : RT_TABLE_LOCAL;
258+
259+
return __inet_dev_addr_type(net, dev, addr, rt_table);
252260
}
253261
EXPORT_SYMBOL(inet_dev_addr_type);
254262

0 commit comments

Comments
 (0)