Commit fab44899 authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

[XFRM] netlink: Enhance indexing of the attribute array

nlmsg_parse() puts attributes at array[type] so the indexing
method can be simpilfied by removing the obscuring "- 1".
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cf5cb79f
...@@ -40,7 +40,7 @@ static inline int alg_len(struct xfrm_algo *alg) ...@@ -40,7 +40,7 @@ static inline int alg_len(struct xfrm_algo *alg)
static int verify_one_alg(struct rtattr **xfrma, enum xfrm_attr_type_t type) static int verify_one_alg(struct rtattr **xfrma, enum xfrm_attr_type_t type)
{ {
struct rtattr *rt = xfrma[type - 1]; struct rtattr *rt = xfrma[type];
struct xfrm_algo *algp; struct xfrm_algo *algp;
if (!rt) if (!rt)
...@@ -78,7 +78,7 @@ static int verify_one_alg(struct rtattr **xfrma, enum xfrm_attr_type_t type) ...@@ -78,7 +78,7 @@ static int verify_one_alg(struct rtattr **xfrma, enum xfrm_attr_type_t type)
static void verify_one_addr(struct rtattr **xfrma, enum xfrm_attr_type_t type, static void verify_one_addr(struct rtattr **xfrma, enum xfrm_attr_type_t type,
xfrm_address_t **addrp) xfrm_address_t **addrp)
{ {
struct rtattr *rt = xfrma[type - 1]; struct rtattr *rt = xfrma[type];
if (rt && addrp) if (rt && addrp)
*addrp = RTA_DATA(rt); *addrp = RTA_DATA(rt);
...@@ -86,7 +86,7 @@ static void verify_one_addr(struct rtattr **xfrma, enum xfrm_attr_type_t type, ...@@ -86,7 +86,7 @@ static void verify_one_addr(struct rtattr **xfrma, enum xfrm_attr_type_t type,
static inline int verify_sec_ctx_len(struct rtattr **xfrma) static inline int verify_sec_ctx_len(struct rtattr **xfrma)
{ {
struct rtattr *rt = xfrma[XFRMA_SEC_CTX - 1]; struct rtattr *rt = xfrma[XFRMA_SEC_CTX];
struct xfrm_user_sec_ctx *uctx; struct xfrm_user_sec_ctx *uctx;
if (!rt) if (!rt)
...@@ -125,35 +125,35 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, ...@@ -125,35 +125,35 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
err = -EINVAL; err = -EINVAL;
switch (p->id.proto) { switch (p->id.proto) {
case IPPROTO_AH: case IPPROTO_AH:
if (!xfrma[XFRMA_ALG_AUTH-1] || if (!xfrma[XFRMA_ALG_AUTH] ||
xfrma[XFRMA_ALG_CRYPT-1] || xfrma[XFRMA_ALG_CRYPT] ||
xfrma[XFRMA_ALG_COMP-1]) xfrma[XFRMA_ALG_COMP])
goto out; goto out;
break; break;
case IPPROTO_ESP: case IPPROTO_ESP:
if ((!xfrma[XFRMA_ALG_AUTH-1] && if ((!xfrma[XFRMA_ALG_AUTH] &&
!xfrma[XFRMA_ALG_CRYPT-1]) || !xfrma[XFRMA_ALG_CRYPT]) ||
xfrma[XFRMA_ALG_COMP-1]) xfrma[XFRMA_ALG_COMP])
goto out; goto out;
break; break;
case IPPROTO_COMP: case IPPROTO_COMP:
if (!xfrma[XFRMA_ALG_COMP-1] || if (!xfrma[XFRMA_ALG_COMP] ||
xfrma[XFRMA_ALG_AUTH-1] || xfrma[XFRMA_ALG_AUTH] ||
xfrma[XFRMA_ALG_CRYPT-1]) xfrma[XFRMA_ALG_CRYPT])
goto out; goto out;
break; break;
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
case IPPROTO_DSTOPTS: case IPPROTO_DSTOPTS:
case IPPROTO_ROUTING: case IPPROTO_ROUTING:
if (xfrma[XFRMA_ALG_COMP-1] || if (xfrma[XFRMA_ALG_COMP] ||
xfrma[XFRMA_ALG_AUTH-1] || xfrma[XFRMA_ALG_AUTH] ||
xfrma[XFRMA_ALG_CRYPT-1] || xfrma[XFRMA_ALG_CRYPT] ||
xfrma[XFRMA_ENCAP-1] || xfrma[XFRMA_ENCAP] ||
xfrma[XFRMA_SEC_CTX-1] || xfrma[XFRMA_SEC_CTX] ||
!xfrma[XFRMA_COADDR-1]) !xfrma[XFRMA_COADDR])
goto out; goto out;
break; break;
#endif #endif
...@@ -300,10 +300,10 @@ static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info * ...@@ -300,10 +300,10 @@ static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info *
*/ */
static void xfrm_update_ae_params(struct xfrm_state *x, struct rtattr **xfrma) static void xfrm_update_ae_params(struct xfrm_state *x, struct rtattr **xfrma)
{ {
struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL-1]; struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL];
struct rtattr *lt = xfrma[XFRMA_LTIME_VAL-1]; struct rtattr *lt = xfrma[XFRMA_LTIME_VAL];
struct rtattr *et = xfrma[XFRMA_ETIMER_THRESH-1]; struct rtattr *et = xfrma[XFRMA_ETIMER_THRESH];
struct rtattr *rt = xfrma[XFRMA_REPLAY_THRESH-1]; struct rtattr *rt = xfrma[XFRMA_REPLAY_THRESH];
if (rp) { if (rp) {
struct xfrm_replay_state *replay; struct xfrm_replay_state *replay;
...@@ -342,25 +342,25 @@ static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p, ...@@ -342,25 +342,25 @@ static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p,
if ((err = attach_one_algo(&x->aalg, &x->props.aalgo, if ((err = attach_one_algo(&x->aalg, &x->props.aalgo,
xfrm_aalg_get_byname, xfrm_aalg_get_byname,
xfrma[XFRMA_ALG_AUTH-1]))) xfrma[XFRMA_ALG_AUTH])))
goto error; goto error;
if ((err = attach_one_algo(&x->ealg, &x->props.ealgo, if ((err = attach_one_algo(&x->ealg, &x->props.ealgo,
xfrm_ealg_get_byname, xfrm_ealg_get_byname,
xfrma[XFRMA_ALG_CRYPT-1]))) xfrma[XFRMA_ALG_CRYPT])))
goto error; goto error;
if ((err = attach_one_algo(&x->calg, &x->props.calgo, if ((err = attach_one_algo(&x->calg, &x->props.calgo,
xfrm_calg_get_byname, xfrm_calg_get_byname,
xfrma[XFRMA_ALG_COMP-1]))) xfrma[XFRMA_ALG_COMP])))
goto error; goto error;
if ((err = attach_encap_tmpl(&x->encap, xfrma[XFRMA_ENCAP-1]))) if ((err = attach_encap_tmpl(&x->encap, xfrma[XFRMA_ENCAP])))
goto error; goto error;
if ((err = attach_one_addr(&x->coaddr, xfrma[XFRMA_COADDR-1]))) if ((err = attach_one_addr(&x->coaddr, xfrma[XFRMA_COADDR])))
goto error; goto error;
err = xfrm_init_state(x); err = xfrm_init_state(x);
if (err) if (err)
goto error; goto error;
if ((err = attach_sec_ctx(x, xfrma[XFRMA_SEC_CTX-1]))) if ((err = attach_sec_ctx(x, xfrma[XFRMA_SEC_CTX])))
goto error; goto error;
x->km.seq = p->seq; x->km.seq = p->seq;
...@@ -917,7 +917,7 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p) ...@@ -917,7 +917,7 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)
static int copy_from_user_sec_ctx(struct xfrm_policy *pol, struct rtattr **xfrma) static int copy_from_user_sec_ctx(struct xfrm_policy *pol, struct rtattr **xfrma)
{ {
struct rtattr *rt = xfrma[XFRMA_SEC_CTX-1]; struct rtattr *rt = xfrma[XFRMA_SEC_CTX];
struct xfrm_user_sec_ctx *uctx; struct xfrm_user_sec_ctx *uctx;
if (!rt) if (!rt)
...@@ -985,7 +985,7 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family) ...@@ -985,7 +985,7 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)
static int copy_from_user_tmpl(struct xfrm_policy *pol, struct rtattr **xfrma) static int copy_from_user_tmpl(struct xfrm_policy *pol, struct rtattr **xfrma)
{ {
struct rtattr *rt = xfrma[XFRMA_TMPL-1]; struct rtattr *rt = xfrma[XFRMA_TMPL];
if (!rt) { if (!rt) {
pol->xfrm_nr = 0; pol->xfrm_nr = 0;
...@@ -1005,7 +1005,7 @@ static int copy_from_user_tmpl(struct xfrm_policy *pol, struct rtattr **xfrma) ...@@ -1005,7 +1005,7 @@ static int copy_from_user_tmpl(struct xfrm_policy *pol, struct rtattr **xfrma)
static int copy_from_user_policy_type(u8 *tp, struct rtattr **xfrma) static int copy_from_user_policy_type(u8 *tp, struct rtattr **xfrma)
{ {
struct rtattr *rt = xfrma[XFRMA_POLICY_TYPE-1]; struct rtattr *rt = xfrma[XFRMA_POLICY_TYPE];
struct xfrm_userpolicy_type *upt; struct xfrm_userpolicy_type *upt;
u8 type = XFRM_POLICY_TYPE_MAIN; u8 type = XFRM_POLICY_TYPE_MAIN;
int err; int err;
...@@ -1294,7 +1294,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1294,7 +1294,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
if (p->index) if (p->index)
xp = xfrm_policy_byid(type, p->dir, p->index, delete, &err); xp = xfrm_policy_byid(type, p->dir, p->index, delete, &err);
else { else {
struct rtattr *rt = xfrma[XFRMA_SEC_CTX-1]; struct rtattr *rt = xfrma[XFRMA_SEC_CTX];
struct xfrm_policy tmp; struct xfrm_policy tmp;
err = verify_sec_ctx_len(xfrma); err = verify_sec_ctx_len(xfrma);
...@@ -1455,8 +1455,8 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1455,8 +1455,8 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
struct km_event c; struct km_event c;
int err = - EINVAL; int err = - EINVAL;
struct xfrm_aevent_id *p = nlmsg_data(nlh); struct xfrm_aevent_id *p = nlmsg_data(nlh);
struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL-1]; struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL];
struct rtattr *lt = xfrma[XFRMA_LTIME_VAL-1]; struct rtattr *lt = xfrma[XFRMA_LTIME_VAL];
if (!lt && !rp) if (!lt && !rp)
return err; return err;
...@@ -1528,7 +1528,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1528,7 +1528,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
if (p->index) if (p->index)
xp = xfrm_policy_byid(type, p->dir, p->index, 0, &err); xp = xfrm_policy_byid(type, p->dir, p->index, 0, &err);
else { else {
struct rtattr *rt = xfrma[XFRMA_SEC_CTX-1]; struct rtattr *rt = xfrma[XFRMA_SEC_CTX];
struct xfrm_policy tmp; struct xfrm_policy tmp;
err = verify_sec_ctx_len(xfrma); err = verify_sec_ctx_len(xfrma);
...@@ -1611,7 +1611,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1611,7 +1611,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,
struct xfrm_policy *xp; struct xfrm_policy *xp;
struct xfrm_user_tmpl *ut; struct xfrm_user_tmpl *ut;
int i; int i;
struct rtattr *rt = xfrma[XFRMA_TMPL-1]; struct rtattr *rt = xfrma[XFRMA_TMPL];
struct xfrm_user_acquire *ua = nlmsg_data(nlh); struct xfrm_user_acquire *ua = nlmsg_data(nlh);
struct xfrm_state *x = xfrm_state_alloc(); struct xfrm_state *x = xfrm_state_alloc();
...@@ -1663,7 +1663,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1663,7 +1663,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,
static int copy_from_user_migrate(struct xfrm_migrate *ma, static int copy_from_user_migrate(struct xfrm_migrate *ma,
struct rtattr **xfrma, int *num) struct rtattr **xfrma, int *num)
{ {
struct rtattr *rt = xfrma[XFRMA_MIGRATE-1]; struct rtattr *rt = xfrma[XFRMA_MIGRATE];
struct xfrm_user_migrate *um; struct xfrm_user_migrate *um;
int i, num_migrate; int i, num_migrate;
...@@ -1700,7 +1700,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1700,7 +1700,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
int err; int err;
int n = 0; int n = 0;
if (xfrma[XFRMA_MIGRATE-1] == NULL) if (xfrma[XFRMA_MIGRATE] == NULL)
return -EINVAL; return -EINVAL;
err = copy_from_user_policy_type(&type, (struct rtattr **)xfrma); err = copy_from_user_policy_type(&type, (struct rtattr **)xfrma);
...@@ -1906,9 +1906,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -1906,9 +1906,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
return netlink_dump_start(xfrm_nl, skb, nlh, link->dump, NULL); return netlink_dump_start(xfrm_nl, skb, nlh, link->dump, NULL);
} }
/* FIXME: Temporary hack, nlmsg_parse() starts at xfrma[1], old code err = nlmsg_parse(nlh, xfrm_msg_min[type], xfrma, XFRMA_MAX,
* expects first attribute at xfrma[0] */
err = nlmsg_parse(nlh, xfrm_msg_min[type], xfrma-1, XFRMA_MAX,
xfrma_policy); xfrma_policy);
if (err < 0) if (err < 0)
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment