2006-01-03 01:04:38 +07:00
|
|
|
/*
|
|
|
|
* net/tipc/discover.c
|
2007-02-09 21:25:21 +07:00
|
|
|
*
|
2015-02-03 20:59:19 +07:00
|
|
|
* Copyright (c) 2003-2006, 2014-2015, Ericsson AB
|
2011-01-08 01:00:11 +07:00
|
|
|
* Copyright (c) 2005-2006, 2010-2011, Wind River Systems
|
2006-01-03 01:04:38 +07:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2006-01-11 19:30:43 +07:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2006-01-03 01:04:38 +07:00
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
2006-01-11 19:30:43 +07: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 01:04:38 +07:00
|
|
|
*
|
2006-01-11 19:30:43 +07: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 01:04:38 +07:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "core.h"
|
2015-07-17 03:54:20 +07:00
|
|
|
#include "node.h"
|
2006-01-03 01:04:38 +07:00
|
|
|
#include "discover.h"
|
|
|
|
|
2015-01-09 14:27:00 +07: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 01:04:38 +07:00
|
|
|
|
|
|
|
/**
|
2011-12-30 08:58:42 +07: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 09:55:46 +07:00
|
|
|
* @bearer_id: identity of bearer issuing requests
|
2015-01-09 14:27:06 +07:00
|
|
|
* @net: network namespace instance
|
2006-01-03 01:04:38 +07: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 09:55:46 +07:00
|
|
|
* @domain: network domain to which links can be established
|
2011-04-22 07:05:25 +07:00
|
|
|
* @num_nodes: number of nodes currently discovered (i.e. with an active link)
|
2014-01-08 05:02:43 +07:00
|
|
|
* @lock: spinlock for controlling access to requests
|
2006-01-03 01:04:38 +07: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 08:58:42 +07: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 09:55:46 +07:00
|
|
|
u32 bearer_id;
|
2006-01-03 01:04:38 +07:00
|
|
|
struct tipc_media_addr dest;
|
2015-01-09 14:27:06 +07:00
|
|
|
struct net *net;
|
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 09:55:46 +07:00
|
|
|
u32 domain;
|
2011-04-22 07:05:25 +07:00
|
|
|
int num_nodes;
|
2014-01-08 05:02:43 +07:00
|
|
|
spinlock_t lock;
|
2006-01-03 01:04:38 +07:00
|
|
|
struct sk_buff *buf;
|
|
|
|
struct timer_list timer;
|
2015-01-09 14:27:00 +07:00
|
|
|
unsigned long timer_intv;
|
2006-01-03 01:04:38 +07:00
|
|
|
};
|
|
|
|
|
2007-02-09 21:25:21 +07:00
|
|
|
/**
|
2006-01-18 06:38:21 +07:00
|
|
|
* tipc_disc_init_msg - initialize a link setup message
|
2015-01-09 14:27:04 +07:00
|
|
|
* @net: the applicable net namespace
|
2006-01-03 01:04:38 +07:00
|
|
|
* @type: message type (request or response)
|
2015-11-20 02:30:47 +07:00
|
|
|
* @b: ptr to bearer issuing message
|
2006-01-03 01:04:38 +07:00
|
|
|
*/
|
2015-01-09 14:27:04 +07:00
|
|
|
static void tipc_disc_init_msg(struct net *net, struct sk_buff *buf, u32 type,
|
2015-11-20 02:30:47 +07:00
|
|
|
struct tipc_bearer *b)
|
2006-01-03 01:04:38 +07:00
|
|
|
{
|
2015-01-09 14:27:04 +07:00
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2006-01-03 01:04:38 +07:00
|
|
|
struct tipc_msg *msg;
|
2015-11-20 02:30:47 +07:00
|
|
|
u32 dest_domain = b->domain;
|
2006-01-03 01:04:38 +07:00
|
|
|
|
2014-04-21 09:55:52 +07:00
|
|
|
msg = buf_msg(buf);
|
2015-02-05 20:36:36 +07:00
|
|
|
tipc_msg_init(tn->own_addr, msg, LINK_CONFIG, type,
|
2015-03-05 16:23:48 +07:00
|
|
|
MAX_H_SIZE, dest_domain);
|
2014-04-21 09:55:52 +07:00
|
|
|
msg_set_non_seq(msg, 1);
|
2015-01-09 14:27:12 +07:00
|
|
|
msg_set_node_sig(msg, tn->random);
|
2015-10-22 19:51:40 +07:00
|
|
|
msg_set_node_capabilities(msg, TIPC_NODE_CAPABILITIES);
|
2014-04-21 09:55:52 +07:00
|
|
|
msg_set_dest_domain(msg, dest_domain);
|
2015-01-09 14:27:04 +07:00
|
|
|
msg_set_bc_netid(msg, tn->net_id);
|
2015-11-20 02:30:47 +07:00
|
|
|
b->media->addr2msg(msg_media_addr(msg), &b->addr);
|
2006-01-03 01:04:38 +07:00
|
|
|
}
|
|
|
|
|
2006-10-17 11:44:59 +07:00
|
|
|
/**
|
|
|
|
* disc_dupl_alert - issue node address duplication alert
|
2015-11-20 02:30:47 +07:00
|
|
|
* @b: pointer to bearer detecting duplication
|
2006-10-17 11:44:59 +07:00
|
|
|
* @node_addr: duplicated node address
|
|
|
|
* @media_addr: media address advertised by duplicated node
|
|
|
|
*/
|
2015-11-20 02:30:47 +07:00
|
|
|
static void disc_dupl_alert(struct tipc_bearer *b, u32 node_addr,
|
2006-10-17 11:44:59 +07:00
|
|
|
struct tipc_media_addr *media_addr)
|
|
|
|
{
|
|
|
|
char node_addr_str[16];
|
|
|
|
char media_addr_str[64];
|
|
|
|
|
2010-05-11 21:30:12 +07:00
|
|
|
tipc_addr_string_fill(node_addr_str, node_addr);
|
2012-06-29 11:50:23 +07:00
|
|
|
tipc_media_addr_printf(media_addr_str, sizeof(media_addr_str),
|
|
|
|
media_addr);
|
2012-06-29 11:16:37 +07:00
|
|
|
pr_warn("Duplicate %s using %s seen on <%s>\n", node_addr_str,
|
2015-11-20 02:30:47 +07:00
|
|
|
media_addr_str, b->name);
|
2006-10-17 11:44:59 +07:00
|
|
|
}
|
|
|
|
|
2006-01-03 01:04:38 +07:00
|
|
|
/**
|
2014-05-14 16:39:14 +07:00
|
|
|
* tipc_disc_rcv - handle incoming discovery message (request or response)
|
2015-01-09 14:27:04 +07:00
|
|
|
* @net: the applicable net namespace
|
2006-01-03 01:04:38 +07:00
|
|
|
* @buf: buffer containing message
|
2014-05-14 16:39:14 +07:00
|
|
|
* @bearer: bearer that message arrived on
|
2006-01-03 01:04:38 +07:00
|
|
|
*/
|
2015-07-31 05:24:22 +07:00
|
|
|
void tipc_disc_rcv(struct net *net, struct sk_buff *skb,
|
2015-01-09 14:27:04 +07:00
|
|
|
struct tipc_bearer *bearer)
|
2006-01-03 01:04:38 +07:00
|
|
|
{
|
2015-01-09 14:27:04 +07:00
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2014-05-14 16:39:14 +07:00
|
|
|
struct tipc_media_addr maddr;
|
2015-07-31 05:24:22 +07:00
|
|
|
struct sk_buff *rskb;
|
|
|
|
struct tipc_msg *hdr = buf_msg(skb);
|
|
|
|
u32 ddom = msg_dest_domain(hdr);
|
|
|
|
u32 onode = msg_prevnode(hdr);
|
|
|
|
u32 net_id = msg_bc_netid(hdr);
|
|
|
|
u32 mtyp = msg_type(hdr);
|
|
|
|
u32 signature = msg_node_sig(hdr);
|
|
|
|
u16 caps = msg_node_capabilities(hdr);
|
2014-05-14 16:39:14 +07:00
|
|
|
bool respond = false;
|
2015-07-31 05:24:22 +07:00
|
|
|
bool dupl_addr = false;
|
2006-01-03 01:04:38 +07:00
|
|
|
|
2015-07-31 05:24:22 +07:00
|
|
|
bearer->media->msg2addr(bearer, &maddr, msg_media_addr(hdr));
|
|
|
|
kfree_skb(skb);
|
2006-01-03 01:04:38 +07:00
|
|
|
|
2011-10-29 04:30:08 +07:00
|
|
|
/* Ensure message from node is valid and communication is permitted */
|
2015-01-09 14:27:04 +07:00
|
|
|
if (net_id != tn->net_id)
|
2006-01-03 01:04:38 +07:00
|
|
|
return;
|
2014-05-14 16:39:14 +07:00
|
|
|
if (maddr.broadcast)
|
2011-10-08 02:48:41 +07:00
|
|
|
return;
|
2014-05-14 16:39:14 +07:00
|
|
|
if (!tipc_addr_domain_valid(ddom))
|
2006-01-03 01:04:38 +07:00
|
|
|
return;
|
2014-05-14 16:39:14 +07:00
|
|
|
if (!tipc_addr_node_valid(onode))
|
2006-01-03 01:04:38 +07:00
|
|
|
return;
|
2014-05-14 16:39:14 +07:00
|
|
|
|
2015-01-09 14:27:10 +07:00
|
|
|
if (in_own_node(net, onode)) {
|
2014-05-14 16:39:14 +07:00
|
|
|
if (memcmp(&maddr, &bearer->addr, sizeof(maddr)))
|
2015-01-09 14:27:10 +07:00
|
|
|
disc_dupl_alert(bearer, tn->own_addr, &maddr);
|
2006-01-03 01:04:38 +07:00
|
|
|
return;
|
2006-10-17 11:44:59 +07:00
|
|
|
}
|
2015-01-09 14:27:10 +07:00
|
|
|
if (!tipc_in_scope(ddom, tn->own_addr))
|
2006-01-03 01:04:38 +07:00
|
|
|
return;
|
2014-05-14 16:39:14 +07:00
|
|
|
if (!tipc_in_scope(bearer->domain, onode))
|
2011-02-28 22:03:05 +07:00
|
|
|
return;
|
2010-08-17 18:00:16 +07:00
|
|
|
|
2015-07-31 05:24:22 +07:00
|
|
|
tipc_node_check_dest(net, onode, bearer, caps, signature,
|
|
|
|
&maddr, &respond, &dupl_addr);
|
|
|
|
if (dupl_addr)
|
2014-05-14 16:39:14 +07:00
|
|
|
disc_dupl_alert(bearer, onode, &maddr);
|
2011-02-28 22:03:05 +07:00
|
|
|
|
2014-05-14 16:39:14 +07:00
|
|
|
/* Send response, if necessary */
|
|
|
|
if (respond && (mtyp == DSC_REQ_MSG)) {
|
2015-07-31 05:24:22 +07:00
|
|
|
rskb = tipc_buf_acquire(MAX_H_SIZE);
|
2015-10-22 19:51:44 +07:00
|
|
|
if (!rskb)
|
|
|
|
return;
|
|
|
|
tipc_disc_init_msg(net, rskb, DSC_RESP_MSG, bearer);
|
|
|
|
tipc_bearer_xmit_skb(net, bearer->identity, rskb, &maddr);
|
2006-01-03 01:04:38 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-22 07:05:25 +07:00
|
|
|
* disc_update - update frequency of periodic link setup requests
|
2006-01-03 01:04:38 +07:00
|
|
|
* @req: ptr to link request structure
|
2011-04-22 08:34:03 +07: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 01:04:38 +07:00
|
|
|
*/
|
2011-12-30 08:58:42 +07:00
|
|
|
static void disc_update(struct tipc_link_req *req)
|
2006-01-03 01:04:38 +07:00
|
|
|
{
|
2011-04-22 08:34:03 +07: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 14:27:00 +07:00
|
|
|
mod_timer(&req->timer, jiffies + req->timer_intv);
|
2006-01-03 01:04:38 +07:00
|
|
|
}
|
|
|
|
}
|
2007-02-09 21:25:21 +07:00
|
|
|
}
|
2006-01-03 01:04:38 +07:00
|
|
|
|
2011-04-22 07:05:25 +07:00
|
|
|
/**
|
|
|
|
* tipc_disc_add_dest - increment set of discovered nodes
|
|
|
|
* @req: ptr to link request structure
|
|
|
|
*/
|
2011-12-30 08:58:42 +07:00
|
|
|
void tipc_disc_add_dest(struct tipc_link_req *req)
|
2011-04-22 07:05:25 +07:00
|
|
|
{
|
2014-01-08 05:02:43 +07:00
|
|
|
spin_lock_bh(&req->lock);
|
2011-04-22 07:05:25 +07:00
|
|
|
req->num_nodes++;
|
2014-01-08 05:02:43 +07:00
|
|
|
spin_unlock_bh(&req->lock);
|
2011-04-22 07:05:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_disc_remove_dest - decrement set of discovered nodes
|
|
|
|
* @req: ptr to link request structure
|
|
|
|
*/
|
2011-12-30 08:58:42 +07:00
|
|
|
void tipc_disc_remove_dest(struct tipc_link_req *req)
|
2011-04-22 07:05:25 +07:00
|
|
|
{
|
2014-01-08 05:02:43 +07:00
|
|
|
spin_lock_bh(&req->lock);
|
2011-04-22 07:05:25 +07:00
|
|
|
req->num_nodes--;
|
|
|
|
disc_update(req);
|
2014-01-08 05:02:43 +07:00
|
|
|
spin_unlock_bh(&req->lock);
|
2011-04-22 07:05:25 +07:00
|
|
|
}
|
|
|
|
|
2006-01-03 01:04:38 +07:00
|
|
|
/**
|
|
|
|
* disc_timeout - send a periodic link setup request
|
2015-01-09 14:27:00 +07:00
|
|
|
* @data: ptr to link request structure
|
2007-02-09 21:25:21 +07:00
|
|
|
*
|
2006-01-03 01:04:38 +07:00
|
|
|
* Called whenever a link setup request timer associated with a bearer expires.
|
|
|
|
*/
|
2015-01-09 14:27:00 +07:00
|
|
|
static void disc_timeout(unsigned long data)
|
2006-01-03 01:04:38 +07:00
|
|
|
{
|
2015-01-09 14:27:00 +07:00
|
|
|
struct tipc_link_req *req = (struct tipc_link_req *)data;
|
2015-10-22 19:51:44 +07:00
|
|
|
struct sk_buff *skb;
|
2011-04-22 08:34:03 +07:00
|
|
|
int max_delay;
|
|
|
|
|
2014-01-08 05:02:43 +07:00
|
|
|
spin_lock_bh(&req->lock);
|
2006-01-03 01:04:38 +07:00
|
|
|
|
2011-04-22 08:34:03 +07: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 09:55:46 +07:00
|
|
|
if (tipc_node(req->domain) && req->num_nodes) {
|
2011-04-22 08:34:03 +07:00
|
|
|
req->timer_intv = TIPC_LINK_REQ_INACTIVE;
|
|
|
|
goto exit;
|
2006-01-03 01:04:38 +07:00
|
|
|
}
|
|
|
|
|
2011-04-22 08:34:03 +07: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
|
|
|
|
*/
|
2015-10-22 19:51:44 +07:00
|
|
|
skb = skb_clone(req->buf, GFP_ATOMIC);
|
|
|
|
if (skb)
|
|
|
|
tipc_bearer_xmit_skb(req->net, req->bearer_id, skb, &req->dest);
|
2011-04-22 08:34:03 +07: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 14:27:00 +07:00
|
|
|
mod_timer(&req->timer, jiffies + req->timer_intv);
|
2011-04-22 08:34:03 +07:00
|
|
|
exit:
|
2014-01-08 05:02:43 +07:00
|
|
|
spin_unlock_bh(&req->lock);
|
2006-01-03 01:04:38 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-22 01:58:26 +07:00
|
|
|
* tipc_disc_create - create object to send periodic link setup requests
|
2015-01-09 14:27:04 +07:00
|
|
|
* @net: the applicable net namespace
|
2015-11-20 02:30:47 +07:00
|
|
|
* @b: ptr to bearer issuing requests
|
2006-01-03 01:04:38 +07:00
|
|
|
* @dest: destination address for request messages
|
2011-04-21 04:24:07 +07:00
|
|
|
* @dest_domain: network domain to which links can be established
|
2007-02-09 21:25:21 +07:00
|
|
|
*
|
2011-04-22 01:58:26 +07:00
|
|
|
* Returns 0 if successful, otherwise -errno.
|
2006-01-03 01:04:38 +07:00
|
|
|
*/
|
2015-11-20 02:30:47 +07:00
|
|
|
int tipc_disc_create(struct net *net, struct tipc_bearer *b,
|
2015-01-09 14:27:04 +07:00
|
|
|
struct tipc_media_addr *dest)
|
2006-01-03 01:04:38 +07:00
|
|
|
{
|
2011-12-30 08:58:42 +07:00
|
|
|
struct tipc_link_req *req;
|
2015-10-22 19:51:44 +07:00
|
|
|
struct sk_buff *skb;
|
2006-01-03 01:04:38 +07:00
|
|
|
|
2006-07-22 05:52:20 +07:00
|
|
|
req = kmalloc(sizeof(*req), GFP_ATOMIC);
|
2006-01-03 01:04:38 +07:00
|
|
|
if (!req)
|
2011-04-22 01:58:26 +07:00
|
|
|
return -ENOMEM;
|
2015-03-05 16:23:48 +07:00
|
|
|
req->buf = tipc_buf_acquire(MAX_H_SIZE);
|
2014-04-25 09:44:15 +07:00
|
|
|
if (!req->buf) {
|
|
|
|
kfree(req);
|
2014-04-21 09:55:52 +07:00
|
|
|
return -ENOMEM;
|
2014-04-25 09:44:15 +07:00
|
|
|
}
|
2006-01-03 01:04:38 +07:00
|
|
|
|
2015-11-20 02:30:47 +07:00
|
|
|
tipc_disc_init_msg(net, req->buf, DSC_REQ_MSG, b);
|
2006-01-03 01:04:38 +07:00
|
|
|
memcpy(&req->dest, dest, sizeof(*dest));
|
2015-01-09 14:27:06 +07:00
|
|
|
req->net = net;
|
2015-11-20 02:30:47 +07:00
|
|
|
req->bearer_id = b->identity;
|
|
|
|
req->domain = b->domain;
|
2011-04-22 07:05:25 +07:00
|
|
|
req->num_nodes = 0;
|
2006-01-03 01:04:38 +07:00
|
|
|
req->timer_intv = TIPC_LINK_REQ_INIT;
|
2014-01-08 05:02:43 +07:00
|
|
|
spin_lock_init(&req->lock);
|
2015-01-09 14:27:00 +07:00
|
|
|
setup_timer(&req->timer, disc_timeout, (unsigned long)req);
|
|
|
|
mod_timer(&req->timer, jiffies + req->timer_intv);
|
2015-11-20 02:30:47 +07:00
|
|
|
b->link_req = req;
|
2015-10-22 19:51:44 +07:00
|
|
|
skb = skb_clone(req->buf, GFP_ATOMIC);
|
|
|
|
if (skb)
|
|
|
|
tipc_bearer_xmit_skb(net, req->bearer_id, skb, &req->dest);
|
2011-04-22 01:58:26 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_disc_delete - destroy object sending periodic link setup requests
|
|
|
|
* @req: ptr to link request structure
|
|
|
|
*/
|
2011-12-30 08:58:42 +07:00
|
|
|
void tipc_disc_delete(struct tipc_link_req *req)
|
2011-04-22 01:58:26 +07:00
|
|
|
{
|
2015-01-09 14:27:00 +07:00
|
|
|
del_timer_sync(&req->timer);
|
2011-11-05 00:24:29 +07:00
|
|
|
kfree_skb(req->buf);
|
2011-04-22 01:58:26 +07:00
|
|
|
kfree(req);
|
2007-02-09 21:25:21 +07:00
|
|
|
}
|
2014-04-21 09:55:52 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_disc_reset - reset object to send periodic link setup requests
|
2015-01-09 14:27:04 +07:00
|
|
|
* @net: the applicable net namespace
|
2015-11-20 02:30:47 +07:00
|
|
|
* @b: ptr to bearer issuing requests
|
2014-04-21 09:55:52 +07:00
|
|
|
* @dest_domain: network domain to which links can be established
|
|
|
|
*/
|
2015-11-20 02:30:47 +07:00
|
|
|
void tipc_disc_reset(struct net *net, struct tipc_bearer *b)
|
2014-04-21 09:55:52 +07:00
|
|
|
{
|
2015-11-20 02:30:47 +07:00
|
|
|
struct tipc_link_req *req = b->link_req;
|
2015-10-22 19:51:44 +07:00
|
|
|
struct sk_buff *skb;
|
2014-04-21 09:55:52 +07:00
|
|
|
|
|
|
|
spin_lock_bh(&req->lock);
|
2015-11-20 02:30:47 +07:00
|
|
|
tipc_disc_init_msg(net, req->buf, DSC_REQ_MSG, b);
|
2015-01-09 14:27:06 +07:00
|
|
|
req->net = net;
|
2015-11-20 02:30:47 +07:00
|
|
|
req->bearer_id = b->identity;
|
|
|
|
req->domain = b->domain;
|
2014-04-21 09:55:52 +07:00
|
|
|
req->num_nodes = 0;
|
|
|
|
req->timer_intv = TIPC_LINK_REQ_INIT;
|
2015-01-09 14:27:00 +07:00
|
|
|
mod_timer(&req->timer, jiffies + req->timer_intv);
|
2015-10-22 19:51:44 +07:00
|
|
|
skb = skb_clone(req->buf, GFP_ATOMIC);
|
|
|
|
if (skb)
|
|
|
|
tipc_bearer_xmit_skb(net, req->bearer_id, skb, &req->dest);
|
2014-04-21 09:55:52 +07:00
|
|
|
spin_unlock_bh(&req->lock);
|
|
|
|
}
|