netlink: allow extack cookie also for error messages
Commit ba0dc5f6e0
("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 <mkubecek@suse.cz>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Родитель
ef299cc3fa
Коммит
fe2a31d790
|
@ -2392,19 +2392,14 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err,
|
||||||
if (nlk_has_extack && extack && extack->_msg)
|
if (nlk_has_extack && extack && extack->_msg)
|
||||||
tlvlen += nla_total_size(strlen(extack->_msg) + 1);
|
tlvlen += nla_total_size(strlen(extack->_msg) + 1);
|
||||||
|
|
||||||
if (err) {
|
if (err && !(nlk->flags & NETLINK_F_CAP_ACK))
|
||||||
if (!(nlk->flags & NETLINK_F_CAP_ACK))
|
payload += nlmsg_len(nlh);
|
||||||
payload += nlmsg_len(nlh);
|
else
|
||||||
else
|
|
||||||
flags |= NLM_F_CAPPED;
|
|
||||||
if (nlk_has_extack && extack && extack->bad_attr)
|
|
||||||
tlvlen += nla_total_size(sizeof(u32));
|
|
||||||
} else {
|
|
||||||
flags |= NLM_F_CAPPED;
|
flags |= NLM_F_CAPPED;
|
||||||
|
if (err && nlk_has_extack && extack && extack->bad_attr)
|
||||||
if (nlk_has_extack && extack && extack->cookie_len)
|
tlvlen += nla_total_size(sizeof(u32));
|
||||||
tlvlen += nla_total_size(extack->cookie_len);
|
if (nlk_has_extack && extack && extack->cookie_len)
|
||||||
}
|
tlvlen += nla_total_size(extack->cookie_len);
|
||||||
|
|
||||||
if (tlvlen)
|
if (tlvlen)
|
||||||
flags |= NLM_F_ACK_TLVS;
|
flags |= NLM_F_ACK_TLVS;
|
||||||
|
@ -2427,20 +2422,16 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err,
|
||||||
WARN_ON(nla_put_string(skb, NLMSGERR_ATTR_MSG,
|
WARN_ON(nla_put_string(skb, NLMSGERR_ATTR_MSG,
|
||||||
extack->_msg));
|
extack->_msg));
|
||||||
}
|
}
|
||||||
if (err) {
|
if (err && extack->bad_attr &&
|
||||||
if (extack->bad_attr &&
|
!WARN_ON((u8 *)extack->bad_attr < in_skb->data ||
|
||||||
!WARN_ON((u8 *)extack->bad_attr < in_skb->data ||
|
(u8 *)extack->bad_attr >= in_skb->data +
|
||||||
(u8 *)extack->bad_attr >= in_skb->data +
|
in_skb->len))
|
||||||
in_skb->len))
|
WARN_ON(nla_put_u32(skb, NLMSGERR_ATTR_OFFS,
|
||||||
WARN_ON(nla_put_u32(skb, NLMSGERR_ATTR_OFFS,
|
(u8 *)extack->bad_attr -
|
||||||
(u8 *)extack->bad_attr -
|
(u8 *)nlh));
|
||||||
(u8 *)nlh));
|
if (extack->cookie_len)
|
||||||
} else {
|
WARN_ON(nla_put(skb, NLMSGERR_ATTR_COOKIE,
|
||||||
if (extack->cookie_len)
|
extack->cookie_len, extack->cookie));
|
||||||
WARN_ON(nla_put(skb, NLMSGERR_ATTR_COOKIE,
|
|
||||||
extack->cookie_len,
|
|
||||||
extack->cookie));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nlmsg_end(skb, rep);
|
nlmsg_end(skb, rep);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче