From 7bfea6edb726ce73828be05057a022d07f1893d7 Mon Sep 17 00:00:00 2001 From: likewise Date: Mon, 16 Feb 2004 21:33:42 +0000 Subject: [PATCH] Applied Ian Wienand's patches (4-2-2004). Was partly applied earlier. --- src/core/dhcp.c | 4 ++++ src/core/mem.c | 2 +- src/core/memp.c | 2 +- src/core/netif.c | 2 +- src/core/pbuf.c | 8 ++++---- src/core/tcp.c | 18 ++++++++++-------- src/core/tcp_in.c | 6 +++--- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/core/dhcp.c b/src/core/dhcp.c index db832270..e2caa8b1 100644 --- a/src/core/dhcp.c +++ b/src/core/dhcp.c @@ -67,6 +67,8 @@ * to remove the DHCP client. * */ +#ifdef LWIP_DHCP /* don't build if not configured for use in lwipopt.h */ + #include "lwip/stats.h" #include "lwip/mem.h" #include "lwip/udp.h" @@ -1418,3 +1420,5 @@ static u32_t dhcp_get_option_long(u8_t *ptr) LWIP_DEBUGF(DHCP_DEBUG, ("option long value=%lu\n", value)); return value; } + +#endif /* LWIP_DHCP */ diff --git a/src/core/mem.c b/src/core/mem.c index 4f6c9217..f898139a 100644 --- a/src/core/mem.c +++ b/src/core/mem.c @@ -292,7 +292,7 @@ mem_malloc(mem_size_t size) } sys_sem_signal(mem_sem); LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.", - (u32_t)mem + SIZEOF_STRUCT_MEM + size <= (u32_t)ram_end); + (mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end); LWIP_ASSERT("mem_malloc: allocated memory properly aligned.", (unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0); return (u8_t *)mem + SIZEOF_STRUCT_MEM; diff --git a/src/core/memp.c b/src/core/memp.c index 7eaf7bfc..8e406659 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -217,7 +217,7 @@ memp_malloc(memp_t type) sys_sem_signal(mutex); #endif /* SYS_LIGHTWEIGHT_PROT */ LWIP_ASSERT("memp_malloc: memp properly aligned", - ((u32_t)MEM_ALIGN((u8_t *)memp + sizeof(struct memp)) % MEM_ALIGNMENT) == 0); + ((mem_ptr_t)MEM_ALIGN((u8_t *)memp + sizeof(struct memp)) % MEM_ALIGNMENT) == 0); mem = MEM_ALIGN((u8_t *)memp + sizeof(struct memp)); return mem; diff --git a/src/core/netif.c b/src/core/netif.c index 13632d4b..625566e2 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -186,7 +186,7 @@ netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr) pcb = pcb->next; } } - for (lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) { + for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) { /* PCB bound to current local interface address? */ if (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr))) { /* The PCB is listening to the old ipaddr and diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 20843080..565ed201 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -100,7 +100,7 @@ pbuf_init(void) u16_t i; pbuf_pool = (struct pbuf *)&pbuf_pool_memory[0]; - LWIP_ASSERT("pbuf_init: pool aligned", (long)pbuf_pool % MEM_ALIGNMENT == 0); + LWIP_ASSERT("pbuf_init: pool aligned", (mem_ptr_t)pbuf_pool % MEM_ALIGNMENT == 0); #if PBUF_STATS lwip_stats.pbuf.avail = PBUF_POOL_SIZE; @@ -254,7 +254,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag) /* make the payload pointer point 'offset' bytes into pbuf data memory */ p->payload = MEM_ALIGN((void *)((u8_t *)p + (sizeof(struct pbuf) + offset))); LWIP_ASSERT("pbuf_alloc: pbuf p->payload properly aligned", - ((u32_t)p->payload % MEM_ALIGNMENT) == 0); + ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0); /* the total length of the pbuf chain is the requested size */ p->tot_len = length; /* set the length of the first pbuf in the chain */ @@ -290,7 +290,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag) q->len = rem_len > PBUF_POOL_BUFSIZE? PBUF_POOL_BUFSIZE: rem_len; q->payload = (void *)((u8_t *)q + sizeof(struct pbuf)); LWIP_ASSERT("pbuf_alloc: pbuf q->payload properly aligned", - ((u32_t)q->payload % MEM_ALIGNMENT) == 0); + ((mem_ptr_t)q->payload % MEM_ALIGNMENT) == 0); q->ref = 1; /* calculate remaining length to be allocated */ rem_len -= q->len; @@ -314,7 +314,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag) p->flags = PBUF_FLAG_RAM; LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned", - ((u32_t)p->payload % MEM_ALIGNMENT) == 0); + ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0); break; /* pbuf references existing (static constant) ROM payload? */ case PBUF_ROM: diff --git a/src/core/tcp.c b/src/core/tcp.c index 8c67650e..f140b96f 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -62,7 +62,9 @@ const u8_t tcp_backoff[13] = { 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7}; /* The TCP PCB lists. */ -struct tcp_pcb_listen *tcp_listen_pcbs; /* List of all TCP PCBs in LISTEN state. */ + +/* List of all TCP PCBs in LISTEN state. */ +union tcp_listen_pcbs_t tcp_listen_pcbs; struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a state in which they accept or send data. */ @@ -85,7 +87,7 @@ void tcp_init(void) { /* Clear globals. */ - tcp_listen_pcbs = NULL; + tcp_listen_pcbs.listen_pcbs = NULL; tcp_active_pcbs = NULL; tcp_tw_pcbs = NULL; tcp_tmp_pcb = NULL; @@ -136,7 +138,7 @@ tcp_close(struct tcp_pcb *pcb) switch (pcb->state) { case LISTEN: err = ERR_OK; - tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_pcbs, pcb); + tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_pcbs.pcbs, pcb); memp_free(MEMP_TCP_PCB_LISTEN, pcb); pcb = NULL; break; @@ -251,7 +253,7 @@ tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port) } #ifndef SO_REUSE /* Check if the address already is in use. */ - for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs; + for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; cpcb != NULL; cpcb = cpcb->next) { if (cpcb->local_port == port) { if (ip_addr_isany(&(cpcb->local_ip)) || @@ -284,7 +286,7 @@ tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port) When the two options aren't set and specified port is already bound, ERR_USE is returned saying that address is already in use. */ - for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs; cpcb != NULL; cpcb = cpcb->next) { + for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; cpcb != NULL; cpcb = cpcb->next) { if(cpcb->local_port == port) { if(ip_addr_cmp(&(cpcb->local_ip), ipaddr)) { if(pcb->so_options & SOF_REUSEPORT) { @@ -421,7 +423,7 @@ tcp_listen(struct tcp_pcb *pcb) #if LWIP_CALLBACK_API lpcb->accept = tcp_accept_null; #endif /* LWIP_CALLBACK_API */ - TCP_REG(&tcp_listen_pcbs, lpcb); + TCP_REG(&tcp_listen_pcbs.listen_pcbs, lpcb); return (struct tcp_pcb *)lpcb; } @@ -483,7 +485,7 @@ tcp_new_port(void) goto again; } } - for(pcb = (struct tcp_pcb *)tcp_listen_pcbs; pcb != NULL; pcb = pcb->next) { + for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) { if (pcb->local_port == port) { goto again; } @@ -1253,7 +1255,7 @@ tcp_debug_print_pcbs(void) tcp_debug_print_state(pcb->state); } LWIP_DEBUGF(TCP_DEBUG, ("Listen PCB states:\n")); - for(pcb = (struct tcp_pcb *)tcp_listen_pcbs; pcb != NULL; pcb = pcb->next) { + for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) { LWIP_DEBUGF(TCP_DEBUG, ("Local port %u, foreign port %u snd_nxt %lu rcv_nxt %lu ", pcb->local_port, pcb->remote_port, pcb->snd_nxt, pcb->rcv_nxt)); diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 8260c22a..a522a002 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -255,7 +255,7 @@ tcp_input(struct pbuf *p, struct netif *inp) /* Finally, if we still did not get a match, we check all PCBs that are LISTENing for incoming connections. */ prev = NULL; - for(lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) { + for(lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) { if ((ip_addr_isany(&(lpcb->local_ip)) || ip_addr_cmp(&(lpcb->local_ip), &(iphdr->dest))) && lpcb->local_port == tcphdr->dest) { @@ -265,9 +265,9 @@ tcp_input(struct pbuf *p, struct netif *inp) if (prev != NULL) { ((struct tcp_pcb_listen *)prev)->next = lpcb->next; /* our successor is the remainder of the listening list */ - lpcb->next = tcp_listen_pcbs; + lpcb->next = tcp_listen_pcbs.listen_pcbs; /* put this listening pcb at the head of the listening list */ - tcp_listen_pcbs = lpcb; + tcp_listen_pcbs.listen_pcbs = lpcb; } LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for LISTENing connection.\n"));