2006-01-02 21:04:38 +03:00
|
|
|
/*
|
|
|
|
* net/tipc/discover.c
|
2007-02-09 17:25:21 +03:00
|
|
|
*
|
2015-02-03 16:59:19 +03:00
|
|
|
* Copyright (c) 2003-2006, 2014-2015, Ericsson AB
|
2011-01-07 21:00:11 +03:00
|
|
|
* Copyright (c) 2005-2006, 2010-2011, Wind River Systems
|
2006-01-02 21:04:38 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2006-01-11 15:30:43 +03:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2006-01-02 21:04:38 +03:00
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
2006-01-11 15:30:43 +03: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-02 21:04:38 +03:00
|
|
|
*
|
2006-01-11 15:30:43 +03: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-02 21:04:38 +03:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "core.h"
|
2015-07-16 23:54:20 +03:00
|
|
|
#include "node.h"
|
2006-01-02 21:04:38 +03:00
|
|
|
#include "discover.h"
|
|
|
|
|
2015-01-09 10:27:00 +03:00
|
|
|
/* min delay during bearer start up */
|
2018-03-22 22:42:46 +03:00
|
|
|
#define TIPC_DISC_INIT msecs_to_jiffies(125)
|
2015-01-09 10:27:00 +03:00
|
|
|
/* max delay if bearer has no links */
|
2018-03-22 22:42:46 +03:00
|
|
|
#define TIPC_DISC_FAST msecs_to_jiffies(1000)
|
2015-01-09 10:27:00 +03:00
|
|
|
/* max delay if bearer has links */
|
2018-03-22 22:42:46 +03:00
|
|
|
#define TIPC_DISC_SLOW msecs_to_jiffies(60000)
|
2015-01-09 10:27:00 +03:00
|
|
|
/* indicates no timer in use */
|
2018-03-22 22:42:46 +03:00
|
|
|
#define TIPC_DISC_INACTIVE 0xffffffff
|
2006-01-02 21:04:38 +03:00
|
|
|
|
|
|
|
/**
|
2018-03-22 22:42:46 +03:00
|
|
|
* struct tipc_discoverer - 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 06:55:46 +04:00
|
|
|
* @bearer_id: identity of bearer issuing requests
|
2015-01-09 10:27:06 +03:00
|
|
|
* @net: network namespace instance
|
2006-01-02 21:04:38 +03: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 06:55:46 +04:00
|
|
|
* @domain: network domain to which links can be established
|
2011-04-22 04:05:25 +04:00
|
|
|
* @num_nodes: number of nodes currently discovered (i.e. with an active link)
|
2014-01-08 02:02:43 +04:00
|
|
|
* @lock: spinlock for controlling access to requests
|
2018-03-22 22:42:46 +03:00
|
|
|
* @skb: request message to be (repeatedly) sent
|
2006-01-02 21:04:38 +03:00
|
|
|
* @timer: timer governing period between requests
|
|
|
|
* @timer_intv: current interval between requests (in ms)
|
|
|
|
*/
|
2018-03-22 22:42:46 +03:00
|
|
|
struct tipc_discoverer {
|
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 06:55:46 +04:00
|
|
|
u32 bearer_id;
|
2006-01-02 21:04:38 +03:00
|
|
|
struct tipc_media_addr dest;
|
2015-01-09 10:27:06 +03: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 06:55:46 +04:00
|
|
|
u32 domain;
|
2011-04-22 04:05:25 +04:00
|
|
|
int num_nodes;
|
2014-01-08 02:02:43 +04:00
|
|
|
spinlock_t lock;
|
2018-03-22 22:42:46 +03:00
|
|
|
struct sk_buff *skb;
|
2006-01-02 21:04:38 +03:00
|
|
|
struct timer_list timer;
|
2015-01-09 10:27:00 +03:00
|
|
|
unsigned long timer_intv;
|
2006-01-02 21:04:38 +03:00
|
|
|
};
|
|
|
|
|
2007-02-09 17:25:21 +03:00
|
|
|
/**
|
2006-01-18 02:38:21 +03:00
|
|
|
* tipc_disc_init_msg - initialize a link setup message
|
2015-01-09 10:27:04 +03:00
|
|
|
* @net: the applicable net namespace
|
2006-01-02 21:04:38 +03:00
|
|
|
* @type: message type (request or response)
|
2015-11-19 22:30:47 +03:00
|
|
|
* @b: ptr to bearer issuing message
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
2018-03-22 22:42:46 +03:00
|
|
|
static void tipc_disc_init_msg(struct net *net, struct sk_buff *skb,
|
|
|
|
u32 mtyp, struct tipc_bearer *b)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2018-03-22 22:42:46 +03:00
|
|
|
struct tipc_net *tn = tipc_net(net);
|
2015-11-19 22:30:47 +03:00
|
|
|
u32 dest_domain = b->domain;
|
2018-03-22 22:42:46 +03:00
|
|
|
struct tipc_msg *hdr;
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2018-03-22 22:42:46 +03:00
|
|
|
hdr = buf_msg(skb);
|
|
|
|
tipc_msg_init(tn->own_addr, hdr, LINK_CONFIG, mtyp,
|
2015-03-05 12:23:48 +03:00
|
|
|
MAX_H_SIZE, dest_domain);
|
2018-03-22 22:42:46 +03:00
|
|
|
msg_set_non_seq(hdr, 1);
|
|
|
|
msg_set_node_sig(hdr, tn->random);
|
|
|
|
msg_set_node_capabilities(hdr, TIPC_NODE_CAPABILITIES);
|
|
|
|
msg_set_dest_domain(hdr, dest_domain);
|
|
|
|
msg_set_bc_netid(hdr, tn->net_id);
|
|
|
|
b->media->addr2msg(msg_media_addr(hdr), &b->addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tipc_disc_msg_xmit(struct net *net, u32 mtyp, u32 dst, u32 src,
|
|
|
|
struct tipc_media_addr *maddr,
|
|
|
|
struct tipc_bearer *b)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
skb = tipc_buf_acquire(MAX_H_SIZE, GFP_ATOMIC);
|
|
|
|
if (!skb)
|
|
|
|
return;
|
|
|
|
tipc_disc_init_msg(net, skb, mtyp, b);
|
|
|
|
tipc_bearer_xmit_skb(net, b->identity, skb, maddr);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
2006-10-17 08:44:59 +04:00
|
|
|
/**
|
|
|
|
* disc_dupl_alert - issue node address duplication alert
|
2015-11-19 22:30:47 +03:00
|
|
|
* @b: pointer to bearer detecting duplication
|
2006-10-17 08:44:59 +04:00
|
|
|
* @node_addr: duplicated node address
|
|
|
|
* @media_addr: media address advertised by duplicated node
|
|
|
|
*/
|
2015-11-19 22:30:47 +03:00
|
|
|
static void disc_dupl_alert(struct tipc_bearer *b, u32 node_addr,
|
2006-10-17 08:44:59 +04:00
|
|
|
struct tipc_media_addr *media_addr)
|
|
|
|
{
|
|
|
|
char node_addr_str[16];
|
|
|
|
char media_addr_str[64];
|
|
|
|
|
2010-05-11 18:30:12 +04:00
|
|
|
tipc_addr_string_fill(node_addr_str, node_addr);
|
2012-06-29 08:50:23 +04:00
|
|
|
tipc_media_addr_printf(media_addr_str, sizeof(media_addr_str),
|
|
|
|
media_addr);
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Duplicate %s using %s seen on <%s>\n", node_addr_str,
|
2015-11-19 22:30:47 +03:00
|
|
|
media_addr_str, b->name);
|
2006-10-17 08:44:59 +04:00
|
|
|
}
|
|
|
|
|
2006-01-02 21:04:38 +03:00
|
|
|
/**
|
2014-05-14 13:39:14 +04:00
|
|
|
* tipc_disc_rcv - handle incoming discovery message (request or response)
|
2018-03-22 22:42:46 +03:00
|
|
|
* @net: applicable net namespace
|
|
|
|
* @skb: buffer containing message
|
|
|
|
* @b: bearer that message arrived on
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
2015-07-31 01:24:22 +03:00
|
|
|
void tipc_disc_rcv(struct net *net, struct sk_buff *skb,
|
2018-03-22 22:42:46 +03:00
|
|
|
struct tipc_bearer *b)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2018-03-22 22:42:46 +03:00
|
|
|
struct tipc_net *tn = tipc_net(net);
|
2015-07-31 01:24:22 +03:00
|
|
|
struct tipc_msg *hdr = buf_msg(skb);
|
2018-03-22 22:42:46 +03:00
|
|
|
u16 caps = msg_node_capabilities(hdr);
|
|
|
|
u32 signature = msg_node_sig(hdr);
|
|
|
|
u32 dst = msg_dest_domain(hdr);
|
2015-07-31 01:24:22 +03:00
|
|
|
u32 net_id = msg_bc_netid(hdr);
|
2018-03-22 22:42:46 +03:00
|
|
|
u32 self = tipc_own_addr(net);
|
|
|
|
struct tipc_media_addr maddr;
|
|
|
|
u32 src = msg_prevnode(hdr);
|
2015-07-31 01:24:22 +03:00
|
|
|
u32 mtyp = msg_type(hdr);
|
|
|
|
bool dupl_addr = false;
|
2018-03-22 22:42:46 +03:00
|
|
|
bool respond = false;
|
2016-06-27 14:34:06 +03:00
|
|
|
int err;
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2018-03-22 22:42:46 +03:00
|
|
|
err = b->media->msg2addr(b, &maddr, msg_media_addr(hdr));
|
2015-07-31 01:24:22 +03:00
|
|
|
kfree_skb(skb);
|
2018-03-22 22:42:46 +03:00
|
|
|
if (err || maddr.broadcast) {
|
|
|
|
pr_warn_ratelimited("Rcv corrupt discovery message\n");
|
2016-06-27 14:34:06 +03:00
|
|
|
return;
|
2018-03-22 22:42:46 +03:00
|
|
|
}
|
|
|
|
/* Ignore discovery messages from own node */
|
|
|
|
if (!memcmp(&maddr, &b->addr, sizeof(maddr)))
|
2006-01-02 21:04:38 +03:00
|
|
|
return;
|
2018-03-22 22:42:46 +03:00
|
|
|
if (net_id != tn->net_id)
|
2011-10-07 23:48:41 +04:00
|
|
|
return;
|
2018-03-22 22:42:46 +03:00
|
|
|
if (in_own_node(net, src)) {
|
|
|
|
disc_dupl_alert(b, self, &maddr);
|
2006-01-02 21:04:38 +03:00
|
|
|
return;
|
2006-10-17 08:44:59 +04:00
|
|
|
}
|
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 22:42:47 +03:00
|
|
|
/* Domain filter only works if both peers use legacy address format */
|
|
|
|
if (b->domain) {
|
|
|
|
if (!tipc_in_scope(dst, self))
|
|
|
|
return;
|
|
|
|
if (!tipc_in_scope(b->domain, src))
|
|
|
|
return;
|
|
|
|
}
|
2018-03-22 22:42:46 +03:00
|
|
|
tipc_node_check_dest(net, src, b, caps, signature,
|
2015-07-31 01:24:22 +03:00
|
|
|
&maddr, &respond, &dupl_addr);
|
|
|
|
if (dupl_addr)
|
2018-03-22 22:42:46 +03:00
|
|
|
disc_dupl_alert(b, src, &maddr);
|
|
|
|
if (!respond)
|
|
|
|
return;
|
|
|
|
if (mtyp != DSC_REQ_MSG)
|
|
|
|
return;
|
|
|
|
tipc_disc_msg_xmit(net, DSC_RESP_MSG, src, self, &maddr, b);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
2018-03-22 22:42:46 +03:00
|
|
|
/* tipc_disc_add_dest - increment set of discovered nodes
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
2018-03-22 22:42:46 +03:00
|
|
|
void tipc_disc_add_dest(struct tipc_discoverer *d)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2018-03-22 22:42:46 +03:00
|
|
|
spin_lock_bh(&d->lock);
|
|
|
|
d->num_nodes++;
|
|
|
|
spin_unlock_bh(&d->lock);
|
2007-02-09 17:25:21 +03:00
|
|
|
}
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2018-03-22 22:42:46 +03:00
|
|
|
/* tipc_disc_remove_dest - decrement set of discovered nodes
|
2011-04-22 04:05:25 +04:00
|
|
|
*/
|
2018-03-22 22:42:46 +03:00
|
|
|
void tipc_disc_remove_dest(struct tipc_discoverer *d)
|
2011-04-22 04:05:25 +04:00
|
|
|
{
|
2018-03-22 22:42:46 +03:00
|
|
|
int intv, num;
|
2011-04-22 04:05:25 +04:00
|
|
|
|
2018-03-22 22:42:46 +03:00
|
|
|
spin_lock_bh(&d->lock);
|
|
|
|
d->num_nodes--;
|
|
|
|
num = d->num_nodes;
|
|
|
|
intv = d->timer_intv;
|
|
|
|
if (!num && (intv == TIPC_DISC_INACTIVE || intv > TIPC_DISC_FAST)) {
|
|
|
|
d->timer_intv = TIPC_DISC_INIT;
|
|
|
|
mod_timer(&d->timer, jiffies + d->timer_intv);
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&d->lock);
|
2011-04-22 04:05:25 +04:00
|
|
|
}
|
|
|
|
|
2018-03-22 22:42:46 +03:00
|
|
|
/* tipc_disc_timeout - send a periodic link setup request
|
2006-01-02 21:04:38 +03:00
|
|
|
* Called whenever a link setup request timer associated with a bearer expires.
|
2018-03-22 22:42:46 +03:00
|
|
|
* - Keep doubling time between sent request until limit is reached;
|
|
|
|
* - Hold at fast polling rate if we don't have any associated nodes
|
|
|
|
* - Otherwise hold at slow polling rate
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
2018-03-22 22:42:46 +03:00
|
|
|
static void tipc_disc_timeout(struct timer_list *t)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2018-03-22 22:42:46 +03:00
|
|
|
struct tipc_discoverer *d = from_timer(d, t, timer);
|
|
|
|
struct tipc_media_addr maddr;
|
|
|
|
struct sk_buff *skb = NULL;
|
|
|
|
struct net *net;
|
|
|
|
u32 bearer_id;
|
2011-04-22 05:34:03 +04:00
|
|
|
|
2018-03-22 22:42:46 +03:00
|
|
|
spin_lock_bh(&d->lock);
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2011-04-22 05:34:03 +04:00
|
|
|
/* Stop searching if only desired node has been found */
|
2018-03-22 22:42:46 +03:00
|
|
|
if (tipc_node(d->domain) && d->num_nodes) {
|
|
|
|
d->timer_intv = TIPC_DISC_INACTIVE;
|
2011-04-22 05:34:03 +04:00
|
|
|
goto exit;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
2018-03-22 22:42:46 +03:00
|
|
|
/* Adjust timeout interval according to discovery phase */
|
|
|
|
d->timer_intv *= 2;
|
|
|
|
if (d->num_nodes && d->timer_intv > TIPC_DISC_SLOW)
|
|
|
|
d->timer_intv = TIPC_DISC_SLOW;
|
|
|
|
else if (!d->num_nodes && d->timer_intv > TIPC_DISC_FAST)
|
|
|
|
d->timer_intv = TIPC_DISC_FAST;
|
|
|
|
mod_timer(&d->timer, jiffies + d->timer_intv);
|
|
|
|
memcpy(&maddr, &d->dest, sizeof(maddr));
|
|
|
|
skb = skb_clone(d->skb, GFP_ATOMIC);
|
|
|
|
net = d->net;
|
|
|
|
bearer_id = d->bearer_id;
|
2011-04-22 05:34:03 +04:00
|
|
|
exit:
|
2018-03-22 22:42:46 +03:00
|
|
|
spin_unlock_bh(&d->lock);
|
|
|
|
if (skb)
|
|
|
|
tipc_bearer_xmit_skb(net, bearer_id, skb, &maddr);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-21 22:58:26 +04:00
|
|
|
* tipc_disc_create - create object to send periodic link setup requests
|
2015-01-09 10:27:04 +03:00
|
|
|
* @net: the applicable net namespace
|
2015-11-19 22:30:47 +03:00
|
|
|
* @b: ptr to bearer issuing requests
|
2006-01-02 21:04:38 +03:00
|
|
|
* @dest: destination address for request messages
|
2011-04-21 01:24:07 +04:00
|
|
|
* @dest_domain: network domain to which links can be established
|
2007-02-09 17:25:21 +03:00
|
|
|
*
|
2011-04-21 22:58:26 +04:00
|
|
|
* Returns 0 if successful, otherwise -errno.
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
2015-11-19 22:30:47 +03:00
|
|
|
int tipc_disc_create(struct net *net, struct tipc_bearer *b,
|
tipc: eliminate buffer leak in bearer layer
When enabling a bearer we create a 'neigbor discoverer' instance by
calling the function tipc_disc_create() before the bearer is actually
registered in the list of enabled bearers. Because of this, the very
first discovery broadcast message, created by the mentioned function,
is lost, since it cannot find any valid bearer to use. Furthermore,
the used send function, tipc_bearer_xmit_skb() does not free the given
buffer when it cannot find a bearer, resulting in the leak of exactly
one send buffer each time a bearer is enabled.
This commit fixes this problem by introducing two changes:
1) Instead of attemting to send the discovery message directly, we let
tipc_disc_create() return the discovery buffer to the calling
function, tipc_enable_bearer(), so that the latter can send it
when the enabling sequence is finished.
2) In tipc_bearer_xmit_skb(), as well as in the two other transmit
functions at the bearer layer, we now free the indicated buffer or
buffer chain when a valid bearer cannot be found.
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>
2016-04-07 17:09:13 +03:00
|
|
|
struct tipc_media_addr *dest, struct sk_buff **skb)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2018-03-22 22:42:46 +03:00
|
|
|
struct tipc_discoverer *d;
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2018-03-22 22:42:46 +03:00
|
|
|
d = kmalloc(sizeof(*d), GFP_ATOMIC);
|
|
|
|
if (!d)
|
2011-04-21 22:58:26 +04:00
|
|
|
return -ENOMEM;
|
2018-03-22 22:42:46 +03:00
|
|
|
d->skb = tipc_buf_acquire(MAX_H_SIZE, GFP_ATOMIC);
|
|
|
|
if (!d->skb) {
|
|
|
|
kfree(d);
|
2014-04-21 06:55:52 +04:00
|
|
|
return -ENOMEM;
|
2014-04-25 06:44:15 +04:00
|
|
|
}
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2018-03-22 22:42:46 +03:00
|
|
|
tipc_disc_init_msg(net, d->skb, DSC_REQ_MSG, b);
|
|
|
|
memcpy(&d->dest, dest, sizeof(*dest));
|
|
|
|
d->net = net;
|
|
|
|
d->bearer_id = b->identity;
|
|
|
|
d->domain = b->domain;
|
|
|
|
d->num_nodes = 0;
|
|
|
|
d->timer_intv = TIPC_DISC_INIT;
|
|
|
|
spin_lock_init(&d->lock);
|
|
|
|
timer_setup(&d->timer, tipc_disc_timeout, 0);
|
|
|
|
mod_timer(&d->timer, jiffies + d->timer_intv);
|
|
|
|
b->disc = d;
|
|
|
|
*skb = skb_clone(d->skb, GFP_ATOMIC);
|
2011-04-21 22:58:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_disc_delete - destroy object sending periodic link setup requests
|
2018-03-22 22:42:46 +03:00
|
|
|
* @d: ptr to link duest structure
|
2011-04-21 22:58:26 +04:00
|
|
|
*/
|
2018-03-22 22:42:46 +03:00
|
|
|
void tipc_disc_delete(struct tipc_discoverer *d)
|
2011-04-21 22:58:26 +04:00
|
|
|
{
|
2018-03-22 22:42:46 +03:00
|
|
|
del_timer_sync(&d->timer);
|
|
|
|
kfree_skb(d->skb);
|
|
|
|
kfree(d);
|
2007-02-09 17:25:21 +03:00
|
|
|
}
|
2014-04-21 06:55:52 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_disc_reset - reset object to send periodic link setup requests
|
2015-01-09 10:27:04 +03:00
|
|
|
* @net: the applicable net namespace
|
2015-11-19 22:30:47 +03:00
|
|
|
* @b: ptr to bearer issuing requests
|
2014-04-21 06:55:52 +04:00
|
|
|
* @dest_domain: network domain to which links can be established
|
|
|
|
*/
|
2015-11-19 22:30:47 +03:00
|
|
|
void tipc_disc_reset(struct net *net, struct tipc_bearer *b)
|
2014-04-21 06:55:52 +04:00
|
|
|
{
|
2018-03-22 22:42:46 +03:00
|
|
|
struct tipc_discoverer *d = b->disc;
|
|
|
|
struct tipc_media_addr maddr;
|
2015-10-22 15:51:44 +03:00
|
|
|
struct sk_buff *skb;
|
2014-04-21 06:55:52 +04:00
|
|
|
|
2018-03-22 22:42:46 +03:00
|
|
|
spin_lock_bh(&d->lock);
|
|
|
|
tipc_disc_init_msg(net, d->skb, DSC_REQ_MSG, b);
|
|
|
|
d->net = net;
|
|
|
|
d->bearer_id = b->identity;
|
|
|
|
d->domain = b->domain;
|
|
|
|
d->num_nodes = 0;
|
|
|
|
d->timer_intv = TIPC_DISC_INIT;
|
|
|
|
memcpy(&maddr, &d->dest, sizeof(maddr));
|
|
|
|
mod_timer(&d->timer, jiffies + d->timer_intv);
|
|
|
|
skb = skb_clone(d->skb, GFP_ATOMIC);
|
|
|
|
spin_unlock_bh(&d->lock);
|
2015-10-22 15:51:44 +03:00
|
|
|
if (skb)
|
2018-03-22 22:42:46 +03:00
|
|
|
tipc_bearer_xmit_skb(net, b->identity, skb, &maddr);
|
2014-04-21 06:55:52 +04:00
|
|
|
}
|