]> err.no Git - linux-2.6/commitdiff
[XFRM] Introduce standalone SAD lookup
authorJamal Hadi Salim <hadi@cyberus.ca>
Tue, 3 Jul 2007 05:41:14 +0000 (22:41 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Wed, 11 Jul 2007 05:16:35 +0000 (22:16 -0700)
This allows other in-kernel functions to do SAD lookups.
The only known user at the moment is pktgen.

Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/xfrm.h
net/xfrm/xfrm_state.c

index ee3827f053d7cc8543de9092d4e702d46cb2bd19..d3a898b18fb4ed55a4e00c074cc8d17740c2d2f2 100644 (file)
@@ -928,6 +928,10 @@ extern struct xfrm_state *xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t
                                          struct flowi *fl, struct xfrm_tmpl *tmpl,
                                          struct xfrm_policy *pol, int *err,
                                          unsigned short family);
+extern struct xfrm_state * xfrm_stateonly_find(xfrm_address_t *daddr,
+                                              xfrm_address_t *saddr,
+                                              unsigned short family,
+                                              u8 mode, u8 proto, u32 reqid);
 extern int xfrm_state_check_expire(struct xfrm_state *x);
 extern void xfrm_state_insert(struct xfrm_state *x);
 extern int xfrm_state_add(struct xfrm_state *x);
index dfacb9c2a6e3861837b1a25b2d919bcc19b88d5a..e070c3f938fb25f3cde9d4e052ff22786a12330f 100644 (file)
@@ -686,6 +686,37 @@ out:
        return x;
 }
 
+struct xfrm_state *
+xfrm_stateonly_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
+                   unsigned short family, u8 mode, u8 proto, u32 reqid)
+{
+       unsigned int h = xfrm_dst_hash(daddr, saddr, reqid, family);
+       struct xfrm_state *rx = NULL, *x = NULL;
+       struct hlist_node *entry;
+
+       spin_lock(&xfrm_state_lock);
+       hlist_for_each_entry(x, entry, xfrm_state_bydst+h, bydst) {
+               if (x->props.family == family &&
+                   x->props.reqid == reqid &&
+                   !(x->props.flags & XFRM_STATE_WILDRECV) &&
+                   xfrm_state_addr_check(x, daddr, saddr, family) &&
+                   mode == x->props.mode &&
+                   proto == x->id.proto &&
+                   x->km.state == XFRM_STATE_VALID) {
+                       rx = x;
+                       break;
+               }
+       }
+
+       if (rx)
+               xfrm_state_hold(rx);
+       spin_unlock(&xfrm_state_lock);
+
+
+       return rx;
+}
+EXPORT_SYMBOL(xfrm_stateonly_find);
+
 static void __xfrm_state_insert(struct xfrm_state *x)
 {
        unsigned int h;