From 4d69d0eda583fdac5fb5161e4315377d0a33f132 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Fri, 21 Feb 2014 08:41:44 +0100 Subject: [PATCH 1/2] Fixed IPv6 raw checksumming after a hint from Philip Gladstone --- src/core/raw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/raw.c b/src/core/raw.c index a3ee94b9..6b597352 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -318,9 +318,9 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *ipaddr) /* If requested, based on the IPV6_CHECKSUM socket option per RFC3542, compute the checksum and update the checksum in the payload. */ if (PCB_ISIPV6(pcb) && pcb->chksum_reqd) { - u16_t chksum; - chksum = ip6_chksum_pseudo(q, pcb->protocol, q->tot_len, ipX_2_ip6(src_ip), ipX_2_ip6(dst_ip)); - *(u16_t *)(((u8_t *)q->payload) + pcb->chksum_offset) = chksum; + u16_t chksum = ip6_chksum_pseudo(p, pcb->protocol, p->tot_len, ipX_2_ip6(src_ip), ipX_2_ip6(dst_ip)); + LWIP_ASSERT("Checksum must fit into first pbuf", p->len >= (pcb->chksum_offset + 2)); + SMEMCPY(((u8_t *)p->payload) + pcb->chksum_offset, &chksum, sizeof(u16_t)); } #endif From fc158ad5c08fb327866d4a335e1e83e5e31544d4 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Fri, 21 Feb 2014 09:04:39 +0100 Subject: [PATCH 2/2] Fixed netconn_gethostbyname for LWIP_MPU_COMPATIBLE: removed invalid check on 'addr', copy 'name' since it could be located on the caller's stack --- src/api/api_lib.c | 9 ++++----- src/include/lwip/api_msg.h | 4 ++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 971fe918..97660377 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -829,20 +829,19 @@ netconn_gethostbyname(const char *name, ip_addr_t *addr) API_VAR_ALLOC(struct dns_api_msg, MEMP_DNS_API_MSG, msg); #if LWIP_MPU_COMPATIBLE - if (addr == NULL) { - addr = IP_ADDR_ANY; - } -#else + strncpy(API_VAR_REF(msg).name, name, DNS_MAX_NAME_LENGTH-1); + API_VAR_REF(msg).name[DNS_MAX_NAME_LENGTH-1] = 0; +#else /* LWIP_MPU_COMPATIBLE */ msg.err = &err; msg.sem = &sem; API_VAR_REF(msg).addr = API_VAR_REF(addr); + API_VAR_REF(msg).name = name; #endif /* LWIP_MPU_COMPATIBLE */ err = sys_sem_new(API_EXPR_REF(API_VAR_REF(msg).sem), 0); if (err != ERR_OK) { API_VAR_FREE(MEMP_DNS_API_MSG, msg); return err; } - API_VAR_REF(msg).name = name; tcpip_callback(lwip_netconn_do_gethostbyname, &API_VAR_REF(msg)); sys_sem_wait(API_EXPR_REF(API_VAR_REF(msg).sem)); diff --git a/src/include/lwip/api_msg.h b/src/include/lwip/api_msg.h index 95614b7a..f9a195ae 100644 --- a/src/include/lwip/api_msg.h +++ b/src/include/lwip/api_msg.h @@ -140,7 +140,11 @@ struct api_msg { (see netconn_gethostbyname). */ struct dns_api_msg { /** Hostname to query or dotted IP address string */ +#if LWIP_MPU_COMPATIBLE + char name[DNS_MAX_NAME_LENGTH]; +#else /* LWIP_MPU_COMPATIBLE */ const char *name; +#endif /* LWIP_MPU_COMPATIBLE */ /** Rhe resolved address is stored here */ ip_addr_t API_MSG_M_DEF(addr); /** This semaphore is posted when the name is resolved, the application thread