netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: martinbj2008@gmail.com
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	baker.kernel@gmail.com, Junwei Zhang <martinbj2008@gmail.com>
Subject: [PATCH V1 net-next] net: only check perm protocol when register proto
Date: Tue, 15 Sep 2015 08:14:05 +0800	[thread overview]
Message-ID: <1442276045-4233-1-git-send-email-martinbj2008@gmail.com> (raw)

From: Junwei Zhang <martinbj2008@gmail.com>

the permanent protocol nodes are at the head of the list.
So only need check all these nodes.

and insert the new node after the last permanent protocol node,
no matter new node is permanent or not.

If the inserted proto conflicts with existing permanent protocol,
then goto out_permanent immediately.

Signed-off-by: Martin Zhang <martinbj2008@gmail.com>
---
 net/ipv4/af_inet.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 1d0c3ad..c61e0b5 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1043,22 +1043,16 @@ void inet_register_protosw(struct inet_protosw *p)
 		goto out_illegal;
 
 	/* If we are trying to override a permanent protocol, bail. */
-	answer = NULL;
 	last_perm = &inetsw[p->type];
 	list_for_each(lh, &inetsw[p->type]) {
 		answer = list_entry(lh, struct inet_protosw, list);
-
 		/* Check only the non-wild match. */
-		if (INET_PROTOSW_PERMANENT & answer->flags) {
-			if (protocol == answer->protocol)
+		if ((INET_PROTOSW_PERMANENT & answer->flags) == 0)
 				break;
-			last_perm = lh;
-		}
-
-		answer = NULL;
+		if (protocol == answer->protocol)
+			goto out_permanent;
+		last_perm = lh;
 	}
-	if (answer)
-		goto out_permanent;
 
 	/* Add the new entry after the last permanent entry if any, so that
 	 * the new entry does not override a permanent entry when matched with
-- 
1.8.3.1

             reply	other threads:[~2015-09-15  0:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-15  0:14 martinbj2008 [this message]
2015-09-17 23:20 ` [PATCH V1 net-next] net: only check perm protocol when register proto David Miller
2015-09-18  4:00   ` [PATCH V2 " martinbj2008
2015-09-18  4:03     ` 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=1442276045-4233-1-git-send-email-martinbj2008@gmail.com \
    --to=martinbj2008@gmail.com \
    --cc=baker.kernel@gmail.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --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).