Commit 0bbbf0e7 authored by Yuval Mintz's avatar Yuval Mintz Committed by David S. Miller

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: default avatarYuval Mintz <yuvalm@mellanox.com>
Acked-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b70432f7
...@@ -85,6 +85,13 @@ void vif_device_init(struct vif_device *v, ...@@ -85,6 +85,13 @@ void vif_device_init(struct vif_device *v,
unsigned char threshold, unsigned char threshold,
unsigned short flags, unsigned short flags,
unsigned short get_iflink_mask); unsigned short get_iflink_mask);
struct mr_table *
mr_table_alloc(struct net *net, u32 id,
const struct rhashtable_params *rht_params,
void (*expire_func)(struct timer_list *t),
void (*table_set)(struct mr_table *mrt,
struct net *net));
#else #else
static inline void vif_device_init(struct vif_device *v, static inline void vif_device_init(struct vif_device *v,
struct net_device *dev, struct net_device *dev,
...@@ -94,5 +101,15 @@ static inline void vif_device_init(struct vif_device *v, ...@@ -94,5 +101,15 @@ static inline void vif_device_init(struct vif_device *v,
unsigned short get_iflink_mask) unsigned short get_iflink_mask)
{ {
} }
static inline struct mr_table *
mr_table_alloc(struct net *net, u32 id,
const struct rhashtable_params *rht_params,
void (*expire_func)(struct timer_list *t),
void (*table_set)(struct mr_table *mrt,
struct net *net))
{
return NULL;
}
#endif #endif
#endif #endif
...@@ -352,6 +352,14 @@ static const struct rhashtable_params ipmr_rht_params = { ...@@ -352,6 +352,14 @@ static const struct rhashtable_params ipmr_rht_params = {
.automatic_shrinking = true, .automatic_shrinking = true,
}; };
static void ipmr_new_table_set(struct mr_table *mrt,
struct net *net)
{
#ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES
list_add_tail_rcu(&mrt->list, &net->ipv4.mr_tables);
#endif
}
static struct mr_table *ipmr_new_table(struct net *net, u32 id) static struct mr_table *ipmr_new_table(struct net *net, u32 id)
{ {
struct mr_table *mrt; struct mr_table *mrt;
...@@ -364,23 +372,8 @@ static struct mr_table *ipmr_new_table(struct net *net, u32 id) ...@@ -364,23 +372,8 @@ static struct mr_table *ipmr_new_table(struct net *net, u32 id)
if (mrt) if (mrt)
return mrt; return mrt;
mrt = kzalloc(sizeof(*mrt), GFP_KERNEL); return mr_table_alloc(net, id, &ipmr_rht_params,
if (!mrt) ipmr_expire_process, ipmr_new_table_set);
return ERR_PTR(-ENOMEM);
write_pnet(&mrt->net, net);
mrt->id = id;
rhltable_init(&mrt->mfc_hash, &ipmr_rht_params);
INIT_LIST_HEAD(&mrt->mfc_cache_list);
INIT_LIST_HEAD(&mrt->mfc_unres_queue);
timer_setup(&mrt->ipmr_expire_timer, ipmr_expire_process, 0);
mrt->mroute_reg_vif_num = -1;
#ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES
list_add_tail_rcu(&mrt->list, &net->ipv4.mr_tables);
#endif
return mrt;
} }
static void ipmr_free_table(struct mr_table *mrt) static void ipmr_free_table(struct mr_table *mrt)
......
...@@ -26,3 +26,30 @@ void vif_device_init(struct vif_device *v, ...@@ -26,3 +26,30 @@ void vif_device_init(struct vif_device *v,
v->link = dev->ifindex; v->link = dev->ifindex;
} }
EXPORT_SYMBOL(vif_device_init); EXPORT_SYMBOL(vif_device_init);
struct mr_table *
mr_table_alloc(struct net *net, u32 id,
const struct rhashtable_params *rht_params,
void (*expire_func)(struct timer_list *t),
void (*table_set)(struct mr_table *mrt,
struct net *net))
{
struct mr_table *mrt;
mrt = kzalloc(sizeof(*mrt), GFP_KERNEL);
if (!mrt)
return NULL;
mrt->id = id;
write_pnet(&mrt->net, net);
rhltable_init(&mrt->mfc_hash, rht_params);
INIT_LIST_HEAD(&mrt->mfc_cache_list);
INIT_LIST_HEAD(&mrt->mfc_unres_queue);
timer_setup(&mrt->ipmr_expire_timer, expire_func, 0);
mrt->mroute_reg_vif_num = -1;
table_set(mrt, net);
return mrt;
}
EXPORT_SYMBOL(mr_table_alloc);
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h>
#include <linux/compat.h> #include <linux/compat.h>
#include <net/protocol.h> #include <net/protocol.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
...@@ -295,6 +294,14 @@ static const struct rhashtable_params ip6mr_rht_params = { ...@@ -295,6 +294,14 @@ static const struct rhashtable_params ip6mr_rht_params = {
.automatic_shrinking = true, .automatic_shrinking = true,
}; };
static void ip6mr_new_table_set(struct mr_table *mrt,
struct net *net)
{
#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
list_add_tail_rcu(&mrt->list, &net->ipv6.mr6_tables);
#endif
}
static struct mr_table *ip6mr_new_table(struct net *net, u32 id) static struct mr_table *ip6mr_new_table(struct net *net, u32 id)
{ {
struct mr_table *mrt; struct mr_table *mrt;
...@@ -303,25 +310,8 @@ static struct mr_table *ip6mr_new_table(struct net *net, u32 id) ...@@ -303,25 +310,8 @@ static struct mr_table *ip6mr_new_table(struct net *net, u32 id)
if (mrt) if (mrt)
return mrt; return mrt;
mrt = kzalloc(sizeof(*mrt), GFP_KERNEL); return mr_table_alloc(net, id, &ip6mr_rht_params,
if (!mrt) ipmr_expire_process, ip6mr_new_table_set);
return NULL;
mrt->id = id;
write_pnet(&mrt->net, net);
rhltable_init(&mrt->mfc_hash, &ip6mr_rht_params);
INIT_LIST_HEAD(&mrt->mfc_cache_list);
INIT_LIST_HEAD(&mrt->mfc_unres_queue);
timer_setup(&mrt->ipmr_expire_timer, ipmr_expire_process, 0);
#ifdef CONFIG_IPV6_PIMSM_V2
mrt->mroute_reg_vif_num = -1;
#endif
#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
list_add_tail_rcu(&mrt->list, &net->ipv6.mr6_tables);
#endif
return mrt;
} }
static void ip6mr_free_table(struct mr_table *mrt) static void ip6mr_free_table(struct mr_table *mrt)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment