Search code examples
linuxdnsipv6uclibc

Fallback ipv4 mechanism when ipv6 communication failed


I have some problem to understand an issue which concerns fallback mechanism in network communication.

Setup : Embedded device (mips) with uclibc and busybox

I am a client with ipv6 adress. I need to contact a service on xxx.com. When I test the hostname of my service with nslookup. I got two result, an ipv4 and an ipv6 address. So I got two ways to contact my server.

In my understanding, I got this result thanks to the dns mechanism which read my resolv.conf file and contact dns server by socket to get ip which are associated with the hostname requested

test : I run ping6 -I eth0 myservice.com

I watch this command thanks to strace. The result is :

execve("/bin/ping6", ["ping6", "-I", "eth0", "myservice"], [/* 7 vars */]) = 0
...
open("/etc/resolv.conf", O_RDONLY)
...
socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.20.20")}, 28) = 0
   -> **192.168.20.20** is my dns server ip fill in resolv.conf
...
send(3, "myservice.."..., 33, 0) = 33
poll([{fd=3, events=POLLIN}], 1, 5000)  = 1 ([{fd=3, revents=POLLIN}])
recv(3, "myservice.."..., 512, MSG_DONTWAIT) = 285
...
sendto(3, "\200\0\0\0iD\0\0\335\2130\7\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 64, 0, {sa_family=AF_INET6, sin6_port=htons(0), inet_pton(AF_INET6, "**Y:Y:Y:Y:Y:Y:Y:Y**", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=2}, 28) = -1 ENETUNREACH (Network is unreachable)
write(2, "ping6: sendto: Network is unreac"..., 38) = 38
exit_group(1)    

For some reason, I cannot contact the server myservice by ipv6 Y:Y:Y:Y:Y:Y:Y:Y. In my opinion, there are a fallback mechanism which allow me to contact my server by ipv4 when ipv6 way failed. Unfortunately, as you can see, after the ipv6 try, I cannot see any tries on ipv4 way.

Question : Is it normal to get this current behavior about this ? Where must be implement this mechanism of fallback ? Inside my busybox on ping code side. Inside uclibc thanks to the dns mechanism ? Somewhere else ?

Thanks, Arthur.


Solution

  • That's probably because you're using ping6, which will only do IPv6 (and ping only does IPv4).

    The implementation of the fallback mechanism will be up to you. You already understand how to retrieve multiple addresses from a name lookup, so now all that's left is to try each of those until you manage to connect.