Skip to content

Commit

Permalink
[NETNS][IPV6] rt6_info - move rt6_info structure inside the namespace
Browse files Browse the repository at this point in the history
The rt6_info structures are moved inside the network namespace
structure. All references to these structures are now relative to the
initial network namespace.

Signed-off-by: Daniel Lezcano <[email protected]>
Signed-off-by: Benjamin Thery <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Daniel Lezcano authored and davem330 committed Mar 4, 2008
1 parent bdb3289 commit 8ed6778
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 108 deletions.
3 changes: 2 additions & 1 deletion include/net/ip6_fib.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ struct fib6_table {
#define RT6_TABLE_LOCAL RT6_TABLE_MAIN
#endif

typedef struct rt6_info *(*pol_lookup_t)(struct fib6_table *,
typedef struct rt6_info *(*pol_lookup_t)(struct net *,
struct fib6_table *,
struct flowi *, int);

/*
Expand Down
3 changes: 3 additions & 0 deletions include/net/netns/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ struct netns_ipv6 {
struct xt_table *ip6table_mangle;
struct xt_table *ip6table_raw;
#endif
struct rt6_info *ip6_null_entry;
struct rt6_statistics *rt6_stats;
struct timer_list *ip6_fib_timer;
struct hlist_head *fib_table_hash;
struct fib6_table *fib6_main_tbl;
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
struct rt6_info *ip6_prohibit_entry;
struct rt6_info *ip6_blk_hole_entry;
struct fib6_table *fib6_local_tbl;
struct fib_rules_ops *fib6_rules_ops;
#endif
Expand Down
9 changes: 0 additions & 9 deletions net/ipv6/addrconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -4301,15 +4301,6 @@ int __init addrconf_init(void)
if (err)
goto errlo;

ip6_null_entry->u.dst.dev = init_net.loopback_dev;
ip6_null_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev);
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
ip6_prohibit_entry->u.dst.dev = init_net.loopback_dev;
ip6_prohibit_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev);
ip6_blk_hole_entry->u.dst.dev = init_net.loopback_dev;
ip6_blk_hole_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev);
#endif

register_netdevice_notifier(&ipv6_dev_notf);

addrconf_verify(0);
Expand Down
17 changes: 9 additions & 8 deletions net/ipv6/fib6_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,38 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi *fl,
if (arg.result)
return arg.result;

dst_hold(&ip6_null_entry->u.dst);
return &ip6_null_entry->u.dst;
dst_hold(&net->ipv6.ip6_null_entry->u.dst);
return &net->ipv6.ip6_null_entry->u.dst;
}

static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
int flags, struct fib_lookup_arg *arg)
{
struct rt6_info *rt = NULL;
struct fib6_table *table;
struct net *net = rule->fr_net;
pol_lookup_t lookup = arg->lookup_ptr;

switch (rule->action) {
case FR_ACT_TO_TBL:
break;
case FR_ACT_UNREACHABLE:
rt = ip6_null_entry;
rt = net->ipv6.ip6_null_entry;
goto discard_pkt;
default:
case FR_ACT_BLACKHOLE:
rt = ip6_blk_hole_entry;
rt = net->ipv6.ip6_blk_hole_entry;
goto discard_pkt;
case FR_ACT_PROHIBIT:
rt = ip6_prohibit_entry;
rt = net->ipv6.ip6_prohibit_entry;
goto discard_pkt;
}

table = fib6_get_table(rule->fr_net, rule->table);
table = fib6_get_table(net, rule->table);
if (table)
rt = lookup(table, flp, flags);
rt = lookup(net, table, flp, flags);

if (rt != ip6_null_entry) {
if (rt != net->ipv6.ip6_null_entry) {
struct fib6_rule *r = (struct fib6_rule *)rule;

/*
Expand Down
45 changes: 24 additions & 21 deletions net/ipv6/ip6_fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ static DEFINE_RWLOCK(fib6_walker_lock);

static void fib6_prune_clones(struct net *net, struct fib6_node *fn,
struct rt6_info *rt);
static struct rt6_info * fib6_find_prefix(struct fib6_node *fn);
static struct fib6_node * fib6_repair_tree(struct fib6_node *fn);
static struct rt6_info *fib6_find_prefix(struct net *net, struct fib6_node *fn);
static struct fib6_node *fib6_repair_tree(struct net *net, struct fib6_node *fn);
static int fib6_walk(struct fib6_walker_t *w);
static int fib6_walk_continue(struct fib6_walker_t *w);

Expand Down Expand Up @@ -193,14 +193,14 @@ static void fib6_link_table(struct net *net, struct fib6_table *tb)

#ifdef CONFIG_IPV6_MULTIPLE_TABLES

static struct fib6_table *fib6_alloc_table(u32 id)
static struct fib6_table *fib6_alloc_table(struct net *net, u32 id)
{
struct fib6_table *table;

table = kzalloc(sizeof(*table), GFP_ATOMIC);
if (table != NULL) {
table->tb6_id = id;
table->tb6_root.leaf = ip6_null_entry;
table->tb6_root.leaf = net->ipv6.ip6_null_entry;
table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
}

Expand All @@ -217,7 +217,7 @@ struct fib6_table *fib6_new_table(struct net *net, u32 id)
if (tb)
return tb;

tb = fib6_alloc_table(id);
tb = fib6_alloc_table(net, id);
if (tb != NULL)
fib6_link_table(net, tb);

Expand Down Expand Up @@ -267,7 +267,7 @@ struct fib6_table *fib6_get_table(struct net *net, u32 id)
struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi *fl,
int flags, pol_lookup_t lookup)
{
return (struct dst_entry *) lookup(net->ipv6.fib6_main_tbl, fl, flags);
return (struct dst_entry *) lookup(net, net->ipv6.fib6_main_tbl, fl, flags);
}

static void fib6_tables_init(struct net *net)
Expand Down Expand Up @@ -717,8 +717,8 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
if (sfn == NULL)
goto st_failure;

sfn->leaf = ip6_null_entry;
atomic_inc(&ip6_null_entry->rt6i_ref);
sfn->leaf = info->nl_net->ipv6.ip6_null_entry;
atomic_inc(&info->nl_net->ipv6.ip6_null_entry->rt6i_ref);
sfn->fn_flags = RTN_ROOT;
sfn->fn_sernum = fib6_new_sernum();

Expand Down Expand Up @@ -773,11 +773,11 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
* super-tree leaf node we have to find a new one for it.
*/
if (pn != fn && !pn->leaf && !(pn->fn_flags & RTN_RTINFO)) {
pn->leaf = fib6_find_prefix(pn);
pn->leaf = fib6_find_prefix(info->nl_net, pn);
#if RT6_DEBUG >= 2
if (!pn->leaf) {
BUG_TRAP(pn->leaf != NULL);
pn->leaf = ip6_null_entry;
pn->leaf = info->nl_net->ipv6.ip6_null_entry;
}
#endif
atomic_inc(&pn->leaf->rt6i_ref);
Expand All @@ -793,7 +793,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
*/
st_failure:
if (fn && !(fn->fn_flags & (RTN_RTINFO|RTN_ROOT)))
fib6_repair_tree(fn);
fib6_repair_tree(info->nl_net, fn);
dst_free(&rt->u.dst);
return err;
#endif
Expand Down Expand Up @@ -959,10 +959,10 @@ struct fib6_node * fib6_locate(struct fib6_node *root,
*
*/

static struct rt6_info * fib6_find_prefix(struct fib6_node *fn)
static struct rt6_info *fib6_find_prefix(struct net *net, struct fib6_node *fn)
{
if (fn->fn_flags&RTN_ROOT)
return ip6_null_entry;
return net->ipv6.ip6_null_entry;

while(fn) {
if(fn->left)
Expand All @@ -981,7 +981,8 @@ static struct rt6_info * fib6_find_prefix(struct fib6_node *fn)
* is the node we want to try and remove.
*/

static struct fib6_node * fib6_repair_tree(struct fib6_node *fn)
static struct fib6_node *fib6_repair_tree(struct net *net,
struct fib6_node *fn)
{
int children;
int nstate;
Expand All @@ -1008,11 +1009,11 @@ static struct fib6_node * fib6_repair_tree(struct fib6_node *fn)
|| (children && fn->fn_flags&RTN_ROOT)
#endif
) {
fn->leaf = fib6_find_prefix(fn);
fn->leaf = fib6_find_prefix(net, fn);
#if RT6_DEBUG >= 2
if (fn->leaf==NULL) {
BUG_TRAP(fn->leaf);
fn->leaf = ip6_null_entry;
fn->leaf = net->ipv6.ip6_null_entry;
}
#endif
atomic_inc(&fn->leaf->rt6i_ref);
Expand Down Expand Up @@ -1117,7 +1118,7 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
if (fn->leaf == NULL) {
fn->fn_flags &= ~RTN_RTINFO;
net->ipv6.rt6_stats->fib_route_nodes--;
fn = fib6_repair_tree(fn);
fn = fib6_repair_tree(net, fn);
}

if (atomic_read(&rt->rt6i_ref) != 1) {
Expand All @@ -1129,7 +1130,7 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
*/
while (fn) {
if (!(fn->fn_flags&RTN_RTINFO) && fn->leaf == rt) {
fn->leaf = fib6_find_prefix(fn);
fn->leaf = fib6_find_prefix(net, fn);
atomic_inc(&fn->leaf->rt6i_ref);
rt6_release(rt);
}
Expand All @@ -1145,6 +1146,7 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,

int fib6_del(struct rt6_info *rt, struct nl_info *info)
{
struct net *net = info->nl_net;
struct fib6_node *fn = rt->rt6i_node;
struct rt6_info **rtp;

Expand All @@ -1154,7 +1156,7 @@ int fib6_del(struct rt6_info *rt, struct nl_info *info)
return -ENOENT;
}
#endif
if (fn == NULL || rt == ip6_null_entry)
if (fn == NULL || rt == net->ipv6.ip6_null_entry)
return -ENOENT;

BUG_TRAP(fn->fn_flags&RTN_RTINFO);
Expand Down Expand Up @@ -1501,7 +1503,7 @@ static int fib6_net_init(struct net *net)
goto out_fib_table_hash;

net->ipv6.fib6_main_tbl->tb6_id = RT6_TABLE_MAIN;
net->ipv6.fib6_main_tbl->tb6_root.leaf = ip6_null_entry;
net->ipv6.fib6_main_tbl->tb6_root.leaf = net->ipv6.ip6_null_entry;
net->ipv6.fib6_main_tbl->tb6_root.fn_flags =
RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;

Expand All @@ -1511,7 +1513,7 @@ static int fib6_net_init(struct net *net)
if (!net->ipv6.fib6_local_tbl)
goto out_fib6_main_tbl;
net->ipv6.fib6_local_tbl->tb6_id = RT6_TABLE_LOCAL;
net->ipv6.fib6_local_tbl->tb6_root.leaf = ip6_null_entry;
net->ipv6.fib6_local_tbl->tb6_root.leaf = net->ipv6.ip6_null_entry;
net->ipv6.fib6_local_tbl->tb6_root.fn_flags =
RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
#endif
Expand All @@ -1536,6 +1538,7 @@ static int fib6_net_init(struct net *net)

static void fib6_net_exit(struct net *net)
{
rt6_ifdown(net, NULL);
del_timer(net->ipv6.ip6_fib_timer);
kfree(net->ipv6.ip6_fib_timer);
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
Expand Down
Loading

0 comments on commit 8ed6778

Please sign in to comment.