libnm-core: add 'metered' property to NMSettingConnection

Add a 'metered' enum property to NMSettingConnection with possible
values: unknown,yes,no. The value indicates the presence of limitations
in the amount of traffic flowing through the connection.
This commit is contained in:
Beniamino Galvani 2015-04-27 17:45:53 +02:00
parent f208e7030f
commit 6f647fe689
4 changed files with 57 additions and 0 deletions

View file

@ -74,6 +74,7 @@ typedef struct {
char *zone;
GSList *secondaries; /* secondary connections to activate with the base connection */
guint gateway_ping_timeout;
NMMetered metered;
} NMSettingConnectionPrivate;
enum {
@ -92,6 +93,7 @@ enum {
PROP_SLAVE_TYPE,
PROP_SECONDARIES,
PROP_GATEWAY_PING_TIMEOUT,
PROP_METERED,
LAST_PROP
};
@ -738,6 +740,23 @@ nm_setting_connection_get_gateway_ping_timeout (NMSettingConnection *setting)
return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->gateway_ping_timeout;
}
/**
* nm_setting_connection_get_metered:
* @setting: the #NMSettingConnection
*
* Returns: the #NMSettingConnection:metered property of the setting.
*
* Since: 1.2
**/
NMMetered
nm_setting_connection_get_metered (NMSettingConnection *setting)
{
g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting),
NM_METERED_UNKNOWN);
return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->metered;
}
static void
_set_error_missing_base_setting (GError **error, const char *type)
{
@ -899,6 +918,18 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
}
if (priv->metered != NM_METERED_UNKNOWN &&
priv->metered != NM_METERED_YES &&
priv->metered != NM_METERED_NO) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("metered value %d is not valid"), priv->metered);
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME,
NM_SETTING_CONNECTION_METERED);
return FALSE;
}
/* *** errors above here should be always fatal, below NORMALIZABLE_ERROR *** */
if (!priv->uuid) {
@ -1129,6 +1160,9 @@ set_property (GObject *object, guint prop_id,
case PROP_GATEWAY_PING_TIMEOUT:
priv->gateway_ping_timeout = g_value_get_uint (value);
break;
case PROP_METERED:
priv->metered = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1199,6 +1233,9 @@ get_property (GObject *object, guint prop_id,
case PROP_GATEWAY_PING_TIMEOUT:
g_value_set_uint (value, priv->gateway_ping_timeout);
break;
case PROP_METERED:
g_value_set_enum (value, priv->metered);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1567,4 +1604,19 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingConnection:metered:
*
* Whether the connection is metered.
*
* Since: 1.2
**/
g_object_class_install_property
(object_class, PROP_METERED,
g_param_spec_enum (NM_SETTING_CONNECTION_METERED, "", "",
NM_TYPE_METERED,
NM_METERED_UNKNOWN,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}

View file

@ -58,6 +58,7 @@ G_BEGIN_DECLS
#define NM_SETTING_CONNECTION_SLAVE_TYPE "slave-type"
#define NM_SETTING_CONNECTION_SECONDARIES "secondaries"
#define NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT "gateway-ping-timeout"
#define NM_SETTING_CONNECTION_METERED "metered"
/**
* NMSettingConnection:
@ -119,6 +120,8 @@ void nm_setting_connection_remove_secondary (NMSettingConnection *set
gboolean nm_setting_connection_remove_secondary_by_value (NMSettingConnection *setting, const char *sec_uuid);
guint32 nm_setting_connection_get_gateway_ping_timeout (NMSettingConnection *setting);
NM_AVAILABLE_IN_1_2
NMMetered nm_setting_connection_get_metered (NMSettingConnection *setting);
G_END_DECLS

View file

@ -1967,6 +1967,7 @@ test_connection_diff_a_only (void)
{ NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_CONNECTION_SECONDARIES, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_CONNECTION_METERED, NM_SETTING_DIFF_RESULT_IN_A },
{ NULL, NM_SETTING_DIFF_RESULT_UNKNOWN }
} },
{ NM_SETTING_WIRED_SETTING_NAME, {

View file

@ -853,6 +853,7 @@ global:
nm_metered_get_type;
nm_setting_802_1x_check_cert_scheme;
nm_setting_bridge_get_multicast_snooping;
nm_setting_connection_get_metered;
nm_setting_ip_config_add_dns_option;
nm_setting_ip_config_clear_dns_options;
nm_setting_ip_config_get_dns_option;