mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-05-25 17:46:56 +08:00
task #7506: added NAT support
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/ip_frag.h"
|
||||
#include "lwip/ip_nat.h"
|
||||
#include "lwip/inet_chksum.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/icmp.h"
|
||||
@@ -377,15 +378,30 @@ ip_input(struct pbuf *p, struct netif *inp)
|
||||
|
||||
/* packet not for us? */
|
||||
if (netif == NULL) {
|
||||
#if IP_FORWARD || IP_NAT
|
||||
u8_t taken = 0;
|
||||
#endif /* IP_FORWARD || IP_NAT */
|
||||
/* packet not for us, route or discard */
|
||||
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip_input: packet not for us.\n"));
|
||||
#if IP_FORWARD
|
||||
#if IP_FORWARD || IP_NAT
|
||||
/* non-broadcast packet? */
|
||||
if (!ip_addr_isbroadcast(&(iphdr->dest), inp)) {
|
||||
/* try to forward IP packet on (other) interfaces */
|
||||
ip_forward(p, iphdr, inp);
|
||||
} else
|
||||
#if IP_NAT
|
||||
/* check if we want to perform NAT with this packet. */
|
||||
taken = ip_nat_out(p);
|
||||
if (!taken)
|
||||
#endif /* IP_NAT */
|
||||
{
|
||||
#if IP_FORWARD
|
||||
/* try to forward IP packet on (other) interfaces */
|
||||
if (ip_forward(p, iphdr, inp) != NULL) {
|
||||
taken = 1;
|
||||
}
|
||||
#endif /* IP_FORWARD */
|
||||
}
|
||||
}
|
||||
if (!taken)
|
||||
#endif /* IP_FORWARD || IP_NAT */
|
||||
{
|
||||
snmp_inc_ipinaddrerrors();
|
||||
snmp_inc_ipindiscards();
|
||||
@@ -443,6 +459,12 @@ ip_input(struct pbuf *p, struct netif *inp)
|
||||
current_netif = inp;
|
||||
current_header = iphdr;
|
||||
|
||||
#if IP_NAT
|
||||
if (!ip_addr_isbroadcast(&(iphdr->dest), inp) &&
|
||||
(ip_nat_input(p) != 0)) {
|
||||
LWIP_DEBUGF(IP_DEBUG, ("ip_input: packet consumed by nat layer\n"));
|
||||
} else
|
||||
#endif /* IP_NAT */
|
||||
#if LWIP_RAW
|
||||
/* raw input did not eat the packet? */
|
||||
if (raw_input(p, inp) == 0)
|
||||
|
||||
1097
src/core/ipv4/ip_nat.c
Normal file
1097
src/core/ipv4/ip_nat.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -53,6 +53,7 @@
|
||||
#include "lwip/autoip.h"
|
||||
#include "lwip/igmp.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/ip_nat.h"
|
||||
|
||||
|
||||
/** The one and only timeout list */
|
||||
@@ -214,6 +215,22 @@ dns_timer(void *arg)
|
||||
}
|
||||
#endif /* LWIP_DNS */
|
||||
|
||||
#if IP_NAT
|
||||
/**
|
||||
* Timer callback function that calls ip_nat_tmr() and reschedules itself.
|
||||
*
|
||||
* @param arg unused argument
|
||||
*/
|
||||
static void
|
||||
nat_timer(void *arg)
|
||||
{
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: nat_timer()\n"));
|
||||
ip_nat_tmr();
|
||||
sys_timeout(LWIP_NAT_TMR_INTERVAL_SEC, nat_timer, NULL);
|
||||
}
|
||||
#endif /* IP_NAT */
|
||||
|
||||
/** Initialize this module */
|
||||
void sys_timeouts_init(void)
|
||||
{
|
||||
@@ -236,6 +253,9 @@ void sys_timeouts_init(void)
|
||||
#if LWIP_DNS
|
||||
sys_timeout(DNS_TMR_INTERVAL, dns_timer, NULL);
|
||||
#endif /* LWIP_DNS */
|
||||
#if IP_NAT
|
||||
sys_timeout(LWIP_NAT_TMR_INTERVAL_SEC, nat_timer, NULL);
|
||||
#endif /* IP_NAT */
|
||||
|
||||
#if NO_SYS
|
||||
/* Initialise timestamp for sys_check_timeouts */
|
||||
|
||||
Reference in New Issue
Block a user