pupnp: The library does not work on IPv6 only networks
I’m using a network with only the IPv6 stack enabled (single stack setup). There is no IPv4 stack available or supported. On this network the initialization with UpnpInit2
always fails with error message:
UpnpInit2(interface=ens1, port=51515) return code: UPNP_E_INVALID_INTERFACE (-121)
I cloned the current pupnp and compiled it. It has this version:
upnp$ grep UPNP_VERSION_STRING upnp/inc/upnpconfig.h
#define UPNP_VERSION_STRING "1.14.1"
The test machine is running Debian Bullseye but I have the issue also seen on Debian Buster. These are the interfaces on the test machine:
upnp$ ip -brief address
lo UNKNOWN 127.0.0.1/8 ::1/128
ens1 UP 2003:d5:272d:d100:5054:ff:fe40:50f6/64 fe80::5054:ff:fe40:50f6/64
The interface ens1 works absolutely perfect, e.g.:
upnp$ ping6 -nc3 google.com
PING google.com(2a00:1450:4001:80f::200e) 56 data bytes
64 bytes from 2a00:1450:4001:80f::200e: icmp_seq=1 ttl=118 time=9.67 ms
64 bytes from 2a00:1450:4001:80f::200e: icmp_seq=2 ttl=118 time=8.39 ms
64 bytes from 2a00:1450:4001:80f::200e: icmp_seq=3 ttl=118 time=8.38 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 8.383/8.813/9.669/0.605 ms
upnp$ curl -6 google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
To verify that the issue is by pupnp I have compiled this tiny test program:
~$ cat testipv6.cpp
#include <stdio.h>
#include <upnp/upnp.h>
#include <upnp/upnptools.h> // UpnpGetErrorMessage
#include <upnp/upnpdebug.h> // UpnpSetLogFileNames
int main()
{
constexpr char INTERFACE[] = "ens1";
unsigned short PORT = 51515;
constexpr char ErrFileName[] = "/dev/stderr";
constexpr char InfoFileName[] = "/dev/stdout";
int rc;
UpnpSetLogFileNames(ErrFileName, InfoFileName);
rc = UpnpInit2(INTERFACE, PORT);
printf("UpnpInit2(interface=%s, port=%d) return code: %s (%d)\n",
INTERFACE, PORT, UpnpGetErrorMessage(rc), rc);
}
It always returns the error message shown above. Can this be fixed, please?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 23 (1 by maintainers)
@mrjimenez I dug up the debugger (gdb) and had a session tonight. This is what I found so far:
There is a point
/* Cycle through the list of interfaces looking for IP addresses. */
(src/api/upnpapi.c:3939). This loop can only check for IPv4 addresses due to the used struct ifreq restricted to AF_INET addresses (IPv4). This loop finds only interface “lo” of course, because it is the only one with an IPv4 address 127.0.0.1.But as checked by the loop, this is not a valid interface for multicasting in this context. So this loop terminates with
close (LocalSock);
(src/api/upnpapi.c:4012) and returns withUPNP_E_INVALID_INTERFACE
. That is what we see.The same would also happen if there was no IPv4 interface at all.
The next part of the program after the IPv4 loop where IPv6 addresses are checked is never reached. You have to ensure that to fix the bug. Because I’m stuck with my project it would be nice if you can publish a patch 😃
PS: your compiling script is very helpful, thanks.