Disable snap refresh on metered connections

by Christian Lønaas, 2018-08-10

In the previous post, I mentioned that I kept an eye on the network traffic on my LTE connection on my laptop. I've been bitten hard (It updated IntelliJ IDEA, several hundred megabytes) by snap's autorefresh feature, which have seemed hard/impossible to disable. There's been config options for only allowing updates at certain times etc., but the feature I've been crying for, to be able to disable it when on a metered connection, has been missing in action. Until now!

$ snap set system refresh.metered=hold

Easy as that!

(Found it here - otherwise not much info about this around the web) UPDATE 2020-02-11: Link is dead, but this is in the official documentation here

Seems quite recent, introduced in snapd 2.33, which was released on 2018-06-25.

So how does it work? How do I confirm that it's actually working? No feedback when running the command, nothing in syslog.

Hmm.

Only one thing to do; use the source, Luke!

From the source, I can see that it reads the DBus property org.freedesktop.NetworkManager.Metered for a value, and decides what to do based on that.

const (
        // https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMMetered
        NetworkManagerMeteredUnknown  = 0
        NetworkManagerMeteredYes      = 1
        NetworkManagerMeteredNo       = 2
        NetworkManagerMeteredGuessYes = 3
        NetworkManagerMeteredGuessNo  = 4
)

If it's a NetworkManagerMeteredYes or NetworkManagerMeteredGuessYes, it will disable autorefresh.

I then read the DBus property with the tool D-Feet, and confirmed that the value returned was '3' when on LTE, and '4' on Wi-fi. Wow, this actually seems to work!

While I would prefer more information about this (regular users will NEVER find it, and it is default off), and more logging, I'll take this for now!

Network stats without ifconfig

by Christian Lønaas, 2018-08-08

Sometimes I get curious about how much data a network interface has transferred. Actually, I get curious quite frequently after I got an LTE modem for my laptop.

Usually, I just use ifconfig:

$ ifconfig wlp3s0
wlp3s0    Link encap:Ethernet  HWaddr 00:15:00:7e:af:bd
          inet addr:192.168.0.165  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::4c15:ef76:132e:768/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20922893 errors:0 dropped:0 overruns:0 frame:0
          TX packets:20916831 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:15370202859 (15.3 GB)  TX bytes:13050802316 (13.0 GB)

With Ubuntu 18.04, however, there is no ifconfig. Yes, I know I can install it, but I wanted to learn how I should be doing it.

I came up with this, using the 'ip' command:

$ ip -s -h addr show wlp3s0
3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:00:7e:af:bd brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.165/24 brd 192.168.0.255 scope global dynamic wlp3s0
       valid_lft 5439sec preferred_lft 5439sec
    inet6 fe80::4c15:ef76:132e:768/64 scope link
       valid_lft forever preferred_lft forever
    RX: bytes  packets  errors  dropped overrun mcast
    15.4G      20.9M    0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    13.1G      20.9M    0       0       0       0

Meh. This is gonna take some time to get used to.

Simplifying port forwarding with LXD

by Christian Lønaas, 2016-09-03

LXD containers are brilliant, but lacks an easy way to forward ports from the containers to the host. One can use iptables manually, of course, but I really missed something easy like Docker. To try and remedy this, I have conjured up a little bash script. With this script, you can add, delete and list port forwarding rules.

It's a bit rough around the edges, but maybe I'll tidy it up a bit some day.

Read on for the script and examples.