Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 8f3ee7f

Browse files
Terence Trittonlag-google
authored andcommitted
Revert "xfrm: policy: remove remaining use of inexact list"
This reverts commit a54ad72. Bug: 367633876 Signed-off-by: Terence Tritton <[email protected]> Change-Id: Id872891910aa24816d4e73f4b7b32b1064ebacab
1 parent 7712c05 commit 8f3ee7f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

include/net/xfrm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ struct xfrm_policy {
585585
u16 family;
586586
struct xfrm_sec_ctx *security;
587587
struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH];
588+
struct hlist_node bydst_inexact_list;
588589
struct rcu_head rcu;
589590

590591
struct xfrm_dev_offload xdo;

net/xfrm/xfrm_policy.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ xfrm_policy_inexact_lookup_rcu(struct net *net,
201201
static struct xfrm_policy *
202202
xfrm_policy_insert_list(struct hlist_head *chain, struct xfrm_policy *policy,
203203
bool excl);
204+
static void xfrm_policy_insert_inexact_list(struct hlist_head *chain,
205+
struct xfrm_policy *policy);
204206

205207
static bool
206208
xfrm_policy_find_inexact_candidates(struct xfrm_pol_inexact_candidates *cand,
@@ -413,6 +415,7 @@ struct xfrm_policy *xfrm_policy_alloc(struct net *net, gfp_t gfp)
413415
if (policy) {
414416
write_pnet(&policy->xp_net, net);
415417
INIT_LIST_HEAD(&policy->walk.all);
418+
INIT_HLIST_NODE(&policy->bydst_inexact_list);
416419
INIT_HLIST_NODE(&policy->bydst);
417420
INIT_HLIST_NODE(&policy->byidx);
418421
rwlock_init(&policy->lock);
@@ -1230,6 +1233,9 @@ xfrm_policy_inexact_insert(struct xfrm_policy *policy, u8 dir, int excl)
12301233
return ERR_PTR(-EEXIST);
12311234
}
12321235

1236+
chain = &net->xfrm.policy_inexact[dir];
1237+
xfrm_policy_insert_inexact_list(chain, policy);
1238+
12331239
if (delpol)
12341240
__xfrm_policy_inexact_prune_bin(bin, false);
12351241

@@ -1337,6 +1343,7 @@ static void xfrm_hash_rebuild(struct work_struct *work)
13371343
continue;
13381344

13391345
hlist_del_rcu(&policy->bydst);
1346+
hlist_del_init(&policy->bydst_inexact_list);
13401347

13411348
newpos = NULL;
13421349
dir = xfrm_policy_id2dir(policy->index);
@@ -1506,6 +1513,36 @@ static const struct rhashtable_params xfrm_pol_inexact_params = {
15061513
.automatic_shrinking = true,
15071514
};
15081515

1516+
static void xfrm_policy_insert_inexact_list(struct hlist_head *chain,
1517+
struct xfrm_policy *policy)
1518+
{
1519+
struct xfrm_policy *pol, *delpol = NULL;
1520+
struct hlist_node *newpos = NULL;
1521+
1522+
hlist_for_each_entry(pol, chain, bydst_inexact_list) {
1523+
if (pol->type == policy->type &&
1524+
pol->if_id == policy->if_id &&
1525+
!selector_cmp(&pol->selector, &policy->selector) &&
1526+
xfrm_policy_mark_match(&policy->mark, pol) &&
1527+
xfrm_sec_ctx_match(pol->security, policy->security) &&
1528+
!WARN_ON(delpol)) {
1529+
delpol = pol;
1530+
if (policy->priority > pol->priority)
1531+
continue;
1532+
} else if (policy->priority >= pol->priority) {
1533+
newpos = &pol->bydst_inexact_list;
1534+
continue;
1535+
}
1536+
if (delpol)
1537+
break;
1538+
}
1539+
1540+
if (newpos && policy->xdo.type != XFRM_DEV_OFFLOAD_PACKET)
1541+
hlist_add_behind_rcu(&policy->bydst_inexact_list, newpos);
1542+
else
1543+
hlist_add_head_rcu(&policy->bydst_inexact_list, chain);
1544+
}
1545+
15091546
static struct xfrm_policy *xfrm_policy_insert_list(struct hlist_head *chain,
15101547
struct xfrm_policy *policy,
15111548
bool excl)
@@ -2307,6 +2344,7 @@ static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol,
23072344
/* Socket policies are not hashed. */
23082345
if (!hlist_unhashed(&pol->bydst)) {
23092346
hlist_del_rcu(&pol->bydst);
2347+
hlist_del_init(&pol->bydst_inexact_list);
23102348
hlist_del(&pol->byidx);
23112349
}
23122350

0 commit comments

Comments
 (0)