aboutsummaryrefslogtreecommitdiffstats
path: root/net/decnet/dn_route.c
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 /net/decnet/dn_route.c
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>
Diffstat (limited to 'net/decnet/dn_route.c')
-rw-r--r--net/decnet/dn_route.c61
1 files changed, 38 insertions, 23 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];