feat(netif): Allow setting interface's routing priority (#11617)

* feat(netif): Allow setting interface's routing priority

* feat(netif): Rename route priority method names and add notes

* feat(netif): Print route prio for each interface
This commit is contained in:
Me No Dev 2025-07-21 15:49:15 +03:00 committed by GitHub
parent 3ad17de6aa
commit 4a3c6d7fbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 3 deletions

View file

@ -606,13 +606,33 @@ 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;
}
return esp_netif_get_route_prio(_esp_netif);
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
int NetworkInterface::setRoutePrio(int prio) {
if (_esp_netif == NULL) {
return -1;
}
return esp_netif_set_route_prio(_esp_netif, 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;
@ -819,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 ");

View file

@ -57,7 +57,10 @@ public:
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 setRoutePrio(int prio);
#endif
bool setDefault();
bool isDefault() const;