Practical UPnP in Linux

UPnP is a set of protocols that allow the automatic configuration of devices. One of those protocols, the Internet Gateway Device (IGD) protocol, allows software to configure routers for NAT traversal without user-intervention. In other words, with UPnP/IGD, the long and error-prone manual configuration for port-forwarding can be done automatically.

When tasks are done automatically, they are less visible to the user, and users are not comfortable that they are in charge of the process.

For the case of UPnP/IGD, we look into the open-source (LGPL) GUPnP library and the companion tool gupnp-universal-cp. You can install these from source (pick the packages gssdp, gupnp, gupnp-tools, and install in this order), or just install the package gupnp-tools from your package manager (for Debian and Ubuntu, these packages reside in Debian unstable).

Once you have installed the tool, you can start it from Application→Programming→UPnP Universal Control Point. This tool can be used for all things UPnP, however we focus on IGD here.

Screenshot of gupnp-universal-control-point, showing one UPnP router found.

Screenshot of gupnp-universal-control-point, showing one UPnP router found.

Once we start the UPnP Universal Control Point, we get the above screen. The tool sends discovery requests to the local network for UPnP-capable devices, and automatically the list gets populated. In the screenshot you can see that a router has been detected, and general information is shown.

If your router does not appear in the list and you are sure that UPnP is enabled on the device, then you might have hit on a known bug, Bug 1078 – Some devices may not work due to User-Agent field in requests. In this case, you need to make a minor edit in the source code and recompile.

Going through the available functions that the router exports, and allows to configure remotely.

Going through the available functions that the router exports, and allows to configure remotely.

Going through the available functions that the router exports, and allows to configure remotely.You can easily distinguish the functions that allow to perform port-forwarding. The one we have highlighted can be used to list the details of the currently active port-forwarding rulers. We right-click and select Invoke, which leads us to…

Action invocation in GUPnP Tool

Action invocation in GUPnP Tool

We just pressed the Invoke button, and since there was a rule with Index 0, the details get filled in for us. Here we can see that Skype has opened a port-forwarding rule for us; when someone from the Internet is connected to port 18210 of this router, the network connection is mapped to the local system with IP address 192.168.1.67.  In the mapping description it shows that Skype was the program that set this rule.

You would normally increase the Mapping Index and click on Invoke, in order to see any additional port mappings. Skype generally opens a few more ports, so there is more to see.

For all the shortcommings, UPnP/IGD is an important network configuration protocol. Due to the lack of an open-source library, applications had to implement UPnP support from scratch. Now with GUPnP, it is much easier to write UPnP-enabled applications.

UPnP/IGD is very important for applications such as Ekiga, Pidgin (file transfers!), Empathy, XChat (for DCC). This has to be done in order to raise the bar in terms of connectivity, and so that it Just works.

Permanent link to this article: https://blog.simos.info/practical-upnp-in-linux/

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.