Snap refresh over metered connections

Testing steps

Basic run through

Enable holding refreshes when on a metered connection:

$ snap set system refresh.metered=hold

Check if your connection is considered to be metered by NetworkManager. First determine the name of active connection:

$ nmcli c show --active
NAME     UUID                                  TYPE  DEVICE
G6_3577  31517f2b-25e7-4189-ab95-6d01f1482a67  wifi  wlp3s0

The host is connected to network G6_3577 which a hotspot on my phone. Check the human readable status (can be yes, no, unknown):

$ nmcli c show 'G6_3577' | grep connection.metered
connection.metered:                     unknown

If the status is unknown, try to determine the exact status reported by NetworkManager:

$ busctl --system get-property org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager org.freedesktop.NetworkManager Metered
u 3

NetworkManager reported status code 3. Refer to the list of status codes reported by NetworkManager:

NM_METERED_UNKNOWN = 0    The metered status is unknown
NM_METERED_YES = 1        Metered, the value was statically set
NM_METERED_NO = 2         Not metered, the value was statically set
NM_METERED_GUESS_YES = 3  Metered, the value was guessed
NM_METERED_GUESS_NO = 4   Not metered, the value was guessed

Status code 3 is NM_METERED_GUESS_YES. Only status codes 1 (NM_METERED_YES) and 3 (NM_METERED_GUESS_YES) will make snapd hold refreshes.

Leave it at that and wait for refresh to kick in. You should observe the following in snapd logs:

Sep 07 13:13:10 corsair snapd[8854]: autorefresh.go:186: DEBUG: Auto refresh disabled on metered connections
Sep 07 13:18:10 corsair snapd[8854]: autorefresh.go:255: DEBUG: Next refresh scheduled for 2018-09-07 13:18:10.159430386 +0200 CEST m=+1200.109631500.
Sep 07 13:18:10 corsair snapd[8854]: autorefresh.go:186: DEBUG: Auto refresh disabled on metered connections
...

My connection is not metered but should be

You can make NetworkManger mark any connection as metered using either command line or the graphical tools (eg. GNOME’s network settings).

Assume I have a network connection named wireless 5.8. NetworkManager did not correctly find out that the connection is metered.

$ nmcli c show --active
NAME            UUID                                  TYPE  DEVICE 
wireless 5.8    227b1939-f7c6-4769-8ac0-7393936eb1d3  wifi  wlp3s0 
$ nmcli c show 'wireless 5.8' |grep connection.metered
connection.metered:                     unknown
$ busctl --system get-property org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager org.freedesktop.NetworkManager Metered
u 4

Reported status code is 4 (NM_METERED_GUESS_NO).

The CLI way

Modify connection properties and mark it as metered:

$ nmcli c modify 'wireless 5.8' connection.metered true

Double check the reported status:

$ nmcli c show 'wireless 5.8' |grep connection.metered       
connection.metered:                     yes
$ busctl --system get-property org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager org.freedesktop.NetworkManager Metered
u 1

Reported status is 1 (NM_METERED_YES).

The GUI way

Head to GNOME network settings:

https://i.imgur.com/AimSeWM.png

Select your currently connected network settings:

https://i.imgur.com/nvcEany.png

And tick Restrict background data usage, then Apply.

Double check the reported status:

$ nmcli c show 'wireless 5.8' |grep connection.metered       
connection.metered:                     yes
$ busctl --system get-property org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager org.freedesktop.NetworkManager Metered
u 1

Reported status is 1 (NM_METERED_YES).

2 Likes