2006-01-03 02:04:38 +08:00
|
|
|
/*
|
|
|
|
* net/tipc/net.c: TIPC network routing code
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
tipc: introduce message evaluation function
When a message arrives in a node and finds no destination
socket, we may need to drop it, reject it, or forward it after
a secondary destination lookup. The latter two cases currently
results in a code path that is perceived as complex, because it
follows a deep call chain via obscure functions such as
net_route_named_msg() and net_route_msg().
We now introduce a function, tipc_msg_eval(), that takes the
decision about whether such a message should be rejected or
forwarded, but leaves it to the caller to actually perform
the indicated action.
If the decision is 'reject', it is still the task of the recently
introduced function tipc_msg_reverse() to take the final decision
about whether the message is rejectable or not. In the latter case
it drops the message.
As a result of this change, we can finally eliminate the function
net_route_named_msg(), and hence become independent of net_route_msg().
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-06-26 09:41:36 +08:00
|
|
|
* Copyright (c) 1995-2006, 2014, Ericsson AB
|
2011-02-25 02:20:20 +08:00
|
|
|
* Copyright (c) 2005, 2010-2011, Wind River Systems
|
2006-01-03 02:04:38 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
2006-01-11 20:30:43 +08:00
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the names of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed under the terms of the
|
|
|
|
* GNU General Public License ("GPL") version 2 as published by the Free
|
|
|
|
* Software Foundation.
|
2006-01-03 02:04:38 +08:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "name_distr.h"
|
|
|
|
#include "subscr.h"
|
2014-05-14 17:39:15 +08:00
|
|
|
#include "socket.h"
|
2011-02-26 07:42:52 +08:00
|
|
|
#include "node.h"
|
2015-05-14 22:46:13 +08:00
|
|
|
#include "bcast.h"
|
2016-03-05 00:04:42 +08:00
|
|
|
#include "netlink.h"
|
2014-11-20 17:29:18 +08:00
|
|
|
|
2007-02-09 22:25:21 +08:00
|
|
|
/*
|
2006-01-03 02:04:38 +08:00
|
|
|
* The TIPC locking policy is designed to ensure a very fine locking
|
|
|
|
* granularity, permitting complete parallel access to individual
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 10:55:48 +08:00
|
|
|
* port and node/link instances. The code consists of four major
|
2006-01-03 02:04:38 +08:00
|
|
|
* locking domains, each protected with their own disjunct set of locks.
|
|
|
|
*
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 10:55:48 +08:00
|
|
|
* 1: The bearer level.
|
|
|
|
* RTNL lock is used to serialize the process of configuring bearer
|
|
|
|
* on update side, and RCU lock is applied on read side to make
|
|
|
|
* bearer instance valid on both paths of message transmission and
|
|
|
|
* reception.
|
2006-01-03 02:04:38 +08:00
|
|
|
*
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 10:55:48 +08:00
|
|
|
* 2: The node and link level.
|
|
|
|
* All node instances are saved into two tipc_node_list and node_htable
|
|
|
|
* lists. The two lists are protected by node_list_lock on write side,
|
|
|
|
* and they are guarded with RCU lock on read side. Especially node
|
|
|
|
* instance is destroyed only when TIPC module is removed, and we can
|
|
|
|
* confirm that there has no any user who is accessing the node at the
|
|
|
|
* moment. Therefore, Except for iterating the two lists within RCU
|
|
|
|
* protection, it's no needed to hold RCU that we access node instance
|
|
|
|
* in other places.
|
2006-01-03 02:04:38 +08:00
|
|
|
*
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 10:55:48 +08:00
|
|
|
* In addition, all members in node structure including link instances
|
|
|
|
* are protected by node spin lock.
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 10:55:48 +08:00
|
|
|
* 3: The transport level of the protocol.
|
|
|
|
* This consists of the structures port, (and its user level
|
|
|
|
* representations, such as user_port and tipc_sock), reference and
|
|
|
|
* tipc_user (port.c, reg.c, socket.c).
|
2006-01-03 02:04:38 +08:00
|
|
|
*
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 10:55:48 +08:00
|
|
|
* This layer has four different locks:
|
2006-01-03 02:04:38 +08:00
|
|
|
* - The tipc_port spin_lock. This is protecting each port instance
|
2007-02-09 22:25:21 +08:00
|
|
|
* from parallel data access and removal. Since we can not place
|
|
|
|
* this lock in the port itself, it has been placed in the
|
2006-01-03 02:04:38 +08:00
|
|
|
* corresponding reference table entry, which has the same life
|
2007-02-09 22:25:21 +08:00
|
|
|
* cycle as the module. This entry is difficult to access from
|
|
|
|
* outside the TIPC core, however, so a pointer to the lock has
|
|
|
|
* been added in the port instance, -to be used for unlocking
|
2006-01-03 02:04:38 +08:00
|
|
|
* only.
|
2007-02-09 22:25:21 +08:00
|
|
|
* - A read/write lock to protect the reference table itself (teg.c).
|
|
|
|
* (Nobody is using read-only access to this, so it can just as
|
2006-01-03 02:04:38 +08:00
|
|
|
* well be changed to a spin_lock)
|
|
|
|
* - A spin lock to protect the registry of kernel/driver users (reg.c)
|
2007-02-09 22:25:21 +08:00
|
|
|
* - A global spin_lock (tipc_port_lock), which only task is to ensure
|
2006-01-03 02:04:38 +08:00
|
|
|
* consistency where more than one port is involved in an operation,
|
|
|
|
* i.e., whe a port is part of a linked list of ports.
|
|
|
|
* There are two such lists; 'port_list', which is used for management,
|
|
|
|
* and 'wait_list', which is used to queue ports during congestion.
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 10:55:48 +08:00
|
|
|
* 4: The name table (name_table.c, name_distr.c, subscription.c)
|
2007-02-09 22:25:21 +08:00
|
|
|
* - There is one big read/write-lock (tipc_nametbl_lock) protecting the
|
|
|
|
* overall name table structure. Nothing must be added/removed to
|
2006-01-03 02:04:38 +08:00
|
|
|
* this structure without holding write access to it.
|
|
|
|
* - There is one local spin_lock per sub_sequence, which can be seen
|
2006-01-18 07:38:21 +08:00
|
|
|
* as a sub-domain to the tipc_nametbl_lock domain. It is used only
|
2006-01-03 02:04:38 +08:00
|
|
|
* for translation operations, and is needed because a translation
|
|
|
|
* steps the root of the 'publication' linked list between each lookup.
|
2006-01-18 07:38:21 +08:00
|
|
|
* This is always used within the scope of a tipc_nametbl_lock(read).
|
2006-01-03 02:04:38 +08:00
|
|
|
* - A local spin_lock protecting the queue of subscriber events.
|
|
|
|
*/
|
|
|
|
|
2018-03-23 03:42:50 +08:00
|
|
|
int tipc_net_init(struct net *net, u8 *node_id, u32 addr)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2018-03-23 03:42:50 +08:00
|
|
|
if (tipc_own_id(net)) {
|
|
|
|
pr_info("Cannot configure node identity twice\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
pr_info("Started in network mode\n");
|
2006-01-03 02:04:38 +08:00
|
|
|
|
tipc: handle collisions of 32-bit node address hash values
When a 32-bit node address is generated from a 128-bit identifier,
there is a risk of collisions which must be discovered and handled.
We do this as follows:
- We don't apply the generated address immediately to the node, but do
instead initiate a 1 sec trial period to allow other cluster members
to discover and handle such collisions.
- During the trial period the node periodically sends out a new type
of message, DSC_TRIAL_MSG, using broadcast or emulated broadcast,
to all the other nodes in the cluster.
- When a node is receiving such a message, it must check that the
presented 32-bit identifier either is unused, or was used by the very
same peer in a previous session. In both cases it accepts the request
by not responding to it.
- If it finds that the same node has been up before using a different
address, it responds with a DSC_TRIAL_FAIL_MSG containing that
address.
- If it finds that the address has already been taken by some other
node, it generates a new, unused address and returns it to the
requester.
- During the trial period the requesting node must always be prepared
to accept a failure message, i.e., a message where a peer suggests a
different (or equal) address to the one tried. In those cases it
must apply the suggested value as trial address and restart the trial
period.
This algorithm ensures that in the vast majority of cases a node will
have the same address before and after a reboot. If a legacy user
configures the address explicitly, there will be no trial period and
messages, so this protocol addition is completely backwards compatible.
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-23 03:42:51 +08:00
|
|
|
if (node_id)
|
2018-03-23 03:42:50 +08:00
|
|
|
tipc_set_node_id(net, node_id);
|
|
|
|
if (addr)
|
|
|
|
tipc_net_finalize(net, addr);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-02-11 19:26:46 +08:00
|
|
|
|
2018-03-23 03:42:50 +08:00
|
|
|
void tipc_net_finalize(struct net *net, u32 addr)
|
|
|
|
{
|
|
|
|
tipc_set_node_addr(net, addr);
|
2017-02-11 19:26:46 +08:00
|
|
|
smp_mb();
|
2015-01-09 15:27:09 +08:00
|
|
|
tipc_named_reinit(net);
|
2015-01-09 15:27:08 +08:00
|
|
|
tipc_sk_reinit(net);
|
2018-03-23 03:42:49 +08:00
|
|
|
tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr,
|
|
|
|
TIPC_CLUSTER_SCOPE, 0, addr);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2015-01-09 15:27:05 +08:00
|
|
|
void tipc_net_stop(struct net *net)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2018-03-23 03:42:49 +08:00
|
|
|
u32 self = tipc_own_addr(net);
|
2015-01-09 15:27:10 +08:00
|
|
|
|
2018-03-23 03:42:49 +08:00
|
|
|
if (!self)
|
2006-01-03 02:04:38 +08:00
|
|
|
return;
|
2014-03-27 12:54:36 +08:00
|
|
|
|
2018-03-23 03:42:49 +08:00
|
|
|
tipc_nametbl_withdraw(net, TIPC_CFG_SRV, self, 0, self);
|
2014-04-21 10:55:44 +08:00
|
|
|
rtnl_lock();
|
2015-01-09 15:27:05 +08:00
|
|
|
tipc_bearer_stop(net);
|
|
|
|
tipc_node_stop(net);
|
2014-04-21 10:55:44 +08:00
|
|
|
rtnl_unlock();
|
2014-03-27 12:54:36 +08:00
|
|
|
|
2012-06-29 12:16:37 +08:00
|
|
|
pr_info("Left network mode\n");
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
2014-11-20 17:29:18 +08:00
|
|
|
|
2015-01-09 15:27:04 +08:00
|
|
|
static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg)
|
2014-11-20 17:29:18 +08:00
|
|
|
{
|
2015-01-09 15:27:04 +08:00
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2018-03-23 03:42:50 +08:00
|
|
|
u64 *w0 = (u64 *)&tn->node_id[0];
|
|
|
|
u64 *w1 = (u64 *)&tn->node_id[8];
|
2014-11-20 17:29:18 +08:00
|
|
|
struct nlattr *attrs;
|
2018-03-23 03:42:50 +08:00
|
|
|
void *hdr;
|
2014-11-20 17:29:18 +08:00
|
|
|
|
2015-02-09 16:50:03 +08:00
|
|
|
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
|
2014-11-20 17:29:18 +08:00
|
|
|
NLM_F_MULTI, TIPC_NL_NET_GET);
|
|
|
|
if (!hdr)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
attrs = nla_nest_start(msg->skb, TIPC_NLA_NET);
|
|
|
|
if (!attrs)
|
|
|
|
goto msg_full;
|
|
|
|
|
2015-01-09 15:27:04 +08:00
|
|
|
if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tn->net_id))
|
2014-11-20 17:29:18 +08:00
|
|
|
goto attr_msg_full;
|
2018-03-23 03:42:50 +08:00
|
|
|
if (nla_put_u64_64bit(msg->skb, TIPC_NLA_NET_NODEID, *w0, 0))
|
|
|
|
goto attr_msg_full;
|
|
|
|
if (nla_put_u64_64bit(msg->skb, TIPC_NLA_NET_NODEID_W1, *w1, 0))
|
|
|
|
goto attr_msg_full;
|
2014-11-20 17:29:18 +08:00
|
|
|
nla_nest_end(msg->skb, attrs);
|
|
|
|
genlmsg_end(msg->skb, hdr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
attr_msg_full:
|
|
|
|
nla_nest_cancel(msg->skb, attrs);
|
|
|
|
msg_full:
|
|
|
|
genlmsg_cancel(msg->skb, hdr);
|
|
|
|
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
2015-01-09 15:27:04 +08:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2014-11-20 17:29:18 +08:00
|
|
|
int err;
|
|
|
|
int done = cb->args[0];
|
|
|
|
struct tipc_nl_msg msg;
|
|
|
|
|
|
|
|
if (done)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
msg.skb = skb;
|
|
|
|
msg.portid = NETLINK_CB(cb->skb).portid;
|
|
|
|
msg.seq = cb->nlh->nlmsg_seq;
|
|
|
|
|
2015-01-09 15:27:04 +08:00
|
|
|
err = __tipc_nl_add_net(net, &msg);
|
2014-11-20 17:29:18 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
done = 1;
|
|
|
|
out:
|
|
|
|
cb->args[0] = done;
|
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
2014-11-20 17:29:19 +08:00
|
|
|
|
2018-02-14 13:38:03 +08:00
|
|
|
int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
|
2014-11-20 17:29:19 +08:00
|
|
|
{
|
|
|
|
struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
|
2018-03-23 03:42:49 +08:00
|
|
|
struct net *net = sock_net(skb->sk);
|
|
|
|
struct tipc_net *tn = tipc_net(net);
|
2015-01-09 15:27:04 +08:00
|
|
|
int err;
|
2014-11-20 17:29:19 +08:00
|
|
|
|
|
|
|
if (!info->attrs[TIPC_NLA_NET])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX,
|
2017-04-12 20:34:07 +08:00
|
|
|
info->attrs[TIPC_NLA_NET], tipc_nl_net_policy,
|
netlink: pass extended ACK struct where available
This is an add-on to the previous patch that passes the extended ACK
structure where it's already available by existing genl_info or extack
function arguments.
This was done with this spatch (with some manual adjustment of
indentation):
@@
expression A, B, C, D, E;
identifier fn, info;
@@
fn(..., struct genl_info *info, ...) {
...
-nlmsg_parse(A, B, C, D, E, NULL)
+nlmsg_parse(A, B, C, D, E, info->extack)
...
}
@@
expression A, B, C, D, E;
identifier fn, info;
@@
fn(..., struct genl_info *info, ...) {
<...
-nla_parse_nested(A, B, C, D, NULL)
+nla_parse_nested(A, B, C, D, info->extack)
...>
}
@@
expression A, B, C, D, E;
identifier fn, extack;
@@
fn(..., struct netlink_ext_ack *extack, ...) {
<...
-nlmsg_parse(A, B, C, D, E, NULL)
+nlmsg_parse(A, B, C, D, E, extack)
...>
}
@@
expression A, B, C, D, E;
identifier fn, extack;
@@
fn(..., struct netlink_ext_ack *extack, ...) {
<...
-nla_parse(A, B, C, D, E, NULL)
+nla_parse(A, B, C, D, E, extack)
...>
}
@@
expression A, B, C, D, E;
identifier fn, extack;
@@
fn(..., struct netlink_ext_ack *extack, ...) {
...
-nlmsg_parse(A, B, C, D, E, NULL)
+nlmsg_parse(A, B, C, D, E, extack)
...
}
@@
expression A, B, C, D;
identifier fn, extack;
@@
fn(..., struct netlink_ext_ack *extack, ...) {
<...
-nla_parse_nested(A, B, C, D, NULL)
+nla_parse_nested(A, B, C, D, extack)
...>
}
@@
expression A, B, C, D;
identifier fn, extack;
@@
fn(..., struct netlink_ext_ack *extack, ...) {
<...
-nlmsg_validate(A, B, C, D, NULL)
+nlmsg_validate(A, B, C, D, extack)
...>
}
@@
expression A, B, C, D;
identifier fn, extack;
@@
fn(..., struct netlink_ext_ack *extack, ...) {
<...
-nla_validate(A, B, C, D, NULL)
+nla_validate(A, B, C, D, extack)
...>
}
@@
expression A, B, C;
identifier fn, extack;
@@
fn(..., struct netlink_ext_ack *extack, ...) {
<...
-nla_validate_nested(A, B, C, NULL)
+nla_validate_nested(A, B, C, extack)
...>
}
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-04-12 20:34:08 +08:00
|
|
|
info->extack);
|
2018-03-23 03:42:50 +08:00
|
|
|
|
2014-11-20 17:29:19 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-03-23 03:42:49 +08:00
|
|
|
/* Can't change net id once TIPC has joined a network */
|
|
|
|
if (tipc_own_addr(net))
|
|
|
|
return -EPERM;
|
|
|
|
|
2014-11-20 17:29:19 +08:00
|
|
|
if (attrs[TIPC_NLA_NET_ID]) {
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = nla_get_u32(attrs[TIPC_NLA_NET_ID]);
|
|
|
|
if (val < 1 || val > 9999)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2015-01-09 15:27:04 +08:00
|
|
|
tn->net_id = val;
|
2014-11-20 17:29:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attrs[TIPC_NLA_NET_ADDR]) {
|
|
|
|
u32 addr;
|
|
|
|
|
|
|
|
addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
|
tipc: remove restrictions on node address values
Nominally, TIPC organizes network nodes into a three-level network
hierarchy consisting of the levels 'zone', 'cluster' and 'node'. This
hierarchy is reflected in the node address format, - it is sub-divided
into an 8-bit zone id, and 12 bit cluster id, and a 12-bit node id.
However, the 'zone' and 'cluster' levels have in reality never been
fully implemented,and never will be. The result of this has been
that the first 20 bits the node identity structure have been wasted,
and the usable node identity range within a cluster has been limited
to 12 bits. This is starting to become a problem.
In the following commits, we will need to be able to connect between
nodes which are using the whole 32-bit value space of the node address.
We therefore remove the restrictions on which values can be assigned
to node identity, -it is from now on only a 32-bit integer with no
assumed internal structure.
Isolation between clusters is now achieved only by setting different
values for the 'network id' field used during neighbor discovery, in
practice leading to the latter becoming the new cluster identity.
The rules for accepting discovery requests/responses from neighboring
nodes now become:
- If the user is using legacy address format on both peers, reception
of discovery messages is subject to the legacy lookup domain check
in addition to the cluster id check.
- Otherwise, the discovery request/response is always accepted, provided
both peers have the same network id.
This secures backwards compatibility for users who have been using zone
or cluster identities as cluster separators, instead of the intended
'network id'.
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-23 03:42:47 +08:00
|
|
|
if (!addr)
|
2014-11-20 17:29:19 +08:00
|
|
|
return -EINVAL;
|
tipc: allow closest-first lookup algorithm when legacy address is configured
The removal of an internal structure of the node address has an unwanted
side effect.
- Currently, if a user is sending an anycast message with destination
domain 0, the tipc_namebl_translate() function will use the 'closest-
first' algorithm to first look for a node local destination, and only
when no such is found, will it resort to the cluster global 'round-
robin' lookup algorithm.
- Current users can get around this, and enforce unconditional use of
global round-robin by indicating a destination as Z.0.0 or Z.C.0.
- This option disappears when we make the node address flat, since the
lookup algorithm has no way of recognizing this case. So, as long as
there are node local destinations, the algorithm will always select
one of those, and there is nothing the sender can do to change this.
We solve this by eliminating the 'closest-first' option, which was never
a good idea anyway, for non-legacy users, but only for those. To
distinguish between legacy users and non-legacy users we introduce a new
flag 'legacy_addr_format' in struct tipc_core, to be set when the user
configures a legacy-style Z.C.N node address. Hence, when a legacy user
indicates a zero lookup domain 'closest-first' is selected, and in all
other cases we use 'round-robin'.
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-23 03:42:48 +08:00
|
|
|
tn->legacy_addr_format = true;
|
2018-03-23 03:42:50 +08:00
|
|
|
tipc_net_init(net, NULL, addr);
|
2014-11-20 17:29:19 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 03:42:50 +08:00
|
|
|
if (attrs[TIPC_NLA_NET_NODEID]) {
|
|
|
|
u8 node_id[NODE_ID_LEN];
|
|
|
|
u64 *w0 = (u64 *)&node_id[0];
|
|
|
|
u64 *w1 = (u64 *)&node_id[8];
|
|
|
|
|
|
|
|
*w0 = nla_get_u64(attrs[TIPC_NLA_NET_NODEID]);
|
|
|
|
*w1 = nla_get_u64(attrs[TIPC_NLA_NET_NODEID_W1]);
|
|
|
|
tipc_net_init(net, node_id, 0);
|
|
|
|
}
|
2014-11-20 17:29:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2018-02-14 13:38:03 +08:00
|
|
|
|
|
|
|
int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
err = __tipc_nl_net_set(skb, info);
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|