netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Allan Stephens <allan.stephens@windriver.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org, allan.stephens@windriver.com
Subject: [PATCH 04/13 net-next-2.6] [TIPC]: Fix minor bugs in link session number handling
Date: Fri, 30 May 2008 14:20:39 -0400	[thread overview]
Message-ID: <1212171648-27122-5-git-send-email-allan.stephens@windriver.com> (raw)
In-Reply-To: <1212171648-27122-1-git-send-email-allan.stephens@windriver.com>

This patch introduces a new, out-of-range value to indicate that
a link endpoint does not have an existing session established
with its peer, eliminating the risk that the previously used
"invalid session number" value (i.e. zero) might eventually be
assigned as a valid session number and cause incorrect link
behavior.

The patch also introduces explicit bit masking when assigning a
new link session number to ensure it does not exceed 16 bits.

Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
---
 net/tipc/link.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/net/tipc/link.c b/net/tipc/link.c
index bd206eb..b8c1231 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -51,6 +51,12 @@
 
 
 /*
+ * Out-of-range value for link session numbers
+ */
+
+#define INVALID_SESSION 0x10000
+
+/*
  * Limit for deferred reception queue:
  */
 
@@ -464,7 +470,7 @@ struct link *tipc_link_create(struct bearer *b_ptr, const u32 peer,
 	msg = l_ptr->pmsg;
 	msg_init(msg, LINK_PROTOCOL, RESET_MSG, TIPC_OK, INT_H_SIZE, l_ptr->addr);
 	msg_set_size(msg, sizeof(l_ptr->proto_msg));
-	msg_set_session(msg, tipc_random);
+	msg_set_session(msg, (tipc_random & 0xffff));
 	msg_set_bearer_id(msg, b_ptr->identity);
 	strcpy((char *)msg_data(msg), if_name);
 
@@ -705,10 +711,10 @@ void tipc_link_reset(struct link *l_ptr)
 	u32 checkpoint = l_ptr->next_in_no;
 	int was_active_link = tipc_link_is_active(l_ptr);
 
-	msg_set_session(l_ptr->pmsg, msg_session(l_ptr->pmsg) + 1);
+	msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff));
 
-	/* Link is down, accept any session: */
-	l_ptr->peer_session = 0;
+	/* Link is down, accept any session */
+	l_ptr->peer_session = INVALID_SESSION;
 
 	/* Prepare for max packet size negotiation */
 	link_init_max_pkt(l_ptr);
@@ -2275,7 +2281,8 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
 	switch (msg_type(msg)) {
 
 	case RESET_MSG:
-		if (!link_working_unknown(l_ptr) && l_ptr->peer_session) {
+		if (!link_working_unknown(l_ptr) &&
+		    (l_ptr->peer_session != INVALID_SESSION)) {
 			if (msg_session(msg) == l_ptr->peer_session) {
 				dbg("Duplicate RESET: %u<->%u\n",
 				    msg_session(msg), l_ptr->peer_session);
-- 
1.5.3.2


  parent reply	other threads:[~2008-05-30 18:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-30 18:20 [PATCH 00/13 net-next-2.6] [TIPC]: More minor fixes and enhancements Allan Stephens
2008-05-30 18:20 ` [PATCH 01/13 net-next-2.6] [TIPC]: Fix bug in connection setup via native API Allan Stephens
2008-05-30 18:20 ` [PATCH 02/13 net-next-2.6] [TIPC]: Standardize error checking on incoming messages " Allan Stephens
2008-05-30 18:20 ` [PATCH 03/13 net-next-2.6] [TIPC]: Fix bugs in message error code display when debugging Allan Stephens
2008-05-30 18:20 ` Allan Stephens [this message]
2008-05-30 18:20 ` [PATCH 05/13 net-next-2.6] [TIPC]: Minor optimizations to received message processing Allan Stephens
2008-05-30 18:20 ` [PATCH 06/13 net-next-2.6] [TIPC]: Prevent access of non-existent field in short message header Allan Stephens
2008-05-30 18:20 ` [PATCH 07/13 net-next-2.6] [TIPC]: Optimize message initialization routine Allan Stephens
2008-05-30 18:20 ` [PATCH 08/13 net-next-2.6] [TIPC]: Prevent display of name table types with no publications Allan Stephens
2008-05-30 18:20 ` [PATCH 09/13 net-next-2.6] [TIPC]: Add missing spinlock in name table display code Allan Stephens
2008-05-30 18:20 ` [PATCH 10/13 net-next-2.6] [TIPC]: Expand link sequence gap field to 13 bits Allan Stephens
2008-05-30 18:20 ` [PATCH 11/13 net-next-2.6] [TIPC]: Message header creation optimizations Allan Stephens
2008-05-30 18:20 ` [PATCH 12/13 net-next-2.6] [TIPC]: Fix bugs in rejection of message with short header Allan Stephens
2008-05-30 18:20 ` [PATCH 13/13 net-next-2.6] [TIPC]: Message rejection rework preparatory changes Allan Stephens
2008-06-05  1:21 ` [PATCH 00/13 net-next-2.6] [TIPC]: More minor fixes and enhancements 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=1212171648-27122-5-git-send-email-allan.stephens@windriver.com \
    --to=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).