diff mbox series

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

Message ID 20210601091619.19372-1-rocco.yue@mediatek.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series ipv6: create ra_mtu proc file to only record mtu in RA | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers warning 7 maintainers not CCed: linmiaohe@huawei.com zxu@linkedin.com willemb@google.com rdunlap@infradead.org praveen5582@gmail.com Jason@zx2c4.com edumazet@google.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 2377 this patch: 2377
netdev/kdoc success Errors and warnings before: 38 this patch: 38
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: line length of 89 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 2469 this patch: 2469
netdev/header_inline success Link

Commit Message

Rocco Yue June 1, 2021, 9:16 a.m. UTC
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.

Signed-off-by: Rocco Yue <rocco.yue@mediatek.com>
---
 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(+)

Comments

David Ahern June 2, 2021, 12:38 a.m. UTC | #1
On 6/1/21 3:16 AM, Rocco Yue wrote:
> 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.
Rocco Yue June 2, 2021, 3:15 a.m. UTC | #2
On Tue, 2021-06-01 at 18:38 -0600, David Ahern wrote:
On 6/1/21 3:16 AM, Rocco Yue wrote:
> > 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.

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
David Ahern June 2, 2021, 4:20 a.m. UTC | #3
On 6/1/21 9:15 PM, Rocco Yue wrote:
> On Tue, 2021-06-01 at 18:38 -0600, David Ahern wrote:
> On 6/1/21 3:16 AM, Rocco Yue wrote:
>>> 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.
> 
> 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.
diff mbox series

Patch

diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
index 70b2ad3b9884..1679b7ce6780 100644
--- a/include/linux/ipv6.h
+++ b/include/linux/ipv6.h
@@ -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;
diff --git a/include/uapi/linux/ipv6.h b/include/uapi/linux/ipv6.h
index 70603775fe91..1214befaea9f 100644
--- a/include/uapi/linux/ipv6.h
+++ b/include/uapi/linux/ipv6.h
@@ -140,6 +140,7 @@  enum {
 	DEVCONF_FORWARDING = 0,
 	DEVCONF_HOPLIMIT,
 	DEVCONF_MTU6,
+	DEVCONF_RA_MTU,
 	DEVCONF_ACCEPT_RA,
 	DEVCONF_ACCEPT_REDIRECTS,
 	DEVCONF_AUTOCONF,
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index b0ef65eb9bd2..d2cd30bd25b3 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -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,
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index c467c6419893..1da626267662 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -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) {