Skip to contentSkip to conversation

net: ipv6: Add sysctl entry to disable MTU updates from RA

PATCH Superseded Harout Hedeshian 3 participants 8 messages Jan 19, 2015 – Jan 20, 2015

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: ipv6: Add sysctl entry to disable MTU updates from RA

The kernel forcefully applies MTU values received in router advertisements provided the new MTU is less than the current. This behavior is undesirable when the user space is managing the MTU. Instead a sysctl flag 'accept_ra_mtu' is introduced such that the user space can control whether or not RA provided MTU updates should be applied. The default behavior is unchanged; user space must explicitly set this flag to 0 for RA MTUs to be ignored.

---
 Documentation/networking/ip-sysctl.txt | 7 +++++++
 include/linux/ipv6.h                   | 1 +
 include/uapi/linux/ipv6.h              | 1 +
 include/uapi/linux/sysctl.h            | 1 +
 kernel/sysctl_binary.c                 | 1 +
 net/ipv6/addrconf.c                    | 9 +++++++++
 net/ipv6/ndisc.c                       | 2 +-
 7 files changed, 21 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.txt +7 -0
index 85b0221..da50faa 100644
@@ -1287,6 +1287,13 @@ accept_ra_rtr_pref - BOOLEAN
 	Functional default: enabled if accept_ra is enabled.
 			    disabled if accept_ra is disabled.
 
+accept_ra_mtu - BOOLEAN
+	Apply the MTU value specified in RA option 5 (RFC4861). If
+	disabled, the MTU specified in the RA will be ignored.
+
+	Functional default: enabled if accept_ra is enabled.
+                            disabled if accept_ra is disabled.
+
 accept_redirects - BOOLEAN
 	Accept Redirects.
 
include/linux/ipv6.h +1 -0
index c694e7b..2805062 100644
@@ -52,6 +52,7 @@ struct ipv6_devconf {
 	__s32		force_tllao;
 	__s32           ndisc_notify;
 	__s32		suppress_frag_ndisc;
+	__s32		accept_ra_mtu;
 	void		*sysctl;
 };
 
include/uapi/linux/ipv6.h +1 -0
index 73cb02d..437a6a4 100644
@@ -169,6 +169,7 @@ enum {
 	DEVCONF_SUPPRESS_FRAG_NDISC,
 	DEVCONF_ACCEPT_RA_FROM_LOCAL,
 	DEVCONF_USE_OPTIMISTIC,
+	DEVCONF_ACCEPT_RA_MTU,
 	DEVCONF_MAX
 };
 
include/uapi/linux/sysctl.h +1 -0
index 0956373..45e4fcf 100644
@@ -570,6 +570,7 @@ enum {
 	NET_IPV6_PROXY_NDP=23,
 	NET_IPV6_ACCEPT_SOURCE_ROUTE=25,
 	NET_IPV6_ACCEPT_RA_FROM_LOCAL=26,
+	NET_IPV6_ACCEPT_RA_MTU=27,
 	__NET_IPV6_MAX
 };
 
kernel/sysctl_binary.c +1 -0
index 7e7746a..16091e5 100644
@@ -523,6 +523,7 @@ static const struct bin_table bin_net_ipv6_conf_var_table[] = {
 	{ CTL_INT,	NET_IPV6_PROXY_NDP,			"proxy_ndp" },
 	{ CTL_INT,	NET_IPV6_ACCEPT_SOURCE_ROUTE,		"accept_source_route" },
 	{ CTL_INT,	NET_IPV6_ACCEPT_RA_FROM_LOCAL,		"accept_ra_from_local" },
+	{ CTL_INT,	NET_IPV6_ACCEPT_RA_MTU,			"accept_ra_mtu" },
 	{}
 };
 
net/ipv6/addrconf.c +9 -0
index f7c8bbe..cdd70ed 100644
@@ -201,6 +201,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
 	.disable_ipv6		= 0,
 	.accept_dad		= 1,
 	.suppress_frag_ndisc	= 1,
+	.accept_ra_mtu		= 1,
 };
 
 static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
@@ -238,6 +239,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
 	.disable_ipv6		= 0,
 	.accept_dad		= 1,
 	.suppress_frag_ndisc	= 1,
+	.accept_ra_mtu		= 1,
 };
 
 /* Check if a valid qdisc is available */
@@ -5253,6 +5255,13 @@ static struct addrconf_sysctl_table
 			.proc_handler	= proc_dointvec,
 		},
 		{
+			.procname	= "accept_ra_mtu",
+			.data		= &ipv6_devconf.accept_ra_mtu,
+			.maxlen		= sizeof(int),
+			.mode		= 0644,
+			.proc_handler	= proc_dointvec,
+		},
+		{
 			/* sentinel */
 		}
 	},
net/ipv6/ndisc.c +1 -1
index 6828667..8a9d7c1 100644
@@ -1348,7 +1348,7 @@ skip_routeinfo:
 		}
 	}
 
-	if (ndopts.nd_opts_mtu) {
+	if (ndopts.nd_opts_mtu && in6_dev->cnf.accept_ra_mtu) {
 		__be32 n;
 		u32 mtu;
 
Signature · 2 lines
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#1 lore raw

On 01/19/2015 10:36 PM, Harout Hedeshian wrote:
...

Quoted 17 lines
include/uapi/linux/sysctl.h +1 -0
index 0956373..45e4fcf 100644
@@ -570,6 +570,7 @@ enum {
  	NET_IPV6_PROXY_NDP=23,
  	NET_IPV6_ACCEPT_SOURCE_ROUTE=25,
  	NET_IPV6_ACCEPT_RA_FROM_LOCAL=26,
+	NET_IPV6_ACCEPT_RA_MTU=27,
  	__NET_IPV6_MAX
  };
 
kernel/sysctl_binary.c +0 -0
index 7e7746a..16091e5 100644

kernel/sysctl_binary.c static const struct bin_table bin_net_ipv6_conf_var_table[] = { · line 528

Quoted 6 lines
kernel/sysctl_binary.c +1 -0
@@ -523,6 +523,7 @@ static const struct bin_table bin_net_ipv6_conf_var_table[] = {
  	{ CTL_INT,	NET_IPV6_PROXY_NDP,			"proxy_ndp" },
  	{ CTL_INT,	NET_IPV6_ACCEPT_SOURCE_ROUTE,		"accept_source_route" },
  	{ CTL_INT,	NET_IPV6_ACCEPT_RA_FROM_LOCAL,		"accept_ra_from_local" },
+	{ CTL_INT,	NET_IPV6_ACCEPT_RA_MTU,			"accept_ra_mtu" },
  	{}
  };

Hm, afaik, the binary sysctl interface is deprecated and nothing should be adding entries there anymore. I believe you copied this over from commit d9333196572 ("ipv6: Allow accepting RA from local IP addresses.")? :/

#2 lore raw
Quoted 9 lines

-----Original Message-----
From: [email protected] [mailto:netdev- [email protected]] On Behalf Of Daniel Borkmann
Sent: Monday, January 19, 2015 3:11 PM
To: Harout Hedeshian
Cc: [email protected]
Subject: Re: [PATCH v2 net-next] net: ipv6: Add sysctl entry to disable

MTU

Quoted 28 lines

updates from RA

On 01/19/2015 10:36 PM, Harout Hedeshian wrote:
...

kernel/sysctl_binary.c static const struct bin_table

Quoted 17 lines
include/uapi/linux/sysctl.h +1 -0
index 0956373..45e4fcf 100644
@@ -570,6 +570,7 @@ enum {
  	NET_IPV6_PROXY_NDP=23,
  	NET_IPV6_ACCEPT_SOURCE_ROUTE=25,
  	NET_IPV6_ACCEPT_RA_FROM_LOCAL=26,
+	NET_IPV6_ACCEPT_RA_MTU=27,
  	__NET_IPV6_MAX
  };
 
kernel/sysctl_binary.c index renamed from kernel/sysctl_binary.c +0 -0

7e7746a..16091e5 100644

kernel/sysctl_binary.c +0 -0
@@ -523,6 +523,7 @@ static const struct bin_table

bin_net_ipv6_conf_var_table[] = {

kernel/sysctl_binary.c static const struct bin_table · line 523

Quoted 1 line
kernel/sysctl_binary.c +0 -0
  	{ CTL_INT,	NET_IPV6_PROXY_NDP,
	"proxy_ndp" },

kernel/sysctl_binary.c static const struct bin_table · line 524

Quoted 1 line
kernel/sysctl_binary.c +0 -0
  	{ CTL_INT,	NET_IPV6_ACCEPT_SOURCE_ROUTE,

"accept_source_route" },

kernel/sysctl_binary.c static const struct bin_table · line 525

Quoted 1 line
kernel/sysctl_binary.c +0 -0
  	{ CTL_INT,	NET_IPV6_ACCEPT_RA_FROM_LOCAL,
	"accept_ra_from_local" },
Quoted 8 lines

kernel/sysctl_binary.c static const struct bin_table · line 526

Quoted 1 line
kernel/sysctl_binary.c +1 -0
+	{ CTL_INT,	NET_IPV6_ACCEPT_RA_MTU,
	"accept_ra_mtu" },

kernel/sysctl_binary.c static const struct bin_table · line 528

Quoted 2 lines
kernel/sysctl_binary.c +0 -0
  	{}
  };

Hm, afaik, the binary sysctl interface is deprecated and nothing should be adding entries there anymore. I believe you copied this over from commit d9333196572 ("ipv6: Allow accepting RA from local IP addresses.")? :/

Hi Daniel,

Indeed, the patch is based on previous modifications to add sysctl/proc entries for IPv6 parameters. It is done this way to maintain consistency. Do you think we need a v3 without the changes to the sysctl_binary.c and corresponding changes in includes/uapi?

d9333196572 ("ipv6: Allow accepting RA from local IP addresses.") is as recent as June 2014.

Thanks,
Harout

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

#5 lore raw
In reply to Harout Hedeshian

On 01/19/2015 10:36 PM, Harout Hedeshian wrote:
...

Quoted 5 lines
Documentation/networking/ip-sysctl.txt +0 -0
index 85b0221..da50faa 100644

Documentation/networking/ip-sysctl.txt accept_ra_rtr_pref - BOOLEAN · line 1295

Quoted 9 lines
Documentation/networking/ip-sysctl.txt +6 -0
@@ -1287,6 +1287,13 @@ accept_ra_rtr_pref - BOOLEAN
  	Functional default: enabled if accept_ra is enabled.
  			    disabled if accept_ra is disabled.
 
+accept_ra_mtu - BOOLEAN
+	Apply the MTU value specified in RA option 5 (RFC4861). If
+	disabled, the MTU specified in the RA will be ignored.
+
+	Functional default: enabled if accept_ra is enabled.
+                            disabled if accept_ra is disabled.

Nit: please indent correctly with tab here.

Quoted 1 line
Documentation/networking/ip-sysctl.txt +1 -0
+

...

include/uapi/linux/ipv6.h enum { · line 174

Quoted 11 lines
include/uapi/linux/ipv6.h +1 -0
index 73cb02d..437a6a4 100644
@@ -169,6 +169,7 @@ enum {
  	DEVCONF_SUPPRESS_FRAG_NDISC,
  	DEVCONF_ACCEPT_RA_FROM_LOCAL,
  	DEVCONF_USE_OPTIMISTIC,
+	DEVCONF_ACCEPT_RA_MTU,
  	DEVCONF_MAX
  };

You also need a corresponding ipv6_store_devconf() entry, otherwise netlink dumps will always see this setting as disabled.

#3 lore raw
In reply to Harout Hedeshian

On 01/19/2015 11:42 PM, Harout Hedeshian wrote:
...

Quoted 4 lines

Indeed, the patch is based on previous modifications to add sysctl/proc entries for IPv6 parameters. It is done this way to maintain consistency. Do you think we need a v3 without the changes to the sysctl_binary.c and corresponding changes in includes/uapi?

Yep, please.

Quoted 2 lines

d9333196572 ("ipv6: Allow accepting RA from local IP addresses.") is as recent as June 2014.

Yeah, that looks wrong unfortunately.

maintainer
#4 lore raw
In reply to Harout Hedeshian

From: "Harout Hedeshian" <[email protected]>
Date: Mon, 19 Jan 2015 15:42:08 -0700

Quoted 4 lines

Indeed, the patch is based on previous modifications to add sysctl/proc entries for IPv6 parameters. It is done this way to maintain consistency. Do you think we need a v3 without the changes to the sysctl_binary.c and corresponding changes in includes/uapi?

Probably, yes.

#6 lore raw
In reply to Daniel Borkmann
Quoted 6 lines
Quoted 6 lines
include/uapi/linux/ipv6.h +0 -0
index 73cb02d..437a6a4 100644
@@ -169,6 +169,7 @@ enum {
  	DEVCONF_SUPPRESS_FRAG_NDISC,
Quoted 8 lines

include/uapi/linux/ipv6.h enum { · line 174

Quoted 5 lines
include/uapi/linux/ipv6.h +1 -0
  	DEVCONF_ACCEPT_RA_FROM_LOCAL,
  	DEVCONF_USE_OPTIMISTIC,
+	DEVCONF_ACCEPT_RA_MTU,
  	DEVCONF_MAX
  };

You also need a corresponding ipv6_store_devconf() entry, otherwise netlink dumps will always see this setting as disabled.

I added the following:

net/ipv6/addrconf.c +0 -0
index cdd70ed..5743293 100644
@@ -4378,6 +4378,7 @@ static inline void ipv6_store_devconf(struct

ipv6_devconf *cnf,

        array[DEVCONF_NDISC_NOTIFY] = cnf->ndisc_notify;
        array[DEVCONF_SUPPRESS_FRAG_NDISC] = cnf->suppress_frag_ndisc;
        array[DEVCONF_ACCEPT_RA_FROM_LOCAL] = cnf->accept_ra_from_local;

+ array[DEVCONF_ACCEPT_RA_MTU] = cnf->accept_ra_mtu;
}

I will upload v3 with the following changes:
- Fix tab indentation in documentation
- Remove changes from sysctl_binary.c and sysctl.h
- Fixed netlink dumps

-- Sanity test results below --

As a quick test, I wrote a very simple utility to dump out the raw contents of a RTM_NEWLINK event and tested it out on a UML instance by assigning some easily identifiable (but meaningless) value:

root@debian-wheezy-template:/mnt/host# ./a.out &
root@debian-wheezy-template:/mnt/host# cd /proc/sys/net/ipv6/conf/eth0
root@debian-wheezy-template:/proc/sys/net/ipv6/conf/eth0# echo 90 >
accept_ra_mtu #should print the letter 'Z'
root@debian-wheezy-template:/proc/sys/net/ipv6/conf/eth0# ifconfig eth0 up
&& ifconfig eth0 down
Read 1152 bytes from the socket
           0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
...<truncated>...
00000020| 09 00 03 00 65 74 68 30 00 00 00 00 08 00 0D 00 | ....eth0........
...<truncated>...
00000300| 00 00 00 00 00 00 00 00 5A 00 00 00 24 01 03 00 | ........Z...$...
root@debian-wheezy-template:/proc/sys/net/ipv6/conf/eth0# echo 89 >
accept_ra_mtu # should print the letter 'Y'
root@debian-wheezy-template:/proc/sys/net/ipv6/conf/eth0# ifconfig eth0 up
&& ifconfig eth0 down
Read 1152 bytes from the socket
           0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
...<truncated>...
00000020| 09 00 03 00 65 74 68 30 00 00 00 00 08 00 0D 00 | ....eth0........
...<truncated>...
00000300| 00 00 00 00 00 00 00 00 59 00 00 00 24 01 03 00 | ........Y...$...

Thanks,
Harout

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

#7 lore raw

On 01/20/2015 05:48 PM, Harout Hedeshian wrote:
...

Quoted 4 lines

I will upload v3 with the following changes:
- Fix tab indentation in documentation
- Remove changes from sysctl_binary.c and sysctl.h
- Fixed netlink dumps

Sounds good, thanks!