aboutsummaryrefslogtreecommitdiffstats
path: root/net/xfrm
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2007-08-22 15:46:53 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:48:18 -0400
commit79b8b7f4ab686e0f14ceb9a6fa4437eb1e73a0e5 (patch)
tree5fd922b7eaff7c0e071c14c9f1ca96ee3d6fc800 /net/xfrm
parent6168b96c07d8d40f83622cfb488ca27e4178a603 (diff)
[XFRM] netlink: Use nlmsg_put() instead of NLMSG_PUT()
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.c83
1 files changed, 40 insertions, 43 deletions
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 61339e17a0f5..ec480b69510b 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -588,10 +588,10 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr)
588 if (sp->this_idx < sp->start_idx) 588 if (sp->this_idx < sp->start_idx)
589 goto out; 589 goto out;
590 590
591 nlh = NLMSG_PUT(skb, NETLINK_CB(in_skb).pid, 591 nlh = nlmsg_put(skb, NETLINK_CB(in_skb).pid, sp->nlmsg_seq,
592 sp->nlmsg_seq, 592 XFRM_MSG_NEWSA, sizeof(*p), sp->nlmsg_flags);
593 XFRM_MSG_NEWSA, sizeof(*p)); 593 if (nlh == NULL)
594 nlh->nlmsg_flags = sp->nlmsg_flags; 594 return -EMSGSIZE;
595 595
596 p = NLMSG_DATA(nlh); 596 p = NLMSG_DATA(nlh);
597 copy_to_user_state(x, p); 597 copy_to_user_state(x, p);
@@ -633,7 +633,6 @@ out:
633 sp->this_idx++; 633 sp->this_idx++;
634 return 0; 634 return 0;
635 635
636nlmsg_failure:
637rtattr_failure: 636rtattr_failure:
638 nlmsg_trim(skb, b); 637 nlmsg_trim(skb, b);
639 return -1; 638 return -1;
@@ -1276,11 +1275,11 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr
1276 if (sp->this_idx < sp->start_idx) 1275 if (sp->this_idx < sp->start_idx)
1277 goto out; 1276 goto out;
1278 1277
1279 nlh = NLMSG_PUT(skb, NETLINK_CB(in_skb).pid, 1278 nlh = nlmsg_put(skb, NETLINK_CB(in_skb).pid, sp->nlmsg_seq,
1280 sp->nlmsg_seq, 1279 XFRM_MSG_NEWPOLICY, sizeof(*p), sp->nlmsg_flags);
1281 XFRM_MSG_NEWPOLICY, sizeof(*p)); 1280 if (nlh == NULL)
1281 return -EMSGSIZE;
1282 p = NLMSG_DATA(nlh); 1282 p = NLMSG_DATA(nlh);
1283 nlh->nlmsg_flags = sp->nlmsg_flags;
1284 1283
1285 copy_to_user_policy(xp, p, dir); 1284 copy_to_user_policy(xp, p, dir);
1286 if (copy_to_user_tmpl(xp, skb) < 0) 1285 if (copy_to_user_tmpl(xp, skb) < 0)
@@ -1449,9 +1448,10 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
1449 struct xfrm_lifetime_cur ltime; 1448 struct xfrm_lifetime_cur ltime;
1450 unsigned char *b = skb_tail_pointer(skb); 1449 unsigned char *b = skb_tail_pointer(skb);
1451 1450
1452 nlh = NLMSG_PUT(skb, c->pid, c->seq, XFRM_MSG_NEWAE, sizeof(*id)); 1451 nlh = nlmsg_put(skb, c->pid, c->seq, XFRM_MSG_NEWAE, sizeof(*id), 0);
1452 if (nlh == NULL)
1453 return -EMSGSIZE;
1453 id = NLMSG_DATA(nlh); 1454 id = NLMSG_DATA(nlh);
1454 nlh->nlmsg_flags = 0;
1455 1455
1456 memcpy(&id->sa_id.daddr, &x->id.daddr,sizeof(x->id.daddr)); 1456 memcpy(&id->sa_id.daddr, &x->id.daddr,sizeof(x->id.daddr));
1457 id->sa_id.spi = x->id.spi; 1457 id->sa_id.spi = x->id.spi;
@@ -1483,7 +1483,6 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
1483 return skb->len; 1483 return skb->len;
1484 1484
1485rtattr_failure: 1485rtattr_failure:
1486nlmsg_failure:
1487 nlmsg_trim(skb, b); 1486 nlmsg_trim(skb, b);
1488 return -1; 1487 return -1;
1489} 1488}
@@ -1866,9 +1865,10 @@ static int build_migrate(struct sk_buff *skb, struct xfrm_migrate *m,
1866 unsigned char *b = skb_tail_pointer(skb); 1865 unsigned char *b = skb_tail_pointer(skb);
1867 int i; 1866 int i;
1868 1867
1869 nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_MIGRATE, sizeof(*pol_id)); 1868 nlh = nlmsg_put(skb, 0, 0, XFRM_MSG_MIGRATE, sizeof(*pol_id), 0);
1869 if (nlh == NULL)
1870 return -EMSGSIZE;
1870 pol_id = NLMSG_DATA(nlh); 1871 pol_id = NLMSG_DATA(nlh);
1871 nlh->nlmsg_flags = 0;
1872 1872
1873 /* copy data from selector, dir, and type to the pol_id */ 1873 /* copy data from selector, dir, and type to the pol_id */
1874 memset(pol_id, 0, sizeof(*pol_id)); 1874 memset(pol_id, 0, sizeof(*pol_id));
@@ -2045,20 +2045,16 @@ static int build_expire(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
2045 struct nlmsghdr *nlh; 2045 struct nlmsghdr *nlh;
2046 unsigned char *b = skb_tail_pointer(skb); 2046 unsigned char *b = skb_tail_pointer(skb);
2047 2047
2048 nlh = NLMSG_PUT(skb, c->pid, 0, XFRM_MSG_EXPIRE, 2048 nlh = nlmsg_put(skb, c->pid, 0, XFRM_MSG_EXPIRE, sizeof(*ue), 0);
2049 sizeof(*ue)); 2049 if (nlh == NULL)
2050 return -EMSGSIZE;
2050 ue = NLMSG_DATA(nlh); 2051 ue = NLMSG_DATA(nlh);
2051 nlh->nlmsg_flags = 0;
2052 2052
2053 copy_to_user_state(x, &ue->state); 2053 copy_to_user_state(x, &ue->state);
2054 ue->hard = (c->data.hard != 0) ? 1 : 0; 2054 ue->hard = (c->data.hard != 0) ? 1 : 0;
2055 2055
2056 nlh->nlmsg_len = skb_tail_pointer(skb) - b; 2056 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
2057 return skb->len; 2057 return skb->len;
2058
2059nlmsg_failure:
2060 nlmsg_trim(skb, b);
2061 return -1;
2062} 2058}
2063 2059
2064static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c) 2060static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c)
@@ -2108,9 +2104,11 @@ static int xfrm_notify_sa_flush(struct km_event *c)
2108 return -ENOMEM; 2104 return -ENOMEM;
2109 b = skb->tail; 2105 b = skb->tail;
2110 2106
2111 nlh = NLMSG_PUT(skb, c->pid, c->seq, 2107 nlh = nlmsg_put(skb, c->pid, c->seq, XFRM_MSG_FLUSHSA, sizeof(*p), 0);
2112 XFRM_MSG_FLUSHSA, sizeof(*p)); 2108 if (nlh == NULL) {
2113 nlh->nlmsg_flags = 0; 2109 kfree_skb(skb);
2110 return -EMSGSIZE;
2111 }
2114 2112
2115 p = NLMSG_DATA(nlh); 2113 p = NLMSG_DATA(nlh);
2116 p->proto = c->data.proto; 2114 p->proto = c->data.proto;
@@ -2119,10 +2117,6 @@ static int xfrm_notify_sa_flush(struct km_event *c)
2119 2117
2120 NETLINK_CB(skb).dst_group = XFRMNLGRP_SA; 2118 NETLINK_CB(skb).dst_group = XFRMNLGRP_SA;
2121 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_SA, GFP_ATOMIC); 2119 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_SA, GFP_ATOMIC);
2122
2123nlmsg_failure:
2124 kfree_skb(skb);
2125 return -1;
2126} 2120}
2127 2121
2128static inline int xfrm_sa_len(struct xfrm_state *x) 2122static inline int xfrm_sa_len(struct xfrm_state *x)
@@ -2162,8 +2156,9 @@ static int xfrm_notify_sa(struct xfrm_state *x, struct km_event *c)
2162 return -ENOMEM; 2156 return -ENOMEM;
2163 b = skb->tail; 2157 b = skb->tail;
2164 2158
2165 nlh = NLMSG_PUT(skb, c->pid, c->seq, c->event, headlen); 2159 nlh = nlmsg_put(skb, c->pid, c->seq, c->event, headlen, 0);
2166 nlh->nlmsg_flags = 0; 2160 if (nlh == NULL)
2161 goto nlmsg_failure;
2167 2162
2168 p = NLMSG_DATA(nlh); 2163 p = NLMSG_DATA(nlh);
2169 if (c->event == XFRM_MSG_DELSA) { 2164 if (c->event == XFRM_MSG_DELSA) {
@@ -2233,10 +2228,10 @@ static int build_acquire(struct sk_buff *skb, struct xfrm_state *x,
2233 unsigned char *b = skb_tail_pointer(skb); 2228 unsigned char *b = skb_tail_pointer(skb);
2234 __u32 seq = xfrm_get_acqseq(); 2229 __u32 seq = xfrm_get_acqseq();
2235 2230
2236 nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_ACQUIRE, 2231 nlh = nlmsg_put(skb, 0, 0, XFRM_MSG_ACQUIRE, sizeof(*ua), 0);
2237 sizeof(*ua)); 2232 if (nlh == NULL)
2233 return -EMSGSIZE;
2238 ua = NLMSG_DATA(nlh); 2234 ua = NLMSG_DATA(nlh);
2239 nlh->nlmsg_flags = 0;
2240 2235
2241 memcpy(&ua->id, &x->id, sizeof(ua->id)); 2236 memcpy(&ua->id, &x->id, sizeof(ua->id));
2242 memcpy(&ua->saddr, &x->props.saddr, sizeof(ua->saddr)); 2237 memcpy(&ua->saddr, &x->props.saddr, sizeof(ua->saddr));
@@ -2352,9 +2347,10 @@ static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp,
2352 int hard = c->data.hard; 2347 int hard = c->data.hard;
2353 unsigned char *b = skb_tail_pointer(skb); 2348 unsigned char *b = skb_tail_pointer(skb);
2354 2349
2355 nlh = NLMSG_PUT(skb, c->pid, 0, XFRM_MSG_POLEXPIRE, sizeof(*upe)); 2350 nlh = nlmsg_put(skb, c->pid, 0, XFRM_MSG_POLEXPIRE, sizeof(*upe), 0);
2351 if (nlh == NULL)
2352 return -EMSGSIZE;
2356 upe = NLMSG_DATA(nlh); 2353 upe = NLMSG_DATA(nlh);
2357 nlh->nlmsg_flags = 0;
2358 2354
2359 copy_to_user_policy(xp, &upe->pol, dir); 2355 copy_to_user_policy(xp, &upe->pol, dir);
2360 if (copy_to_user_tmpl(xp, skb) < 0) 2356 if (copy_to_user_tmpl(xp, skb) < 0)
@@ -2420,7 +2416,9 @@ static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *
2420 return -ENOMEM; 2416 return -ENOMEM;
2421 b = skb->tail; 2417 b = skb->tail;
2422 2418
2423 nlh = NLMSG_PUT(skb, c->pid, c->seq, c->event, headlen); 2419 nlh = nlmsg_put(skb, c->pid, c->seq, c->event, headlen, 0);
2420 if (nlh == NULL)
2421 goto nlmsg_failure;
2424 2422
2425 p = NLMSG_DATA(nlh); 2423 p = NLMSG_DATA(nlh);
2426 if (c->event == XFRM_MSG_DELPOLICY) { 2424 if (c->event == XFRM_MSG_DELPOLICY) {
@@ -2435,8 +2433,6 @@ static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *
2435 p = RTA_DATA(__RTA_PUT(skb, XFRMA_POLICY, sizeof(*p))); 2433 p = RTA_DATA(__RTA_PUT(skb, XFRMA_POLICY, sizeof(*p)));
2436 } 2434 }
2437 2435
2438 nlh->nlmsg_flags = 0;
2439
2440 copy_to_user_policy(xp, p, dir); 2436 copy_to_user_policy(xp, p, dir);
2441 if (copy_to_user_tmpl(xp, skb) < 0) 2437 if (copy_to_user_tmpl(xp, skb) < 0)
2442 goto nlmsg_failure; 2438 goto nlmsg_failure;
@@ -2471,8 +2467,9 @@ static int xfrm_notify_policy_flush(struct km_event *c)
2471 b = skb->tail; 2467 b = skb->tail;
2472 2468
2473 2469
2474 nlh = NLMSG_PUT(skb, c->pid, c->seq, XFRM_MSG_FLUSHPOLICY, 0); 2470 nlh = nlmsg_put(skb, c->pid, c->seq, XFRM_MSG_FLUSHPOLICY, 0, 0);
2475 nlh->nlmsg_flags = 0; 2471 if (nlh == NULL)
2472 goto nlmsg_failure;
2476 if (copy_to_user_policy_type(c->data.type, skb) < 0) 2473 if (copy_to_user_policy_type(c->data.type, skb) < 0)
2477 goto nlmsg_failure; 2474 goto nlmsg_failure;
2478 2475
@@ -2513,9 +2510,10 @@ static int build_report(struct sk_buff *skb, u8 proto,
2513 struct nlmsghdr *nlh; 2510 struct nlmsghdr *nlh;
2514 unsigned char *b = skb_tail_pointer(skb); 2511 unsigned char *b = skb_tail_pointer(skb);
2515 2512
2516 nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_REPORT, sizeof(*ur)); 2513 nlh = nlmsg_put(skb, 0, 0, XFRM_MSG_REPORT, sizeof(*ur), 0);
2514 if (nlh == NULL)
2515 return -EMSGSIZE;
2517 ur = NLMSG_DATA(nlh); 2516 ur = NLMSG_DATA(nlh);
2518 nlh->nlmsg_flags = 0;
2519 2517
2520 ur->proto = proto; 2518 ur->proto = proto;
2521 memcpy(&ur->sel, sel, sizeof(ur->sel)); 2519 memcpy(&ur->sel, sel, sizeof(ur->sel));
@@ -2526,7 +2524,6 @@ static int build_report(struct sk_buff *skb, u8 proto,
2526 nlh->nlmsg_len = skb_tail_pointer(skb) - b; 2524 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
2527 return skb->len; 2525 return skb->len;
2528 2526
2529nlmsg_failure:
2530rtattr_failure: 2527rtattr_failure:
2531 nlmsg_trim(skb, b); 2528 nlmsg_trim(skb, b);
2532 return -1; 2529 return -1;