summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2012-05-17 17:01:50 -0500
committerDan Williams <dcbw@redhat.com>2012-05-18 15:42:56 -0500
commiteefda8aa7df28fb419b8ff827cfba0f8177b1485 (patch)
tree0e0c39b04abd90146beeb122b3d1a507f6d15864
parente048b8e01375a2668020bef8adc0a1c31789af4b (diff)
core: clarify device routing priority
Instead of using the device's type number, which is a poor measure of routing priority since it has nothing to do with routing priority, let's make the decision more explicit.
-rw-r--r--src/nm-device.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/nm-device.c b/src/nm-device.c
index dfa1a2299a..69c3a770d2 100644
--- a/src/nm-device.c
+++ b/src/nm-device.c
@@ -543,12 +543,52 @@ nm_device_get_device_type (NMDevice *self)
}
+/**
+ * nm_device_get_priority():
+ * @dev: the #NMDevice
+ *
+ * Returns: the device's routing priority. Lower numbers means a "better"
+ * device, eg higher priority.
+ */
int
nm_device_get_priority (NMDevice *dev)
{
- g_return_val_if_fail (NM_IS_DEVICE (dev), -1);
+ g_return_val_if_fail (NM_IS_DEVICE (dev), 100);
- return (int) nm_device_get_device_type (dev);
+ /* Device 'priority' is used for two things:
+ *
+ * a) two devices on the same IP subnet: the "better" (ie, lower number)
+ * device is the default outgoing device for that subnet
+ * b) default route: the "better" device gets the default route. This can
+ * always be modified by setting a connection to never-default=TRUE, in
+ * which case that device will never take the default route when
+ * it's using that connection.
+ */
+
+ switch (nm_device_get_device_type (dev)) {
+ case NM_DEVICE_TYPE_ETHERNET:
+ return 1;
+ case NM_DEVICE_TYPE_INFINIBAND:
+ return 2;
+ case NM_DEVICE_TYPE_ADSL:
+ return 3;
+ case NM_DEVICE_TYPE_WIMAX:
+ return 4;
+ case NM_DEVICE_TYPE_BOND:
+ return 5;
+ case NM_DEVICE_TYPE_VLAN:
+ return 6;
+ case NM_DEVICE_TYPE_MODEM:
+ return 7;
+ case NM_DEVICE_TYPE_BT:
+ return 8;
+ case NM_DEVICE_TYPE_WIFI:
+ return 9;
+ case NM_DEVICE_TYPE_OLPC_MESH:
+ return 10;
+ default:
+ return 20;
+ }
}