diff options
author | Thomas Graf <tgraf@suug.ch> | 2007-08-22 17:01:33 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:48:25 -0400 |
commit | 5424f32e484b9697808bbc0c0088dc2ead018d4f (patch) | |
tree | 91daf130e6816a7fc7bef89932e4df45fc26fec5 /net/xfrm/xfrm_user.c | |
parent | 35a7aa08bf7863dbfdb0eb69122d8aeaedd52748 (diff) |
[XFRM] netlink: Use nlattr instead of rtattr
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 | 157 |
1 files changed, 77 insertions, 80 deletions
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 7319c7f8060d..e46bcf02ac69 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c | |||
@@ -38,16 +38,16 @@ static inline int alg_len(struct xfrm_algo *alg) | |||
38 | return sizeof(*alg) + ((alg->alg_key_len + 7) / 8); | 38 | return sizeof(*alg) + ((alg->alg_key_len + 7) / 8); |
39 | } | 39 | } |
40 | 40 | ||
41 | static int verify_one_alg(struct rtattr **attrs, enum xfrm_attr_type_t type) | 41 | static int verify_one_alg(struct nlattr **attrs, enum xfrm_attr_type_t type) |
42 | { | 42 | { |
43 | struct rtattr *rt = attrs[type]; | 43 | struct nlattr *rt = attrs[type]; |
44 | struct xfrm_algo *algp; | 44 | struct xfrm_algo *algp; |
45 | 45 | ||
46 | if (!rt) | 46 | if (!rt) |
47 | return 0; | 47 | return 0; |
48 | 48 | ||
49 | algp = RTA_DATA(rt); | 49 | algp = nla_data(rt); |
50 | if (RTA_PAYLOAD(rt) < alg_len(algp)) | 50 | if (nla_len(rt) < alg_len(algp)) |
51 | return -EINVAL; | 51 | return -EINVAL; |
52 | 52 | ||
53 | switch (type) { | 53 | switch (type) { |
@@ -75,24 +75,24 @@ static int verify_one_alg(struct rtattr **attrs, enum xfrm_attr_type_t type) | |||
75 | return 0; | 75 | return 0; |
76 | } | 76 | } |
77 | 77 | ||
78 | static void verify_one_addr(struct rtattr **attrs, enum xfrm_attr_type_t type, | 78 | static void verify_one_addr(struct nlattr **attrs, enum xfrm_attr_type_t type, |
79 | xfrm_address_t **addrp) | 79 | xfrm_address_t **addrp) |
80 | { | 80 | { |
81 | struct rtattr *rt = attrs[type]; | 81 | struct nlattr *rt = attrs[type]; |
82 | 82 | ||
83 | if (rt && addrp) | 83 | if (rt && addrp) |
84 | *addrp = RTA_DATA(rt); | 84 | *addrp = nla_data(rt); |
85 | } | 85 | } |
86 | 86 | ||
87 | static inline int verify_sec_ctx_len(struct rtattr **attrs) | 87 | static inline int verify_sec_ctx_len(struct nlattr **attrs) |
88 | { | 88 | { |
89 | struct rtattr *rt = attrs[XFRMA_SEC_CTX]; | 89 | struct nlattr *rt = attrs[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) |
93 | return 0; | 93 | return 0; |
94 | 94 | ||
95 | uctx = RTA_DATA(rt); | 95 | uctx = nla_data(rt); |
96 | if (uctx->len != (sizeof(struct xfrm_user_sec_ctx) + uctx->ctx_len)) | 96 | if (uctx->len != (sizeof(struct xfrm_user_sec_ctx) + uctx->ctx_len)) |
97 | return -EINVAL; | 97 | return -EINVAL; |
98 | 98 | ||
@@ -101,7 +101,7 @@ static inline int verify_sec_ctx_len(struct rtattr **attrs) | |||
101 | 101 | ||
102 | 102 | ||
103 | static int verify_newsa_info(struct xfrm_usersa_info *p, | 103 | static int verify_newsa_info(struct xfrm_usersa_info *p, |
104 | struct rtattr **attrs) | 104 | struct nlattr **attrs) |
105 | { | 105 | { |
106 | int err; | 106 | int err; |
107 | 107 | ||
@@ -191,16 +191,15 @@ out: | |||
191 | 191 | ||
192 | static int attach_one_algo(struct xfrm_algo **algpp, u8 *props, | 192 | static int attach_one_algo(struct xfrm_algo **algpp, u8 *props, |
193 | struct xfrm_algo_desc *(*get_byname)(char *, int), | 193 | struct xfrm_algo_desc *(*get_byname)(char *, int), |
194 | struct rtattr *u_arg) | 194 | struct nlattr *rta) |
195 | { | 195 | { |
196 | struct rtattr *rta = u_arg; | ||
197 | struct xfrm_algo *p, *ualg; | 196 | struct xfrm_algo *p, *ualg; |
198 | struct xfrm_algo_desc *algo; | 197 | struct xfrm_algo_desc *algo; |
199 | 198 | ||
200 | if (!rta) | 199 | if (!rta) |
201 | return 0; | 200 | return 0; |
202 | 201 | ||
203 | ualg = RTA_DATA(rta); | 202 | ualg = nla_data(rta); |
204 | 203 | ||
205 | algo = get_byname(ualg->alg_name, 1); | 204 | algo = get_byname(ualg->alg_name, 1); |
206 | if (!algo) | 205 | if (!algo) |
@@ -216,15 +215,14 @@ static int attach_one_algo(struct xfrm_algo **algpp, u8 *props, | |||
216 | return 0; | 215 | return 0; |
217 | } | 216 | } |
218 | 217 | ||
219 | static int attach_encap_tmpl(struct xfrm_encap_tmpl **encapp, struct rtattr *u_arg) | 218 | static int attach_encap_tmpl(struct xfrm_encap_tmpl **encapp, struct nlattr *rta) |
220 | { | 219 | { |
221 | struct rtattr *rta = u_arg; | ||
222 | struct xfrm_encap_tmpl *p, *uencap; | 220 | struct xfrm_encap_tmpl *p, *uencap; |
223 | 221 | ||
224 | if (!rta) | 222 | if (!rta) |
225 | return 0; | 223 | return 0; |
226 | 224 | ||
227 | uencap = RTA_DATA(rta); | 225 | uencap = nla_data(rta); |
228 | p = kmemdup(uencap, sizeof(*p), GFP_KERNEL); | 226 | p = kmemdup(uencap, sizeof(*p), GFP_KERNEL); |
229 | if (!p) | 227 | if (!p) |
230 | return -ENOMEM; | 228 | return -ENOMEM; |
@@ -245,26 +243,25 @@ static inline int xfrm_user_sec_ctx_size(struct xfrm_sec_ctx *xfrm_ctx) | |||
245 | return len; | 243 | return len; |
246 | } | 244 | } |
247 | 245 | ||
248 | static int attach_sec_ctx(struct xfrm_state *x, struct rtattr *u_arg) | 246 | static int attach_sec_ctx(struct xfrm_state *x, struct nlattr *u_arg) |
249 | { | 247 | { |
250 | struct xfrm_user_sec_ctx *uctx; | 248 | struct xfrm_user_sec_ctx *uctx; |
251 | 249 | ||
252 | if (!u_arg) | 250 | if (!u_arg) |
253 | return 0; | 251 | return 0; |
254 | 252 | ||
255 | uctx = RTA_DATA(u_arg); | 253 | uctx = nla_data(u_arg); |
256 | return security_xfrm_state_alloc(x, uctx); | 254 | return security_xfrm_state_alloc(x, uctx); |
257 | } | 255 | } |
258 | 256 | ||
259 | static int attach_one_addr(xfrm_address_t **addrpp, struct rtattr *u_arg) | 257 | static int attach_one_addr(xfrm_address_t **addrpp, struct nlattr *rta) |
260 | { | 258 | { |
261 | struct rtattr *rta = u_arg; | ||
262 | xfrm_address_t *p, *uaddrp; | 259 | xfrm_address_t *p, *uaddrp; |
263 | 260 | ||
264 | if (!rta) | 261 | if (!rta) |
265 | return 0; | 262 | return 0; |
266 | 263 | ||
267 | uaddrp = RTA_DATA(rta); | 264 | uaddrp = nla_data(rta); |
268 | p = kmemdup(uaddrp, sizeof(*p), GFP_KERNEL); | 265 | p = kmemdup(uaddrp, sizeof(*p), GFP_KERNEL); |
269 | if (!p) | 266 | if (!p) |
270 | return -ENOMEM; | 267 | return -ENOMEM; |
@@ -298,23 +295,23 @@ static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info * | |||
298 | * somehow made shareable and move it to xfrm_state.c - JHS | 295 | * somehow made shareable and move it to xfrm_state.c - JHS |
299 | * | 296 | * |
300 | */ | 297 | */ |
301 | static void xfrm_update_ae_params(struct xfrm_state *x, struct rtattr **attrs) | 298 | static void xfrm_update_ae_params(struct xfrm_state *x, struct nlattr **attrs) |
302 | { | 299 | { |
303 | struct rtattr *rp = attrs[XFRMA_REPLAY_VAL]; | 300 | struct nlattr *rp = attrs[XFRMA_REPLAY_VAL]; |
304 | struct rtattr *lt = attrs[XFRMA_LTIME_VAL]; | 301 | struct nlattr *lt = attrs[XFRMA_LTIME_VAL]; |
305 | struct rtattr *et = attrs[XFRMA_ETIMER_THRESH]; | 302 | struct nlattr *et = attrs[XFRMA_ETIMER_THRESH]; |
306 | struct rtattr *rt = attrs[XFRMA_REPLAY_THRESH]; | 303 | struct nlattr *rt = attrs[XFRMA_REPLAY_THRESH]; |
307 | 304 | ||
308 | if (rp) { | 305 | if (rp) { |
309 | struct xfrm_replay_state *replay; | 306 | struct xfrm_replay_state *replay; |
310 | replay = RTA_DATA(rp); | 307 | replay = nla_data(rp); |
311 | memcpy(&x->replay, replay, sizeof(*replay)); | 308 | memcpy(&x->replay, replay, sizeof(*replay)); |
312 | memcpy(&x->preplay, replay, sizeof(*replay)); | 309 | memcpy(&x->preplay, replay, sizeof(*replay)); |
313 | } | 310 | } |
314 | 311 | ||
315 | if (lt) { | 312 | if (lt) { |
316 | struct xfrm_lifetime_cur *ltime; | 313 | struct xfrm_lifetime_cur *ltime; |
317 | ltime = RTA_DATA(lt); | 314 | ltime = nla_data(lt); |
318 | x->curlft.bytes = ltime->bytes; | 315 | x->curlft.bytes = ltime->bytes; |
319 | x->curlft.packets = ltime->packets; | 316 | x->curlft.packets = ltime->packets; |
320 | x->curlft.add_time = ltime->add_time; | 317 | x->curlft.add_time = ltime->add_time; |
@@ -322,14 +319,14 @@ static void xfrm_update_ae_params(struct xfrm_state *x, struct rtattr **attrs) | |||
322 | } | 319 | } |
323 | 320 | ||
324 | if (et) | 321 | if (et) |
325 | x->replay_maxage = *(u32*)RTA_DATA(et); | 322 | x->replay_maxage = nla_get_u32(et); |
326 | 323 | ||
327 | if (rt) | 324 | if (rt) |
328 | x->replay_maxdiff = *(u32*)RTA_DATA(rt); | 325 | x->replay_maxdiff = nla_get_u32(rt); |
329 | } | 326 | } |
330 | 327 | ||
331 | static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p, | 328 | static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p, |
332 | struct rtattr **attrs, | 329 | struct nlattr **attrs, |
333 | int *errp) | 330 | int *errp) |
334 | { | 331 | { |
335 | struct xfrm_state *x = xfrm_state_alloc(); | 332 | struct xfrm_state *x = xfrm_state_alloc(); |
@@ -373,7 +370,7 @@ static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p, | |||
373 | 370 | ||
374 | /* override default values from above */ | 371 | /* override default values from above */ |
375 | 372 | ||
376 | xfrm_update_ae_params(x, (struct rtattr **)attrs); | 373 | xfrm_update_ae_params(x, attrs); |
377 | 374 | ||
378 | return x; | 375 | return x; |
379 | 376 | ||
@@ -386,7 +383,7 @@ error_no_put: | |||
386 | } | 383 | } |
387 | 384 | ||
388 | static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh, | 385 | static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh, |
389 | struct rtattr **attrs) | 386 | struct nlattr **attrs) |
390 | { | 387 | { |
391 | struct xfrm_usersa_info *p = nlmsg_data(nlh); | 388 | struct xfrm_usersa_info *p = nlmsg_data(nlh); |
392 | struct xfrm_state *x; | 389 | struct xfrm_state *x; |
@@ -427,7 +424,7 @@ out: | |||
427 | } | 424 | } |
428 | 425 | ||
429 | static struct xfrm_state *xfrm_user_state_lookup(struct xfrm_usersa_id *p, | 426 | static struct xfrm_state *xfrm_user_state_lookup(struct xfrm_usersa_id *p, |
430 | struct rtattr **attrs, | 427 | struct nlattr **attrs, |
431 | int *errp) | 428 | int *errp) |
432 | { | 429 | { |
433 | struct xfrm_state *x = NULL; | 430 | struct xfrm_state *x = NULL; |
@@ -457,7 +454,7 @@ static struct xfrm_state *xfrm_user_state_lookup(struct xfrm_usersa_id *p, | |||
457 | } | 454 | } |
458 | 455 | ||
459 | static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh, | 456 | static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh, |
460 | struct rtattr **attrs) | 457 | struct nlattr **attrs) |
461 | { | 458 | { |
462 | struct xfrm_state *x; | 459 | struct xfrm_state *x; |
463 | int err = -ESRCH; | 460 | int err = -ESRCH; |
@@ -669,7 +666,7 @@ nla_put_failure: | |||
669 | } | 666 | } |
670 | 667 | ||
671 | static int xfrm_get_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh, | 668 | static int xfrm_get_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh, |
672 | struct rtattr **attrs) | 669 | struct nlattr **attrs) |
673 | { | 670 | { |
674 | struct sk_buff *r_skb; | 671 | struct sk_buff *r_skb; |
675 | u32 *flags = nlmsg_data(nlh); | 672 | u32 *flags = nlmsg_data(nlh); |
@@ -722,7 +719,7 @@ nla_put_failure: | |||
722 | } | 719 | } |
723 | 720 | ||
724 | static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh, | 721 | static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh, |
725 | struct rtattr **attrs) | 722 | struct nlattr **attrs) |
726 | { | 723 | { |
727 | struct sk_buff *r_skb; | 724 | struct sk_buff *r_skb; |
728 | u32 *flags = nlmsg_data(nlh); | 725 | u32 *flags = nlmsg_data(nlh); |
@@ -740,7 +737,7 @@ static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
740 | } | 737 | } |
741 | 738 | ||
742 | static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh, | 739 | static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh, |
743 | struct rtattr **attrs) | 740 | struct nlattr **attrs) |
744 | { | 741 | { |
745 | struct xfrm_usersa_id *p = nlmsg_data(nlh); | 742 | struct xfrm_usersa_id *p = nlmsg_data(nlh); |
746 | struct xfrm_state *x; | 743 | struct xfrm_state *x; |
@@ -786,7 +783,7 @@ static int verify_userspi_info(struct xfrm_userspi_info *p) | |||
786 | } | 783 | } |
787 | 784 | ||
788 | static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, | 785 | static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, |
789 | struct rtattr **attrs) | 786 | struct nlattr **attrs) |
790 | { | 787 | { |
791 | struct xfrm_state *x; | 788 | struct xfrm_state *x; |
792 | struct xfrm_userspi_info *p; | 789 | struct xfrm_userspi_info *p; |
@@ -915,15 +912,15 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p) | |||
915 | return verify_policy_dir(p->dir); | 912 | return verify_policy_dir(p->dir); |
916 | } | 913 | } |
917 | 914 | ||
918 | static int copy_from_user_sec_ctx(struct xfrm_policy *pol, struct rtattr **attrs) | 915 | static int copy_from_user_sec_ctx(struct xfrm_policy *pol, struct nlattr **attrs) |
919 | { | 916 | { |
920 | struct rtattr *rt = attrs[XFRMA_SEC_CTX]; | 917 | struct nlattr *rt = attrs[XFRMA_SEC_CTX]; |
921 | struct xfrm_user_sec_ctx *uctx; | 918 | struct xfrm_user_sec_ctx *uctx; |
922 | 919 | ||
923 | if (!rt) | 920 | if (!rt) |
924 | return 0; | 921 | return 0; |
925 | 922 | ||
926 | uctx = RTA_DATA(rt); | 923 | uctx = nla_data(rt); |
927 | return security_xfrm_policy_alloc(pol, uctx); | 924 | return security_xfrm_policy_alloc(pol, uctx); |
928 | } | 925 | } |
929 | 926 | ||
@@ -983,35 +980,35 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family) | |||
983 | return 0; | 980 | return 0; |
984 | } | 981 | } |
985 | 982 | ||
986 | static int copy_from_user_tmpl(struct xfrm_policy *pol, struct rtattr **attrs) | 983 | static int copy_from_user_tmpl(struct xfrm_policy *pol, struct nlattr **attrs) |
987 | { | 984 | { |
988 | struct rtattr *rt = attrs[XFRMA_TMPL]; | 985 | struct nlattr *rt = attrs[XFRMA_TMPL]; |
989 | 986 | ||
990 | if (!rt) { | 987 | if (!rt) { |
991 | pol->xfrm_nr = 0; | 988 | pol->xfrm_nr = 0; |
992 | } else { | 989 | } else { |
993 | struct xfrm_user_tmpl *utmpl = RTA_DATA(rt); | 990 | struct xfrm_user_tmpl *utmpl = nla_data(rt); |
994 | int nr = (rt->rta_len - sizeof(*rt)) / sizeof(*utmpl); | 991 | int nr = nla_len(rt) / sizeof(*utmpl); |
995 | int err; | 992 | int err; |
996 | 993 | ||
997 | err = validate_tmpl(nr, utmpl, pol->family); | 994 | err = validate_tmpl(nr, utmpl, pol->family); |
998 | if (err) | 995 | if (err) |
999 | return err; | 996 | return err; |
1000 | 997 | ||
1001 | copy_templates(pol, RTA_DATA(rt), nr); | 998 | copy_templates(pol, utmpl, nr); |
1002 | } | 999 | } |
1003 | return 0; | 1000 | return 0; |
1004 | } | 1001 | } |
1005 | 1002 | ||
1006 | static int copy_from_user_policy_type(u8 *tp, struct rtattr **attrs) | 1003 | static int copy_from_user_policy_type(u8 *tp, struct nlattr **attrs) |
1007 | { | 1004 | { |
1008 | struct rtattr *rt = attrs[XFRMA_POLICY_TYPE]; | 1005 | struct nlattr *rt = attrs[XFRMA_POLICY_TYPE]; |
1009 | struct xfrm_userpolicy_type *upt; | 1006 | struct xfrm_userpolicy_type *upt; |
1010 | u8 type = XFRM_POLICY_TYPE_MAIN; | 1007 | u8 type = XFRM_POLICY_TYPE_MAIN; |
1011 | int err; | 1008 | int err; |
1012 | 1009 | ||
1013 | if (rt) { | 1010 | if (rt) { |
1014 | upt = RTA_DATA(rt); | 1011 | upt = nla_data(rt); |
1015 | type = upt->type; | 1012 | type = upt->type; |
1016 | } | 1013 | } |
1017 | 1014 | ||
@@ -1049,7 +1046,7 @@ static void copy_to_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_i | |||
1049 | p->share = XFRM_SHARE_ANY; /* XXX xp->share */ | 1046 | p->share = XFRM_SHARE_ANY; /* XXX xp->share */ |
1050 | } | 1047 | } |
1051 | 1048 | ||
1052 | static struct xfrm_policy *xfrm_policy_construct(struct xfrm_userpolicy_info *p, struct rtattr **attrs, int *errp) | 1049 | static struct xfrm_policy *xfrm_policy_construct(struct xfrm_userpolicy_info *p, struct nlattr **attrs, int *errp) |
1053 | { | 1050 | { |
1054 | struct xfrm_policy *xp = xfrm_policy_alloc(GFP_KERNEL); | 1051 | struct xfrm_policy *xp = xfrm_policy_alloc(GFP_KERNEL); |
1055 | int err; | 1052 | int err; |
@@ -1078,7 +1075,7 @@ static struct xfrm_policy *xfrm_policy_construct(struct xfrm_userpolicy_info *p, | |||
1078 | } | 1075 | } |
1079 | 1076 | ||
1080 | static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh, | 1077 | static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh, |
1081 | struct rtattr **attrs) | 1078 | struct nlattr **attrs) |
1082 | { | 1079 | { |
1083 | struct xfrm_userpolicy_info *p = nlmsg_data(nlh); | 1080 | struct xfrm_userpolicy_info *p = nlmsg_data(nlh); |
1084 | struct xfrm_policy *xp; | 1081 | struct xfrm_policy *xp; |
@@ -1271,7 +1268,7 @@ static struct sk_buff *xfrm_policy_netlink(struct sk_buff *in_skb, | |||
1271 | } | 1268 | } |
1272 | 1269 | ||
1273 | static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh, | 1270 | static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh, |
1274 | struct rtattr **attrs) | 1271 | struct nlattr **attrs) |
1275 | { | 1272 | { |
1276 | struct xfrm_policy *xp; | 1273 | struct xfrm_policy *xp; |
1277 | struct xfrm_userpolicy_id *p; | 1274 | struct xfrm_userpolicy_id *p; |
@@ -1294,7 +1291,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1294 | if (p->index) | 1291 | if (p->index) |
1295 | xp = xfrm_policy_byid(type, p->dir, p->index, delete, &err); | 1292 | xp = xfrm_policy_byid(type, p->dir, p->index, delete, &err); |
1296 | else { | 1293 | else { |
1297 | struct rtattr *rt = attrs[XFRMA_SEC_CTX]; | 1294 | struct nlattr *rt = attrs[XFRMA_SEC_CTX]; |
1298 | struct xfrm_policy tmp; | 1295 | struct xfrm_policy tmp; |
1299 | 1296 | ||
1300 | err = verify_sec_ctx_len(attrs); | 1297 | err = verify_sec_ctx_len(attrs); |
@@ -1303,7 +1300,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1303 | 1300 | ||
1304 | memset(&tmp, 0, sizeof(struct xfrm_policy)); | 1301 | memset(&tmp, 0, sizeof(struct xfrm_policy)); |
1305 | if (rt) { | 1302 | if (rt) { |
1306 | struct xfrm_user_sec_ctx *uctx = RTA_DATA(rt); | 1303 | struct xfrm_user_sec_ctx *uctx = nla_data(rt); |
1307 | 1304 | ||
1308 | if ((err = security_xfrm_policy_alloc(&tmp, uctx))) | 1305 | if ((err = security_xfrm_policy_alloc(&tmp, uctx))) |
1309 | return err; | 1306 | return err; |
@@ -1345,7 +1342,7 @@ out: | |||
1345 | } | 1342 | } |
1346 | 1343 | ||
1347 | static int xfrm_flush_sa(struct sk_buff *skb, struct nlmsghdr *nlh, | 1344 | static int xfrm_flush_sa(struct sk_buff *skb, struct nlmsghdr *nlh, |
1348 | struct rtattr **attrs) | 1345 | struct nlattr **attrs) |
1349 | { | 1346 | { |
1350 | struct km_event c; | 1347 | struct km_event c; |
1351 | struct xfrm_usersa_flush *p = nlmsg_data(nlh); | 1348 | struct xfrm_usersa_flush *p = nlmsg_data(nlh); |
@@ -1411,7 +1408,7 @@ nla_put_failure: | |||
1411 | } | 1408 | } |
1412 | 1409 | ||
1413 | static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh, | 1410 | static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh, |
1414 | struct rtattr **attrs) | 1411 | struct nlattr **attrs) |
1415 | { | 1412 | { |
1416 | struct xfrm_state *x; | 1413 | struct xfrm_state *x; |
1417 | struct sk_buff *r_skb; | 1414 | struct sk_buff *r_skb; |
@@ -1449,14 +1446,14 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1449 | } | 1446 | } |
1450 | 1447 | ||
1451 | static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh, | 1448 | static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh, |
1452 | struct rtattr **attrs) | 1449 | struct nlattr **attrs) |
1453 | { | 1450 | { |
1454 | struct xfrm_state *x; | 1451 | struct xfrm_state *x; |
1455 | struct km_event c; | 1452 | struct km_event c; |
1456 | int err = - EINVAL; | 1453 | int err = - EINVAL; |
1457 | struct xfrm_aevent_id *p = nlmsg_data(nlh); | 1454 | struct xfrm_aevent_id *p = nlmsg_data(nlh); |
1458 | struct rtattr *rp = attrs[XFRMA_REPLAY_VAL]; | 1455 | struct nlattr *rp = attrs[XFRMA_REPLAY_VAL]; |
1459 | struct rtattr *lt = attrs[XFRMA_LTIME_VAL]; | 1456 | struct nlattr *lt = attrs[XFRMA_LTIME_VAL]; |
1460 | 1457 | ||
1461 | if (!lt && !rp) | 1458 | if (!lt && !rp) |
1462 | return err; | 1459 | return err; |
@@ -1488,7 +1485,7 @@ out: | |||
1488 | } | 1485 | } |
1489 | 1486 | ||
1490 | static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, | 1487 | static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, |
1491 | struct rtattr **attrs) | 1488 | struct nlattr **attrs) |
1492 | { | 1489 | { |
1493 | struct km_event c; | 1490 | struct km_event c; |
1494 | u8 type = XFRM_POLICY_TYPE_MAIN; | 1491 | u8 type = XFRM_POLICY_TYPE_MAIN; |
@@ -1513,7 +1510,7 @@ static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1513 | } | 1510 | } |
1514 | 1511 | ||
1515 | static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, | 1512 | static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, |
1516 | struct rtattr **attrs) | 1513 | struct nlattr **attrs) |
1517 | { | 1514 | { |
1518 | struct xfrm_policy *xp; | 1515 | struct xfrm_policy *xp; |
1519 | struct xfrm_user_polexpire *up = nlmsg_data(nlh); | 1516 | struct xfrm_user_polexpire *up = nlmsg_data(nlh); |
@@ -1528,7 +1525,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1528 | if (p->index) | 1525 | if (p->index) |
1529 | xp = xfrm_policy_byid(type, p->dir, p->index, 0, &err); | 1526 | xp = xfrm_policy_byid(type, p->dir, p->index, 0, &err); |
1530 | else { | 1527 | else { |
1531 | struct rtattr *rt = attrs[XFRMA_SEC_CTX]; | 1528 | struct nlattr *rt = attrs[XFRMA_SEC_CTX]; |
1532 | struct xfrm_policy tmp; | 1529 | struct xfrm_policy tmp; |
1533 | 1530 | ||
1534 | err = verify_sec_ctx_len(attrs); | 1531 | err = verify_sec_ctx_len(attrs); |
@@ -1537,7 +1534,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1537 | 1534 | ||
1538 | memset(&tmp, 0, sizeof(struct xfrm_policy)); | 1535 | memset(&tmp, 0, sizeof(struct xfrm_policy)); |
1539 | if (rt) { | 1536 | if (rt) { |
1540 | struct xfrm_user_sec_ctx *uctx = RTA_DATA(rt); | 1537 | struct xfrm_user_sec_ctx *uctx = nla_data(rt); |
1541 | 1538 | ||
1542 | if ((err = security_xfrm_policy_alloc(&tmp, uctx))) | 1539 | if ((err = security_xfrm_policy_alloc(&tmp, uctx))) |
1543 | return err; | 1540 | return err; |
@@ -1574,7 +1571,7 @@ out: | |||
1574 | } | 1571 | } |
1575 | 1572 | ||
1576 | static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh, | 1573 | static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh, |
1577 | struct rtattr **attrs) | 1574 | struct nlattr **attrs) |
1578 | { | 1575 | { |
1579 | struct xfrm_state *x; | 1576 | struct xfrm_state *x; |
1580 | int err; | 1577 | int err; |
@@ -1606,12 +1603,12 @@ out: | |||
1606 | } | 1603 | } |
1607 | 1604 | ||
1608 | static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, | 1605 | static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, |
1609 | struct rtattr **attrs) | 1606 | struct nlattr **attrs) |
1610 | { | 1607 | { |
1611 | struct xfrm_policy *xp; | 1608 | struct xfrm_policy *xp; |
1612 | struct xfrm_user_tmpl *ut; | 1609 | struct xfrm_user_tmpl *ut; |
1613 | int i; | 1610 | int i; |
1614 | struct rtattr *rt = attrs[XFRMA_TMPL]; | 1611 | struct nlattr *rt = attrs[XFRMA_TMPL]; |
1615 | 1612 | ||
1616 | struct xfrm_user_acquire *ua = nlmsg_data(nlh); | 1613 | struct xfrm_user_acquire *ua = nlmsg_data(nlh); |
1617 | struct xfrm_state *x = xfrm_state_alloc(); | 1614 | struct xfrm_state *x = xfrm_state_alloc(); |
@@ -1628,7 +1625,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1628 | } | 1625 | } |
1629 | 1626 | ||
1630 | /* build an XP */ | 1627 | /* build an XP */ |
1631 | xp = xfrm_policy_construct(&ua->policy, (struct rtattr **) attrs, &err); | 1628 | xp = xfrm_policy_construct(&ua->policy, attrs, &err); |
1632 | if (!xp) { | 1629 | if (!xp) { |
1633 | kfree(x); | 1630 | kfree(x); |
1634 | return err; | 1631 | return err; |
@@ -1638,7 +1635,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1638 | memcpy(&x->props.saddr, &ua->saddr, sizeof(ua->saddr)); | 1635 | memcpy(&x->props.saddr, &ua->saddr, sizeof(ua->saddr)); |
1639 | memcpy(&x->sel, &ua->sel, sizeof(ua->sel)); | 1636 | memcpy(&x->sel, &ua->sel, sizeof(ua->sel)); |
1640 | 1637 | ||
1641 | ut = RTA_DATA(rt); | 1638 | ut = nla_data(rt); |
1642 | /* extract the templates and for each call km_key */ | 1639 | /* extract the templates and for each call km_key */ |
1643 | for (i = 0; i < xp->xfrm_nr; i++, ut++) { | 1640 | for (i = 0; i < xp->xfrm_nr; i++, ut++) { |
1644 | struct xfrm_tmpl *t = &xp->xfrm_vec[i]; | 1641 | struct xfrm_tmpl *t = &xp->xfrm_vec[i]; |
@@ -1661,14 +1658,14 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1661 | 1658 | ||
1662 | #ifdef CONFIG_XFRM_MIGRATE | 1659 | #ifdef CONFIG_XFRM_MIGRATE |
1663 | static int copy_from_user_migrate(struct xfrm_migrate *ma, | 1660 | static int copy_from_user_migrate(struct xfrm_migrate *ma, |
1664 | struct rtattr **attrs, int *num) | 1661 | struct nlattr **attrs, int *num) |
1665 | { | 1662 | { |
1666 | struct rtattr *rt = attrs[XFRMA_MIGRATE]; | 1663 | struct nlattr *rt = attrs[XFRMA_MIGRATE]; |
1667 | struct xfrm_user_migrate *um; | 1664 | struct xfrm_user_migrate *um; |
1668 | int i, num_migrate; | 1665 | int i, num_migrate; |
1669 | 1666 | ||
1670 | um = RTA_DATA(rt); | 1667 | um = nla_data(rt); |
1671 | num_migrate = (rt->rta_len - sizeof(*rt)) / sizeof(*um); | 1668 | num_migrate = nla_len(rt) / sizeof(*um); |
1672 | 1669 | ||
1673 | if (num_migrate <= 0 || num_migrate > XFRM_MAX_DEPTH) | 1670 | if (num_migrate <= 0 || num_migrate > XFRM_MAX_DEPTH) |
1674 | return -EINVAL; | 1671 | return -EINVAL; |
@@ -1692,7 +1689,7 @@ static int copy_from_user_migrate(struct xfrm_migrate *ma, | |||
1692 | } | 1689 | } |
1693 | 1690 | ||
1694 | static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh, | 1691 | static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh, |
1695 | struct rtattr **attrs) | 1692 | struct nlattr **attrs) |
1696 | { | 1693 | { |
1697 | struct xfrm_userpolicy_id *pi = nlmsg_data(nlh); | 1694 | struct xfrm_userpolicy_id *pi = nlmsg_data(nlh); |
1698 | struct xfrm_migrate m[XFRM_MAX_DEPTH]; | 1695 | struct xfrm_migrate m[XFRM_MAX_DEPTH]; |
@@ -1703,12 +1700,12 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1703 | if (attrs[XFRMA_MIGRATE] == NULL) | 1700 | if (attrs[XFRMA_MIGRATE] == NULL) |
1704 | return -EINVAL; | 1701 | return -EINVAL; |
1705 | 1702 | ||
1706 | err = copy_from_user_policy_type(&type, (struct rtattr **)attrs); | 1703 | err = copy_from_user_policy_type(&type, attrs); |
1707 | if (err) | 1704 | if (err) |
1708 | return err; | 1705 | return err; |
1709 | 1706 | ||
1710 | err = copy_from_user_migrate((struct xfrm_migrate *)m, | 1707 | err = copy_from_user_migrate((struct xfrm_migrate *)m, |
1711 | (struct rtattr **)attrs, &n); | 1708 | attrs, &n); |
1712 | if (err) | 1709 | if (err) |
1713 | return err; | 1710 | return err; |
1714 | 1711 | ||
@@ -1721,7 +1718,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1721 | } | 1718 | } |
1722 | #else | 1719 | #else |
1723 | static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh, | 1720 | static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh, |
1724 | struct rtattr **attrs) | 1721 | struct nlattr **attrs) |
1725 | { | 1722 | { |
1726 | return -ENOPROTOOPT; | 1723 | return -ENOPROTOOPT; |
1727 | } | 1724 | } |
@@ -1854,7 +1851,7 @@ static const struct nla_policy xfrma_policy[XFRMA_MAX+1] = { | |||
1854 | }; | 1851 | }; |
1855 | 1852 | ||
1856 | static struct xfrm_link { | 1853 | static struct xfrm_link { |
1857 | int (*doit)(struct sk_buff *, struct nlmsghdr *, struct rtattr **); | 1854 | int (*doit)(struct sk_buff *, struct nlmsghdr *, struct nlattr **); |
1858 | int (*dump)(struct sk_buff *, struct netlink_callback *); | 1855 | int (*dump)(struct sk_buff *, struct netlink_callback *); |
1859 | } xfrm_dispatch[XFRM_NR_MSGTYPES] = { | 1856 | } xfrm_dispatch[XFRM_NR_MSGTYPES] = { |
1860 | [XFRM_MSG_NEWSA - XFRM_MSG_BASE] = { .doit = xfrm_add_sa }, | 1857 | [XFRM_MSG_NEWSA - XFRM_MSG_BASE] = { .doit = xfrm_add_sa }, |
@@ -1914,7 +1911,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
1914 | if (link->doit == NULL) | 1911 | if (link->doit == NULL) |
1915 | return -EINVAL; | 1912 | return -EINVAL; |
1916 | 1913 | ||
1917 | return link->doit(skb, nlh, (struct rtattr **) attrs); | 1914 | return link->doit(skb, nlh, attrs); |
1918 | } | 1915 | } |
1919 | 1916 | ||
1920 | static void xfrm_netlink_rcv(struct sock *sk, int len) | 1917 | static void xfrm_netlink_rcv(struct sock *sk, int len) |