mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 07:30:10 +01:00
core: add 'metered' flag to NMIP4Config
Some DHCP servers send specific options to give a hint that clients should avoid unneeded data usage. Add a metered flag to NMIP4Config to keep track of this information.
This commit is contained in:
parent
f0aebfd746
commit
68db65b727
2 changed files with 34 additions and 0 deletions
|
|
@ -59,6 +59,7 @@ typedef struct {
|
|||
NMIPConfigSource mtu_source;
|
||||
int ifindex;
|
||||
gint64 route_metric;
|
||||
gboolean metered;
|
||||
} NMIP4ConfigPrivate;
|
||||
|
||||
/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */
|
||||
|
|
@ -607,6 +608,10 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src)
|
|||
for (i = 0; i < nm_ip4_config_get_num_wins (src); i++)
|
||||
nm_ip4_config_add_wins (dst, nm_ip4_config_get_wins (src, i));
|
||||
|
||||
/* metered flag */
|
||||
nm_ip4_config_set_metered (dst, nm_ip4_config_get_metered (dst) ||
|
||||
nm_ip4_config_get_metered (src));
|
||||
|
||||
g_object_thaw_notify (G_OBJECT (dst));
|
||||
}
|
||||
|
||||
|
|
@ -1117,6 +1122,12 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
|
|||
has_minor_changes = TRUE;
|
||||
}
|
||||
|
||||
/* metered */
|
||||
if (src_priv->metered != dst_priv->metered) {
|
||||
dst_priv->metered = src_priv->metered;
|
||||
has_minor_changes = TRUE;
|
||||
}
|
||||
|
||||
/* config_equal does not compare *all* the fields, therefore, we might have has_minor_changes
|
||||
* regardless of config_equal. But config_equal must correspond to has_relevant_changes. */
|
||||
g_assert (config_equal == !has_relevant_changes);
|
||||
|
|
@ -1192,6 +1203,7 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
|
|||
}
|
||||
|
||||
g_message (" n-dflt: %d", nm_ip4_config_get_never_default (config));
|
||||
g_message (" mtrd: %d", (int) nm_ip4_config_get_metered (config));
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
@ -1906,6 +1918,24 @@ nm_ip4_config_get_mtu_source (const NMIP4Config *config)
|
|||
|
||||
/******************************************************************/
|
||||
|
||||
void
|
||||
nm_ip4_config_set_metered (NMIP4Config *config, gboolean metered)
|
||||
{
|
||||
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
||||
|
||||
priv->metered = !!metered;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_ip4_config_get_metered (const NMIP4Config *config)
|
||||
{
|
||||
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
||||
|
||||
return priv->metered;
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
static inline void
|
||||
hash_u32 (GChecksum *sum, guint32 n)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -161,6 +161,10 @@ void nm_ip4_config_set_mtu (NMIP4Config *config, guint32 mtu, NMIPConfigSource s
|
|||
guint32 nm_ip4_config_get_mtu (const NMIP4Config *config);
|
||||
NMIPConfigSource nm_ip4_config_get_mtu_source (const NMIP4Config *config);
|
||||
|
||||
/* Metered */
|
||||
void nm_ip4_config_set_metered (NMIP4Config *config, gboolean metered);
|
||||
gboolean nm_ip4_config_get_metered (const NMIP4Config *config);
|
||||
|
||||
void nm_ip4_config_hash (const NMIP4Config *config, GChecksum *sum, gboolean dns_only);
|
||||
gboolean nm_ip4_config_equal (const NMIP4Config *a, const NMIP4Config *b);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue