Skip to content

Commit 0bbbf0e

Browse files
Yuval Mintzdavem330
Yuval Mintz
authored andcommitted
ipmr, ip6mr: Unite creation of new mr_table
Now that both ipmr and ip6mr are using the same mr_table structure, we can have a common function to allocate & initialize a new instance. Signed-off-by: Yuval Mintz <[email protected]> Acked-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b70432f commit 0bbbf0e

File tree

4 files changed

+64
-37
lines changed

4 files changed

+64
-37
lines changed

include/linux/mroute_base.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ void vif_device_init(struct vif_device *v,
8585
unsigned char threshold,
8686
unsigned short flags,
8787
unsigned short get_iflink_mask);
88+
89+
struct mr_table *
90+
mr_table_alloc(struct net *net, u32 id,
91+
const struct rhashtable_params *rht_params,
92+
void (*expire_func)(struct timer_list *t),
93+
void (*table_set)(struct mr_table *mrt,
94+
struct net *net));
8895
#else
8996
static inline void vif_device_init(struct vif_device *v,
9097
struct net_device *dev,
@@ -94,5 +101,15 @@ static inline void vif_device_init(struct vif_device *v,
94101
unsigned short get_iflink_mask)
95102
{
96103
}
104+
105+
static inline struct mr_table *
106+
mr_table_alloc(struct net *net, u32 id,
107+
const struct rhashtable_params *rht_params,
108+
void (*expire_func)(struct timer_list *t),
109+
void (*table_set)(struct mr_table *mrt,
110+
struct net *net))
111+
{
112+
return NULL;
113+
}
97114
#endif
98115
#endif

net/ipv4/ipmr.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ static const struct rhashtable_params ipmr_rht_params = {
352352
.automatic_shrinking = true,
353353
};
354354

355+
static void ipmr_new_table_set(struct mr_table *mrt,
356+
struct net *net)
357+
{
358+
#ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES
359+
list_add_tail_rcu(&mrt->list, &net->ipv4.mr_tables);
360+
#endif
361+
}
362+
355363
static struct mr_table *ipmr_new_table(struct net *net, u32 id)
356364
{
357365
struct mr_table *mrt;
@@ -364,23 +372,8 @@ static struct mr_table *ipmr_new_table(struct net *net, u32 id)
364372
if (mrt)
365373
return mrt;
366374

367-
mrt = kzalloc(sizeof(*mrt), GFP_KERNEL);
368-
if (!mrt)
369-
return ERR_PTR(-ENOMEM);
370-
write_pnet(&mrt->net, net);
371-
mrt->id = id;
372-
373-
rhltable_init(&mrt->mfc_hash, &ipmr_rht_params);
374-
INIT_LIST_HEAD(&mrt->mfc_cache_list);
375-
INIT_LIST_HEAD(&mrt->mfc_unres_queue);
376-
377-
timer_setup(&mrt->ipmr_expire_timer, ipmr_expire_process, 0);
378-
379-
mrt->mroute_reg_vif_num = -1;
380-
#ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES
381-
list_add_tail_rcu(&mrt->list, &net->ipv4.mr_tables);
382-
#endif
383-
return mrt;
375+
return mr_table_alloc(net, id, &ipmr_rht_params,
376+
ipmr_expire_process, ipmr_new_table_set);
384377
}
385378

386379
static void ipmr_free_table(struct mr_table *mrt)

net/ipv4/ipmr_base.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,30 @@ void vif_device_init(struct vif_device *v,
2626
v->link = dev->ifindex;
2727
}
2828
EXPORT_SYMBOL(vif_device_init);
29+
30+
struct mr_table *
31+
mr_table_alloc(struct net *net, u32 id,
32+
const struct rhashtable_params *rht_params,
33+
void (*expire_func)(struct timer_list *t),
34+
void (*table_set)(struct mr_table *mrt,
35+
struct net *net))
36+
{
37+
struct mr_table *mrt;
38+
39+
mrt = kzalloc(sizeof(*mrt), GFP_KERNEL);
40+
if (!mrt)
41+
return NULL;
42+
mrt->id = id;
43+
write_pnet(&mrt->net, net);
44+
45+
rhltable_init(&mrt->mfc_hash, rht_params);
46+
INIT_LIST_HEAD(&mrt->mfc_cache_list);
47+
INIT_LIST_HEAD(&mrt->mfc_unres_queue);
48+
49+
timer_setup(&mrt->ipmr_expire_timer, expire_func, 0);
50+
51+
mrt->mroute_reg_vif_num = -1;
52+
table_set(mrt, net);
53+
return mrt;
54+
}
55+
EXPORT_SYMBOL(mr_table_alloc);

net/ipv6/ip6mr.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <linux/proc_fs.h>
3232
#include <linux/seq_file.h>
3333
#include <linux/init.h>
34-
#include <linux/slab.h>
3534
#include <linux/compat.h>
3635
#include <net/protocol.h>
3736
#include <linux/skbuff.h>
@@ -295,6 +294,14 @@ static const struct rhashtable_params ip6mr_rht_params = {
295294
.automatic_shrinking = true,
296295
};
297296

297+
static void ip6mr_new_table_set(struct mr_table *mrt,
298+
struct net *net)
299+
{
300+
#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
301+
list_add_tail_rcu(&mrt->list, &net->ipv6.mr6_tables);
302+
#endif
303+
}
304+
298305
static struct mr_table *ip6mr_new_table(struct net *net, u32 id)
299306
{
300307
struct mr_table *mrt;
@@ -303,25 +310,8 @@ static struct mr_table *ip6mr_new_table(struct net *net, u32 id)
303310
if (mrt)
304311
return mrt;
305312

306-
mrt = kzalloc(sizeof(*mrt), GFP_KERNEL);
307-
if (!mrt)
308-
return NULL;
309-
mrt->id = id;
310-
write_pnet(&mrt->net, net);
311-
312-
rhltable_init(&mrt->mfc_hash, &ip6mr_rht_params);
313-
INIT_LIST_HEAD(&mrt->mfc_cache_list);
314-
INIT_LIST_HEAD(&mrt->mfc_unres_queue);
315-
316-
timer_setup(&mrt->ipmr_expire_timer, ipmr_expire_process, 0);
317-
318-
#ifdef CONFIG_IPV6_PIMSM_V2
319-
mrt->mroute_reg_vif_num = -1;
320-
#endif
321-
#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
322-
list_add_tail_rcu(&mrt->list, &net->ipv6.mr6_tables);
323-
#endif
324-
return mrt;
313+
return mr_table_alloc(net, id, &ip6mr_rht_params,
314+
ipmr_expire_process, ip6mr_new_table_set);
325315
}
326316

327317
static void ip6mr_free_table(struct mr_table *mrt)

0 commit comments

Comments
 (0)