diff options
author | Thomas Graf <tgraf@suug.ch> | 2007-08-22 16:59:43 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:48:23 -0400 |
commit | fab448991df4ecca6c244e23982c70f7e715b864 (patch) | |
tree | f4f0dd583f2934da4bb4b1621dfebb03c9d6a5ba /net/xfrm | |
parent | cf5cb79f6946063b04be3df16dcaa781e48bdbef (diff) |
[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: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/xfrm')
-rw-r--r-- | net/xfrm/xfrm_user.c | 80 |
1 files changed, 39 insertions, 41 deletions
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 1371a0ae0606..8c323b187e6a 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c | |||
@@ -40,7 +40,7 @@ static inline int alg_len(struct xfrm_algo *alg) | |||
40 | 40 | ||
41 | 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) |
42 | { | 42 | { |
43 | struct rtattr *rt = xfrma[type - 1]; | 43 | struct rtattr *rt = xfrma[type]; |
44 | struct xfrm_algo *algp; | 44 | struct xfrm_algo *algp; |
45 | 45 | ||
46 | if (!rt) | 46 | if (!rt) |
@@ -78,7 +78,7 @@ static int verify_one_alg(struct rtattr **xfrma, enum xfrm_attr_type_t type) | |||
78 | static void verify_one_addr(struct rtattr **xfrma, enum xfrm_attr_type_t type, | 78 | static void verify_one_addr(struct rtattr **xfrma, enum xfrm_attr_type_t type, |
79 | xfrm_address_t **addrp) | 79 | xfrm_address_t **addrp) |
80 | { | 80 | { |
81 | struct rtattr *rt = xfrma[type - 1]; | 81 | struct rtattr *rt = xfrma[type]; |
82 | 82 | ||
83 | if (rt && addrp) | 83 | if (rt && addrp) |
84 | *addrp = RTA_DATA(rt); | 84 | *addrp = RTA_DATA(rt); |
@@ -86,7 +86,7 @@ static void verify_one_addr(struct rtattr **xfrma, enum xfrm_attr_type_t type, | |||
86 | 86 | ||
87 | static inline int verify_sec_ctx_len(struct rtattr **xfrma) | 87 | static inline int verify_sec_ctx_len(struct rtattr **xfrma) |
88 | { | 88 | { |
89 | struct rtattr *rt = xfrma[XFRMA_SEC_CTX - 1]; | 89 | struct rtattr *rt = xfrma[XFRMA_SEC_CTX]; |
90 | struct xfrm_user_sec_ctx *uctx; | 90 | struct xfrm_user_sec_ctx *uctx; |
91 | 91 | ||
92 | if (!rt) | 92 | if (!rt) |
@@ -125,35 +125,35 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, | |||
125 | err = -EINVAL; | 125 | err = -EINVAL; |
126 | switch (p->id.proto) { | 126 | switch (p->id.proto) { |
127 | case IPPROTO_AH: | 127 | case IPPROTO_AH: |
128 | if (!xfrma[XFRMA_ALG_AUTH-1] || | 128 | if (!xfrma[XFRMA_ALG_AUTH] || |
129 | xfrma[XFRMA_ALG_CRYPT-1] || | 129 | xfrma[XFRMA_ALG_CRYPT] || |
130 | xfrma[XFRMA_ALG_COMP-1]) | 130 | xfrma[XFRMA_ALG_COMP]) |
131 | goto out; | 131 | goto out; |
132 | break; | 132 | break; |
133 | 133 | ||
134 | case IPPROTO_ESP: | 134 | case IPPROTO_ESP: |
135 | if ((!xfrma[XFRMA_ALG_AUTH-1] && | 135 | if ((!xfrma[XFRMA_ALG_AUTH] && |
136 | !xfrma[XFRMA_ALG_CRYPT-1]) || | 136 | !xfrma[XFRMA_ALG_CRYPT]) || |
137 | xfrma[XFRMA_ALG_COMP-1]) | 137 | xfrma[XFRMA_ALG_COMP]) |
138 | goto out; | 138 | goto out; |
139 | break; | 139 | break; |
140 | 140 | ||
141 | case IPPROTO_COMP: | 141 | case IPPROTO_COMP: |
142 | if (!xfrma[XFRMA_ALG_COMP-1] || | 142 | if (!xfrma[XFRMA_ALG_COMP] || |
143 | xfrma[XFRMA_ALG_AUTH-1] || | 143 | xfrma[XFRMA_ALG_AUTH] || |
144 | xfrma[XFRMA_ALG_CRYPT-1]) | 144 | xfrma[XFRMA_ALG_CRYPT]) |
145 | goto out; | 145 | goto out; |
146 | break; | 146 | break; |
147 | 147 | ||
148 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | 148 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
149 | case IPPROTO_DSTOPTS: | 149 | case IPPROTO_DSTOPTS: |
150 | case IPPROTO_ROUTING: | 150 | case IPPROTO_ROUTING: |
151 | if (xfrma[XFRMA_ALG_COMP-1] || | 151 | if (xfrma[XFRMA_ALG_COMP] || |
152 | xfrma[XFRMA_ALG_AUTH-1] || | 152 | xfrma[XFRMA_ALG_AUTH] || |
153 | xfrma[XFRMA_ALG_CRYPT-1] || | 153 | xfrma[XFRMA_ALG_CRYPT] || |
154 | xfrma[XFRMA_ENCAP-1] || | 154 | xfrma[XFRMA_ENCAP] || |
155 | xfrma[XFRMA_SEC_CTX-1] || | 155 | xfrma[XFRMA_SEC_CTX] || |
156 | !xfrma[XFRMA_COADDR-1]) | 156 | !xfrma[XFRMA_COADDR]) |
157 | goto out; | 157 | goto out; |
158 | break; | 158 | break; |
159 | #endif | 159 | #endif |
@@ -300,10 +300,10 @@ static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info * | |||
300 | */ | 300 | */ |
301 | static void xfrm_update_ae_params(struct xfrm_state *x, struct rtattr **xfrma) | 301 | static void xfrm_update_ae_params(struct xfrm_state *x, struct rtattr **xfrma) |
302 | { | 302 | { |
303 | struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL-1]; | 303 | struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL]; |
304 | struct rtattr *lt = xfrma[XFRMA_LTIME_VAL-1]; | 304 | struct rtattr *lt = xfrma[XFRMA_LTIME_VAL]; |
305 | struct rtattr *et = xfrma[XFRMA_ETIMER_THRESH-1]; | 305 | struct rtattr *et = xfrma[XFRMA_ETIMER_THRESH]; |
306 | struct rtattr *rt = xfrma[XFRMA_REPLAY_THRESH-1]; | 306 | struct rtattr *rt = xfrma[XFRMA_REPLAY_THRESH]; |
307 | 307 | ||
308 | if (rp) { | 308 | if (rp) { |
309 | struct xfrm_replay_state *replay; | 309 | struct xfrm_replay_state *replay; |
@@ -342,25 +342,25 @@ static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p, | |||
342 | 342 | ||
343 | if ((err = attach_one_algo(&x->aalg, &x->props.aalgo, | 343 | if ((err = attach_one_algo(&x->aalg, &x->props.aalgo, |
344 | xfrm_aalg_get_byname, | 344 | xfrm_aalg_get_byname, |
345 | xfrma[XFRMA_ALG_AUTH-1]))) | 345 | xfrma[XFRMA_ALG_AUTH]))) |
346 | goto error; | 346 | goto error; |
347 | if ((err = attach_one_algo(&x->ealg, &x->props.ealgo, | 347 | if ((err = attach_one_algo(&x->ealg, &x->props.ealgo, |
348 | xfrm_ealg_get_byname, | 348 | xfrm_ealg_get_byname, |
349 | xfrma[XFRMA_ALG_CRYPT-1]))) | 349 | xfrma[XFRMA_ALG_CRYPT]))) |
350 | goto error; | 350 | goto error; |
351 | if ((err = attach_one_algo(&x->calg, &x->props.calgo, | 351 | if ((err = attach_one_algo(&x->calg, &x->props.calgo, |
352 | xfrm_calg_get_byname, | 352 | xfrm_calg_get_byname, |
353 | xfrma[XFRMA_ALG_COMP-1]))) | 353 | xfrma[XFRMA_ALG_COMP]))) |
354 | goto error; | 354 | goto error; |
355 | if ((err = attach_encap_tmpl(&x->encap, xfrma[XFRMA_ENCAP-1]))) | 355 | if ((err = attach_encap_tmpl(&x->encap, xfrma[XFRMA_ENCAP]))) |
356 | goto error; | 356 | goto error; |
357 | if ((err = attach_one_addr(&x->coaddr, xfrma[XFRMA_COADDR-1]))) | 357 | if ((err = attach_one_addr(&x->coaddr, xfrma[XFRMA_COADDR]))) |
358 | goto error; | 358 | goto error; |
359 | err = xfrm_init_state(x); | 359 | err = xfrm_init_state(x); |
360 | if (err) | 360 | if (err) |
361 | goto error; | 361 | goto error; |
362 | 362 | ||
363 | if ((err = attach_sec_ctx(x, xfrma[XFRMA_SEC_CTX-1]))) | 363 | if ((err = attach_sec_ctx(x, xfrma[XFRMA_SEC_CTX]))) |
364 | goto error; | 364 | goto error; |
365 | 365 | ||
366 | x->km.seq = p->seq; | 366 | x->km.seq = p->seq; |
@@ -917,7 +917,7 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p) | |||
917 | 917 | ||
918 | static int copy_from_user_sec_ctx(struct xfrm_policy *pol, struct rtattr **xfrma) | 918 | static int copy_from_user_sec_ctx(struct xfrm_policy *pol, struct rtattr **xfrma) |
919 | { | 919 | { |
920 | struct rtattr *rt = xfrma[XFRMA_SEC_CTX-1]; | 920 | struct rtattr *rt = xfrma[XFRMA_SEC_CTX]; |
921 | struct xfrm_user_sec_ctx *uctx; | 921 | struct xfrm_user_sec_ctx *uctx; |
922 | 922 | ||
923 | if (!rt) | 923 | if (!rt) |
@@ -985,7 +985,7 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family) | |||
985 | 985 | ||
986 | static int copy_from_user_tmpl(struct xfrm_policy *pol, struct rtattr **xfrma) | 986 | static int copy_from_user_tmpl(struct xfrm_policy *pol, struct rtattr **xfrma) |
987 | { | 987 | { |
988 | struct rtattr *rt = xfrma[XFRMA_TMPL-1]; | 988 | struct rtattr *rt = xfrma[XFRMA_TMPL]; |
989 | 989 | ||
990 | if (!rt) { | 990 | if (!rt) { |
991 | pol->xfrm_nr = 0; | 991 | pol->xfrm_nr = 0; |
@@ -1005,7 +1005,7 @@ static int copy_from_user_tmpl(struct xfrm_policy *pol, struct rtattr **xfrma) | |||
1005 | 1005 | ||
1006 | static int copy_from_user_policy_type(u8 *tp, struct rtattr **xfrma) | 1006 | static int copy_from_user_policy_type(u8 *tp, struct rtattr **xfrma) |
1007 | { | 1007 | { |
1008 | struct rtattr *rt = xfrma[XFRMA_POLICY_TYPE-1]; | 1008 | struct rtattr *rt = xfrma[XFRMA_POLICY_TYPE]; |
1009 | struct xfrm_userpolicy_type *upt; | 1009 | struct xfrm_userpolicy_type *upt; |
1010 | u8 type = XFRM_POLICY_TYPE_MAIN; | 1010 | u8 type = XFRM_POLICY_TYPE_MAIN; |
1011 | int err; | 1011 | int err; |
@@ -1294,7 +1294,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1294 | if (p->index) | 1294 | if (p->index) |
1295 | xp = xfrm_policy_byid(type, p->dir, p->index, delete, &err); | 1295 | xp = xfrm_policy_byid(type, p->dir, p->index, delete, &err); |
1296 | else { | 1296 | else { |
1297 | struct rtattr *rt = xfrma[XFRMA_SEC_CTX-1]; | 1297 | struct rtattr *rt = xfrma[XFRMA_SEC_CTX]; |
1298 | struct xfrm_policy tmp; | 1298 | struct xfrm_policy tmp; |
1299 | 1299 | ||
1300 | err = verify_sec_ctx_len(xfrma); | 1300 | err = verify_sec_ctx_len(xfrma); |
@@ -1455,8 +1455,8 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1455 | struct km_event c; | 1455 | struct km_event c; |
1456 | int err = - EINVAL; | 1456 | int err = - EINVAL; |
1457 | struct xfrm_aevent_id *p = nlmsg_data(nlh); | 1457 | struct xfrm_aevent_id *p = nlmsg_data(nlh); |
1458 | struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL-1]; | 1458 | struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL]; |
1459 | struct rtattr *lt = xfrma[XFRMA_LTIME_VAL-1]; | 1459 | struct rtattr *lt = xfrma[XFRMA_LTIME_VAL]; |
1460 | 1460 | ||
1461 | if (!lt && !rp) | 1461 | if (!lt && !rp) |
1462 | return err; | 1462 | return err; |
@@ -1528,7 +1528,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1528 | if (p->index) | 1528 | if (p->index) |
1529 | xp = xfrm_policy_byid(type, p->dir, p->index, 0, &err); | 1529 | xp = xfrm_policy_byid(type, p->dir, p->index, 0, &err); |
1530 | else { | 1530 | else { |
1531 | struct rtattr *rt = xfrma[XFRMA_SEC_CTX-1]; | 1531 | struct rtattr *rt = xfrma[XFRMA_SEC_CTX]; |
1532 | struct xfrm_policy tmp; | 1532 | struct xfrm_policy tmp; |
1533 | 1533 | ||
1534 | err = verify_sec_ctx_len(xfrma); | 1534 | err = verify_sec_ctx_len(xfrma); |
@@ -1611,7 +1611,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1611 | struct xfrm_policy *xp; | 1611 | struct xfrm_policy *xp; |
1612 | struct xfrm_user_tmpl *ut; | 1612 | struct xfrm_user_tmpl *ut; |
1613 | int i; | 1613 | int i; |
1614 | struct rtattr *rt = xfrma[XFRMA_TMPL-1]; | 1614 | struct rtattr *rt = xfrma[XFRMA_TMPL]; |
1615 | 1615 | ||
1616 | struct xfrm_user_acquire *ua = nlmsg_data(nlh); | 1616 | struct xfrm_user_acquire *ua = nlmsg_data(nlh); |
1617 | struct xfrm_state *x = xfrm_state_alloc(); | 1617 | struct xfrm_state *x = xfrm_state_alloc(); |
@@ -1663,7 +1663,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1663 | static int copy_from_user_migrate(struct xfrm_migrate *ma, | 1663 | static int copy_from_user_migrate(struct xfrm_migrate *ma, |
1664 | struct rtattr **xfrma, int *num) | 1664 | struct rtattr **xfrma, int *num) |
1665 | { | 1665 | { |
1666 | struct rtattr *rt = xfrma[XFRMA_MIGRATE-1]; | 1666 | struct rtattr *rt = xfrma[XFRMA_MIGRATE]; |
1667 | struct xfrm_user_migrate *um; | 1667 | struct xfrm_user_migrate *um; |
1668 | int i, num_migrate; | 1668 | int i, num_migrate; |
1669 | 1669 | ||
@@ -1700,7 +1700,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1700 | int err; | 1700 | int err; |
1701 | int n = 0; | 1701 | int n = 0; |
1702 | 1702 | ||
1703 | if (xfrma[XFRMA_MIGRATE-1] == NULL) | 1703 | if (xfrma[XFRMA_MIGRATE] == NULL) |
1704 | return -EINVAL; | 1704 | return -EINVAL; |
1705 | 1705 | ||
1706 | err = copy_from_user_policy_type(&type, (struct rtattr **)xfrma); | 1706 | 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 | return netlink_dump_start(xfrm_nl, skb, nlh, link->dump, NULL); | 1906 | return netlink_dump_start(xfrm_nl, skb, nlh, link->dump, NULL); |
1907 | } | 1907 | } |
1908 | 1908 | ||
1909 | /* FIXME: Temporary hack, nlmsg_parse() starts at xfrma[1], old code | 1909 | err = nlmsg_parse(nlh, xfrm_msg_min[type], xfrma, XFRMA_MAX, |
1910 | * expects first attribute at xfrma[0] */ | ||
1911 | err = nlmsg_parse(nlh, xfrm_msg_min[type], xfrma-1, XFRMA_MAX, | ||
1912 | xfrma_policy); | 1910 | xfrma_policy); |
1913 | if (err < 0) | 1911 | if (err < 0) |
1914 | return err; | 1912 | return err; |