[PATCH net-next v2 1/2] net: Add sysfs atttributes for max_mtu min_mtu

From: Shradha Gupta
Date: Wed Apr 24 2024 - 06:33:49 EST


Add sysfs attributes to read max_mtu and min_mtu value for
network devices

Signed-off-by: Shradha Gupta <shradhagupta@xxxxxxxxxxxxxxxxxxx>
---
Changes in v2:
* Created a new patch for generic attributes
---
Documentation/ABI/testing/sysfs-class-net | 16 ++++++++++++++++
net/core/net-sysfs.c | 4 ++++
2 files changed, 20 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-net b/Documentation/ABI/testing/sysfs-class-net
index ebf21beba846..f68f3b9be6ec 100644
--- a/Documentation/ABI/testing/sysfs-class-net
+++ b/Documentation/ABI/testing/sysfs-class-net
@@ -352,3 +352,19 @@ Description:
0 threaded mode disabled for this dev
1 threaded mode enabled for this dev
== ==================================
+
+What: /sys/class/net/<iface>/max_mtu
+Date: April 2024
+KernelVersion: 6.10
+Contact: netdev@xxxxxxxxxxxxxxx
+Description:
+ Indicates the interface's maximum supported MTU value, in
+ bytes, and in decimal format.
+
+What: /sys/class/net/<iface>/min_mtu
+Date: April 2024
+KernelVersion: 6.10
+Contact: netdev@xxxxxxxxxxxxxxx
+Description:
+ Indicates the interface's minimum supported MTU value, in
+ bytes, and in decimal format.
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index e3d7a8cfa20b..525b85d47676 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -114,6 +114,8 @@ NETDEVICE_SHOW_RO(addr_len, fmt_dec);
NETDEVICE_SHOW_RO(ifindex, fmt_dec);
NETDEVICE_SHOW_RO(type, fmt_dec);
NETDEVICE_SHOW_RO(link_mode, fmt_dec);
+NETDEVICE_SHOW_RO(max_mtu, fmt_dec);
+NETDEVICE_SHOW_RO(min_mtu, fmt_dec);

static ssize_t iflink_show(struct device *dev, struct device_attribute *attr,
char *buf)
@@ -671,6 +673,8 @@ static struct attribute *net_class_attrs[] __ro_after_init = {
&dev_attr_carrier_up_count.attr,
&dev_attr_carrier_down_count.attr,
&dev_attr_threaded.attr,
+ &dev_attr_max_mtu.attr,
+ &dev_attr_min_mtu.attr,
NULL,
};
ATTRIBUTE_GROUPS(net_class);
--
2.34.1