netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Maloy <jon.maloy@ericsson.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	erik.hugne@ericsson.com, ying.xue@windriver.com,
	maloy@donjonn.com, tipc-discussion@lists.sourceforge.net,
	Jon Maloy <jon.maloy@ericsson.com>
Subject: [PATCH net-next 02/13] tipc: move link creation from neighbor discoverer to node
Date: Thu, 16 Jul 2015 16:54:20 -0400	[thread overview]
Message-ID: <1437080071-6686-3-git-send-email-jon.maloy@ericsson.com> (raw)
In-Reply-To: <1437080071-6686-1-git-send-email-jon.maloy@ericsson.com>

As a step towards turning links into node internal entities, we move the
creation of links from the neighbor discovery logics to the node's link
control logics.

We also create an additional entry for the link's media address in the
newly introduced struct tipc_link_entry, since this is where it is
needed in the upcoming commits. The current copy in struct tipc_link
is kept for now, but will be removed later.

Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
---
 net/tipc/discover.c | 20 ++++----------------
 net/tipc/node.c     | 27 +++++++++++++++++++++++++++
 net/tipc/node.h     |  6 ++++++
 3 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/net/tipc/discover.c b/net/tipc/discover.c
index 9334453..164d089 100644
--- a/net/tipc/discover.c
+++ b/net/tipc/discover.c
@@ -35,7 +35,7 @@
  */
 
 #include "core.h"
-#include "link.h"
+#include "node.h"
 #include "discover.h"
 
 /* min delay during bearer start up */
@@ -125,7 +125,6 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *buf,
 {
 	struct tipc_net *tn = net_generic(net, tipc_net_id);
 	struct tipc_node *node;
-	struct tipc_link *link;
 	struct tipc_media_addr maddr;
 	struct sk_buff *rbuf;
 	struct tipc_msg *msg = buf_msg(buf);
@@ -170,13 +169,10 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *buf,
 		return;
 	tipc_node_lock(node);
 	node->capabilities = caps;
-	link = node->links[bearer->identity].link;
 
 	/* Prepare to validate requesting node's signature and media address */
 	sign_match = (signature == node->signature);
-	addr_match = link && !memcmp(&link->media_addr, &maddr, sizeof(maddr));
-	link_up = link && tipc_link_is_up(link);
-
+	tipc_node_check_dest(node, bearer, &link_up, &addr_match, &maddr);
 
 	/* These three flags give us eight permutations: */
 
@@ -239,16 +235,8 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *buf,
 	if (accept_sign)
 		node->signature = signature;
 
-	if (accept_addr) {
-		if (!link)
-			link = tipc_link_create(node, bearer, &maddr);
-		if (link) {
-			memcpy(&link->media_addr, &maddr, sizeof(maddr));
-			tipc_link_reset(link);
-		} else {
-			respond = false;
-		}
-	}
+	if (accept_addr && !tipc_node_update_dest(node, bearer, &maddr))
+		respond = false;
 
 	/* Send response, if necessary */
 	if (respond && (mtyp == DSC_REQ_MSG)) {
diff --git a/net/tipc/node.c b/net/tipc/node.c
index db46e5d..06f642a 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -334,6 +334,33 @@ bool tipc_node_is_up(struct tipc_node *n)
 	return n->active_links[0];
 }
 
+void tipc_node_check_dest(struct tipc_node *n, struct tipc_bearer *b,
+			  bool *link_up, bool *addr_match,
+			  struct tipc_media_addr *maddr)
+{
+	struct tipc_link *l = n->links[b->identity].link;
+	struct tipc_media_addr *curr = &n->links[b->identity].maddr;
+
+	*link_up = l && tipc_link_is_up(l);
+	*addr_match = l && !memcmp(curr, maddr, sizeof(*maddr));
+}
+
+bool tipc_node_update_dest(struct tipc_node *n,  struct tipc_bearer *b,
+			   struct tipc_media_addr *maddr)
+{
+	struct tipc_link *l = n->links[b->identity].link;
+	struct tipc_media_addr *curr = &n->links[b->identity].maddr;
+
+	if (!l)
+		l = tipc_link_create(n, b, maddr);
+	if (!l)
+		return false;
+	memcpy(&l->media_addr, maddr, sizeof(*maddr));
+	memcpy(curr, maddr, sizeof(*maddr));
+	tipc_link_reset(l);
+	return true;
+}
+
 void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
 {
 	n_ptr->links[l_ptr->bearer_id].link = l_ptr;
diff --git a/net/tipc/node.h b/net/tipc/node.h
index 320cea3..68579c7 100644
--- a/net/tipc/node.h
+++ b/net/tipc/node.h
@@ -92,6 +92,7 @@ struct tipc_node_bclink {
 struct tipc_link_entry {
 	struct tipc_link *link;
 	u32 mtu;
+	struct tipc_media_addr maddr;
 };
 
 /**
@@ -143,6 +144,11 @@ struct tipc_node *tipc_node_find(struct net *net, u32 addr);
 void tipc_node_put(struct tipc_node *node);
 struct tipc_node *tipc_node_create(struct net *net, u32 addr);
 void tipc_node_stop(struct net *net);
+void tipc_node_check_dest(struct tipc_node *n, struct tipc_bearer *bearer,
+			  bool *link_up, bool *addr_match,
+			  struct tipc_media_addr *maddr);
+bool tipc_node_update_dest(struct tipc_node *n, struct tipc_bearer *bearer,
+			   struct tipc_media_addr *maddr);
 void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr);
 void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr);
 void tipc_node_link_down(struct tipc_node *n_ptr, int bearer_id);
-- 
1.9.1

  parent reply	other threads:[~2015-07-16 20:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-16 20:54 [PATCH net-next 00/13] tipc: separate link and link aggregation layer Jon Maloy
2015-07-16 20:54 ` [PATCH net-next 01/13] tipc: introduce link entry structure to struct tipc_node Jon Maloy
2015-07-16 20:54 ` Jon Maloy [this message]
2015-07-16 20:54 ` [PATCH net-next 03/13] tipc: move link input queue to tipc_node Jon Maloy
2015-07-16 20:54 ` [PATCH net-next 04/13] tipc: use bearer index when looking up active links Jon Maloy
2015-07-16 20:54 ` [PATCH net-next 05/13] tipc: change sk_buffer handling in tipc_link_xmit() Jon Maloy
2015-07-16 20:54 ` [PATCH net-next 06/13] tipc: make media xmit call outside node spinlock context Jon Maloy
2015-07-16 20:54 ` [PATCH net-next 07/13] tipc: clean up definitions and usage of link flags Jon Maloy
2015-07-16 20:54 ` [PATCH net-next 08/13] tipc: introduce new link protocol msg create function Jon Maloy
2015-07-16 20:54 ` [PATCH net-next 09/13] tipc: improve link FSM implementation Jon Maloy
2015-07-16 20:54 ` [PATCH net-next 10/13] tipc: simplify link timer implementation Jon Maloy
2015-07-16 20:54 ` [PATCH net-next 11/13] tipc: move link supervision timer to node level Jon Maloy
2015-07-16 20:54 ` [PATCH net-next 12/13] tipc: introduce node contact FSM Jon Maloy
2015-07-16 20:54 ` [PATCH net-next 13/13] tipc: reduce locking scope during packet reception Jon Maloy
2015-07-21  3:41 ` [PATCH net-next 00/13] tipc: separate link and link aggregation layer 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=1437080071-6686-3-git-send-email-jon.maloy@ericsson.com \
    --to=jon.maloy@ericsson.com \
    --cc=davem@davemloft.net \
    --cc=erik.hugne@ericsson.com \
    --cc=maloy@donjonn.com \
    --cc=netdev@vger.kernel.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=tipc-discussion@lists.sourceforge.net \
    --cc=ying.xue@windriver.com \
    /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).