提交 77d8d7a6 编写于 作者: H Herbert Xu 提交者: David S. Miller

[IPSEC]: Document that policy direction is derived from the index.

Here is a patch that adds a helper called xfrm_policy_id2dir to
document the fact that the policy direction can be and is derived
from the index.

This is based on a patch by YOSHIFUJI Hideaki and 210313105@suda.edu.cn.
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 140e26fc
...@@ -931,4 +931,9 @@ static inline int xfrm_addr_cmp(xfrm_address_t *a, xfrm_address_t *b, ...@@ -931,4 +931,9 @@ static inline int xfrm_addr_cmp(xfrm_address_t *a, xfrm_address_t *b,
} }
} }
static inline int xfrm_policy_id2dir(u32 index)
{
return index & 7;
}
#endif /* _NET_XFRM_H */ #endif /* _NET_XFRM_H */
...@@ -2154,6 +2154,7 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, struct sadb ...@@ -2154,6 +2154,7 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, struct sadb
static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs)
{ {
unsigned int dir;
int err; int err;
struct sadb_x_policy *pol; struct sadb_x_policy *pol;
struct xfrm_policy *xp; struct xfrm_policy *xp;
...@@ -2162,7 +2163,11 @@ static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h ...@@ -2162,7 +2163,11 @@ static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
if ((pol = ext_hdrs[SADB_X_EXT_POLICY-1]) == NULL) if ((pol = ext_hdrs[SADB_X_EXT_POLICY-1]) == NULL)
return -EINVAL; return -EINVAL;
xp = xfrm_policy_byid(0, pol->sadb_x_policy_id, dir = xfrm_policy_id2dir(pol->sadb_x_policy_id);
if (dir >= XFRM_POLICY_MAX)
return -EINVAL;
xp = xfrm_policy_byid(dir, pol->sadb_x_policy_id,
hdr->sadb_msg_type == SADB_X_SPDDELETE2); hdr->sadb_msg_type == SADB_X_SPDDELETE2);
if (xp == NULL) if (xp == NULL)
return -ENOENT; return -ENOENT;
...@@ -2174,9 +2179,9 @@ static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h ...@@ -2174,9 +2179,9 @@ static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
if (hdr->sadb_msg_type == SADB_X_SPDDELETE2) { if (hdr->sadb_msg_type == SADB_X_SPDDELETE2) {
c.data.byid = 1; c.data.byid = 1;
c.event = XFRM_MSG_DELPOLICY; c.event = XFRM_MSG_DELPOLICY;
km_policy_notify(xp, pol->sadb_x_policy_dir-1, &c); km_policy_notify(xp, dir, &c);
} else { } else {
err = key_pol_get_resp(sk, xp, hdr, pol->sadb_x_policy_dir-1); err = key_pol_get_resp(sk, xp, hdr, dir);
} }
xfrm_pol_put(xp); xfrm_pol_put(xp);
......
...@@ -163,7 +163,7 @@ static void xfrm_policy_timer(unsigned long data) ...@@ -163,7 +163,7 @@ static void xfrm_policy_timer(unsigned long data)
if (xp->dead) if (xp->dead)
goto out; goto out;
dir = xp->index & 7; dir = xfrm_policy_id2dir(xp->index);
if (xp->lft.hard_add_expires_seconds) { if (xp->lft.hard_add_expires_seconds) {
long tmo = xp->lft.hard_add_expires_seconds + long tmo = xp->lft.hard_add_expires_seconds +
...@@ -417,7 +417,7 @@ struct xfrm_policy *xfrm_policy_byid(int dir, u32 id, int delete) ...@@ -417,7 +417,7 @@ struct xfrm_policy *xfrm_policy_byid(int dir, u32 id, int delete)
struct xfrm_policy *pol, **p; struct xfrm_policy *pol, **p;
write_lock_bh(&xfrm_policy_lock); write_lock_bh(&xfrm_policy_lock);
for (p = &xfrm_policy_list[id & 7]; (pol=*p)!=NULL; p = &pol->next) { for (p = &xfrm_policy_list[dir]; (pol=*p)!=NULL; p = &pol->next) {
if (pol->index == id) { if (pol->index == id) {
xfrm_pol_hold(pol); xfrm_pol_hold(pol);
if (delete) if (delete)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册