summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Sevatz <yuri_sevatz@hotmail.com>2020-12-17 06:56:08 -0500
committerYuri Sevatz <yuri_sevatz@hotmail.com>2020-12-17 06:56:08 -0500
commit65f8f26ed892f16011970ff19f075b7a288299dc (patch)
treedd5d6dbb745cf8c97c6bb230c1d0498941a19e0f
parent4bd4d2b2927c87b65de915d42ebd7c082ae13ff8 (diff)
downloadnetifaces-git-65f8f26ed892f16011970ff19f075b7a288299dc.tar.gz
Interpret missing gateway priority, handle some out of order metrics
-rw-r--r--netifaces.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/netifaces.c b/netifaces.c
index ffaf8c8..839c42c 100644
--- a/netifaces.c
+++ b/netifaces.c
@@ -1927,16 +1927,22 @@ gateways (PyObject *self)
isdefault = pmsg->rt.rtm_table == RT_TABLE_MAIN ? Py_True : Py_False;
+ /* Priority starts at 0, having none means we use kernel default (0) */
+ if (priority < 0) {
+ priority = 0;
+ }
+
/* Try to pick the active default route based on priority (which
is displayed in the UI as "metric", confusingly) */
if (pmsg->rt.rtm_family < RTNL_FAMILY_MAX) {
- if (def_priorities[pmsg->rt.rtm_family] == -1)
+ /* If no active default route found, or metric is lower */
+ if (def_priorities[pmsg->rt.rtm_family] == -1
+ || priority < def_priorities[pmsg->rt.rtm_family])
+ /* Set new default */
def_priorities[pmsg->rt.rtm_family] = priority;
- else {
- if (priority == -1
- || priority > def_priorities[pmsg->rt.rtm_family])
- isdefault = Py_False;
- }
+ else
+ /* Leave default, but unset isdefault for iface tuple */
+ isdefault = Py_False;
}
pyifname = PyUnicode_FromString (ifname);