From 599da6fd02039e8b5b78953d2c517a62e5a08a4a Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 6 Mar 2018 14:34:02 +0000 Subject: devices: Set NM_METERED_GUESS_YES for Bluetooth PANU/DUN connections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bluetooth tethering using DUN or PANU is a common way to expose a metered 3G or 4G connection from a phone to a laptop. We deliberately ignore NAP connections, which is where we’re sharing internet from the laptop to another device. We could also set GUESS_YES for WiMAX connections, but NetworkManager doesn’t support them any more. Add a comment about that. Signed-off-by: Philip Withnall https://bugzilla.gnome.org/show_bug.cgi?id=794120 --- src/devices/nm-device.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 2044f5511f..ce02292079 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -12363,10 +12363,27 @@ nm_device_update_metered (NMDevice *self) value = NM_METERED_GUESS_YES; } - /* Otherwise look at connection type */ + /* Otherwise look at connection type. For Bluetooth, we look at the type of + * Bluetooth sharing: for PANU/DUN (where we are receiving internet from + * another device) we set GUESS_YES; for NAP (where we are sharing internet + * to another device) we set GUESS_NO. We ignore WiMAX here as it’s no + * longer supported by NetworkManager. */ + if (value == NM_METERED_INVALID && + nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) { + NMSettingBluetooth *bt = nm_connection_get_setting_bluetooth (connection); + const gchar *bt_type = (bt != NULL) ? nm_setting_bluetooth_get_connection_type (bt) : NULL; + + if ( nm_streq0 (bt_type, NM_SETTING_BLUETOOTH_TYPE_PANU) + || nm_streq0 (bt_type, NM_SETTING_BLUETOOTH_TYPE_DUN)) + value = NM_METERED_GUESS_YES; + else + value = NM_METERED_GUESS_NO; + } + if (value == NM_METERED_INVALID) { if ( nm_connection_is_type (connection, NM_SETTING_GSM_SETTING_NAME) - || nm_connection_is_type (connection, NM_SETTING_CDMA_SETTING_NAME)) + || nm_connection_is_type (connection, NM_SETTING_CDMA_SETTING_NAME) + || nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) value = NM_METERED_GUESS_YES; else value = NM_METERED_GUESS_NO; -- cgit v1.2.1