mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Lwip addons (#2260)
* Add multicast TTL to UDP and rework UdpContext * Add limit for TCP TIME_WAIT pcbs * Add liblwip_gcc.a * Make the changes be backward compatible with the current xcc version
This commit is contained in:
parent
86067333f5
commit
07f4d4c241
@ -1680,7 +1680,7 @@ coredev.build.lwip_flags=
|
|||||||
|
|
||||||
coredev.menu.LwIPVariant.Espressif=Espressif (xcc)
|
coredev.menu.LwIPVariant.Espressif=Espressif (xcc)
|
||||||
coredev.menu.LwIPVariant.Espressif.build.lwip_lib=-llwip
|
coredev.menu.LwIPVariant.Espressif.build.lwip_lib=-llwip
|
||||||
coredev.menu.LwIPVariant.Espressif.build.lwip_flags=
|
coredev.menu.LwIPVariant.Espressif.build.lwip_flags=-DLWIP_MAYBE_XCC
|
||||||
coredev.menu.LwIPVariant.Prebuilt=Prebuilt Source (gcc)
|
coredev.menu.LwIPVariant.Prebuilt=Prebuilt Source (gcc)
|
||||||
coredev.menu.LwIPVariant.Prebuilt.build.lwip_lib=-llwip_gcc
|
coredev.menu.LwIPVariant.Prebuilt.build.lwip_lib=-llwip_gcc
|
||||||
coredev.menu.LwIPVariant.Prebuilt.build.lwip_flags=-DLWIP_OPEN_SRC
|
coredev.menu.LwIPVariant.Prebuilt.build.lwip_flags=-DLWIP_OPEN_SRC
|
||||||
|
@ -44,11 +44,11 @@ public:
|
|||||||
, _tx_buf_head(0)
|
, _tx_buf_head(0)
|
||||||
, _tx_buf_cur(0)
|
, _tx_buf_cur(0)
|
||||||
, _tx_buf_offset(0)
|
, _tx_buf_offset(0)
|
||||||
, _multicast_ttl(1)
|
|
||||||
, _dest_port(0)
|
|
||||||
{
|
{
|
||||||
_pcb = udp_new();
|
_pcb = udp_new();
|
||||||
_dest_addr.addr = 0;
|
#ifdef LWIP_MAYBE_XCC
|
||||||
|
_mcast_ttl = 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
~UdpContext()
|
~UdpContext()
|
||||||
@ -87,8 +87,8 @@ public:
|
|||||||
|
|
||||||
bool connect(ip_addr_t addr, uint16_t port)
|
bool connect(ip_addr_t addr, uint16_t port)
|
||||||
{
|
{
|
||||||
_dest_addr = addr;
|
ip_addr_copy(_pcb->remote_ip, addr);
|
||||||
_dest_port = port;
|
_pcb->remote_port = port;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,17 +106,16 @@ public:
|
|||||||
|
|
||||||
void setMulticastInterface(ip_addr_t addr)
|
void setMulticastInterface(ip_addr_t addr)
|
||||||
{
|
{
|
||||||
// newer versions of lwip have a macro to set the multicast ip
|
udp_set_multicast_netif_addr(_pcb, addr);
|
||||||
// udp_set_multicast_netif_addr(_pcb, addr);
|
|
||||||
_pcb->multicast_ip = addr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMulticastTTL(int ttl)
|
void setMulticastTTL(int ttl)
|
||||||
{
|
{
|
||||||
// newer versions of lwip have an additional field (mcast_ttl) for this purpose
|
#ifdef LWIP_MAYBE_XCC
|
||||||
// and a macro to set it instead of direct field access
|
_mcast_ttl = ttl;
|
||||||
// udp_set_multicast_ttl(_pcb, ttl);
|
#else
|
||||||
_multicast_ttl = ttl;
|
udp_set_multicast_ttl(_pcb, ttl);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// warning: handler is called from tcp stack context
|
// warning: handler is called from tcp stack context
|
||||||
@ -275,20 +274,22 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
if (!addr) {
|
if (!addr) {
|
||||||
addr = &_dest_addr;
|
addr = &_pcb->remote_ip;
|
||||||
port = _dest_port;
|
port = _pcb->remote_port;
|
||||||
}
|
}
|
||||||
|
#ifdef LWIP_MAYBE_XCC
|
||||||
uint16_t old_ttl = _pcb->ttl;
|
uint16_t old_ttl = _pcb->ttl;
|
||||||
if (ip_addr_ismulticast(addr)) {
|
if (ip_addr_ismulticast(addr)) {
|
||||||
_pcb->ttl = _multicast_ttl;
|
_pcb->ttl = _mcast_ttl;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
err_t err = udp_sendto(_pcb, tx_copy, addr, port);
|
err_t err = udp_sendto(_pcb, tx_copy, addr, port);
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
DEBUGV(":ust rc=%d\r\n", err);
|
DEBUGV(":ust rc=%d\r\n", err);
|
||||||
}
|
}
|
||||||
|
#ifdef LWIP_MAYBE_XCC
|
||||||
_pcb->ttl = old_ttl;
|
_pcb->ttl = old_ttl;
|
||||||
|
#endif
|
||||||
pbuf_free(tx_copy);
|
pbuf_free(tx_copy);
|
||||||
return err == ERR_OK;
|
return err == ERR_OK;
|
||||||
}
|
}
|
||||||
@ -365,10 +366,10 @@ private:
|
|||||||
pbuf* _tx_buf_head;
|
pbuf* _tx_buf_head;
|
||||||
pbuf* _tx_buf_cur;
|
pbuf* _tx_buf_cur;
|
||||||
size_t _tx_buf_offset;
|
size_t _tx_buf_offset;
|
||||||
uint16_t _multicast_ttl;
|
|
||||||
uint16_t _dest_port;
|
|
||||||
ip_addr_t _dest_addr;
|
|
||||||
rxhandler_t _on_rx;
|
rxhandler_t _on_rx;
|
||||||
|
#ifdef LWIP_MAYBE_XCC
|
||||||
|
uint16_t _mcast_ttl;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Binary file not shown.
@ -396,6 +396,26 @@ extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
|
|||||||
|
|
||||||
#endif /* LWIP_DEBUG */
|
#endif /* LWIP_DEBUG */
|
||||||
|
|
||||||
|
#define TCP_TW_LIMIT(l) \
|
||||||
|
do { \
|
||||||
|
u32_t tcp_tmp_pcbs_count = 0; \
|
||||||
|
tcp_tmp_pcb = tcp_tw_pcbs; \
|
||||||
|
while(tcp_tmp_pcb != NULL) { \
|
||||||
|
if(++tcp_tmp_pcbs_count == (l)) { \
|
||||||
|
struct tcp_pcb *_tcp_tmp_pcb = tcp_tmp_pcb->next; \
|
||||||
|
tcp_tmp_pcb->next = NULL; \
|
||||||
|
tcp_tmp_pcb = _tcp_tmp_pcb; \
|
||||||
|
while(tcp_tmp_pcb != NULL) { \
|
||||||
|
_tcp_tmp_pcb = tcp_tmp_pcb; \
|
||||||
|
tcp_pcb_purge(tcp_tmp_pcb); \
|
||||||
|
tcp_tmp_pcb = tcp_tmp_pcb->next; \
|
||||||
|
memp_free(MEMP_TCP_PCB, _tcp_tmp_pcb); \
|
||||||
|
} \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
tcp_tmp_pcb = tcp_tmp_pcb->next; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
/* Internal functions: */
|
/* Internal functions: */
|
||||||
struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
|
struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
|
||||||
|
@ -103,6 +103,10 @@ struct udp_pcb {
|
|||||||
#if LWIP_IGMP
|
#if LWIP_IGMP
|
||||||
/** outgoing network interface for multicast packets */
|
/** outgoing network interface for multicast packets */
|
||||||
ip_addr_t multicast_ip;
|
ip_addr_t multicast_ip;
|
||||||
|
#ifndef LWIP_MAYBE_XCC
|
||||||
|
/** TTL for outgoing multicast packets */
|
||||||
|
u8_t mcast_ttl;
|
||||||
|
#endif /* LWIP_MAYBE_XCC */
|
||||||
#endif /* LWIP_IGMP */
|
#endif /* LWIP_IGMP */
|
||||||
|
|
||||||
#if LWIP_UDPLITE
|
#if LWIP_UDPLITE
|
||||||
@ -156,6 +160,15 @@ void udp_input (struct pbuf *p, struct netif *inp)ICACHE_FLASH_
|
|||||||
|
|
||||||
#define udp_init() /* Compatibility define, not init needed. */
|
#define udp_init() /* Compatibility define, not init needed. */
|
||||||
|
|
||||||
|
#if LWIP_IGMP
|
||||||
|
#define udp_set_multicast_netif_addr(pcb, ipaddr) ip_addr_copy((pcb)->multicast_ip, (ipaddr))
|
||||||
|
#define udp_get_multicast_netif_addr(pcb) ((pcb)->multicast_ip)
|
||||||
|
#ifndef LWIP_MAYBE_XCC
|
||||||
|
#define udp_set_multicast_ttl(pcb, value) do { (pcb)->mcast_ttl = value; } while(0)
|
||||||
|
#define udp_get_multicast_ttl(pcb) ((pcb)->mcast_ttl)
|
||||||
|
#endif /* LWIP_MAYBE_XCC */
|
||||||
|
#endif /* LWIP_IGMP */
|
||||||
|
|
||||||
#if UDP_DEBUG
|
#if UDP_DEBUG
|
||||||
void udp_debug_print(struct udp_hdr *udphdr)ICACHE_FLASH_ATTR;
|
void udp_debug_print(struct udp_hdr *udphdr)ICACHE_FLASH_ATTR;
|
||||||
#else
|
#else
|
||||||
|
@ -255,6 +255,14 @@
|
|||||||
#define MEMP_NUM_TCP_PCB_LISTEN 2
|
#define MEMP_NUM_TCP_PCB_LISTEN 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MEMP_NUM_TCP_PCB_TIME_WAIT: the number of TCP pcbs in TIME_WAIT state.
|
||||||
|
* (requires the LWIP_TCP option, 0 = disabled)
|
||||||
|
*/
|
||||||
|
#ifndef MEMP_NUM_TCP_PCB_TIME_WAIT
|
||||||
|
#define MEMP_NUM_TCP_PCB_TIME_WAIT 5
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments.
|
* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments.
|
||||||
* (requires the LWIP_TCP option)
|
* (requires the LWIP_TCP option)
|
||||||
|
@ -28,5 +28,8 @@ all: $(LWIP_LIB)
|
|||||||
install: all
|
install: all
|
||||||
cp -f $(LWIP_LIB) $(SDK_PATH)/lib/$(LWIP_LIB)
|
cp -f $(LWIP_LIB) $(SDK_PATH)/lib/$(LWIP_LIB)
|
||||||
|
|
||||||
|
release: all
|
||||||
|
cp -f $(LWIP_LIB) $(SDK_PATH)/lib/liblwip_gcc.a
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -rf $(BUILD_PATH) $(LWIP_LIB)
|
@rm -rf $(BUILD_PATH) $(LWIP_LIB)
|
||||||
|
@ -166,7 +166,9 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
|
|||||||
TCP_RMV(&tcp_active_pcbs, pcb);
|
TCP_RMV(&tcp_active_pcbs, pcb);
|
||||||
pcb->state = TIME_WAIT;
|
pcb->state = TIME_WAIT;
|
||||||
TCP_REG(&tcp_tw_pcbs, pcb);
|
TCP_REG(&tcp_tw_pcbs, pcb);
|
||||||
|
#if MEMP_NUM_TCP_PCB_TIME_WAIT
|
||||||
|
TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT);
|
||||||
|
#endif
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -808,6 +808,9 @@ tcp_process(struct tcp_pcb *pcb)
|
|||||||
TCP_RMV(&tcp_active_pcbs, pcb);
|
TCP_RMV(&tcp_active_pcbs, pcb);
|
||||||
pcb->state = TIME_WAIT;
|
pcb->state = TIME_WAIT;
|
||||||
TCP_REG(&tcp_tw_pcbs, pcb);
|
TCP_REG(&tcp_tw_pcbs, pcb);
|
||||||
|
#if MEMP_NUM_TCP_PCB_TIME_WAIT
|
||||||
|
TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
tcp_ack_now(pcb);
|
tcp_ack_now(pcb);
|
||||||
pcb->state = CLOSING;
|
pcb->state = CLOSING;
|
||||||
@ -825,6 +828,9 @@ tcp_process(struct tcp_pcb *pcb)
|
|||||||
TCP_RMV(&tcp_active_pcbs, pcb);
|
TCP_RMV(&tcp_active_pcbs, pcb);
|
||||||
pcb->state = TIME_WAIT;
|
pcb->state = TIME_WAIT;
|
||||||
TCP_REG(&tcp_tw_pcbs, pcb);
|
TCP_REG(&tcp_tw_pcbs, pcb);
|
||||||
|
#if MEMP_NUM_TCP_PCB_TIME_WAIT
|
||||||
|
TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CLOSING:
|
case CLOSING:
|
||||||
@ -835,6 +841,9 @@ tcp_process(struct tcp_pcb *pcb)
|
|||||||
TCP_RMV(&tcp_active_pcbs, pcb);
|
TCP_RMV(&tcp_active_pcbs, pcb);
|
||||||
pcb->state = TIME_WAIT;
|
pcb->state = TIME_WAIT;
|
||||||
TCP_REG(&tcp_tw_pcbs, pcb);
|
TCP_REG(&tcp_tw_pcbs, pcb);
|
||||||
|
#if MEMP_NUM_TCP_PCB_TIME_WAIT
|
||||||
|
TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LAST_ACK:
|
case LAST_ACK:
|
||||||
|
@ -504,6 +504,7 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
|
|||||||
ip_addr_t *src_ip;
|
ip_addr_t *src_ip;
|
||||||
err_t err;
|
err_t err;
|
||||||
struct pbuf *q; /* q will be sent down the stack */
|
struct pbuf *q; /* q will be sent down the stack */
|
||||||
|
u8_t ttl;
|
||||||
|
|
||||||
#if IP_SOF_BROADCAST
|
#if IP_SOF_BROADCAST
|
||||||
/* broadcast filter? */
|
/* broadcast filter? */
|
||||||
@ -557,7 +558,7 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
|
|||||||
|
|
||||||
/* Multicast Loop? */
|
/* Multicast Loop? */
|
||||||
#if LWIP_IGMP
|
#if LWIP_IGMP
|
||||||
if (ip_addr_ismulticast(dst_ip) && ((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0)) {
|
if (((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) && ip_addr_ismulticast(dst_ip)) {
|
||||||
q->flags |= PBUF_FLAG_MCASTLOOP;
|
q->flags |= PBUF_FLAG_MCASTLOOP;
|
||||||
}
|
}
|
||||||
#endif /* LWIP_IGMP */
|
#endif /* LWIP_IGMP */
|
||||||
@ -665,13 +666,21 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
|
|||||||
udphdr->chksum = udpchksum;
|
udphdr->chksum = udpchksum;
|
||||||
}
|
}
|
||||||
#endif /* CHECKSUM_GEN_UDP */
|
#endif /* CHECKSUM_GEN_UDP */
|
||||||
|
|
||||||
|
/* Determine TTL to use */
|
||||||
|
#if LWIP_IGMP
|
||||||
|
ttl = (ip_addr_ismulticast(dst_ip) ? pcb->mcast_ttl : pcb->ttl);
|
||||||
|
#else /* LWIP_IGMP */
|
||||||
|
ttl = pcb->ttl;
|
||||||
|
#endif /* LWIP_IGMP */
|
||||||
|
|
||||||
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum));
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum));
|
||||||
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDP,)\n"));
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDP,)\n"));
|
||||||
/* output to IP */
|
/* output to IP */
|
||||||
#if LWIP_NETIF_HWADDRHINT
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
netif->addr_hint = &(pcb->addr_hint);
|
netif->addr_hint = &(pcb->addr_hint);
|
||||||
#endif /* LWIP_NETIF_HWADDRHINT*/
|
#endif /* LWIP_NETIF_HWADDRHINT*/
|
||||||
err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif);
|
err = ip_output_if(q, src_ip, dst_ip, ttl, pcb->tos, IP_PROTO_UDP, netif);
|
||||||
#if LWIP_NETIF_HWADDRHINT
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
netif->addr_hint = NULL;
|
netif->addr_hint = NULL;
|
||||||
#endif /* LWIP_NETIF_HWADDRHINT*/
|
#endif /* LWIP_NETIF_HWADDRHINT*/
|
||||||
@ -950,6 +959,9 @@ udp_new(void)
|
|||||||
/* initialize PCB to all zeroes */
|
/* initialize PCB to all zeroes */
|
||||||
os_memset(pcb, 0, sizeof(struct udp_pcb));
|
os_memset(pcb, 0, sizeof(struct udp_pcb));
|
||||||
pcb->ttl = UDP_TTL;
|
pcb->ttl = UDP_TTL;
|
||||||
|
#if LWIP_IGMP
|
||||||
|
pcb->mcast_ttl = UDP_TTL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return pcb;
|
return pcb;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user