Skip to content

Commit 7c90cc2

Browse files
fxlbdavem330
authored andcommitted
ipv6: enable anycast addresses as source addresses for datagrams
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 <[email protected]> Acked-by: Hannes Frederic Sowa <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent eb97768 commit 7c90cc2

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

include/net/addrconf.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ void ipv6_sock_ac_close(struct sock *sk);
205205
int ipv6_dev_ac_inc(struct net_device *dev, const struct in6_addr *addr);
206206
int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr);
207207
bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
208-
const struct in6_addr *addr);
209-
208+
const struct in6_addr *addr);
209+
bool ipv6_chk_acast_addr_src(struct net *net, struct net_device *dev,
210+
const struct in6_addr *addr);
210211

211212
/* Device notifier */
212213
int register_inet6addr_notifier(struct notifier_block *nb);

net/ipv6/anycast.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,17 @@ bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
383383
return found;
384384
}
385385

386+
/* check if this anycast address is link-local on given interface or
387+
* is global
388+
*/
389+
bool ipv6_chk_acast_addr_src(struct net *net, struct net_device *dev,
390+
const struct in6_addr *addr)
391+
{
392+
return ipv6_chk_acast_addr(net,
393+
(ipv6_addr_type(addr) & IPV6_ADDR_LINKLOCAL ?
394+
dev : NULL),
395+
addr);
396+
}
386397

387398
#ifdef CONFIG_PROC_FS
388399
struct ac6_iter_state {

net/ipv6/datagram.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,9 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk,
699699
int strict = __ipv6_addr_src_scope(addr_type) <= IPV6_ADDR_SCOPE_LINKLOCAL;
700700
if (!(inet_sk(sk)->freebind || inet_sk(sk)->transparent) &&
701701
!ipv6_chk_addr(net, &src_info->ipi6_addr,
702-
strict ? dev : NULL, 0))
702+
strict ? dev : NULL, 0) &&
703+
!ipv6_chk_acast_addr_src(net, dev,
704+
&src_info->ipi6_addr))
703705
err = -EINVAL;
704706
else
705707
fl6->saddr = src_info->ipi6_addr;

0 commit comments

Comments
 (0)