All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V1 net-next] net: only check perm protocol when register proto
@ 2015-09-15  0:14 martinbj2008
  2015-09-17 23:20 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: martinbj2008 @ 2015-09-15  0:14 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-kernel, baker.kernel, Junwei Zhang

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V1 net-next] net: only check perm protocol when register proto
  2015-09-15  0:14 [PATCH V1 net-next] net: only check perm protocol when register proto martinbj2008
@ 2015-09-17 23:20 ` David Miller
  2015-09-18  4:00   ` [PATCH V2 " martinbj2008
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2015-09-17 23:20 UTC (permalink / raw)
  To: martinbj2008; +Cc: netdev, linux-kernel, baker.kernel

From: martinbj2008@gmail.com
Date: Tue, 15 Sep 2015 08:14:05 +0800

> @@ -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;

Well, if you're going to do this, you need to fix up the indentation
of that "break;" statement.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH V2 net-next] net: only check perm protocol when register proto
  2015-09-17 23:20 ` David Miller
@ 2015-09-18  4:00   ` martinbj2008
  2015-09-18  4:03     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: martinbj2008 @ 2015-09-18  4:00 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-kernel, Junwei Zhang

From: Junwei Zhang <martinbj2008@gmail.com>

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

No matter the new node is permanent or not,
insert the new node after the last permanent protocol node,

If the new node conflicts with existing permanent node,
return error.

Signed-off-by: Martin Zhang <martinbj2008@gmail.com>
---
V2: Fix indentation
    rewrite statement
 
 net/ipv4/af_inet.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 1d0c3ad..8a55664 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)
-				break;
-			last_perm = lh;
-		}
-
-		answer = NULL;
+		if ((INET_PROTOSW_PERMANENT & answer->flags) == 0)
+			break;
+		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
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V2 net-next] net: only check perm protocol when register proto
  2015-09-18  4:00   ` [PATCH V2 " martinbj2008
@ 2015-09-18  4:03     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2015-09-18  4:03 UTC (permalink / raw)
  To: martinbj2008; +Cc: netdev, linux-kernel

From: martinbj2008@gmail.com
Date: Fri, 18 Sep 2015 00:00:05 -0400

> From: Junwei Zhang <martinbj2008@gmail.com>
> 
> The permanent protocol nodes are at the head of the list,
> So only need check all these nodes.
> 
> No matter the new node is permanent or not,
> insert the new node after the last permanent protocol node,
> 
> If the new node conflicts with existing permanent node,
> return error.
> 
> Signed-off-by: Martin Zhang <martinbj2008@gmail.com>
> ---
> V2: Fix indentation
>     rewrite statement

Applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-18  4:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-15  0:14 [PATCH V1 net-next] net: only check perm protocol when register proto martinbj2008
2015-09-17 23:20 ` David Miller
2015-09-18  4:00   ` [PATCH V2 " martinbj2008
2015-09-18  4:03     ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.