tipc: Cosmetic changes to neighbor discovery logic
Reworks the appearance of the routine that processes incoming LINK_CONFIG messages to keep the main logic flow at a consistent level of indentation, and to add comments outlining the various phases involved in processing each message. This rework is being done to allow upcoming enhancements to this routine to be integrated more cleanly. The diff isn't really readable, so know that it was a case of the old code being like: tipc_disc_recv_msg(..) { if (in_own_cluster(orig)) { ... lines and lines of stuff ... } } which is now replaced with the more sane: tipc_disc_recv_msg(..) { if (!in_own_cluster(orig)) return; ... lines and lines of stuff ... } Instances of spin locking within the reindented block were replaced with the identical tipc_node_[un]lock() abstractions. Note that all these changes are cosmetic in nature, and do not change the way LINK_CONFIG messages are processed. Signed-off-by: Allan Stephens <Allan.Stephens@windriver.com> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
This commit is contained in:
parent
75f0aa4990
commit
a728750e4f
1 changed files with 60 additions and 45 deletions
|
@ -119,17 +119,21 @@ static void disc_dupl_alert(struct tipc_bearer *b_ptr, u32 node_addr,
|
||||||
|
|
||||||
void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr)
|
void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr)
|
||||||
{
|
{
|
||||||
|
struct tipc_node *n_ptr;
|
||||||
struct link *link;
|
struct link *link;
|
||||||
struct tipc_media_addr media_addr;
|
struct tipc_media_addr media_addr, *addr;
|
||||||
|
struct sk_buff *rbuf;
|
||||||
struct tipc_msg *msg = buf_msg(buf);
|
struct tipc_msg *msg = buf_msg(buf);
|
||||||
u32 dest = msg_dest_domain(msg);
|
u32 dest = msg_dest_domain(msg);
|
||||||
u32 orig = msg_prevnode(msg);
|
u32 orig = msg_prevnode(msg);
|
||||||
u32 net_id = msg_bc_netid(msg);
|
u32 net_id = msg_bc_netid(msg);
|
||||||
u32 type = msg_type(msg);
|
u32 type = msg_type(msg);
|
||||||
|
int link_fully_up;
|
||||||
|
|
||||||
msg_get_media_addr(msg, &media_addr);
|
msg_get_media_addr(msg, &media_addr);
|
||||||
buf_discard(buf);
|
buf_discard(buf);
|
||||||
|
|
||||||
|
/* Validate discovery message from requesting node */
|
||||||
if (net_id != tipc_net_id)
|
if (net_id != tipc_net_id)
|
||||||
return;
|
return;
|
||||||
if (!tipc_addr_domain_valid(dest))
|
if (!tipc_addr_domain_valid(dest))
|
||||||
|
@ -143,57 +147,68 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr)
|
||||||
}
|
}
|
||||||
if (!tipc_in_scope(dest, tipc_own_addr))
|
if (!tipc_in_scope(dest, tipc_own_addr))
|
||||||
return;
|
return;
|
||||||
if (in_own_cluster(orig)) {
|
if (!in_own_cluster(orig))
|
||||||
/* Always accept link here */
|
return;
|
||||||
struct sk_buff *rbuf;
|
|
||||||
struct tipc_media_addr *addr;
|
|
||||||
struct tipc_node *n_ptr = tipc_node_find(orig);
|
|
||||||
int link_fully_up;
|
|
||||||
|
|
||||||
if (n_ptr == NULL) {
|
/* Locate structure corresponding to requesting node */
|
||||||
n_ptr = tipc_node_create(orig);
|
n_ptr = tipc_node_find(orig);
|
||||||
if (!n_ptr)
|
if (!n_ptr) {
|
||||||
return;
|
n_ptr = tipc_node_create(orig);
|
||||||
}
|
if (!n_ptr)
|
||||||
spin_lock_bh(&n_ptr->lock);
|
|
||||||
|
|
||||||
/* Don't talk to neighbor during cleanup after last session */
|
|
||||||
|
|
||||||
if (n_ptr->cleanup_required) {
|
|
||||||
spin_unlock_bh(&n_ptr->lock);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
tipc_node_lock(n_ptr);
|
||||||
|
|
||||||
link = n_ptr->links[b_ptr->identity];
|
/* Don't talk to neighbor during cleanup after last session */
|
||||||
|
if (n_ptr->cleanup_required) {
|
||||||
|
tipc_node_unlock(n_ptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
link = n_ptr->links[b_ptr->identity];
|
||||||
|
|
||||||
|
/* Create a link endpoint for this bearer, if necessary */
|
||||||
|
if (!link) {
|
||||||
|
link = tipc_link_create(b_ptr, orig, &media_addr);
|
||||||
if (!link) {
|
if (!link) {
|
||||||
link = tipc_link_create(b_ptr, orig, &media_addr);
|
tipc_node_unlock(n_ptr);
|
||||||
if (!link) {
|
|
||||||
spin_unlock_bh(&n_ptr->lock);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addr = &link->media_addr;
|
|
||||||
if (memcmp(addr, &media_addr, sizeof(*addr))) {
|
|
||||||
if (tipc_link_is_up(link) || (!link->started)) {
|
|
||||||
disc_dupl_alert(b_ptr, orig, &media_addr);
|
|
||||||
spin_unlock_bh(&n_ptr->lock);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
warn("Resetting link <%s>, peer interface address changed\n",
|
|
||||||
link->name);
|
|
||||||
memcpy(addr, &media_addr, sizeof(*addr));
|
|
||||||
tipc_link_reset(link);
|
|
||||||
}
|
|
||||||
link_fully_up = link_working_working(link);
|
|
||||||
spin_unlock_bh(&n_ptr->lock);
|
|
||||||
if ((type == DSC_RESP_MSG) || link_fully_up)
|
|
||||||
return;
|
return;
|
||||||
rbuf = tipc_disc_init_msg(DSC_RESP_MSG, orig, b_ptr);
|
|
||||||
if (rbuf != NULL) {
|
|
||||||
b_ptr->media->send_msg(rbuf, b_ptr, &media_addr);
|
|
||||||
buf_discard(rbuf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ensure requesting node's media address is correct
|
||||||
|
*
|
||||||
|
* If media address doesn't match and the link is working, reject the
|
||||||
|
* request (must be from a duplicate node).
|
||||||
|
*
|
||||||
|
* If media address doesn't match and the link is not working, accept
|
||||||
|
* the new media address and reset the link to ensure it starts up
|
||||||
|
* cleanly.
|
||||||
|
*/
|
||||||
|
addr = &link->media_addr;
|
||||||
|
if (memcmp(addr, &media_addr, sizeof(*addr))) {
|
||||||
|
if (tipc_link_is_up(link) || (!link->started)) {
|
||||||
|
disc_dupl_alert(b_ptr, orig, &media_addr);
|
||||||
|
tipc_node_unlock(n_ptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
warn("Resetting link <%s>, peer interface address changed\n",
|
||||||
|
link->name);
|
||||||
|
memcpy(addr, &media_addr, sizeof(*addr));
|
||||||
|
tipc_link_reset(link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Accept discovery message & send response, if necessary */
|
||||||
|
link_fully_up = link_working_working(link);
|
||||||
|
tipc_node_unlock(n_ptr);
|
||||||
|
if ((type == DSC_RESP_MSG) || link_fully_up)
|
||||||
|
return;
|
||||||
|
rbuf = tipc_disc_init_msg(DSC_RESP_MSG, orig, b_ptr);
|
||||||
|
if (rbuf != NULL) {
|
||||||
|
b_ptr->media->send_msg(rbuf, b_ptr, &media_addr);
|
||||||
|
buf_discard(rbuf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Reference in a new issue