aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2012-06-26 19:36:15 -0400
committerDavid S. Miller <davem@davemloft.net>2012-06-27 18:36:44 -0400
commit6b60978fde2b09a15d7aec0e15f2d3863bad2d24 (patch)
tree6c974a67e0ec978f58f8bcaea138cd24f15f716f
parent74a0bd7d0ef4ed11345aaebc29bf4578ccf44087 (diff)
decnet: Do not use RTA_PUT() macros
Also, no need to trim on nlmsg_put() failure, nothing has been added yet. We also want to use nlmsg_end(), nlmsg_new() and nlmsg_free(). Signed-off-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/decnet/dn_route.c61
-rw-r--r--net/decnet/dn_table.c69
2 files changed, 79 insertions, 51 deletions
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index cd584f7de4dd..2493ed5bfecd 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -1515,56 +1515,68 @@ static int dn_rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1515 struct dn_route *rt = (struct dn_route *)skb_dst(skb); 1515 struct dn_route *rt = (struct dn_route *)skb_dst(skb);
1516 struct rtmsg *r; 1516 struct rtmsg *r;
1517 struct nlmsghdr *nlh; 1517 struct nlmsghdr *nlh;
1518 unsigned char *b = skb_tail_pointer(skb);
1519 long expires; 1518 long expires;
1520 1519
1521 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*r), flags); 1520 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*r), flags);
1522 if (!nlh) 1521 if (!nlh)
1523 goto out_nlmsg_trim; 1522 return -EMSGSIZE;
1523
1524 r = nlmsg_data(nlh); 1524 r = nlmsg_data(nlh);
1525 r->rtm_family = AF_DECnet; 1525 r->rtm_family = AF_DECnet;
1526 r->rtm_dst_len = 16; 1526 r->rtm_dst_len = 16;
1527 r->rtm_src_len = 0; 1527 r->rtm_src_len = 0;
1528 r->rtm_tos = 0; 1528 r->rtm_tos = 0;
1529 r->rtm_table = RT_TABLE_MAIN; 1529 r->rtm_table = RT_TABLE_MAIN;
1530 RTA_PUT_U32(skb, RTA_TABLE, RT_TABLE_MAIN);
1531 r->rtm_type = rt->rt_type; 1530 r->rtm_type = rt->rt_type;
1532 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED; 1531 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
1533 r->rtm_scope = RT_SCOPE_UNIVERSE; 1532 r->rtm_scope = RT_SCOPE_UNIVERSE;
1534 r->rtm_protocol = RTPROT_UNSPEC; 1533 r->rtm_protocol = RTPROT_UNSPEC;
1534
1535 if (rt->rt_flags & RTCF_NOTIFY) 1535 if (rt->rt_flags & RTCF_NOTIFY)
1536 r->rtm_flags |= RTM_F_NOTIFY; 1536 r->rtm_flags |= RTM_F_NOTIFY;
1537 RTA_PUT(skb, RTA_DST, 2, &rt->rt_daddr); 1537
1538 if (nla_put_u32(skb, RTA_TABLE, RT_TABLE_MAIN) < 0 ||
1539 nla_put_le16(skb, RTA_DST, rt->rt_daddr) < 0)
1540 goto errout;
1541
1538 if (rt->fld.saddr) { 1542 if (rt->fld.saddr) {
1539 r->rtm_src_len = 16; 1543 r->rtm_src_len = 16;
1540 RTA_PUT(skb, RTA_SRC, 2, &rt->fld.saddr); 1544 if (nla_put_le16(skb, RTA_SRC, rt->fld.saddr) < 0)
1545 goto errout;
1541 } 1546 }
1542 if (rt->dst.dev) 1547 if (rt->dst.dev &&
1543 RTA_PUT(skb, RTA_OIF, sizeof(int), &rt->dst.dev->ifindex); 1548 nla_put_u32(skb, RTA_OIF, rt->dst.dev->ifindex) < 0)
1549 goto errout;
1550
1544 /* 1551 /*
1545 * Note to self - change this if input routes reverse direction when 1552 * Note to self - change this if input routes reverse direction when
1546 * they deal only with inputs and not with replies like they do 1553 * they deal only with inputs and not with replies like they do
1547 * currently. 1554 * currently.
1548 */ 1555 */
1549 RTA_PUT(skb, RTA_PREFSRC, 2, &rt->rt_local_src); 1556 if (nla_put_le16(skb, RTA_PREFSRC, rt->rt_local_src) < 0)
1550 if (rt->rt_daddr != rt->rt_gateway) 1557 goto errout;
1551 RTA_PUT(skb, RTA_GATEWAY, 2, &rt->rt_gateway); 1558
1559 if (rt->rt_daddr != rt->rt_gateway &&
1560 nla_put_le16(skb, RTA_GATEWAY, rt->rt_gateway) < 0)
1561 goto errout;
1562
1552 if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0) 1563 if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0)
1553 goto rtattr_failure; 1564 goto errout;
1565
1554 expires = rt->dst.expires ? rt->dst.expires - jiffies : 0; 1566 expires = rt->dst.expires ? rt->dst.expires - jiffies : 0;
1555 if (rtnl_put_cacheinfo(skb, &rt->dst, 0, 0, 0, expires, 1567 if (rtnl_put_cacheinfo(skb, &rt->dst, 0, 0, 0, expires,
1556 rt->dst.error) < 0) 1568 rt->dst.error) < 0)
1557 goto rtattr_failure; 1569 goto errout;
1558 if (dn_is_input_route(rt))
1559 RTA_PUT(skb, RTA_IIF, sizeof(int), &rt->fld.flowidn_iif);
1560 1570
1561 nlh->nlmsg_len = skb_tail_pointer(skb) - b; 1571 if (dn_is_input_route(rt) &&
1562 return skb->len; 1572 nla_put_u32(skb, RTA_IIF, rt->fld.flowidn_iif) < 0)
1573 goto errout;
1563 1574
1564out_nlmsg_trim: 1575 return nlmsg_end(skb, nlh);
1565rtattr_failure: 1576
1566 nlmsg_trim(skb, b); 1577errout:
1567 return -1; 1578 nlmsg_cancel(skb, nlh);
1579 return -EMSGSIZE;
1568} 1580}
1569 1581
1570/* 1582/*
@@ -1587,7 +1599,7 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void
1587 memset(&fld, 0, sizeof(fld)); 1599 memset(&fld, 0, sizeof(fld));
1588 fld.flowidn_proto = DNPROTO_NSP; 1600 fld.flowidn_proto = DNPROTO_NSP;
1589 1601
1590 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); 1602 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1591 if (skb == NULL) 1603 if (skb == NULL)
1592 return -ENOBUFS; 1604 return -ENOBUFS;
1593 skb_reset_mac_header(skb); 1605 skb_reset_mac_header(skb);
@@ -1665,13 +1677,16 @@ int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
1665 struct dn_route *rt; 1677 struct dn_route *rt;
1666 int h, s_h; 1678 int h, s_h;
1667 int idx, s_idx; 1679 int idx, s_idx;
1680 struct rtmsg *rtm;
1668 1681
1669 if (!net_eq(net, &init_net)) 1682 if (!net_eq(net, &init_net))
1670 return 0; 1683 return 0;
1671 1684
1672 if (NLMSG_PAYLOAD(cb->nlh, 0) < sizeof(struct rtmsg)) 1685 if (nlmsg_len(cb->nlh) < sizeof(struct rtmsg))
1673 return -EINVAL; 1686 return -EINVAL;
1674 if (!(((struct rtmsg *)nlmsg_data(cb->nlh))->rtm_flags&RTM_F_CLONED)) 1687
1688 rtm = nlmsg_data(cb->nlh);
1689 if (!(rtm->rtm_flags & RTM_F_CLONED))
1675 return 0; 1690 return 0;
1676 1691
1677 s_h = cb->args[0]; 1692 s_h = cb->args[0];
diff --git a/net/decnet/dn_table.c b/net/decnet/dn_table.c
index 92ec7417a4d9..16c986ab1228 100644
--- a/net/decnet/dn_table.c
+++ b/net/decnet/dn_table.c
@@ -297,62 +297,75 @@ static int dn_fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
297{ 297{
298 struct rtmsg *rtm; 298 struct rtmsg *rtm;
299 struct nlmsghdr *nlh; 299 struct nlmsghdr *nlh;
300 unsigned char *b = skb_tail_pointer(skb);
301 300
302 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*rtm), flags); 301 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*rtm), flags);
303 if (!nlh) 302 if (!nlh)
304 goto out_nlmsg_trim; 303 return -EMSGSIZE;
304
305 rtm = nlmsg_data(nlh); 305 rtm = nlmsg_data(nlh);
306 rtm->rtm_family = AF_DECnet; 306 rtm->rtm_family = AF_DECnet;
307 rtm->rtm_dst_len = dst_len; 307 rtm->rtm_dst_len = dst_len;
308 rtm->rtm_src_len = 0; 308 rtm->rtm_src_len = 0;
309 rtm->rtm_tos = 0; 309 rtm->rtm_tos = 0;
310 rtm->rtm_table = tb_id; 310 rtm->rtm_table = tb_id;
311 RTA_PUT_U32(skb, RTA_TABLE, tb_id);
312 rtm->rtm_flags = fi->fib_flags; 311 rtm->rtm_flags = fi->fib_flags;
313 rtm->rtm_scope = scope; 312 rtm->rtm_scope = scope;
314 rtm->rtm_type = type; 313 rtm->rtm_type = type;
315 if (rtm->rtm_dst_len)
316 RTA_PUT(skb, RTA_DST, 2, dst);
317 rtm->rtm_protocol = fi->fib_protocol; 314 rtm->rtm_protocol = fi->fib_protocol;
318 if (fi->fib_priority) 315
319 RTA_PUT(skb, RTA_PRIORITY, 4, &fi->fib_priority); 316 if (nla_put_u32(skb, RTA_TABLE, tb_id) < 0)
317 goto errout;
318
319 if (rtm->rtm_dst_len &&
320 nla_put(skb, RTA_DST, 2, dst) < 0)
321 goto errout;
322
323 if (fi->fib_priority &&
324 nla_put_u32(skb, RTA_PRIORITY, fi->fib_priority) < 0)
325 goto errout;
326
320 if (rtnetlink_put_metrics(skb, fi->fib_metrics) < 0) 327 if (rtnetlink_put_metrics(skb, fi->fib_metrics) < 0)
321 goto rtattr_failure; 328 goto errout;
329
322 if (fi->fib_nhs == 1) { 330 if (fi->fib_nhs == 1) {
323 if (fi->fib_nh->nh_gw) 331 if (fi->fib_nh->nh_gw &&
324 RTA_PUT(skb, RTA_GATEWAY, 2, &fi->fib_nh->nh_gw); 332 nla_put_le16(skb, RTA_GATEWAY, fi->fib_nh->nh_gw) < 0)
325 if (fi->fib_nh->nh_oif) 333 goto errout;
326 RTA_PUT(skb, RTA_OIF, sizeof(int), &fi->fib_nh->nh_oif); 334
335 if (fi->fib_nh->nh_oif &&
336 nla_put_u32(skb, RTA_OIF, fi->fib_nh->nh_oif) < 0)
337 goto errout;
327 } 338 }
339
328 if (fi->fib_nhs > 1) { 340 if (fi->fib_nhs > 1) {
329 struct rtnexthop *nhp; 341 struct rtnexthop *nhp;
330 struct rtattr *mp_head; 342 struct nlattr *mp_head;
331 if (skb_tailroom(skb) <= RTA_SPACE(0)) 343
332 goto rtattr_failure; 344 if (!(mp_head = nla_nest_start(skb, RTA_MULTIPATH)))
333 mp_head = (struct rtattr *)skb_put(skb, RTA_SPACE(0)); 345 goto errout;
334 346
335 for_nexthops(fi) { 347 for_nexthops(fi) {
336 if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4)) 348 if (!(nhp = nla_reserve_nohdr(skb, sizeof(*nhp))))
337 goto rtattr_failure; 349 goto errout;
338 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); 350
339 nhp->rtnh_flags = nh->nh_flags & 0xFF; 351 nhp->rtnh_flags = nh->nh_flags & 0xFF;
340 nhp->rtnh_hops = nh->nh_weight - 1; 352 nhp->rtnh_hops = nh->nh_weight - 1;
341 nhp->rtnh_ifindex = nh->nh_oif; 353 nhp->rtnh_ifindex = nh->nh_oif;
342 if (nh->nh_gw) 354
343 RTA_PUT(skb, RTA_GATEWAY, 2, &nh->nh_gw); 355 if (nh->nh_gw &&
356 nla_put_le16(skb, RTA_GATEWAY, nh->nh_gw) < 0)
357 goto errout;
358
344 nhp->rtnh_len = skb_tail_pointer(skb) - (unsigned char *)nhp; 359 nhp->rtnh_len = skb_tail_pointer(skb) - (unsigned char *)nhp;
345 } endfor_nexthops(fi); 360 } endfor_nexthops(fi);
346 mp_head->rta_type = RTA_MULTIPATH; 361
347 mp_head->rta_len = skb_tail_pointer(skb) - (u8 *)mp_head; 362 nla_nest_end(skb, mp_head);
348 } 363 }
349 364
350 nlh->nlmsg_len = skb_tail_pointer(skb) - b; 365 return nlmsg_end(skb, nlh);
351 return skb->len;
352 366
353out_nlmsg_trim: 367errout:
354rtattr_failure: 368 nlmsg_cancel(skb, nlh);
355 nlmsg_trim(skb, b);
356 return -EMSGSIZE; 369 return -EMSGSIZE;
357} 370}
358 371