Dual IPv4 and IPv6 support in Flask applications

℡╲_俬逩灬. 提交于 2019-12-05 07:40:20

What happens is that the operating system automatically attaches incoming IPv4 requests to the listening IPv6 socket. The IPv4 address is mapped to an IPv6 address by prefixing it with ::ffff:. Therefore an incoming IPv4 connection from 127.0.0.1 looks like it is coming from IPv6 address ::ffff:127.0.0.1.

From the client's point of view it is talking to an IPv4 server. The client cannot tell the difference. From the server's point of view everybody is connecting using IPv6. The operating system performs the mapping between IPv4 packets and the IPv6 software.

The effect of this is that you can develop software without manually having to deal with dual stack programming. All software can be written for IPv6 and deal with all addresses as IPv6 addresses. This can simplify the code (no need to deal with having both a listening IPv4 and a listening IPv6 sockets etc.) while still providing a full dual-stack experience to the 'outside'.

So your service is fully dual-stack as seen from outside your system. In the application itself you will see the whole world represented with IPv6 addresses though, like you show in your log file. That usually doesn't cause any problems. It might affect the way you handle ACLs, logging and other things like that though.

Unfortunately, while Linux uses mapped IPv4 addresses to qualify "::", this does not work on several other IPv6 stacks, such as on Microsoft Windows. "::" will bind to the IPv6 address family, as for security reasons, Windows and other IPv6 stack implementors have decided to against mapping IPv4 addresses into the IPv6 address space, unless an application especially signals to do so. The rationale here, as far as I understand the discussion, is that otherwise unexpected IPv4 connectivity would happen that could undermine ACLs, or other application-layer security mechanisms.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!