summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-08-27 19:57:24 +0200
committerThomas Haller <thaller@redhat.com>2014-11-07 15:19:06 +0100
commitce7fc351dbfca50eaf231779697fcdf4d7a2d04a (patch)
tree015c550841c4eaf3aba23aa9c914a524fed08ad1
parent627ad6f8056137244c6671eb18670ee227acb788 (diff)
downloadNetworkManager-ce7fc351dbfca50eaf231779697fcdf4d7a2d04a.tar.gz
libnm: add NMSettingIPConfig:route-metric
https://bugzilla.gnome.org/show_bug.cgi?id=735512 https://bugzilla.redhat.com/show_bug.cgi?id=663730 Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--libnm-core/nm-setting-ip-config.c49
-rw-r--r--libnm-core/nm-setting-ip-config.h3
-rw-r--r--libnm-core/tests/test-general.c3
-rwxr-xr-xlibnm-util/generate-setting-docs.py6
-rw-r--r--libnm-util/libnm-util.ver2
-rw-r--r--libnm-util/nm-setting-ip4-config.c50
-rw-r--r--libnm-util/nm-setting-ip4-config.h4
-rw-r--r--libnm-util/nm-setting-ip6-config.c50
-rw-r--r--libnm-util/nm-setting-ip6-config.h4
-rw-r--r--libnm-util/tests/test-general.c1
-rw-r--r--libnm/libnm.ver1
11 files changed, 171 insertions, 2 deletions
diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c
index 8d0504e2b1..0a781798fe 100644
--- a/libnm-core/nm-setting-ip-config.c
+++ b/libnm-core/nm-setting-ip-config.c
@@ -1058,6 +1058,7 @@ typedef struct {
GPtrArray *dns_search; /* array of domain name strings */
GPtrArray *addresses; /* array of NMIPAddress */
GPtrArray *routes; /* array of NMIPRoute */
+ gint64 route_metric;
char *gateway;
gboolean ignore_auto_routes;
gboolean ignore_auto_dns;
@@ -1075,6 +1076,7 @@ enum {
PROP_ADDRESSES,
PROP_GATEWAY,
PROP_ROUTES,
+ PROP_ROUTE_METRIC,
PROP_IGNORE_AUTO_ROUTES,
PROP_IGNORE_AUTO_DNS,
PROP_DHCP_HOSTNAME,
@@ -1672,6 +1674,25 @@ nm_setting_ip_config_clear_routes (NMSettingIPConfig *setting)
}
/**
+ * nm_setting_ip_config_get_route_metric:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns the value contained in the #NMSettingIPConfig:route-metric
+ * property.
+ *
+ * Returns: the route metric that is used for routes that don't explicitly
+ * specify a metric. See #NMSettingIPConfig:route-metric for more details.
+ **/
+gint64
+nm_setting_ip_config_get_route_metric (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), -1);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->route_metric;
+}
+
+
+/**
* nm_setting_ip_config_get_ignore_auto_routes:
* @setting: the #NMSettingIPConfig
*
@@ -1984,6 +2005,9 @@ set_property (GObject *object, guint prop_id,
(NMUtilsCopyFunc) nm_ip_route_dup,
(GDestroyNotify) nm_ip_route_unref);
break;
+ case PROP_ROUTE_METRIC:
+ priv->route_metric = g_value_get_int64 (value);
+ break;
case PROP_IGNORE_AUTO_ROUTES:
priv->ignore_auto_routes = g_value_get_boolean (value);
break;
@@ -2039,6 +2063,9 @@ get_property (GObject *object, guint prop_id,
(NMUtilsCopyFunc) nm_ip_route_dup,
(GDestroyNotify) nm_ip_route_unref));
break;
+ case PROP_ROUTE_METRIC:
+ g_value_set_int64 (value, priv->route_metric);
+ break;
case PROP_IGNORE_AUTO_ROUTES:
g_value_set_boolean (value, nm_setting_ip_config_get_ignore_auto_routes (setting));
break;
@@ -2174,6 +2201,28 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *setting_class)
G_PARAM_STATIC_STRINGS));
/**
+ * NMSettingIPConfig:route-metric:
+ *
+ * The default metric for routes that don't explicitly specify a metric.
+ * The default value -1 means that the metric is choosen automatically
+ * based on the device type.
+ * The metric applies to dynamic routes, manual (static) routes that
+ * don't have an explicit metric setting, address prefix routes, and
+ * the default route.
+ * Note that for IPv6, the kernel accepts accepts zero (0) but coerces
+ * it to 1024 (user default). Hence, setting this value to zero effectively
+ * mean setting it to 1024.
+ * For IPv4, zero is a regular value for the metric.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_ROUTE_METRIC,
+ g_param_spec_int64 (NM_SETTING_IP_CONFIG_ROUTE_METRIC, "", "",
+ -1, G_MAXUINT32, -1,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
* NMSettingIPConfig:ignore-auto-routes:
*
* When #NMSettingIPConfig:method is set to "auto" and this property to
diff --git a/libnm-core/nm-setting-ip-config.h b/libnm-core/nm-setting-ip-config.h
index fba226c331..12763fa857 100644
--- a/libnm-core/nm-setting-ip-config.h
+++ b/libnm-core/nm-setting-ip-config.h
@@ -136,6 +136,7 @@ void nm_ip_route_set_attribute (NMIPRoute *route,
#define NM_SETTING_IP_CONFIG_ADDRESSES "addresses"
#define NM_SETTING_IP_CONFIG_GATEWAY "gateway"
#define NM_SETTING_IP_CONFIG_ROUTES "routes"
+#define NM_SETTING_IP_CONFIG_ROUTE_METRIC "route-metric"
#define NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES "ignore-auto-routes"
#define NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS "ignore-auto-dns"
#define NM_SETTING_IP_CONFIG_DHCP_HOSTNAME "dhcp-hostname"
@@ -204,6 +205,8 @@ gboolean nm_setting_ip_config_remove_route_by_value (NMSettingIPConfig
NMIPRoute *route);
void nm_setting_ip_config_clear_routes (NMSettingIPConfig *setting);
+gint64 nm_setting_ip_config_get_route_metric (NMSettingIPConfig *setting);
+
gboolean nm_setting_ip_config_get_ignore_auto_routes (NMSettingIPConfig *setting);
gboolean nm_setting_ip_config_get_ignore_auto_dns (NMSettingIPConfig *setting);
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c
index 09e05856c8..2c77726654 100644
--- a/libnm-core/tests/test-general.c
+++ b/libnm-core/tests/test-general.c
@@ -1701,9 +1701,10 @@ test_connection_diff_a_only (void)
{ NM_SETTING_IP_CONFIG_ADDRESSES, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP_CONFIG_GATEWAY, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP_CONFIG_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_ROUTE_METRIC, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP_CONFIG_NEVER_DEFAULT, NM_SETTING_DIFF_RESULT_IN_A },
diff --git a/libnm-util/generate-setting-docs.py b/libnm-util/generate-setting-docs.py
index 69b115a7e1..463d0f2ec7 100755
--- a/libnm-util/generate-setting-docs.py
+++ b/libnm-util/generate-setting-docs.py
@@ -48,7 +48,11 @@ identifier_key = '{%s}identifier' % ns_map['c']
nick_key = '{%s}nick' % ns_map['glib']
symbol_prefix_key = '{%s}symbol-prefix' % ns_map['c']
-constants = { 'TRUE': 'TRUE', 'FALSE': 'FALSE', 'NULL': 'NULL' }
+constants = {
+ 'TRUE': 'TRUE',
+ 'FALSE': 'FALSE',
+ 'G_MAXUINT32': 'G_MAXUINT32',
+ 'NULL': 'NULL' }
setting_names = {}
def init_constants(girxml):
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index c6fc0d7f69..794cc87f43 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -367,6 +367,7 @@ global:
nm_setting_ip4_config_get_num_dns_searches;
nm_setting_ip4_config_get_num_routes;
nm_setting_ip4_config_get_route;
+ nm_setting_ip4_config_get_route_metric;
nm_setting_ip4_config_get_type;
nm_setting_ip4_config_new;
nm_setting_ip4_config_remove_address;
@@ -402,6 +403,7 @@ global:
nm_setting_ip6_config_get_num_dns_searches;
nm_setting_ip6_config_get_num_routes;
nm_setting_ip6_config_get_route;
+ nm_setting_ip6_config_get_route_metric;
nm_setting_ip6_config_get_type;
nm_setting_ip6_config_new;
nm_setting_ip6_config_privacy_get_type;
diff --git a/libnm-util/nm-setting-ip4-config.c b/libnm-util/nm-setting-ip4-config.c
index f7f709ec54..c7a730769c 100644
--- a/libnm-util/nm-setting-ip4-config.c
+++ b/libnm-util/nm-setting-ip4-config.c
@@ -76,6 +76,7 @@ typedef struct {
GSList *dns_search; /* list of strings */
GSList *addresses; /* array of NMIP4Address */
GSList *routes; /* array of NMIP4Route */
+ gint64 route_metric;
gboolean ignore_auto_routes;
gboolean ignore_auto_dns;
char *dhcp_client_id;
@@ -92,6 +93,7 @@ enum {
PROP_DNS_SEARCH,
PROP_ADDRESSES,
PROP_ROUTES,
+ PROP_ROUTE_METRIC,
PROP_IGNORE_AUTO_ROUTES,
PROP_IGNORE_AUTO_DNS,
PROP_DHCP_CLIENT_ID,
@@ -689,6 +691,26 @@ nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting)
}
/**
+ * nm_setting_ip4_config_get_route_metric:
+ * @setting: the #NMSettingIP4Config
+ *
+ * Returns the value contained in the #NMSettingIP4Config:route-metric
+ * property.
+ *
+ * Returns: the route metric that is used for IPv4 routes that don't explicitly
+ * specify a metric. See #NMSettingIP4Config:route-metric for more details.
+ *
+ * Since: 1.0
+ **/
+gint64
+nm_setting_ip4_config_get_route_metric (NMSettingIP4Config *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), -1);
+
+ return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->route_metric;
+}
+
+/**
* nm_setting_ip4_config_get_ignore_auto_routes:
* @setting: the #NMSettingIP4Config
*
@@ -1018,6 +1040,9 @@ set_property (GObject *object, guint prop_id,
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
priv->routes = nm_utils_ip4_routes_from_gvalue (value);
break;
+ case PROP_ROUTE_METRIC:
+ priv->route_metric = g_value_get_int64 (value);
+ break;
case PROP_IGNORE_AUTO_ROUTES:
priv->ignore_auto_routes = g_value_get_boolean (value);
break;
@@ -1070,6 +1095,9 @@ get_property (GObject *object, guint prop_id,
case PROP_ROUTES:
nm_utils_ip4_routes_to_gvalue (priv->routes, value);
break;
+ case PROP_ROUTE_METRIC:
+ g_value_set_int64 (value, priv->route_metric);
+ break;
case PROP_IGNORE_AUTO_ROUTES:
g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_routes (setting));
break;
@@ -1276,6 +1304,28 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
G_PARAM_STATIC_STRINGS));
/**
+ * NMSettingIP4Config:route-metric:
+ *
+ * The default metric for routes that don't explicitly specify a metric.
+ * The default value -1 means that the metric is choosen automatically
+ * based on the device type.
+ * The metric applies to dynamic routes, manual (static) routes that
+ * don't have an explicit metric setting, address prefix routes, and
+ * the default route.
+ * As the linux kernel accepts zero (0) as a valid metric, zero is
+ * a valid value.
+ *
+ * Since: 1.0
+ **/
+ g_object_class_install_property
+ (object_class, PROP_ROUTE_METRIC,
+ g_param_spec_int64 (NM_SETTING_IP4_CONFIG_ROUTE_METRIC, "", "",
+ -1, G_MAXUINT32, -1,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
* NMSettingIP4Config:ignore-auto-routes:
*
* When the method is set to "auto" and this property to %TRUE,
diff --git a/libnm-util/nm-setting-ip4-config.h b/libnm-util/nm-setting-ip4-config.h
index 1b7c23072d..6e9a9a227a 100644
--- a/libnm-util/nm-setting-ip4-config.h
+++ b/libnm-util/nm-setting-ip4-config.h
@@ -60,6 +60,7 @@ GQuark nm_setting_ip4_config_error_quark (void);
#define NM_SETTING_IP4_CONFIG_DNS_SEARCH "dns-search"
#define NM_SETTING_IP4_CONFIG_ADDRESSES "addresses"
#define NM_SETTING_IP4_CONFIG_ROUTES "routes"
+#define NM_SETTING_IP4_CONFIG_ROUTE_METRIC "route-metric"
#define NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES "ignore-auto-routes"
#define NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS "ignore-auto-dns"
#define NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID "dhcp-client-id"
@@ -214,6 +215,9 @@ NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting, NMIP4Route *route);
void nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting);
+NM_AVAILABLE_IN_1_0
+gint64 nm_setting_ip4_config_get_route_metric (NMSettingIP4Config *setting);
+
gboolean nm_setting_ip4_config_get_ignore_auto_routes (NMSettingIP4Config *setting);
gboolean nm_setting_ip4_config_get_ignore_auto_dns (NMSettingIP4Config *setting);
const char * nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting);
diff --git a/libnm-util/nm-setting-ip6-config.c b/libnm-util/nm-setting-ip6-config.c
index ec90fd2bd7..64a81136a9 100644
--- a/libnm-util/nm-setting-ip6-config.c
+++ b/libnm-util/nm-setting-ip6-config.c
@@ -75,6 +75,7 @@ typedef struct {
GSList *dns_search; /* list of strings */
GSList *addresses; /* array of NMIP6Address */
GSList *routes; /* array of NMIP6Route */
+ gint64 route_metric;
gboolean ignore_auto_routes;
gboolean ignore_auto_dns;
gboolean never_default;
@@ -91,6 +92,7 @@ enum {
PROP_DNS_SEARCH,
PROP_ADDRESSES,
PROP_ROUTES,
+ PROP_ROUTE_METRIC,
PROP_IGNORE_AUTO_ROUTES,
PROP_IGNORE_AUTO_DNS,
PROP_NEVER_DEFAULT,
@@ -709,6 +711,26 @@ nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting)
}
/**
+ * nm_setting_ip6_config_get_route_metric:
+ * @setting: the #NMSettingIP4Config
+ *
+ * Returns the value contained in the #NMSettingIP6Config:route-metric
+ * property.
+ *
+ * Returns: the route metric that is used for IPv6 routes that don't explicitly
+ * specify a metric. See #NMSettingIP6Config:route-metric for more details.
+ *
+ * Since: 1.0
+ **/
+gint64
+nm_setting_ip6_config_get_route_metric (NMSettingIP6Config *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), -1);
+
+ return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->route_metric;
+}
+
+/**
* nm_setting_ip6_config_get_ignore_auto_routes:
* @setting: the #NMSettingIP6Config
*
@@ -927,6 +949,9 @@ set_property (GObject *object, guint prop_id,
g_slist_free_full (priv->routes, g_free);
priv->routes = nm_utils_ip6_routes_from_gvalue (value);
break;
+ case PROP_ROUTE_METRIC:
+ priv->route_metric = g_value_get_int64 (value);
+ break;
case PROP_IGNORE_AUTO_ROUTES:
priv->ignore_auto_routes = g_value_get_boolean (value);
break;
@@ -974,6 +999,9 @@ get_property (GObject *object, guint prop_id,
case PROP_ROUTES:
nm_utils_ip6_routes_to_gvalue (priv->routes, value);
break;
+ case PROP_ROUTE_METRIC:
+ g_value_set_int64 (value, priv->route_metric);
+ break;
case PROP_IGNORE_AUTO_ROUTES:
g_value_set_boolean (value, priv->ignore_auto_routes);
break;
@@ -1187,6 +1215,28 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class)
G_PARAM_STATIC_STRINGS));
/**
+ * NMSettingIP6Config:route-metric:
+ *
+ * The default metric for routes that don't explicitly specify a metric.
+ * The default value -1 means that the metric is choosen automatically
+ * based on the device type.
+ * The metric applies to dynamic routes, manual (static) routes that
+ * don't have an explicit metric setting, address prefix routes, and
+ * the default route.
+ * As the linux kernel replaces zero (0) by 1024 (user-default), setting
+ * this property to 0 means effectively setting it to 1024.
+ *
+ * Since: 1.0
+ **/
+ g_object_class_install_property
+ (object_class, PROP_ROUTE_METRIC,
+ g_param_spec_int64 (NM_SETTING_IP6_CONFIG_ROUTE_METRIC, "", "",
+ -1, G_MAXUINT32, -1,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
* NMSettingIP6Config:ignore-auto-routes:
*
* When the method is set to "auto" or "dhcp" and this property is set to
diff --git a/libnm-util/nm-setting-ip6-config.h b/libnm-util/nm-setting-ip6-config.h
index 4486a40e26..0a2f00ddcc 100644
--- a/libnm-util/nm-setting-ip6-config.h
+++ b/libnm-util/nm-setting-ip6-config.h
@@ -61,6 +61,7 @@ GQuark nm_setting_ip6_config_error_quark (void);
#define NM_SETTING_IP6_CONFIG_DNS_SEARCH "dns-search"
#define NM_SETTING_IP6_CONFIG_ADDRESSES "addresses"
#define NM_SETTING_IP6_CONFIG_ROUTES "routes"
+#define NM_SETTING_IP6_CONFIG_ROUTE_METRIC "route-metric"
#define NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES "ignore-auto-routes"
#define NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS "ignore-auto-dns"
#define NM_SETTING_IP6_CONFIG_NEVER_DEFAULT "never-default"
@@ -245,6 +246,9 @@ gboolean nm_setting_ip6_config_remove_route_by_value (NMSettingIP
void nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting);
gboolean nm_setting_ip6_config_get_ignore_auto_routes (NMSettingIP6Config *setting);
+NM_AVAILABLE_IN_1_0
+gint64 nm_setting_ip6_config_get_route_metric (NMSettingIP6Config *setting);
+
gboolean nm_setting_ip6_config_get_ignore_auto_dns (NMSettingIP6Config *setting);
const char * nm_setting_ip6_config_get_dhcp_hostname (NMSettingIP6Config *setting);
gboolean nm_setting_ip6_config_get_never_default (NMSettingIP6Config *setting);
diff --git a/libnm-util/tests/test-general.c b/libnm-util/tests/test-general.c
index bdec7e1354..eea22b5f3b 100644
--- a/libnm-util/tests/test-general.c
+++ b/libnm-util/tests/test-general.c
@@ -1268,6 +1268,7 @@ test_connection_diff_a_only (void)
{ NM_SETTING_IP4_CONFIG_DNS_SEARCH, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_ADDRESSES, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP4_CONFIG_ROUTE_METRIC, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, NM_SETTING_DIFF_RESULT_IN_A },
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index 8d9ca07834..baf83ca548 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -572,6 +572,7 @@ global:
nm_setting_ip_config_get_num_dns_searches;
nm_setting_ip_config_get_num_routes;
nm_setting_ip_config_get_route;
+ nm_setting_ip_config_get_route_metric;
nm_setting_ip_config_get_type;
nm_setting_ip_config_remove_address;
nm_setting_ip_config_remove_address_by_value;