Skip to contentSkip to conversation

Introduce standalone SAD lookup

XFRM jamal 1 participant 2 messages Jun 9, 2007

Subsystems (3)
lore
Share & tools
lore

jamal

author
#0 lore raw

3 of 4.

cheers,
jamal

commit 923d6c49f9f513da41e4bfd8188304787a5c8093

Author: Jamal Hadi Salim <[email protected]>
Date:   Sat Jun 9 09:16:12 2007 -0400

[XFRM] Introduce standalone SAD lookup
This allows other in-kernel functions to do SAD lookups. The only known user at the moment is pktgen.

include/net/xfrm.h +4 -0
index 311f25a..79d2c37 100644
@@ -920,6 +920,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);
net/xfrm/xfrm_state.c +35 -0
index 85f3f43..b8562e4 100644
@@ -686,6 +686,41 @@ 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)  {
+
+			if (x->km.state != XFRM_STATE_VALID)
+					continue;
+			else {
+				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;
author
#1 lore raw

Sorry, meant to cc Herbert and James since they commented two generations ago.
Gents, if you manage to have the cycles please look at this specific one. Herbert, for tunnel mode i think i will agree with you and introduce a dst struct; but i will defer that to some later patch.

cheers,
jamal

Quoted 4 lines · jamal

3 of 4.

cheers,
jamal