mirror of
https://github.com/espressif/esp-lwip.git
synced 2026-06-05 21:04:45 +00:00
lwip/napt: Added api to enable/disable napt based on lwip netif.
This commit is contained in:
@@ -205,6 +205,37 @@ ip_napt_enable_no(u8_t number, int enable)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
ip_napt_enable_netif(struct netif *netif, int enable)
|
||||
{
|
||||
struct netif *each_netif;
|
||||
|
||||
if (!netif_is_up(netif)){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!netif->napt && enable) {
|
||||
/* Enable napt */
|
||||
netif->napt = 1;
|
||||
ip_napt_init(IP_NAPT_MAX, IP_PORTMAP_MAX);
|
||||
|
||||
} else if (netif->napt && !enable) {
|
||||
/* Disable napt */
|
||||
netif->napt = 0;
|
||||
|
||||
NETIF_FOREACH(each_netif) {
|
||||
if (each_netif->napt) {
|
||||
/* napt used on another interface, no need for cleanup */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ip_napt_deinit();
|
||||
}
|
||||
/* Enabling/disabling napt a second time is a no operation */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* adjusts checksum in a packet
|
||||
- chksum points to the chksum in the packet
|
||||
- optr points to the old data in the packet (before)
|
||||
|
||||
@@ -67,6 +67,7 @@ extern "C" {
|
||||
#define IP_NAPT_PORT_RANGE_START 49152
|
||||
#define IP_NAPT_PORT_RANGE_END 61439
|
||||
|
||||
|
||||
/**
|
||||
* Enable/Disable NAPT for a specified interface.
|
||||
*
|
||||
@@ -87,6 +88,20 @@ void
|
||||
ip_napt_enable_no(u8_t number, int enable);
|
||||
|
||||
|
||||
/**
|
||||
* Enable/Disable NAPT for a specified interface.
|
||||
*
|
||||
* @param netif interface handle
|
||||
* @param enable non-zero to enable NAPT, or 0 to disable.
|
||||
*
|
||||
* @return
|
||||
* - 0: Failure
|
||||
* - 1: Success
|
||||
*/
|
||||
int
|
||||
ip_napt_enable_netif(struct netif *netif, int enable);
|
||||
|
||||
|
||||
/**
|
||||
* Register port mapping on the external interface to internal interface.
|
||||
* When the same port mapping is registered again, the old mapping is overwritten.
|
||||
|
||||
Reference in New Issue
Block a user