Commit 5794708f authored by Masahide NAKAMURA's avatar Masahide NAKAMURA Committed by David S. Miller

[XFRM]: Introduce a helper to compare id protocol.

Put the helper to header for future use.
Based on MIPL2 kernel patch.
Signed-off-by: default avatarMasahide NAKAMURA <nakam@linux-ipv6.org>
Signed-off-by: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7e49e6de
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/socket.h> #include <linux/socket.h>
#include <linux/pfkeyv2.h> #include <linux/pfkeyv2.h>
#include <linux/ipsec.h>
#include <linux/in6.h> #include <linux/in6.h>
#include <linux/mutex.h> #include <linux/mutex.h>
...@@ -835,6 +836,11 @@ static inline int xfrm_state_kern(struct xfrm_state *x) ...@@ -835,6 +836,11 @@ static inline int xfrm_state_kern(struct xfrm_state *x)
return atomic_read(&x->tunnel_users); 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 * xfrm algorithm information
*/ */
......
...@@ -294,7 +294,7 @@ void xfrm_state_flush(u8 proto) ...@@ -294,7 +294,7 @@ void xfrm_state_flush(u8 proto)
restart: restart:
list_for_each_entry(x, xfrm_state_bydst+i, bydst) { list_for_each_entry(x, xfrm_state_bydst+i, bydst) {
if (!xfrm_state_kern(x) && 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); xfrm_state_hold(x);
spin_unlock_bh(&xfrm_state_lock); spin_unlock_bh(&xfrm_state_lock);
...@@ -772,7 +772,7 @@ int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*), ...@@ -772,7 +772,7 @@ int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*),
spin_lock_bh(&xfrm_state_lock); spin_lock_bh(&xfrm_state_lock);
for (i = 0; i < XFRM_DST_HSIZE; i++) { for (i = 0; i < XFRM_DST_HSIZE; i++) {
list_for_each_entry(x, xfrm_state_bydst+i, bydst) { 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++; count++;
} }
} }
...@@ -783,7 +783,7 @@ int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*), ...@@ -783,7 +783,7 @@ int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*),
for (i = 0; i < XFRM_DST_HSIZE; i++) { for (i = 0; i < XFRM_DST_HSIZE; i++) {
list_for_each_entry(x, xfrm_state_bydst+i, bydst) { 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; continue;
err = func(x, --count, data); err = func(x, --count, data);
if (err) if (err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment