Re: [PATCH net-next v4] net: ipv6: Make address flushing on ifdown optional

2015-10-11 Thread David Miller
From: David Ahern 
Date: Wed,  7 Oct 2015 08:17:39 -0700

> +static void fixup_managed_addr(struct inet6_dev *idev, struct inet6_ifaddr 
> *ifp)
> +{
> + if (!ifp->rt)
> + ifp->rt = addrconf_dst_alloc(idev, >addr, false);

This potentially leaves an error pointer dangling in ifp->rt
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH net-next v4] net: ipv6: Make address flushing on ifdown optional

2015-10-08 Thread Hannes Frederic Sowa
Hi David,

David Ahern  writes:

> 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:  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:  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:  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:  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
>
> Signed-off-by: David Ahern 
> ---
> It has been 8 months since the last version:
>http://lists.openwall.net/netdev/2015/02/12/33
>
> but wanted to revive it. This current version addresses the last round of
> comments and verifies all routes are deleted and re-added correctly
>
> Nicolas: I ran 'ip monitor' on a link down and link up cycle and you can
>  see the neighbor and route deletes on a down and routes added on
>  an up.
>
> 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| 91 
> +-
>  5 files changed, 87 insertions(+), 13 deletions(-)
>
> diff --git a/Documentation/networking/ip-sysctl.txt 
> b/Documentation/networking/ip-sysctl.txt
> index ebe94f2cab98..51c60f58f7ec 100644
> --- a/Documentation/networking/ip-sysctl.txt
> +++ b/Documentation/networking/ip-sysctl.txt
> @@ -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.
>  
> diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
> index 0ef2a97ccdb5..112a18940ab2 100644
> --- a/include/linux/ipv6.h
> +++ b/include/linux/ipv6.h
> @@ -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;
>  };
>  
> diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
> index 1c8b6820b694..f190a14148ab 100644
> --- a/include/net/if_inet6.h
> +++ b/include/net/if_inet6.h
> @@ -72,6 +72,7 @@ struct inet6_ifaddr {
>   int regen_count;
>  
>   booltokenized;
> + boolmanaged;

IMHO the naming of the bool is a bit too 

Re: [PATCH net-next v4] net: ipv6: Make address flushing on ifdown optional

2015-10-08 Thread David Ahern

Hi Hannes:

On 10/8/15 1:25 PM, Hannes Frederic Sowa wrote:

diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
index 1c8b6820b694..f190a14148ab 100644
--- a/include/net/if_inet6.h
+++ b/include/net/if_inet6.h
@@ -72,6 +72,7 @@ struct inet6_ifaddr {
int regen_count;

booltokenized;
+   boolmanaged;


IMHO the naming of the bool is a bit too vague. ;) Would you mind
renaming it to something like puuh... user_managed, non_autoconf,
manual_conf etc.?  'managed' seems so often used in the context of
temporary addresses, I first thought about that.

enum { USER_SPACE, KERNEL_AUTOCONF } managed_by;


I have no preference on naming; unless other preferences are stated I'll 
do v5 with it renamed to 'user_managed'.





@@ -2689,6 +2692,9 @@ static int inet6_addr_add(struct net *net, int ifindex,
valid_lft, prefered_lft);

if (!IS_ERR(ifp)) {
+   if (!expires)
+   ifp->managed = true;
+


This assumes that user space managed addresses don't time out. This is
in fact not true. I am not sure if it matters a lot, as most addresses
added from user space with a timeout most probably will be added because
of autoconf, but they are not managed by kernel autoconf. Not sure if we
want to make this more explicit, certainly it would avoid surprises.


Not exactly. I'm taking the easy way out and saying only addresses with 
no expiration time fall into the 'user managed' category and retained on 
an ifdown. Trying to accommodate lifetimes is a PITA. I mentioned that 
in the documentation:

  "static global addresses with no expiration time are not flushed"

Thanks for the review,
David
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH net-next v4] net: ipv6: Make address flushing on ifdown optional

2015-10-08 Thread Hannes Frederic Sowa
Hi David,

David Ahern  writes:
> On 10/8/15 1:25 PM, Hannes Frederic Sowa wrote:
>>> diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
>>> index 1c8b6820b694..f190a14148ab 100644
>>> --- a/include/net/if_inet6.h
>>> +++ b/include/net/if_inet6.h
>>> @@ -72,6 +72,7 @@ struct inet6_ifaddr {
>>> int regen_count;
>>>
>>> booltokenized;
>>> +   boolmanaged;
>>
>> IMHO the naming of the bool is a bit too vague. ;) Would you mind
>> renaming it to something like puuh... user_managed, non_autoconf,
>> manual_conf etc.?  'managed' seems so often used in the context of
>> temporary addresses, I first thought about that.
>>
>> enum { USER_SPACE, KERNEL_AUTOCONF } managed_by;
>
> I have no preference on naming; unless other preferences are stated I'll 
> do v5 with it renamed to 'user_managed'.

I think this is more appropriate. Thanks!

>>> @@ -2689,6 +2692,9 @@ static int inet6_addr_add(struct net *net, int 
>>> ifindex,
>>> valid_lft, prefered_lft);
>>>
>>> if (!IS_ERR(ifp)) {
>>> +   if (!expires)
>>> +   ifp->managed = true;
>>> +
>>
>> This assumes that user space managed addresses don't time out. This is
>> in fact not true. I am not sure if it matters a lot, as most addresses
>> added from user space with a timeout most probably will be added because
>> of autoconf, but they are not managed by kernel autoconf. Not sure if we
>> want to make this more explicit, certainly it would avoid surprises.
>
> Not exactly. I'm taking the easy way out and saying only addresses with 
> no expiration time fall into the 'user managed' category and retained on 
> an ifdown. Trying to accommodate lifetimes is a PITA. I mentioned that 
> in the documentation:
>"static global addresses with no expiration time are not flushed"

Hmm, I thought a call to addrconf_verify on up would be sufficient but
haven't looked into that too closely.

Anyway, this logic actually only makes sense with addresses which don't
expire.

Thanks,
Hannes
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH net-next v4] net: ipv6: Make address flushing on ifdown optional

2015-10-07 Thread David Ahern
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:  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:  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:  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:  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

Signed-off-by: David Ahern 
---
It has been 8 months since the last version:
   http://lists.openwall.net/netdev/2015/02/12/33

but wanted to revive it. This current version addresses the last round of
comments and verifies all routes are deleted and re-added correctly

Nicolas: I ran 'ip monitor' on a link down and link up cycle and you can
 see the neighbor and route deletes on a down and routes added on
 an up.

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| 91 +-
 5 files changed, 87 insertions(+), 13 deletions(-)

diff --git a/Documentation/networking/ip-sysctl.txt 
b/Documentation/networking/ip-sysctl.txt
index ebe94f2cab98..51c60f58f7ec 100644
--- a/Documentation/networking/ip-sysctl.txt
+++ b/Documentation/networking/ip-sysctl.txt
@@ -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.
 
diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
index 0ef2a97ccdb5..112a18940ab2 100644
--- a/include/linux/ipv6.h
+++ b/include/linux/ipv6.h
@@ -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;
 };
 
diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
index 1c8b6820b694..f190a14148ab 100644
--- a/include/net/if_inet6.h
+++ b/include/net/if_inet6.h
@@ -72,6 +72,7 @@ struct inet6_ifaddr {
int regen_count;
 
booltokenized;
+   boolmanaged;
 
struct rcu_head rcu;
struct in6_addr peer_addr;
diff --git a/include/uapi/linux/ipv6.h b/include/uapi/linux/ipv6.h
index 38b4fef20219..7c514f7cd209 100644
--- a/include/uapi/linux/ipv6.h
+++ b/include/uapi/linux/ipv6.h
@@ -174,6 +174,7 @@ enum {

Re: [PATCH net-next v4] net: ipv6: Make address flushing on ifdown optional

2015-10-07 Thread Sowmini Varadhan
On Wed, Oct 7, 2015 at 11:17 AM, David Ahern  wrote:
> Currently, all ipv6 addresses are flushed when the interface is configured
> down, including global, static addresses:
  :
>
> 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:

does src addr selection also need to be modified to know if/when it can/cannot
use this static address as a source addr? Or does the TENTATIVE flag
make it Do The Right Thing per rfc 3484?

--Sowmini
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH net-next v4] net: ipv6: Make address flushing on ifdown optional

2015-10-07 Thread David Ahern

On 10/7/15 9:43 AM, Sowmini Varadhan wrote:

On Wed, Oct 7, 2015 at 11:17 AM, David Ahern  wrote:

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

   :


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:


does src addr selection also need to be modified to know if/when it can/cannot
use this static address as a source addr? Or does the TENTATIVE flag
make it Do The Right Thing per rfc 3484?



When the device is set 'down' (admin state) all routes (including cached 
ones) for the device are cleared so there should not be any way to 
select the source address that is saved. i.e, ipv6_dev_get_saddr() 
should not get invoked for the device.


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html