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 */
|
2018-03-23 02:42:46 +07:00
|
|
|
#define TIPC_DISC_INIT msecs_to_jiffies(125)
|
2015-01-09 14:27:00 +07:00
|
|
|
/* max delay if bearer has no links */
|
2018-03-23 02:42:46 +07:00
|
|
|
#define TIPC_DISC_FAST msecs_to_jiffies(1000)
|
2015-01-09 14:27:00 +07:00
|
|
|
/* max delay if bearer has links */
|
2018-03-23 02:42:46 +07:00
|
|
|
#define TIPC_DISC_SLOW msecs_to_jiffies(60000)
|
2015-01-09 14:27:00 +07:00
|
|
|
/* indicates no timer in use */
|
2018-03-23 02:42:46 +07:00
|
|
|
#define TIPC_DISC_INACTIVE 0xffffffff
|
2006-01-03 01:04:38 +07:00
|
|
|
|
|
|
|
/**
|
2018-03-23 02:42:46 +07: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 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
|
2018-03-23 02:42:46 +07:00
|
|
|
* @skb: request message to be (repeatedly) sent
|
2006-01-03 01:04:38 +07:00
|
|
|
* @timer: timer governing period between requests
|
|
|
|
* @timer_intv: current interval between requests (in ms)
|
|
|
|
*/
|
2018-03-23 02:42:46 +07: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 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;
|
2018-03-23 02:42:46 +07:00
|
|
|
struct sk_buff *skb;
|
2006-01-03 01:04:38 +07:00
|
|
|
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
|
|
|
*/
|
2018-03-23 02:42:46 +07:00
|
|
|
static void tipc_disc_init_msg(struct net *net, struct sk_buff *skb,
|
|
|
|
u32 mtyp, struct tipc_bearer *b)
|
2006-01-03 01:04:38 +07:00
|
|
|
{
|
2018-03-23 02:42:46 +07:00
|
|
|
struct tipc_net *tn = tipc_net(net);
|
2018-03-23 02:42:49 +07:00
|
|
|
u32 self = tipc_own_addr(net);
|
2015-11-20 02:30:47 +07:00
|
|
|
u32 dest_domain = b->domain;
|
2018-03-23 02:42:46 +07:00
|
|
|
struct tipc_msg *hdr;
|
2006-01-03 01:04:38 +07:00
|
|
|
|
2018-03-23 02:42:46 +07:00
|
|
|
hdr = buf_msg(skb);
|
2018-03-23 02:42:49 +07:00
|
|
|
tipc_msg_init(self, hdr, LINK_CONFIG, mtyp,
|
2015-03-05 16:23:48 +07:00
|
|
|
MAX_H_SIZE, dest_domain);
|
2018-03-23 02:42:46 +07: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-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)
|
2018-03-23 02:42:46 +07:00
|
|
|
* @net: applicable net namespace
|
|
|
|
* @skb: buffer containing message
|
|
|
|
* @b: 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,
|
2018-03-23 02:42:46 +07:00
|
|
|
struct tipc_bearer *b)
|
2006-01-03 01:04:38 +07:00
|
|
|
{
|
2018-03-23 02:42:46 +07:00
|
|
|
struct tipc_net *tn = tipc_net(net);
|
2015-07-31 05:24:22 +07:00
|
|
|
struct tipc_msg *hdr = buf_msg(skb);
|
2018-03-23 02:42:46 +07:00
|
|
|
u16 caps = msg_node_capabilities(hdr);
|
tipc: allow closest-first lookup algorithm when legacy address is configured
The removal of an internal structure of the node address has an unwanted
side effect.
- Currently, if a user is sending an anycast message with destination
domain 0, the tipc_namebl_translate() function will use the 'closest-
first' algorithm to first look for a node local destination, and only
when no such is found, will it resort to the cluster global 'round-
robin' lookup algorithm.
- Current users can get around this, and enforce unconditional use of
global round-robin by indicating a destination as Z.0.0 or Z.C.0.
- This option disappears when we make the node address flat, since the
lookup algorithm has no way of recognizing this case. So, as long as
there are node local destinations, the algorithm will always select
one of those, and there is nothing the sender can do to change this.
We solve this by eliminating the 'closest-first' option, which was never
a good idea anyway, for non-legacy users, but only for those. To
distinguish between legacy users and non-legacy users we introduce a new
flag 'legacy_addr_format' in struct tipc_core, to be set when the user
configures a legacy-style Z.C.N node address. Hence, when a legacy user
indicates a zero lookup domain 'closest-first' is selected, and in all
other cases we use 'round-robin'.
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-23 02:42:48 +07:00
|
|
|
bool legacy = tn->legacy_addr_format;
|
2018-03-23 02:42:46 +07:00
|
|
|
u32 signature = msg_node_sig(hdr);
|
|
|
|
u32 dst = msg_dest_domain(hdr);
|
2015-07-31 05:24:22 +07:00
|
|
|
u32 net_id = msg_bc_netid(hdr);
|
2018-03-23 02:42:46 +07:00
|
|
|
u32 self = tipc_own_addr(net);
|
|
|
|
struct tipc_media_addr maddr;
|
|
|
|
u32 src = msg_prevnode(hdr);
|
2015-07-31 05:24:22 +07:00
|
|
|
u32 mtyp = msg_type(hdr);
|
|
|
|
bool dupl_addr = false;
|
2018-03-23 02:42:46 +07:00
|
|
|
bool respond = false;
|
2016-06-27 18:34:06 +07:00
|
|
|
int err;
|
2006-01-03 01:04:38 +07:00
|
|
|
|
2018-03-23 02:42:46 +07:00
|
|
|
err = b->media->msg2addr(b, &maddr, msg_media_addr(hdr));
|
2015-07-31 05:24:22 +07:00
|
|
|
kfree_skb(skb);
|
2018-03-23 02:42:46 +07:00
|
|
|
if (err || maddr.broadcast) {
|
|
|
|
pr_warn_ratelimited("Rcv corrupt discovery message\n");
|
2016-06-27 18:34:06 +07:00
|
|
|
return;
|
2018-03-23 02:42:46 +07:00
|
|
|
}
|
|
|
|
/* Ignore discovery messages from own node */
|
|
|
|
if (!memcmp(&maddr, &b->addr, sizeof(maddr)))
|
2006-01-03 01:04:38 +07:00
|
|
|
return;
|
2018-03-23 02:42:46 +07:00
|
|
|
if (net_id != tn->net_id)
|
2011-10-08 02:48:41 +07:00
|
|
|
return;
|
2018-03-23 02:42:46 +07:00
|
|
|
if (in_own_node(net, src)) {
|
|
|
|
disc_dupl_alert(b, self, &maddr);
|
2006-01-03 01:04:38 +07:00
|
|
|
return;
|
2006-10-17 11:44:59 +07:00
|
|
|
}
|
tipc: allow closest-first lookup algorithm when legacy address is configured
The removal of an internal structure of the node address has an unwanted
side effect.
- Currently, if a user is sending an anycast message with destination
domain 0, the tipc_namebl_translate() function will use the 'closest-
first' algorithm to first look for a node local destination, and only
when no such is found, will it resort to the cluster global 'round-
robin' lookup algorithm.
- Current users can get around this, and enforce unconditional use of
global round-robin by indicating a destination as Z.0.0 or Z.C.0.
- This option disappears when we make the node address flat, since the
lookup algorithm has no way of recognizing this case. So, as long as
there are node local destinations, the algorithm will always select
one of those, and there is nothing the sender can do to change this.
We solve this by eliminating the 'closest-first' option, which was never
a good idea anyway, for non-legacy users, but only for those. To
distinguish between legacy users and non-legacy users we introduce a new
flag 'legacy_addr_format' in struct tipc_core, to be set when the user
configures a legacy-style Z.C.N node address. Hence, when a legacy user
indicates a zero lookup domain 'closest-first' is selected, and in all
other cases we use 'round-robin'.
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-23 02:42:48 +07:00
|
|
|
if (!tipc_in_scope(legacy, dst, self))
|
|
|
|
return;
|
|
|
|
if (!tipc_in_scope(legacy, b->domain, src))
|
|
|
|
return;
|
|
|
|
|
2018-03-23 02:42:46 +07:00
|
|
|
tipc_node_check_dest(net, src, b, caps, signature,
|
2015-07-31 05:24:22 +07:00
|
|
|
&maddr, &respond, &dupl_addr);
|
|
|
|
if (dupl_addr)
|
2018-03-23 02:42:46 +07: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-03 01:04:38 +07:00
|
|
|
}
|
|
|
|
|
2018-03-23 02:42:46 +07:00
|
|
|
/* tipc_disc_add_dest - increment set of discovered nodes
|
2006-01-03 01:04:38 +07:00
|
|
|
*/
|
2018-03-23 02:42:46 +07:00
|
|
|
void tipc_disc_add_dest(struct tipc_discoverer *d)
|
2006-01-03 01:04:38 +07:00
|
|
|
{
|
2018-03-23 02:42:46 +07:00
|
|
|
spin_lock_bh(&d->lock);
|
|
|
|
d->num_nodes++;
|
|
|
|
spin_unlock_bh(&d->lock);
|
2007-02-09 21:25:21 +07:00
|
|
|
}
|
2006-01-03 01:04:38 +07:00
|
|
|
|
2018-03-23 02:42:46 +07:00
|
|
|
/* tipc_disc_remove_dest - decrement set of discovered nodes
|
2011-04-22 07:05:25 +07:00
|
|
|
*/
|
2018-03-23 02:42:46 +07:00
|
|
|
void tipc_disc_remove_dest(struct tipc_discoverer *d)
|
2011-04-22 07:05:25 +07:00
|
|
|
{
|
2018-03-23 02:42:46 +07:00
|
|
|
int intv, num;
|
2011-04-22 07:05:25 +07:00
|
|
|
|
2018-03-23 02:42:46 +07: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 07:05:25 +07:00
|
|
|
}
|
|
|
|
|
2018-03-23 02:42:46 +07:00
|
|
|
/* tipc_disc_timeout - send a periodic link setup request
|
2006-01-03 01:04:38 +07:00
|
|
|
* Called whenever a link setup request timer associated with a bearer expires.
|
2018-03-23 02:42:46 +07: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-03 01:04:38 +07:00
|
|
|
*/
|
2018-03-23 02:42:46 +07:00
|
|
|
static void tipc_disc_timeout(struct timer_list *t)
|
2006-01-03 01:04:38 +07:00
|
|
|
{
|
2018-03-23 02:42:46 +07: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 08:34:03 +07:00
|
|
|
|
2018-03-23 02:42:46 +07:00
|
|
|
spin_lock_bh(&d->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 */
|
2018-03-23 02:42:46 +07:00
|
|
|
if (tipc_node(d->domain) && d->num_nodes) {
|
|
|
|
d->timer_intv = TIPC_DISC_INACTIVE;
|
2011-04-22 08:34:03 +07:00
|
|
|
goto exit;
|
2006-01-03 01:04:38 +07:00
|
|
|
}
|
2018-03-23 02:42:46 +07: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 08:34:03 +07:00
|
|
|
exit:
|
2018-03-23 02:42:46 +07:00
|
|
|
spin_unlock_bh(&d->lock);
|
|
|
|
if (skb)
|
|
|
|
tipc_bearer_xmit_skb(net, bearer_id, skb, &maddr);
|
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,
|
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 21:09:13 +07:00
|
|
|
struct tipc_media_addr *dest, struct sk_buff **skb)
|
2006-01-03 01:04:38 +07:00
|
|
|
{
|
2018-03-23 02:42:46 +07:00
|
|
|
struct tipc_discoverer *d;
|
2006-01-03 01:04:38 +07:00
|
|
|
|
2018-03-23 02:42:46 +07:00
|
|
|
d = kmalloc(sizeof(*d), GFP_ATOMIC);
|
|
|
|
if (!d)
|
2011-04-22 01:58:26 +07:00
|
|
|
return -ENOMEM;
|
2018-03-23 02:42:46 +07:00
|
|
|
d->skb = tipc_buf_acquire(MAX_H_SIZE, GFP_ATOMIC);
|
|
|
|
if (!d->skb) {
|
|
|
|
kfree(d);
|
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
|
|
|
|
2018-03-23 02:42:46 +07: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-22 01:58:26 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_disc_delete - destroy object sending periodic link setup requests
|
2018-03-23 02:42:46 +07:00
|
|
|
* @d: ptr to link duest structure
|
2011-04-22 01:58:26 +07:00
|
|
|
*/
|
2018-03-23 02:42:46 +07:00
|
|
|
void tipc_disc_delete(struct tipc_discoverer *d)
|
2011-04-22 01:58:26 +07:00
|
|
|
{
|
2018-03-23 02:42:46 +07:00
|
|
|
del_timer_sync(&d->timer);
|
|
|
|
kfree_skb(d->skb);
|
|
|
|
kfree(d);
|
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
|
|
|
{
|
2018-03-23 02:42:46 +07:00
|
|
|
struct tipc_discoverer *d = b->disc;
|
|
|
|
struct tipc_media_addr maddr;
|
2015-10-22 19:51:44 +07:00
|
|
|
struct sk_buff *skb;
|
2014-04-21 09:55:52 +07:00
|
|
|
|
2018-03-23 02:42:46 +07: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 19:51:44 +07:00
|
|
|
if (skb)
|
2018-03-23 02:42:46 +07:00
|
|
|
tipc_bearer_xmit_skb(net, b->identity, skb, &maddr);
|
2014-04-21 09:55:52 +07:00
|
|
|
}
|