# BUG: IPv6: ipv6\_bind fails on implicitly-assigned address

- From: ko-zu \<hidden\>
- Date: 2013-03-30 21:29:45 
- List: netdev
- Page: https://ratatoskr.run/netdev/2013/03/10919046
- Thread: https://ratatoskr.run/netdev/2013/03/10919046/t.md

```text
Current Any-IP support for IPv6, introduced with this commit
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=ab79ad14a2d51e95f0ac3cef7cd116a57089ba82
, allows to assign whole subnet to host but current implemantation
does not allow binding assigned address to socket without IP_FREEBIND
sockopt.
When an ipv6 address was assigned as Any-IP, ipv6_bind() fails with
EADDRNOTAVAIL error because ipv6_chk_addr() does not consider Any-IP
as locally hosted.

To reproduce this bug,

# assign whole subnet to host
ip -4 route add local 192.0.2.0/24 dev lo
ip -6 route add local 2001:db8::/32 dev lo

python -c '
import socket
IP_FREEBIND = 15

print "IPv4 without IP_FREEBIND"
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("192.0.2.123", 10000))

print "IPv6 with IP_FREEBIND"
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_IP, IP_FREEBIND, 1)
s.bind(("2001:db8::1234", 10000))

print "IPv6 without IP_FREEBIND"
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
s.bind(("2001:db8::5678", 10000))
print "should success without error."
'
```
