Skip to content

Commit 8af4f60

Browse files
committed
netlink: support all extack types in dumps
Note that when this commit message refers to netlink dump it only means the actual dumping part, the parsing / dump start is handled by the same code as "doit". Commit 4a19edb ("netlink: Pass extack to dump handlers") added support for returning extack messages from dump handlers, but left out other extack info, e.g. bad attribute. This used to be fine because until YNL we had little practical use for the machine readable attributes, and only messages were used in practice. YNL flips the preference 180 degrees, it's now much more useful to point to a bad attr with NL_SET_BAD_ATTR() than type an English message saying "attribute XYZ is $reason-why-bad". Support all of extack. The fact that extack only gets added if it fits remains unaddressed. Reviewed-by: David Ahern <dsahern@kernel.org> Link: https://lore.kernel.org/r/20240420023543.3300306-4-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 652332e commit 8af4f60

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

net/netlink/af_netlink.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ netlink_ack_tlv_len(struct netlink_sock *nlk, int err,
21982198

21992199
static void
22002200
netlink_ack_tlv_fill(struct sk_buff *in_skb, struct sk_buff *skb,
2201-
struct nlmsghdr *nlh, int err,
2201+
const struct nlmsghdr *nlh, int err,
22022202
const struct netlink_ext_ack *extack)
22032203
{
22042204
if (extack->_msg)
@@ -2214,7 +2214,7 @@ netlink_ack_tlv_fill(struct sk_buff *in_skb, struct sk_buff *skb,
22142214
!WARN_ON((u8 *)extack->bad_attr < in_skb->data ||
22152215
(u8 *)extack->bad_attr >= in_skb->data + in_skb->len))
22162216
WARN_ON(nla_put_u32(skb, NLMSGERR_ATTR_OFFS,
2217-
(u8 *)extack->bad_attr - (u8 *)nlh));
2217+
(u8 *)extack->bad_attr - (const u8 *)nlh));
22182218
if (extack->policy)
22192219
netlink_policy_dump_write_attr(skb, extack->policy,
22202220
NLMSGERR_ATTR_POLICY);
@@ -2225,7 +2225,7 @@ netlink_ack_tlv_fill(struct sk_buff *in_skb, struct sk_buff *skb,
22252225
!WARN_ON((u8 *)extack->miss_nest < in_skb->data ||
22262226
(u8 *)extack->miss_nest > in_skb->data + in_skb->len))
22272227
WARN_ON(nla_put_u32(skb, NLMSGERR_ATTR_MISS_NEST,
2228-
(u8 *)extack->miss_nest - (u8 *)nlh));
2228+
(u8 *)extack->miss_nest - (const u8 *)nlh));
22292229
}
22302230

22312231
/*
@@ -2238,6 +2238,7 @@ static int netlink_dump_done(struct netlink_sock *nlk, struct sk_buff *skb,
22382238
struct netlink_ext_ack *extack)
22392239
{
22402240
struct nlmsghdr *nlh;
2241+
size_t extack_len;
22412242

22422243
nlh = nlmsg_put_answer(skb, cb, NLMSG_DONE, sizeof(nlk->dump_done_errno),
22432244
NLM_F_MULTI | cb->answer_flags);
@@ -2247,10 +2248,14 @@ static int netlink_dump_done(struct netlink_sock *nlk, struct sk_buff *skb,
22472248
nl_dump_check_consistent(cb, nlh);
22482249
memcpy(nlmsg_data(nlh), &nlk->dump_done_errno, sizeof(nlk->dump_done_errno));
22492250

2250-
if (extack->_msg && test_bit(NETLINK_F_EXT_ACK, &nlk->flags)) {
2251+
extack_len = netlink_ack_tlv_len(nlk, nlk->dump_done_errno, extack);
2252+
if (extack_len) {
22512253
nlh->nlmsg_flags |= NLM_F_ACK_TLVS;
2252-
if (!nla_put_string(skb, NLMSGERR_ATTR_MSG, extack->_msg))
2254+
if (skb_tailroom(skb) >= extack_len) {
2255+
netlink_ack_tlv_fill(cb->skb, skb, cb->nlh,
2256+
nlk->dump_done_errno, extack);
22532257
nlmsg_end(skb, nlh);
2258+
}
22542259
}
22552260

22562261
return 0;

0 commit comments

Comments
 (0)