2006-01-02 18:04:38 +00:00
|
|
|
/*
|
|
|
|
* net/tipc/net.c: TIPC network routing code
|
2007-02-09 14:25:21 +00: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 01:41:36 +00:00
|
|
|
* Copyright (c) 1995-2006, 2014, Ericsson AB
|
2011-02-24 18:20:20 +00:00
|
|
|
* Copyright (c) 2005, 2010-2011, Wind River Systems
|
2006-01-02 18:04:38 +00: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 12:30:43 +00: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-02 18:04:38 +00: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 09:39:15 +00:00
|
|
|
#include "socket.h"
|
2011-02-25 23:42:52 +00:00
|
|
|
#include "node.h"
|
2015-05-14 14:46:13 +00:00
|
|
|
#include "bcast.h"
|
2016-03-04 16:04:42 +00:00
|
|
|
#include "netlink.h"
|
2014-11-20 09:29:18 +00:00
|
|
|
|
2007-02-09 14:25:21 +00:00
|
|
|
/*
|
2006-01-02 18:04:38 +00: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 02:55:48 +00:00
|
|
|
* port and node/link instances. The code consists of four major
|
2006-01-02 18:04:38 +00: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 02:55:48 +00: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-02 18:04:38 +00: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 02:55:48 +00: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-02 18:04:38 +00: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 02:55:48 +00:00
|
|
|
* In addition, all members in node structure including link instances
|
|
|
|
* are protected by node spin lock.
|
2007-02-09 14:25:21 +00: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 02:55:48 +00: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-02 18:04:38 +00: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 02:55:48 +00:00
|
|
|
* This layer has four different locks:
|
2006-01-02 18:04:38 +00:00
|
|
|
* - The tipc_port spin_lock. This is protecting each port instance
|
2007-02-09 14:25:21 +00: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-02 18:04:38 +00:00
|
|
|
* corresponding reference table entry, which has the same life
|
2007-02-09 14:25:21 +00: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-02 18:04:38 +00:00
|
|
|
* only.
|
2007-02-09 14:25:21 +00: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-02 18:04:38 +00:00
|
|
|
* well be changed to a spin_lock)
|
|
|
|
* - A spin lock to protect the registry of kernel/driver users (reg.c)
|
2007-02-09 14:25:21 +00:00
|
|
|
* - A global spin_lock (tipc_port_lock), which only task is to ensure
|
2006-01-02 18:04:38 +00: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 14:25:21 +00: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 02:55:48 +00:00
|
|
|
* 4: The name table (name_table.c, name_distr.c, subscription.c)
|
2007-02-09 14:25:21 +00: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-02 18:04:38 +00:00
|
|
|
* this structure without holding write access to it.
|
|
|
|
* - There is one local spin_lock per sub_sequence, which can be seen
|
2006-01-17 23:38:21 +00:00
|
|
|
* as a sub-domain to the tipc_nametbl_lock domain. It is used only
|
2006-01-02 18:04:38 +00:00
|
|
|
* for translation operations, and is needed because a translation
|
|
|
|
* steps the root of the 'publication' linked list between each lookup.
|
2006-01-17 23:38:21 +00:00
|
|
|
* This is always used within the scope of a tipc_nametbl_lock(read).
|
2006-01-02 18:04:38 +00:00
|
|
|
* - A local spin_lock protecting the queue of subscriber events.
|
|
|
|
*/
|
|
|
|
|
2018-11-16 21:55:04 +00:00
|
|
|
struct tipc_net_work {
|
|
|
|
struct work_struct work;
|
|
|
|
struct net *net;
|
|
|
|
u32 addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void tipc_net_finalize(struct net *net, u32 addr);
|
|
|
|
|
2018-03-22 19:42:50 +00:00
|
|
|
int tipc_net_init(struct net *net, u8 *node_id, u32 addr)
|
2006-01-02 18:04:38 +00:00
|
|
|
{
|
2018-03-22 19:42:50 +00: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-02 18:04:38 +00: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-22 19:42:51 +00:00
|
|
|
if (node_id)
|
2018-03-22 19:42:50 +00:00
|
|
|
tipc_set_node_id(net, node_id);
|
|
|
|
if (addr)
|
|
|
|
tipc_net_finalize(net, addr);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-02-11 11:26:46 +00:00
|
|
|
|
2018-11-16 21:55:04 +00:00
|
|
|
static void tipc_net_finalize(struct net *net, u32 addr)
|
2018-03-22 19:42:50 +00:00
|
|
|
{
|
2018-07-06 18:10:06 +00:00
|
|
|
struct tipc_net *tn = tipc_net(net);
|
|
|
|
|
2018-11-16 21:55:04 +00:00
|
|
|
if (cmpxchg(&tn->node_addr, 0, addr))
|
|
|
|
return;
|
|
|
|
tipc_set_node_addr(net, addr);
|
|
|
|
tipc_named_reinit(net);
|
|
|
|
tipc_sk_reinit(net);
|
|
|
|
tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr,
|
|
|
|
TIPC_CLUSTER_SCOPE, 0, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tipc_net_finalize_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct tipc_net_work *fwork;
|
|
|
|
|
|
|
|
fwork = container_of(work, struct tipc_net_work, work);
|
|
|
|
tipc_net_finalize(fwork->net, fwork->addr);
|
|
|
|
kfree(fwork);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tipc_sched_net_finalize(struct net *net, u32 addr)
|
|
|
|
{
|
|
|
|
struct tipc_net_work *fwork = kzalloc(sizeof(*fwork), GFP_ATOMIC);
|
|
|
|
|
|
|
|
if (!fwork)
|
|
|
|
return;
|
|
|
|
INIT_WORK(&fwork->work, tipc_net_finalize_work);
|
|
|
|
fwork->net = net;
|
|
|
|
fwork->addr = addr;
|
|
|
|
schedule_work(&fwork->work);
|
2006-01-02 18:04:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 07:27:05 +00:00
|
|
|
void tipc_net_stop(struct net *net)
|
2006-01-02 18:04:38 +00:00
|
|
|
{
|
2019-03-23 16:48:22 +00:00
|
|
|
if (!tipc_own_id(net))
|
2006-01-02 18:04:38 +00:00
|
|
|
return;
|
2014-03-27 04:54:36 +00:00
|
|
|
|
2014-04-21 02:55:44 +00:00
|
|
|
rtnl_lock();
|
2015-01-09 07:27:05 +00:00
|
|
|
tipc_bearer_stop(net);
|
|
|
|
tipc_node_stop(net);
|
2014-04-21 02:55:44 +00:00
|
|
|
rtnl_unlock();
|
2014-03-27 04:54:36 +00:00
|
|
|
|
2012-06-29 04:16:37 +00:00
|
|
|
pr_info("Left network mode\n");
|
2006-01-02 18:04:38 +00:00
|
|
|
}
|
2014-11-20 09:29:18 +00:00
|
|
|
|
2015-01-09 07:27:04 +00:00
|
|
|
static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg)
|
2014-11-20 09:29:18 +00:00
|
|
|
{
|
2015-01-09 07:27:04 +00:00
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2018-03-22 19:42:50 +00:00
|
|
|
u64 *w0 = (u64 *)&tn->node_id[0];
|
|
|
|
u64 *w1 = (u64 *)&tn->node_id[8];
|
2014-11-20 09:29:18 +00:00
|
|
|
struct nlattr *attrs;
|
2018-03-22 19:42:50 +00:00
|
|
|
void *hdr;
|
2014-11-20 09:29:18 +00:00
|
|
|
|
2015-02-09 08:50:03 +00:00
|
|
|
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
|
2014-11-20 09:29:18 +00:00
|
|
|
NLM_F_MULTI, TIPC_NL_NET_GET);
|
|
|
|
if (!hdr)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
2019-04-26 09:13:06 +00:00
|
|
|
attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_NET);
|
2014-11-20 09:29:18 +00:00
|
|
|
if (!attrs)
|
|
|
|
goto msg_full;
|
|
|
|
|
2015-01-09 07:27:04 +00:00
|
|
|
if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tn->net_id))
|
2014-11-20 09:29:18 +00:00
|
|
|
goto attr_msg_full;
|
2018-03-22 19:42:50 +00: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 09:29:18 +00: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 07:27:04 +00:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2014-11-20 09:29:18 +00: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 07:27:04 +00:00
|
|
|
err = __tipc_nl_add_net(net, &msg);
|
2014-11-20 09:29:18 +00:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
done = 1;
|
|
|
|
out:
|
|
|
|
cb->args[0] = done;
|
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
2014-11-20 09:29:19 +00:00
|
|
|
|
2018-02-14 05:38:03 +00:00
|
|
|
int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
|
2014-11-20 09:29:19 +00:00
|
|
|
{
|
|
|
|
struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
|
2018-03-22 19:42:49 +00:00
|
|
|
struct net *net = sock_net(skb->sk);
|
|
|
|
struct tipc_net *tn = tipc_net(net);
|
2015-01-09 07:27:04 +00:00
|
|
|
int err;
|
2014-11-20 09:29:19 +00:00
|
|
|
|
|
|
|
if (!info->attrs[TIPC_NLA_NET])
|
|
|
|
return -EINVAL;
|
|
|
|
|
netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:
1) liberal (default)
- undefined (type >= max) & NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
- garbage at end of message accepted
2) strict (opt-in)
- NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
Split out parsing strictness into four different options:
* TRAILING - check that there's no trailing data after parsing
attributes (in message or nested)
* MAXTYPE - reject attrs > max known type
* UNSPEC - reject attributes with NLA_UNSPEC policy entries
* STRICT_ATTRS - strictly validate attribute size
The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().
Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.
We end up with the following renames:
* nla_parse -> nla_parse_deprecated
* nla_parse_strict -> nla_parse_deprecated_strict
* nlmsg_parse -> nlmsg_parse_deprecated
* nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
* nla_parse_nested -> nla_parse_nested_deprecated
* nla_validate_nested -> nla_validate_nested_deprecated
Using spatch, of course:
@@
expression TB, MAX, HEAD, LEN, POL, EXT;
@@
-nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
+nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression TB, MAX, NLA, POL, EXT;
@@
-nla_parse_nested(TB, MAX, NLA, POL, EXT)
+nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
@@
expression START, MAX, POL, EXT;
@@
-nla_validate_nested(START, MAX, POL, EXT)
+nla_validate_nested_deprecated(START, MAX, POL, EXT)
@@
expression NLH, HDRLEN, MAX, POL, EXT;
@@
-nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
+nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.
Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.
Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.
In effect then, this adds fully strict validation for any new command.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-26 12:07:28 +00:00
|
|
|
err = nla_parse_nested_deprecated(attrs, TIPC_NLA_NET_MAX,
|
|
|
|
info->attrs[TIPC_NLA_NET],
|
|
|
|
tipc_nl_net_policy, info->extack);
|
2018-03-22 19:42:50 +00:00
|
|
|
|
2014-11-20 09:29:19 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-03-22 19:42:49 +00:00
|
|
|
/* Can't change net id once TIPC has joined a network */
|
|
|
|
if (tipc_own_addr(net))
|
|
|
|
return -EPERM;
|
|
|
|
|
2014-11-20 09:29:19 +00: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 07:27:04 +00:00
|
|
|
tn->net_id = val;
|
2014-11-20 09:29:19 +00: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-22 19:42:47 +00:00
|
|
|
if (!addr)
|
2014-11-20 09:29:19 +00: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-22 19:42:48 +00:00
|
|
|
tn->legacy_addr_format = true;
|
2018-03-22 19:42:50 +00:00
|
|
|
tipc_net_init(net, NULL, addr);
|
2014-11-20 09:29:19 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 19:42:50 +00: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];
|
|
|
|
|
2018-04-16 15:29:43 +00:00
|
|
|
if (!attrs[TIPC_NLA_NET_NODEID_W1])
|
|
|
|
return -EINVAL;
|
2018-03-22 19:42:50 +00:00
|
|
|
*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 09:29:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-02-14 05:38:03 +00: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;
|
|
|
|
}
|