Skip to contentSkip to conversation

ipv6: create ra_mtu proc file to only record mtu in RA

PATCH In review Rocco Yue 2 participants 4 messages Jun 1, 2021 – Jun 2, 2021

Subsystems (4)
lore
Share & tools
lore

Rocco Yue

author
#0 lore raw

PATCH 1/1 ipv6: create ra_mtu proc file to only record mtu in RA

kernel provides a "/proc/sys/net/ipv6/conf/<iface>/mtu" file, which can temporarily record the mtu value of the last received RA message when ra mtu is lower than the interface mtu, but this proc has following limitations:
(1) when the interface mtu (/sys/class/net/<iface>/mtu) is updeated, mtu6 (/proc/sys/net/ipv6/conf/<iface>/mtu) will be updated to the value of interface mtu;
(2) mtu6 (/proc/sys/net/ipv6/conf/<iface>/mtu) only affect ipv6 connection, and not affect ipv4.

Therefore, when the mtu option is carried in the RA message, there will be a problem that the user sometimes cannot obtain ra mtu value by reading mtu6.

Waiting for RA to arrive, setting the interface mtu after reading mtu6 can avoid above problem. But device can't do this, on the one hand, the device should first ensure that the ipv4 function is normal, and on the other hand, the time point of receiving the RA message from the network is not certain.

For this patch set, if RA message carries the mtu option, "proc/sys/net/ipv6/conf/<iface>/ra_mtu" will be updated to the mtu value carried in the last RA message received, and ra_mtu is an independent proc file, which is not affected by the update of interface mtu value.

In this way, If the MTU values that the device receives from the network in the PCO IPv4 and the RA IPv6 procedures are different, the user space process can read ra_mtu to get the mtu value carried in the RA message without worrying about the issue of ipv4 being stuck due to the late arrival of RA message. After comparing the value of ra_mtu and ipv4 mtu, then the device can use the lower MTU value for both IPv4 and IPv6.

---
 include/linux/ipv6.h      |  1 +
 include/uapi/linux/ipv6.h |  1 +
 net/ipv6/addrconf.c       | 10 ++++++++++
 net/ipv6/ndisc.c          |  5 +++++
 4 files changed, 17 insertions(+)
include/linux/ipv6.h +1 -0
index 70b2ad3b9884..1679b7ce6780 100644
@@ -13,6 +13,7 @@ struct ipv6_devconf {
 	__s32		forwarding;
 	__s32		hop_limit;
 	__s32		mtu6;
+	__s32		ra_mtu;
 	__s32		accept_ra;
 	__s32		accept_redirects;
 	__s32		autoconf;
include/uapi/linux/ipv6.h +1 -0
index 70603775fe91..1214befaea9f 100644
@@ -140,6 +140,7 @@ enum {
 	DEVCONF_FORWARDING = 0,
 	DEVCONF_HOPLIMIT,
 	DEVCONF_MTU6,
+	DEVCONF_RA_MTU,
 	DEVCONF_ACCEPT_RA,
 	DEVCONF_ACCEPT_REDIRECTS,
 	DEVCONF_AUTOCONF,
net/ipv6/addrconf.c +10 -0
index b0ef65eb9bd2..d2cd30bd25b3 100644
@@ -187,6 +187,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
 	.forwarding		= 0,
 	.hop_limit		= IPV6_DEFAULT_HOPLIMIT,
 	.mtu6			= IPV6_MIN_MTU,
+	.ra_mtu			= 0,
 	.accept_ra		= 1,
 	.accept_redirects	= 1,
 	.autoconf		= 1,
@@ -243,6 +244,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
 	.forwarding		= 0,
 	.hop_limit		= IPV6_DEFAULT_HOPLIMIT,
 	.mtu6			= IPV6_MIN_MTU,
+	.ra_mtu			= 0,
 	.accept_ra		= 1,
 	.accept_redirects	= 1,
 	.autoconf		= 1,
@@ -5460,6 +5462,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
 	array[DEVCONF_FORWARDING] = cnf->forwarding;
 	array[DEVCONF_HOPLIMIT] = cnf->hop_limit;
 	array[DEVCONF_MTU6] = cnf->mtu6;
+	array[DEVCONF_RA_MTU] = cnf->ra_mtu;
 	array[DEVCONF_ACCEPT_RA] = cnf->accept_ra;
 	array[DEVCONF_ACCEPT_REDIRECTS] = cnf->accept_redirects;
 	array[DEVCONF_AUTOCONF] = cnf->autoconf;
@@ -6565,6 +6568,13 @@ static const struct ctl_table addrconf_sysctl[] = {
 		.mode		= 0644,
 		.proc_handler	= addrconf_sysctl_mtu,
 	},
+	{
+		.procname	= "ra_mtu",
+		.data		= &ipv6_devconf.ra_mtu,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
 	{
 		.procname	= "accept_ra",
 		.data		= &ipv6_devconf.accept_ra,
net/ipv6/ndisc.c +5 -0
index c467c6419893..1da626267662 100644
@@ -1496,6 +1496,11 @@ static void ndisc_router_discovery(struct sk_buff *skb)
 		memcpy(&n, ((u8 *)(ndopts.nd_opts_mtu+1))+2, sizeof(mtu));
 		mtu = ntohl(n);
 
+		if (in6_dev->cnf.ra_mtu != mtu) {
+			in6_dev->cnf.ra_mtu = mtu;
+			ND_PRINTK(2, info, "update ra_mtu to %d\n", in6_dev->cnf.ra_mtu);
+		}
+
 		if (mtu < IPV6_MIN_MTU || mtu > skb->dev->mtu) {
 			ND_PRINTK(2, warn, "RA: invalid mtu: %d\n", mtu);
 		} else if (in6_dev->cnf.mtu6 != mtu) {
Signature · 1 line
2.18.0
#1 lore raw
Quoted 5 lines · Rocco Yue

For this patch set, if RA message carries the mtu option, "proc/sys/net/ipv6/conf/<iface>/ra_mtu" will be updated to the mtu value carried in the last RA message received, and ra_mtu is an independent proc file, which is not affected by the update of interface mtu value.

I am not a fan of more /proc/sys files.

You are adding it to devconf which is good. You can add another link attribute, e.g., IFLA_RA_MTU, and have it returned on link queries.

Make sure the attribute can not be sent in a NEWLINK or SETLINK request; it should be read-only for GETLINK.

author
#2 lore raw

On Tue, 2021-06-01 at 18:38 -0600, David Ahern wrote:

Quoted 6 lines · Rocco Yue
Quoted 5 lines

For this patch set, if RA message carries the mtu option, "proc/sys/net/ipv6/conf/<iface>/ra_mtu" will be updated to the mtu value carried in the last RA message received, and ra_mtu is an independent proc file, which is not affected by the update of interface mtu value.

Quoted 7 lines

I am not a fan of more /proc/sys files.

You are adding it to devconf which is good. You can add another link attribute, e.g., IFLA_RA_MTU, and have it returned on link queries.

Make sure the attribute can not be sent in a NEWLINK or SETLINK request; it should be read-only for GETLINK.

Thanks for your review and advice.
Do you mean that I should keep the ra_mtu proc and add an another extra netlink msg? Or only use netlink msg instead of ra_mtu proc?
I will do it.

Thanks,
Rocco

#3 lore raw
Quoted 13 lines · Rocco Yue

On Tue, 2021-06-01 at 18:38 -0600, David Ahern wrote:

Quoted 11 lines · Rocco Yue
Quoted 5 lines

For this patch set, if RA message carries the mtu option, "proc/sys/net/ipv6/conf/<iface>/ra_mtu" will be updated to the mtu value carried in the last RA message received, and ra_mtu is an independent proc file, which is not affected by the update of interface mtu value.

I am not a fan of more /proc/sys files.

You are adding it to devconf which is good. You can add another link attribute, e.g., IFLA_RA_MTU, and have it returned on link queries.

Quoted 8 lines
Quoted 2 lines

Make sure the attribute can not be sent in a NEWLINK or SETLINK request; it should be read-only for GETLINK.

Thanks for your review and advice.
Do you mean that I should keep the ra_mtu proc and add an another extra netlink msg? Or only use netlink msg instead of ra_mtu proc?
I will do it.

I meant DEVCONF and notification to userspace was good, but using an IFLA attribute and no proc/sys file is better.