Skip to content

Commit

Permalink
netlink: provide an ability to set default extack message
Browse files Browse the repository at this point in the history
In netdev common pattern, extack pointer is forwarded to the drivers
to be filled with error message. However, the caller can easily
overwrite the filled message.

Instead of adding multiple "if (!extack->_msg)" checks before any
NL_SET_ERR_MSG() call, which appears after call to the driver, let's
add new macro to common code.

[1] https://lore.kernel.org/all/Y9Irgrgf3uxOjwUm@unreal
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Link: https://lore.kernel.org/r/6993fac557a40a1973dfa0095107c3d03d40bec1.1675171790.git.leon@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Leon Romanovsky authored and Jakub Kicinski committed Feb 2, 2023
1 parent 62e395f commit 028fb19
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
10 changes: 10 additions & 0 deletions include/linux/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ struct netlink_ext_ack {
#define NL_SET_ERR_MSG_FMT_MOD(extack, fmt, args...) \
NL_SET_ERR_MSG_FMT((extack), KBUILD_MODNAME ": " fmt, ##args)

#define NL_SET_ERR_MSG_WEAK(extack, msg) do { \
if ((extack) && !(extack)->_msg) \
NL_SET_ERR_MSG((extack), msg); \
} while (0)

#define NL_SET_ERR_MSG_WEAK_MOD(extack, msg) do { \
if ((extack) && !(extack)->_msg) \
NL_SET_ERR_MSG_MOD((extack), msg); \
} while (0)

#define NL_SET_BAD_ATTR_POLICY(extack, attr, pol) do { \
if ((extack)) { \
(extack)->bad_attr = (attr); \
Expand Down
10 changes: 4 additions & 6 deletions net/bridge/br_switchdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
return 0;

if (err) {
if (extack && !extack->_msg)
NL_SET_ERR_MSG_MOD(extack,
"bridge flag offload is not supported");
NL_SET_ERR_MSG_WEAK_MOD(extack,
"bridge flag offload is not supported");
return -EOPNOTSUPP;
}

Expand All @@ -115,9 +114,8 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,

err = switchdev_port_attr_set(p->dev, &attr, extack);
if (err) {
if (extack && !extack->_msg)
NL_SET_ERR_MSG_MOD(extack,
"error setting offload flag on port");
NL_SET_ERR_MSG_WEAK_MOD(extack,
"error setting offload flag on port");
return err;
}

Expand Down
4 changes: 1 addition & 3 deletions net/dsa/master.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,7 @@ int dsa_master_lag_setup(struct net_device *lag_dev, struct dsa_port *cpu_dp,

err = dsa_port_lag_join(cpu_dp, lag_dev, uinfo, extack);
if (err) {
if (extack && !extack->_msg)
NL_SET_ERR_MSG_MOD(extack,
"CPU port failed to join LAG");
NL_SET_ERR_MSG_WEAK_MOD(extack, "CPU port failed to join LAG");
goto out_master_teardown;
}

Expand Down
4 changes: 1 addition & 3 deletions net/dsa/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -2692,9 +2692,7 @@ static int dsa_slave_changeupper(struct net_device *dev,
if (!err)
dsa_bridge_mtu_normalization(dp);
if (err == -EOPNOTSUPP) {
if (extack && !extack->_msg)
NL_SET_ERR_MSG_MOD(extack,
"Offloading not supported");
NL_SET_ERR_MSG_WEAK_MOD(extack, "Offloading not supported");
err = 0;
}
err = notifier_from_errno(err);
Expand Down
5 changes: 4 additions & 1 deletion net/xfrm/xfrm_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
* authors to do not return -EOPNOTSUPP in packet offload mode.
*/
WARN_ON(err == -EOPNOTSUPP && is_packet_offload);
if (err != -EOPNOTSUPP || is_packet_offload)
if (err != -EOPNOTSUPP || is_packet_offload) {
NL_SET_ERR_MSG_WEAK(extack, "Device failed to offload this state");
return err;
}
}

return 0;
Expand Down Expand Up @@ -388,6 +390,7 @@ int xfrm_dev_policy_add(struct net *net, struct xfrm_policy *xp,
xdo->type = XFRM_DEV_OFFLOAD_UNSPECIFIED;
xdo->dir = 0;
netdev_put(dev, &xdo->dev_tracker);
NL_SET_ERR_MSG_WEAK(extack, "Device failed to offload this policy");
return err;
}

Expand Down

0 comments on commit 028fb19

Please sign in to comment.