Skip to content

Commit b9b33e7

Browse files
Paolo Abenidavem330
authored andcommitted
ipv6: keep track of routes using src
Use a per namespace counter, increment it on successful creation of any route using the source address, decrement it on deletion of such routes. This allows us to check easily if the routing decision in the current namespace depends on the packet source. Will be used by the next patch. Suggested-by: David Ahern <dsahern@gmail.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Reviewed-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1f8ac57 commit b9b33e7

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

include/net/ip6_fib.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,32 @@ struct fib6_gc_args {
9090

9191
#ifndef CONFIG_IPV6_SUBTREES
9292
#define FIB6_SUBTREE(fn) NULL
93+
94+
static inline bool fib6_routes_require_src(const struct net *net)
95+
{
96+
return false;
97+
}
98+
99+
static inline void fib6_routes_require_src_inc(struct net *net) {}
100+
static inline void fib6_routes_require_src_dec(struct net *net) {}
101+
93102
#else
103+
104+
static inline bool fib6_routes_require_src(const struct net *net)
105+
{
106+
return net->ipv6.fib6_routes_require_src > 0;
107+
}
108+
109+
static inline void fib6_routes_require_src_inc(struct net *net)
110+
{
111+
net->ipv6.fib6_routes_require_src++;
112+
}
113+
114+
static inline void fib6_routes_require_src_dec(struct net *net)
115+
{
116+
net->ipv6.fib6_routes_require_src--;
117+
}
118+
94119
#define FIB6_SUBTREE(fn) (rcu_dereference_protected((fn)->subtree, 1))
95120
#endif
96121

@@ -212,6 +237,11 @@ static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
212237
return ((struct rt6_info *)dst)->rt6i_idev;
213238
}
214239

240+
static inline bool fib6_requires_src(const struct fib6_info *rt)
241+
{
242+
return rt->fib6_src.plen > 0;
243+
}
244+
215245
static inline void fib6_clean_expires(struct fib6_info *f6i)
216246
{
217247
f6i->fib6_flags &= ~RTF_EXPIRES;

include/net/netns/ipv6.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ struct netns_ipv6 {
8383
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
8484
unsigned int fib6_rules_require_fldissect;
8585
bool fib6_has_custom_rules;
86+
#ifdef CONFIG_IPV6_SUBTREES
87+
unsigned int fib6_routes_require_src;
88+
#endif
8689
struct rt6_info *ip6_prohibit_entry;
8790
struct rt6_info *ip6_blk_hole_entry;
8891
struct fib6_table *fib6_local_tbl;

net/ipv6/ip6_fib.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,8 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt,
14611461
}
14621462
#endif
14631463
goto failure;
1464+
} else if (fib6_requires_src(rt)) {
1465+
fib6_routes_require_src_inc(info->nl_net);
14641466
}
14651467
return err;
14661468

@@ -1933,6 +1935,8 @@ int fib6_del(struct fib6_info *rt, struct nl_info *info)
19331935
struct fib6_info *cur = rcu_dereference_protected(*rtp,
19341936
lockdep_is_held(&table->tb6_lock));
19351937
if (rt == cur) {
1938+
if (fib6_requires_src(cur))
1939+
fib6_routes_require_src_dec(info->nl_net);
19361940
fib6_del_route(table, fn, rtp, info);
19371941
return 0;
19381942
}

net/ipv6/route.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6199,6 +6199,9 @@ static int __net_init ip6_route_net_init(struct net *net)
61996199
dst_init_metrics(&net->ipv6.ip6_blk_hole_entry->dst,
62006200
ip6_template_metrics, true);
62016201
INIT_LIST_HEAD(&net->ipv6.ip6_blk_hole_entry->rt6i_uncached);
6202+
#ifdef CONFIG_IPV6_SUBTREES
6203+
net->ipv6.fib6_routes_require_src = 0;
6204+
#endif
62026205
#endif
62036206

62046207
net->ipv6.sysctl.flush_delay = 0;

0 commit comments

Comments
 (0)