Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I recently got a static IPv6 /56 prefix of my own from Freenet6, and am trying to allow applications to bind arbitrary addresses in the prefix. I modified the tunnel creation script that gogoc uses in order to assign both the client address (here we'll call it 2001:5c0:1000::cccc/128) and the entire subnet I have allocated (here called 2001:5c0:2000:5800::/56) to tun and tun:1, respectively. I can bind an application to listen on 2001:5c0::cccc or 2001:5c0:5800:: just fine, and using IPv6 open port testers indicates that the connection is succeeding.

However, the dilemma lies in that I am unable to bind an address like 2001:5c0:2000:5800:1111:2222:3333:4444, which is part of the subnet I assigned to tun:1, getting EADDRNOTAVAIL as an error code. socat reads:

2014/05/10 12:12:06 socat[16940] E bind(3, {AF=10 [2001:5c0:2000:5800:1111:2222:3333:4444]:9876}, 28): Cannot assign requested address

The application I wish to use does not support IP_FREEBIND or IP_TRANSPARENT.

Is there a kernel setting I can use to implicitly free-bind sockets? Or perhaps a way to intercept socket creation from a given process, and attach socket options to that creation?

ip addr:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether 04:7d:7b:XX:XX:XX brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 9c:b7:0d:XX:XX:XX brd ff:ff:ff:ff:ff:ff
5: wlan1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:c0:ff:XX:XX:XX brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.8/24 brd 192.168.2.255 scope global wlan1
       valid_lft forever preferred_lft forever
    inet6 fe80::2c0:ffff:feff:70d1/64 scope link 
       valid_lft forever preferred_lft forever
11: tun: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1280 qdisc pfifo_fast state UNKNOWN group default qlen 500
    link/none 
    inet6 2001:5c0:1103:5800::/56 scope global 
       valid_lft forever preferred_lft forever
    inet6 2001:5c0:1000:b::5225/128 scope global 
       valid_lft forever preferred_lft forever
share|improve this question
    
I think it's you can't bind specific address if it's not assigned to some interface. Could you post what does ip addr print out? –  TNW May 10 at 16:35
    
@TNW It's assigned, implicitly, as I understand. I assigned a subnet that contains that address to that interface (as the address itself, not the subnet mask) –  hexafraction May 10 at 16:47
    
You don't assign prefixes to interfaces, you assign addresses (from the prefix that belongs to that link) to interfaces. Out of curiosity: why do you want 4722366482869645213696 addresses on one interface? –  Sander Steffann May 10 at 19:45

1 Answer 1

up vote 3 down vote accepted

The part of your interface config, namely inet6 2001:5c0:1103:5800::/56 in ip addr listing, means two things:

  1. 2001:5c0:1103:5800:: is assigned to your interface - you can ping6 it to find out it's valid, whereas 2001:5c0:1103:5800::1 won't respond
  2. /56 serves for routing purposes, and means only that if you want to send something to the network with that prefix (inet6 2001:5c0:1103:5800::/56), it should go out using the tun interface. You can find that out using ip -6 route.

For how to do what you want, you can check out this answer.

Now, why did the binds work? It's because you can use a network address in bind call, and it will bind your socket to interface(s) which have access to the given network (specifically binding to 0.0.0.0 binds to all interfaces, rather than to all of the IPs in the Internet).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.