2006-01-03 02:04:38 +08:00
|
|
|
/*
|
|
|
|
* net/tipc/node.c: TIPC node management routines
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
2015-05-14 22:46:18 +08:00
|
|
|
* Copyright (c) 2000-2006, 2012-2015, Ericsson AB
|
2014-03-27 12:54:36 +08:00
|
|
|
* Copyright (c) 2005-2006, 2010-2014, 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"
|
2015-02-09 16:50:18 +08:00
|
|
|
#include "link.h"
|
2006-01-03 02:04:38 +08:00
|
|
|
#include "node.h"
|
|
|
|
#include "name_distr.h"
|
2014-08-23 06:09:07 +08:00
|
|
|
#include "socket.h"
|
2015-05-14 22:46:13 +08:00
|
|
|
#include "bcast.h"
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
#include "discover.h"
|
2015-10-16 02:52:46 +08:00
|
|
|
|
2015-11-20 03:30:45 +08:00
|
|
|
#define INVALID_NODE_SIG 0x10000
|
|
|
|
|
|
|
|
/* Flags used to take different actions according to flag type
|
|
|
|
* TIPC_NOTIFY_NODE_DOWN: notify node is down
|
|
|
|
* TIPC_NOTIFY_NODE_UP: notify node is up
|
|
|
|
* TIPC_DISTRIBUTE_NAME: publish or withdraw link state name type
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
TIPC_NOTIFY_NODE_DOWN = (1 << 3),
|
|
|
|
TIPC_NOTIFY_NODE_UP = (1 << 4),
|
|
|
|
TIPC_NOTIFY_LINK_UP = (1 << 6),
|
|
|
|
TIPC_NOTIFY_LINK_DOWN = (1 << 7)
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tipc_link_entry {
|
|
|
|
struct tipc_link *link;
|
|
|
|
spinlock_t lock; /* per link */
|
|
|
|
u32 mtu;
|
|
|
|
struct sk_buff_head inputq;
|
|
|
|
struct tipc_media_addr maddr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tipc_bclink_entry {
|
|
|
|
struct tipc_link *link;
|
|
|
|
struct sk_buff_head inputq1;
|
|
|
|
struct sk_buff_head arrvq;
|
|
|
|
struct sk_buff_head inputq2;
|
|
|
|
struct sk_buff_head namedq;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct tipc_node - TIPC node structure
|
|
|
|
* @addr: network address of node
|
|
|
|
* @ref: reference counter to node object
|
|
|
|
* @lock: rwlock governing access to structure
|
|
|
|
* @net: the applicable net namespace
|
|
|
|
* @hash: links to adjacent nodes in unsorted hash chain
|
|
|
|
* @inputq: pointer to input queue containing messages for msg event
|
|
|
|
* @namedq: pointer to name table input queue with name table messages
|
|
|
|
* @active_links: bearer ids of active links, used as index into links[] array
|
|
|
|
* @links: array containing references to all links to node
|
|
|
|
* @action_flags: bit mask of different types of node actions
|
|
|
|
* @state: connectivity state vs peer node
|
|
|
|
* @sync_point: sequence number where synch/failover is finished
|
|
|
|
* @list: links to adjacent nodes in sorted list of cluster's nodes
|
|
|
|
* @working_links: number of working links to node (both active and standby)
|
|
|
|
* @link_cnt: number of links to node
|
|
|
|
* @capabilities: bitmap, indicating peer node's functional capabilities
|
|
|
|
* @signature: node instance identifier
|
|
|
|
* @link_id: local and remote bearer ids of changing link, if any
|
|
|
|
* @publ_list: list of publications
|
|
|
|
* @rcu: rcu struct for tipc_node
|
|
|
|
*/
|
|
|
|
struct tipc_node {
|
|
|
|
u32 addr;
|
|
|
|
struct kref kref;
|
|
|
|
rwlock_t lock;
|
|
|
|
struct net *net;
|
|
|
|
struct hlist_node hash;
|
|
|
|
int active_links[2];
|
|
|
|
struct tipc_link_entry links[MAX_BEARERS];
|
|
|
|
struct tipc_bclink_entry bc_entry;
|
|
|
|
int action_flags;
|
|
|
|
struct list_head list;
|
|
|
|
int state;
|
|
|
|
u16 sync_point;
|
|
|
|
int link_cnt;
|
|
|
|
u16 working_links;
|
|
|
|
u16 capabilities;
|
|
|
|
u32 signature;
|
|
|
|
u32 link_id;
|
|
|
|
struct list_head publ_list;
|
|
|
|
struct list_head conn_sks;
|
|
|
|
unsigned long keepalive_intv;
|
|
|
|
struct timer_list timer;
|
|
|
|
struct rcu_head rcu;
|
|
|
|
};
|
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
/* Node FSM states and events:
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
SELF_DOWN_PEER_DOWN = 0xdd,
|
|
|
|
SELF_UP_PEER_UP = 0xaa,
|
|
|
|
SELF_DOWN_PEER_LEAVING = 0xd1,
|
|
|
|
SELF_UP_PEER_COMING = 0xac,
|
|
|
|
SELF_COMING_PEER_UP = 0xca,
|
|
|
|
SELF_LEAVING_PEER_DOWN = 0x1d,
|
|
|
|
NODE_FAILINGOVER = 0xf0,
|
|
|
|
NODE_SYNCHING = 0xcc
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
SELF_ESTABL_CONTACT_EVT = 0xece,
|
|
|
|
SELF_LOST_CONTACT_EVT = 0x1ce,
|
|
|
|
PEER_ESTABL_CONTACT_EVT = 0x9ece,
|
|
|
|
PEER_LOST_CONTACT_EVT = 0x91ce,
|
|
|
|
NODE_FAILOVER_BEGIN_EVT = 0xfbe,
|
|
|
|
NODE_FAILOVER_END_EVT = 0xfee,
|
|
|
|
NODE_SYNCH_BEGIN_EVT = 0xcbe,
|
|
|
|
NODE_SYNCH_END_EVT = 0xcee
|
|
|
|
};
|
|
|
|
|
2015-07-31 06:24:23 +08:00
|
|
|
static void __tipc_node_link_down(struct tipc_node *n, int *bearer_id,
|
|
|
|
struct sk_buff_head *xmitq,
|
|
|
|
struct tipc_media_addr **maddr);
|
|
|
|
static void tipc_node_link_down(struct tipc_node *n, int bearer_id,
|
|
|
|
bool delete);
|
|
|
|
static void node_lost_contact(struct tipc_node *n, struct sk_buff_head *inputq);
|
2015-03-26 18:10:24 +08:00
|
|
|
static void tipc_node_delete(struct tipc_node *node);
|
2015-07-17 04:54:29 +08:00
|
|
|
static void tipc_node_timeout(unsigned long data);
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
static void tipc_node_fsm_evt(struct tipc_node *n, int evt);
|
2015-11-20 03:30:45 +08:00
|
|
|
static struct tipc_node *tipc_node_find(struct net *net, u32 addr);
|
|
|
|
static void tipc_node_put(struct tipc_node *node);
|
|
|
|
static bool tipc_node_is_up(struct tipc_node *n);
|
2006-01-03 02:04:38 +08:00
|
|
|
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
struct tipc_sock_conn {
|
|
|
|
u32 port;
|
|
|
|
u32 peer_port;
|
|
|
|
u32 peer_node;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2015-11-20 03:30:45 +08:00
|
|
|
static const struct nla_policy tipc_nl_link_policy[TIPC_NLA_LINK_MAX + 1] = {
|
|
|
|
[TIPC_NLA_LINK_UNSPEC] = { .type = NLA_UNSPEC },
|
|
|
|
[TIPC_NLA_LINK_NAME] = {
|
|
|
|
.type = NLA_STRING,
|
|
|
|
.len = TIPC_MAX_LINK_NAME
|
|
|
|
},
|
|
|
|
[TIPC_NLA_LINK_MTU] = { .type = NLA_U32 },
|
|
|
|
[TIPC_NLA_LINK_BROADCAST] = { .type = NLA_FLAG },
|
|
|
|
[TIPC_NLA_LINK_UP] = { .type = NLA_FLAG },
|
|
|
|
[TIPC_NLA_LINK_ACTIVE] = { .type = NLA_FLAG },
|
|
|
|
[TIPC_NLA_LINK_PROP] = { .type = NLA_NESTED },
|
|
|
|
[TIPC_NLA_LINK_STATS] = { .type = NLA_NESTED },
|
|
|
|
[TIPC_NLA_LINK_RX] = { .type = NLA_U32 },
|
|
|
|
[TIPC_NLA_LINK_TX] = { .type = NLA_U32 }
|
|
|
|
};
|
|
|
|
|
2014-11-20 17:29:17 +08:00
|
|
|
static const struct nla_policy tipc_nl_node_policy[TIPC_NLA_NODE_MAX + 1] = {
|
|
|
|
[TIPC_NLA_NODE_UNSPEC] = { .type = NLA_UNSPEC },
|
|
|
|
[TIPC_NLA_NODE_ADDR] = { .type = NLA_U32 },
|
|
|
|
[TIPC_NLA_NODE_UP] = { .type = NLA_FLAG }
|
|
|
|
};
|
|
|
|
|
2015-11-20 03:30:45 +08:00
|
|
|
static struct tipc_link *node_active_link(struct tipc_node *n, int sel)
|
|
|
|
{
|
|
|
|
int bearer_id = n->active_links[sel & 1];
|
|
|
|
|
|
|
|
if (unlikely(bearer_id == INVALID_BEARER_ID))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return n->links[bearer_id].link;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_node_get_mtu(struct net *net, u32 addr, u32 sel)
|
|
|
|
{
|
|
|
|
struct tipc_node *n;
|
|
|
|
int bearer_id;
|
|
|
|
unsigned int mtu = MAX_MSG_SIZE;
|
|
|
|
|
|
|
|
n = tipc_node_find(net, addr);
|
|
|
|
if (unlikely(!n))
|
|
|
|
return mtu;
|
|
|
|
|
|
|
|
bearer_id = n->active_links[sel & 1];
|
|
|
|
if (likely(bearer_id != INVALID_BEARER_ID))
|
|
|
|
mtu = n->links[bearer_id].mtu;
|
|
|
|
tipc_node_put(n);
|
|
|
|
return mtu;
|
|
|
|
}
|
2011-11-04 23:54:43 +08:00
|
|
|
/*
|
|
|
|
* A trivial power-of-two bitmask technique is used for speed, since this
|
|
|
|
* operation is done for every incoming TIPC packet. The number of hash table
|
|
|
|
* entries has been chosen so that no hash chain exceeds 8 nodes and will
|
|
|
|
* usually be much smaller (typically only a single node).
|
|
|
|
*/
|
2012-04-23 12:49:13 +08:00
|
|
|
static unsigned int tipc_hashfn(u32 addr)
|
2011-11-04 23:54:43 +08:00
|
|
|
{
|
|
|
|
return addr & (NODE_HTABLE_SIZE - 1);
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:10:24 +08:00
|
|
|
static void tipc_node_kref_release(struct kref *kref)
|
|
|
|
{
|
|
|
|
struct tipc_node *node = container_of(kref, struct tipc_node, kref);
|
|
|
|
|
|
|
|
tipc_node_delete(node);
|
|
|
|
}
|
|
|
|
|
2015-11-20 03:30:45 +08:00
|
|
|
static void tipc_node_put(struct tipc_node *node)
|
2015-03-26 18:10:24 +08:00
|
|
|
{
|
|
|
|
kref_put(&node->kref, tipc_node_kref_release);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tipc_node_get(struct tipc_node *node)
|
|
|
|
{
|
|
|
|
kref_get(&node->kref);
|
|
|
|
}
|
|
|
|
|
2011-10-28 03:03:24 +08:00
|
|
|
/*
|
2011-02-26 07:42:52 +08:00
|
|
|
* tipc_node_find - locate specified node object, if it exists
|
|
|
|
*/
|
2015-11-20 03:30:45 +08:00
|
|
|
static struct tipc_node *tipc_node_find(struct net *net, u32 addr)
|
2011-02-26 07:42:52 +08:00
|
|
|
{
|
2015-01-09 15:27:05 +08:00
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2011-02-26 07:42:52 +08:00
|
|
|
struct tipc_node *node;
|
|
|
|
|
2015-01-09 15:27:10 +08:00
|
|
|
if (unlikely(!in_own_cluster_exact(net, addr)))
|
2011-02-26 07:42:52 +08:00
|
|
|
return NULL;
|
|
|
|
|
2014-03-27 12:54:37 +08:00
|
|
|
rcu_read_lock();
|
2015-01-09 15:27:05 +08:00
|
|
|
hlist_for_each_entry_rcu(node, &tn->node_htable[tipc_hashfn(addr)],
|
|
|
|
hash) {
|
2014-03-27 12:54:36 +08:00
|
|
|
if (node->addr == addr) {
|
2015-03-26 18:10:24 +08:00
|
|
|
tipc_node_get(node);
|
2014-03-27 12:54:37 +08:00
|
|
|
rcu_read_unlock();
|
2011-02-26 07:42:52 +08:00
|
|
|
return node;
|
2014-03-27 12:54:36 +08:00
|
|
|
}
|
2011-02-26 07:42:52 +08:00
|
|
|
}
|
2014-03-27 12:54:37 +08:00
|
|
|
rcu_read_unlock();
|
2011-02-26 07:42:52 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-20 03:30:45 +08:00
|
|
|
static void tipc_node_read_lock(struct tipc_node *n)
|
2015-11-20 03:30:44 +08:00
|
|
|
{
|
|
|
|
read_lock_bh(&n->lock);
|
|
|
|
}
|
|
|
|
|
2015-11-20 03:30:45 +08:00
|
|
|
static void tipc_node_read_unlock(struct tipc_node *n)
|
2015-11-20 03:30:44 +08:00
|
|
|
{
|
|
|
|
read_unlock_bh(&n->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tipc_node_write_lock(struct tipc_node *n)
|
|
|
|
{
|
|
|
|
write_lock_bh(&n->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tipc_node_write_unlock(struct tipc_node *n)
|
|
|
|
{
|
|
|
|
struct net *net = n->net;
|
|
|
|
u32 addr = 0;
|
|
|
|
u32 flags = n->action_flags;
|
|
|
|
u32 link_id = 0;
|
|
|
|
struct list_head *publ_list;
|
|
|
|
|
|
|
|
if (likely(!flags)) {
|
|
|
|
write_unlock_bh(&n->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = n->addr;
|
|
|
|
link_id = n->link_id;
|
|
|
|
publ_list = &n->publ_list;
|
|
|
|
|
|
|
|
n->action_flags &= ~(TIPC_NOTIFY_NODE_DOWN | TIPC_NOTIFY_NODE_UP |
|
|
|
|
TIPC_NOTIFY_LINK_DOWN | TIPC_NOTIFY_LINK_UP);
|
|
|
|
|
|
|
|
write_unlock_bh(&n->lock);
|
|
|
|
|
|
|
|
if (flags & TIPC_NOTIFY_NODE_DOWN)
|
|
|
|
tipc_publ_notify(net, publ_list, addr);
|
|
|
|
|
|
|
|
if (flags & TIPC_NOTIFY_NODE_UP)
|
|
|
|
tipc_named_node_up(net, addr);
|
|
|
|
|
|
|
|
if (flags & TIPC_NOTIFY_LINK_UP)
|
|
|
|
tipc_nametbl_publish(net, TIPC_LINK_STATE, addr, addr,
|
|
|
|
TIPC_NODE_SCOPE, link_id, addr);
|
|
|
|
|
|
|
|
if (flags & TIPC_NOTIFY_LINK_DOWN)
|
|
|
|
tipc_nametbl_withdraw(net, TIPC_LINK_STATE, addr,
|
|
|
|
link_id, addr);
|
|
|
|
}
|
|
|
|
|
2015-07-31 06:24:22 +08:00
|
|
|
struct tipc_node *tipc_node_create(struct net *net, u32 addr, u16 capabilities)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2015-01-09 15:27:05 +08:00
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2015-11-20 03:30:47 +08:00
|
|
|
struct tipc_node *n, *temp_node;
|
2015-11-20 03:30:44 +08:00
|
|
|
int i;
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2015-01-09 15:27:05 +08:00
|
|
|
spin_lock_bh(&tn->node_list_lock);
|
2015-11-20 03:30:47 +08:00
|
|
|
n = tipc_node_find(net, addr);
|
|
|
|
if (n)
|
2015-02-03 21:59:19 +08:00
|
|
|
goto exit;
|
2015-11-20 03:30:47 +08:00
|
|
|
n = kzalloc(sizeof(*n), GFP_ATOMIC);
|
|
|
|
if (!n) {
|
2012-06-29 12:16:37 +08:00
|
|
|
pr_warn("Node creation failed, no memory\n");
|
2015-02-03 21:59:19 +08:00
|
|
|
goto exit;
|
2006-06-26 14:52:17 +08:00
|
|
|
}
|
2015-11-20 03:30:47 +08:00
|
|
|
n->addr = addr;
|
|
|
|
n->net = net;
|
|
|
|
n->capabilities = capabilities;
|
|
|
|
kref_init(&n->kref);
|
|
|
|
rwlock_init(&n->lock);
|
|
|
|
INIT_HLIST_NODE(&n->hash);
|
|
|
|
INIT_LIST_HEAD(&n->list);
|
|
|
|
INIT_LIST_HEAD(&n->publ_list);
|
|
|
|
INIT_LIST_HEAD(&n->conn_sks);
|
|
|
|
skb_queue_head_init(&n->bc_entry.namedq);
|
|
|
|
skb_queue_head_init(&n->bc_entry.inputq1);
|
|
|
|
__skb_queue_head_init(&n->bc_entry.arrvq);
|
|
|
|
skb_queue_head_init(&n->bc_entry.inputq2);
|
2015-11-20 03:30:44 +08:00
|
|
|
for (i = 0; i < MAX_BEARERS; i++)
|
2015-11-20 03:30:47 +08:00
|
|
|
spin_lock_init(&n->links[i].lock);
|
|
|
|
hlist_add_head_rcu(&n->hash, &tn->node_htable[tipc_hashfn(addr)]);
|
2015-01-09 15:27:05 +08:00
|
|
|
list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
|
2015-11-20 03:30:47 +08:00
|
|
|
if (n->addr < temp_node->addr)
|
2011-02-26 07:42:52 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-11-20 03:30:47 +08:00
|
|
|
list_add_tail_rcu(&n->list, &temp_node->list);
|
|
|
|
n->state = SELF_DOWN_PEER_LEAVING;
|
|
|
|
n->signature = INVALID_NODE_SIG;
|
|
|
|
n->active_links[0] = INVALID_BEARER_ID;
|
|
|
|
n->active_links[1] = INVALID_BEARER_ID;
|
|
|
|
if (!tipc_link_bc_create(net, tipc_own_addr(net), n->addr,
|
2015-11-20 03:30:46 +08:00
|
|
|
U16_MAX,
|
|
|
|
tipc_link_window(tipc_bc_sndlink(net)),
|
2015-11-20 03:30:47 +08:00
|
|
|
n->capabilities,
|
|
|
|
&n->bc_entry.inputq1,
|
|
|
|
&n->bc_entry.namedq,
|
2015-10-22 20:51:41 +08:00
|
|
|
tipc_bc_sndlink(net),
|
2015-11-20 03:30:47 +08:00
|
|
|
&n->bc_entry.link)) {
|
2015-10-22 20:51:41 +08:00
|
|
|
pr_warn("Broadcast rcv link creation failed, no memory\n");
|
2015-11-20 03:30:47 +08:00
|
|
|
kfree(n);
|
|
|
|
n = NULL;
|
2015-10-22 20:51:41 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-11-20 03:30:47 +08:00
|
|
|
tipc_node_get(n);
|
|
|
|
setup_timer(&n->timer, tipc_node_timeout, (unsigned long)n);
|
|
|
|
n->keepalive_intv = U32_MAX;
|
2015-02-03 21:59:19 +08:00
|
|
|
exit:
|
2015-01-09 15:27:05 +08:00
|
|
|
spin_unlock_bh(&tn->node_list_lock);
|
2015-11-20 03:30:47 +08:00
|
|
|
return n;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2015-07-17 04:54:29 +08:00
|
|
|
static void tipc_node_calculate_timer(struct tipc_node *n, struct tipc_link *l)
|
|
|
|
{
|
2015-11-20 03:30:46 +08:00
|
|
|
unsigned long tol = tipc_link_tolerance(l);
|
2015-07-17 04:54:29 +08:00
|
|
|
unsigned long intv = ((tol / 4) > 500) ? 500 : tol / 4;
|
|
|
|
unsigned long keepalive_intv = msecs_to_jiffies(intv);
|
|
|
|
|
|
|
|
/* Link with lowest tolerance determines timer interval */
|
|
|
|
if (keepalive_intv < n->keepalive_intv)
|
|
|
|
n->keepalive_intv = keepalive_intv;
|
|
|
|
|
|
|
|
/* Ensure link's abort limit corresponds to current interval */
|
2015-11-20 03:30:46 +08:00
|
|
|
tipc_link_set_abort_limit(l, tol / jiffies_to_msecs(n->keepalive_intv));
|
2015-07-17 04:54:29 +08:00
|
|
|
}
|
|
|
|
|
2015-03-26 18:10:24 +08:00
|
|
|
static void tipc_node_delete(struct tipc_node *node)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2015-03-26 18:10:24 +08:00
|
|
|
list_del_rcu(&node->list);
|
|
|
|
hlist_del_rcu(&node->hash);
|
2015-10-22 20:51:41 +08:00
|
|
|
kfree(node->bc_entry.link);
|
2015-03-26 18:10:24 +08:00
|
|
|
kfree_rcu(node, rcu);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2015-01-09 15:27:05 +08:00
|
|
|
void tipc_node_stop(struct net *net)
|
2014-03-27 12:54:36 +08:00
|
|
|
{
|
2015-01-09 15:27:05 +08:00
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2014-03-27 12:54:36 +08:00
|
|
|
struct tipc_node *node, *t_node;
|
|
|
|
|
2015-01-09 15:27:05 +08:00
|
|
|
spin_lock_bh(&tn->node_list_lock);
|
2015-07-17 04:54:29 +08:00
|
|
|
list_for_each_entry_safe(node, t_node, &tn->node_list, list) {
|
|
|
|
if (del_timer(&node->timer))
|
|
|
|
tipc_node_put(node);
|
2015-03-26 18:10:24 +08:00
|
|
|
tipc_node_put(node);
|
2015-07-17 04:54:29 +08:00
|
|
|
}
|
2015-01-09 15:27:05 +08:00
|
|
|
spin_unlock_bh(&tn->node_list_lock);
|
2014-03-27 12:54:36 +08:00
|
|
|
}
|
|
|
|
|
2015-11-20 03:30:42 +08:00
|
|
|
void tipc_node_subscribe(struct net *net, struct list_head *subscr, u32 addr)
|
|
|
|
{
|
|
|
|
struct tipc_node *n;
|
|
|
|
|
|
|
|
if (in_own_node(net, addr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
n = tipc_node_find(net, addr);
|
|
|
|
if (!n) {
|
|
|
|
pr_warn("Node subscribe rejected, unknown node 0x%x\n", addr);
|
|
|
|
return;
|
|
|
|
}
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_lock(n);
|
2015-11-20 03:30:42 +08:00
|
|
|
list_add_tail(subscr, &n->publ_list);
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_unlock(n);
|
2015-11-20 03:30:42 +08:00
|
|
|
tipc_node_put(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tipc_node_unsubscribe(struct net *net, struct list_head *subscr, u32 addr)
|
|
|
|
{
|
|
|
|
struct tipc_node *n;
|
|
|
|
|
|
|
|
if (in_own_node(net, addr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
n = tipc_node_find(net, addr);
|
|
|
|
if (!n) {
|
|
|
|
pr_warn("Node unsubscribe rejected, unknown node 0x%x\n", addr);
|
|
|
|
return;
|
|
|
|
}
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_lock(n);
|
2015-11-20 03:30:42 +08:00
|
|
|
list_del_init(subscr);
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_unlock(n);
|
2015-11-20 03:30:42 +08:00
|
|
|
tipc_node_put(n);
|
|
|
|
}
|
|
|
|
|
2015-01-09 15:27:05 +08:00
|
|
|
int tipc_node_add_conn(struct net *net, u32 dnode, u32 port, u32 peer_port)
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
{
|
|
|
|
struct tipc_node *node;
|
|
|
|
struct tipc_sock_conn *conn;
|
2015-03-26 18:10:24 +08:00
|
|
|
int err = 0;
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
|
2015-01-09 15:27:10 +08:00
|
|
|
if (in_own_node(net, dnode))
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
return 0;
|
|
|
|
|
2015-01-09 15:27:05 +08:00
|
|
|
node = tipc_node_find(net, dnode);
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
if (!node) {
|
|
|
|
pr_warn("Connecting sock to node 0x%x failed\n", dnode);
|
|
|
|
return -EHOSTUNREACH;
|
|
|
|
}
|
|
|
|
conn = kmalloc(sizeof(*conn), GFP_ATOMIC);
|
2015-03-26 18:10:24 +08:00
|
|
|
if (!conn) {
|
|
|
|
err = -EHOSTUNREACH;
|
|
|
|
goto exit;
|
|
|
|
}
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
conn->peer_node = dnode;
|
|
|
|
conn->port = port;
|
|
|
|
conn->peer_port = peer_port;
|
|
|
|
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_lock(node);
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
list_add_tail(&conn->list, &node->conn_sks);
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_unlock(node);
|
2015-03-26 18:10:24 +08:00
|
|
|
exit:
|
|
|
|
tipc_node_put(node);
|
|
|
|
return err;
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
}
|
|
|
|
|
2015-01-09 15:27:05 +08:00
|
|
|
void tipc_node_remove_conn(struct net *net, u32 dnode, u32 port)
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
{
|
|
|
|
struct tipc_node *node;
|
|
|
|
struct tipc_sock_conn *conn, *safe;
|
|
|
|
|
2015-01-09 15:27:10 +08:00
|
|
|
if (in_own_node(net, dnode))
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
return;
|
|
|
|
|
2015-01-09 15:27:05 +08:00
|
|
|
node = tipc_node_find(net, dnode);
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_lock(node);
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
list_for_each_entry_safe(conn, safe, &node->conn_sks, list) {
|
|
|
|
if (port != conn->port)
|
|
|
|
continue;
|
|
|
|
list_del(&conn->list);
|
|
|
|
kfree(conn);
|
|
|
|
}
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_unlock(node);
|
2015-03-26 18:10:24 +08:00
|
|
|
tipc_node_put(node);
|
tipc: use message to abort connections when losing contact to node
In the current implementation, each 'struct tipc_node' instance keeps
a linked list of those ports/sockets that are connected to the node
represented by that struct. The purpose of this is to let the node
object know which sockets to alert when it loses contact with its peer
node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure
back to the port/socket structure, and a need to grab port_lock
when we have to make an upcall to the port. We want to get rid of
this unecessary BH entry point into the socket, and also eliminate
its use of port_lock.
In this commit, we instead let the node struct keep list of "connected
socket" structs, which each represents a connected socket, but is
allocated independently by the node at the moment of connection. If
the node loses contact with its peer node, the list is traversed, and
a "connection abort" message is created for each entry in the list. The
message is sent to it respective connected socket using the ordinary
data path, and the receiving socket aborts its connections upon reception
of the message.
This enables us to get rid of the direct reference from 'struct node' to
´struct port', and another unwanted BH access point to the latter.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-08-23 06:09:08 +08:00
|
|
|
}
|
|
|
|
|
2015-07-17 04:54:29 +08:00
|
|
|
/* tipc_node_timeout - handle expiration of node timer
|
|
|
|
*/
|
|
|
|
static void tipc_node_timeout(unsigned long data)
|
|
|
|
{
|
|
|
|
struct tipc_node *n = (struct tipc_node *)data;
|
2015-07-31 06:24:23 +08:00
|
|
|
struct tipc_link_entry *le;
|
2015-07-17 04:54:29 +08:00
|
|
|
struct sk_buff_head xmitq;
|
|
|
|
int bearer_id;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
__skb_queue_head_init(&xmitq);
|
|
|
|
|
|
|
|
for (bearer_id = 0; bearer_id < MAX_BEARERS; bearer_id++) {
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_lock(n);
|
2015-07-31 06:24:23 +08:00
|
|
|
le = &n->links[bearer_id];
|
2015-11-20 03:30:43 +08:00
|
|
|
spin_lock_bh(&le->lock);
|
2015-07-31 06:24:23 +08:00
|
|
|
if (le->link) {
|
2015-07-17 04:54:29 +08:00
|
|
|
/* Link tolerance may change asynchronously: */
|
2015-07-31 06:24:23 +08:00
|
|
|
tipc_node_calculate_timer(n, le->link);
|
|
|
|
rc = tipc_link_timeout(le->link, &xmitq);
|
2015-07-17 04:54:29 +08:00
|
|
|
}
|
2015-11-20 03:30:43 +08:00
|
|
|
spin_unlock_bh(&le->lock);
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_unlock(n);
|
2015-07-31 06:24:23 +08:00
|
|
|
tipc_bearer_xmit(n->net, bearer_id, &xmitq, &le->maddr);
|
|
|
|
if (rc & TIPC_LINK_DOWN_EVT)
|
|
|
|
tipc_node_link_down(n, bearer_id, false);
|
2015-07-17 04:54:29 +08:00
|
|
|
}
|
|
|
|
if (!mod_timer(&n->timer, jiffies + n->keepalive_intv))
|
|
|
|
tipc_node_get(n);
|
|
|
|
tipc_node_put(n);
|
|
|
|
}
|
|
|
|
|
2006-01-03 02:04:38 +08:00
|
|
|
/**
|
2015-07-31 06:24:23 +08:00
|
|
|
* __tipc_node_link_up - handle addition of link
|
|
|
|
* Node lock must be held by caller
|
2006-01-03 02:04:38 +08:00
|
|
|
* Link becomes active (alone or shared) or standby, depending on its priority.
|
|
|
|
*/
|
2015-07-31 06:24:23 +08:00
|
|
|
static void __tipc_node_link_up(struct tipc_node *n, int bearer_id,
|
|
|
|
struct sk_buff_head *xmitq)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2015-07-17 04:54:22 +08:00
|
|
|
int *slot0 = &n->active_links[0];
|
|
|
|
int *slot1 = &n->active_links[1];
|
2015-07-31 06:24:19 +08:00
|
|
|
struct tipc_link *ol = node_active_link(n, 0);
|
|
|
|
struct tipc_link *nl = n->links[bearer_id].link;
|
2015-07-17 04:54:19 +08:00
|
|
|
|
tipc: delay ESTABLISH state event when link is established
Link establishing, just like link teardown, is a non-atomic action, in
the sense that discovering that conditions are right to establish a link,
and the actual adding of the link to one of the node's send slots is done
in two different lock contexts. The link FSM is designed to help bridging
the gap between the two contexts in a safe manner.
We have now discovered a weakness in the implementaton of this FSM.
Because we directly let the link go from state LINK_ESTABLISHING to
state LINK_ESTABLISHED already in the first lock context, we are unable
to distinguish between a fully established link, i.e., a link that has
been added to its slot, and a link that has not yet reached the second
lock context. It may hence happen that a manual intervention, e.g., when
disabling an interface, causes the function tipc_node_link_down() to try
removing the link from the node slots, decrementing its active link
counter etc, although the link was never added there in the first place.
We solve this by delaying the actual state change until we reach the
second lock context, inside the function tipc_node_link_up(). This
makes it possible for potentail callers of __tipc_node_link_down() to
know if they should proceed or not, and the problem is solved.
Unforunately, the situation described above also has a second problem.
Since there by necessity is a tipc_node_link_up() call pending once
the node lock has been released, we must defuse that call by setting
the link back from LINK_ESTABLISHING to LINK_RESET state. This forces
us to make a slight modification to the link FSM, which will now look
as follows.
+------------------------------------+
|RESET_EVT |
| |
| +--------------+
| +-----------------| SYNCHING |-----------------+
| |FAILURE_EVT +--------------+ PEER_RESET_EVT|
| | A | |
| | | | |
| | | | |
| | |SYNCH_ |SYNCH_ |
| | |BEGIN_EVT |END_EVT |
| | | | |
| V | V V
| +-------------+ +--------------+ +------------+
| | RESETTING |<---------| ESTABLISHED |--------->| PEER_RESET |
| +-------------+ FAILURE_ +--------------+ PEER_ +------------+
| | EVT | A RESET_EVT |
| | | | |
| | +----------------+ | |
| RESET_EVT| |RESET_EVT | |
| | | | |
| | | |ESTABLISH_EVT |
| | | +-------------+ | |
| | | | RESET_EVT | | |
| | | | | | |
| V V V | | |
| +-------------+ +--------------+ RESET_EVT|
+--->| RESET |--------->| ESTABLISHING |<----------------+
+-------------+ PEER_ +--------------+
| A RESET_EVT |
| | |
| | |
|FAILOVER_ |FAILOVER_ |FAILOVER_
|BEGIN_EVT |END_EVT |BEGIN_EVT
| | |
V | |
+-------------+ |
| FAILINGOVER |<----------------+
+-------------+
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-10-16 02:52:44 +08:00
|
|
|
if (!nl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tipc_link_fsm_evt(nl, LINK_ESTABLISH_EVT);
|
|
|
|
if (!tipc_link_is_up(nl))
|
2015-07-31 06:24:23 +08:00
|
|
|
return;
|
|
|
|
|
2015-07-17 04:54:19 +08:00
|
|
|
n->working_links++;
|
|
|
|
n->action_flags |= TIPC_NOTIFY_LINK_UP;
|
2015-11-20 03:30:46 +08:00
|
|
|
n->link_id = tipc_link_id(nl);
|
2015-07-31 06:24:19 +08:00
|
|
|
|
|
|
|
/* Leave room for tunnel header when returning 'mtu' to users: */
|
2015-11-20 03:30:46 +08:00
|
|
|
n->links[bearer_id].mtu = tipc_link_mtu(nl) - INT_H_SIZE;
|
2014-10-20 14:44:25 +08:00
|
|
|
|
2015-07-31 06:24:15 +08:00
|
|
|
tipc_bearer_add_dest(n->net, bearer_id, n->addr);
|
tipc: simplify bearer level broadcast
Until now, we have been keeping track of the exact set of broadcast
destinations though the help structure tipc_node_map. This leads us to
have to maintain a whole infrastructure for supporting this, including
a pseudo-bearer and a number of functions to manipulate both the bearers
and the node map correctly. Apart from the complexity, this approach is
also limiting, as struct tipc_node_map only can support cluster local
broadcast if we want to avoid it becoming excessively large. We want to
eliminate this limitation, in order to enable introduction of scoped
multicast in the future.
A closer analysis reveals that it is unnecessary maintaining this "full
set" overview; it is sufficient to keep a counter per bearer, indicating
how many nodes can be reached via this bearer at the moment. The protocol
is now robust enough to handle transitional discrepancies between the
nominal number of reachable destinations, as expected by the broadcast
protocol itself, and the number which is actually reachable at the
moment. The initial broadcast synchronization, in conjunction with the
retransmission mechanism, ensures that all packets will eventually be
acknowledged by the correct set of destinations.
This commit introduces these changes.
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>
2015-10-22 20:51:42 +08:00
|
|
|
tipc_bcast_inc_bearer_dst_cnt(n->net, bearer_id);
|
2015-07-31 06:24:15 +08:00
|
|
|
|
2015-01-23 00:10:31 +08:00
|
|
|
pr_debug("Established link <%s> on network plane %c\n",
|
2015-11-20 03:30:46 +08:00
|
|
|
tipc_link_name(nl), tipc_link_plane(nl));
|
2007-02-09 22:25:21 +08:00
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
/* First link? => give it both slots */
|
|
|
|
if (!ol) {
|
2015-07-17 04:54:22 +08:00
|
|
|
*slot0 = bearer_id;
|
|
|
|
*slot1 = bearer_id;
|
2015-10-22 20:51:41 +08:00
|
|
|
tipc_node_fsm_evt(n, SELF_ESTABL_CONTACT_EVT);
|
|
|
|
n->action_flags |= TIPC_NOTIFY_NODE_UP;
|
tipc: simplify bearer level broadcast
Until now, we have been keeping track of the exact set of broadcast
destinations though the help structure tipc_node_map. This leads us to
have to maintain a whole infrastructure for supporting this, including
a pseudo-bearer and a number of functions to manipulate both the bearers
and the node map correctly. Apart from the complexity, this approach is
also limiting, as struct tipc_node_map only can support cluster local
broadcast if we want to avoid it becoming excessively large. We want to
eliminate this limitation, in order to enable introduction of scoped
multicast in the future.
A closer analysis reveals that it is unnecessary maintaining this "full
set" overview; it is sufficient to keep a counter per bearer, indicating
how many nodes can be reached via this bearer at the moment. The protocol
is now robust enough to handle transitional discrepancies between the
nominal number of reachable destinations, as expected by the broadcast
protocol itself, and the number which is actually reachable at the
moment. The initial broadcast synchronization, in conjunction with the
retransmission mechanism, ensures that all packets will eventually be
acknowledged by the correct set of destinations.
This commit introduces these changes.
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>
2015-10-22 20:51:42 +08:00
|
|
|
tipc_bcast_add_peer(n->net, nl, xmitq);
|
2015-07-17 04:54:19 +08:00
|
|
|
return;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
2015-07-17 04:54:22 +08:00
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
/* Second link => redistribute slots */
|
2015-11-20 03:30:46 +08:00
|
|
|
if (tipc_link_prio(nl) > tipc_link_prio(ol)) {
|
|
|
|
pr_debug("Old link <%s> becomes standby\n", tipc_link_name(ol));
|
2015-07-17 04:54:22 +08:00
|
|
|
*slot0 = bearer_id;
|
2015-07-31 06:24:19 +08:00
|
|
|
*slot1 = bearer_id;
|
2015-10-22 20:51:46 +08:00
|
|
|
tipc_link_set_active(nl, true);
|
|
|
|
tipc_link_set_active(ol, false);
|
2015-11-20 03:30:46 +08:00
|
|
|
} else if (tipc_link_prio(nl) == tipc_link_prio(ol)) {
|
2015-10-22 20:51:46 +08:00
|
|
|
tipc_link_set_active(nl, true);
|
2015-10-22 20:51:47 +08:00
|
|
|
*slot1 = bearer_id;
|
2015-07-31 06:24:19 +08:00
|
|
|
} else {
|
2015-11-20 03:30:46 +08:00
|
|
|
pr_debug("New link <%s> is standby\n", tipc_link_name(nl));
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
/* Prepare synchronization with first link */
|
|
|
|
tipc_link_tnl_prepare(ol, nl, SYNCH_MSG, xmitq);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-31 06:24:23 +08:00
|
|
|
* tipc_node_link_up - handle addition of link
|
|
|
|
*
|
|
|
|
* Link becomes active (alone or shared) or standby, depending on its priority.
|
2006-01-03 02:04:38 +08:00
|
|
|
*/
|
2015-07-31 06:24:23 +08:00
|
|
|
static void tipc_node_link_up(struct tipc_node *n, int bearer_id,
|
|
|
|
struct sk_buff_head *xmitq)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_lock(n);
|
2015-07-31 06:24:23 +08:00
|
|
|
__tipc_node_link_up(n, bearer_id, xmitq);
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_unlock(n);
|
2015-07-31 06:24:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __tipc_node_link_down - handle loss of link
|
|
|
|
*/
|
|
|
|
static void __tipc_node_link_down(struct tipc_node *n, int *bearer_id,
|
|
|
|
struct sk_buff_head *xmitq,
|
|
|
|
struct tipc_media_addr **maddr)
|
|
|
|
{
|
|
|
|
struct tipc_link_entry *le = &n->links[*bearer_id];
|
2015-07-17 04:54:22 +08:00
|
|
|
int *slot0 = &n->active_links[0];
|
|
|
|
int *slot1 = &n->active_links[1];
|
2015-11-20 03:30:46 +08:00
|
|
|
int i, highest = 0, prio;
|
2015-07-31 06:24:19 +08:00
|
|
|
struct tipc_link *l, *_l, *tnl;
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2015-07-31 06:24:23 +08:00
|
|
|
l = n->links[*bearer_id].link;
|
2015-07-31 06:24:21 +08:00
|
|
|
if (!l || tipc_link_is_reset(l))
|
2015-07-31 06:24:17 +08:00
|
|
|
return;
|
|
|
|
|
2015-07-17 04:54:19 +08:00
|
|
|
n->working_links--;
|
|
|
|
n->action_flags |= TIPC_NOTIFY_LINK_DOWN;
|
2015-11-20 03:30:46 +08:00
|
|
|
n->link_id = tipc_link_id(l);
|
2006-06-26 14:52:50 +08:00
|
|
|
|
2015-07-31 06:24:23 +08:00
|
|
|
tipc_bearer_remove_dest(n->net, *bearer_id, n->addr);
|
2015-07-31 06:24:17 +08:00
|
|
|
|
2015-01-23 00:10:31 +08:00
|
|
|
pr_debug("Lost link <%s> on network plane %c\n",
|
2015-11-20 03:30:46 +08:00
|
|
|
tipc_link_name(l), tipc_link_plane(l));
|
2014-06-26 09:41:33 +08:00
|
|
|
|
2015-07-17 04:54:22 +08:00
|
|
|
/* Select new active link if any available */
|
|
|
|
*slot0 = INVALID_BEARER_ID;
|
|
|
|
*slot1 = INVALID_BEARER_ID;
|
|
|
|
for (i = 0; i < MAX_BEARERS; i++) {
|
|
|
|
_l = n->links[i].link;
|
|
|
|
if (!_l || !tipc_link_is_up(_l))
|
|
|
|
continue;
|
2015-07-31 06:24:17 +08:00
|
|
|
if (_l == l)
|
|
|
|
continue;
|
2015-11-20 03:30:46 +08:00
|
|
|
prio = tipc_link_prio(_l);
|
|
|
|
if (prio < highest)
|
2015-07-17 04:54:22 +08:00
|
|
|
continue;
|
2015-11-20 03:30:46 +08:00
|
|
|
if (prio > highest) {
|
|
|
|
highest = prio;
|
2015-07-17 04:54:22 +08:00
|
|
|
*slot0 = i;
|
|
|
|
*slot1 = i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*slot1 = i;
|
|
|
|
}
|
2015-07-31 06:24:17 +08:00
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
if (!tipc_node_is_up(n)) {
|
2015-10-16 02:52:46 +08:00
|
|
|
if (tipc_link_peer_is_down(l))
|
|
|
|
tipc_node_fsm_evt(n, PEER_LOST_CONTACT_EVT);
|
|
|
|
tipc_node_fsm_evt(n, SELF_LOST_CONTACT_EVT);
|
|
|
|
tipc_link_fsm_evt(l, LINK_RESET_EVT);
|
2015-07-31 06:24:19 +08:00
|
|
|
tipc_link_reset(l);
|
2015-10-16 02:52:45 +08:00
|
|
|
tipc_link_build_reset_msg(l, xmitq);
|
|
|
|
*maddr = &n->links[*bearer_id].maddr;
|
2015-07-31 06:24:23 +08:00
|
|
|
node_lost_contact(n, &le->inputq);
|
tipc: simplify bearer level broadcast
Until now, we have been keeping track of the exact set of broadcast
destinations though the help structure tipc_node_map. This leads us to
have to maintain a whole infrastructure for supporting this, including
a pseudo-bearer and a number of functions to manipulate both the bearers
and the node map correctly. Apart from the complexity, this approach is
also limiting, as struct tipc_node_map only can support cluster local
broadcast if we want to avoid it becoming excessively large. We want to
eliminate this limitation, in order to enable introduction of scoped
multicast in the future.
A closer analysis reveals that it is unnecessary maintaining this "full
set" overview; it is sufficient to keep a counter per bearer, indicating
how many nodes can be reached via this bearer at the moment. The protocol
is now robust enough to handle transitional discrepancies between the
nominal number of reachable destinations, as expected by the broadcast
protocol itself, and the number which is actually reachable at the
moment. The initial broadcast synchronization, in conjunction with the
retransmission mechanism, ensures that all packets will eventually be
acknowledged by the correct set of destinations.
This commit introduces these changes.
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>
2015-10-22 20:51:42 +08:00
|
|
|
tipc_bcast_dec_bearer_dst_cnt(n->net, *bearer_id);
|
2015-07-31 06:24:19 +08:00
|
|
|
return;
|
|
|
|
}
|
tipc: simplify bearer level broadcast
Until now, we have been keeping track of the exact set of broadcast
destinations though the help structure tipc_node_map. This leads us to
have to maintain a whole infrastructure for supporting this, including
a pseudo-bearer and a number of functions to manipulate both the bearers
and the node map correctly. Apart from the complexity, this approach is
also limiting, as struct tipc_node_map only can support cluster local
broadcast if we want to avoid it becoming excessively large. We want to
eliminate this limitation, in order to enable introduction of scoped
multicast in the future.
A closer analysis reveals that it is unnecessary maintaining this "full
set" overview; it is sufficient to keep a counter per bearer, indicating
how many nodes can be reached via this bearer at the moment. The protocol
is now robust enough to handle transitional discrepancies between the
nominal number of reachable destinations, as expected by the broadcast
protocol itself, and the number which is actually reachable at the
moment. The initial broadcast synchronization, in conjunction with the
retransmission mechanism, ensures that all packets will eventually be
acknowledged by the correct set of destinations.
This commit introduces these changes.
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>
2015-10-22 20:51:42 +08:00
|
|
|
tipc_bcast_dec_bearer_dst_cnt(n->net, *bearer_id);
|
2015-07-31 06:24:17 +08:00
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
/* There is still a working link => initiate failover */
|
2015-11-20 03:30:46 +08:00
|
|
|
*bearer_id = n->active_links[0];
|
|
|
|
tnl = n->links[*bearer_id].link;
|
2015-08-20 14:12:55 +08:00
|
|
|
tipc_link_fsm_evt(tnl, LINK_SYNCH_END_EVT);
|
|
|
|
tipc_node_fsm_evt(n, NODE_SYNCH_END_EVT);
|
2015-11-20 03:30:46 +08:00
|
|
|
n->sync_point = tipc_link_rcv_nxt(tnl) + (U16_MAX / 2 - 1);
|
2015-07-31 06:24:23 +08:00
|
|
|
tipc_link_tnl_prepare(l, tnl, FAILOVER_MSG, xmitq);
|
2015-07-31 06:24:17 +08:00
|
|
|
tipc_link_reset(l);
|
2015-10-16 02:52:46 +08:00
|
|
|
tipc_link_fsm_evt(l, LINK_RESET_EVT);
|
2015-07-31 06:24:21 +08:00
|
|
|
tipc_link_fsm_evt(l, LINK_FAILOVER_BEGIN_EVT);
|
2015-07-31 06:24:23 +08:00
|
|
|
tipc_node_fsm_evt(n, NODE_FAILOVER_BEGIN_EVT);
|
2015-11-20 03:30:46 +08:00
|
|
|
*maddr = &n->links[*bearer_id].maddr;
|
2015-07-31 06:24:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tipc_node_link_down(struct tipc_node *n, int bearer_id, bool delete)
|
|
|
|
{
|
|
|
|
struct tipc_link_entry *le = &n->links[bearer_id];
|
tipc: delay ESTABLISH state event when link is established
Link establishing, just like link teardown, is a non-atomic action, in
the sense that discovering that conditions are right to establish a link,
and the actual adding of the link to one of the node's send slots is done
in two different lock contexts. The link FSM is designed to help bridging
the gap between the two contexts in a safe manner.
We have now discovered a weakness in the implementaton of this FSM.
Because we directly let the link go from state LINK_ESTABLISHING to
state LINK_ESTABLISHED already in the first lock context, we are unable
to distinguish between a fully established link, i.e., a link that has
been added to its slot, and a link that has not yet reached the second
lock context. It may hence happen that a manual intervention, e.g., when
disabling an interface, causes the function tipc_node_link_down() to try
removing the link from the node slots, decrementing its active link
counter etc, although the link was never added there in the first place.
We solve this by delaying the actual state change until we reach the
second lock context, inside the function tipc_node_link_up(). This
makes it possible for potentail callers of __tipc_node_link_down() to
know if they should proceed or not, and the problem is solved.
Unforunately, the situation described above also has a second problem.
Since there by necessity is a tipc_node_link_up() call pending once
the node lock has been released, we must defuse that call by setting
the link back from LINK_ESTABLISHING to LINK_RESET state. This forces
us to make a slight modification to the link FSM, which will now look
as follows.
+------------------------------------+
|RESET_EVT |
| |
| +--------------+
| +-----------------| SYNCHING |-----------------+
| |FAILURE_EVT +--------------+ PEER_RESET_EVT|
| | A | |
| | | | |
| | | | |
| | |SYNCH_ |SYNCH_ |
| | |BEGIN_EVT |END_EVT |
| | | | |
| V | V V
| +-------------+ +--------------+ +------------+
| | RESETTING |<---------| ESTABLISHED |--------->| PEER_RESET |
| +-------------+ FAILURE_ +--------------+ PEER_ +------------+
| | EVT | A RESET_EVT |
| | | | |
| | +----------------+ | |
| RESET_EVT| |RESET_EVT | |
| | | | |
| | | |ESTABLISH_EVT |
| | | +-------------+ | |
| | | | RESET_EVT | | |
| | | | | | |
| V V V | | |
| +-------------+ +--------------+ RESET_EVT|
+--->| RESET |--------->| ESTABLISHING |<----------------+
+-------------+ PEER_ +--------------+
| A RESET_EVT |
| | |
| | |
|FAILOVER_ |FAILOVER_ |FAILOVER_
|BEGIN_EVT |END_EVT |BEGIN_EVT
| | |
V | |
+-------------+ |
| FAILINGOVER |<----------------+
+-------------+
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-10-16 02:52:44 +08:00
|
|
|
struct tipc_link *l = le->link;
|
2015-07-31 06:24:23 +08:00
|
|
|
struct tipc_media_addr *maddr;
|
|
|
|
struct sk_buff_head xmitq;
|
|
|
|
|
tipc: delay ESTABLISH state event when link is established
Link establishing, just like link teardown, is a non-atomic action, in
the sense that discovering that conditions are right to establish a link,
and the actual adding of the link to one of the node's send slots is done
in two different lock contexts. The link FSM is designed to help bridging
the gap between the two contexts in a safe manner.
We have now discovered a weakness in the implementaton of this FSM.
Because we directly let the link go from state LINK_ESTABLISHING to
state LINK_ESTABLISHED already in the first lock context, we are unable
to distinguish between a fully established link, i.e., a link that has
been added to its slot, and a link that has not yet reached the second
lock context. It may hence happen that a manual intervention, e.g., when
disabling an interface, causes the function tipc_node_link_down() to try
removing the link from the node slots, decrementing its active link
counter etc, although the link was never added there in the first place.
We solve this by delaying the actual state change until we reach the
second lock context, inside the function tipc_node_link_up(). This
makes it possible for potentail callers of __tipc_node_link_down() to
know if they should proceed or not, and the problem is solved.
Unforunately, the situation described above also has a second problem.
Since there by necessity is a tipc_node_link_up() call pending once
the node lock has been released, we must defuse that call by setting
the link back from LINK_ESTABLISHING to LINK_RESET state. This forces
us to make a slight modification to the link FSM, which will now look
as follows.
+------------------------------------+
|RESET_EVT |
| |
| +--------------+
| +-----------------| SYNCHING |-----------------+
| |FAILURE_EVT +--------------+ PEER_RESET_EVT|
| | A | |
| | | | |
| | | | |
| | |SYNCH_ |SYNCH_ |
| | |BEGIN_EVT |END_EVT |
| | | | |
| V | V V
| +-------------+ +--------------+ +------------+
| | RESETTING |<---------| ESTABLISHED |--------->| PEER_RESET |
| +-------------+ FAILURE_ +--------------+ PEER_ +------------+
| | EVT | A RESET_EVT |
| | | | |
| | +----------------+ | |
| RESET_EVT| |RESET_EVT | |
| | | | |
| | | |ESTABLISH_EVT |
| | | +-------------+ | |
| | | | RESET_EVT | | |
| | | | | | |
| V V V | | |
| +-------------+ +--------------+ RESET_EVT|
+--->| RESET |--------->| ESTABLISHING |<----------------+
+-------------+ PEER_ +--------------+
| A RESET_EVT |
| | |
| | |
|FAILOVER_ |FAILOVER_ |FAILOVER_
|BEGIN_EVT |END_EVT |BEGIN_EVT
| | |
V | |
+-------------+ |
| FAILINGOVER |<----------------+
+-------------+
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-10-16 02:52:44 +08:00
|
|
|
if (!l)
|
|
|
|
return;
|
|
|
|
|
2015-07-31 06:24:23 +08:00
|
|
|
__skb_queue_head_init(&xmitq);
|
|
|
|
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_lock(n);
|
tipc: delay ESTABLISH state event when link is established
Link establishing, just like link teardown, is a non-atomic action, in
the sense that discovering that conditions are right to establish a link,
and the actual adding of the link to one of the node's send slots is done
in two different lock contexts. The link FSM is designed to help bridging
the gap between the two contexts in a safe manner.
We have now discovered a weakness in the implementaton of this FSM.
Because we directly let the link go from state LINK_ESTABLISHING to
state LINK_ESTABLISHED already in the first lock context, we are unable
to distinguish between a fully established link, i.e., a link that has
been added to its slot, and a link that has not yet reached the second
lock context. It may hence happen that a manual intervention, e.g., when
disabling an interface, causes the function tipc_node_link_down() to try
removing the link from the node slots, decrementing its active link
counter etc, although the link was never added there in the first place.
We solve this by delaying the actual state change until we reach the
second lock context, inside the function tipc_node_link_up(). This
makes it possible for potentail callers of __tipc_node_link_down() to
know if they should proceed or not, and the problem is solved.
Unforunately, the situation described above also has a second problem.
Since there by necessity is a tipc_node_link_up() call pending once
the node lock has been released, we must defuse that call by setting
the link back from LINK_ESTABLISHING to LINK_RESET state. This forces
us to make a slight modification to the link FSM, which will now look
as follows.
+------------------------------------+
|RESET_EVT |
| |
| +--------------+
| +-----------------| SYNCHING |-----------------+
| |FAILURE_EVT +--------------+ PEER_RESET_EVT|
| | A | |
| | | | |
| | | | |
| | |SYNCH_ |SYNCH_ |
| | |BEGIN_EVT |END_EVT |
| | | | |
| V | V V
| +-------------+ +--------------+ +------------+
| | RESETTING |<---------| ESTABLISHED |--------->| PEER_RESET |
| +-------------+ FAILURE_ +--------------+ PEER_ +------------+
| | EVT | A RESET_EVT |
| | | | |
| | +----------------+ | |
| RESET_EVT| |RESET_EVT | |
| | | | |
| | | |ESTABLISH_EVT |
| | | +-------------+ | |
| | | | RESET_EVT | | |
| | | | | | |
| V V V | | |
| +-------------+ +--------------+ RESET_EVT|
+--->| RESET |--------->| ESTABLISHING |<----------------+
+-------------+ PEER_ +--------------+
| A RESET_EVT |
| | |
| | |
|FAILOVER_ |FAILOVER_ |FAILOVER_
|BEGIN_EVT |END_EVT |BEGIN_EVT
| | |
V | |
+-------------+ |
| FAILINGOVER |<----------------+
+-------------+
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-10-16 02:52:44 +08:00
|
|
|
if (!tipc_link_is_establishing(l)) {
|
|
|
|
__tipc_node_link_down(n, &bearer_id, &xmitq, &maddr);
|
|
|
|
if (delete) {
|
|
|
|
kfree(l);
|
|
|
|
le->link = NULL;
|
|
|
|
n->link_cnt--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Defuse pending tipc_node_link_up() */
|
|
|
|
tipc_link_fsm_evt(l, LINK_RESET_EVT);
|
2015-07-31 06:24:23 +08:00
|
|
|
}
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_unlock(n);
|
2015-07-31 06:24:23 +08:00
|
|
|
tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr);
|
|
|
|
tipc_sk_rcv(n->net, &le->inputq);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2015-11-20 03:30:45 +08:00
|
|
|
static bool tipc_node_is_up(struct tipc_node *n)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2015-07-17 04:54:22 +08:00
|
|
|
return n->active_links[0] != INVALID_BEARER_ID;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2015-07-31 06:24:22 +08:00
|
|
|
void tipc_node_check_dest(struct net *net, u32 onode,
|
|
|
|
struct tipc_bearer *b,
|
|
|
|
u16 capabilities, u32 signature,
|
|
|
|
struct tipc_media_addr *maddr,
|
|
|
|
bool *respond, bool *dupl_addr)
|
2015-07-17 04:54:20 +08:00
|
|
|
{
|
2015-07-31 06:24:22 +08:00
|
|
|
struct tipc_node *n;
|
|
|
|
struct tipc_link *l;
|
2015-07-31 06:24:26 +08:00
|
|
|
struct tipc_link_entry *le;
|
2015-07-31 06:24:22 +08:00
|
|
|
bool addr_match = false;
|
|
|
|
bool sign_match = false;
|
|
|
|
bool link_up = false;
|
|
|
|
bool accept_addr = false;
|
2015-07-31 06:24:23 +08:00
|
|
|
bool reset = true;
|
2015-10-22 20:51:36 +08:00
|
|
|
char *if_name;
|
2015-07-31 06:24:26 +08:00
|
|
|
|
2015-07-31 06:24:22 +08:00
|
|
|
*dupl_addr = false;
|
|
|
|
*respond = false;
|
|
|
|
|
|
|
|
n = tipc_node_create(net, onode, capabilities);
|
|
|
|
if (!n)
|
|
|
|
return;
|
2015-07-17 04:54:20 +08:00
|
|
|
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_lock(n);
|
2015-07-31 06:24:22 +08:00
|
|
|
|
2015-07-31 06:24:26 +08:00
|
|
|
le = &n->links[b->identity];
|
2015-07-31 06:24:22 +08:00
|
|
|
|
|
|
|
/* Prepare to validate requesting node's signature and media address */
|
2015-07-31 06:24:26 +08:00
|
|
|
l = le->link;
|
2015-07-31 06:24:22 +08:00
|
|
|
link_up = l && tipc_link_is_up(l);
|
2015-07-31 06:24:26 +08:00
|
|
|
addr_match = l && !memcmp(&le->maddr, maddr, sizeof(*maddr));
|
2015-07-31 06:24:22 +08:00
|
|
|
sign_match = (signature == n->signature);
|
|
|
|
|
|
|
|
/* These three flags give us eight permutations: */
|
|
|
|
|
|
|
|
if (sign_match && addr_match && link_up) {
|
|
|
|
/* All is fine. Do nothing. */
|
2015-07-31 06:24:23 +08:00
|
|
|
reset = false;
|
2015-07-31 06:24:22 +08:00
|
|
|
} 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.
|
|
|
|
*/
|
|
|
|
*dupl_addr = true;
|
|
|
|
} 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.
|
|
|
|
*/
|
|
|
|
n->signature = signature;
|
|
|
|
} else if (!sign_match && addr_match && !link_up) {
|
|
|
|
/* The peer node has rebooted.
|
|
|
|
* Accept signature, since it is a known peer.
|
|
|
|
*/
|
|
|
|
n->signature = signature;
|
|
|
|
*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.
|
|
|
|
*/
|
|
|
|
*dupl_addr = true;
|
|
|
|
} else if (!sign_match && !addr_match && !link_up) {
|
|
|
|
/* Peer rebooted with new address, or it is a new peer.
|
|
|
|
* Accept signature and address.
|
|
|
|
*/
|
|
|
|
n->signature = signature;
|
|
|
|
accept_addr = true;
|
|
|
|
*respond = true;
|
|
|
|
}
|
2015-07-17 04:54:20 +08:00
|
|
|
|
2015-07-31 06:24:22 +08:00
|
|
|
if (!accept_addr)
|
|
|
|
goto exit;
|
2015-07-17 04:54:20 +08:00
|
|
|
|
2015-07-31 06:24:22 +08:00
|
|
|
/* Now create new link if not already existing */
|
2015-07-17 04:54:29 +08:00
|
|
|
if (!l) {
|
2015-07-31 06:24:26 +08:00
|
|
|
if (n->link_cnt == 2) {
|
|
|
|
pr_warn("Cannot establish 3rd link to %x\n", n->addr);
|
|
|
|
goto exit;
|
|
|
|
}
|
2015-10-22 20:51:36 +08:00
|
|
|
if_name = strchr(b->name, ':') + 1;
|
2015-10-22 20:51:46 +08:00
|
|
|
if (!tipc_link_create(net, if_name, b->identity, b->tolerance,
|
2015-10-22 20:51:36 +08:00
|
|
|
b->net_plane, b->mtu, b->priority,
|
|
|
|
b->window, mod(tipc_net(net)->random),
|
2015-10-22 20:51:40 +08:00
|
|
|
tipc_own_addr(net), onode,
|
2015-10-22 20:51:48 +08:00
|
|
|
n->capabilities,
|
2015-10-22 20:51:41 +08:00
|
|
|
tipc_bc_sndlink(n->net), n->bc_entry.link,
|
|
|
|
&le->inputq,
|
|
|
|
&n->bc_entry.namedq, &l)) {
|
2015-07-31 06:24:22 +08:00
|
|
|
*respond = false;
|
|
|
|
goto exit;
|
|
|
|
}
|
2015-07-31 06:24:26 +08:00
|
|
|
tipc_link_reset(l);
|
2015-10-16 02:52:46 +08:00
|
|
|
tipc_link_fsm_evt(l, LINK_RESET_EVT);
|
tipc: eliminate risk of premature link setup during failover
When a link goes down, and there is still a working link towards its
destination node, a failover is initiated, and the failed link is not
allowed to re-establish until that procedure is finished. To ensure
this, the concerned link endpoints are set to state LINK_FAILINGOVER,
and the node endpoints to NODE_FAILINGOVER during the failover period.
However, if the link reset is due to a disabled bearer, the corres-
ponding link endpoint is deleted, and only the node endpoint knows
about the ongoing failover. Now, if the disabled bearer is re-enabled
during the failover period, the discovery mechanism may create a new
link endpoint that is ready to be established, despite that this is not
permitted. This situation may cause both the ongoing failover and any
subsequent link synchronization to fail.
In this commit, we ensure that a newly created link goes directly to
state LINK_FAILINGOVER if the corresponding node state is
NODE_FAILINGOVER. This eliminates the problem described above.
Furthermore, we tighten the criteria for which packets are allowed
to end a failover state in the function tipc_node_check_state().
By checking that the receiving link is up and running, instead of just
checking that it is not in failover mode, we eliminate the risk that
protocol packets from the re-created link may cause the failover to
be prematurely terminated.
Reviewed-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>
2015-08-20 14:12:54 +08:00
|
|
|
if (n->state == NODE_FAILINGOVER)
|
|
|
|
tipc_link_fsm_evt(l, LINK_FAILOVER_BEGIN_EVT);
|
2015-07-31 06:24:26 +08:00
|
|
|
le->link = l;
|
|
|
|
n->link_cnt++;
|
2015-07-17 04:54:29 +08:00
|
|
|
tipc_node_calculate_timer(n, l);
|
2015-07-31 06:24:22 +08:00
|
|
|
if (n->link_cnt == 1)
|
2015-07-17 04:54:29 +08:00
|
|
|
if (!mod_timer(&n->timer, jiffies + n->keepalive_intv))
|
|
|
|
tipc_node_get(n);
|
|
|
|
}
|
2015-07-31 06:24:26 +08:00
|
|
|
memcpy(&le->maddr, maddr, sizeof(*maddr));
|
2015-07-31 06:24:22 +08:00
|
|
|
exit:
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_write_unlock(n);
|
tipc: delay ESTABLISH state event when link is established
Link establishing, just like link teardown, is a non-atomic action, in
the sense that discovering that conditions are right to establish a link,
and the actual adding of the link to one of the node's send slots is done
in two different lock contexts. The link FSM is designed to help bridging
the gap between the two contexts in a safe manner.
We have now discovered a weakness in the implementaton of this FSM.
Because we directly let the link go from state LINK_ESTABLISHING to
state LINK_ESTABLISHED already in the first lock context, we are unable
to distinguish between a fully established link, i.e., a link that has
been added to its slot, and a link that has not yet reached the second
lock context. It may hence happen that a manual intervention, e.g., when
disabling an interface, causes the function tipc_node_link_down() to try
removing the link from the node slots, decrementing its active link
counter etc, although the link was never added there in the first place.
We solve this by delaying the actual state change until we reach the
second lock context, inside the function tipc_node_link_up(). This
makes it possible for potentail callers of __tipc_node_link_down() to
know if they should proceed or not, and the problem is solved.
Unforunately, the situation described above also has a second problem.
Since there by necessity is a tipc_node_link_up() call pending once
the node lock has been released, we must defuse that call by setting
the link back from LINK_ESTABLISHING to LINK_RESET state. This forces
us to make a slight modification to the link FSM, which will now look
as follows.
+------------------------------------+
|RESET_EVT |
| |
| +--------------+
| +-----------------| SYNCHING |-----------------+
| |FAILURE_EVT +--------------+ PEER_RESET_EVT|
| | A | |
| | | | |
| | | | |
| | |SYNCH_ |SYNCH_ |
| | |BEGIN_EVT |END_EVT |
| | | | |
| V | V V
| +-------------+ +--------------+ +------------+
| | RESETTING |<---------| ESTABLISHED |--------->| PEER_RESET |
| +-------------+ FAILURE_ +--------------+ PEER_ +------------+
| | EVT | A RESET_EVT |
| | | | |
| | +----------------+ | |
| RESET_EVT| |RESET_EVT | |
| | | | |
| | | |ESTABLISH_EVT |
| | | +-------------+ | |
| | | | RESET_EVT | | |
| | | | | | |
| V V V | | |
| +-------------+ +--------------+ RESET_EVT|
+--->| RESET |--------->| ESTABLISHING |<----------------+
+-------------+ PEER_ +--------------+
| A RESET_EVT |
| | |
| | |
|FAILOVER_ |FAILOVER_ |FAILOVER_
|BEGIN_EVT |END_EVT |BEGIN_EVT
| | |
V | |
+-------------+ |
| FAILINGOVER |<----------------+
+-------------+
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-10-16 02:52:44 +08:00
|
|
|
if (reset && !tipc_link_is_reset(l))
|
2015-07-31 06:24:23 +08:00
|
|
|
tipc_node_link_down(n, b->identity, false);
|
2015-07-31 06:24:22 +08:00
|
|
|
tipc_node_put(n);
|
2015-07-17 04:54:20 +08:00
|
|
|
}
|
|
|
|
|
2015-07-31 06:24:16 +08:00
|
|
|
void tipc_node_delete_links(struct net *net, int bearer_id)
|
|
|
|
{
|
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
|
|
|
struct tipc_node *n;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(n, &tn->node_list, list) {
|
2015-07-31 06:24:23 +08:00
|
|
|
tipc_node_link_down(n, bearer_id, true);
|
2015-07-31 06:24:16 +08:00
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tipc_node_reset_links(struct tipc_node *n)
|
|
|
|
{
|
|
|
|
char addr_string[16];
|
2015-07-31 06:24:23 +08:00
|
|
|
int i;
|
2015-07-31 06:24:16 +08:00
|
|
|
|
|
|
|
pr_warn("Resetting all links to %s\n",
|
|
|
|
tipc_addr_string_fill(addr_string, n->addr));
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_BEARERS; i++) {
|
2015-07-31 06:24:23 +08:00
|
|
|
tipc_node_link_down(n, i, false);
|
2015-07-31 06:24:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 04:54:30 +08:00
|
|
|
/* tipc_node_fsm_evt - node finite state machine
|
|
|
|
* Determines when contact is allowed with peer node
|
|
|
|
*/
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
static void tipc_node_fsm_evt(struct tipc_node *n, int evt)
|
2015-07-17 04:54:30 +08:00
|
|
|
{
|
|
|
|
int state = n->state;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case SELF_DOWN_PEER_DOWN:
|
|
|
|
switch (evt) {
|
|
|
|
case SELF_ESTABL_CONTACT_EVT:
|
|
|
|
state = SELF_UP_PEER_COMING;
|
|
|
|
break;
|
|
|
|
case PEER_ESTABL_CONTACT_EVT:
|
|
|
|
state = SELF_COMING_PEER_UP;
|
|
|
|
break;
|
|
|
|
case SELF_LOST_CONTACT_EVT:
|
|
|
|
case PEER_LOST_CONTACT_EVT:
|
|
|
|
break;
|
2015-07-31 06:24:18 +08:00
|
|
|
case NODE_SYNCH_END_EVT:
|
|
|
|
case NODE_SYNCH_BEGIN_EVT:
|
|
|
|
case NODE_FAILOVER_BEGIN_EVT:
|
|
|
|
case NODE_FAILOVER_END_EVT:
|
2015-07-17 04:54:30 +08:00
|
|
|
default:
|
2015-07-31 06:24:18 +08:00
|
|
|
goto illegal_evt;
|
2015-07-17 04:54:30 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SELF_UP_PEER_UP:
|
|
|
|
switch (evt) {
|
|
|
|
case SELF_LOST_CONTACT_EVT:
|
|
|
|
state = SELF_DOWN_PEER_LEAVING;
|
|
|
|
break;
|
|
|
|
case PEER_LOST_CONTACT_EVT:
|
|
|
|
state = SELF_LEAVING_PEER_DOWN;
|
|
|
|
break;
|
2015-07-31 06:24:18 +08:00
|
|
|
case NODE_SYNCH_BEGIN_EVT:
|
|
|
|
state = NODE_SYNCHING;
|
|
|
|
break;
|
|
|
|
case NODE_FAILOVER_BEGIN_EVT:
|
|
|
|
state = NODE_FAILINGOVER;
|
|
|
|
break;
|
2015-07-17 04:54:30 +08:00
|
|
|
case SELF_ESTABL_CONTACT_EVT:
|
|
|
|
case PEER_ESTABL_CONTACT_EVT:
|
2015-07-31 06:24:18 +08:00
|
|
|
case NODE_SYNCH_END_EVT:
|
|
|
|
case NODE_FAILOVER_END_EVT:
|
2015-07-17 04:54:30 +08:00
|
|
|
break;
|
|
|
|
default:
|
2015-07-31 06:24:18 +08:00
|
|
|
goto illegal_evt;
|
2015-07-17 04:54:30 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SELF_DOWN_PEER_LEAVING:
|
|
|
|
switch (evt) {
|
|
|
|
case PEER_LOST_CONTACT_EVT:
|
|
|
|
state = SELF_DOWN_PEER_DOWN;
|
|
|
|
break;
|
|
|
|
case SELF_ESTABL_CONTACT_EVT:
|
|
|
|
case PEER_ESTABL_CONTACT_EVT:
|
|
|
|
case SELF_LOST_CONTACT_EVT:
|
|
|
|
break;
|
2015-07-31 06:24:18 +08:00
|
|
|
case NODE_SYNCH_END_EVT:
|
|
|
|
case NODE_SYNCH_BEGIN_EVT:
|
|
|
|
case NODE_FAILOVER_BEGIN_EVT:
|
|
|
|
case NODE_FAILOVER_END_EVT:
|
2015-07-17 04:54:30 +08:00
|
|
|
default:
|
2015-07-31 06:24:18 +08:00
|
|
|
goto illegal_evt;
|
2015-07-17 04:54:30 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SELF_UP_PEER_COMING:
|
|
|
|
switch (evt) {
|
|
|
|
case PEER_ESTABL_CONTACT_EVT:
|
|
|
|
state = SELF_UP_PEER_UP;
|
|
|
|
break;
|
|
|
|
case SELF_LOST_CONTACT_EVT:
|
|
|
|
state = SELF_DOWN_PEER_LEAVING;
|
|
|
|
break;
|
|
|
|
case SELF_ESTABL_CONTACT_EVT:
|
|
|
|
case PEER_LOST_CONTACT_EVT:
|
2015-07-31 06:24:18 +08:00
|
|
|
case NODE_SYNCH_END_EVT:
|
|
|
|
case NODE_FAILOVER_BEGIN_EVT:
|
tipc: delay ESTABLISH state event when link is established
Link establishing, just like link teardown, is a non-atomic action, in
the sense that discovering that conditions are right to establish a link,
and the actual adding of the link to one of the node's send slots is done
in two different lock contexts. The link FSM is designed to help bridging
the gap between the two contexts in a safe manner.
We have now discovered a weakness in the implementaton of this FSM.
Because we directly let the link go from state LINK_ESTABLISHING to
state LINK_ESTABLISHED already in the first lock context, we are unable
to distinguish between a fully established link, i.e., a link that has
been added to its slot, and a link that has not yet reached the second
lock context. It may hence happen that a manual intervention, e.g., when
disabling an interface, causes the function tipc_node_link_down() to try
removing the link from the node slots, decrementing its active link
counter etc, although the link was never added there in the first place.
We solve this by delaying the actual state change until we reach the
second lock context, inside the function tipc_node_link_up(). This
makes it possible for potentail callers of __tipc_node_link_down() to
know if they should proceed or not, and the problem is solved.
Unforunately, the situation described above also has a second problem.
Since there by necessity is a tipc_node_link_up() call pending once
the node lock has been released, we must defuse that call by setting
the link back from LINK_ESTABLISHING to LINK_RESET state. This forces
us to make a slight modification to the link FSM, which will now look
as follows.
+------------------------------------+
|RESET_EVT |
| |
| +--------------+
| +-----------------| SYNCHING |-----------------+
| |FAILURE_EVT +--------------+ PEER_RESET_EVT|
| | A | |
| | | | |
| | | | |
| | |SYNCH_ |SYNCH_ |
| | |BEGIN_EVT |END_EVT |
| | | | |
| V | V V
| +-------------+ +--------------+ +------------+
| | RESETTING |<---------| ESTABLISHED |--------->| PEER_RESET |
| +-------------+ FAILURE_ +--------------+ PEER_ +------------+
| | EVT | A RESET_EVT |
| | | | |
| | +----------------+ | |
| RESET_EVT| |RESET_EVT | |
| | | | |
| | | |ESTABLISH_EVT |
| | | +-------------+ | |
| | | | RESET_EVT | | |
| | | | | | |
| V V V | | |
| +-------------+ +--------------+ RESET_EVT|
+--->| RESET |--------->| ESTABLISHING |<----------------+
+-------------+ PEER_ +--------------+
| A RESET_EVT |
| | |
| | |
|FAILOVER_ |FAILOVER_ |FAILOVER_
|BEGIN_EVT |END_EVT |BEGIN_EVT
| | |
V | |
+-------------+ |
| FAILINGOVER |<----------------+
+-------------+
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-10-16 02:52:44 +08:00
|
|
|
break;
|
|
|
|
case NODE_SYNCH_BEGIN_EVT:
|
2015-07-31 06:24:18 +08:00
|
|
|
case NODE_FAILOVER_END_EVT:
|
2015-07-17 04:54:30 +08:00
|
|
|
default:
|
2015-07-31 06:24:18 +08:00
|
|
|
goto illegal_evt;
|
2015-07-17 04:54:30 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SELF_COMING_PEER_UP:
|
|
|
|
switch (evt) {
|
|
|
|
case SELF_ESTABL_CONTACT_EVT:
|
|
|
|
state = SELF_UP_PEER_UP;
|
|
|
|
break;
|
|
|
|
case PEER_LOST_CONTACT_EVT:
|
|
|
|
state = SELF_LEAVING_PEER_DOWN;
|
|
|
|
break;
|
|
|
|
case SELF_LOST_CONTACT_EVT:
|
|
|
|
case PEER_ESTABL_CONTACT_EVT:
|
|
|
|
break;
|
2015-07-31 06:24:18 +08:00
|
|
|
case NODE_SYNCH_END_EVT:
|
|
|
|
case NODE_SYNCH_BEGIN_EVT:
|
|
|
|
case NODE_FAILOVER_BEGIN_EVT:
|
|
|
|
case NODE_FAILOVER_END_EVT:
|
2015-07-17 04:54:30 +08:00
|
|
|
default:
|
2015-07-31 06:24:18 +08:00
|
|
|
goto illegal_evt;
|
2015-07-17 04:54:30 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SELF_LEAVING_PEER_DOWN:
|
|
|
|
switch (evt) {
|
|
|
|
case SELF_LOST_CONTACT_EVT:
|
|
|
|
state = SELF_DOWN_PEER_DOWN;
|
|
|
|
break;
|
|
|
|
case SELF_ESTABL_CONTACT_EVT:
|
|
|
|
case PEER_ESTABL_CONTACT_EVT:
|
|
|
|
case PEER_LOST_CONTACT_EVT:
|
|
|
|
break;
|
2015-07-31 06:24:18 +08:00
|
|
|
case NODE_SYNCH_END_EVT:
|
|
|
|
case NODE_SYNCH_BEGIN_EVT:
|
|
|
|
case NODE_FAILOVER_BEGIN_EVT:
|
|
|
|
case NODE_FAILOVER_END_EVT:
|
|
|
|
default:
|
|
|
|
goto illegal_evt;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NODE_FAILINGOVER:
|
|
|
|
switch (evt) {
|
|
|
|
case SELF_LOST_CONTACT_EVT:
|
|
|
|
state = SELF_DOWN_PEER_LEAVING;
|
|
|
|
break;
|
|
|
|
case PEER_LOST_CONTACT_EVT:
|
|
|
|
state = SELF_LEAVING_PEER_DOWN;
|
|
|
|
break;
|
|
|
|
case NODE_FAILOVER_END_EVT:
|
|
|
|
state = SELF_UP_PEER_UP;
|
|
|
|
break;
|
|
|
|
case NODE_FAILOVER_BEGIN_EVT:
|
|
|
|
case SELF_ESTABL_CONTACT_EVT:
|
|
|
|
case PEER_ESTABL_CONTACT_EVT:
|
|
|
|
break;
|
|
|
|
case NODE_SYNCH_BEGIN_EVT:
|
|
|
|
case NODE_SYNCH_END_EVT:
|
2015-07-17 04:54:30 +08:00
|
|
|
default:
|
2015-07-31 06:24:18 +08:00
|
|
|
goto illegal_evt;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NODE_SYNCHING:
|
|
|
|
switch (evt) {
|
|
|
|
case SELF_LOST_CONTACT_EVT:
|
|
|
|
state = SELF_DOWN_PEER_LEAVING;
|
|
|
|
break;
|
|
|
|
case PEER_LOST_CONTACT_EVT:
|
|
|
|
state = SELF_LEAVING_PEER_DOWN;
|
|
|
|
break;
|
|
|
|
case NODE_SYNCH_END_EVT:
|
|
|
|
state = SELF_UP_PEER_UP;
|
|
|
|
break;
|
|
|
|
case NODE_FAILOVER_BEGIN_EVT:
|
|
|
|
state = NODE_FAILINGOVER;
|
|
|
|
break;
|
|
|
|
case NODE_SYNCH_BEGIN_EVT:
|
|
|
|
case SELF_ESTABL_CONTACT_EVT:
|
|
|
|
case PEER_ESTABL_CONTACT_EVT:
|
|
|
|
break;
|
|
|
|
case NODE_FAILOVER_END_EVT:
|
|
|
|
default:
|
|
|
|
goto illegal_evt;
|
2015-07-17 04:54:30 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pr_err("Unknown node fsm state %x\n", state);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
n->state = state;
|
2015-07-31 06:24:18 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
illegal_evt:
|
|
|
|
pr_err("Illegal node fsm evt %x in state %x\n", evt, state);
|
2015-07-17 04:54:30 +08:00
|
|
|
}
|
|
|
|
|
2015-10-22 20:51:41 +08:00
|
|
|
static void node_lost_contact(struct tipc_node *n,
|
2015-07-31 06:24:23 +08:00
|
|
|
struct sk_buff_head *inputq)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
|
|
|
char addr_string[16];
|
2015-02-05 21:36:42 +08:00
|
|
|
struct tipc_sock_conn *conn, *safe;
|
2015-07-31 06:24:23 +08:00
|
|
|
struct tipc_link *l;
|
2015-10-22 20:51:41 +08:00
|
|
|
struct list_head *conns = &n->conn_sks;
|
2015-02-05 21:36:42 +08:00
|
|
|
struct sk_buff *skb;
|
|
|
|
uint i;
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2015-01-23 00:10:31 +08:00
|
|
|
pr_debug("Lost contact with %s\n",
|
2015-10-22 20:51:41 +08:00
|
|
|
tipc_addr_string_fill(addr_string, n->addr));
|
2011-04-07 23:58:08 +08:00
|
|
|
|
2015-10-22 20:51:41 +08:00
|
|
|
/* Clean up broadcast state */
|
tipc: simplify bearer level broadcast
Until now, we have been keeping track of the exact set of broadcast
destinations though the help structure tipc_node_map. This leads us to
have to maintain a whole infrastructure for supporting this, including
a pseudo-bearer and a number of functions to manipulate both the bearers
and the node map correctly. Apart from the complexity, this approach is
also limiting, as struct tipc_node_map only can support cluster local
broadcast if we want to avoid it becoming excessively large. We want to
eliminate this limitation, in order to enable introduction of scoped
multicast in the future.
A closer analysis reveals that it is unnecessary maintaining this "full
set" overview; it is sufficient to keep a counter per bearer, indicating
how many nodes can be reached via this bearer at the moment. The protocol
is now robust enough to handle transitional discrepancies between the
nominal number of reachable destinations, as expected by the broadcast
protocol itself, and the number which is actually reachable at the
moment. The initial broadcast synchronization, in conjunction with the
retransmission mechanism, ensures that all packets will eventually be
acknowledged by the correct set of destinations.
This commit introduces these changes.
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>
2015-10-22 20:51:42 +08:00
|
|
|
tipc_bcast_remove_peer(n->net, n->bc_entry.link);
|
2006-01-03 02:04:38 +08:00
|
|
|
|
tipc: eliminate delayed link deletion at link failover
When a bearer is disabled manually, all its links have to be reset
and deleted. However, if there is a remaining, parallel link ready
to take over a deleted link's traffic, we currently delay the delete
of the removed link until the failover procedure is finished. This
is because the remaining link needs to access state from the reset
link, such as the last received packet number, and any partially
reassembled buffer, in order to perform a successful failover.
In this commit, we do instead move the state data over to the new
link, so that it can fulfill the procedure autonomously, without
accessing any data on the old link. This means that we can now
proceed and delete all pertaining links immediately when a bearer
is disabled. This saves us from some unnecessary complexity in such
situations.
We also choose to change the confusing definitions CHANGEOVER_PROTOCOL,
ORIGINAL_MSG and DUPLICATE_MSG to the more descriptive TUNNEL_PROTOCOL,
FAILOVER_MSG and SYNCH_MSG respectively.
Reviewed-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>
2015-04-02 21:33:01 +08:00
|
|
|
/* Abort any ongoing link failover */
|
2006-01-03 02:04:38 +08:00
|
|
|
for (i = 0; i < MAX_BEARERS; i++) {
|
2015-10-22 20:51:41 +08:00
|
|
|
l = n->links[i].link;
|
2015-07-31 06:24:23 +08:00
|
|
|
if (l)
|
|
|
|
tipc_link_fsm_evt(l, LINK_FAILOVER_END_EVT);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
2015-07-31 06:24:23 +08:00
|
|
|
|
2015-02-05 21:36:42 +08:00
|
|
|
/* Notify publications from this node */
|
2015-10-22 20:51:41 +08:00
|
|
|
n->action_flags |= TIPC_NOTIFY_NODE_DOWN;
|
2015-02-05 21:36:42 +08:00
|
|
|
|
|
|
|
/* Notify sockets connected to node */
|
|
|
|
list_for_each_entry_safe(conn, safe, conns, list) {
|
|
|
|
skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG,
|
2015-10-22 20:51:41 +08:00
|
|
|
SHORT_H_SIZE, 0, tipc_own_addr(n->net),
|
2015-02-05 21:36:42 +08:00
|
|
|
conn->peer_node, conn->port,
|
|
|
|
conn->peer_port, TIPC_ERR_NO_NODE);
|
2015-07-31 06:24:24 +08:00
|
|
|
if (likely(skb))
|
2015-07-31 06:24:23 +08:00
|
|
|
skb_queue_tail(inputq, skb);
|
2015-02-05 21:36:42 +08:00
|
|
|
list_del(&conn->list);
|
|
|
|
kfree(conn);
|
|
|
|
}
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2014-04-24 22:26:47 +08:00
|
|
|
/**
|
|
|
|
* tipc_node_get_linkname - get the name of a link
|
|
|
|
*
|
|
|
|
* @bearer_id: id of the bearer
|
|
|
|
* @node: peer node address
|
|
|
|
* @linkname: link name output buffer
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
2015-01-09 15:27:05 +08:00
|
|
|
int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr,
|
|
|
|
char *linkname, size_t len)
|
2014-04-24 22:26:47 +08:00
|
|
|
{
|
|
|
|
struct tipc_link *link;
|
2015-03-26 18:10:24 +08:00
|
|
|
int err = -EINVAL;
|
2015-01-09 15:27:05 +08:00
|
|
|
struct tipc_node *node = tipc_node_find(net, addr);
|
2014-04-24 22:26:47 +08:00
|
|
|
|
2015-03-26 18:10:24 +08:00
|
|
|
if (!node)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (bearer_id >= MAX_BEARERS)
|
|
|
|
goto exit;
|
|
|
|
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_lock(node);
|
2015-07-17 04:54:19 +08:00
|
|
|
link = node->links[bearer_id].link;
|
2014-04-24 22:26:47 +08:00
|
|
|
if (link) {
|
2015-11-20 03:30:46 +08:00
|
|
|
strncpy(linkname, tipc_link_name(link), len);
|
2015-03-26 18:10:24 +08:00
|
|
|
err = 0;
|
2014-04-24 22:26:47 +08:00
|
|
|
}
|
2015-03-26 18:10:24 +08:00
|
|
|
exit:
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_unlock(node);
|
2015-03-26 18:10:24 +08:00
|
|
|
tipc_node_put(node);
|
|
|
|
return err;
|
2014-04-24 22:26:47 +08:00
|
|
|
}
|
2014-05-05 08:56:12 +08:00
|
|
|
|
2014-11-20 17:29:17 +08:00
|
|
|
/* Caller should hold node lock for the passed node */
|
2014-11-24 18:10:29 +08:00
|
|
|
static int __tipc_nl_add_node(struct tipc_nl_msg *msg, struct tipc_node *node)
|
2014-11-20 17:29:17 +08:00
|
|
|
{
|
|
|
|
void *hdr;
|
|
|
|
struct nlattr *attrs;
|
|
|
|
|
2015-02-09 16:50:03 +08:00
|
|
|
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
|
2014-11-20 17:29:17 +08:00
|
|
|
NLM_F_MULTI, TIPC_NL_NODE_GET);
|
|
|
|
if (!hdr)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
attrs = nla_nest_start(msg->skb, TIPC_NLA_NODE);
|
|
|
|
if (!attrs)
|
|
|
|
goto msg_full;
|
|
|
|
|
|
|
|
if (nla_put_u32(msg->skb, TIPC_NLA_NODE_ADDR, node->addr))
|
|
|
|
goto attr_msg_full;
|
|
|
|
if (tipc_node_is_up(node))
|
|
|
|
if (nla_put_flag(msg->skb, TIPC_NLA_NODE_UP))
|
|
|
|
goto attr_msg_full;
|
|
|
|
|
|
|
|
nla_nest_end(msg->skb, attrs);
|
|
|
|
genlmsg_end(msg->skb, hdr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
attr_msg_full:
|
|
|
|
nla_nest_cancel(msg->skb, attrs);
|
|
|
|
msg_full:
|
|
|
|
genlmsg_cancel(msg->skb, hdr);
|
|
|
|
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
2015-07-17 04:54:24 +08:00
|
|
|
/**
|
|
|
|
* tipc_node_xmit() is the general link level function for message sending
|
|
|
|
* @net: the applicable net namespace
|
|
|
|
* @list: chain of buffers containing message
|
|
|
|
* @dnode: address of destination node
|
|
|
|
* @selector: a number used for deterministic link selection
|
|
|
|
* Consumes the buffer chain, except when returning -ELINKCONG
|
|
|
|
* Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE
|
|
|
|
*/
|
|
|
|
int tipc_node_xmit(struct net *net, struct sk_buff_head *list,
|
|
|
|
u32 dnode, int selector)
|
|
|
|
{
|
2015-11-20 03:30:44 +08:00
|
|
|
struct tipc_link_entry *le = NULL;
|
2015-07-17 04:54:24 +08:00
|
|
|
struct tipc_node *n;
|
|
|
|
struct sk_buff_head xmitq;
|
2015-11-20 03:30:43 +08:00
|
|
|
int bearer_id = -1;
|
2015-07-17 04:54:24 +08:00
|
|
|
int rc = -EHOSTUNREACH;
|
|
|
|
|
|
|
|
__skb_queue_head_init(&xmitq);
|
|
|
|
n = tipc_node_find(net, dnode);
|
|
|
|
if (likely(n)) {
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_lock(n);
|
2015-11-20 03:30:43 +08:00
|
|
|
bearer_id = n->active_links[selector & 1];
|
|
|
|
if (bearer_id >= 0) {
|
|
|
|
le = &n->links[bearer_id];
|
|
|
|
spin_lock_bh(&le->lock);
|
2015-11-20 03:30:44 +08:00
|
|
|
rc = tipc_link_xmit(le->link, list, &xmitq);
|
2015-11-20 03:30:43 +08:00
|
|
|
spin_unlock_bh(&le->lock);
|
|
|
|
}
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_unlock(n);
|
2015-12-03 04:19:37 +08:00
|
|
|
if (likely(!rc))
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
|
2015-12-03 04:19:37 +08:00
|
|
|
else if (rc == -ENOBUFS)
|
2015-07-31 06:24:23 +08:00
|
|
|
tipc_node_link_down(n, bearer_id, false);
|
2015-07-17 04:54:24 +08:00
|
|
|
tipc_node_put(n);
|
2015-11-20 03:30:44 +08:00
|
|
|
return rc;
|
2015-07-17 04:54:24 +08:00
|
|
|
}
|
2015-11-20 03:30:44 +08:00
|
|
|
|
2015-12-03 04:19:37 +08:00
|
|
|
if (likely(in_own_node(net, dnode))) {
|
|
|
|
tipc_sk_rcv(net, list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return rc;
|
2015-07-17 04:54:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tipc_node_xmit_skb(): send single buffer to destination
|
|
|
|
* Buffers sent via this functon are generally TIPC_SYSTEM_IMPORTANCE
|
|
|
|
* messages, which will not be rejected
|
|
|
|
* The only exception is datagram messages rerouted after secondary
|
|
|
|
* lookup, which are rare and safe to dispose of anyway.
|
|
|
|
* TODO: Return real return value, and let callers use
|
|
|
|
* tipc_wait_for_sendpkt() where applicable
|
|
|
|
*/
|
|
|
|
int tipc_node_xmit_skb(struct net *net, struct sk_buff *skb, u32 dnode,
|
|
|
|
u32 selector)
|
|
|
|
{
|
|
|
|
struct sk_buff_head head;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
skb_queue_head_init(&head);
|
|
|
|
__skb_queue_tail(&head, skb);
|
|
|
|
rc = tipc_node_xmit(net, &head, dnode, selector);
|
|
|
|
if (rc == -ELINKCONG)
|
|
|
|
kfree_skb(skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-20 03:30:42 +08:00
|
|
|
void tipc_node_broadcast(struct net *net, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct sk_buff *txskb;
|
|
|
|
struct tipc_node *n;
|
|
|
|
u32 dst;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(n, tipc_nodes(net), list) {
|
|
|
|
dst = n->addr;
|
|
|
|
if (in_own_node(net, dst))
|
|
|
|
continue;
|
|
|
|
if (!tipc_node_is_up(n))
|
|
|
|
continue;
|
|
|
|
txskb = pskb_copy(skb, GFP_ATOMIC);
|
|
|
|
if (!txskb)
|
|
|
|
break;
|
|
|
|
msg_set_destnode(buf_msg(txskb), dst);
|
|
|
|
tipc_node_xmit_skb(net, txskb, dst, 0);
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
2015-10-22 20:51:41 +08:00
|
|
|
/**
|
|
|
|
* tipc_node_bc_rcv - process TIPC broadcast packet arriving from off-node
|
|
|
|
* @net: the applicable net namespace
|
|
|
|
* @skb: TIPC packet
|
|
|
|
* @bearer_id: id of bearer message arrived on
|
|
|
|
*
|
|
|
|
* Invoked with no locks held.
|
|
|
|
*/
|
2015-10-24 22:56:01 +08:00
|
|
|
static void tipc_node_bc_rcv(struct net *net, struct sk_buff *skb, int bearer_id)
|
2015-10-22 20:51:41 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct sk_buff_head xmitq;
|
|
|
|
struct tipc_bclink_entry *be;
|
|
|
|
struct tipc_link_entry *le;
|
|
|
|
struct tipc_msg *hdr = buf_msg(skb);
|
|
|
|
int usr = msg_user(hdr);
|
|
|
|
u32 dnode = msg_destnode(hdr);
|
|
|
|
struct tipc_node *n;
|
|
|
|
|
|
|
|
__skb_queue_head_init(&xmitq);
|
|
|
|
|
|
|
|
/* If NACK for other node, let rcv link for that node peek into it */
|
|
|
|
if ((usr == BCAST_PROTOCOL) && (dnode != tipc_own_addr(net)))
|
|
|
|
n = tipc_node_find(net, dnode);
|
|
|
|
else
|
|
|
|
n = tipc_node_find(net, msg_prevnode(hdr));
|
|
|
|
if (!n) {
|
|
|
|
kfree_skb(skb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
be = &n->bc_entry;
|
|
|
|
le = &n->links[bearer_id];
|
|
|
|
|
|
|
|
rc = tipc_bcast_rcv(net, be->link, skb);
|
|
|
|
|
|
|
|
/* Broadcast link reset may happen at reassembly failure */
|
|
|
|
if (rc & TIPC_LINK_DOWN_EVT)
|
|
|
|
tipc_node_reset_links(n);
|
|
|
|
|
|
|
|
/* Broadcast ACKs are sent on a unicast link */
|
|
|
|
if (rc & TIPC_LINK_SND_BC_ACK) {
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_lock(n);
|
2015-10-22 20:51:41 +08:00
|
|
|
tipc_link_build_ack_msg(le->link, &xmitq);
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_unlock(n);
|
2015-10-22 20:51:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!skb_queue_empty(&xmitq))
|
|
|
|
tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
|
|
|
|
|
|
|
|
/* Deliver. 'arrvq' is under inputq2's lock protection */
|
|
|
|
if (!skb_queue_empty(&be->inputq1)) {
|
|
|
|
spin_lock_bh(&be->inputq2.lock);
|
|
|
|
spin_lock_bh(&be->inputq1.lock);
|
|
|
|
skb_queue_splice_tail_init(&be->inputq1, &be->arrvq);
|
|
|
|
spin_unlock_bh(&be->inputq1.lock);
|
|
|
|
spin_unlock_bh(&be->inputq2.lock);
|
|
|
|
tipc_sk_mcast_rcv(net, &be->arrvq, &be->inputq2);
|
|
|
|
}
|
|
|
|
tipc_node_put(n);
|
|
|
|
}
|
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
/**
|
|
|
|
* tipc_node_check_state - check and if necessary update node state
|
|
|
|
* @skb: TIPC packet
|
|
|
|
* @bearer_id: identity of bearer delivering the packet
|
|
|
|
* Returns true if state is ok, otherwise consumes buffer and returns false
|
2015-07-31 06:24:16 +08:00
|
|
|
*/
|
2015-07-31 06:24:19 +08:00
|
|
|
static bool tipc_node_check_state(struct tipc_node *n, struct sk_buff *skb,
|
2015-07-31 06:24:21 +08:00
|
|
|
int bearer_id, struct sk_buff_head *xmitq)
|
2015-07-31 06:24:16 +08:00
|
|
|
{
|
|
|
|
struct tipc_msg *hdr = buf_msg(skb);
|
2015-07-31 06:24:19 +08:00
|
|
|
int usr = msg_user(hdr);
|
|
|
|
int mtyp = msg_type(hdr);
|
2015-07-31 06:24:16 +08:00
|
|
|
u16 oseqno = msg_seqno(hdr);
|
2015-07-31 06:24:19 +08:00
|
|
|
u16 iseqno = msg_seqno(msg_get_wrapped(hdr));
|
|
|
|
u16 exp_pkts = msg_msgcnt(hdr);
|
2015-11-20 03:30:46 +08:00
|
|
|
u16 rcv_nxt, syncpt, dlv_nxt, inputq_len;
|
2015-07-31 06:24:19 +08:00
|
|
|
int state = n->state;
|
tipc: fix stale link problem during synchronization
Recent changes to the link synchronization means that we can now just
drop packets arriving on the synchronizing link before the synch point
is reached. This has lead to significant simplifications to the
implementation, but also turns out to have a flip side that we need
to consider.
Under unlucky circumstances, the two endpoints may end up
repeatedly dropping each other's packets, while immediately
asking for retransmission of the same packets, just to drop
them once more. This pattern will eventually be broken when
the synch point is reached on the other link, but before that,
the endpoints may have arrived at the retransmission limit
(stale counter) that indicates that the link should be broken.
We see this happen at rare occasions.
The fix for this is to not ask for retransmissions when a link is in
state LINK_SYNCHING. The fact that the link has reached this state
means that it has already received the first SYNCH packet, and that it
knows the synch point. Hence, it doesn't need any more packets until the
other link has reached the synch point, whereafter it can go ahead and
ask for the missing packets.
However, because of the reduced traffic on the synching link that
follows this change, it may now take longer to discover that the
synch point has been reached. We compensate for this by letting all
packets, on any of the links, trig a check for synchronization
termination. This is possible because the packets themselves don't
contain any information that is needed for discovering this condition.
Reviewed-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>
2015-08-20 14:12:56 +08:00
|
|
|
struct tipc_link *l, *tnl, *pl = NULL;
|
2015-07-31 06:24:23 +08:00
|
|
|
struct tipc_media_addr *maddr;
|
2015-11-20 03:30:46 +08:00
|
|
|
int pb_id;
|
2015-07-31 06:24:16 +08:00
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
l = n->links[bearer_id].link;
|
|
|
|
if (!l)
|
|
|
|
return false;
|
2015-11-20 03:30:46 +08:00
|
|
|
rcv_nxt = tipc_link_rcv_nxt(l);
|
2015-07-31 06:24:16 +08:00
|
|
|
|
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
if (likely((state == SELF_UP_PEER_UP) && (usr != TUNNEL_PROTOCOL)))
|
|
|
|
return true;
|
2015-07-31 06:24:16 +08:00
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
/* Find parallel link, if any */
|
2015-11-20 03:30:46 +08:00
|
|
|
for (pb_id = 0; pb_id < MAX_BEARERS; pb_id++) {
|
|
|
|
if ((pb_id != bearer_id) && n->links[pb_id].link) {
|
|
|
|
pl = n->links[pb_id].link;
|
2015-07-31 06:24:19 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-07-31 06:24:16 +08:00
|
|
|
|
2015-11-20 03:30:44 +08:00
|
|
|
/* Check and update node accesibility if applicable */
|
2015-07-31 06:24:19 +08:00
|
|
|
if (state == SELF_UP_PEER_COMING) {
|
|
|
|
if (!tipc_link_is_up(l))
|
|
|
|
return true;
|
|
|
|
if (!msg_peer_link_is_up(hdr))
|
|
|
|
return true;
|
|
|
|
tipc_node_fsm_evt(n, PEER_ESTABL_CONTACT_EVT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == SELF_DOWN_PEER_LEAVING) {
|
|
|
|
if (msg_peer_node_is_up(hdr))
|
|
|
|
return false;
|
|
|
|
tipc_node_fsm_evt(n, PEER_LOST_CONTACT_EVT);
|
2015-11-20 03:30:41 +08:00
|
|
|
return true;
|
2015-07-31 06:24:19 +08:00
|
|
|
}
|
|
|
|
|
2015-11-20 03:30:44 +08:00
|
|
|
if (state == SELF_LEAVING_PEER_DOWN)
|
|
|
|
return false;
|
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
/* Ignore duplicate packets */
|
tipc: eliminate risk of stalled link synchronization
In commit 6e498158a827 ("tipc: move link synch and failover to link aggregation level")
we introduced a new mechanism for performing link failover and
synchronization. We have now detected a bug in this mechanism.
During link synchronization we use the arrival of any packet on
the tunnel link to trig a check for whether it has reached the
synchronization point or not. This has turned out to be too
permissive, since it may cause an arriving non-last SYNCH packet to
end the synch state, just to see the next SYNCH packet initiate a
new synch state with a new, higher synch point. This is not fatal,
but should be avoided, because it may significantly extend the
synchronization period, while at the same time we are not allowed
to send NACKs if packets are lost. In the worst case, a low-traffic
user may see its traffic stall until a LINK_PROTOCOL state message
trigs the link to leave synchronization state.
At the same time, LINK_PROTOCOL packets which happen to have a (non-
valid) sequence number lower than the tunnel link's rcv_nxt value will
be consistently dropped, and will never be able to resolve the situation
described above.
We fix this by exempting LINK_PROTOCOL packets from the sequence number
check, as they should be. We also reduce (but don't completely
eliminate) the risk of entering multiple synchronization states by only
allowing the (logically) first SYNCH packet to initiate a synchronization
state. This works independently of actual packet arrival order.
Fixes: commit 6e498158a827 ("tipc: move link synch and failover to link aggregation level")
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-10-14 00:41:51 +08:00
|
|
|
if ((usr != LINK_PROTOCOL) && less(oseqno, rcv_nxt))
|
2015-07-31 06:24:19 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
/* Initiate or update failover mode if applicable */
|
|
|
|
if ((usr == TUNNEL_PROTOCOL) && (mtyp == FAILOVER_MSG)) {
|
|
|
|
syncpt = oseqno + exp_pkts - 1;
|
2015-07-31 06:24:23 +08:00
|
|
|
if (pl && tipc_link_is_up(pl)) {
|
|
|
|
__tipc_node_link_down(n, &pb_id, xmitq, &maddr);
|
2015-11-20 03:30:46 +08:00
|
|
|
tipc_skb_queue_splice_tail_init(tipc_link_inputq(pl),
|
|
|
|
tipc_link_inputq(l));
|
2015-07-31 06:24:23 +08:00
|
|
|
}
|
2015-07-31 06:24:19 +08:00
|
|
|
/* If pkts arrive out of order, use lowest calculated syncpt */
|
|
|
|
if (less(syncpt, n->sync_point))
|
|
|
|
n->sync_point = syncpt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open parallel link when tunnel link reaches synch point */
|
tipc: eliminate risk of premature link setup during failover
When a link goes down, and there is still a working link towards its
destination node, a failover is initiated, and the failed link is not
allowed to re-establish until that procedure is finished. To ensure
this, the concerned link endpoints are set to state LINK_FAILINGOVER,
and the node endpoints to NODE_FAILINGOVER during the failover period.
However, if the link reset is due to a disabled bearer, the corres-
ponding link endpoint is deleted, and only the node endpoint knows
about the ongoing failover. Now, if the disabled bearer is re-enabled
during the failover period, the discovery mechanism may create a new
link endpoint that is ready to be established, despite that this is not
permitted. This situation may cause both the ongoing failover and any
subsequent link synchronization to fail.
In this commit, we ensure that a newly created link goes directly to
state LINK_FAILINGOVER if the corresponding node state is
NODE_FAILINGOVER. This eliminates the problem described above.
Furthermore, we tighten the criteria for which packets are allowed
to end a failover state in the function tipc_node_check_state().
By checking that the receiving link is up and running, instead of just
checking that it is not in failover mode, we eliminate the risk that
protocol packets from the re-created link may cause the failover to
be prematurely terminated.
Reviewed-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>
2015-08-20 14:12:54 +08:00
|
|
|
if ((n->state == NODE_FAILINGOVER) && tipc_link_is_up(l)) {
|
2015-07-31 06:24:21 +08:00
|
|
|
if (!more(rcv_nxt, n->sync_point))
|
|
|
|
return true;
|
2015-07-31 06:24:19 +08:00
|
|
|
tipc_node_fsm_evt(n, NODE_FAILOVER_END_EVT);
|
|
|
|
if (pl)
|
2015-07-31 06:24:21 +08:00
|
|
|
tipc_link_fsm_evt(pl, LINK_FAILOVER_END_EVT);
|
2015-07-31 06:24:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-20 14:12:55 +08:00
|
|
|
/* No synching needed if only one link */
|
|
|
|
if (!pl || !tipc_link_is_up(pl))
|
|
|
|
return true;
|
|
|
|
|
tipc: eliminate risk of stalled link synchronization
In commit 6e498158a827 ("tipc: move link synch and failover to link aggregation level")
we introduced a new mechanism for performing link failover and
synchronization. We have now detected a bug in this mechanism.
During link synchronization we use the arrival of any packet on
the tunnel link to trig a check for whether it has reached the
synchronization point or not. This has turned out to be too
permissive, since it may cause an arriving non-last SYNCH packet to
end the synch state, just to see the next SYNCH packet initiate a
new synch state with a new, higher synch point. This is not fatal,
but should be avoided, because it may significantly extend the
synchronization period, while at the same time we are not allowed
to send NACKs if packets are lost. In the worst case, a low-traffic
user may see its traffic stall until a LINK_PROTOCOL state message
trigs the link to leave synchronization state.
At the same time, LINK_PROTOCOL packets which happen to have a (non-
valid) sequence number lower than the tunnel link's rcv_nxt value will
be consistently dropped, and will never be able to resolve the situation
described above.
We fix this by exempting LINK_PROTOCOL packets from the sequence number
check, as they should be. We also reduce (but don't completely
eliminate) the risk of entering multiple synchronization states by only
allowing the (logically) first SYNCH packet to initiate a synchronization
state. This works independently of actual packet arrival order.
Fixes: commit 6e498158a827 ("tipc: move link synch and failover to link aggregation level")
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-10-14 00:41:51 +08:00
|
|
|
/* Initiate synch mode if applicable */
|
|
|
|
if ((usr == TUNNEL_PROTOCOL) && (mtyp == SYNCH_MSG) && (oseqno == 1)) {
|
2015-07-31 06:24:19 +08:00
|
|
|
syncpt = iseqno + exp_pkts - 1;
|
2015-07-31 06:24:21 +08:00
|
|
|
if (!tipc_link_is_up(l)) {
|
|
|
|
tipc_link_fsm_evt(l, LINK_ESTABLISH_EVT);
|
2015-07-31 06:24:23 +08:00
|
|
|
__tipc_node_link_up(n, bearer_id, xmitq);
|
2015-07-31 06:24:21 +08:00
|
|
|
}
|
2015-07-31 06:24:19 +08:00
|
|
|
if (n->state == SELF_UP_PEER_UP) {
|
|
|
|
n->sync_point = syncpt;
|
2015-07-31 06:24:21 +08:00
|
|
|
tipc_link_fsm_evt(l, LINK_SYNCH_BEGIN_EVT);
|
2015-07-31 06:24:19 +08:00
|
|
|
tipc_node_fsm_evt(n, NODE_SYNCH_BEGIN_EVT);
|
|
|
|
}
|
2015-07-31 06:24:16 +08:00
|
|
|
}
|
2015-07-31 06:24:19 +08:00
|
|
|
|
|
|
|
/* Open tunnel link when parallel link reaches synch point */
|
2015-11-20 03:30:41 +08:00
|
|
|
if (n->state == NODE_SYNCHING) {
|
tipc: fix stale link problem during synchronization
Recent changes to the link synchronization means that we can now just
drop packets arriving on the synchronizing link before the synch point
is reached. This has lead to significant simplifications to the
implementation, but also turns out to have a flip side that we need
to consider.
Under unlucky circumstances, the two endpoints may end up
repeatedly dropping each other's packets, while immediately
asking for retransmission of the same packets, just to drop
them once more. This pattern will eventually be broken when
the synch point is reached on the other link, but before that,
the endpoints may have arrived at the retransmission limit
(stale counter) that indicates that the link should be broken.
We see this happen at rare occasions.
The fix for this is to not ask for retransmissions when a link is in
state LINK_SYNCHING. The fact that the link has reached this state
means that it has already received the first SYNCH packet, and that it
knows the synch point. Hence, it doesn't need any more packets until the
other link has reached the synch point, whereafter it can go ahead and
ask for the missing packets.
However, because of the reduced traffic on the synching link that
follows this change, it may now take longer to discover that the
synch point has been reached. We compensate for this by letting all
packets, on any of the links, trig a check for synchronization
termination. This is possible because the packets themselves don't
contain any information that is needed for discovering this condition.
Reviewed-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>
2015-08-20 14:12:56 +08:00
|
|
|
if (tipc_link_is_synching(l)) {
|
|
|
|
tnl = l;
|
|
|
|
} else {
|
|
|
|
tnl = pl;
|
|
|
|
pl = l;
|
|
|
|
}
|
2015-11-20 03:30:46 +08:00
|
|
|
inputq_len = skb_queue_len(tipc_link_inputq(pl));
|
|
|
|
dlv_nxt = tipc_link_rcv_nxt(pl) - inputq_len;
|
2015-08-20 14:12:55 +08:00
|
|
|
if (more(dlv_nxt, n->sync_point)) {
|
tipc: fix stale link problem during synchronization
Recent changes to the link synchronization means that we can now just
drop packets arriving on the synchronizing link before the synch point
is reached. This has lead to significant simplifications to the
implementation, but also turns out to have a flip side that we need
to consider.
Under unlucky circumstances, the two endpoints may end up
repeatedly dropping each other's packets, while immediately
asking for retransmission of the same packets, just to drop
them once more. This pattern will eventually be broken when
the synch point is reached on the other link, but before that,
the endpoints may have arrived at the retransmission limit
(stale counter) that indicates that the link should be broken.
We see this happen at rare occasions.
The fix for this is to not ask for retransmissions when a link is in
state LINK_SYNCHING. The fact that the link has reached this state
means that it has already received the first SYNCH packet, and that it
knows the synch point. Hence, it doesn't need any more packets until the
other link has reached the synch point, whereafter it can go ahead and
ask for the missing packets.
However, because of the reduced traffic on the synching link that
follows this change, it may now take longer to discover that the
synch point has been reached. We compensate for this by letting all
packets, on any of the links, trig a check for synchronization
termination. This is possible because the packets themselves don't
contain any information that is needed for discovering this condition.
Reviewed-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>
2015-08-20 14:12:56 +08:00
|
|
|
tipc_link_fsm_evt(tnl, LINK_SYNCH_END_EVT);
|
2015-07-31 06:24:19 +08:00
|
|
|
tipc_node_fsm_evt(n, NODE_SYNCH_END_EVT);
|
|
|
|
return true;
|
|
|
|
}
|
tipc: fix stale link problem during synchronization
Recent changes to the link synchronization means that we can now just
drop packets arriving on the synchronizing link before the synch point
is reached. This has lead to significant simplifications to the
implementation, but also turns out to have a flip side that we need
to consider.
Under unlucky circumstances, the two endpoints may end up
repeatedly dropping each other's packets, while immediately
asking for retransmission of the same packets, just to drop
them once more. This pattern will eventually be broken when
the synch point is reached on the other link, but before that,
the endpoints may have arrived at the retransmission limit
(stale counter) that indicates that the link should be broken.
We see this happen at rare occasions.
The fix for this is to not ask for retransmissions when a link is in
state LINK_SYNCHING. The fact that the link has reached this state
means that it has already received the first SYNCH packet, and that it
knows the synch point. Hence, it doesn't need any more packets until the
other link has reached the synch point, whereafter it can go ahead and
ask for the missing packets.
However, because of the reduced traffic on the synching link that
follows this change, it may now take longer to discover that the
synch point has been reached. We compensate for this by letting all
packets, on any of the links, trig a check for synchronization
termination. This is possible because the packets themselves don't
contain any information that is needed for discovering this condition.
Reviewed-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>
2015-08-20 14:12:56 +08:00
|
|
|
if (l == pl)
|
|
|
|
return true;
|
2015-07-31 06:24:19 +08:00
|
|
|
if ((usr == TUNNEL_PROTOCOL) && (mtyp == SYNCH_MSG))
|
|
|
|
return true;
|
|
|
|
if (usr == LINK_PROTOCOL)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2015-07-31 06:24:16 +08:00
|
|
|
}
|
|
|
|
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
/**
|
|
|
|
* tipc_rcv - process TIPC packets/messages arriving from off-node
|
|
|
|
* @net: the applicable net namespace
|
|
|
|
* @skb: TIPC packet
|
|
|
|
* @bearer: pointer to bearer message arrived on
|
|
|
|
*
|
|
|
|
* Invoked with no locks held. Bearer pointer must point to a valid bearer
|
|
|
|
* structure (i.e. cannot be NULL), but bearer can be inactive.
|
|
|
|
*/
|
|
|
|
void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
|
|
|
|
{
|
|
|
|
struct sk_buff_head xmitq;
|
|
|
|
struct tipc_node *n;
|
2015-07-31 06:24:19 +08:00
|
|
|
struct tipc_msg *hdr = buf_msg(skb);
|
|
|
|
int usr = msg_user(hdr);
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
int bearer_id = b->identity;
|
2015-07-31 06:24:19 +08:00
|
|
|
struct tipc_link_entry *le;
|
2015-10-22 20:51:41 +08:00
|
|
|
u16 bc_ack = msg_bcast_ack(hdr);
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
__skb_queue_head_init(&xmitq);
|
|
|
|
|
|
|
|
/* Ensure message is well-formed */
|
|
|
|
if (unlikely(!tipc_msg_validate(skb)))
|
|
|
|
goto discard;
|
|
|
|
|
2015-10-22 20:51:41 +08:00
|
|
|
/* Handle arrival of discovery or broadcast packet */
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
if (unlikely(msg_non_seq(hdr))) {
|
2015-10-22 20:51:41 +08:00
|
|
|
if (unlikely(usr == LINK_CONFIG))
|
|
|
|
return tipc_disc_rcv(net, skb, b);
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
else
|
2015-10-22 20:51:41 +08:00
|
|
|
return tipc_node_bc_rcv(net, skb, bearer_id);
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Locate neighboring node that sent packet */
|
|
|
|
n = tipc_node_find(net, msg_prevnode(hdr));
|
|
|
|
if (unlikely(!n))
|
|
|
|
goto discard;
|
2015-07-31 06:24:19 +08:00
|
|
|
le = &n->links[bearer_id];
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
|
2015-10-22 20:51:41 +08:00
|
|
|
/* Ensure broadcast reception is in synch with peer's send state */
|
|
|
|
if (unlikely(usr == LINK_PROTOCOL))
|
|
|
|
tipc_bcast_sync_rcv(net, n->bc_entry.link, hdr);
|
2015-11-20 03:30:46 +08:00
|
|
|
else if (unlikely(tipc_link_acked(n->bc_entry.link) != bc_ack))
|
2015-10-22 20:51:41 +08:00
|
|
|
tipc_bcast_ack_rcv(net, n->bc_entry.link, bc_ack);
|
|
|
|
|
2015-11-20 03:30:44 +08:00
|
|
|
/* Receive packet directly if conditions permit */
|
|
|
|
tipc_node_read_lock(n);
|
|
|
|
if (likely((n->state == SELF_UP_PEER_UP) && (usr != TUNNEL_PROTOCOL))) {
|
2015-11-20 03:30:43 +08:00
|
|
|
spin_lock_bh(&le->lock);
|
2015-11-20 03:30:44 +08:00
|
|
|
if (le->link) {
|
|
|
|
rc = tipc_link_rcv(le->link, skb, &xmitq);
|
|
|
|
skb = NULL;
|
|
|
|
}
|
2015-11-20 03:30:43 +08:00
|
|
|
spin_unlock_bh(&le->lock);
|
2015-07-31 06:24:19 +08:00
|
|
|
}
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_unlock(n);
|
|
|
|
|
|
|
|
/* Check/update node state before receiving */
|
|
|
|
if (unlikely(skb)) {
|
|
|
|
tipc_node_write_lock(n);
|
|
|
|
if (tipc_node_check_state(n, skb, bearer_id, &xmitq)) {
|
|
|
|
if (le->link) {
|
|
|
|
rc = tipc_link_rcv(le->link, skb, &xmitq);
|
|
|
|
skb = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tipc_node_write_unlock(n);
|
|
|
|
}
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
|
|
|
|
if (unlikely(rc & TIPC_LINK_UP_EVT))
|
2015-07-31 06:24:19 +08:00
|
|
|
tipc_node_link_up(n, bearer_id, &xmitq);
|
|
|
|
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
if (unlikely(rc & TIPC_LINK_DOWN_EVT))
|
2015-07-31 06:24:23 +08:00
|
|
|
tipc_node_link_down(n, bearer_id, false);
|
2015-07-31 06:24:19 +08:00
|
|
|
|
2015-10-22 20:51:41 +08:00
|
|
|
if (unlikely(!skb_queue_empty(&n->bc_entry.namedq)))
|
|
|
|
tipc_named_rcv(net, &n->bc_entry.namedq);
|
2015-07-31 06:24:24 +08:00
|
|
|
|
2015-07-31 06:24:19 +08:00
|
|
|
if (!skb_queue_empty(&le->inputq))
|
|
|
|
tipc_sk_rcv(net, &le->inputq);
|
|
|
|
|
|
|
|
if (!skb_queue_empty(&xmitq))
|
|
|
|
tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
|
|
|
|
|
tipc: reduce locking scope during packet reception
We convert packet/message reception according to the same principle
we have been using for message sending and timeout handling:
We move the function tipc_rcv() to node.c, hence handling the initial
packet reception at the link aggregation level. The function grabs
the node lock, selects the receiving link, and accesses it via a new
call tipc_link_rcv(). This function appends buffers to the input
queue for delivery upwards, but it may also append outgoing packets
to the xmit queue, just as we do during regular message sending. The
latter will happen when buffers are forwarded from the link backlog,
or when retransmission is requested.
Upon return of this function, and after having released the node lock,
tipc_rcv() delivers/tranmsits the contents of those queues, but it may
also perform actions such as link activation or reset, as indicated by
the return flags from the link.
This reduces the number of cpu cycles spent inside the node spinlock,
and reduces contention on that lock.
Reviewed-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>
2015-07-17 04:54:31 +08:00
|
|
|
tipc_node_put(n);
|
|
|
|
discard:
|
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
2014-11-20 17:29:17 +08:00
|
|
|
int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
int err;
|
2015-01-09 15:27:05 +08:00
|
|
|
struct net *net = sock_net(skb->sk);
|
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2014-11-20 17:29:17 +08:00
|
|
|
int done = cb->args[0];
|
|
|
|
int last_addr = cb->args[1];
|
|
|
|
struct tipc_node *node;
|
|
|
|
struct tipc_nl_msg msg;
|
|
|
|
|
|
|
|
if (done)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
msg.skb = skb;
|
|
|
|
msg.portid = NETLINK_CB(cb->skb).portid;
|
|
|
|
msg.seq = cb->nlh->nlmsg_seq;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2015-03-26 18:10:24 +08:00
|
|
|
if (last_addr) {
|
|
|
|
node = tipc_node_find(net, last_addr);
|
|
|
|
if (!node) {
|
|
|
|
rcu_read_unlock();
|
|
|
|
/* We never set seq or call nl_dump_check_consistent()
|
|
|
|
* this means that setting prev_seq here will cause the
|
|
|
|
* consistence check to fail in the netlink callback
|
|
|
|
* handler. Resulting in the NLMSG_DONE message having
|
|
|
|
* the NLM_F_DUMP_INTR flag set if the node state
|
|
|
|
* changed while we released the lock.
|
|
|
|
*/
|
|
|
|
cb->prev_seq = 1;
|
|
|
|
return -EPIPE;
|
|
|
|
}
|
|
|
|
tipc_node_put(node);
|
2014-11-20 17:29:17 +08:00
|
|
|
}
|
|
|
|
|
2015-01-09 15:27:05 +08:00
|
|
|
list_for_each_entry_rcu(node, &tn->node_list, list) {
|
2014-11-20 17:29:17 +08:00
|
|
|
if (last_addr) {
|
|
|
|
if (node->addr == last_addr)
|
|
|
|
last_addr = 0;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_lock(node);
|
2014-11-20 17:29:17 +08:00
|
|
|
err = __tipc_nl_add_node(&msg, node);
|
|
|
|
if (err) {
|
|
|
|
last_addr = node->addr;
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_unlock(node);
|
2014-11-20 17:29:17 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-11-20 03:30:44 +08:00
|
|
|
tipc_node_read_unlock(node);
|
2014-11-20 17:29:17 +08:00
|
|
|
}
|
|
|
|
done = 1;
|
|
|
|
out:
|
|
|
|
cb->args[0] = done;
|
|
|
|
cb->args[1] = last_addr;
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
2015-11-20 03:30:45 +08:00
|
|
|
|
2015-11-20 03:30:46 +08:00
|
|
|
/* tipc_node_find_by_name - locate owner node of link by link's name
|
2015-11-20 03:30:45 +08:00
|
|
|
* @net: the applicable net namespace
|
|
|
|
* @name: pointer to link name string
|
|
|
|
* @bearer_id: pointer to index in 'node->links' array where the link was found.
|
|
|
|
*
|
|
|
|
* Returns pointer to node owning the link, or 0 if no matching link is found.
|
|
|
|
*/
|
2015-11-20 03:30:46 +08:00
|
|
|
static struct tipc_node *tipc_node_find_by_name(struct net *net,
|
|
|
|
const char *link_name,
|
|
|
|
unsigned int *bearer_id)
|
2015-11-20 03:30:45 +08:00
|
|
|
{
|
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2015-11-20 03:30:46 +08:00
|
|
|
struct tipc_link *l;
|
|
|
|
struct tipc_node *n;
|
2015-11-20 03:30:45 +08:00
|
|
|
struct tipc_node *found_node = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
*bearer_id = 0;
|
|
|
|
rcu_read_lock();
|
2015-11-20 03:30:46 +08:00
|
|
|
list_for_each_entry_rcu(n, &tn->node_list, list) {
|
|
|
|
tipc_node_read_lock(n);
|
2015-11-20 03:30:45 +08:00
|
|
|
for (i = 0; i < MAX_BEARERS; i++) {
|
2015-11-20 03:30:46 +08:00
|
|
|
l = n->links[i].link;
|
|
|
|
if (l && !strcmp(tipc_link_name(l), link_name)) {
|
2015-11-20 03:30:45 +08:00
|
|
|
*bearer_id = i;
|
2015-11-20 03:30:46 +08:00
|
|
|
found_node = n;
|
2015-11-20 03:30:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-20 03:30:46 +08:00
|
|
|
tipc_node_read_unlock(n);
|
2015-11-20 03:30:45 +08:00
|
|
|
if (found_node)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return found_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_nl_node_set_link(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int res = 0;
|
|
|
|
int bearer_id;
|
|
|
|
char *name;
|
|
|
|
struct tipc_link *link;
|
|
|
|
struct tipc_node *node;
|
2016-02-01 15:19:56 +08:00
|
|
|
struct sk_buff_head xmitq;
|
2015-11-20 03:30:45 +08:00
|
|
|
struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
|
|
|
|
struct net *net = sock_net(skb->sk);
|
|
|
|
|
2016-02-01 15:19:56 +08:00
|
|
|
__skb_queue_head_init(&xmitq);
|
|
|
|
|
2015-11-20 03:30:45 +08:00
|
|
|
if (!info->attrs[TIPC_NLA_LINK])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
|
|
|
|
info->attrs[TIPC_NLA_LINK],
|
|
|
|
tipc_nl_link_policy);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!attrs[TIPC_NLA_LINK_NAME])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
|
|
|
|
|
|
|
|
if (strcmp(name, tipc_bclink_name) == 0)
|
|
|
|
return tipc_nl_bc_link_set(net, attrs);
|
|
|
|
|
2015-11-20 03:30:46 +08:00
|
|
|
node = tipc_node_find_by_name(net, name, &bearer_id);
|
2015-11-20 03:30:45 +08:00
|
|
|
if (!node)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
tipc_node_read_lock(node);
|
|
|
|
|
|
|
|
link = node->links[bearer_id].link;
|
|
|
|
if (!link) {
|
|
|
|
res = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attrs[TIPC_NLA_LINK_PROP]) {
|
|
|
|
struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
|
|
|
|
|
|
|
|
err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP],
|
|
|
|
props);
|
|
|
|
if (err) {
|
|
|
|
res = err;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props[TIPC_NLA_PROP_TOL]) {
|
|
|
|
u32 tol;
|
|
|
|
|
|
|
|
tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
|
2016-02-01 15:19:56 +08:00
|
|
|
tipc_link_set_tolerance(link, tol, &xmitq);
|
2015-11-20 03:30:45 +08:00
|
|
|
}
|
|
|
|
if (props[TIPC_NLA_PROP_PRIO]) {
|
|
|
|
u32 prio;
|
|
|
|
|
|
|
|
prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
|
2016-02-01 15:19:56 +08:00
|
|
|
tipc_link_set_prio(link, prio, &xmitq);
|
2015-11-20 03:30:45 +08:00
|
|
|
}
|
|
|
|
if (props[TIPC_NLA_PROP_WIN]) {
|
|
|
|
u32 win;
|
|
|
|
|
|
|
|
win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
|
|
|
|
tipc_link_set_queue_limits(link, win);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
tipc_node_read_unlock(node);
|
2016-02-01 15:19:56 +08:00
|
|
|
tipc_bearer_xmit(net, bearer_id, &xmitq, &node->links[bearer_id].maddr);
|
2015-11-20 03:30:45 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct net *net = genl_info_net(info);
|
|
|
|
struct tipc_nl_msg msg;
|
|
|
|
char *name;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
msg.portid = info->snd_portid;
|
|
|
|
msg.seq = info->snd_seq;
|
|
|
|
|
|
|
|
if (!info->attrs[TIPC_NLA_LINK_NAME])
|
|
|
|
return -EINVAL;
|
|
|
|
name = nla_data(info->attrs[TIPC_NLA_LINK_NAME]);
|
|
|
|
|
|
|
|
msg.skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
|
|
|
|
if (!msg.skb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (strcmp(name, tipc_bclink_name) == 0) {
|
|
|
|
err = tipc_nl_add_bc_link(net, &msg);
|
|
|
|
if (err) {
|
|
|
|
nlmsg_free(msg.skb);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int bearer_id;
|
|
|
|
struct tipc_node *node;
|
|
|
|
struct tipc_link *link;
|
|
|
|
|
2015-11-20 03:30:46 +08:00
|
|
|
node = tipc_node_find_by_name(net, name, &bearer_id);
|
2015-11-20 03:30:45 +08:00
|
|
|
if (!node)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
tipc_node_read_lock(node);
|
|
|
|
link = node->links[bearer_id].link;
|
|
|
|
if (!link) {
|
|
|
|
tipc_node_read_unlock(node);
|
|
|
|
nlmsg_free(msg.skb);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = __tipc_nl_add_link(net, &msg, link, 0);
|
|
|
|
tipc_node_read_unlock(node);
|
|
|
|
if (err) {
|
|
|
|
nlmsg_free(msg.skb);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return genlmsg_reply(msg.skb, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
char *link_name;
|
|
|
|
unsigned int bearer_id;
|
|
|
|
struct tipc_link *link;
|
|
|
|
struct tipc_node *node;
|
|
|
|
struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
|
|
|
|
struct net *net = sock_net(skb->sk);
|
|
|
|
struct tipc_link_entry *le;
|
|
|
|
|
|
|
|
if (!info->attrs[TIPC_NLA_LINK])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
|
|
|
|
info->attrs[TIPC_NLA_LINK],
|
|
|
|
tipc_nl_link_policy);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!attrs[TIPC_NLA_LINK_NAME])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
link_name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
|
|
|
|
|
|
|
|
if (strcmp(link_name, tipc_bclink_name) == 0) {
|
|
|
|
err = tipc_bclink_reset_stats(net);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-20 03:30:46 +08:00
|
|
|
node = tipc_node_find_by_name(net, link_name, &bearer_id);
|
2015-11-20 03:30:45 +08:00
|
|
|
if (!node)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
le = &node->links[bearer_id];
|
|
|
|
tipc_node_read_lock(node);
|
|
|
|
spin_lock_bh(&le->lock);
|
|
|
|
link = node->links[bearer_id].link;
|
|
|
|
if (!link) {
|
|
|
|
spin_unlock_bh(&le->lock);
|
|
|
|
tipc_node_read_unlock(node);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2015-11-20 03:30:46 +08:00
|
|
|
tipc_link_reset_stats(link);
|
2015-11-20 03:30:45 +08:00
|
|
|
spin_unlock_bh(&le->lock);
|
|
|
|
tipc_node_read_unlock(node);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Caller should hold node lock */
|
|
|
|
static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg,
|
|
|
|
struct tipc_node *node, u32 *prev_link)
|
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
for (i = *prev_link; i < MAX_BEARERS; i++) {
|
|
|
|
*prev_link = i;
|
|
|
|
|
|
|
|
if (!node->links[i].link)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
err = __tipc_nl_add_link(net, msg,
|
|
|
|
node->links[i].link, NLM_F_MULTI);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
*prev_link = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-20 03:30:46 +08:00
|
|
|
int tipc_nl_node_dump_link(struct sk_buff *skb, struct netlink_callback *cb)
|
2015-11-20 03:30:45 +08:00
|
|
|
{
|
|
|
|
struct net *net = sock_net(skb->sk);
|
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
|
|
|
struct tipc_node *node;
|
|
|
|
struct tipc_nl_msg msg;
|
|
|
|
u32 prev_node = cb->args[0];
|
|
|
|
u32 prev_link = cb->args[1];
|
|
|
|
int done = cb->args[2];
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (done)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
msg.skb = skb;
|
|
|
|
msg.portid = NETLINK_CB(cb->skb).portid;
|
|
|
|
msg.seq = cb->nlh->nlmsg_seq;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
if (prev_node) {
|
|
|
|
node = tipc_node_find(net, prev_node);
|
|
|
|
if (!node) {
|
|
|
|
/* We never set seq or call nl_dump_check_consistent()
|
|
|
|
* this means that setting prev_seq here will cause the
|
|
|
|
* consistence check to fail in the netlink callback
|
|
|
|
* handler. Resulting in the last NLMSG_DONE message
|
|
|
|
* having the NLM_F_DUMP_INTR flag set.
|
|
|
|
*/
|
|
|
|
cb->prev_seq = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
tipc_node_put(node);
|
|
|
|
|
|
|
|
list_for_each_entry_continue_rcu(node, &tn->node_list,
|
|
|
|
list) {
|
|
|
|
tipc_node_read_lock(node);
|
|
|
|
err = __tipc_nl_add_node_links(net, &msg, node,
|
|
|
|
&prev_link);
|
|
|
|
tipc_node_read_unlock(node);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
prev_node = node->addr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err = tipc_nl_add_bc_link(net, &msg);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
list_for_each_entry_rcu(node, &tn->node_list, list) {
|
|
|
|
tipc_node_read_lock(node);
|
|
|
|
err = __tipc_nl_add_node_links(net, &msg, node,
|
|
|
|
&prev_link);
|
|
|
|
tipc_node_read_unlock(node);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
prev_node = node->addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done = 1;
|
|
|
|
out:
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
cb->args[0] = prev_node;
|
|
|
|
cb->args[1] = prev_link;
|
|
|
|
cb->args[2] = done;
|
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|