Skip to content

Commit

Permalink
lwip/napt: Added api to enable/disable napt based on lwip netif.
Browse files Browse the repository at this point in the history
  • Loading branch information
espressif-abhikroy committed Feb 13, 2023
1 parent 86df9f4 commit 280c3d6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/core/ipv4/ip4_napt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions src/include/lwip/lwip_napt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
Expand Down

0 comments on commit 280c3d6

Please sign in to comment.