Skip to content

Commit 028fb19

Browse files
rleonkuba-moo
authored andcommitted
netlink: provide an ability to set default extack message
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>
1 parent 62e395f commit 028fb19

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

include/linux/netlink.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ struct netlink_ext_ack {
130130
#define NL_SET_ERR_MSG_FMT_MOD(extack, fmt, args...) \
131131
NL_SET_ERR_MSG_FMT((extack), KBUILD_MODNAME ": " fmt, ##args)
132132

133+
#define NL_SET_ERR_MSG_WEAK(extack, msg) do { \
134+
if ((extack) && !(extack)->_msg) \
135+
NL_SET_ERR_MSG((extack), msg); \
136+
} while (0)
137+
138+
#define NL_SET_ERR_MSG_WEAK_MOD(extack, msg) do { \
139+
if ((extack) && !(extack)->_msg) \
140+
NL_SET_ERR_MSG_MOD((extack), msg); \
141+
} while (0)
142+
133143
#define NL_SET_BAD_ATTR_POLICY(extack, attr, pol) do { \
134144
if ((extack)) { \
135145
(extack)->bad_attr = (attr); \

net/bridge/br_switchdev.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
104104
return 0;
105105

106106
if (err) {
107-
if (extack && !extack->_msg)
108-
NL_SET_ERR_MSG_MOD(extack,
109-
"bridge flag offload is not supported");
107+
NL_SET_ERR_MSG_WEAK_MOD(extack,
108+
"bridge flag offload is not supported");
110109
return -EOPNOTSUPP;
111110
}
112111

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

116115
err = switchdev_port_attr_set(p->dev, &attr, extack);
117116
if (err) {
118-
if (extack && !extack->_msg)
119-
NL_SET_ERR_MSG_MOD(extack,
120-
"error setting offload flag on port");
117+
NL_SET_ERR_MSG_WEAK_MOD(extack,
118+
"error setting offload flag on port");
121119
return err;
122120
}
123121

net/dsa/master.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,7 @@ int dsa_master_lag_setup(struct net_device *lag_dev, struct dsa_port *cpu_dp,
464464

465465
err = dsa_port_lag_join(cpu_dp, lag_dev, uinfo, extack);
466466
if (err) {
467-
if (extack && !extack->_msg)
468-
NL_SET_ERR_MSG_MOD(extack,
469-
"CPU port failed to join LAG");
467+
NL_SET_ERR_MSG_WEAK_MOD(extack, "CPU port failed to join LAG");
470468
goto out_master_teardown;
471469
}
472470

net/dsa/slave.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,9 +2692,7 @@ static int dsa_slave_changeupper(struct net_device *dev,
26922692
if (!err)
26932693
dsa_bridge_mtu_normalization(dp);
26942694
if (err == -EOPNOTSUPP) {
2695-
if (extack && !extack->_msg)
2696-
NL_SET_ERR_MSG_MOD(extack,
2697-
"Offloading not supported");
2695+
NL_SET_ERR_MSG_WEAK_MOD(extack, "Offloading not supported");
26982696
err = 0;
26992697
}
27002698
err = notifier_from_errno(err);

net/xfrm/xfrm_device.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
325325
* authors to do not return -EOPNOTSUPP in packet offload mode.
326326
*/
327327
WARN_ON(err == -EOPNOTSUPP && is_packet_offload);
328-
if (err != -EOPNOTSUPP || is_packet_offload)
328+
if (err != -EOPNOTSUPP || is_packet_offload) {
329+
NL_SET_ERR_MSG_WEAK(extack, "Device failed to offload this state");
329330
return err;
331+
}
330332
}
331333

332334
return 0;
@@ -388,6 +390,7 @@ int xfrm_dev_policy_add(struct net *net, struct xfrm_policy *xp,
388390
xdo->type = XFRM_DEV_OFFLOAD_UNSPECIFIED;
389391
xdo->dir = 0;
390392
netdev_put(dev, &xdo->dev_tracker);
393+
NL_SET_ERR_MSG_WEAK(extack, "Device failed to offload this policy");
391394
return err;
392395
}
393396

0 commit comments

Comments
 (0)