[lwIP] fix the pbuf q=NULL issue in ip_nat_input.
This commit is contained in:
parent
72298bac32
commit
3e31d349ea
|
@ -162,9 +162,9 @@
|
||||||
#define SYS_LIGHTWEIGHT_PROT (NO_SYS==0)
|
#define SYS_LIGHTWEIGHT_PROT (NO_SYS==0)
|
||||||
|
|
||||||
#ifdef LWIP_USING_NAT
|
#ifdef LWIP_USING_NAT
|
||||||
#define LWIP_NAT 1
|
#define IP_NAT 1
|
||||||
#else
|
#else
|
||||||
#define LWIP_NAT 0
|
#define IP_NAT 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ---------- TCP options ---------- */
|
/* ---------- TCP options ---------- */
|
||||||
|
|
|
@ -117,9 +117,10 @@
|
||||||
#define LWIP_NAT_TTL_INFINITE (INT_MAX)
|
#define LWIP_NAT_TTL_INFINITE (INT_MAX)
|
||||||
#define LWIP_NAT_DEFAULT_TTL_SECONDS (128)
|
#define LWIP_NAT_DEFAULT_TTL_SECONDS (128)
|
||||||
#define LWIP_NAT_FORWARD_HEADER_SIZE_MIN (sizeof(struct eth_hdr))
|
#define LWIP_NAT_FORWARD_HEADER_SIZE_MIN (sizeof(struct eth_hdr))
|
||||||
#define LWIP_NAT_DEFAULT_STATE_TABLES_ICMP (2)
|
|
||||||
#define LWIP_NAT_DEFAULT_STATE_TABLES_TCP (16)
|
#define LWIP_NAT_DEFAULT_STATE_TABLES_ICMP (4)
|
||||||
#define LWIP_NAT_DEFAULT_STATE_TABLES_UDP (16)
|
#define LWIP_NAT_DEFAULT_STATE_TABLES_TCP (32)
|
||||||
|
#define LWIP_NAT_DEFAULT_STATE_TABLES_UDP (32)
|
||||||
|
|
||||||
#define LWIP_NAT_DEFAULT_TCP_SOURCE_PORT (40000)
|
#define LWIP_NAT_DEFAULT_TCP_SOURCE_PORT (40000)
|
||||||
#define LWIP_NAT_DEFAULT_UDP_SOURCE_PORT (40000)
|
#define LWIP_NAT_DEFAULT_UDP_SOURCE_PORT (40000)
|
||||||
|
@ -538,6 +539,7 @@ ip_nat_input(struct pbuf *p)
|
||||||
q = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM);
|
q = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM);
|
||||||
if (q == NULL) {
|
if (q == NULL) {
|
||||||
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_input: no pbuf for outgoing header\n"));
|
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_input: no pbuf for outgoing header\n"));
|
||||||
|
// rt_kprintf("ip_nat_input: no pbuf for outgoing header\n");
|
||||||
/* @todo: stats? */
|
/* @todo: stats? */
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
p = NULL;
|
p = NULL;
|
||||||
|
@ -549,11 +551,13 @@ ip_nat_input(struct pbuf *p)
|
||||||
/* restore p->payload to IP header */
|
/* restore p->payload to IP header */
|
||||||
if (pbuf_header(p, -PBUF_LINK_HLEN)) {
|
if (pbuf_header(p, -PBUF_LINK_HLEN)) {
|
||||||
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_input: restoring header failed\n"));
|
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_input: restoring header failed\n"));
|
||||||
|
// rt_kprintf("ip_nat_input: restoring header failed\n");
|
||||||
/* @todo: stats? */
|
/* @todo: stats? */
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
p = NULL;
|
p = NULL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
else q = p;
|
||||||
}
|
}
|
||||||
/* if we come here, q is the pbuf to send (either points to p or to a chain) */
|
/* if we come here, q is the pbuf to send (either points to p or to a chain) */
|
||||||
in_if = nat_entry.cmn->cfg->entry.in_if;
|
in_if = nat_entry.cmn->cfg->entry.in_if;
|
||||||
|
@ -572,6 +576,7 @@ ip_nat_input(struct pbuf *p)
|
||||||
LWIP_DEBUGF(LWIP_NAT_DEBUG,
|
LWIP_DEBUGF(LWIP_NAT_DEBUG,
|
||||||
("ip_nat_input: failed to send rewritten packet. link layer returned %d\n",
|
("ip_nat_input: failed to send rewritten packet. link layer returned %d\n",
|
||||||
err));
|
err));
|
||||||
|
// rt_kprintf("ip_nat_input: failed to send rewritten packet. link layer returned %d\n", err);
|
||||||
}
|
}
|
||||||
/* now that q (and/or p) is sent (or not), give up the reference to it
|
/* now that q (and/or p) is sent (or not), give up the reference to it
|
||||||
this frees the input pbuf (p) as we have consumed it. */
|
this frees the input pbuf (p) as we have consumed it. */
|
||||||
|
@ -736,6 +741,7 @@ ip_nat_out(struct pbuf *p)
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
LWIP_DEBUGF(LWIP_NAT_DEBUG,
|
LWIP_DEBUGF(LWIP_NAT_DEBUG,
|
||||||
("ip_nat_out: failed to send rewritten packet. link layer returned %d\n", err));
|
("ip_nat_out: failed to send rewritten packet. link layer returned %d\n", err));
|
||||||
|
// rt_kprintf("ip_nat_out: failed to send rewritten packet. link layer returned %d\n", err);
|
||||||
} else {
|
} else {
|
||||||
sent = 1;
|
sent = 1;
|
||||||
}
|
}
|
||||||
|
@ -842,6 +848,7 @@ ip_nat_udp_lookup_outgoing(ip_nat_conf_t *nat_config, const struct ip_hdr *iphdr
|
||||||
nat_entry.udp);
|
nat_entry.udp);
|
||||||
} else {
|
} else {
|
||||||
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_udp_lookup_outgoing: no more NAT entries available\n"));
|
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_udp_lookup_outgoing: no more NAT entries available\n"));
|
||||||
|
// rt_kprintf("ip_nat_udp_lookup_outgoing: no more NAT entries available\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -926,6 +933,7 @@ ip_nat_tcp_lookup_outgoing(ip_nat_conf_t *nat_config, const struct ip_hdr *iphdr
|
||||||
nat_entry.tcp);
|
nat_entry.tcp);
|
||||||
} else {
|
} else {
|
||||||
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_udp_lookup_outgoing: no more NAT entries available\n"));
|
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_udp_lookup_outgoing: no more NAT entries available\n"));
|
||||||
|
// rt_kprintf("ip_nat_udp_lookup_outgoing: no more NAT entries available\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1005,9 +1013,9 @@ ip_nat_dbg_dump(const char *msg, const struct ip_hdr *iphdr)
|
||||||
LWIP_ASSERT("NULL != msg", NULL != msg);
|
LWIP_ASSERT("NULL != msg", NULL != msg);
|
||||||
LWIP_ASSERT("NULL != iphdr", NULL != iphdr);
|
LWIP_ASSERT("NULL != iphdr", NULL != iphdr);
|
||||||
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("%s: IP: (", msg));
|
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("%s: IP: (", msg));
|
||||||
ip_nat_dbg_dump_ip(&iphdr->src);
|
ip_nat_dbg_dump_ip((ip_addr_t *)&(iphdr->src));
|
||||||
LWIP_DEBUGF(LWIP_NAT_DEBUG, (" --> "));
|
LWIP_DEBUGF(LWIP_NAT_DEBUG, (" --> "));
|
||||||
ip_nat_dbg_dump_ip(&iphdr->dest);
|
ip_nat_dbg_dump_ip((ip_addr_t *)&(iphdr->dest));
|
||||||
LWIP_DEBUGF(LWIP_NAT_DEBUG, (" id=%" U16_F ", chksum=%" U16_F ")\n",
|
LWIP_DEBUGF(LWIP_NAT_DEBUG, (" id=%" U16_F ", chksum=%" U16_F ")\n",
|
||||||
ntohs(IPH_ID(iphdr)), ntohs(IPH_CHKSUM(iphdr))));
|
ntohs(IPH_ID(iphdr)), ntohs(IPH_CHKSUM(iphdr))));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue