/* * net/tipc/node.c: TIPC node management routines * * Copyright (c) 2000-2006, 2012-2016, Ericsson AB * Copyright (c) 2005-2006, 2010-2014, Wind River Systems * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 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. * * 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 * POSSIBILITY OF SUCH DAMAGE.
*/
/* 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_node - TIPC node structure * @addr: network address of node * @kref: 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 * @active_links: bearer ids of active links, used as index into links[] array * @links: array containing references to all links to node * @bc_entry: broadcast link entry * @action_flags: bit mask of different types of node actions * @state: connectivity state vs peer node * @preliminary: a preliminary node or not * @failover_sent: failover sent or not * @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 * @peer_id: 128-bit ID of peer * @peer_id_string: ID string of peer * @publ_list: list of publications * @conn_sks: list of connections (FIXME) * @timer: node's keepalive timer * @keepalive_intv: keepalive interval in milliseconds * @rcu: rcu struct for tipc_node * @delete_at: indicates the time for deleting a down node * @peer_net: peer's net namespace * @peer_hash_mix: hash for this peer (FIXME) * @crypto_rx: RX crypto handler
*/ 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; bool preliminary; bool failover_sent;
u16 sync_point; int link_cnt;
u16 working_links;
u16 capabilities;
u32 signature;
u32 link_id;
u8 peer_id[16]; char peer_id_string[NODE_ID_STR_LEN]; struct list_head publ_list; struct list_head conn_sks; unsignedlong keepalive_intv; struct timer_list timer; struct rcu_head rcu; unsignedlong delete_at; struct net *peer_net;
u32 peer_hash_mix; #ifdef CONFIG_TIPC_CRYPTO struct tipc_crypto *crypto_rx; #endif
};
staticstruct 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, bool connected)
{ struct tipc_node *n; int bearer_id; unsignedint mtu = MAX_MSG_SIZE;
n = tipc_node_find(net, addr); if (unlikely(!n)) return mtu;
/* Allow MAX_MSG_SIZE when building connection oriented message * if they are in the same core network
*/ if (n->peer_net && connected) {
tipc_node_put(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;
}
/* tipc_node_find_by_id - locate specified node object by its 128-bit id * Note: this function is called only when a discovery request failed * to find the node by its 32-bit id, and is not time critical
*/ staticstruct tipc_node *tipc_node_find_by_id(struct net *net, u8 *id)
{ struct tipc_net *tn = tipc_net(net); struct tipc_node *n; bool found = false;
rcu_read_lock();
list_for_each_entry_rcu(n, &tn->node_list, list) {
read_lock_bh(&n->lock); if (!memcmp(id, n->peer_id, 16) &&
kref_get_unless_zero(&n->kref))
found = true;
read_unlock_bh(&n->lock); if (found) break;
}
rcu_read_unlock(); return found ? n : NULL;
}
spin_lock_bh(&tn->node_list_lock);
n = tipc_node_find(net, addr) ?:
tipc_node_find_by_id(net, peer_id); if (n) { if (!n->preliminary) goto update; if (preliminary) gotoexit; /* A preliminary node becomes "real" now, refresh its data */
tipc_node_write_lock(n); if (!tipc_link_bc_create(net, tipc_own_addr(net), addr, peer_id, U16_MAX,
tipc_link_min_win(snd_l), tipc_link_max_win(snd_l),
n->capabilities, &n->bc_entry.inputq1,
&n->bc_entry.namedq, snd_l, &n->bc_entry.link)) {
pr_warn("Broadcast rcv link refresh failed, no memory\n");
tipc_node_write_unlock_fast(n);
tipc_node_put(n);
n = NULL; gotoexit;
}
n->preliminary = false;
n->addr = addr;
hlist_del_rcu(&n->hash);
hlist_add_head_rcu(&n->hash,
&tn->node_htable[tipc_hashfn(addr)]);
list_del_rcu(&n->list);
list_for_each_entry_rcu(temp_node, &tn->node_list, list) { if (n->addr < temp_node->addr) break;
}
list_add_tail_rcu(&n->list, &temp_node->list);
tipc_node_write_unlock_fast(n);
update: if (n->peer_hash_mix ^ hash_mixes)
tipc_node_assign_peer_net(n, hash_mixes); if (n->capabilities == capabilities) gotoexit; /* Same node may come back with new capabilities */
tipc_node_write_lock(n);
n->capabilities = capabilities; for (bearer_id = 0; bearer_id < MAX_BEARERS; bearer_id++) {
l = n->links[bearer_id].link; if (l)
tipc_link_update_caps(l, capabilities);
}
tipc_node_write_unlock_fast(n);
/* tipc_node_cleanup - delete nodes that does not * have active links for NODE_CLEANUP_AFTER time
*/ staticbool tipc_node_cleanup(struct tipc_node *peer)
{ struct tipc_node *temp_node; struct tipc_net *tn = tipc_net(peer->net); bool deleted = false;
/* If lock held by tipc_node_stop() the node will be deleted anyway */ if (!spin_trylock_bh(&tn->node_list_lock)) returnfalse;
/* tipc_node_timeout - handle expiration of node timer
*/ staticvoid tipc_node_timeout(struct timer_list *t)
{ struct tipc_node *n = timer_container_of(n, t, timer); struct tipc_link_entry *le; struct sk_buff_head xmitq; int remains = n->link_cnt; int bearer_id; int rc = 0;
trace_tipc_node_timeout(n, false, " "); if (!node_is_up(n) && tipc_node_cleanup(n)) { /*Removing the reference of Timer*/
tipc_node_put(n); return;
}
#ifdef CONFIG_TIPC_CRYPTO /* Take any crypto key related actions first */
tipc_crypto_timeout(n->crypto_rx); #endif
__skb_queue_head_init(&xmitq);
/* Initial node interval to value larger (10 seconds), then it will be * recalculated with link lowest tolerance
*/
tipc_node_read_lock(n);
n->keepalive_intv = 10000;
tipc_node_read_unlock(n); for (bearer_id = 0; remains && (bearer_id < MAX_BEARERS); bearer_id++) {
tipc_node_read_lock(n);
le = &n->links[bearer_id]; if (le->link) {
spin_lock_bh(&le->lock); /* Link tolerance may change asynchronously: */
tipc_node_calculate_timer(n, le->link);
rc = tipc_link_timeout(le->link, &xmitq);
spin_unlock_bh(&le->lock);
remains--;
}
tipc_node_read_unlock(n);
tipc_bearer_xmit(n->net, bearer_id, &xmitq, &le->maddr, n); if (rc & TIPC_LINK_DOWN_EVT)
tipc_node_link_down(n, bearer_id, false);
}
mod_timer(&n->timer, jiffies + msecs_to_jiffies(n->keepalive_intv));
}
/** * __tipc_node_link_up - handle addition of link * @n: target tipc_node * @bearer_id: id of the bearer * @xmitq: queue for messages to be xmited on * Node lock must be held by caller * Link becomes active (alone or shared) or standby, depending on its priority.
*/ staticvoid __tipc_node_link_up(struct tipc_node *n, int bearer_id, struct sk_buff_head *xmitq)
{ int *slot0 = &n->active_links[0]; int *slot1 = &n->active_links[1]; struct tipc_link *ol = node_active_link(n, 0); struct tipc_link *nl = n->links[bearer_id].link;
if (!nl || tipc_link_is_up(nl)) return;
tipc_link_fsm_evt(nl, LINK_ESTABLISH_EVT); if (!tipc_link_is_up(nl)) return;
pr_debug("Established link <%s> on network plane %c\n",
tipc_link_name(nl), tipc_link_plane(nl));
trace_tipc_node_link_up(n, true, " ");
/* Ensure that a STATE message goes first */
tipc_link_build_state_msg(nl, xmitq);
/* First link? => give it both slots */ if (!ol) {
*slot0 = bearer_id;
*slot1 = bearer_id;
tipc_node_fsm_evt(n, SELF_ESTABL_CONTACT_EVT);
n->action_flags |= TIPC_NOTIFY_NODE_UP;
tipc_link_set_active(nl, true);
tipc_bcast_add_peer(n->net, nl, xmitq); return;
}
/* Second link => redistribute slots */ if (tipc_link_prio(nl) > tipc_link_prio(ol)) {
pr_debug("Old link <%s> becomes standby\n", tipc_link_name(ol));
*slot0 = bearer_id;
*slot1 = bearer_id;
tipc_link_set_active(nl, true);
tipc_link_set_active(ol, false);
} elseif (tipc_link_prio(nl) == tipc_link_prio(ol)) {
tipc_link_set_active(nl, true);
*slot1 = bearer_id;
} else {
pr_debug("New link <%s> is standby\n", tipc_link_name(nl));
}
/* Prepare synchronization with first link */
tipc_link_tnl_prepare(ol, nl, SYNCH_MSG, xmitq);
}
/** * tipc_node_link_up - handle addition of link * @n: target tipc_node * @bearer_id: id of the bearer * @xmitq: queue for messages to be xmited on * * Link becomes active (alone or shared) or standby, depending on its priority.
*/ staticvoid tipc_node_link_up(struct tipc_node *n, int bearer_id, struct sk_buff_head *xmitq)
{ struct tipc_media_addr *maddr;
/** * tipc_node_link_failover() - start failover in case "half-failover" * * This function is only called in a very special situation where link * failover can be already started on peer node but not on this node. * This can happen when e.g.:: * * 1. Both links <1A-2A>, <1B-2B> down * 2. Link endpoint 2A up, but 1A still down (e.g. due to network * disturbance, wrong session, etc.) * 3. Link <1B-2B> up * 4. Link endpoint 2A down (e.g. due to link tolerance timeout) * 5. Node 2 starts failover onto link <1B-2B> * * ==> Node 1 does never start link/node failover! * * @n: tipc node structure * @l: link peer endpoint failingover (- can be NULL) * @tnl: tunnel link * @xmitq: queue for messages to be xmited on tnl link later
*/ staticvoid tipc_node_link_failover(struct tipc_node *n, struct tipc_link *l, struct tipc_link *tnl, struct sk_buff_head *xmitq)
{ /* Avoid to be "self-failover" that can never end */ if (!tipc_link_is_up(tnl)) return;
/* Don't rush, failure link may be in the process of resetting */ if (l && !tipc_link_is_reset(l)) return;
if (l)
tipc_link_fsm_evt(l, LINK_FAILOVER_BEGIN_EVT);
tipc_node_fsm_evt(n, NODE_FAILOVER_BEGIN_EVT);
}
/** * __tipc_node_link_down - handle loss of link * @n: target tipc_node * @bearer_id: id of the bearer * @xmitq: queue for messages to be xmited on * @maddr: output media address of the bearer
*/ staticvoid __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]; int *slot0 = &n->active_links[0]; int *slot1 = &n->active_links[1]; int i, highest = 0, prio; struct tipc_link *l, *_l, *tnl;
l = n->links[*bearer_id].link; if (!l || tipc_link_is_reset(l)) return;
pr_debug("Lost link <%s> on network plane %c\n",
tipc_link_name(l), tipc_link_plane(l));
/* 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; if (_l == l) continue;
prio = tipc_link_prio(_l); if (prio < highest) continue; if (prio > highest) {
highest = prio;
*slot0 = i;
*slot1 = i; continue;
}
*slot1 = i;
}
/* tipc_node_try_addr(): Check if addr can be used by peer, suggest other if not * Returns suggested address if any, otherwise 0
*/
u32 tipc_node_try_addr(struct net *net, u8 *id, u32 addr)
{ struct tipc_net *tn = tipc_net(net); struct tipc_node *n; bool preliminary;
u32 sugg_addr;
/* Suggest new address if some other peer is using this one */
n = tipc_node_find(net, addr); if (n) { if (!memcmp(n->peer_id, id, NODE_ID_LEN))
addr = 0;
tipc_node_put(n); if (!addr) return 0; return tipc_node_suggest_addr(net, addr);
}
/* Suggest previously used address if peer is known */
n = tipc_node_find_by_id(net, id); if (n) {
sugg_addr = n->addr;
preliminary = n->preliminary;
tipc_node_put(n); if (!preliminary) return sugg_addr;
}
/* Even this node may be in conflict */ if (tn->trial_addr == addr) return tipc_node_suggest_addr(net, addr);
n = tipc_node_create(net, addr, peer_id, capabilities, hash_mixes, false); if (!n) return;
tipc_node_write_lock(n);
le = &n->links[b->identity];
/* Prepare to validate requesting node's signature and media address */
l = le->link;
link_up = l && tipc_link_is_up(l);
link_is_reset = l && tipc_link_is_reset(l);
addr_match = l && !memcmp(&le->maddr, maddr, sizeof(*maddr));
sign_match = (signature == n->signature);
/* These three flags give us eight permutations: */
if (sign_match && addr_match && link_up) { /* All is fine. Ignore requests. */ /* Peer node is not a container/local namespace */ if (!n->peer_hash_mix)
n->peer_hash_mix = hash_mixes;
} elseif (sign_match && addr_match && !link_up) { /* Respond. The link will come up in due time */
*respond = true;
} elseif (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 a 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;
} elseif (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;
reset = true;
} elseif (!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;
} elseif (!sign_match && addr_match && !link_up) { /* The peer node has rebooted. * Accept signature, since it is a known peer.
*/
n->signature = signature;
*respond = true;
} elseif (!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;
} elseif (!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;
reset = true;
}
if (!accept_addr) gotoexit;
/* Now create new link if not already existing */ if (!l) { if (n->link_cnt == 2) gotoexit;
staticvoid tipc_node_reset_links(struct tipc_node *n)
{ int i;
pr_warn("Resetting all links to %x\n", n->addr);
trace_tipc_node_reset_links(n, true, " "); for (i = 0; i < MAX_BEARERS; i++) {
tipc_node_link_down(n, i, false);
}
}
/* tipc_node_fsm_evt - node finite state machine * Determines when contact is allowed with peer node
*/ staticvoid tipc_node_fsm_evt(struct tipc_node *n, int evt)
{ 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; 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 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; case NODE_SYNCH_BEGIN_EVT:
state = NODE_SYNCHING; break; case NODE_FAILOVER_BEGIN_EVT:
state = NODE_FAILINGOVER; break; case SELF_ESTABL_CONTACT_EVT: case PEER_ESTABL_CONTACT_EVT: case NODE_SYNCH_END_EVT: case NODE_FAILOVER_END_EVT: break; default: goto illegal_evt;
} 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; 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 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_DOWN; break; case SELF_ESTABL_CONTACT_EVT: case PEER_LOST_CONTACT_EVT: case NODE_SYNCH_END_EVT: case NODE_FAILOVER_BEGIN_EVT: break; case NODE_SYNCH_BEGIN_EVT: case NODE_FAILOVER_END_EVT: default: goto illegal_evt;
} 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_DOWN_PEER_DOWN; break; case SELF_LOST_CONTACT_EVT: case PEER_ESTABL_CONTACT_EVT: break; 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 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; 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: default: 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;
} break; default:
pr_err("Unknown node fsm state %x\n", state); break;
}
trace_tipc_node_fsm(n->peer_id, n->state, state, evt);
n->state = state; return;
illegal_evt:
pr_err("Illegal node fsm evt %x in state %x\n", evt, state);
trace_tipc_node_fsm(n->peer_id, n->state, state, evt);
}
/** * tipc_node_get_linkname - get the name of a link * * @net: the applicable net namespace * @bearer_id: id of the bearer * @addr: peer node address * @linkname: link name output buffer * @len: size of @linkname output buffer * * Return: 0 on success
*/ int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr, char *linkname, size_t len)
{ struct tipc_link *link; int err = -EINVAL; struct tipc_node *node = tipc_node_find(net, addr);
if (!node) return err;
if (bearer_id >= MAX_BEARERS) gotoexit;
tipc_node_read_lock(node);
link = node->links[bearer_id].link; if (link) {
strscpy(linkname, tipc_link_name(link), len);
err = 0;
}
tipc_node_read_unlock(node); exit:
tipc_node_put(node); return err;
}
/* Caller should hold node lock for the passed node */ staticint __tipc_nl_add_node(struct tipc_nl_msg *msg, struct tipc_node *node)
{ void *hdr; struct nlattr *attrs;
attrs = nla_nest_start_noflag(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 (node_is_up(node)) if (nla_put_flag(msg->skb, TIPC_NLA_NODE_UP)) goto attr_msg_full;
switch (msg_user(hdr)) { case TIPC_LOW_IMPORTANCE: case TIPC_MEDIUM_IMPORTANCE: case TIPC_HIGH_IMPORTANCE: case TIPC_CRITICAL_IMPORTANCE: if (msg_connected(hdr) || msg_named(hdr) ||
msg_direct(hdr)) {
tipc_loopback_trace(peer_net, list);
spin_lock_init(&list->lock);
tipc_sk_rcv(peer_net, list); return;
} if (msg_mcast(hdr)) {
tipc_loopback_trace(peer_net, list);
skb_queue_head_init(&inputq);
tipc_sk_mcast_rcv(peer_net, list, &inputq);
__skb_queue_purge(list);
skb_queue_purge(&inputq); return;
} return; case MSG_FRAGMENTER: if (tipc_msg_assemble(list)) {
tipc_loopback_trace(peer_net, list);
skb_queue_head_init(&inputq);
tipc_sk_mcast_rcv(peer_net, list, &inputq);
__skb_queue_purge(list);
skb_queue_purge(&inputq);
} return; case GROUP_PROTOCOL: case CONN_MANAGER:
tipc_loopback_trace(peer_net, list);
spin_lock_init(&list->lock);
tipc_sk_rcv(peer_net, list); return; case LINK_PROTOCOL: case NAME_DISTRIBUTOR: case TUNNEL_PROTOCOL: case BCAST_PROTOCOL: return; default: return;
}
}
/** * tipc_node_xmit() - 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. * Return: 0 if success, otherwise: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE,-ENOBUF
*/ int tipc_node_xmit(struct net *net, struct sk_buff_head *list,
u32 dnode, int selector)
{ struct tipc_link_entry *le = NULL; struct tipc_node *n; struct sk_buff_head xmitq; bool node_up = false; struct net *peer_net; int bearer_id; int rc;
/* tipc_node_xmit_skb(): send single buffer to destination * Buffers sent via this function 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.
*/ int tipc_node_xmit_skb(struct net *net, struct sk_buff *skb, u32 dnode,
u32 selector)
{ struct sk_buff_head head;
/* tipc_node_distr_xmit(): send single buffer msgs to individual destinations * Note: this is only for SYSTEM_IMPORTANCE messages, which cannot be rejected
*/ int tipc_node_distr_xmit(struct net *net, struct sk_buff_head *xmitq)
{ struct sk_buff *skb;
u32 selector, dnode;
/* Use broadcast if all nodes support it */ if (!rc_dests && tipc_bcast_get_mode(net) != BCLINK_MODE_RCAST) {
__skb_queue_head_init(&xmitq);
__skb_queue_tail(&xmitq, skb);
tipc_bcast_xmit(net, &xmitq, &dummy); return;
}
/* Otherwise use legacy replicast method */
rcu_read_lock();
list_for_each_entry_rcu(n, tipc_nodes(net), list) {
dst = n->addr; if (in_own_node(net, dst)) continue; if (!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);
}
if (rc & TIPC_LINK_DOWN_EVT) {
tipc_node_reset_links(n); return;
}
if (!(rc & TIPC_LINK_SND_STATE)) return;
/* If probe message, a STATE response will be sent anyway */ if (msg_probe(hdr)) return;
/* Produce a STATE message carrying broadcast NACK */
tipc_node_read_lock(n);
ucl = n->links[bearer_id].link; if (ucl)
tipc_link_build_state_msg(ucl, xmitq);
tipc_node_read_unlock(n);
}
/** * 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.
*/ staticvoid tipc_node_bc_rcv(struct net *net, struct sk_buff *skb, int bearer_id)
{ 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 ACKs are sent on a unicast link */ if (rc & TIPC_LINK_SND_STATE) {
tipc_node_read_lock(n);
tipc_link_build_state_msg(le->link, &xmitq);
tipc_node_read_unlock(n);
}
if (!skb_queue_empty(&xmitq))
tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr, n);
if (!skb_queue_empty(&be->inputq1))
tipc_node_mcast_rcv(n);
/* Handle NAME_DISTRIBUTOR messages sent from 1.7 nodes */ if (!skb_queue_empty(&n->bc_entry.namedq))
tipc_named_rcv(net, &n->bc_entry.namedq,
&n->bc_entry.named_rcv_nxt,
&n->bc_entry.named_open);
/* If reassembly or retransmission failure => reset all links to peer */ if (rc & TIPC_LINK_DOWN_EVT)
tipc_node_reset_links(n);
tipc_node_put(n);
}
/** * tipc_node_check_state - check and if necessary update node state * @n: target tipc_node * @skb: TIPC packet * @bearer_id: identity of bearer delivering the packet * @xmitq: queue for messages to be xmited on * Return: true if state and msg are ok, otherwise false
*/ staticbool tipc_node_check_state(struct tipc_node *n, struct sk_buff *skb, int bearer_id, struct sk_buff_head *xmitq)
{ struct tipc_msg *hdr = buf_msg(skb); int usr = msg_user(hdr); int mtyp = msg_type(hdr);
u16 oseqno = msg_seqno(hdr);
u16 exp_pkts = msg_msgcnt(hdr);
u16 rcv_nxt, syncpt, dlv_nxt, inputq_len; int state = n->state; struct tipc_link *l, *tnl, *pl = NULL; struct tipc_media_addr *maddr; int pb_id;
if (trace_tipc_node_check_state_enabled()) {
trace_tipc_skb_dump(skb, false, "skb for node state check");
trace_tipc_node_check_state(n, true, " ");
}
l = n->links[bearer_id].link; if (!l) returnfalse;
rcv_nxt = tipc_link_rcv_nxt(l);
if (likely((state == SELF_UP_PEER_UP) && (usr != TUNNEL_PROTOCOL))) returntrue;
/* Find parallel link, if any */ 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; break;
}
}
/* Check and update node accesibility if applicable */ if (state == SELF_UP_PEER_COMING) { if (!tipc_link_is_up(l)) returntrue; if (!msg_peer_link_is_up(hdr)) returntrue;
tipc_node_fsm_evt(n, PEER_ESTABL_CONTACT_EVT);
}
if (state == SELF_DOWN_PEER_LEAVING) { if (msg_peer_node_is_up(hdr)) returnfalse;
tipc_node_fsm_evt(n, PEER_LOST_CONTACT_EVT); returntrue;
}
/* Initiate or update failover mode if applicable */ if ((usr == TUNNEL_PROTOCOL) && (mtyp == FAILOVER_MSG)) {
syncpt = oseqno + exp_pkts - 1; if (pl && !tipc_link_is_reset(pl)) {
__tipc_node_link_down(n, &pb_id, xmitq, &maddr);
trace_tipc_node_link_down(n, true, "node link down <- failover!");
tipc_skb_queue_splice_tail_init(tipc_link_inputq(pl),
tipc_link_inputq(l));
}
/* If parallel link was already down, and this happened before * the tunnel link came up, node failover was never started. * Ensure that a FAILOVER_MSG is sent to get peer out of * NODE_FAILINGOVER state, also this node must accept * TUNNEL_MSGs from peer.
*/ if (n->state != NODE_FAILINGOVER)
tipc_node_link_failover(n, pl, l, xmitq);
/* 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 */ if ((n->state == NODE_FAILINGOVER) && tipc_link_is_up(l)) { if (!more(rcv_nxt, n->sync_point)) returntrue;
tipc_node_fsm_evt(n, NODE_FAILOVER_END_EVT); if (pl)
tipc_link_fsm_evt(pl, LINK_FAILOVER_END_EVT); returntrue;
}
/* No syncing needed if only one link */ if (!pl || !tipc_link_is_up(pl)) returntrue;
rcu_read_lock(); 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);
}
list_for_each_entry_rcu(node, &tn->node_list, list) { if (node->preliminary) continue; if (last_addr) { if (node->addr == last_addr)
last_addr = 0; else continue;
}
/* tipc_node_find_by_name - locate owner node of link by link's name * @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.
*/ staticstruct tipc_node *tipc_node_find_by_name(struct net *net, constchar *link_name, unsignedint *bearer_id)
{ struct tipc_net *tn = net_generic(net, tipc_net_id); struct tipc_link *l; struct tipc_node *n; struct tipc_node *found_node = NULL; int i;
*bearer_id = 0;
rcu_read_lock();
list_for_each_entry_rcu(n, &tn->node_list, list) {
tipc_node_read_lock(n); for (i = 0; i < MAX_BEARERS; i++) {
l = n->links[i].link; if (l && !strcmp(tipc_link_name(l), link_name)) {
*bearer_id = i;
found_node = n; break;
}
}
tipc_node_read_unlock(n); 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; struct sk_buff_head xmitq; struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1]; struct net *net = sock_net(skb->sk);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.