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:
parent
3ad17de6aa
commit
4a3c6d7fbb
2 changed files with 30 additions and 3 deletions
|
|
@ -606,13 +606,33 @@ int NetworkInterface::impl_index() const {
|
||||||
return esp_netif_get_netif_impl_index(_esp_netif);
|
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) {
|
if (_esp_netif == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return esp_netif_get_route_prio(_esp_netif);
|
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() {
|
bool NetworkInterface::setDefault() {
|
||||||
if (_esp_netif == NULL) {
|
if (_esp_netif == NULL) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -819,7 +839,11 @@ size_t NetworkInterface::printTo(Print &out) const {
|
||||||
if (flags & ESP_NETIF_FLAG_MLDV6_REPORT) {
|
if (flags & ESP_NETIF_FLAG_MLDV6_REPORT) {
|
||||||
bytes += out.print(",V6_REP");
|
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(" ");
|
||||||
bytes += out.print("ether ");
|
bytes += out.print("ether ");
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,10 @@ public:
|
||||||
const char *desc() const;
|
const char *desc() const;
|
||||||
String impl_name() const;
|
String impl_name() const;
|
||||||
int impl_index() 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 setDefault();
|
||||||
bool isDefault() const;
|
bool isDefault() const;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue