diff options
author | Thomas Graf <tgraf@suug.ch> | 2007-08-22 16:56:23 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:48:21 -0400 |
commit | c26445acbc292ab0466407db6d3bdcc5cbe1d03b (patch) | |
tree | 15cc1f7b56929ffd269d5960d130e5c30c47277b /net/xfrm/xfrm_user.c | |
parent | c0144beaeca42b643f4d1632f2b24fdc6c48a170 (diff) |
[XFRM] netlink: Move algorithm length calculation to its own function
Adds alg_len() to calculate the properly padded length of an
algorithm attribute to simplify the code.
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/xfrm/xfrm_user.c')
-rw-r--r-- | net/xfrm/xfrm_user.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 24a97b1179f..30e47c678d5 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c | |||
@@ -33,6 +33,11 @@ | |||
33 | #endif | 33 | #endif |
34 | #include <linux/audit.h> | 34 | #include <linux/audit.h> |
35 | 35 | ||
36 | static inline int alg_len(struct xfrm_algo *alg) | ||
37 | { | ||
38 | return sizeof(*alg) + ((alg->alg_key_len + 7) / 8); | ||
39 | } | ||
40 | |||
36 | static int verify_one_alg(struct rtattr **xfrma, enum xfrm_attr_type_t type) | 41 | static int verify_one_alg(struct rtattr **xfrma, enum xfrm_attr_type_t type) |
37 | { | 42 | { |
38 | struct rtattr *rt = xfrma[type - 1]; | 43 | struct rtattr *rt = xfrma[type - 1]; |
@@ -232,7 +237,6 @@ static int attach_one_algo(struct xfrm_algo **algpp, u8 *props, | |||
232 | struct rtattr *rta = u_arg; | 237 | struct rtattr *rta = u_arg; |
233 | struct xfrm_algo *p, *ualg; | 238 | struct xfrm_algo *p, *ualg; |
234 | struct xfrm_algo_desc *algo; | 239 | struct xfrm_algo_desc *algo; |
235 | int len; | ||
236 | 240 | ||
237 | if (!rta) | 241 | if (!rta) |
238 | return 0; | 242 | return 0; |
@@ -244,8 +248,7 @@ static int attach_one_algo(struct xfrm_algo **algpp, u8 *props, | |||
244 | return -ENOSYS; | 248 | return -ENOSYS; |
245 | *props = algo->desc.sadb_alg_id; | 249 | *props = algo->desc.sadb_alg_id; |
246 | 250 | ||
247 | len = sizeof(*ualg) + (ualg->alg_key_len + 7U) / 8; | 251 | p = kmemdup(ualg, alg_len(ualg), GFP_KERNEL); |
248 | p = kmemdup(ualg, len, GFP_KERNEL); | ||
249 | if (!p) | 252 | if (!p) |
250 | return -ENOMEM; | 253 | return -ENOMEM; |
251 | 254 | ||
@@ -617,11 +620,9 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr) | |||
617 | copy_to_user_state(x, p); | 620 | copy_to_user_state(x, p); |
618 | 621 | ||
619 | if (x->aalg) | 622 | if (x->aalg) |
620 | NLA_PUT(skb, XFRMA_ALG_AUTH, | 623 | NLA_PUT(skb, XFRMA_ALG_AUTH, alg_len(x->aalg), x->aalg); |
621 | sizeof(*(x->aalg))+(x->aalg->alg_key_len+7)/8, x->aalg); | ||
622 | if (x->ealg) | 624 | if (x->ealg) |
623 | NLA_PUT(skb, XFRMA_ALG_CRYPT, | 625 | NLA_PUT(skb, XFRMA_ALG_CRYPT, alg_len(x->ealg), x->ealg); |
624 | sizeof(*(x->ealg))+(x->ealg->alg_key_len+7)/8, x->ealg); | ||
625 | if (x->calg) | 626 | if (x->calg) |
626 | NLA_PUT(skb, XFRMA_ALG_COMP, sizeof(*(x->calg)), x->calg); | 627 | NLA_PUT(skb, XFRMA_ALG_COMP, sizeof(*(x->calg)), x->calg); |
627 | 628 | ||
@@ -2072,9 +2073,9 @@ static inline int xfrm_sa_len(struct xfrm_state *x) | |||
2072 | { | 2073 | { |
2073 | int l = 0; | 2074 | int l = 0; |
2074 | if (x->aalg) | 2075 | if (x->aalg) |
2075 | l += RTA_SPACE(sizeof(*x->aalg) + (x->aalg->alg_key_len+7)/8); | 2076 | l += RTA_SPACE(alg_len(x->aalg)); |
2076 | if (x->ealg) | 2077 | if (x->ealg) |
2077 | l += RTA_SPACE(sizeof(*x->ealg) + (x->ealg->alg_key_len+7)/8); | 2078 | l += RTA_SPACE(alg_len(x->ealg)); |
2078 | if (x->calg) | 2079 | if (x->calg) |
2079 | l += RTA_SPACE(sizeof(*x->calg)); | 2080 | l += RTA_SPACE(sizeof(*x->calg)); |
2080 | if (x->encap) | 2081 | if (x->encap) |
@@ -2127,11 +2128,9 @@ static int xfrm_notify_sa(struct xfrm_state *x, struct km_event *c) | |||
2127 | copy_to_user_state(x, p); | 2128 | copy_to_user_state(x, p); |
2128 | 2129 | ||
2129 | if (x->aalg) | 2130 | if (x->aalg) |
2130 | NLA_PUT(skb, XFRMA_ALG_AUTH, | 2131 | NLA_PUT(skb, XFRMA_ALG_AUTH, alg_len(x->aalg), x->aalg); |
2131 | sizeof(*(x->aalg))+(x->aalg->alg_key_len+7)/8, x->aalg); | ||
2132 | if (x->ealg) | 2132 | if (x->ealg) |
2133 | NLA_PUT(skb, XFRMA_ALG_CRYPT, | 2133 | NLA_PUT(skb, XFRMA_ALG_CRYPT, alg_len(x->ealg), x->ealg); |
2134 | sizeof(*(x->ealg))+(x->ealg->alg_key_len+7)/8, x->ealg); | ||
2135 | if (x->calg) | 2134 | if (x->calg) |
2136 | NLA_PUT(skb, XFRMA_ALG_COMP, sizeof(*(x->calg)), x->calg); | 2135 | NLA_PUT(skb, XFRMA_ALG_COMP, sizeof(*(x->calg)), x->calg); |
2137 | 2136 | ||