Reporting active network connection within container


#1

Is there a recommended way to view the currently active network connection in the Docker container (i.e. whether wired ethernet is used, which access point is used)? My team was doing this with nmcli before using Resin, but installing network-manager in the container is not recommended according to the documentation (also we tried it and it broke network connectivity on our devices).


#4

Hi,

have you tried looking at the nodes in /sys/class/net/?

Example with wired plugged in:
eth0/carrier:1
eth0/operstate:unknown

Best,
ilias


#5

Thanks, I can see the network adapters and their status in that folder. I can’t find any info on the access point name that is used though, do you know if that is exposed anywhere in these folders?

I see that iwconfig or iwlist can be used to get access point information in Linux. Is it OK to install these tools in a Resin container, or is it not recommended like nmcli?


#6

Those tools should be OK to install in the container. Alternatively, you could use the Network Manager D-Bus API to fetch the list of connections and see which is active. You can find the documentation for the API here:

https://developer.gnome.org/NetworkManager/stable/spec.html

Specifically, it seems that the properties on the org.freedesktop.NetworkManager interface like ActiveConnections and PrimaryConnection are what you are looking for.


#7

Hi, @aric-mira

I can confirm that after an apt-get install wireless-tools I was able to use iwconfig.

Alternativelly, after an apt-get install dbus I was able to query dbus with something like the following:

DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \
dbus-send \
  --system \
  --print-reply \
  --reply-timeout=2000 \
  --type=method_call \
  --dest=org.freedesktop.NetworkManager \
  /org/freedesktop/NetworkManager  \
  org.freedesktop.DBus.Properties.GetAll \
  string:"org.freedesktop.NetworkManager"

In case you also need some code for dbus parsing, you can take a look at the other dbus related repos
https://github.com/resin-io-playground?utf8=✓&q=dbus&type=&language=

Let us know whether this works for your use case.