Skip to contentSkip to conversation

: Introduce a helper to compare id protocol.

PATCH In review Masahide NAKAMURA 2 participants 2 messages Jul 29, 2006 – Aug 1, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 2/23 : Introduce a helper to compare id protocol.

Put the helper to header for future use.

---
 include/net/xfrm.h    |    6 ++++++
 net/xfrm/xfrm_state.c |    6 +++---
 2 files changed, 9 insertions(+), 3 deletions(-)
include/net/xfrm.h +6 -0
index ddb153d..ca537b5 100644
@@ -10,6 +10,7 @@ #include <linux/skbuff.h>
 #include <linux/socket.h>
 #include <linux/crypto.h>
 #include <linux/pfkeyv2.h>
+#include <linux/ipsec.h>
 #include <linux/in6.h>
 #include <linux/mutex.h>
 
@@ -826,6 +827,11 @@ static inline int xfrm_state_kern(struct
 	return atomic_read(&x->tunnel_users);
 }
 
+static inline int xfrm_id_proto_match(u8 proto, u8 userproto)
+{
+	return (userproto == IPSEC_PROTO_ANY || proto == userproto);
+}
+
 /*
  * xfrm algorithm information
  */
net/xfrm/xfrm_state.c +3 -3
index 93a2f36..6cf080f 100644
@@ -293,7 +293,7 @@ void xfrm_state_flush(u8 proto)
 restart:
 		list_for_each_entry(x, xfrm_state_bydst+i, bydst) {
 			if (!xfrm_state_kern(x) &&
-			    (proto == IPSEC_PROTO_ANY || x->id.proto == proto)) {
+			    xfrm_id_proto_match(x->id.proto, proto)) {
 				xfrm_state_hold(x);
 				spin_unlock_bh(&xfrm_state_lock);
 
@@ -763,7 +763,7 @@ int xfrm_state_walk(u8 proto, int (*func
 	spin_lock_bh(&xfrm_state_lock);
 	for (i = 0; i < XFRM_DST_HSIZE; i++) {
 		list_for_each_entry(x, xfrm_state_bydst+i, bydst) {
-			if (proto == IPSEC_PROTO_ANY || x->id.proto == proto)
+			if (xfrm_id_proto_match(x->id.proto, proto))
 				count++;
 		}
 	}
@@ -774,7 +774,7 @@ int xfrm_state_walk(u8 proto, int (*func
 
 	for (i = 0; i < XFRM_DST_HSIZE; i++) {
 		list_for_each_entry(x, xfrm_state_bydst+i, bydst) {
-			if (proto != IPSEC_PROTO_ANY && x->id.proto != proto)
+			if (!xfrm_id_proto_match(x->id.proto, proto))
 				continue;
 			err = func(x, --count, data);
 			if (err)
Signature · 1 line
1.4.1
maintainer
#1 lore raw

From: Masahide NAKAMURA <[email protected]>
Date: Sat, 29 Jul 2006 18:29:56 +0900

Quoted 1 line

Put the helper to header for future use.

This change is fine.