netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] ipv6: enable anycast addresses as source addresses for datagrams
@ 2014-01-21 16:01 Francois-Xavier Le Bail
  2014-01-22  0:16 ` Hannes Frederic Sowa
  0 siblings, 1 reply; 2+ messages in thread
From: Francois-Xavier Le Bail @ 2014-01-21 16:01 UTC (permalink / raw)
  To: netdev; +Cc: Hannes Frederic Sowa, David Stevens, David Miller

This change allows to consider an anycast address valid as source address
when given via an IPV6_PKTINFO or IPV6_2292PKTINFO ancillary data item.
So, when sending a datagram with ancillary data, the unicast and anycast
addresses are handled in the same way.

- Adds ipv6_chk_acast_addr_src() to check if an anycast address is link-local
  on given interface or is global.
- Uses it in ip6_datagram_send_ctl().

Signed-off-by: Francois-Xavier Le Bail <fx.lebail@yahoo.com>
---
v2: Consideration of Hannes's review:
    - Same behaviour for anycast and unicast.
    - No need for a new socket option.

Typical usage :
A server uses IPV6_RECVPKTINFO socket option to get ancillary data with
recvmsg() and can use sendmsg() to reply with anycast adress as source address
in the same way it does for unicast.

 include/net/addrconf.h |    5 +++--
 net/ipv6/anycast.c     |   11 +++++++++++
 net/ipv6/datagram.c    |    4 +++-
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index 66c4a44..50e39a8 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -205,8 +205,9 @@ void ipv6_sock_ac_close(struct sock *sk);
 int ipv6_dev_ac_inc(struct net_device *dev, const struct in6_addr *addr);
 int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr);
 bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
-				const struct in6_addr *addr);
-
+			 const struct in6_addr *addr);
+bool ipv6_chk_acast_addr_src(struct net *net, struct net_device *dev,
+			     const struct in6_addr *addr);
 
 /* Device notifier */
 int register_inet6addr_notifier(struct notifier_block *nb);
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 5a80f15..d3a6e2d 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -383,6 +383,17 @@ bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
 	return found;
 }
 
+/*	check if this anycast address is link-local on given interface or
+ *	is global
+ */
+bool ipv6_chk_acast_addr_src(struct net *net, struct net_device *dev,
+			     const struct in6_addr *addr)
+{
+	if (ipv6_addr_type(addr) & IPV6_ADDR_LINKLOCAL)
+		return ipv6_chk_acast_dev(dev, addr);
+	else
+		return ipv6_chk_acast_addr(net, NULL, addr);
+}
 
 #ifdef CONFIG_PROC_FS
 struct ac6_iter_state {
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index cd8699b..2615197 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -689,7 +689,9 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk,
 				int strict = __ipv6_addr_src_scope(addr_type) <= IPV6_ADDR_SCOPE_LINKLOCAL;
 				if (!(inet_sk(sk)->freebind || inet_sk(sk)->transparent) &&
 				    !ipv6_chk_addr(net, &src_info->ipi6_addr,
-						   strict ? dev : NULL, 0))
+						   strict ? dev : NULL, 0) &&
+				    !ipv6_chk_acast_addr_src(net, dev,
+							     &src_info->ipi6_addr))
 					err = -EINVAL;
 				else
 					fl6->saddr = src_info->ipi6_addr;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next v2] ipv6: enable anycast addresses as source addresses for datagrams
  2014-01-21 16:01 [PATCH net-next v2] ipv6: enable anycast addresses as source addresses for datagrams Francois-Xavier Le Bail
@ 2014-01-22  0:16 ` Hannes Frederic Sowa
  0 siblings, 0 replies; 2+ messages in thread
From: Hannes Frederic Sowa @ 2014-01-22  0:16 UTC (permalink / raw)
  To: Francois-Xavier Le Bail; +Cc: netdev, David Stevens, David Miller

On Tue, Jan 21, 2014 at 05:01:10PM +0100, Francois-Xavier Le Bail wrote:
> diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
> index 5a80f15..d3a6e2d 100644
> --- a/net/ipv6/anycast.c
> +++ b/net/ipv6/anycast.c
> @@ -383,6 +383,17 @@ bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
>  	return found;
>  }
>  
> +/*	check if this anycast address is link-local on given interface or
> + *	is global
> + */
> +bool ipv6_chk_acast_addr_src(struct net *net, struct net_device *dev,
> +			     const struct in6_addr *addr)
> +{
> +	if (ipv6_addr_type(addr) & IPV6_ADDR_LINKLOCAL)
> +		return ipv6_chk_acast_dev(dev, addr);
> +	else
> +		return ipv6_chk_acast_addr(net, NULL, addr);
> +}

You need to do the check with ipv6_chk_acast_addr in both cases, as only
ipv6_chk_acast_addr does a rcu_read_lock and it is needed for the dereference
of inet6_dev (__in6_dev_get is not safe in ipv6_chk_acast_dev without
rcu_read_lock).

Otherwise I am fine with this patch, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-01-22  0:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-21 16:01 [PATCH net-next v2] ipv6: enable anycast addresses as source addresses for datagrams Francois-Xavier Le Bail
2014-01-22  0:16 ` Hannes Frederic Sowa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).