Merge branch 'ethtool-fail-with-error-if-request-has-unknown-flags'
Michal Kubecek says: ==================== ethtool: fail with error if request has unknown flags Jakub Kicinski pointed out that if unrecognized flags are set in netlink header request, kernel shoud fail with an error rather than silently ignore them so that we have more freedom in future flags semantics. To help userspace with handling such errors, inform the client which flags are supported by kernel. For that purpose, we need to allow passing cookies as part of extack also in case of error (they can be only passed on success now). ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Коммит
23c394819d
|
@ -119,6 +119,15 @@ static inline void nl_set_extack_cookie_u64(struct netlink_ext_ack *extack,
|
|||
extack->cookie_len = sizeof(__cookie);
|
||||
}
|
||||
|
||||
static inline void nl_set_extack_cookie_u32(struct netlink_ext_ack *extack,
|
||||
u32 cookie)
|
||||
{
|
||||
u32 __cookie = cookie;
|
||||
|
||||
memcpy(extack->cookie, &__cookie, sizeof(__cookie));
|
||||
extack->cookie_len = sizeof(__cookie);
|
||||
}
|
||||
|
||||
void netlink_kernel_release(struct sock *sk);
|
||||
int __netlink_change_ngroups(struct sock *sk, unsigned int groups);
|
||||
int netlink_change_ngroups(struct sock *sk, unsigned int groups);
|
||||
|
|
|
@ -40,6 +40,7 @@ int ethnl_parse_header(struct ethnl_req_info *req_info,
|
|||
struct nlattr *tb[ETHTOOL_A_HEADER_MAX + 1];
|
||||
const struct nlattr *devname_attr;
|
||||
struct net_device *dev = NULL;
|
||||
u32 flags = 0;
|
||||
int ret;
|
||||
|
||||
if (!header) {
|
||||
|
@ -50,8 +51,17 @@ int ethnl_parse_header(struct ethnl_req_info *req_info,
|
|||
ethnl_header_policy, extack);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME];
|
||||
if (tb[ETHTOOL_A_HEADER_FLAGS]) {
|
||||
flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]);
|
||||
if (flags & ~ETHTOOL_FLAG_ALL) {
|
||||
NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_HEADER_FLAGS],
|
||||
"unrecognized request flags");
|
||||
nl_set_extack_cookie_u32(extack, ETHTOOL_FLAG_ALL);
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
}
|
||||
|
||||
devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME];
|
||||
if (tb[ETHTOOL_A_HEADER_DEV_INDEX]) {
|
||||
u32 ifindex = nla_get_u32(tb[ETHTOOL_A_HEADER_DEV_INDEX]);
|
||||
|
||||
|
@ -90,9 +100,7 @@ int ethnl_parse_header(struct ethnl_req_info *req_info,
|
|||
}
|
||||
|
||||
req_info->dev = dev;
|
||||
if (tb[ETHTOOL_A_HEADER_FLAGS])
|
||||
req_info->flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]);
|
||||
|
||||
req_info->flags = flags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -2392,19 +2392,14 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err,
|
|||
if (nlk_has_extack && extack && extack->_msg)
|
||||
tlvlen += nla_total_size(strlen(extack->_msg) + 1);
|
||||
|
||||
if (err) {
|
||||
if (!(nlk->flags & NETLINK_F_CAP_ACK))
|
||||
payload += nlmsg_len(nlh);
|
||||
else
|
||||
flags |= NLM_F_CAPPED;
|
||||
if (nlk_has_extack && extack && extack->bad_attr)
|
||||
tlvlen += nla_total_size(sizeof(u32));
|
||||
} else {
|
||||
if (err && !(nlk->flags & NETLINK_F_CAP_ACK))
|
||||
payload += nlmsg_len(nlh);
|
||||
else
|
||||
flags |= NLM_F_CAPPED;
|
||||
|
||||
if (nlk_has_extack && extack && extack->cookie_len)
|
||||
tlvlen += nla_total_size(extack->cookie_len);
|
||||
}
|
||||
if (err && nlk_has_extack && extack && extack->bad_attr)
|
||||
tlvlen += nla_total_size(sizeof(u32));
|
||||
if (nlk_has_extack && extack && extack->cookie_len)
|
||||
tlvlen += nla_total_size(extack->cookie_len);
|
||||
|
||||
if (tlvlen)
|
||||
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,
|
||||
extack->_msg));
|
||||
}
|
||||
if (err) {
|
||||
if (extack->bad_attr &&
|
||||
!WARN_ON((u8 *)extack->bad_attr < in_skb->data ||
|
||||
(u8 *)extack->bad_attr >= in_skb->data +
|
||||
in_skb->len))
|
||||
WARN_ON(nla_put_u32(skb, NLMSGERR_ATTR_OFFS,
|
||||
(u8 *)extack->bad_attr -
|
||||
(u8 *)nlh));
|
||||
} else {
|
||||
if (extack->cookie_len)
|
||||
WARN_ON(nla_put(skb, NLMSGERR_ATTR_COOKIE,
|
||||
extack->cookie_len,
|
||||
extack->cookie));
|
||||
}
|
||||
if (err && extack->bad_attr &&
|
||||
!WARN_ON((u8 *)extack->bad_attr < in_skb->data ||
|
||||
(u8 *)extack->bad_attr >= in_skb->data +
|
||||
in_skb->len))
|
||||
WARN_ON(nla_put_u32(skb, NLMSGERR_ATTR_OFFS,
|
||||
(u8 *)extack->bad_attr -
|
||||
(u8 *)nlh));
|
||||
if (extack->cookie_len)
|
||||
WARN_ON(nla_put(skb, NLMSGERR_ATTR_COOKIE,
|
||||
extack->cookie_len, extack->cookie));
|
||||
}
|
||||
|
||||
nlmsg_end(skb, rep);
|
||||
|
|
Загрузка…
Ссылка в новой задаче