From ff7076b2f71b746803004f420470078975257bd5 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sun, 20 Jul 2025 23:15:54 +0300 Subject: [PATCH 1/3] feat(netif): Allow setting interface's routing priority --- libraries/Network/src/NetworkInterface.cpp | 9 +++++++++ libraries/Network/src/NetworkInterface.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/libraries/Network/src/NetworkInterface.cpp b/libraries/Network/src/NetworkInterface.cpp index 01790ec2493..84ac97e3a4e 100644 --- a/libraries/Network/src/NetworkInterface.cpp +++ b/libraries/Network/src/NetworkInterface.cpp @@ -613,6 +613,15 @@ int NetworkInterface::route_prio() const { return esp_netif_get_route_prio(_esp_netif); } +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0) +int NetworkInterface::route_prio(int prio) { + if (_esp_netif == NULL) { + return -1; + } + return esp_netif_set_route_prio(_esp_netif, prio); +} +#endif + bool NetworkInterface::setDefault() { if (_esp_netif == NULL) { return false; diff --git a/libraries/Network/src/NetworkInterface.h b/libraries/Network/src/NetworkInterface.h index 4f97181d4fd..c653f8f3bc7 100644 --- a/libraries/Network/src/NetworkInterface.h +++ b/libraries/Network/src/NetworkInterface.h @@ -58,6 +58,9 @@ class NetworkInterface : public Printable { String impl_name() const; int impl_index() const; int route_prio() const; +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0) + int route_prio(int prio); +#endif bool setDefault(); bool isDefault() const; From ba5f79b699ff1f96823e01e62af52adec41526bc Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sun, 20 Jul 2025 23:44:50 +0300 Subject: [PATCH 2/3] feat(netif): Rename route priority method names and add notes --- libraries/Network/src/NetworkInterface.cpp | 15 +++++++++++++-- libraries/Network/src/NetworkInterface.h | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libraries/Network/src/NetworkInterface.cpp b/libraries/Network/src/NetworkInterface.cpp index 84ac97e3a4e..5a5a2c36e8c 100644 --- a/libraries/Network/src/NetworkInterface.cpp +++ b/libraries/Network/src/NetworkInterface.cpp @@ -606,7 +606,13 @@ int NetworkInterface::impl_index() const { return esp_netif_get_netif_impl_index(_esp_netif); } -int NetworkInterface::route_prio() const { +/** + * Every netif has a parameter named route_prio, you can refer to file esp_netif_defaults.h. + * A higher value of route_prio indicates a higher priority. + * The active interface with highest priority will be used for default route (gateway). + * Defaults are: STA=100, BR=70, ETH=50, PPP=20, AP/NAN=10 + */ +int NetworkInterface::getRoutePrio() const { if (_esp_netif == NULL) { return -1; } @@ -614,7 +620,7 @@ int NetworkInterface::route_prio() const { } #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0) -int NetworkInterface::route_prio(int prio) { +int NetworkInterface::setRoutePrio(int prio) { if (_esp_netif == NULL) { return -1; } @@ -622,6 +628,11 @@ int NetworkInterface::route_prio(int prio) { } #endif +/** + * This API overrides the automatic configuration of the default interface based on the route_prio + * If the selected netif is set default using this API, no other interface could be set-default disregarding + * its route_prio number (unless the selected netif gets destroyed) + */ bool NetworkInterface::setDefault() { if (_esp_netif == NULL) { return false; diff --git a/libraries/Network/src/NetworkInterface.h b/libraries/Network/src/NetworkInterface.h index c653f8f3bc7..fd26df77697 100644 --- a/libraries/Network/src/NetworkInterface.h +++ b/libraries/Network/src/NetworkInterface.h @@ -57,9 +57,9 @@ class NetworkInterface : public Printable { const char *desc() const; String impl_name() const; int impl_index() const; - int route_prio() const; + int getRoutePrio() const; #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0) - int route_prio(int prio); + int setRoutePrio(int prio); #endif bool setDefault(); bool isDefault() const; From 306dc46c3347bc608e848c52a90c5933a6b617e2 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 21 Jul 2025 00:14:23 +0300 Subject: [PATCH 3/3] feat(netif): Print route prio for each interface --- libraries/Network/src/NetworkInterface.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/Network/src/NetworkInterface.cpp b/libraries/Network/src/NetworkInterface.cpp index 5a5a2c36e8c..06cf2a377b0 100644 --- a/libraries/Network/src/NetworkInterface.cpp +++ b/libraries/Network/src/NetworkInterface.cpp @@ -839,7 +839,11 @@ size_t NetworkInterface::printTo(Print &out) const { if (flags & ESP_NETIF_FLAG_MLDV6_REPORT) { bytes += out.print(",V6_REP"); } - bytes += out.println(")"); + bytes += out.print(")"); + + bytes += out.print(" PRIO: "); + bytes += out.print(getRoutePrio()); + bytes += out.println(""); bytes += out.print(" "); bytes += out.print("ether ");