mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-04 18:09:57 +00:00
net: report invalid mtu value via netlink extack
If an invalid MTU value is set through rtnetlink return extra error information instead of putting message in kernel log. For other cases where there is no visible API, keep the error report in the log. Example: # ip li set dev enp12s0 mtu 10000 Error: mtu greater than device maximum. # ifconfig enp12s0 mtu 10000 SIOCSIFMTU: Invalid argument # dmesg | tail -1 [ 2047.795467] enp12s0: mtu greater than device maximum Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
3e7a50ceb1
commit
7a4c53bee3
3 changed files with 20 additions and 7 deletions
|
@ -3546,6 +3546,8 @@ int dev_set_alias(struct net_device *, const char *, size_t);
|
|||
int dev_get_alias(const struct net_device *, char *, size_t);
|
||||
int dev_change_net_namespace(struct net_device *, struct net *, const char *);
|
||||
int __dev_set_mtu(struct net_device *, int);
|
||||
int dev_set_mtu_ext(struct net_device *dev, int mtu,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dev_set_mtu(struct net_device *, int);
|
||||
int dev_change_tx_queue_len(struct net_device *, unsigned long);
|
||||
void dev_set_group(struct net_device *, int);
|
||||
|
|
|
@ -7523,13 +7523,15 @@ int __dev_set_mtu(struct net_device *dev, int new_mtu)
|
|||
EXPORT_SYMBOL(__dev_set_mtu);
|
||||
|
||||
/**
|
||||
* dev_set_mtu - Change maximum transfer unit
|
||||
* dev_set_mtu_ext - Change maximum transfer unit
|
||||
* @dev: device
|
||||
* @new_mtu: new transfer unit
|
||||
* @extack: netlink extended ack
|
||||
*
|
||||
* Change the maximum transfer size of the network device.
|
||||
*/
|
||||
int dev_set_mtu(struct net_device *dev, int new_mtu)
|
||||
int dev_set_mtu_ext(struct net_device *dev, int new_mtu,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
int err, orig_mtu;
|
||||
|
||||
|
@ -7538,14 +7540,12 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
|
|||
|
||||
/* MTU must be positive, and in range */
|
||||
if (new_mtu < 0 || new_mtu < dev->min_mtu) {
|
||||
net_err_ratelimited("%s: Invalid MTU %d requested, hw min %d\n",
|
||||
dev->name, new_mtu, dev->min_mtu);
|
||||
NL_SET_ERR_MSG(extack, "mtu less than device minimum");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (dev->max_mtu > 0 && new_mtu > dev->max_mtu) {
|
||||
net_err_ratelimited("%s: Invalid MTU %d requested, hw max %d\n",
|
||||
dev->name, new_mtu, dev->max_mtu);
|
||||
NL_SET_ERR_MSG(extack, "mtu greater than device maximum");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -7573,6 +7573,17 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
|
|||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
int dev_set_mtu(struct net_device *dev, int new_mtu)
|
||||
{
|
||||
struct netlink_ext_ack extack;
|
||||
int err;
|
||||
|
||||
err = dev_set_mtu_ext(dev, new_mtu, &extack);
|
||||
if (err)
|
||||
net_err_ratelimited("%s: %s\n", dev->name, extack._msg);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(dev_set_mtu);
|
||||
|
||||
/**
|
||||
|
|
|
@ -2382,7 +2382,7 @@ static int do_setlink(const struct sk_buff *skb,
|
|||
}
|
||||
|
||||
if (tb[IFLA_MTU]) {
|
||||
err = dev_set_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
|
||||
err = dev_set_mtu_ext(dev, nla_get_u32(tb[IFLA_MTU]), extack);
|
||||
if (err < 0)
|
||||
goto errout;
|
||||
status |= DO_SETLINK_MODIFIED;
|
||||
|
|
Loading…
Reference in a new issue