mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 07:48:10 +02:00
dhcp: detect NMIP4Config 'metered' flag based on ANDROID_METERED DHCP option
Some versions of Android's DHCP server send option 43 (Vendor specific information) with value "ANDROID_METERED" in Wi-Fi hotspot mode. Mark the NMIP4Config as metered when such option is received.
This commit is contained in:
parent
3c2f4a17f9
commit
1e39b2320d
3 changed files with 35 additions and 0 deletions
|
|
@ -226,6 +226,8 @@ lease_to_ip4_config (const char *iface,
|
|||
guint16 mtu;
|
||||
int r, num;
|
||||
guint64 end_time;
|
||||
uint8_t *data;
|
||||
gboolean metered = FALSE;
|
||||
|
||||
g_return_val_if_fail (lease != NULL, NULL);
|
||||
|
||||
|
|
@ -357,6 +359,11 @@ lease_to_ip4_config (const char *iface,
|
|||
g_string_free (l, TRUE);
|
||||
}
|
||||
|
||||
num = sd_dhcp_lease_get_vendor_specific (lease, &data);
|
||||
if (num > 0)
|
||||
metered = !!memmem (data, num, "ANDROID_METERED", STRLEN ("ANDROID_METERED"));
|
||||
nm_ip4_config_set_metered (ip4_config, metered);
|
||||
|
||||
return ip4_config;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -576,6 +576,9 @@ nm_dhcp_utils_ip4_config_from_options (int ifindex,
|
|||
g_strfreev (nis);
|
||||
}
|
||||
|
||||
str = g_hash_table_lookup (options, "vendor_encapsulated_options");
|
||||
nm_ip4_config_set_metered (ip4_config, str && strstr (str, "ANDROID_METERED"));
|
||||
|
||||
return ip4_config;
|
||||
|
||||
error:
|
||||
|
|
|
|||
|
|
@ -175,6 +175,30 @@ test_wins_options (void)
|
|||
g_hash_table_destroy (options);
|
||||
}
|
||||
|
||||
static void
|
||||
test_vendor_option_metered (void)
|
||||
{
|
||||
GHashTable *options;
|
||||
NMIP4Config *ip4_config;
|
||||
static const Option data[] = {
|
||||
{ "vendor_encapsulated_options", "ANDROID_METERED" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
options = fill_table (generic_options, NULL);
|
||||
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0);
|
||||
g_assert (ip4_config);
|
||||
g_assert (nm_ip4_config_get_metered (ip4_config) == FALSE);
|
||||
g_hash_table_destroy (options);
|
||||
|
||||
options = fill_table (generic_options, NULL);
|
||||
options = fill_table (data, options);
|
||||
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0);
|
||||
g_assert (ip4_config);
|
||||
g_assert (nm_ip4_config_get_metered (ip4_config) == TRUE);
|
||||
g_hash_table_destroy (options);
|
||||
}
|
||||
|
||||
static void
|
||||
ip4_test_route (NMIP4Config *ip4_config,
|
||||
guint route_num,
|
||||
|
|
@ -716,6 +740,7 @@ int main (int argc, char **argv)
|
|||
g_test_add_func ("/dhcp/ip4-missing-prefix-8", test_ip4_missing_prefix_8);
|
||||
g_test_add_func ("/dhcp/ip4-prefix-classless", test_ip4_prefix_classless);
|
||||
g_test_add_func ("/dhcp/client-id-from-string", test_client_id_from_string);
|
||||
g_test_add_func ("/dhcp/vendor-option-metered", test_vendor_option_metered);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue