2006-01-03 02:04:38 +08:00
|
|
|
/*
|
|
|
|
* net/tipc/discover.c
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
2014-05-14 17:39:14 +08:00
|
|
|
* Copyright (c) 2003-2006, 2014, Ericsson AB
|
2011-01-08 02:00:11 +08:00
|
|
|
* Copyright (c) 2005-2006, 2010-2011, Wind River Systems
|
2006-01-03 02:04:38 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2006-01-11 20:30:43 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2006-01-03 02:04:38 +08:00
|
|
|
* 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.
|
2006-01-03 02:04:38 +08:00
|
|
|
*
|
2006-01-11 20:30:43 +08:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
2006-01-03 02:04:38 +08:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
#include "link.h"
|
|
|
|
#include "discover.h"
|
|
|
|
|
2015-01-09 15:27:00 +08:00
|
|
|
/* min delay during bearer start up */
|
|
|
|
#define TIPC_LINK_REQ_INIT msecs_to_jiffies(125)
|
|
|
|
/* max delay if bearer has no links */
|
|
|
|
#define TIPC_LINK_REQ_FAST msecs_to_jiffies(1000)
|
|
|
|
/* max delay if bearer has links */
|
|
|
|
#define TIPC_LINK_REQ_SLOW msecs_to_jiffies(60000)
|
|
|
|
/* indicates no timer in use */
|
|
|
|
#define TIPC_LINK_REQ_INACTIVE 0xffffffff
|
2006-01-03 02:04:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-12-30 09:58:42 +08:00
|
|
|
* struct tipc_link_req - information about an ongoing link setup request
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
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:46 +08:00
|
|
|
* @bearer_id: identity of bearer issuing requests
|
2006-01-03 02:04:38 +08:00
|
|
|
* @dest: destination address for request messages
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
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:46 +08:00
|
|
|
* @domain: network domain to which links can be established
|
2011-04-22 08:05:25 +08:00
|
|
|
* @num_nodes: number of nodes currently discovered (i.e. with an active link)
|
2014-01-08 06:02:43 +08:00
|
|
|
* @lock: spinlock for controlling access to requests
|
2006-01-03 02:04:38 +08:00
|
|
|
* @buf: request message to be (repeatedly) sent
|
|
|
|
* @timer: timer governing period between requests
|
|
|
|
* @timer_intv: current interval between requests (in ms)
|
|
|
|
*/
|
2011-12-30 09:58:42 +08:00
|
|
|
struct tipc_link_req {
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
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:46 +08:00
|
|
|
u32 bearer_id;
|
2006-01-03 02:04:38 +08:00
|
|
|
struct tipc_media_addr dest;
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
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:46 +08:00
|
|
|
u32 domain;
|
2011-04-22 08:05:25 +08:00
|
|
|
int num_nodes;
|
2014-01-08 06:02:43 +08:00
|
|
|
spinlock_t lock;
|
2006-01-03 02:04:38 +08:00
|
|
|
struct sk_buff *buf;
|
|
|
|
struct timer_list timer;
|
2015-01-09 15:27:00 +08:00
|
|
|
unsigned long timer_intv;
|
2006-01-03 02:04:38 +08:00
|
|
|
};
|
|
|
|
|
2007-02-09 22:25:21 +08:00
|
|
|
/**
|
2006-01-18 07:38:21 +08:00
|
|
|
* tipc_disc_init_msg - initialize a link setup message
|
2015-01-09 15:27:04 +08:00
|
|
|
* @net: the applicable net namespace
|
2006-01-03 02:04:38 +08:00
|
|
|
* @type: message type (request or response)
|
|
|
|
* @b_ptr: ptr to bearer issuing message
|
|
|
|
*/
|
2015-01-09 15:27:04 +08:00
|
|
|
static void tipc_disc_init_msg(struct net *net, struct sk_buff *buf, u32 type,
|
2014-04-21 10:55:52 +08:00
|
|
|
struct tipc_bearer *b_ptr)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2015-01-09 15:27:04 +08:00
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2006-01-03 02:04:38 +08:00
|
|
|
struct tipc_msg *msg;
|
2014-03-28 17:32:09 +08:00
|
|
|
u32 dest_domain = b_ptr->domain;
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2014-04-21 10:55:52 +08:00
|
|
|
msg = buf_msg(buf);
|
|
|
|
tipc_msg_init(msg, LINK_CONFIG, type, INT_H_SIZE, dest_domain);
|
|
|
|
msg_set_non_seq(msg, 1);
|
|
|
|
msg_set_node_sig(msg, tipc_random);
|
|
|
|
msg_set_dest_domain(msg, dest_domain);
|
2015-01-09 15:27:04 +08:00
|
|
|
msg_set_bc_netid(msg, tn->net_id);
|
tipc: improve and extend media address conversion functions
TIPC currently handles two media specific addresses: Ethernet MAC
addresses and InfiniBand addresses. Those are kept in three different
formats:
1) A "raw" format as obtained from the device. This format is known
only by the media specific adapter code in eth_media.c and
ib_media.c.
2) A "generic" internal format, in the form of struct tipc_media_addr,
which can be referenced and passed around by the generic media-
unaware code.
3) A serialized version of the latter, to be conveyed in neighbor
discovery messages.
Conversion between the three formats can only be done by the media
specific code, so we have function pointers for this purpose in
struct tipc_media. Here, the media adapters can install their own
conversion functions at startup.
We now introduce a new such function, 'raw2addr()', whose purpose
is to convert from format 1 to format 2 above. We also try to as far
as possible uniform commenting, variable names and usage of these
functions, with the purpose of making them more comprehensible.
We can now also remove the function tipc_l2_media_addr_set(), whose
job is done better by the new function.
Finally, we expand the field for serialized addresses (format 3)
in discovery messages from 20 to 32 bytes. This is permitted
according to the spec, and reduces the risk of problems when we
add new media in the future.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-05-14 17:39:13 +08:00
|
|
|
b_ptr->media->addr2msg(msg_media_addr(msg), &b_ptr->addr);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2006-10-17 12:44:59 +08:00
|
|
|
/**
|
|
|
|
* disc_dupl_alert - issue node address duplication alert
|
|
|
|
* @b_ptr: pointer to bearer detecting duplication
|
|
|
|
* @node_addr: duplicated node address
|
|
|
|
* @media_addr: media address advertised by duplicated node
|
|
|
|
*/
|
2011-01-08 02:00:11 +08:00
|
|
|
static void disc_dupl_alert(struct tipc_bearer *b_ptr, u32 node_addr,
|
2006-10-17 12:44:59 +08:00
|
|
|
struct tipc_media_addr *media_addr)
|
|
|
|
{
|
|
|
|
char node_addr_str[16];
|
|
|
|
char media_addr_str[64];
|
|
|
|
|
2010-05-11 22:30:12 +08:00
|
|
|
tipc_addr_string_fill(node_addr_str, node_addr);
|
2012-06-29 12:50:23 +08:00
|
|
|
tipc_media_addr_printf(media_addr_str, sizeof(media_addr_str),
|
|
|
|
media_addr);
|
2012-06-29 12:16:37 +08:00
|
|
|
pr_warn("Duplicate %s using %s seen on <%s>\n", node_addr_str,
|
|
|
|
media_addr_str, b_ptr->name);
|
2006-10-17 12:44:59 +08:00
|
|
|
}
|
|
|
|
|
2006-01-03 02:04:38 +08:00
|
|
|
/**
|
2014-05-14 17:39:14 +08:00
|
|
|
* tipc_disc_rcv - handle incoming discovery message (request or response)
|
2015-01-09 15:27:04 +08:00
|
|
|
* @net: the applicable net namespace
|
2006-01-03 02:04:38 +08:00
|
|
|
* @buf: buffer containing message
|
2014-05-14 17:39:14 +08:00
|
|
|
* @bearer: bearer that message arrived on
|
2006-01-03 02:04:38 +08:00
|
|
|
*/
|
2015-01-09 15:27:04 +08:00
|
|
|
void tipc_disc_rcv(struct net *net, struct sk_buff *buf,
|
|
|
|
struct tipc_bearer *bearer)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2015-01-09 15:27:04 +08:00
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2014-05-14 17:39:14 +08:00
|
|
|
struct tipc_node *node;
|
2011-12-30 09:58:42 +08:00
|
|
|
struct tipc_link *link;
|
2014-05-14 17:39:14 +08:00
|
|
|
struct tipc_media_addr maddr;
|
2011-02-28 23:03:05 +08:00
|
|
|
struct sk_buff *rbuf;
|
2006-01-03 02:04:38 +08:00
|
|
|
struct tipc_msg *msg = buf_msg(buf);
|
2014-05-14 17:39:14 +08:00
|
|
|
u32 ddom = msg_dest_domain(msg);
|
|
|
|
u32 onode = msg_prevnode(msg);
|
2006-01-03 02:04:38 +08:00
|
|
|
u32 net_id = msg_bc_netid(msg);
|
2014-05-14 17:39:14 +08:00
|
|
|
u32 mtyp = msg_type(msg);
|
2011-10-29 04:26:41 +08:00
|
|
|
u32 signature = msg_node_sig(msg);
|
2014-05-14 17:39:14 +08:00
|
|
|
bool addr_match = false;
|
|
|
|
bool sign_match = false;
|
|
|
|
bool link_up = false;
|
|
|
|
bool accept_addr = false;
|
|
|
|
bool accept_sign = false;
|
|
|
|
bool respond = false;
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2014-05-14 17:39:14 +08:00
|
|
|
bearer->media->msg2addr(bearer, &maddr, msg_media_addr(msg));
|
2011-11-05 01:24:29 +08:00
|
|
|
kfree_skb(buf);
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2011-10-29 05:30:08 +08:00
|
|
|
/* Ensure message from node is valid and communication is permitted */
|
2015-01-09 15:27:04 +08:00
|
|
|
if (net_id != tn->net_id)
|
2006-01-03 02:04:38 +08:00
|
|
|
return;
|
2014-05-14 17:39:14 +08:00
|
|
|
if (maddr.broadcast)
|
2011-10-08 03:48:41 +08:00
|
|
|
return;
|
2014-05-14 17:39:14 +08:00
|
|
|
if (!tipc_addr_domain_valid(ddom))
|
2006-01-03 02:04:38 +08:00
|
|
|
return;
|
2014-05-14 17:39:14 +08:00
|
|
|
if (!tipc_addr_node_valid(onode))
|
2006-01-03 02:04:38 +08:00
|
|
|
return;
|
2014-05-14 17:39:14 +08:00
|
|
|
|
|
|
|
if (in_own_node(onode)) {
|
|
|
|
if (memcmp(&maddr, &bearer->addr, sizeof(maddr)))
|
|
|
|
disc_dupl_alert(bearer, tipc_own_addr, &maddr);
|
2006-01-03 02:04:38 +08:00
|
|
|
return;
|
2006-10-17 12:44:59 +08:00
|
|
|
}
|
2014-05-14 17:39:14 +08:00
|
|
|
if (!tipc_in_scope(ddom, tipc_own_addr))
|
2006-01-03 02:04:38 +08:00
|
|
|
return;
|
2014-05-14 17:39:14 +08:00
|
|
|
if (!tipc_in_scope(bearer->domain, onode))
|
2011-02-28 23:03:05 +08:00
|
|
|
return;
|
2010-08-17 19:00:16 +08:00
|
|
|
|
2014-05-14 17:39:14 +08:00
|
|
|
/* Locate, or if necessary, create, node: */
|
|
|
|
node = tipc_node_find(onode);
|
|
|
|
if (!node)
|
|
|
|
node = tipc_node_create(onode);
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tipc_node_lock(node);
|
|
|
|
link = node->links[bearer->identity];
|
2011-02-28 23:03:05 +08:00
|
|
|
|
2011-10-29 05:30:08 +08:00
|
|
|
/* Prepare to validate requesting node's signature and media address */
|
2014-05-14 17:39:14 +08:00
|
|
|
sign_match = (signature == node->signature);
|
|
|
|
addr_match = link && !memcmp(&link->media_addr, &maddr, sizeof(maddr));
|
|
|
|
link_up = link && tipc_link_is_up(link);
|
2011-02-28 23:03:05 +08:00
|
|
|
|
2011-10-29 05:30:08 +08:00
|
|
|
|
2014-05-14 17:39:14 +08:00
|
|
|
/* These three flags give us eight permutations: */
|
2011-02-28 23:03:05 +08:00
|
|
|
|
2014-05-14 17:39:14 +08:00
|
|
|
if (sign_match && addr_match && link_up) {
|
|
|
|
/* All is fine. Do nothing. */
|
|
|
|
} else if (sign_match && addr_match && !link_up) {
|
|
|
|
/* Respond. The link will come up in due time */
|
|
|
|
respond = true;
|
|
|
|
} else if (sign_match && !addr_match && link_up) {
|
|
|
|
/* Peer has changed i/f address without rebooting.
|
|
|
|
* If so, the link will reset soon, and the next
|
|
|
|
* discovery will be accepted. So we can ignore it.
|
|
|
|
* It may also be an cloned or malicious peer having
|
|
|
|
* chosen the same node address and signature as an
|
|
|
|
* existing one.
|
|
|
|
* Ignore requests until the link goes down, if ever.
|
|
|
|
*/
|
|
|
|
disc_dupl_alert(bearer, onode, &maddr);
|
|
|
|
} else if (sign_match && !addr_match && !link_up) {
|
|
|
|
/* Peer link has changed i/f address without rebooting.
|
|
|
|
* It may also be a cloned or malicious peer; we can't
|
|
|
|
* distinguish between the two.
|
|
|
|
* The signature is correct, so we must accept.
|
|
|
|
*/
|
|
|
|
accept_addr = true;
|
|
|
|
respond = true;
|
|
|
|
} else if (!sign_match && addr_match && link_up) {
|
|
|
|
/* Peer node rebooted. Two possibilities:
|
|
|
|
* - Delayed re-discovery; this link endpoint has already
|
|
|
|
* reset and re-established contact with the peer, before
|
|
|
|
* receiving a discovery message from that node.
|
|
|
|
* (The peer happened to receive one from this node first).
|
|
|
|
* - The peer came back so fast that our side has not
|
|
|
|
* discovered it yet. Probing from this side will soon
|
|
|
|
* reset the link, since there can be no working link
|
|
|
|
* endpoint at the peer end, and the link will re-establish.
|
|
|
|
* Accept the signature, since it comes from a known peer.
|
|
|
|
*/
|
|
|
|
accept_sign = true;
|
|
|
|
} else if (!sign_match && addr_match && !link_up) {
|
|
|
|
/* The peer node has rebooted.
|
|
|
|
* Accept signature, since it is a known peer.
|
|
|
|
*/
|
|
|
|
accept_sign = true;
|
|
|
|
respond = true;
|
|
|
|
} else if (!sign_match && !addr_match && link_up) {
|
|
|
|
/* Peer rebooted with new address, or a new/duplicate peer.
|
|
|
|
* Ignore until the link goes down, if ever.
|
|
|
|
*/
|
|
|
|
disc_dupl_alert(bearer, onode, &maddr);
|
|
|
|
} else if (!sign_match && !addr_match && !link_up) {
|
|
|
|
/* Peer rebooted with new address, or it is a new peer.
|
|
|
|
* Accept signature and address.
|
|
|
|
*/
|
|
|
|
accept_sign = true;
|
|
|
|
accept_addr = true;
|
|
|
|
respond = true;
|
2011-10-29 05:30:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-14 17:39:14 +08:00
|
|
|
if (accept_sign)
|
|
|
|
node->signature = signature;
|
|
|
|
|
|
|
|
if (accept_addr) {
|
|
|
|
if (!link)
|
|
|
|
link = tipc_link_create(node, bearer, &maddr);
|
|
|
|
if (link) {
|
|
|
|
memcpy(&link->media_addr, &maddr, sizeof(maddr));
|
|
|
|
tipc_link_reset(link);
|
|
|
|
} else {
|
|
|
|
respond = false;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
2011-02-28 23:03:05 +08:00
|
|
|
}
|
|
|
|
|
2014-05-14 17:39:14 +08:00
|
|
|
/* Send response, if necessary */
|
|
|
|
if (respond && (mtyp == DSC_REQ_MSG)) {
|
2014-04-21 10:55:52 +08:00
|
|
|
rbuf = tipc_buf_acquire(INT_H_SIZE);
|
2011-02-28 23:56:23 +08:00
|
|
|
if (rbuf) {
|
2015-01-09 15:27:04 +08:00
|
|
|
tipc_disc_init_msg(net, rbuf, DSC_RESP_MSG, bearer);
|
2014-05-14 17:39:14 +08:00
|
|
|
tipc_bearer_send(bearer->identity, rbuf, &maddr);
|
2011-11-05 01:24:29 +08:00
|
|
|
kfree_skb(rbuf);
|
2011-02-28 23:56:23 +08:00
|
|
|
}
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
2014-05-14 17:39:14 +08:00
|
|
|
tipc_node_unlock(node);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-22 08:05:25 +08:00
|
|
|
* disc_update - update frequency of periodic link setup requests
|
2006-01-03 02:04:38 +08:00
|
|
|
* @req: ptr to link request structure
|
2011-04-22 09:34:03 +08:00
|
|
|
*
|
|
|
|
* Reinitiates discovery process if discovery object has no associated nodes
|
|
|
|
* and is either not currently searching or is searching at a slow rate
|
2006-01-03 02:04:38 +08:00
|
|
|
*/
|
2011-12-30 09:58:42 +08:00
|
|
|
static void disc_update(struct tipc_link_req *req)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2011-04-22 09:34:03 +08:00
|
|
|
if (!req->num_nodes) {
|
|
|
|
if ((req->timer_intv == TIPC_LINK_REQ_INACTIVE) ||
|
|
|
|
(req->timer_intv > TIPC_LINK_REQ_FAST)) {
|
|
|
|
req->timer_intv = TIPC_LINK_REQ_INIT;
|
2015-01-09 15:27:00 +08:00
|
|
|
mod_timer(&req->timer, jiffies + req->timer_intv);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
}
|
2007-02-09 22:25:21 +08:00
|
|
|
}
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2011-04-22 08:05:25 +08:00
|
|
|
/**
|
|
|
|
* tipc_disc_add_dest - increment set of discovered nodes
|
|
|
|
* @req: ptr to link request structure
|
|
|
|
*/
|
2011-12-30 09:58:42 +08:00
|
|
|
void tipc_disc_add_dest(struct tipc_link_req *req)
|
2011-04-22 08:05:25 +08:00
|
|
|
{
|
2014-01-08 06:02:43 +08:00
|
|
|
spin_lock_bh(&req->lock);
|
2011-04-22 08:05:25 +08:00
|
|
|
req->num_nodes++;
|
2014-01-08 06:02:43 +08:00
|
|
|
spin_unlock_bh(&req->lock);
|
2011-04-22 08:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_disc_remove_dest - decrement set of discovered nodes
|
|
|
|
* @req: ptr to link request structure
|
|
|
|
*/
|
2011-12-30 09:58:42 +08:00
|
|
|
void tipc_disc_remove_dest(struct tipc_link_req *req)
|
2011-04-22 08:05:25 +08:00
|
|
|
{
|
2014-01-08 06:02:43 +08:00
|
|
|
spin_lock_bh(&req->lock);
|
2011-04-22 08:05:25 +08:00
|
|
|
req->num_nodes--;
|
|
|
|
disc_update(req);
|
2014-01-08 06:02:43 +08:00
|
|
|
spin_unlock_bh(&req->lock);
|
2011-04-22 08:05:25 +08:00
|
|
|
}
|
|
|
|
|
2006-01-03 02:04:38 +08:00
|
|
|
/**
|
|
|
|
* disc_timeout - send a periodic link setup request
|
2015-01-09 15:27:00 +08:00
|
|
|
* @data: ptr to link request structure
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
2006-01-03 02:04:38 +08:00
|
|
|
* Called whenever a link setup request timer associated with a bearer expires.
|
|
|
|
*/
|
2015-01-09 15:27:00 +08:00
|
|
|
static void disc_timeout(unsigned long data)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2015-01-09 15:27:00 +08:00
|
|
|
struct tipc_link_req *req = (struct tipc_link_req *)data;
|
2011-04-22 09:34:03 +08:00
|
|
|
int max_delay;
|
|
|
|
|
2014-01-08 06:02:43 +08:00
|
|
|
spin_lock_bh(&req->lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2011-04-22 09:34:03 +08:00
|
|
|
/* Stop searching if only desired node has been found */
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
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:46 +08:00
|
|
|
if (tipc_node(req->domain) && req->num_nodes) {
|
2011-04-22 09:34:03 +08:00
|
|
|
req->timer_intv = TIPC_LINK_REQ_INACTIVE;
|
|
|
|
goto exit;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2011-04-22 09:34:03 +08:00
|
|
|
/*
|
|
|
|
* Send discovery message, then update discovery timer
|
|
|
|
*
|
|
|
|
* Keep doubling time between requests until limit is reached;
|
|
|
|
* hold at fast polling rate if don't have any associated nodes,
|
|
|
|
* otherwise hold at slow polling rate
|
|
|
|
*/
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
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:46 +08:00
|
|
|
tipc_bearer_send(req->bearer_id, req->buf, &req->dest);
|
tipc: remove interface state mirroring in bearer
struct 'tipc_bearer' is a generic representation of the underlying
media type, and exists in a one-to-one relationship to each interface
TIPC is using. The struct contains a 'blocked' flag that mirrors the
operational and execution state of the represented interface, and is
updated through notification calls from the latter. The users of
tipc_bearer are checking this flag before each attempt to send a
packet via the interface.
This state mirroring serves no purpose in the current code base. TIPC
links will not discover a media failure any faster through this
mechanism, and in reality the flag only adds overhead at packet
sending and reception.
Furthermore, the fact that the flag needs to be protected by a spinlock
aggregated into tipc_bearer has turned out to cause a serious and
completely unnecessary deadlock problem.
CPU0 CPU1
---- ----
Time 0: bearer_disable() link_timeout()
Time 1: spin_lock_bh(&b_ptr->lock) tipc_link_push_queue()
Time 2: tipc_link_delete() tipc_bearer_blocked(b_ptr)
Time 3: k_cancel_timer(&req->timer) spin_lock_bh(&b_ptr->lock)
Time 4: del_timer_sync(&req->timer)
I.e., del_timer_sync() on CPU0 never returns, because the timer handler
on CPU1 is waiting for the bearer lock.
We eliminate the 'blocked' flag from struct tipc_bearer, along with all
tests on this flag. This not only resolves the deadlock, but also
simplifies and speeds up the data path execution of TIPC. It also fits
well into our ongoing effort to make the locking policy simpler and
more manageable.
An effect of this change is that we can get rid of functions such as
tipc_bearer_blocked(), tipc_continue() and tipc_block_bearer().
We replace the latter with a new function, tipc_reset_bearer(), which
resets all links associated to the bearer immediately after an
interface goes down.
A user might notice one slight change in link behaviour after this
change. When an interface goes down, (e.g. through a NETDEV_DOWN
event) all attached links will be reset immediately, instead of
leaving it to each link to detect the failure through a timer-driven
mechanism. We consider this an improvement, and see no obvious risks
with the new behavior.
Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Paul Gortmaker <Paul.Gortmaker@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-06 23:08:00 +08:00
|
|
|
|
2011-04-22 09:34:03 +08:00
|
|
|
|
|
|
|
req->timer_intv *= 2;
|
|
|
|
if (req->num_nodes)
|
|
|
|
max_delay = TIPC_LINK_REQ_SLOW;
|
|
|
|
else
|
|
|
|
max_delay = TIPC_LINK_REQ_FAST;
|
|
|
|
if (req->timer_intv > max_delay)
|
|
|
|
req->timer_intv = max_delay;
|
|
|
|
|
2015-01-09 15:27:00 +08:00
|
|
|
mod_timer(&req->timer, jiffies + req->timer_intv);
|
2011-04-22 09:34:03 +08:00
|
|
|
exit:
|
2014-01-08 06:02:43 +08:00
|
|
|
spin_unlock_bh(&req->lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-22 02:58:26 +08:00
|
|
|
* tipc_disc_create - create object to send periodic link setup requests
|
2015-01-09 15:27:04 +08:00
|
|
|
* @net: the applicable net namespace
|
2006-01-03 02:04:38 +08:00
|
|
|
* @b_ptr: ptr to bearer issuing requests
|
|
|
|
* @dest: destination address for request messages
|
2011-04-21 05:24:07 +08:00
|
|
|
* @dest_domain: network domain to which links can be established
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
2011-04-22 02:58:26 +08:00
|
|
|
* Returns 0 if successful, otherwise -errno.
|
2006-01-03 02:04:38 +08:00
|
|
|
*/
|
2015-01-09 15:27:04 +08:00
|
|
|
int tipc_disc_create(struct net *net, struct tipc_bearer *b_ptr,
|
|
|
|
struct tipc_media_addr *dest)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2011-12-30 09:58:42 +08:00
|
|
|
struct tipc_link_req *req;
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2006-07-22 06:52:20 +08:00
|
|
|
req = kmalloc(sizeof(*req), GFP_ATOMIC);
|
2006-01-03 02:04:38 +08:00
|
|
|
if (!req)
|
2011-04-22 02:58:26 +08:00
|
|
|
return -ENOMEM;
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2014-04-21 10:55:52 +08:00
|
|
|
req->buf = tipc_buf_acquire(INT_H_SIZE);
|
2014-04-25 10:44:15 +08:00
|
|
|
if (!req->buf) {
|
|
|
|
kfree(req);
|
2014-04-21 10:55:52 +08:00
|
|
|
return -ENOMEM;
|
2014-04-25 10:44:15 +08:00
|
|
|
}
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2015-01-09 15:27:04 +08:00
|
|
|
tipc_disc_init_msg(net, req->buf, DSC_REQ_MSG, b_ptr);
|
2006-01-03 02:04:38 +08:00
|
|
|
memcpy(&req->dest, dest, sizeof(*dest));
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
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:46 +08:00
|
|
|
req->bearer_id = b_ptr->identity;
|
|
|
|
req->domain = b_ptr->domain;
|
2011-04-22 08:05:25 +08:00
|
|
|
req->num_nodes = 0;
|
2006-01-03 02:04:38 +08:00
|
|
|
req->timer_intv = TIPC_LINK_REQ_INIT;
|
2014-01-08 06:02:43 +08:00
|
|
|
spin_lock_init(&req->lock);
|
2015-01-09 15:27:00 +08:00
|
|
|
setup_timer(&req->timer, disc_timeout, (unsigned long)req);
|
|
|
|
mod_timer(&req->timer, jiffies + req->timer_intv);
|
2011-04-22 02:58:26 +08:00
|
|
|
b_ptr->link_req = req;
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
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:46 +08:00
|
|
|
tipc_bearer_send(req->bearer_id, req->buf, &req->dest);
|
2011-04-22 02:58:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_disc_delete - destroy object sending periodic link setup requests
|
|
|
|
* @req: ptr to link request structure
|
|
|
|
*/
|
2011-12-30 09:58:42 +08:00
|
|
|
void tipc_disc_delete(struct tipc_link_req *req)
|
2011-04-22 02:58:26 +08:00
|
|
|
{
|
2015-01-09 15:27:00 +08:00
|
|
|
del_timer_sync(&req->timer);
|
2011-11-05 01:24:29 +08:00
|
|
|
kfree_skb(req->buf);
|
2011-04-22 02:58:26 +08:00
|
|
|
kfree(req);
|
2007-02-09 22:25:21 +08:00
|
|
|
}
|
2014-04-21 10:55:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_disc_reset - reset object to send periodic link setup requests
|
2015-01-09 15:27:04 +08:00
|
|
|
* @net: the applicable net namespace
|
2014-04-21 10:55:52 +08:00
|
|
|
* @b_ptr: ptr to bearer issuing requests
|
|
|
|
* @dest_domain: network domain to which links can be established
|
|
|
|
*/
|
2015-01-09 15:27:04 +08:00
|
|
|
void tipc_disc_reset(struct net *net, struct tipc_bearer *b_ptr)
|
2014-04-21 10:55:52 +08:00
|
|
|
{
|
|
|
|
struct tipc_link_req *req = b_ptr->link_req;
|
|
|
|
|
|
|
|
spin_lock_bh(&req->lock);
|
2015-01-09 15:27:04 +08:00
|
|
|
tipc_disc_init_msg(net, req->buf, DSC_REQ_MSG, b_ptr);
|
2014-04-21 10:55:52 +08:00
|
|
|
req->bearer_id = b_ptr->identity;
|
|
|
|
req->domain = b_ptr->domain;
|
|
|
|
req->num_nodes = 0;
|
|
|
|
req->timer_intv = TIPC_LINK_REQ_INIT;
|
2015-01-09 15:27:00 +08:00
|
|
|
mod_timer(&req->timer, jiffies + req->timer_intv);
|
2014-04-21 10:55:52 +08:00
|
|
|
tipc_bearer_send(req->bearer_id, req->buf, &req->dest);
|
|
|
|
spin_unlock_bh(&req->lock);
|
|
|
|
}
|