Skip to content

Commit fe2a31d

Browse files
mkubecekdavem330
authored andcommitted
netlink: allow extack cookie also for error messages
Commit ba0dc5f ("netlink: allow sending extended ACK with cookie on success") introduced a cookie which can be sent to userspace as part of extended ack message in the form of NLMSGERR_ATTR_COOKIE attribute. Currently the cookie is ignored if error code is non-zero but there is no technical reason for such limitation and it can be useful to provide machine parseable information as part of an error message. Include NLMSGERR_ATTR_COOKIE whenever the cookie has been set, regardless of error code. Signed-off-by: Michal Kubecek <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ef299cc commit fe2a31d

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

net/netlink/af_netlink.c

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,19 +2392,14 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err,
23922392
if (nlk_has_extack && extack && extack->_msg)
23932393
tlvlen += nla_total_size(strlen(extack->_msg) + 1);
23942394

2395-
if (err) {
2396-
if (!(nlk->flags & NETLINK_F_CAP_ACK))
2397-
payload += nlmsg_len(nlh);
2398-
else
2399-
flags |= NLM_F_CAPPED;
2400-
if (nlk_has_extack && extack && extack->bad_attr)
2401-
tlvlen += nla_total_size(sizeof(u32));
2402-
} else {
2395+
if (err && !(nlk->flags & NETLINK_F_CAP_ACK))
2396+
payload += nlmsg_len(nlh);
2397+
else
24032398
flags |= NLM_F_CAPPED;
2404-
2405-
if (nlk_has_extack && extack && extack->cookie_len)
2406-
tlvlen += nla_total_size(extack->cookie_len);
2407-
}
2399+
if (err && nlk_has_extack && extack && extack->bad_attr)
2400+
tlvlen += nla_total_size(sizeof(u32));
2401+
if (nlk_has_extack && extack && extack->cookie_len)
2402+
tlvlen += nla_total_size(extack->cookie_len);
24082403

24092404
if (tlvlen)
24102405
flags |= NLM_F_ACK_TLVS;
@@ -2427,20 +2422,16 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err,
24272422
WARN_ON(nla_put_string(skb, NLMSGERR_ATTR_MSG,
24282423
extack->_msg));
24292424
}
2430-
if (err) {
2431-
if (extack->bad_attr &&
2432-
!WARN_ON((u8 *)extack->bad_attr < in_skb->data ||
2433-
(u8 *)extack->bad_attr >= in_skb->data +
2434-
in_skb->len))
2435-
WARN_ON(nla_put_u32(skb, NLMSGERR_ATTR_OFFS,
2436-
(u8 *)extack->bad_attr -
2437-
(u8 *)nlh));
2438-
} else {
2439-
if (extack->cookie_len)
2440-
WARN_ON(nla_put(skb, NLMSGERR_ATTR_COOKIE,
2441-
extack->cookie_len,
2442-
extack->cookie));
2443-
}
2425+
if (err && extack->bad_attr &&
2426+
!WARN_ON((u8 *)extack->bad_attr < in_skb->data ||
2427+
(u8 *)extack->bad_attr >= in_skb->data +
2428+
in_skb->len))
2429+
WARN_ON(nla_put_u32(skb, NLMSGERR_ATTR_OFFS,
2430+
(u8 *)extack->bad_attr -
2431+
(u8 *)nlh));
2432+
if (extack->cookie_len)
2433+
WARN_ON(nla_put(skb, NLMSGERR_ATTR_COOKIE,
2434+
extack->cookie_len, extack->cookie));
24442435
}
24452436

24462437
nlmsg_end(skb, rep);

0 commit comments

Comments
 (0)