Skip to content

Commit 628529b

Browse files
Jamal Hadi SalimDavid S. Miller
authored andcommitted
[XFRM] Introduce standalone SAD lookup
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>
1 parent 007a531 commit 628529b

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎include/net/xfrm.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,10 @@ extern struct xfrm_state *xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t
928928
struct flowi *fl, struct xfrm_tmpl *tmpl,
929929
struct xfrm_policy *pol, int *err,
930930
unsigned short family);
931+
extern struct xfrm_state * xfrm_stateonly_find(xfrm_address_t *daddr,
932+
xfrm_address_t *saddr,
933+
unsigned short family,
934+
u8 mode, u8 proto, u32 reqid);
931935
extern int xfrm_state_check_expire(struct xfrm_state *x);
932936
extern void xfrm_state_insert(struct xfrm_state *x);
933937
extern int xfrm_state_add(struct xfrm_state *x);

‎net/xfrm/xfrm_state.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,37 @@ xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
686686
return x;
687687
}
688688

689+
struct xfrm_state *
690+
xfrm_stateonly_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
691+
unsigned short family, u8 mode, u8 proto, u32 reqid)
692+
{
693+
unsigned int h = xfrm_dst_hash(daddr, saddr, reqid, family);
694+
struct xfrm_state *rx = NULL, *x = NULL;
695+
struct hlist_node *entry;
696+
697+
spin_lock(&xfrm_state_lock);
698+
hlist_for_each_entry(x, entry, xfrm_state_bydst+h, bydst) {
699+
if (x->props.family == family &&
700+
x->props.reqid == reqid &&
701+
!(x->props.flags & XFRM_STATE_WILDRECV) &&
702+
xfrm_state_addr_check(x, daddr, saddr, family) &&
703+
mode == x->props.mode &&
704+
proto == x->id.proto &&
705+
x->km.state == XFRM_STATE_VALID) {
706+
rx = x;
707+
break;
708+
}
709+
}
710+
711+
if (rx)
712+
xfrm_state_hold(rx);
713+
spin_unlock(&xfrm_state_lock);
714+
715+
716+
return rx;
717+
}
718+
EXPORT_SYMBOL(xfrm_stateonly_find);
719+
689720
static void __xfrm_state_insert(struct xfrm_state *x)
690721
{
691722
unsigned int h;

0 commit comments

Comments
 (0)