diff options
author | Jon Maloy <jon.maloy@ericsson.com> | 2018-07-06 14:10:06 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-07-07 06:49:02 -0400 |
commit | 9faa89d4ed9d7d326f4763d262842270450f9b1f (patch) | |
tree | 7d2f742a0a79418fa0b8388e0b4d19847d58298a | |
parent | 92018c7ca959ccd346d6235dac03cf7fc1ba51f7 (diff) |
tipc: make function tipc_net_finalize() thread safe
The setting of the node address is not thread safe, meaning that
two discoverers may decide to set it simultanously, with a duplicate
entry in the name table as result. We fix that with this commit.
Fixes: 25b0b9c4e835 ("tipc: handle collisions of 32-bit node address hash values")
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/tipc/net.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/net/tipc/net.c b/net/tipc/net.c index 4fbaa0464405..a7f6964c3a4b 100644 --- a/net/tipc/net.c +++ b/net/tipc/net.c | |||
@@ -121,12 +121,17 @@ int tipc_net_init(struct net *net, u8 *node_id, u32 addr) | |||
121 | 121 | ||
122 | void tipc_net_finalize(struct net *net, u32 addr) | 122 | void tipc_net_finalize(struct net *net, u32 addr) |
123 | { | 123 | { |
124 | tipc_set_node_addr(net, addr); | 124 | struct tipc_net *tn = tipc_net(net); |
125 | smp_mb(); | 125 | |
126 | tipc_named_reinit(net); | 126 | spin_lock_bh(&tn->node_list_lock); |
127 | tipc_sk_reinit(net); | 127 | if (!tipc_own_addr(net)) { |
128 | tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr, | 128 | tipc_set_node_addr(net, addr); |
129 | TIPC_CLUSTER_SCOPE, 0, addr); | 129 | tipc_named_reinit(net); |
130 | tipc_sk_reinit(net); | ||
131 | tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr, | ||
132 | TIPC_CLUSTER_SCOPE, 0, addr); | ||
133 | } | ||
134 | spin_unlock_bh(&tn->node_list_lock); | ||
130 | } | 135 | } |
131 | 136 | ||
132 | void tipc_net_stop(struct net *net) | 137 | void tipc_net_stop(struct net *net) |