* [patch net-next 0/2] ipv4: fib: FIB notifications cleanup
@ 2017-03-10 7:56 Jiri Pirko
2017-03-10 7:56 ` [patch net-next 1/2] ipv4: fib: Move FIB notification code to a separate file Jiri Pirko
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Jiri Pirko @ 2017-03-10 7:56 UTC (permalink / raw)
To: netdev; +Cc: davem, idosch, mlxsw, ivecera, kuznet, jmorris, yoshfuji, kaber
From: Jiri Pirko <jiri@mellanox.com>
Ido says:
The first patch moves the core FIB notification code to a separate file,
so that code related to FIB rules is placed in fib_rules.c and not
fib_trie.c. The reason for the change will become even more apparent in
follow-up patchset where we extend the FIB rules notifications.
Second patch removes a redundant argument.
Ido Schimmel (2):
ipv4: fib: Move FIB notification code to a separate file
ipv4: fib: Remove redundant argument
include/net/ip_fib.h | 12 ++++++
net/ipv4/Makefile | 2 +-
net/ipv4/fib_notifier.c | 86 ++++++++++++++++++++++++++++++++++++++
net/ipv4/fib_rules.c | 8 ++++
net/ipv4/fib_trie.c | 108 +++---------------------------------------------
5 files changed, 113 insertions(+), 103 deletions(-)
create mode 100644 net/ipv4/fib_notifier.c
--
2.7.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch net-next 1/2] ipv4: fib: Move FIB notification code to a separate file
2017-03-10 7:56 [patch net-next 0/2] ipv4: fib: FIB notifications cleanup Jiri Pirko
@ 2017-03-10 7:56 ` Jiri Pirko
2017-03-10 16:31 ` David Ahern
2017-03-10 7:56 ` [patch net-next 2/2] ipv4: fib: Remove redundant argument Jiri Pirko
2017-03-10 17:45 ` [patch net-next 0/2] ipv4: fib: FIB notifications cleanup David Miller
2 siblings, 1 reply; 6+ messages in thread
From: Jiri Pirko @ 2017-03-10 7:56 UTC (permalink / raw)
To: netdev; +Cc: davem, idosch, mlxsw, ivecera, kuznet, jmorris, yoshfuji, kaber
From: Ido Schimmel <idosch@mellanox.com>
Most of the code concerned with the FIB notification chain currently
resides in fib_trie.c, but this isn't really appropriate, as the FIB
notification chain is also used for FIB rules.
Therefore, it makes sense to move the common FIB notification code to a
separate file and have it export the relevant functions, which can be
invoked by its different users (e.g., fib_trie.c, fib_rules.c).
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
include/net/ip_fib.h | 15 ++++++++
net/ipv4/Makefile | 2 +-
net/ipv4/fib_notifier.c | 86 +++++++++++++++++++++++++++++++++++++++++++
net/ipv4/fib_rules.c | 9 +++++
net/ipv4/fib_trie.c | 97 +------------------------------------------------
5 files changed, 113 insertions(+), 96 deletions(-)
create mode 100644 net/ipv4/fib_notifier.c
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 368bb40..3ad8706 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -232,9 +232,24 @@ enum fib_event_type {
int register_fib_notifier(struct notifier_block *nb,
void (*cb)(struct notifier_block *nb));
int unregister_fib_notifier(struct notifier_block *nb);
+int call_fib_notifier(struct notifier_block *nb, struct net *net,
+ enum fib_event_type event_type,
+ struct fib_notifier_info *info);
int call_fib_notifiers(struct net *net, enum fib_event_type event_type,
struct fib_notifier_info *info);
+void fib_notify(struct net *net, struct notifier_block *nb,
+ enum fib_event_type event_type);
+#ifdef CONFIG_IP_MULTIPLE_TABLES
+void fib_rules_notify(struct net *net, struct notifier_block *nb,
+ enum fib_event_type event_type);
+#else
+static inline void fib_rules_notify(struct net *net, struct notifier_block *nb,
+ enum fib_event_type event_type)
+{
+}
+#endif
+
struct fib_table {
struct hlist_node tb_hlist;
u32 tb_id;
diff --git a/net/ipv4/Makefile b/net/ipv4/Makefile
index c6d4238..f83de23 100644
--- a/net/ipv4/Makefile
+++ b/net/ipv4/Makefile
@@ -11,7 +11,7 @@ obj-y := route.o inetpeer.o protocol.o \
tcp_rate.o tcp_recovery.o \
tcp_offload.o datagram.o raw.o udp.o udplite.o \
udp_offload.o arp.o icmp.o devinet.o af_inet.o igmp.o \
- fib_frontend.o fib_semantics.o fib_trie.o \
+ fib_frontend.o fib_semantics.o fib_trie.o fib_notifier.o \
inet_fragment.o ping.o ip_tunnel_core.o gre_offload.o
obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o
diff --git a/net/ipv4/fib_notifier.c b/net/ipv4/fib_notifier.c
new file mode 100644
index 0000000..91f8f18
--- /dev/null
+++ b/net/ipv4/fib_notifier.c
@@ -0,0 +1,86 @@
+#include <linux/rtnetlink.h>
+#include <linux/notifier.h>
+#include <linux/rcupdate.h>
+#include <linux/kernel.h>
+#include <net/net_namespace.h>
+#include <net/netns/ipv4.h>
+#include <net/ip_fib.h>
+
+static ATOMIC_NOTIFIER_HEAD(fib_chain);
+
+int call_fib_notifier(struct notifier_block *nb, struct net *net,
+ enum fib_event_type event_type,
+ struct fib_notifier_info *info)
+{
+ info->net = net;
+ return nb->notifier_call(nb, event_type, info);
+}
+
+int call_fib_notifiers(struct net *net, enum fib_event_type event_type,
+ struct fib_notifier_info *info)
+{
+ net->ipv4.fib_seq++;
+ info->net = net;
+ return atomic_notifier_call_chain(&fib_chain, event_type, info);
+}
+
+static unsigned int fib_seq_sum(void)
+{
+ unsigned int fib_seq = 0;
+ struct net *net;
+
+ rtnl_lock();
+ for_each_net(net)
+ fib_seq += net->ipv4.fib_seq;
+ rtnl_unlock();
+
+ return fib_seq;
+}
+
+static bool fib_dump_is_consistent(struct notifier_block *nb,
+ void (*cb)(struct notifier_block *nb),
+ unsigned int fib_seq)
+{
+ atomic_notifier_chain_register(&fib_chain, nb);
+ if (fib_seq == fib_seq_sum())
+ return true;
+ atomic_notifier_chain_unregister(&fib_chain, nb);
+ if (cb)
+ cb(nb);
+ return false;
+}
+
+#define FIB_DUMP_MAX_RETRIES 5
+int register_fib_notifier(struct notifier_block *nb,
+ void (*cb)(struct notifier_block *nb))
+{
+ int retries = 0;
+
+ do {
+ unsigned int fib_seq = fib_seq_sum();
+ struct net *net;
+
+ /* Mutex semantics guarantee that every change done to
+ * FIB tries before we read the change sequence counter
+ * is now visible to us.
+ */
+ rcu_read_lock();
+ for_each_net_rcu(net) {
+ fib_rules_notify(net, nb, FIB_EVENT_RULE_ADD);
+ fib_notify(net, nb, FIB_EVENT_ENTRY_ADD);
+ }
+ rcu_read_unlock();
+
+ if (fib_dump_is_consistent(nb, cb, fib_seq))
+ return 0;
+ } while (++retries < FIB_DUMP_MAX_RETRIES);
+
+ return -EBUSY;
+}
+EXPORT_SYMBOL(register_fib_notifier);
+
+int unregister_fib_notifier(struct notifier_block *nb)
+{
+ return atomic_notifier_chain_unregister(&fib_chain, nb);
+}
+EXPORT_SYMBOL(unregister_fib_notifier);
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index 2e50062..bbd57f0 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -172,6 +172,15 @@ static int call_fib_rule_notifiers(struct net *net,
return call_fib_notifiers(net, event_type, &info);
}
+void fib_rules_notify(struct net *net, struct notifier_block *nb,
+ enum fib_event_type event_type)
+{
+ struct fib_notifier_info info;
+
+ if (net->ipv4.fib_has_custom_rules)
+ call_fib_notifier(nb, net, event_type, &info);
+}
+
static const struct nla_policy fib4_rule_policy[FRA_MAX+1] = {
FRA_GENERIC_POLICY,
[FRA_FLOW] = { .type = NLA_U32 },
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 2f0d823..5639e8a 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -84,43 +84,6 @@
#include <trace/events/fib.h>
#include "fib_lookup.h"
-static unsigned int fib_seq_sum(void)
-{
- unsigned int fib_seq = 0;
- struct net *net;
-
- rtnl_lock();
- for_each_net(net)
- fib_seq += net->ipv4.fib_seq;
- rtnl_unlock();
-
- return fib_seq;
-}
-
-static ATOMIC_NOTIFIER_HEAD(fib_chain);
-
-static int call_fib_notifier(struct notifier_block *nb, struct net *net,
- enum fib_event_type event_type,
- struct fib_notifier_info *info)
-{
- info->net = net;
- return nb->notifier_call(nb, event_type, info);
-}
-
-static void fib_rules_notify(struct net *net, struct notifier_block *nb,
- enum fib_event_type event_type)
-{
-#ifdef CONFIG_IP_MULTIPLE_TABLES
- struct fib_notifier_info info;
-
- if (net->ipv4.fib_has_custom_rules)
- call_fib_notifier(nb, net, event_type, &info);
-#endif
-}
-
-static void fib_notify(struct net *net, struct notifier_block *nb,
- enum fib_event_type event_type);
-
static int call_fib_entry_notifier(struct notifier_block *nb, struct net *net,
enum fib_event_type event_type, u32 dst,
int dst_len, struct fib_info *fi,
@@ -137,62 +100,6 @@ static int call_fib_entry_notifier(struct notifier_block *nb, struct net *net,
return call_fib_notifier(nb, net, event_type, &info.info);
}
-static bool fib_dump_is_consistent(struct notifier_block *nb,
- void (*cb)(struct notifier_block *nb),
- unsigned int fib_seq)
-{
- atomic_notifier_chain_register(&fib_chain, nb);
- if (fib_seq == fib_seq_sum())
- return true;
- atomic_notifier_chain_unregister(&fib_chain, nb);
- if (cb)
- cb(nb);
- return false;
-}
-
-#define FIB_DUMP_MAX_RETRIES 5
-int register_fib_notifier(struct notifier_block *nb,
- void (*cb)(struct notifier_block *nb))
-{
- int retries = 0;
-
- do {
- unsigned int fib_seq = fib_seq_sum();
- struct net *net;
-
- /* Mutex semantics guarantee that every change done to
- * FIB tries before we read the change sequence counter
- * is now visible to us.
- */
- rcu_read_lock();
- for_each_net_rcu(net) {
- fib_rules_notify(net, nb, FIB_EVENT_RULE_ADD);
- fib_notify(net, nb, FIB_EVENT_ENTRY_ADD);
- }
- rcu_read_unlock();
-
- if (fib_dump_is_consistent(nb, cb, fib_seq))
- return 0;
- } while (++retries < FIB_DUMP_MAX_RETRIES);
-
- return -EBUSY;
-}
-EXPORT_SYMBOL(register_fib_notifier);
-
-int unregister_fib_notifier(struct notifier_block *nb)
-{
- return atomic_notifier_chain_unregister(&fib_chain, nb);
-}
-EXPORT_SYMBOL(unregister_fib_notifier);
-
-int call_fib_notifiers(struct net *net, enum fib_event_type event_type,
- struct fib_notifier_info *info)
-{
- net->ipv4.fib_seq++;
- info->net = net;
- return atomic_notifier_call_chain(&fib_chain, event_type, info);
-}
-
static int call_fib_entry_notifiers(struct net *net,
enum fib_event_type event_type, u32 dst,
int dst_len, struct fib_info *fi,
@@ -2036,8 +1943,8 @@ static void fib_table_notify(struct net *net, struct fib_table *tb,
}
}
-static void fib_notify(struct net *net, struct notifier_block *nb,
- enum fib_event_type event_type)
+void fib_notify(struct net *net, struct notifier_block *nb,
+ enum fib_event_type event_type)
{
unsigned int h;
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [patch net-next 2/2] ipv4: fib: Remove redundant argument
2017-03-10 7:56 [patch net-next 0/2] ipv4: fib: FIB notifications cleanup Jiri Pirko
2017-03-10 7:56 ` [patch net-next 1/2] ipv4: fib: Move FIB notification code to a separate file Jiri Pirko
@ 2017-03-10 7:56 ` Jiri Pirko
2017-03-10 16:31 ` David Ahern
2017-03-10 17:45 ` [patch net-next 0/2] ipv4: fib: FIB notifications cleanup David Miller
2 siblings, 1 reply; 6+ messages in thread
From: Jiri Pirko @ 2017-03-10 7:56 UTC (permalink / raw)
To: netdev; +Cc: davem, idosch, mlxsw, ivecera, kuznet, jmorris, yoshfuji, kaber
From: Ido Schimmel <idosch@mellanox.com>
We always pass the same event type to fib_notify() and
fib_rules_notify(), so we can safely drop this argument.
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
include/net/ip_fib.h | 9 +++------
net/ipv4/fib_notifier.c | 4 ++--
net/ipv4/fib_rules.c | 5 ++---
net/ipv4/fib_trie.c | 15 ++++++---------
4 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 3ad8706..d9cee96 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -238,14 +238,11 @@ int call_fib_notifier(struct notifier_block *nb, struct net *net,
int call_fib_notifiers(struct net *net, enum fib_event_type event_type,
struct fib_notifier_info *info);
-void fib_notify(struct net *net, struct notifier_block *nb,
- enum fib_event_type event_type);
+void fib_notify(struct net *net, struct notifier_block *nb);
#ifdef CONFIG_IP_MULTIPLE_TABLES
-void fib_rules_notify(struct net *net, struct notifier_block *nb,
- enum fib_event_type event_type);
+void fib_rules_notify(struct net *net, struct notifier_block *nb);
#else
-static inline void fib_rules_notify(struct net *net, struct notifier_block *nb,
- enum fib_event_type event_type)
+static inline void fib_rules_notify(struct net *net, struct notifier_block *nb)
{
}
#endif
diff --git a/net/ipv4/fib_notifier.c b/net/ipv4/fib_notifier.c
index 91f8f18..e0714d9 100644
--- a/net/ipv4/fib_notifier.c
+++ b/net/ipv4/fib_notifier.c
@@ -66,8 +66,8 @@ int register_fib_notifier(struct notifier_block *nb,
*/
rcu_read_lock();
for_each_net_rcu(net) {
- fib_rules_notify(net, nb, FIB_EVENT_RULE_ADD);
- fib_notify(net, nb, FIB_EVENT_ENTRY_ADD);
+ fib_rules_notify(net, nb);
+ fib_notify(net, nb);
}
rcu_read_unlock();
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index bbd57f0..2892109 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -172,13 +172,12 @@ static int call_fib_rule_notifiers(struct net *net,
return call_fib_notifiers(net, event_type, &info);
}
-void fib_rules_notify(struct net *net, struct notifier_block *nb,
- enum fib_event_type event_type)
+void fib_rules_notify(struct net *net, struct notifier_block *nb)
{
struct fib_notifier_info info;
if (net->ipv4.fib_has_custom_rules)
- call_fib_notifier(nb, net, event_type, &info);
+ call_fib_notifier(nb, net, FIB_EVENT_RULE_ADD, &info);
}
static const struct nla_policy fib4_rule_policy[FRA_MAX+1] = {
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 5639e8a..1201409 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1902,8 +1902,7 @@ int fib_table_flush(struct net *net, struct fib_table *tb)
}
static void fib_leaf_notify(struct net *net, struct key_vector *l,
- struct fib_table *tb, struct notifier_block *nb,
- enum fib_event_type event_type)
+ struct fib_table *tb, struct notifier_block *nb)
{
struct fib_alias *fa;
@@ -1919,22 +1918,21 @@ static void fib_leaf_notify(struct net *net, struct key_vector *l,
if (tb->tb_id != fa->tb_id)
continue;
- call_fib_entry_notifier(nb, net, event_type, l->key,
+ call_fib_entry_notifier(nb, net, FIB_EVENT_ENTRY_ADD, l->key,
KEYLENGTH - fa->fa_slen, fi, fa->fa_tos,
fa->fa_type, fa->tb_id);
}
}
static void fib_table_notify(struct net *net, struct fib_table *tb,
- struct notifier_block *nb,
- enum fib_event_type event_type)
+ struct notifier_block *nb)
{
struct trie *t = (struct trie *)tb->tb_data;
struct key_vector *l, *tp = t->kv;
t_key key = 0;
while ((l = leaf_walk_rcu(&tp, key)) != NULL) {
- fib_leaf_notify(net, l, tb, nb, event_type);
+ fib_leaf_notify(net, l, tb, nb);
key = l->key + 1;
/* stop in case of wrap around */
@@ -1943,8 +1941,7 @@ static void fib_table_notify(struct net *net, struct fib_table *tb,
}
}
-void fib_notify(struct net *net, struct notifier_block *nb,
- enum fib_event_type event_type)
+void fib_notify(struct net *net, struct notifier_block *nb)
{
unsigned int h;
@@ -1953,7 +1950,7 @@ void fib_notify(struct net *net, struct notifier_block *nb,
struct fib_table *tb;
hlist_for_each_entry_rcu(tb, head, tb_hlist)
- fib_table_notify(net, tb, nb, event_type);
+ fib_table_notify(net, tb, nb);
}
}
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [patch net-next 1/2] ipv4: fib: Move FIB notification code to a separate file
2017-03-10 7:56 ` [patch net-next 1/2] ipv4: fib: Move FIB notification code to a separate file Jiri Pirko
@ 2017-03-10 16:31 ` David Ahern
0 siblings, 0 replies; 6+ messages in thread
From: David Ahern @ 2017-03-10 16:31 UTC (permalink / raw)
To: Jiri Pirko, netdev
Cc: davem, idosch, mlxsw, ivecera, kuznet, jmorris, yoshfuji, kaber
On 3/10/17 12:56 AM, Jiri Pirko wrote:
> From: Ido Schimmel <idosch@mellanox.com>
>
> Most of the code concerned with the FIB notification chain currently
> resides in fib_trie.c, but this isn't really appropriate, as the FIB
> notification chain is also used for FIB rules.
>
> Therefore, it makes sense to move the common FIB notification code to a
> separate file and have it export the relevant functions, which can be
> invoked by its different users (e.g., fib_trie.c, fib_rules.c).
>
> Signed-off-by: Ido Schimmel <idosch@mellanox.com>
> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
> ---
> include/net/ip_fib.h | 15 ++++++++
> net/ipv4/Makefile | 2 +-
> net/ipv4/fib_notifier.c | 86 +++++++++++++++++++++++++++++++++++++++++++
> net/ipv4/fib_rules.c | 9 +++++
> net/ipv4/fib_trie.c | 97 +------------------------------------------------
> 5 files changed, 113 insertions(+), 96 deletions(-)
> create mode 100644 net/ipv4/fib_notifier.c
>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch net-next 2/2] ipv4: fib: Remove redundant argument
2017-03-10 7:56 ` [patch net-next 2/2] ipv4: fib: Remove redundant argument Jiri Pirko
@ 2017-03-10 16:31 ` David Ahern
0 siblings, 0 replies; 6+ messages in thread
From: David Ahern @ 2017-03-10 16:31 UTC (permalink / raw)
To: Jiri Pirko, netdev
Cc: davem, idosch, mlxsw, ivecera, kuznet, jmorris, yoshfuji, kaber
On 3/10/17 12:56 AM, Jiri Pirko wrote:
> From: Ido Schimmel <idosch@mellanox.com>
>
> We always pass the same event type to fib_notify() and
> fib_rules_notify(), so we can safely drop this argument.
>
> Signed-off-by: Ido Schimmel <idosch@mellanox.com>
> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
> ---
> include/net/ip_fib.h | 9 +++------
> net/ipv4/fib_notifier.c | 4 ++--
> net/ipv4/fib_rules.c | 5 ++---
> net/ipv4/fib_trie.c | 15 ++++++---------
> 4 files changed, 13 insertions(+), 20 deletions(-)
>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch net-next 0/2] ipv4: fib: FIB notifications cleanup
2017-03-10 7:56 [patch net-next 0/2] ipv4: fib: FIB notifications cleanup Jiri Pirko
2017-03-10 7:56 ` [patch net-next 1/2] ipv4: fib: Move FIB notification code to a separate file Jiri Pirko
2017-03-10 7:56 ` [patch net-next 2/2] ipv4: fib: Remove redundant argument Jiri Pirko
@ 2017-03-10 17:45 ` David Miller
2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2017-03-10 17:45 UTC (permalink / raw)
To: jiri; +Cc: netdev, idosch, mlxsw, ivecera, kuznet, jmorris, yoshfuji, kaber
From: Jiri Pirko <jiri@resnulli.us>
Date: Fri, 10 Mar 2017 08:56:17 +0100
> Ido says:
>
> The first patch moves the core FIB notification code to a separate file,
> so that code related to FIB rules is placed in fib_rules.c and not
> fib_trie.c. The reason for the change will become even more apparent in
> follow-up patchset where we extend the FIB rules notifications.
>
> Second patch removes a redundant argument.
Looks good, series applied.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-03-10 17:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-10 7:56 [patch net-next 0/2] ipv4: fib: FIB notifications cleanup Jiri Pirko
2017-03-10 7:56 ` [patch net-next 1/2] ipv4: fib: Move FIB notification code to a separate file Jiri Pirko
2017-03-10 16:31 ` David Ahern
2017-03-10 7:56 ` [patch net-next 2/2] ipv4: fib: Remove redundant argument Jiri Pirko
2017-03-10 16:31 ` David Ahern
2017-03-10 17:45 ` [patch net-next 0/2] ipv4: fib: FIB notifications cleanup David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).