Skip to content

Commit 92a395e

Browse files
tgrafdavem330
authored andcommitted
ipmr: Do not use RTA_PUT() macros
Also fix a needless skb tailroom check for a 4 bytes area after after each rtnexthop block. Signed-off-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6e277ed commit 92a395e

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

‎net/ipv4/ipmr.c‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,37 +2006,37 @@ static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
20062006
{
20072007
int ct;
20082008
struct rtnexthop *nhp;
2009-
u8 *b = skb_tail_pointer(skb);
2010-
struct rtattr *mp_head;
2009+
struct nlattr *mp_attr;
20112010

20122011
/* If cache is unresolved, don't try to parse IIF and OIF */
20132012
if (c->mfc_parent >= MAXVIFS)
20142013
return -ENOENT;
20152014

2016-
if (VIF_EXISTS(mrt, c->mfc_parent))
2017-
RTA_PUT(skb, RTA_IIF, 4, &mrt->vif_table[c->mfc_parent].dev->ifindex);
2015+
if (VIF_EXISTS(mrt, c->mfc_parent) &&
2016+
nla_put_u32(skb, RTA_IIF, mrt->vif_table[c->mfc_parent].dev->ifindex) < 0)
2017+
return -EMSGSIZE;
20182018

2019-
mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0));
2019+
if (!(mp_attr = nla_nest_start(skb, RTA_MULTIPATH)))
2020+
return -EMSGSIZE;
20202021

20212022
for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) {
20222023
if (VIF_EXISTS(mrt, ct) && c->mfc_un.res.ttls[ct] < 255) {
2023-
if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4))
2024-
goto rtattr_failure;
2025-
nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
2024+
if (!(nhp = nla_reserve_nohdr(skb, sizeof(*nhp)))) {
2025+
nla_nest_cancel(skb, mp_attr);
2026+
return -EMSGSIZE;
2027+
}
2028+
20262029
nhp->rtnh_flags = 0;
20272030
nhp->rtnh_hops = c->mfc_un.res.ttls[ct];
20282031
nhp->rtnh_ifindex = mrt->vif_table[ct].dev->ifindex;
20292032
nhp->rtnh_len = sizeof(*nhp);
20302033
}
20312034
}
2032-
mp_head->rta_type = RTA_MULTIPATH;
2033-
mp_head->rta_len = skb_tail_pointer(skb) - (u8 *)mp_head;
2035+
2036+
nla_nest_end(skb, mp_attr);
2037+
20342038
rtm->rtm_type = RTN_MULTICAST;
20352039
return 1;
2036-
2037-
rtattr_failure:
2038-
nlmsg_trim(skb, b);
2039-
return -EMSGSIZE;
20402040
}
20412041

20422042
int ipmr_get_route(struct net *net, struct sk_buff *skb,

0 commit comments

Comments
 (0)