Skip to contentSkip to conversation

net: ipv6: Make address flushing on ifdown optional

PATCH Superseded David Ahern 4 participants 11 messages Oct 12, 2015 – Oct 15, 2015

Subsystems (4)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 net: ipv6: Make address flushing on ifdown optional

Currently, all ipv6 addresses are flushed when the interface is configured down, including global, static addresses:

    $ ip -6 addr add dev eth1 2000:11:1:1::1/64
    $ ip addr show dev eth1
    3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
        link/ether 02:04:11:22:33:01 brd ff:ff:ff:ff:ff:ff
        inet6 2000:11:1:1::1/64 scope global tentative
           valid_lft forever preferred_lft forever
    $ ip link set dev eth1 up
    $ ip link set dev eth1 down
    $ ip addr show dev eth1
    3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
        link/ether 02:04:11:22:33:01 brd ff:ff:ff:ff:ff:ff

Add a new sysctl to make this behavior optional. The new setting defaults to flush all addresses to maintain backwards compatibility. When the setting is reset global addresses with no expire times are not flushed:

    $ echo 0 > /proc/sys/net/ipv6/conf/eth1/flush_addr_on_down
    $ ip -6 addr add dev eth1 2000:11:1:1::1/64
    $ ip addr show dev eth1
    3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
        link/ether 02:04:11:22:33:01 brd ff:ff:ff:ff:ff:ff
        inet6 2000:11:1:1::1/64 scope global tentative
           valid_lft forever preferred_lft forever
    $ ip link set dev eth1 up
    $ ip link set dev eth1 down
    $ ip addr show dev eth1
    3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
        link/ether 02:04:11:22:33:01 brd ff:ff:ff:ff:ff:ff
        inet6 2000:11:1:1::1/64 scope global
           valid_lft forever preferred_lft forever
        inet6 fe80::4:11ff:fe22:3301/64 scope link
           valid_lft forever preferred_lft forever

---
v5:
- renamed managed to user_managed as requested by Hannes
- handle addrconf_dst_alloc failure and cleanup ifp as noted by Dave -- tested by faking allocation failure
- minor ordering changes in addrconf_ifdown() to handle changes under lock

v4:
- rebased to top of tree
- updated to clear all routes on admin down and re-added on admin up
- verified the route tables (main and local) on a link down have *no* remnants of the configured, global address. On a link up all routes are restored -- multicast, linklocal, local routes and connected.

v3:
- fix local variable ordering and comment style per Dave's comment
- consistency in DEVCONF naming per Brian Haley's comment
- added entry to Documentation/networking/ip-sysctl.txt

v2:
- only keep static addresses as suggested by Hannes
- added new managed flag to track configured addresses
- on ifdown do not remove from configured address from inet6_addr_lst
- on ifdown reset the TENTATIVE flag and set state to DAD so that DAD is redone when link is brought up again

 Documentation/networking/ip-sysctl.txt |   6 ++
 include/linux/ipv6.h                   |   1 +
 include/net/if_inet6.h                 |   1 +
 include/uapi/linux/ipv6.h              |   1 +
 net/ipv6/addrconf.c                    | 124 +++++++++++++++++++++++++++++----
 5 files changed, 118 insertions(+), 15 deletions(-)
Documentation/networking/ip-sysctl.txt +6 -0
index ebe94f2cab98..51c60f58f7ec 100644
@@ -1432,6 +1432,12 @@ dad_transmits - INTEGER
 	The amount of Duplicate Address Detection probes to send.
 	Default: 1
 
+flush_addr_on_down - BOOLEAN
+	Flush all IPv6 addresses on an interface down event. If disabled
+	static global addresses with no expiration time are not flushed.
+
+	Default: enabled
+
 forwarding - INTEGER
 	Configure interface-specific Host/Router behaviour.
 
include/linux/ipv6.h +1 -0
index 0ef2a97ccdb5..112a18940ab2 100644
@@ -60,6 +60,7 @@ struct ipv6_devconf {
 		struct in6_addr secret;
 	} stable_secret;
 	__s32		use_oif_addrs_only;
+	__s32		flush_addr_on_down;
 	void		*sysctl;
 };
 
include/net/if_inet6.h +1 -0
index 1c8b6820b694..01ba6a286a4b 100644
@@ -72,6 +72,7 @@ struct inet6_ifaddr {
 	int			regen_count;
 
 	bool			tokenized;
+	bool			user_managed;
 
 	struct rcu_head		rcu;
 	struct in6_addr		peer_addr;
include/uapi/linux/ipv6.h +1 -0
index 38b4fef20219..7c514f7cd209 100644
@@ -174,6 +174,7 @@ enum {
 	DEVCONF_USE_OIF_ADDRS_ONLY,
 	DEVCONF_ACCEPT_RA_MIN_HOP_LIMIT,
 	DEVCONF_IGNORE_ROUTES_WITH_LINKDOWN,
+	DEVCONF_FLUSH_ADDR_ON_DOWN,
 	DEVCONF_MAX
 };
 
net/ipv6/addrconf.c +109 -15

214 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#1 lore raw

From: David Ahern <[email protected]>
Date: Mon, 12 Oct 2015 09:33:07 -0700

Quoted 2 lines

Currently, all ipv6 addresses are flushed when the interface is configured down, including global, static addresses:

...

Quoted 3 lines

Add a new sysctl to make this behavior optional. The new setting defaults to flush all addresses to maintain backwards compatibility. When the setting is reset global addresses with no expire times are not flushed:

...

Quoted 1 line

Here is what I really don't like about these changes: the failure semantics are terrible.

If I add an address or a route, and some memory allocation fails, I get a notification and see that my operation did not succeed.

But here, my routes can fail to be added during an ifup and all I will get, at best, is a kernel log message.

This places a serious disconnect between what the user asked for and making sure he finds out directly that his operation did not really fully succeed.

In fact, this failure handling here during ifup leaves the interface in a partially configured state.

There are really two ways to deal with this properly:

1) Propagate the failure back through the notifiers and fail the ifup completely when the addrconf_dst_alloc() fails.

2) On ifdown, stash the objects away somewhere so that memory allocation is not necessary on ifup.

Neither are really smooth approaches, but they have the attribute that they give the user clean behavior and semantics.

#2 lore raw

Hello,

Quoted 21 lines · David Miller

From: David Ahern <[email protected]>
Date: Mon, 12 Oct 2015 09:33:07 -0700

Quoted 2 lines

Currently, all ipv6 addresses are flushed when the interface is configured down, including global, static addresses:

...

Quoted 3 lines

Add a new sysctl to make this behavior optional. The new setting defaults to flush all addresses to maintain backwards compatibility. When the setting is reset global addresses with no expire times are not flushed:

...

Quoted 1 line

Here is what I really don't like about these changes: the failure semantics are terrible.

If I add an address or a route, and some memory allocation fails, I get a notification and see that my operation did not succeed.

But here, my routes can fail to be added during an ifup and all I will get, at best, is a kernel log message.

Quoted 6 lines

This places a serious disconnect between what the user asked for and making sure he finds out directly that his operation did not really fully succeed.

In fact, this failure handling here during ifup leaves the interface in a partially configured state.

Agreed, it would be better.

Quoted 7 lines

There are really two ways to deal with this properly:

1) Propagate the failure back through the notifiers and fail the ifup completely when the addrconf_dst_alloc() fails.

2) On ifdown, stash the objects away somewhere so that memory allocation is not necessary on ifup.

In regard to error propagation I think 2) is the only viable option. I don't think why you shouldn't be able to simply remove the ip6_rt_put after the ip6_del_rt and keep the dst_entry hanging there and later reinsert.

Quoted 2 lines

Neither are really smooth approaches, but they have the attribute that they give the user clean behavior and semantics.

On another node:

This sysctl is on my list to be enabled soon by default by any systemd based distribution. For that reason, could you maybe remove all the unlikely annotations from your code. It really doesn't matter in configuration code, because it is not performance critical and in my opinion just distracts.

Thanks,
Hannes

#3 lore raw

Le 14/10/2015 11:34, Hannes Frederic Sowa a écrit :
[sni]

Quoted 2 lines

This sysctl is on my list to be enabled soon by default by any systemd based distribution. For that reason, could you maybe remove all the

I'm not sure to understand why we add a sysctl then. Or at least, why the linux default value is different from all standard distrib. I will be like rp_filter :/

#4 lore raw
Quoted 8 lines · Nicolas Dichtel

Le 14/10/2015 11:34, Hannes Frederic Sowa a écrit :
[sni]

Quoted 2 lines

This sysctl is on my list to be enabled soon by default by any systemd based distribution. For that reason, could you maybe remove all the

I'm not sure to understand why we add a sysctl then. Or at least, why the linux
default value is different from all standard distrib. I will be like rp_filter :/

The difference is that people upgrade (in case of fedora they get a .rpmnew file) or install a distribution and don't wonder or have assumptions about old behavior. In case companies integrate kernel in products/appliances without a way to manage those sysctls we cannot simply change them as this would break assumptions for them. I think those are two different cases.

Bye,
Hannes

maintainer
#5 lore raw

From: Hannes Frederic Sowa <[email protected]>
Date: Wed, 14 Oct 2015 13:03:41 +0200

Quoted 10 lines · Nicolas Dichtel
Quoted 8 lines · Hannes Frederic Sowa

[sni]

Quoted 2 lines

This sysctl is on my list to be enabled soon by default by any systemd based distribution. For that reason, could you maybe remove all the

I'm not sure to understand why we add a sysctl then. Or at least, why the linux
default value is different from all standard distrib. I will be like rp_filter :/

Quoted 6 lines

The difference is that people upgrade (in case of fedora they get a .rpmnew file) or install a distribution and don't wonder or have assumptions about old behavior. In case companies integrate kernel in products/appliances without a way to manage those sysctls we cannot simply change them as this would break assumptions for them. I think those are two different cases.

The thing that is similar is that people set rp_filter inappropriately (no end host should have that knob enabled, ever, it's totally unnecesary). And the risk here is similar, distribution X will set it so Y will say "we probably should set it too even though we really don't understand it fully".

I really hate situations like this.

#6 lore raw
Quoted 9 lines · David Miller

From: Hannes Frederic Sowa <[email protected]>
Date: Wed, 14 Oct 2015 13:03:41 +0200

Quoted 6 lines

The difference is that people upgrade (in case of fedora they get a .rpmnew file) or install a distribution and don't wonder or have assumptions about old behavior. In case companies integrate kernel in products/appliances without a way to manage those sysctls we cannot simply change them as this would break assumptions for them. I think those are two different cases.

Quoted 7 lines

The thing that is similar is that people set rp_filter inappropriately (no end host should have that knob enabled, ever, it's totally unnecesary). And the risk here is similar, distribution X will set it so Y will say "we probably should set it too even though we really don't understand it fully".

I really hate situations like this.

I can bring up the rp_filter setting, too. It currently gets unconditional set to strict mode in systemd on all interfaces.

The question is, if we should care about people enabling forwarding by simply toggling the sysctl forwarding knob? Essentially in the kernel we could provide two sysctl knobs, one for forwarding and one for local reception. So people following the guidelines how to enable forwarding could automatically have rp_filter enabled while host mode does not because we leave the forwarding rp_filter setting enabled. This at the same time seems unnecessary complex and maybe we should simply talk to distributions. ;)

What do you think?

Bye,
Hannes

maintainer
#7 lore raw

From: Hannes Frederic Sowa <[email protected]>
Date: Wed, 14 Oct 2015 14:14:05 +0200

Quoted 2 lines

I can bring up the rp_filter setting, too. It currently gets unconditional set to strict mode in systemd on all interfaces.

Sigh...

Quoted 10 lines

The question is, if we should care about people enabling forwarding by simply toggling the sysctl forwarding knob? Essentially in the kernel we could provide two sysctl knobs, one for forwarding and one for local reception. So people following the guidelines how to enable forwarding could automatically have rp_filter enabled while host mode does not because we leave the forwarding rp_filter setting enabled. This at the same time seems unnecessary complex and maybe we should simply talk to distributions. ;)

What do you think?

We could make rp_filter only apply when something more than default and subnet routes are configured. Another bypass might be when only one interface other than loopback is up and enabled for ipv4.

#8 lore raw
In reply to Hannes Frederic Sowa
Quoted 38 lines · Hannes Frederic Sowa

Hello,

Quoted 21 lines · David Miller

From: David Ahern <[email protected]>
Date: Mon, 12 Oct 2015 09:33:07 -0700

Quoted 2 lines

Currently, all ipv6 addresses are flushed when the interface is configured down, including global, static addresses:

...

Quoted 3 lines

Add a new sysctl to make this behavior optional. The new setting defaults to flush all addresses to maintain backwards compatibility. When the setting is reset global addresses with no expire times are not flushed:

...

Quoted 1 line

Here is what I really don't like about these changes: the failure semantics are terrible.

If I add an address or a route, and some memory allocation fails, I get a notification and see that my operation did not succeed.

But here, my routes can fail to be added during an ifup and all I will get, at best, is a kernel log message.

Quoted 6 lines

This places a serious disconnect between what the user asked for and making sure he finds out directly that his operation did not really fully succeed.

In fact, this failure handling here during ifup leaves the interface in a partially configured state.

Agreed, it would be better.

Quoted 5 lines

There are really two ways to deal with this properly:

1) Propagate the failure back through the notifiers and fail the ifup completely when the addrconf_dst_alloc() fails.

Quoted 7 lines
Quoted 2 lines

2) On ifdown, stash the objects away somewhere so that memory allocation is not necessary on ifup.

In regard to error propagation I think 2) is the only viable option. I don't think why you shouldn't be able to simply remove the ip6_rt_put after the ip6_del_rt and keep the dst_entry hanging there and later reinsert.

I don't agree with stashing it. IPv4 code does not do that and handling the stashed routes makes the implementation more complex than needed.

This latest patch makes IPv6 static addresses on par with IPv4, including error paths. On admin link down IPv4 code removes local and connected routes. On admin link up they are reinserted. Error paths are not handled. ie., any memory allocations or insertion failures are silently ignored.

As for this IPv6 patch the only real failure scenario is ENOMEM in the dst_alloc.

David

maintainer
#9 lore raw

From: David Ahern <[email protected]>
Date: Wed, 14 Oct 2015 10:09:59 -0600

Quoted 2 lines

This latest patch makes IPv6 static addresses on par with IPv4, including error paths.

I don't agree with ipv4's behavior... and just because ipv4 does something poorly doesn't mean we get a free pass to replicate that lazyness in ipv6.

#10 lore raw
Quoted 10 lines · David Miller

From: David Ahern <[email protected]>
Date: Wed, 14 Oct 2015 10:09:59 -0600

Quoted 2 lines

This latest patch makes IPv6 static addresses on par with IPv4, including error paths.

I don't agree with ipv4's behavior... and just because ipv4 does something poorly doesn't mean we get a free pass to replicate that lazyness in ipv6.

As I stated this patch makes IPv6 on par with IPv4 with regards to saving the address and lack of error handling back to the user should a failure happen on a link up. Yes, it is best to give the user notification of a failure, but step back for a moment and look at the bigger picture:

At best the address is saved and restored on a link up (the expected outcome for 99.999999...% of the time). At worst the address is removed because the prefix route fails a memory allocation and the user is not notified. But that is exactly what happens today - the address is dropped and the user has to restore it.

As for the 1 failure path -- it's a GFP_ATOMIC memory allocation failure. Frankly if that happens lack of an address on an interface is the least of the user's problems.

As for the options to fix this existing shortcoming:

1. The existing call_netdevice_notifiers infra does not allow a notifier to 'fail' the transaction and roll it back or even to give the user an error message.

2. Stashing the prefix route has its merits but it has to deal with error paths as well. What if the address is deleted? What if the mask is changed while the device is a down state? What if the device is deleted? Sure, handle those cases but what other paths are missing from that list?

Both paths introduce a lot of complexity all b/c we want to save the address on a link and restore the route on a link up.

Why not take this as a start point that at least does the right thing almost every time?

David