netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Gortmaker <paul.gortmaker@windriver.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, Allan.Stephens@windriver.com,
	Paul Gortmaker <paul.gortmaker@windriver.com>
Subject: [PATCH net-next 16/26] tipc: Cosmetic changes to neighbor discovery logic
Date: Sun, 13 Mar 2011 17:34:04 -0400	[thread overview]
Message-ID: <1300052054-7531-17-git-send-email-paul.gortmaker@windriver.com> (raw)
In-Reply-To: <1300052054-7531-1-git-send-email-paul.gortmaker@windriver.com>

From: Allan Stephens <Allan.Stephens@windriver.com>

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>
---
 net/tipc/discover.c |  103 +++++++++++++++++++++++++++++----------------------
 1 files changed, 59 insertions(+), 44 deletions(-)

diff --git a/net/tipc/discover.c b/net/tipc/discover.c
index 09ce231..2345268 100644
--- a/net/tipc/discover.c
+++ b/net/tipc/discover.c
@@ -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)
 {
+	struct tipc_node *n_ptr;
 	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);
 	u32 dest = msg_dest_domain(msg);
 	u32 orig = msg_prevnode(msg);
 	u32 net_id = msg_bc_netid(msg);
 	u32 type = msg_type(msg);
+	int link_fully_up;
 
 	msg_get_media_addr(msg, &media_addr);
 	buf_discard(buf);
 
+	/* Validate discovery message from requesting node */
 	if (net_id != tipc_net_id)
 		return;
 	if (!tipc_addr_domain_valid(dest))
@@ -143,56 +147,67 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr)
 	}
 	if (!tipc_in_scope(dest, tipc_own_addr))
 		return;
-	if (in_own_cluster(orig)) {
-		/* Always accept link here */
-		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) {
-			n_ptr = tipc_node_create(orig);
-			if (!n_ptr)
-				return;
-		}
-		spin_lock_bh(&n_ptr->lock);
-
-		/* Don't talk to neighbor during cleanup after last session */
+	if (!in_own_cluster(orig))
+		return;
 
-		if (n_ptr->cleanup_required) {
-			spin_unlock_bh(&n_ptr->lock);
+	/* Locate structure corresponding to requesting node */
+	n_ptr = tipc_node_find(orig);
+	if (!n_ptr) {
+		n_ptr = tipc_node_create(orig);
+		if (!n_ptr)
 			return;
-		}
+	}
+	tipc_node_lock(n_ptr);
+
+	/* 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];
+	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) {
-			link = tipc_link_create(b_ptr, orig, &media_addr);
-			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);
+			tipc_node_unlock(n_ptr);
+			return;
 		}
-		link_fully_up = link_working_working(link);
-		spin_unlock_bh(&n_ptr->lock);
-		if ((type == DSC_RESP_MSG) || link_fully_up)
+	}
+
+	/*
+	 * 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;
-		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);
 		}
+		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);
 	}
 }
 
-- 
1.7.3.3


  parent reply	other threads:[~2011-03-13 21:34 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-13 21:33 [PATCH net-next 00/26] tipc: Yet another mixed bag of updates Paul Gortmaker
2011-03-13 21:33 ` [PATCH net-next 01/26] tipc: Allow receiving into iovec containing multiple entries Paul Gortmaker
2011-03-13 21:33 ` [PATCH net-next 02/26] tipc: Correct broadcast link peer info when displaying links Paul Gortmaker
2011-03-13 21:33 ` [PATCH net-next 03/26] tipc: Add network address mask helper routines Paul Gortmaker
2011-03-13 21:33 ` [PATCH net-next 04/26] tipc: Prevent null pointer error when removing a node subscription Paul Gortmaker
2011-03-13 21:33 ` [PATCH net-next 05/26] tipc: Cosmetic changes to node subscription code Paul Gortmaker
2011-03-13 21:33 ` [PATCH net-next 06/26] tipc: Add support for SO_RCVTIMEO socket option Paul Gortmaker
2011-03-13 21:33 ` [PATCH net-next 07/26] tipc: Fix problem with missing link in "tipc-config -l" output Paul Gortmaker
2011-03-13 21:33 ` [PATCH net-next 08/26] tipc: Split up unified structure of network-related variables Paul Gortmaker
2011-03-13 21:33 ` [PATCH net-next 09/26] tipc: Eliminate configuration for maximum number of cluster nodes Paul Gortmaker
2011-03-13 21:33 ` [PATCH net-next 10/26] tipc: Convert node object array to a hash table Paul Gortmaker
2011-03-13 21:33 ` [PATCH net-next 11/26] tipc: manually inline net_start/stop, make assoc. vars static Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 12/26] tipc: Eliminate timestamp from link protocol messages Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 13/26] tipc: cosmetic - function names are not to be full sentences Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 14/26] tipc: make msg_set_redundant_link() consistent with other set ops Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 15/26] tipc: Fix redundant link field handling in link protocol message Paul Gortmaker
2011-03-13 21:34 ` Paul Gortmaker [this message]
2011-03-13 21:34 ` [PATCH net-next 17/26] tipc: Give Tx of discovery responses priority over link messages Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 18/26] tipc: Optimizations to link creation code Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 19/26] tipc: Correct misnamed references to neighbor discovery domain Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 20/26] tipc: Remove unused field in bearer structure Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 21/26] tipc: Eliminate unnecessary constant for neighbor discovery msg size Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 22/26] tipc: Don't respond to neighbor discovery request on blocked bearer Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 23/26] tipc: Remove bearer flag indicating existence of broadcast address Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 24/26] tipc: Eliminate remaining support for routing table messages Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 25/26] tipc: Eliminate obsolete routine for handling routed messages Paul Gortmaker
2011-03-13 21:34 ` [PATCH net-next 26/26] tipc: Update maintenance information Paul Gortmaker
2011-03-14  1:53 ` [PATCH net-next 00/26] tipc: Yet another mixed bag of updates David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1300052054-7531-17-git-send-email-paul.gortmaker@windriver.com \
    --to=paul.gortmaker@windriver.com \
    --cc=Allan.Stephens@windriver.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).