All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yuval Mintz <yuvalm@mellanox.com>
To: netdev@vger.kernel.org
Cc: mlxsw@mellanox.com, kuznet@ms2.inr.ac.ru,
	yoshfuji@linux-ipv6.org, nikolay@cumulusnetworks.com,
	Yuval Mintz <yuvalm@mellanox.com>
Subject: [PATCH net-next 05/11] ipmr, ip6mr: Unite creation of new mr_table
Date: Tue, 27 Feb 2018 20:58:22 +0200	[thread overview]
Message-ID: <1519757908-32863-6-git-send-email-yuvalm@mellanox.com> (raw)
In-Reply-To: <1519757908-32863-1-git-send-email-yuvalm@mellanox.com>

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 <yuvalm@mellanox.com>
---
 include/linux/mroute_base.h | 17 +++++++++++++++++
 net/ipv4/ipmr.c             | 27 ++++++++++-----------------
 net/ipv4/ipmr_base.c        | 27 +++++++++++++++++++++++++++
 net/ipv6/ip6mr.c            | 30 ++++++++++--------------------
 4 files changed, 64 insertions(+), 37 deletions(-)

diff --git a/include/linux/mroute_base.h b/include/linux/mroute_base.h
index 1cc944a..8053057 100644
--- a/include/linux/mroute_base.h
+++ b/include/linux/mroute_base.h
@@ -85,6 +85,13 @@ void vif_device_init(struct vif_device *v,
 		     unsigned char threshold,
 		     unsigned short flags,
 		     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
 static inline void vif_device_init(struct vif_device *v,
 				   struct net_device *dev,
@@ -94,5 +101,15 @@ static inline void vif_device_init(struct vif_device *v,
 				   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
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 78046d2..09f965d 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -351,6 +351,14 @@ static const struct rhashtable_params ipmr_rht_params = {
 	.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)
 {
 	struct mr_table *mrt;
@@ -363,23 +371,8 @@ static struct mr_table *ipmr_new_table(struct net *net, u32 id)
 	if (mrt)
 		return mrt;
 
-	mrt = kzalloc(sizeof(*mrt), GFP_KERNEL);
-	if (!mrt)
-		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;
+	return mr_table_alloc(net, id, &ipmr_rht_params,
+			      ipmr_expire_process, ipmr_new_table_set);
 }
 
 static void ipmr_free_table(struct mr_table *mrt)
diff --git a/net/ipv4/ipmr_base.c b/net/ipv4/ipmr_base.c
index 22758f8..3e21a58 100644
--- a/net/ipv4/ipmr_base.c
+++ b/net/ipv4/ipmr_base.c
@@ -26,3 +26,30 @@ void vif_device_init(struct vif_device *v,
 		v->link = dev->ifindex;
 }
 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);
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index adbb826..d508528 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -31,7 +31,6 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/init.h>
-#include <linux/slab.h>
 #include <linux/compat.h>
 #include <net/protocol.h>
 #include <linux/skbuff.h>
@@ -295,6 +294,14 @@ static const struct rhashtable_params ip6mr_rht_params = {
 	.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)
 {
 	struct mr_table *mrt;
@@ -303,25 +310,8 @@ static struct mr_table *ip6mr_new_table(struct net *net, u32 id)
 	if (mrt)
 		return mrt;
 
-	mrt = kzalloc(sizeof(*mrt), GFP_KERNEL);
-	if (!mrt)
-		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;
+	return mr_table_alloc(net, id, &ip6mr_rht_params,
+			      ipmr_expire_process, ip6mr_new_table_set);
 }
 
 static void ip6mr_free_table(struct mr_table *mrt)
-- 
2.4.3

  parent reply	other threads:[~2018-02-27 18:59 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-27 18:58 [PATCH net-next 00/11] ipmr, ip6mr: Align multicast routing for IPv4 & IPv6 Yuval Mintz
2018-02-27 18:58 ` [PATCH net-next 01/11] ipmr,ipmr6: Define a uniform vif_device Yuval Mintz
2018-02-27 19:36   ` Nikolay Aleksandrov
2018-02-27 18:58 ` [PATCH net-next 02/11] ip6mr: Make mroute_sk rcu-based Yuval Mintz
2018-02-27 20:10   ` Nikolay Aleksandrov
2018-02-27 18:58 ` [PATCH net-next 03/11] ip6mr: Align hash implementation to ipmr Yuval Mintz
2018-02-27 20:12   ` Nikolay Aleksandrov
2018-02-27 18:58 ` [PATCH net-next 04/11] mroute*: Make mr_table a common struct Yuval Mintz
2018-02-27 20:14   ` Nikolay Aleksandrov
2018-02-27 18:58 ` Yuval Mintz [this message]
2018-02-27 22:14   ` [PATCH net-next 05/11] ipmr, ip6mr: Unite creation of new mr_table Nikolay Aleksandrov
2018-02-27 18:58 ` [PATCH net-next 06/11] ipmr, ip6mr: Make mfc_cache a common structure Yuval Mintz
2018-02-27 22:38   ` Nikolay Aleksandrov
2018-02-28 20:50     ` Yuval Mintz
2018-02-27 18:58 ` [PATCH net-next 07/11] ipmr, ip6mr: Unite logic for searching in MFC cache Yuval Mintz
2018-02-27 22:38   ` Nikolay Aleksandrov
2018-02-27 18:58 ` [PATCH net-next 08/11] ipmr, ip6mr: Unite mfc seq logic Yuval Mintz
2018-02-27 22:40   ` Nikolay Aleksandrov
2018-02-27 18:58 ` [PATCH net-next 09/11] ipmr, ip6mr: Unite vif seq functions Yuval Mintz
2018-02-27 22:45   ` Nikolay Aleksandrov
2018-02-27 18:58 ` [PATCH net-next 10/11] ip6mr: Remove MFC_NOTIFY and refactor flags Yuval Mintz
2018-02-27 22:42   ` Nikolay Aleksandrov
2018-02-27 18:58 ` [PATCH net-next 11/11] ipmr, ip6mr: Unite dumproute flows Yuval Mintz
2018-02-27 22:51   ` Nikolay Aleksandrov
2018-02-28 16:30 ` [PATCH net-next 00/11] ipmr, ip6mr: Align multicast routing for IPv4 & IPv6 David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1519757908-32863-6-git-send-email-yuvalm@mellanox.com \
    --to=yuvalm@mellanox.com \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=mlxsw@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@cumulusnetworks.com \
    --cc=yoshfuji@linux-ipv6.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.