diff --git a/src/core/altcp_tcp.c b/src/core/altcp_tcp.c index d5c617fc..cbbc422e 100644 --- a/src/core/altcp_tcp.c +++ b/src/core/altcp_tcp.c @@ -494,7 +494,7 @@ const struct altcp_functions altcp_tcp_functions = { altcp_tcp_get_ip, altcp_tcp_get_port #ifdef LWIP_DEBUG - ,altcp_tcp_dbg_get_tcp_state + , altcp_tcp_dbg_get_tcp_state #endif }; diff --git a/src/core/def.c b/src/core/def.c index ef1d9e0b..c483aa68 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -11,7 +11,7 @@ * \#define lwip_htonl(x) your_htonl * * Note lwip_ntohs() and lwip_ntohl() are merely references to the htonx counterparts. - * + * * If you \#define them to htons() and htonl(), you should * \#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS to prevent lwIP from * defining htonx/ntohx compatibility macros. @@ -101,10 +101,10 @@ lwip_htonl(u32_t n) * lwIP default implementation for strnstr() non-standard function. * This can be \#defined to strnstr() depending on your platform port. */ -char* -lwip_strnstr(const char* buffer, const char* token, size_t n) +char * +lwip_strnstr(const char *buffer, const char *token, size_t n) { - const char* p; + const char *p; size_t tokenlen = strlen(token); if (tokenlen == 0) { return LWIP_CONST_CAST(char *, buffer); @@ -125,7 +125,7 @@ lwip_strnstr(const char* buffer, const char* token, size_t n) * This can be \#defined to stricmp() depending on your platform port. */ int -lwip_stricmp(const char* str1, const char* str2) +lwip_stricmp(const char *str1, const char *str2) { char c1, c2; @@ -160,7 +160,7 @@ lwip_stricmp(const char* str1, const char* str2) * This can be \#defined to strnicmp() depending on your platform port. */ int -lwip_strnicmp(const char* str1, const char* str2, size_t len) +lwip_strnicmp(const char *str1, const char *str2, size_t len) { char c1, c2; @@ -195,7 +195,7 @@ lwip_strnicmp(const char* str1, const char* str2, size_t len) * This can be \#defined to itoa() or snprintf(result, bufsize, "%d", number) depending on your platform port. */ void -lwip_itoa(char* result, size_t bufsize, int number) +lwip_itoa(char *result, size_t bufsize, int number) { char *res = result; char *tmp = result; @@ -212,11 +212,11 @@ lwip_itoa(char* result, size_t bufsize, int number) } /* ensure output string is zero terminated */ - result[bufsize-1] = 0; + result[bufsize - 1] = 0; result_len = 1; /* create the string in a temporary buffer since we don't know how long it will get */ - tmp = &result[bufsize-2]; + tmp = &result[bufsize - 2]; if (n == 0) { *tmp = '0'; tmp--; @@ -243,6 +243,6 @@ lwip_itoa(char* result, size_t bufsize, int number) return; } /* copy from temporary buffer to output buffer */ - memmove(res, tmp+1, result_len); + memmove(res, tmp + 1, result_len); } #endif diff --git a/src/core/dns.c b/src/core/dns.c index de482bae..4a648662 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -23,14 +23,14 @@ * Once a hostname has been resolved (or found to be non-existent), * the resolver code calls a specified callback function (which * must be implemented by the module that uses the resolver). - * + * * Multicast DNS queries are supported for names ending on ".local". * However, only "One-Shot Multicast DNS Queries" are supported (RFC 6762 * chapter 5.1), this is not a fully compliant implementation of continuous * mDNS querying! * * All functions must be called from TCPIP thread. - * + * * @see @ref netconn_common for thread-safe access. */ @@ -287,7 +287,7 @@ static err_t dns_lookup_local(const char *hostname, ip_addr_t *addr LWIP_DNS_ADD /* forward declarations */ static void dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port); static void dns_check_entries(void); -static void dns_call_found(u8_t idx, ip_addr_t* addr); +static void dns_call_found(u8_t idx, ip_addr_t *addr); /*----------------------------------------------------------------------------- * Globals @@ -325,9 +325,9 @@ dns_init(void) #endif /* DNS_SERVER_ADDRESS */ LWIP_ASSERT("sanity check SIZEOF_DNS_QUERY", - sizeof(struct dns_query) == SIZEOF_DNS_QUERY); + sizeof(struct dns_query) == SIZEOF_DNS_QUERY); LWIP_ASSERT("sanity check SIZEOF_DNS_ANSWER", - sizeof(struct dns_answer) <= SIZEOF_DNS_ANSWER_ASSERT); + sizeof(struct dns_answer) <= SIZEOF_DNS_ANSWER_ASSERT); LWIP_DEBUGF(DNS_DEBUG, ("dns_init: initializing\n")); @@ -340,7 +340,7 @@ dns_init(void) /* initialize DNS table not needed (initialized to zero since it is a * global variable) */ LWIP_ASSERT("For implicit initialization to work, DNS_STATE_UNUSED needs to be 0", - DNS_STATE_UNUSED == 0); + DNS_STATE_UNUSED == 0); /* initialize DNS client */ udp_bind(dns_pcbs[0], IP_ANY_TYPE, 0); @@ -380,7 +380,7 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver) * @return IP address of the indexed DNS server or "ip_addr_any" if the DNS * server has not been configured. */ -const ip_addr_t* +const ip_addr_t * dns_getserver(u8_t numdns) { if (numdns < DNS_MAX_SERVERS) { @@ -419,7 +419,7 @@ dns_init_local(void) entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST); LWIP_ASSERT("mem-error in dns_init_local", entry != NULL); if (entry != NULL) { - char* entry_name = (char*)entry + sizeof(struct local_hostlist_entry); + char *entry_name = (char *)entry + sizeof(struct local_hostlist_entry); MEMCPY(entry_name, init_entry->name, namelen); entry_name[namelen] = 0; entry->name = entry_name; @@ -566,7 +566,7 @@ dns_local_addhost(const char *hostname, const ip_addr_t *addr) { struct local_hostlist_entry *entry; size_t namelen; - char* entry_name; + char *entry_name; LWIP_ASSERT("invalid host name (NULL)", hostname != NULL); namelen = strlen(hostname); LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN); @@ -574,7 +574,7 @@ dns_local_addhost(const char *hostname, const ip_addr_t *addr) if (entry == NULL) { return ERR_MEM; } - entry_name = (char*)entry + sizeof(struct local_hostlist_entry); + entry_name = (char *)entry + sizeof(struct local_hostlist_entry); MEMCPY(entry_name, hostname, namelen); entry_name[namelen] = 0; entry->name = entry_name; @@ -646,7 +646,7 @@ dns_lookup(const char *name, ip_addr_t *addr LWIP_DNS_ADDRTYPE_ARG(u8_t dns_addr * @return 0xFFFF: names differ, other: names equal -> offset behind name */ static u16_t -dns_compare_name(const char *query, struct pbuf* p, u16_t start_offset) +dns_compare_name(const char *query, struct pbuf *p, u16_t start_offset) { int n; u16_t response_offset = start_offset; @@ -699,7 +699,7 @@ dns_compare_name(const char *query, struct pbuf* p, u16_t start_offset) * @return index to end of the name */ static u16_t -dns_skip_name(struct pbuf* p, u16_t query_idx) +dns_skip_name(struct pbuf *p, u16_t query_idx) { int n; u16_t offset = query_idx; @@ -749,16 +749,16 @@ dns_send(u8_t idx) const char *hostname, *hostname_part; u8_t n; u8_t pcb_idx; - struct dns_table_entry* entry = &dns_table[idx]; + struct dns_table_entry *entry = &dns_table[idx]; LWIP_DEBUGF(DNS_DEBUG, ("dns_send: dns_servers[%"U16_F"] \"%s\": request\n", - (u16_t)(entry->server_idx), entry->name)); + (u16_t)(entry->server_idx), entry->name)); LWIP_ASSERT("dns server out of array", entry->server_idx < DNS_MAX_SERVERS); if (ip_addr_isany_val(dns_servers[entry->server_idx]) #if LWIP_DNS_SUPPORT_MDNS_QUERIES && !entry->is_mdns #endif - ) { + ) { /* DNS server not valid anymore, e.g. PPP netif has been shut down */ /* call specified callback function if provided */ dns_call_found(idx, NULL); @@ -769,9 +769,9 @@ dns_send(u8_t idx) /* if here, we have either a new query or a retry on a previous query to process */ p = pbuf_alloc(PBUF_TRANSPORT, (u16_t)(SIZEOF_DNS_HDR + strlen(entry->name) + 2 + - SIZEOF_DNS_QUERY), PBUF_RAM); + SIZEOF_DNS_QUERY), PBUF_RAM); if (p != NULL) { - const ip_addr_t* dst; + const ip_addr_t *dst; u16_t dst_port; /* fill dns header */ memset(&hdr, 0, SIZEOF_DNS_HDR); @@ -818,13 +818,12 @@ dns_send(u8_t idx) #endif /* send dns packet */ LWIP_DEBUGF(DNS_DEBUG, ("sending DNS request ID %d for name \"%s\" to server %d\r\n", - entry->txid, entry->name, entry->server_idx)); + entry->txid, entry->name, entry->server_idx)); #if LWIP_DNS_SUPPORT_MDNS_QUERIES if (entry->is_mdns) { dst_port = DNS_MQUERY_PORT; #if LWIP_IPV6 - if (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype)) - { + if (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype)) { dst = &dns_mquery_v6group; } #endif @@ -857,11 +856,11 @@ overflow_return: } #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0) -static struct udp_pcb* +static struct udp_pcb * dns_alloc_random_port(void) { err_t err; - struct udp_pcb* pcb; + struct udp_pcb *pcb; pcb = udp_new_ip_type(IPADDR_TYPE_ANY); if (pcb == NULL) { @@ -934,7 +933,7 @@ dns_alloc_pcb(void) * @param addr IP address for the hostname (or NULL on error or memory shortage) */ static void -dns_call_found(u8_t idx, ip_addr_t* addr) +dns_call_found(u8_t idx, ip_addr_t *addr) { #if ((LWIP_DNS_SECURE & (LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING | LWIP_DNS_SECURE_RAND_SRC_PORT)) != 0) u8_t i; @@ -1050,9 +1049,9 @@ dns_check_entry(u8_t i) if (++entry->retries == DNS_MAX_RETRIES) { if ((entry->server_idx + 1 < DNS_MAX_SERVERS) && !ip_addr_isany_val(dns_servers[entry->server_idx + 1]) #if LWIP_DNS_SUPPORT_MDNS_QUERIES - && !entry->is_mdns + && !entry->is_mdns #endif /* LWIP_DNS_SUPPORT_MDNS_QUERIES */ - ) { + ) { /* change of server */ entry->server_idx++; entry->tmr = 1; @@ -1213,8 +1212,8 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, goto memerr; /* ignore this packet */ } if ((qry.cls != PP_HTONS(DNS_RRCLASS_IN)) || - (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype) && (qry.type != PP_HTONS(DNS_RRTYPE_AAAA))) || - (!LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype) && (qry.type != PP_HTONS(DNS_RRTYPE_A)))) { + (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype) && (qry.type != PP_HTONS(DNS_RRTYPE_AAAA))) || + (!LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype) && (qry.type != PP_HTONS(DNS_RRTYPE_A)))) { LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response not match to query\n", entry->name)); goto memerr; /* ignore this packet */ } @@ -1342,7 +1341,7 @@ dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found, u8_t lseq, lseqi; struct dns_table_entry *entry = NULL; size_t namelen; - struct dns_req_entry* req; + struct dns_req_entry *req; #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0) u8_t r; @@ -1436,7 +1435,7 @@ dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found, LWIP_DNS_SET_ADDRTYPE(req->reqaddrtype, dns_addrtype); req->found = found; req->arg = callback_arg; - namelen = LWIP_MIN(hostnamelen, DNS_MAX_NAME_LENGTH-1); + namelen = LWIP_MIN(hostnamelen, DNS_MAX_NAME_LENGTH - 1); MEMCPY(entry->name, name, namelen); entry->name[namelen] = 0; @@ -1588,7 +1587,7 @@ dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr, dns_found_call /* queue query with specified callback */ return dns_enqueue(hostname, hostnamelen, found, callback_arg LWIP_DNS_ADDRTYPE_ARG(dns_addrtype) - LWIP_DNS_ISMDNS_ARG(is_mdns)); + LWIP_DNS_ISMDNS_ARG(is_mdns)); } #endif /* LWIP_DNS */ diff --git a/src/core/inet_chksum.c b/src/core/inet_chksum.c index e027169e..79fbd8d8 100644 --- a/src/core/inet_chksum.c +++ b/src/core/inet_chksum.c @@ -8,7 +8,7 @@ * your own version, link it in and in your cc.h put: * * \#define LWIP_CHKSUM your_checksum_routine - * + * * Or you can select from the implementations below by defining * LWIP_CHKSUM_ALGORITHM to 1, 2 or 3. */ @@ -85,7 +85,7 @@ lwip_standard_chksum(const void *dataptr, int len) acc = 0; /* dataptr may be at odd or even addresses */ - octetptr = (const u8_t*)dataptr; + octetptr = (const u8_t *)dataptr; while (len > 1) { /* declare first octet as most significant thus assume network order, ignoring host order */ @@ -201,14 +201,14 @@ lwip_standard_chksum(const void *dataptr, int len) len--; } - ps = (const u16_t *)(const void*)pb; + ps = (const u16_t *)(const void *)pb; if (((mem_ptr_t)ps & 3) && len > 1) { sum += *ps++; len -= 2; } - pl = (const u32_t *)(const void*)ps; + pl = (const u32_t *)(const void *)ps; while (len > 7) { tmp = sum + *pl++; /* ping */ @@ -265,7 +265,7 @@ inet_cksum_pseudo_base(struct pbuf *p, u8_t proto, u16_t proto_len, u32_t acc) /* iterate through all pbuf in chain */ for (q = p; q != NULL; q = q->next) { LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n", - (void *)q, (void *)q->next)); + (void *)q, (void *)q->next)); acc += LWIP_CHKSUM(q->payload, q->len); /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%"X32_F" \n", acc));*/ /* just executing this next line is probably faster that the if statement needed @@ -308,7 +308,7 @@ inet_cksum_pseudo_base(struct pbuf *p, u8_t proto, u16_t proto_len, u32_t acc) */ u16_t inet_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, - const ip4_addr_t *src, const ip4_addr_t *dest) + const ip4_addr_t *src, const ip4_addr_t *dest) { u32_t acc; u32_t addr; @@ -341,7 +341,7 @@ inet_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, */ u16_t ip6_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, - const ip6_addr_t *src, const ip6_addr_t *dest) + const ip6_addr_t *src, const ip6_addr_t *dest) { u32_t acc = 0; u32_t addr; @@ -377,7 +377,7 @@ ip6_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, */ u16_t ip_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, - const ip_addr_t *src, const ip_addr_t *dest) + const ip_addr_t *src, const ip_addr_t *dest) { #if LWIP_IPV6 if (IP_IS_V6(dest)) { @@ -397,7 +397,7 @@ ip_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, /** Parts of the pseudo checksum which are common to IPv4 and IPv6 */ static u16_t inet_cksum_pseudo_partial_base(struct pbuf *p, u8_t proto, u16_t proto_len, - u16_t chksum_len, u32_t acc) + u16_t chksum_len, u32_t acc) { struct pbuf *q; int swapped = 0; @@ -406,7 +406,7 @@ inet_cksum_pseudo_partial_base(struct pbuf *p, u8_t proto, u16_t proto_len, /* iterate through all pbuf in chain */ for (q = p; (q != NULL) && (chksum_len > 0); q = q->next) { LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n", - (void *)q, (void *)q->next)); + (void *)q, (void *)q->next)); chklen = q->len; if (chklen > chksum_len) { chklen = chksum_len; @@ -454,7 +454,7 @@ inet_cksum_pseudo_partial_base(struct pbuf *p, u8_t proto, u16_t proto_len, */ u16_t inet_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, - u16_t chksum_len, const ip4_addr_t *src, const ip4_addr_t *dest) + u16_t chksum_len, const ip4_addr_t *src, const ip4_addr_t *dest) { u32_t acc; u32_t addr; @@ -489,7 +489,7 @@ inet_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, */ u16_t ip6_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, - u16_t chksum_len, const ip6_addr_t *src, const ip6_addr_t *dest) + u16_t chksum_len, const ip6_addr_t *src, const ip6_addr_t *dest) { u32_t acc = 0; u32_t addr; @@ -524,7 +524,7 @@ ip6_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, */ u16_t ip_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, - u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest) + u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest) { #if LWIP_IPV6 if (IP_IS_V6(dest)) { diff --git a/src/core/init.c b/src/core/init.c index 9a73034b..8841fa05 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -67,8 +67,7 @@ # include "arch/bpstruct.h" #endif PACK_STRUCT_BEGIN -struct packed_struct_test -{ +struct packed_struct_test { PACK_STRUCT_FLD_8(u8_t dummy1); PACK_STRUCT_FIELD(u32_t dummy2); } PACK_STRUCT_STRUCT; @@ -84,85 +83,85 @@ PACK_STRUCT_END * These can be done independently of LWIP_DEBUG, without penalty. */ #ifndef BYTE_ORDER - #error "BYTE_ORDER is not defined, you have to define it in your cc.h" +#error "BYTE_ORDER is not defined, you have to define it in your cc.h" #endif #if (!IP_SOF_BROADCAST && IP_SOF_BROADCAST_RECV) - #error "If you want to use broadcast filter per pcb on recv operations, you have to define IP_SOF_BROADCAST=1 in your lwipopts.h" +#error "If you want to use broadcast filter per pcb on recv operations, you have to define IP_SOF_BROADCAST=1 in your lwipopts.h" #endif #if (!LWIP_UDP && LWIP_UDPLITE) - #error "If you want to use UDP Lite, you have to define LWIP_UDP=1 in your lwipopts.h" +#error "If you want to use UDP Lite, you have to define LWIP_UDP=1 in your lwipopts.h" #endif #if (!LWIP_UDP && LWIP_DHCP) - #error "If you want to use DHCP, you have to define LWIP_UDP=1 in your lwipopts.h" +#error "If you want to use DHCP, you have to define LWIP_UDP=1 in your lwipopts.h" #endif #if (!LWIP_UDP && !LWIP_RAW && LWIP_MULTICAST_TX_OPTIONS) - #error "If you want to use LWIP_MULTICAST_TX_OPTIONS, you have to define LWIP_UDP=1 and/or LWIP_RAW=1 in your lwipopts.h" +#error "If you want to use LWIP_MULTICAST_TX_OPTIONS, you have to define LWIP_UDP=1 and/or LWIP_RAW=1 in your lwipopts.h" #endif #if (!LWIP_UDP && LWIP_DNS) - #error "If you want to use DNS, you have to define LWIP_UDP=1 in your lwipopts.h" +#error "If you want to use DNS, you have to define LWIP_UDP=1 in your lwipopts.h" #endif #if !MEMP_MEM_MALLOC /* MEMP_NUM_* checks are disabled when not using the pool allocator */ #if (LWIP_ARP && ARP_QUEUEING && (MEMP_NUM_ARP_QUEUE<=0)) - #error "If you want to use ARP Queueing, you have to define MEMP_NUM_ARP_QUEUE>=1 in your lwipopts.h" +#error "If you want to use ARP Queueing, you have to define MEMP_NUM_ARP_QUEUE>=1 in your lwipopts.h" #endif #if (LWIP_RAW && (MEMP_NUM_RAW_PCB<=0)) - #error "If you want to use RAW, you have to define MEMP_NUM_RAW_PCB>=1 in your lwipopts.h" +#error "If you want to use RAW, you have to define MEMP_NUM_RAW_PCB>=1 in your lwipopts.h" #endif #if (LWIP_UDP && (MEMP_NUM_UDP_PCB<=0)) - #error "If you want to use UDP, you have to define MEMP_NUM_UDP_PCB>=1 in your lwipopts.h" +#error "If you want to use UDP, you have to define MEMP_NUM_UDP_PCB>=1 in your lwipopts.h" #endif #if (LWIP_TCP && (MEMP_NUM_TCP_PCB<=0)) - #error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h" +#error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h" #endif #if (LWIP_IGMP && (MEMP_NUM_IGMP_GROUP<=1)) - #error "If you want to use IGMP, you have to define MEMP_NUM_IGMP_GROUP>1 in your lwipopts.h" +#error "If you want to use IGMP, you have to define MEMP_NUM_IGMP_GROUP>1 in your lwipopts.h" #endif #if (LWIP_IGMP && !LWIP_MULTICAST_TX_OPTIONS) - #error "If you want to use IGMP, you have to define LWIP_MULTICAST_TX_OPTIONS==1 in your lwipopts.h" +#error "If you want to use IGMP, you have to define LWIP_MULTICAST_TX_OPTIONS==1 in your lwipopts.h" #endif #if (LWIP_IGMP && !LWIP_IPV4) - #error "IGMP needs LWIP_IPV4 enabled in your lwipopts.h" +#error "IGMP needs LWIP_IPV4 enabled in your lwipopts.h" #endif #if ((LWIP_NETCONN || LWIP_SOCKET) && (MEMP_NUM_TCPIP_MSG_API<=0)) - #error "If you want to use Sequential API, you have to define MEMP_NUM_TCPIP_MSG_API>=1 in your lwipopts.h" +#error "If you want to use Sequential API, you have to define MEMP_NUM_TCPIP_MSG_API>=1 in your lwipopts.h" #endif /* There must be sufficient timeouts, taking into account requirements of the subsystems. */ #if LWIP_TIMERS && (MEMP_NUM_SYS_TIMEOUT < LWIP_NUM_SYS_TIMEOUT_INTERNAL) - #error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts" +#error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts" #endif #if (IP_REASSEMBLY && (MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS)) - #error "MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS doesn't make sense since each struct ip_reassdata must hold 2 pbufs at least!" +#error "MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS doesn't make sense since each struct ip_reassdata must hold 2 pbufs at least!" #endif #endif /* !MEMP_MEM_MALLOC */ #if LWIP_WND_SCALE #if (LWIP_TCP && (TCP_WND > 0xffffffff)) - #error "If you want to use TCP, TCP_WND must fit in an u32_t, so, you have to reduce it in your lwipopts.h" +#error "If you want to use TCP, TCP_WND must fit in an u32_t, so, you have to reduce it in your lwipopts.h" #endif #if (LWIP_TCP && (TCP_RCV_SCALE > 14)) - #error "The maximum valid window scale value is 14!" +#error "The maximum valid window scale value is 14!" #endif #if (LWIP_TCP && (TCP_WND > (0xFFFFU << TCP_RCV_SCALE))) - #error "TCP_WND is bigger than the configured LWIP_WND_SCALE allows!" +#error "TCP_WND is bigger than the configured LWIP_WND_SCALE allows!" #endif #if (LWIP_TCP && ((TCP_WND >> TCP_RCV_SCALE) == 0)) - #error "TCP_WND is too small for the configured LWIP_WND_SCALE (results in zero window)!" +#error "TCP_WND is too small for the configured LWIP_WND_SCALE (results in zero window)!" #endif #else /* LWIP_WND_SCALE */ #if (LWIP_TCP && (TCP_WND > 0xffff)) - #error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h (or enable window scaling)" +#error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h (or enable window scaling)" #endif #endif /* LWIP_WND_SCALE */ #if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff)) - #error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h" +#error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h" #endif #if (LWIP_TCP && (TCP_SND_QUEUELEN < 2)) - #error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work" +#error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work" #endif #if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12))) - #error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h" +#error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h" #endif #if (LWIP_TCP && TCP_LISTEN_BACKLOG && ((TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff))) - #error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t" +#error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t" #endif #if (LWIP_TCP && LWIP_TCP_SACK_OUT && !TCP_QUEUE_OOSEQ) #error "To use LWIP_TCP_SACK_OUT, TCP_QUEUE_OOSEQ needs to be enabled" @@ -171,80 +170,80 @@ PACK_STRUCT_END #error "LWIP_TCP_MAX_SACK_NUM must be greater than 0" #endif #if (LWIP_NETIF_API && (NO_SYS==1)) - #error "If you want to use NETIF API, you have to define NO_SYS=0 in your lwipopts.h" +#error "If you want to use NETIF API, you have to define NO_SYS=0 in your lwipopts.h" #endif #if ((LWIP_SOCKET || LWIP_NETCONN) && (NO_SYS==1)) - #error "If you want to use Sequential API, you have to define NO_SYS=0 in your lwipopts.h" +#error "If you want to use Sequential API, you have to define NO_SYS=0 in your lwipopts.h" #endif #if (LWIP_PPP_API && (NO_SYS==1)) - #error "If you want to use PPP API, you have to define NO_SYS=0 in your lwipopts.h" +#error "If you want to use PPP API, you have to define NO_SYS=0 in your lwipopts.h" #endif #if (LWIP_PPP_API && (PPP_SUPPORT==0)) - #error "If you want to use PPP API, you have to enable PPP_SUPPORT in your lwipopts.h" +#error "If you want to use PPP API, you have to enable PPP_SUPPORT in your lwipopts.h" #endif #if (((!LWIP_DHCP) || (!LWIP_AUTOIP)) && LWIP_DHCP_AUTOIP_COOP) - #error "If you want to use DHCP/AUTOIP cooperation mode, you have to define LWIP_DHCP=1 and LWIP_AUTOIP=1 in your lwipopts.h" +#error "If you want to use DHCP/AUTOIP cooperation mode, you have to define LWIP_DHCP=1 and LWIP_AUTOIP=1 in your lwipopts.h" #endif #if (((!LWIP_DHCP) || (!LWIP_ARP)) && DHCP_DOES_ARP_CHECK) - #error "If you want to use DHCP ARP checking, you have to define LWIP_DHCP=1 and LWIP_ARP=1 in your lwipopts.h" +#error "If you want to use DHCP ARP checking, you have to define LWIP_DHCP=1 and LWIP_ARP=1 in your lwipopts.h" #endif #if (!LWIP_ARP && LWIP_AUTOIP) - #error "If you want to use AUTOIP, you have to define LWIP_ARP=1 in your lwipopts.h" +#error "If you want to use AUTOIP, you have to define LWIP_ARP=1 in your lwipopts.h" #endif #if (LWIP_TCP && ((LWIP_EVENT_API && LWIP_CALLBACK_API) || (!LWIP_EVENT_API && !LWIP_CALLBACK_API))) - #error "One and exactly one of LWIP_EVENT_API and LWIP_CALLBACK_API has to be enabled in your lwipopts.h" +#error "One and exactly one of LWIP_EVENT_API and LWIP_CALLBACK_API has to be enabled in your lwipopts.h" #endif #if (MEM_LIBC_MALLOC && MEM_USE_POOLS) - #error "MEM_LIBC_MALLOC and MEM_USE_POOLS may not both be simultaneously enabled in your lwipopts.h" +#error "MEM_LIBC_MALLOC and MEM_USE_POOLS may not both be simultaneously enabled in your lwipopts.h" #endif #if (MEM_USE_POOLS && !MEMP_USE_CUSTOM_POOLS) - #error "MEM_USE_POOLS requires custom pools (MEMP_USE_CUSTOM_POOLS) to be enabled in your lwipopts.h" +#error "MEM_USE_POOLS requires custom pools (MEMP_USE_CUSTOM_POOLS) to be enabled in your lwipopts.h" #endif #if (PBUF_POOL_BUFSIZE <= MEM_ALIGNMENT) - #error "PBUF_POOL_BUFSIZE must be greater than MEM_ALIGNMENT or the offset may take the full first pbuf" +#error "PBUF_POOL_BUFSIZE must be greater than MEM_ALIGNMENT or the offset may take the full first pbuf" #endif #if (DNS_LOCAL_HOSTLIST && !DNS_LOCAL_HOSTLIST_IS_DYNAMIC && !(defined(DNS_LOCAL_HOSTLIST_INIT))) - #error "you have to define define DNS_LOCAL_HOSTLIST_INIT {{'host1', 0x123}, {'host2', 0x234}} to initialize DNS_LOCAL_HOSTLIST" +#error "you have to define define DNS_LOCAL_HOSTLIST_INIT {{'host1', 0x123}, {'host2', 0x234}} to initialize DNS_LOCAL_HOSTLIST" #endif #if PPP_SUPPORT && !PPPOS_SUPPORT && !PPPOE_SUPPORT && !PPPOL2TP_SUPPORT - #error "PPP_SUPPORT needs at least one of PPPOS_SUPPORT, PPPOE_SUPPORT or PPPOL2TP_SUPPORT turned on" +#error "PPP_SUPPORT needs at least one of PPPOS_SUPPORT, PPPOE_SUPPORT or PPPOL2TP_SUPPORT turned on" #endif #if PPP_SUPPORT && !PPP_IPV4_SUPPORT && !PPP_IPV6_SUPPORT - #error "PPP_SUPPORT needs PPP_IPV4_SUPPORT and/or PPP_IPV6_SUPPORT turned on" +#error "PPP_SUPPORT needs PPP_IPV4_SUPPORT and/or PPP_IPV6_SUPPORT turned on" #endif #if PPP_SUPPORT && PPP_IPV4_SUPPORT && !LWIP_IPV4 - #error "PPP_IPV4_SUPPORT needs LWIP_IPV4 turned on" +#error "PPP_IPV4_SUPPORT needs LWIP_IPV4 turned on" #endif #if PPP_SUPPORT && PPP_IPV6_SUPPORT && !LWIP_IPV6 - #error "PPP_IPV6_SUPPORT needs LWIP_IPV6 turned on" +#error "PPP_IPV6_SUPPORT needs LWIP_IPV6 turned on" #endif #if !LWIP_ETHERNET && (LWIP_ARP || PPPOE_SUPPORT) - #error "LWIP_ETHERNET needs to be turned on for LWIP_ARP or PPPOE_SUPPORT" +#error "LWIP_ETHERNET needs to be turned on for LWIP_ARP or PPPOE_SUPPORT" #endif #if LWIP_TCPIP_CORE_LOCKING_INPUT && !LWIP_TCPIP_CORE_LOCKING - #error "When using LWIP_TCPIP_CORE_LOCKING_INPUT, LWIP_TCPIP_CORE_LOCKING must be enabled, too" +#error "When using LWIP_TCPIP_CORE_LOCKING_INPUT, LWIP_TCPIP_CORE_LOCKING must be enabled, too" #endif #if LWIP_TCP && LWIP_NETIF_TX_SINGLE_PBUF && !TCP_OVERSIZE - #error "LWIP_NETIF_TX_SINGLE_PBUF needs TCP_OVERSIZE enabled to create single-pbuf TCP packets" +#error "LWIP_NETIF_TX_SINGLE_PBUF needs TCP_OVERSIZE enabled to create single-pbuf TCP packets" #endif #if LWIP_NETCONN && LWIP_TCP #if NETCONN_COPY != TCP_WRITE_FLAG_COPY - #error "NETCONN_COPY != TCP_WRITE_FLAG_COPY" +#error "NETCONN_COPY != TCP_WRITE_FLAG_COPY" #endif #if NETCONN_MORE != TCP_WRITE_FLAG_MORE - #error "NETCONN_MORE != TCP_WRITE_FLAG_MORE" +#error "NETCONN_MORE != TCP_WRITE_FLAG_MORE" #endif #endif /* LWIP_NETCONN && LWIP_TCP */ #if LWIP_SOCKET /* Check that the SO_* socket options and SOF_* lwIP-internal flags match */ #if SO_REUSEADDR != SOF_REUSEADDR - #error "WARNING: SO_REUSEADDR != SOF_REUSEADDR" +#error "WARNING: SO_REUSEADDR != SOF_REUSEADDR" #endif #if SO_KEEPALIVE != SOF_KEEPALIVE - #error "WARNING: SO_KEEPALIVE != SOF_KEEPALIVE" +#error "WARNING: SO_KEEPALIVE != SOF_KEEPALIVE" #endif #if SO_BROADCAST != SOF_BROADCAST - #error "WARNING: SO_BROADCAST != SOF_BROADCAST" +#error "WARNING: SO_BROADCAST != SOF_BROADCAST" #endif #endif /* LWIP_SOCKET */ @@ -252,22 +251,22 @@ PACK_STRUCT_END /* Compile-time checks for deprecated options. */ #ifdef MEMP_NUM_TCPIP_MSG - #error "MEMP_NUM_TCPIP_MSG option is deprecated. Remove it from your lwipopts.h." +#error "MEMP_NUM_TCPIP_MSG option is deprecated. Remove it from your lwipopts.h." #endif #ifdef TCP_REXMIT_DEBUG - #error "TCP_REXMIT_DEBUG option is deprecated. Remove it from your lwipopts.h." +#error "TCP_REXMIT_DEBUG option is deprecated. Remove it from your lwipopts.h." #endif #ifdef RAW_STATS - #error "RAW_STATS option is deprecated. Remove it from your lwipopts.h." +#error "RAW_STATS option is deprecated. Remove it from your lwipopts.h." #endif #ifdef ETHARP_QUEUE_FIRST - #error "ETHARP_QUEUE_FIRST option is deprecated. Remove it from your lwipopts.h." +#error "ETHARP_QUEUE_FIRST option is deprecated. Remove it from your lwipopts.h." #endif #ifdef ETHARP_ALWAYS_INSERT - #error "ETHARP_ALWAYS_INSERT option is deprecated. Remove it from your lwipopts.h." +#error "ETHARP_ALWAYS_INSERT option is deprecated. Remove it from your lwipopts.h." #endif #if !NO_SYS && LWIP_TCPIP_CORE_LOCKING && LWIP_COMPAT_MUTEX && !defined(LWIP_COMPAT_MUTEX_ALLOWED) - #error "LWIP_COMPAT_MUTEX cannot prevent priority inversion. It is recommended to implement priority-aware mutexes. (Define LWIP_COMPAT_MUTEX_ALLOWED to disable this error.)" +#error "LWIP_COMPAT_MUTEX cannot prevent priority inversion. It is recommended to implement priority-aware mutexes. (Define LWIP_COMPAT_MUTEX_ALLOWED to disable this error.)" #endif #ifndef LWIP_DISABLE_TCP_SANITY_CHECKS @@ -302,31 +301,31 @@ PACK_STRUCT_END #if !LWIP_DISABLE_TCP_SANITY_CHECKS #if LWIP_TCP #if !MEMP_MEM_MALLOC && (MEMP_NUM_TCP_SEG < TCP_SND_QUEUELEN) - #error "lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." +#error "lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if TCP_SND_BUF < (2 * TCP_MSS) - #error "lwip_sanity_check: WARNING: TCP_SND_BUF must be at least as much as (2 * TCP_MSS) for things to work smoothly. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." +#error "lwip_sanity_check: WARNING: TCP_SND_BUF must be at least as much as (2 * TCP_MSS) for things to work smoothly. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if TCP_SND_QUEUELEN < (2 * (TCP_SND_BUF / TCP_MSS)) - #error "lwip_sanity_check: WARNING: TCP_SND_QUEUELEN must be at least as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." +#error "lwip_sanity_check: WARNING: TCP_SND_QUEUELEN must be at least as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if TCP_SNDLOWAT >= TCP_SND_BUF - #error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than TCP_SND_BUF. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." +#error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than TCP_SND_BUF. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if TCP_SNDLOWAT >= (0xFFFF - (4 * TCP_MSS)) - #error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must at least be 4*MSS below u16_t overflow!" +#error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must at least be 4*MSS below u16_t overflow!" #endif #if TCP_SNDQUEUELOWAT >= TCP_SND_QUEUELEN - #error "lwip_sanity_check: WARNING: TCP_SNDQUEUELOWAT must be less than TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." +#error "lwip_sanity_check: WARNING: TCP_SNDQUEUELOWAT must be less than TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (PBUF_POOL_BUFSIZE <= (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)) - #error "lwip_sanity_check: WARNING: PBUF_POOL_BUFSIZE does not provide enough space for protocol headers. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." +#error "lwip_sanity_check: WARNING: PBUF_POOL_BUFSIZE does not provide enough space for protocol headers. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (TCP_WND > (PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)))) - #error "lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - protocol headers). If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." +#error "lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - protocol headers). If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if TCP_WND < TCP_MSS - #error "lwip_sanity_check: WARNING: TCP_WND is smaller than MSS. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." +#error "lwip_sanity_check: WARNING: TCP_WND is smaller than MSS. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #endif /* LWIP_TCP */ #endif /* !LWIP_DISABLE_TCP_SANITY_CHECKS */ @@ -342,7 +341,7 @@ lwip_init(void) #ifndef LWIP_SKIP_CONST_CHECK int a = 0; LWIP_UNUSED_ARG(a); - LWIP_ASSERT("LWIP_CONST_CAST not implemented correctly. Check your lwIP port.", LWIP_CONST_CAST(void*, &a) == &a); + LWIP_ASSERT("LWIP_CONST_CAST not implemented correctly. Check your lwIP port.", LWIP_CONST_CAST(void *, &a) == &a); #endif #ifndef LWIP_SKIP_PACKING_CHECK LWIP_ASSERT("Struct packing not implemented correctly. Check your lwIP port.", sizeof(struct packed_struct_test) == PACKED_STRUCT_TEST_EXPECTED_SIZE); @@ -381,7 +380,7 @@ lwip_init(void) #if PPP_SUPPORT ppp_init(); #endif - + #if LWIP_TIMERS sys_timeouts_init(); #endif /* LWIP_TIMERS */ diff --git a/src/core/ip.c b/src/core/ip.c index 181ebf51..18514cf3 100644 --- a/src/core/ip.c +++ b/src/core/ip.c @@ -4,19 +4,19 @@ * * @defgroup ip IP * @ingroup callbackstyle_api - * + * * @defgroup ip4 IPv4 * @ingroup ip * * @defgroup ip6 IPv6 * @ingroup ip - * + * * @defgroup ipaddr IP address handling * @ingroup infrastructure - * + * * @defgroup ip4addr IPv4 only * @ingroup ipaddr - * + * * @defgroup ip6addr IPv6 only * @ingroup ipaddr */ @@ -123,7 +123,7 @@ int ipaddr_aton(const char *cp, ip_addr_t *addr) { if (cp != NULL) { - const char* c; + const char *c; for (c = cp; *c != 0; c++) { if (*c == ':') { /* contains a colon: IPv6 address */ diff --git a/src/core/mem.c b/src/core/mem.c index 8fb7f334..8a77a670 100644 --- a/src/core/mem.c +++ b/src/core/mem.c @@ -84,7 +84,7 @@ mem_init(void) * C library malloc(): we can't free part of a pool element and the stack * support mem_trim() to return a different pointer */ -void* +void * mem_trim(void *mem, mem_size_t size) { LWIP_UNUSED_ARG(size); @@ -125,14 +125,14 @@ mem_trim(void *mem, mem_size_t size) void * mem_malloc(mem_size_t size) { - void* ret = mem_clib_malloc(size + MEM_LIBC_STATSHELPER_SIZE); + void *ret = mem_clib_malloc(size + MEM_LIBC_STATSHELPER_SIZE); if (ret == NULL) { MEM_STATS_INC_LOCKED(err); } else { LWIP_ASSERT("malloc() must return aligned memory", LWIP_MEM_ALIGN(ret) == ret); #if LWIP_STATS && MEM_STATS - *(mem_size_t*)ret = size; - ret = (u8_t*)ret + MEM_LIBC_STATSHELPER_SIZE; + *(mem_size_t *)ret = size; + ret = (u8_t *)ret + MEM_LIBC_STATSHELPER_SIZE; MEM_STATS_INC_USED_LOCKED(used, size); #endif } @@ -149,8 +149,8 @@ mem_free(void *rmem) LWIP_ASSERT("rmem != NULL", (rmem != NULL)); LWIP_ASSERT("rmem == MEM_ALIGN(rmem)", (rmem == LWIP_MEM_ALIGN(rmem))); #if LWIP_STATS && MEM_STATS - rmem = (u8_t*)rmem - MEM_LIBC_STATSHELPER_SIZE; - MEM_STATS_DEC_USED_LOCKED(used, *(mem_size_t*)rmem); + rmem = (u8_t *)rmem - MEM_LIBC_STATSHELPER_SIZE; + MEM_STATS_DEC_USED_LOCKED(used, *(mem_size_t *)rmem); #endif mem_clib_free(rmem); } @@ -178,7 +178,7 @@ mem_malloc(mem_size_t size) /* is this pool big enough to hold an element of the required size plus a struct memp_malloc_helper that saves the pool this element came from? */ if (required_size <= memp_pools[poolnr]->size) { - element = (struct memp_malloc_helper*)memp_malloc(poolnr); + element = (struct memp_malloc_helper *)memp_malloc(poolnr); if (element == NULL) { /* No need to DEBUGF or ASSERT: This error is already taken care of in memp.c */ #if MEM_USE_POOLS_TRY_BIGGER_POOL @@ -202,7 +202,7 @@ mem_malloc(mem_size_t size) /* save the pool number this element came from */ element->poolnr = poolnr; /* and return a pointer to the memory directly after the struct memp_malloc_helper */ - ret = (u8_t*)element + LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper)); + ret = (u8_t *)element + LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper)); #if MEMP_OVERFLOW_CHECK || (LWIP_STATS && MEM_STATS) /* truncating to u16_t is safe because struct memp_desc::size is u16_t */ @@ -211,7 +211,7 @@ mem_malloc(mem_size_t size) #endif /* MEMP_OVERFLOW_CHECK || (LWIP_STATS && MEM_STATS) */ #if MEMP_OVERFLOW_CHECK /* initialize unused memory (diff between requested size and selected pool's size) */ - memset((u8_t*)ret + size, 0xcd, memp_pools[poolnr]->size - size); + memset((u8_t *)ret + size, 0xcd, memp_pools[poolnr]->size - size); #endif /* MEMP_OVERFLOW_CHECK */ return ret; } @@ -233,7 +233,7 @@ mem_free(void *rmem) /* get the original struct memp_malloc_helper */ /* cast through void* to get rid of alignment warnings */ - hmem = (struct memp_malloc_helper*)(void*)((u8_t*)rmem - LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper))); + hmem = (struct memp_malloc_helper *)(void *)((u8_t *)rmem - LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper))); LWIP_ASSERT("hmem != NULL", (hmem != NULL)); LWIP_ASSERT("hmem == MEM_ALIGN(hmem)", (hmem == LWIP_MEM_ALIGN(hmem))); @@ -242,14 +242,14 @@ mem_free(void *rmem) MEM_STATS_DEC_USED_LOCKED(used, hmem->size); #if MEMP_OVERFLOW_CHECK { - u16_t i; - LWIP_ASSERT("MEM_USE_POOLS: invalid chunk size", - hmem->size <= memp_pools[hmem->poolnr]->size); - /* check that unused memory remained untouched (diff between requested size and selected pool's size) */ - for (i = hmem->size; i < memp_pools[hmem->poolnr]->size; i++) { - u8_t data = *((u8_t*)rmem + i); - LWIP_ASSERT("MEM_USE_POOLS: mem overflow detected", data == 0xcd); - } + u16_t i; + LWIP_ASSERT("MEM_USE_POOLS: invalid chunk size", + hmem->size <= memp_pools[hmem->poolnr]->size); + /* check that unused memory remained untouched (diff between requested size and selected pool's size) */ + for (i = hmem->size; i < memp_pools[hmem->poolnr]->size; i++) { + u8_t data = *((u8_t *)rmem + i); + LWIP_ASSERT("MEM_USE_POOLS: mem overflow detected", data == 0xcd); + } } #endif /* MEMP_OVERFLOW_CHECK */ @@ -291,7 +291,7 @@ struct mem { * how that space is calculated). */ #ifndef LWIP_RAM_HEAP_POINTER /** the heap. we need one struct mem at the end and some room for alignment */ -LWIP_DECLARE_MEMORY_ALIGNED(ram_heap, MEM_SIZE_ALIGNED + (2U*SIZEOF_STRUCT_MEM)); +LWIP_DECLARE_MEMORY_ALIGNED(ram_heap, MEM_SIZE_ALIGNED + (2U * SIZEOF_STRUCT_MEM)); #define LWIP_RAM_HEAP_POINTER ram_heap #endif /* LWIP_RAM_HEAP_POINTER */ @@ -388,7 +388,7 @@ mem_init(void) struct mem *mem; LWIP_ASSERT("Sanity check alignment", - (SIZEOF_STRUCT_MEM & (MEM_ALIGNMENT-1)) == 0); + (SIZEOF_STRUCT_MEM & (MEM_ALIGNMENT - 1)) == 0); /* align the heap */ ram = (u8_t *)LWIP_MEM_ALIGN(LWIP_RAM_HEAP_POINTER); @@ -429,10 +429,10 @@ mem_free(void *rmem) LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("mem_free(p == NULL) was called.\n")); return; } - LWIP_ASSERT("mem_free: sanity check alignment", (((mem_ptr_t)rmem) & (MEM_ALIGNMENT-1)) == 0); + LWIP_ASSERT("mem_free: sanity check alignment", (((mem_ptr_t)rmem) & (MEM_ALIGNMENT - 1)) == 0); LWIP_ASSERT("mem_free: legal memory", (u8_t *)rmem >= (u8_t *)ram && - (u8_t *)rmem < (u8_t *)ram_end); + (u8_t *)rmem < (u8_t *)ram_end); if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) { LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("mem_free: illegal memory\n")); @@ -497,7 +497,7 @@ mem_trim(void *rmem, mem_size_t new_size) } LWIP_ASSERT("mem_trim: legal memory", (u8_t *)rmem >= (u8_t *)ram && - (u8_t *)rmem < (u8_t *)ram_end); + (u8_t *)rmem < (u8_t *)ram_end); if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) { LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("mem_trim: illegal memory\n")); @@ -718,11 +718,11 @@ mem_malloc_adjust_lfree: LWIP_MEM_ALLOC_UNPROTECT(); sys_mutex_unlock(&mem_mutex); LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.", - (mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end); + (mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end); LWIP_ASSERT("mem_malloc: allocated memory properly aligned.", - ((mem_ptr_t)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0); + ((mem_ptr_t)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0); LWIP_ASSERT("mem_malloc: sanity check alignment", - (((mem_ptr_t)mem) & (MEM_ALIGNMENT-1)) == 0); + (((mem_ptr_t)mem) & (MEM_ALIGNMENT - 1)) == 0); return (u8_t *)mem + SIZEOF_STRUCT_MEM; } diff --git a/src/core/memp.c b/src/core/memp.c index 09c84f5c..10932100 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -80,7 +80,7 @@ #define LWIP_MEMPOOL(name,num,size,desc) LWIP_MEMPOOL_DECLARE(name,num,size,desc) #include "lwip/priv/memp_std.h" -const struct memp_desc* const memp_pools[MEMP_MAX] = { +const struct memp_desc *const memp_pools[MEMP_MAX] = { #define LWIP_MEMPOOL(name,num,size,desc) &memp_ ## name, #include "lwip/priv/memp_std.h" }; @@ -107,7 +107,7 @@ memp_sanity(const struct memp_desc *desc) t = *desc->tab; if (t != NULL) { for (h = t->next; (t != NULL) && (h != NULL); t = t->next, - h = ((h->next != NULL) ? h->next->next : NULL)) { + h = ((h->next != NULL) ? h->next->next : NULL)) { if (t == h) { return 0; } @@ -132,7 +132,7 @@ memp_overflow_check_element_overflow(struct memp *p, const struct memp_desc *des #if MEMP_SANITY_REGION_AFTER_ALIGNED > 0 u16_t k; u8_t *m; - m = (u8_t*)p + MEMP_SIZE + desc->size; + m = (u8_t *)p + MEMP_SIZE + desc->size; for (k = 0; k < MEMP_SANITY_REGION_AFTER_ALIGNED; k++) { if (m[k] != 0xcd) { char errstr[128] = "detected memp overflow in pool "; @@ -159,7 +159,7 @@ memp_overflow_check_element_underflow(struct memp *p, const struct memp_desc *de #if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 u16_t k; u8_t *m; - m = (u8_t*)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED; + m = (u8_t *)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED; for (k = 0; k < MEMP_SANITY_REGION_BEFORE_ALIGNED; k++) { if (m[k] != 0xcd) { char errstr[128] = "detected memp underflow in pool "; @@ -182,11 +182,11 @@ memp_overflow_init_element(struct memp *p, const struct memp_desc *desc) #if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 || MEMP_SANITY_REGION_AFTER_ALIGNED > 0 u8_t *m; #if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 - m = (u8_t*)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED; + m = (u8_t *)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED; memset(m, 0xcd, MEMP_SANITY_REGION_BEFORE_ALIGNED); #endif #if MEMP_SANITY_REGION_AFTER_ALIGNED > 0 - m = (u8_t*)p + MEMP_SIZE + desc->size; + m = (u8_t *)p + MEMP_SIZE + desc->size; memset(m, 0xcd, MEMP_SANITY_REGION_AFTER_ALIGNED); #endif #else /* MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 || MEMP_SANITY_REGION_AFTER_ALIGNED > 0 */ @@ -210,11 +210,11 @@ memp_overflow_check_all(void) SYS_ARCH_PROTECT(old_level); for (i = 0; i < MEMP_MAX; ++i) { - p = (struct memp*)LWIP_MEM_ALIGN(memp_pools[i]->base); + p = (struct memp *)LWIP_MEM_ALIGN(memp_pools[i]->base); for (j = 0; j < memp_pools[i]->num; ++j) { memp_overflow_check_element_overflow(p, memp_pools[i]); memp_overflow_check_element_underflow(p, memp_pools[i]); - p = LWIP_ALIGNMENT_CAST(struct memp*, ((u8_t*)p + MEMP_SIZE + memp_pools[i]->size + MEMP_SANITY_REGION_AFTER_ALIGNED)); + p = LWIP_ALIGNMENT_CAST(struct memp *, ((u8_t *)p + MEMP_SIZE + memp_pools[i]->size + MEMP_SANITY_REGION_AFTER_ALIGNED)); } } SYS_ARCH_UNPROTECT(old_level); @@ -238,14 +238,14 @@ memp_init_pool(const struct memp_desc *desc) struct memp *memp; *desc->tab = NULL; - memp = (struct memp*)LWIP_MEM_ALIGN(desc->base); + memp = (struct memp *)LWIP_MEM_ALIGN(desc->base); #if MEMP_MEM_INIT /* force memset on pool memory */ memset(memp, 0, (size_t)desc->num * (MEMP_SIZE + desc->size #if MEMP_OVERFLOW_CHECK - + MEMP_SANITY_REGION_AFTER_ALIGNED + + MEMP_SANITY_REGION_AFTER_ALIGNED #endif - )); + )); #endif /* create a linked list of memp elements */ for (i = 0; i < desc->num; ++i) { @@ -254,12 +254,12 @@ memp_init_pool(const struct memp_desc *desc) #if MEMP_OVERFLOW_CHECK memp_overflow_init_element(memp, desc); #endif /* MEMP_OVERFLOW_CHECK */ - /* cast through void* to get rid of alignment warnings */ - memp = (struct memp *)(void *)((u8_t *)memp + MEMP_SIZE + desc->size + /* cast through void* to get rid of alignment warnings */ + memp = (struct memp *)(void *)((u8_t *)memp + MEMP_SIZE + desc->size #if MEMP_OVERFLOW_CHECK - + MEMP_SANITY_REGION_AFTER_ALIGNED + + MEMP_SANITY_REGION_AFTER_ALIGNED #endif - ); + ); } #if MEMP_STATS desc->stats->avail = desc->num; @@ -297,11 +297,11 @@ memp_init(void) #endif /* MEMP_OVERFLOW_CHECK >= 2 */ } -static void* +static void * #if !MEMP_OVERFLOW_CHECK do_memp_malloc_pool(const struct memp_desc *desc) #else -do_memp_malloc_pool_fn(const struct memp_desc *desc, const char* file, const int line) +do_memp_malloc_pool_fn(const struct memp_desc *desc, const char *file, const int line) #endif { struct memp *memp; @@ -345,7 +345,7 @@ do_memp_malloc_pool_fn(const struct memp_desc *desc, const char* file, const int #endif SYS_ARCH_UNPROTECT(old_level); /* cast through u8_t* to get rid of alignment warnings */ - return ((u8_t*)memp + MEMP_SIZE); + return ((u8_t *)memp + MEMP_SIZE); } else { #if MEMP_STATS desc->stats->err++; @@ -368,7 +368,7 @@ void * #if !MEMP_OVERFLOW_CHECK memp_malloc_pool(const struct memp_desc *desc) #else -memp_malloc_pool_fn(const struct memp_desc *desc, const char* file, const int line) +memp_malloc_pool_fn(const struct memp_desc *desc, const char *file, const int line) #endif { LWIP_ASSERT("invalid pool desc", desc != NULL); @@ -394,7 +394,7 @@ void * #if !MEMP_OVERFLOW_CHECK memp_malloc(memp_t type) #else -memp_malloc_fn(memp_t type, const char* file, const int line) +memp_malloc_fn(memp_t type, const char *file, const int line) #endif { void *memp; @@ -414,16 +414,16 @@ memp_malloc_fn(memp_t type, const char* file, const int line) } static void -do_memp_free_pool(const struct memp_desc* desc, void *mem) +do_memp_free_pool(const struct memp_desc *desc, void *mem) { struct memp *memp; SYS_ARCH_DECL_PROTECT(old_level); LWIP_ASSERT("memp_free: mem properly aligned", - ((mem_ptr_t)mem % MEM_ALIGNMENT) == 0); + ((mem_ptr_t)mem % MEM_ALIGNMENT) == 0); /* cast through void* to get rid of alignment warnings */ - memp = (struct memp *)(void *)((u8_t*)mem - MEMP_SIZE); + memp = (struct memp *)(void *)((u8_t *)mem - MEMP_SIZE); SYS_ARCH_PROTECT(old_level); @@ -459,7 +459,7 @@ do_memp_free_pool(const struct memp_desc* desc, void *mem) * @param mem the memp element to free */ void -memp_free_pool(const struct memp_desc* desc, void *mem) +memp_free_pool(const struct memp_desc *desc, void *mem) { LWIP_ASSERT("invalid pool desc", desc != NULL); if ((desc == NULL) || (mem == NULL)) { diff --git a/src/core/netif.c b/src/core/netif.c index 19348ec6..3e9f399f 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -1,16 +1,16 @@ /** * @file * lwIP network interface abstraction - * + * * @defgroup netif Network interface (NETIF) * @ingroup callbackstyle_api - * + * * @defgroup netif_ip4 IPv4 address handling * @ingroup netif - * + * * @defgroup netif_ip6 IPv6 address handling * @ingroup netif - * + * * @defgroup netif_cd Client data handling * Store data (void*) on a netif for application usage. * @see @ref LWIP_NUM_NETIF_CLIENT_DATA @@ -103,7 +103,7 @@ #endif /* LWIP_NETIF_LINK_CALLBACK */ #if LWIP_NETIF_EXT_STATUS_CALLBACK -static netif_ext_callback_t* ext_callback; +static netif_ext_callback_t *ext_callback; #endif #if !LWIP_SINGLE_NETIF @@ -120,7 +120,7 @@ static u8_t netif_client_id; #define NETIF_REPORT_TYPE_IPV4 0x01 #define NETIF_REPORT_TYPE_IPV6 0x02 -static void netif_issue_reports(struct netif* netif, u8_t report_type); +static void netif_issue_reports(struct netif *netif, u8_t report_type); #if LWIP_IPV6 static err_t netif_null_output_ip6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr); @@ -128,10 +128,10 @@ static err_t netif_null_output_ip6(struct netif *netif, struct pbuf *p, const ip #if LWIP_HAVE_LOOPIF #if LWIP_IPV4 -static err_t netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip4_addr_t* addr); +static err_t netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip4_addr_t *addr); #endif #if LWIP_IPV6 -static err_t netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const ip6_addr_t* addr); +static err_t netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const ip6_addr_t *addr); #endif @@ -174,9 +174,9 @@ netif_init(void) #if LWIP_IPV4 #define LOOPIF_ADDRINIT &loop_ipaddr, &loop_netmask, &loop_gw, ip4_addr_t loop_ipaddr, loop_netmask, loop_gw; - IP4_ADDR(&loop_gw, 127,0,0,1); - IP4_ADDR(&loop_ipaddr, 127,0,0,1); - IP4_ADDR(&loop_netmask, 255,0,0,0); + IP4_ADDR(&loop_gw, 127, 0, 0, 1); + IP4_ADDR(&loop_ipaddr, 127, 0, 0, 1); + IP4_ADDR(&loop_netmask, 255, 0, 0, 0); #else /* LWIP_IPV4 */ #define LOOPIF_ADDRINIT #endif /* LWIP_IPV4 */ @@ -204,7 +204,7 @@ netif_init(void) * ethernet_input() or ip_input() depending on netif flags. * Don't call directly, pass to netif_add() and call * netif->input(). - * Only works if the netif driver correctly sets + * Only works if the netif driver correctly sets * NETIF_FLAG_ETHARP and/or NETIF_FLAG_ETHERNET flag! */ err_t @@ -215,7 +215,7 @@ netif_input(struct pbuf *p, struct netif *inp) return ethernet_input(p, inp); } else #endif /* LWIP_ETHERNET */ - return ip_input(p, inp); + return ip_input(p, inp); } /** @@ -229,9 +229,9 @@ netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_inp { return netif_add(netif, #if LWIP_IPV4 - NULL, NULL, NULL, + NULL, NULL, NULL, #endif /* LWIP_IPV4*/ - state, init, input); + state, init, input); } /** @@ -253,12 +253,12 @@ netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_inp * to decide whether to forward to ethernet_input() or ip_input(). * In other words, the functions only work when the netif * driver is implemented correctly!\n - * Most members of struct netif should be be initialized by the + * Most members of struct netif should be be initialized by the * netif init function = netif driver (init parameter of this function).\n * IPv6: Don't forget to call netif_create_ip6_linklocal_address() after * setting the MAC address in struct netif.hwaddr * (IPv6 requires a link-local address). - * + * * @return netif, or NULL if failed. */ struct netif * @@ -400,7 +400,7 @@ netif_add(struct netif *netif, #endif /* LWIP_IGMP */ LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP", - netif->name[0], netif->name[1])); + netif->name[0], netif->name[1])); #if LWIP_IPV4 LWIP_DEBUGF(NETIF_DEBUG, (" addr ")); ip4_addr_debug_print(NETIF_DEBUG, ipaddr); @@ -429,11 +429,11 @@ netif_add(struct netif *netif, */ void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, - const ip4_addr_t *gw) + const ip4_addr_t *gw) { #if LWIP_NETIF_EXT_STATUS_CALLBACK u8_t something_changed = 0; - + if ((ip4_addr_cmp(ipaddr, netif_ip4_addr(netif)) == 0) || (ip4_addr_cmp(gw, netif_ip4_gw(netif)) == 0) || (ip4_addr_cmp(netmask, netif_ip4_netmask(netif)) == 0)) { @@ -539,7 +539,7 @@ netif_remove(struct netif *netif) netif_list = netif->next; } else { /* look for netif further down the list */ - struct netif * tmp_netif; + struct netif *tmp_netif; for (tmp_netif = netif_list; tmp_netif != NULL; tmp_netif = tmp_netif->next) { if (tmp_netif->next == netif) { tmp_netif->next = netif->next; @@ -615,11 +615,11 @@ netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr) } LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IP address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", - netif->name[0], netif->name[1], - ip4_addr1_16(netif_ip4_addr(netif)), - ip4_addr2_16(netif_ip4_addr(netif)), - ip4_addr3_16(netif_ip4_addr(netif)), - ip4_addr4_16(netif_ip4_addr(netif)))); + netif->name[0], netif->name[1], + ip4_addr1_16(netif_ip4_addr(netif)), + ip4_addr2_16(netif_ip4_addr(netif)), + ip4_addr3_16(netif_ip4_addr(netif)), + ip4_addr4_16(netif_ip4_addr(netif)))); } /** @@ -647,12 +647,12 @@ netif_set_gw(struct netif *netif, const ip4_addr_t *gw) ip4_addr_set(ip_2_ip4(&netif->gw), gw); IP_SET_TYPE_VAL(netif->gw, IPADDR_TYPE_V4); LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: GW address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", - netif->name[0], netif->name[1], - ip4_addr1_16(netif_ip4_gw(netif)), - ip4_addr2_16(netif_ip4_gw(netif)), - ip4_addr3_16(netif_ip4_gw(netif)), - ip4_addr4_16(netif_ip4_gw(netif)))); - + netif->name[0], netif->name[1], + ip4_addr1_16(netif_ip4_gw(netif)), + ip4_addr2_16(netif_ip4_gw(netif)), + ip4_addr3_16(netif_ip4_gw(netif)), + ip4_addr4_16(netif_ip4_gw(netif)))); + netif_invoke_ext_callback(netif, LWIP_NSC_IPV4_GATEWAY_CHANGED, &args); } } @@ -686,11 +686,11 @@ netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask) IP_SET_TYPE_VAL(netif->netmask, IPADDR_TYPE_V4); mib2_add_route_ip4(0, netif); LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: netmask of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", - netif->name[0], netif->name[1], - ip4_addr1_16(netif_ip4_netmask(netif)), - ip4_addr2_16(netif_ip4_netmask(netif)), - ip4_addr3_16(netif_ip4_netmask(netif)), - ip4_addr4_16(netif_ip4_netmask(netif)))); + netif->name[0], netif->name[1], + ip4_addr1_16(netif_ip4_netmask(netif)), + ip4_addr2_16(netif_ip4_netmask(netif)), + ip4_addr3_16(netif_ip4_netmask(netif)), + ip4_addr4_16(netif_ip4_netmask(netif)))); netif_invoke_ext_callback(netif, LWIP_NSC_IPV4_NETMASK_CHANGED, &args); } @@ -716,7 +716,7 @@ netif_set_default(struct netif *netif) } netif_default = netif; LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n", - netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\'')); + netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\'')); } /** @@ -743,7 +743,7 @@ netif_set_up(struct netif *netif) #endif if (netif->flags & NETIF_FLAG_LINK_UP) { - netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4|NETIF_REPORT_TYPE_IPV6); + netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4 | NETIF_REPORT_TYPE_IPV6); } } } @@ -751,7 +751,7 @@ netif_set_up(struct netif *netif) /** Send ARP/IGMP/MLD/RS events, e.g. on link-up/netif-up or addr-change */ static void -netif_issue_reports(struct netif* netif, u8_t report_type) +netif_issue_reports(struct netif *netif, u8_t report_type) { #if LWIP_IPV4 if ((report_type & NETIF_REPORT_TYPE_IPV4) && @@ -866,7 +866,7 @@ netif_set_link_up(struct netif *netif) #endif /* LWIP_AUTOIP */ if (netif->flags & NETIF_FLAG_UP) { - netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4|NETIF_REPORT_TYPE_IPV6); + netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4 | NETIF_REPORT_TYPE_IPV6); } NETIF_LINK_CALLBACK(netif); #if LWIP_NETIF_EXT_STATUS_CALLBACK @@ -960,7 +960,7 @@ netif_loop_output(struct netif *netif, struct pbuf *p) clen = pbuf_clen(r); /* check for overflow or too many pbuf on queue */ if (((netif->loop_cnt_current + clen) < netif->loop_cnt_current) || - ((netif->loop_cnt_current + clen) > LWIP_MIN(LWIP_LOOPBACK_MAX_PBUFS, 0xFFFF))) { + ((netif->loop_cnt_current + clen) > LWIP_MIN(LWIP_LOOPBACK_MAX_PBUFS, 0xFFFF))) { pbuf_free(r); LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); @@ -1013,7 +1013,7 @@ netif_loop_output(struct netif *netif, struct pbuf *p) #if LWIP_HAVE_LOOPIF #if LWIP_IPV4 static err_t -netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip4_addr_t* addr) +netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip4_addr_t *addr) { LWIP_UNUSED_ARG(addr); return netif_loop_output(netif, p); @@ -1022,7 +1022,7 @@ netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip4_addr_t* ad #if LWIP_IPV6 static err_t -netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const ip6_addr_t* addr) +netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const ip6_addr_t *addr) { LWIP_UNUSED_ARG(addr); return netif_loop_output(netif, p); @@ -1070,7 +1070,7 @@ netif_poll(struct netif *netif) #if LWIP_LOOPBACK_MAX_PBUFS /* adjust the number of pbufs on queue */ LWIP_ASSERT("netif->loop_cnt_current underflow", - ((netif->loop_cnt_current - clen) < netif->loop_cnt_current)); + ((netif->loop_cnt_current - clen) < netif->loop_cnt_current)); netif->loop_cnt_current = (u16_t)(netif->loop_cnt_current - clen); #endif /* LWIP_LOOPBACK_MAX_PBUFS */ @@ -1154,7 +1154,7 @@ netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6) { LWIP_ASSERT("addr6 != NULL", addr6 != NULL); netif_ip6_addr_set_parts(netif, addr_idx, addr6->addr[0], addr6->addr[1], - addr6->addr[2], addr6->addr[3]); + addr6->addr[2], addr6->addr[3]); } /* @@ -1217,8 +1217,8 @@ netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, } LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IPv6 address %d of interface %c%c set to %s/0x%"X8_F"\n", - addr_idx, netif->name[0], netif->name[1], ip6addr_ntoa(netif_ip6_addr(netif, addr_idx)), - netif_ip6_addr_state(netif, addr_idx))); + addr_idx, netif->name[0], netif->name[1], ip6addr_ntoa(netif_ip6_addr(netif, addr_idx)), + netif_ip6_addr_state(netif, addr_idx))); } /** @@ -1232,7 +1232,7 @@ netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, * @param state the new IPv6 address state */ void -netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state) +netif_ip6_addr_set_state(struct netif *netif, s8_t addr_idx, u8_t state) { u8_t old_state; LWIP_ASSERT("netif != NULL", netif != NULL); @@ -1291,8 +1291,8 @@ netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state) #endif LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IPv6 address %d of interface %c%c set to %s/0x%"X8_F"\n", - addr_idx, netif->name[0], netif->name[1], ip6addr_ntoa(netif_ip6_addr(netif, addr_idx)), - netif_ip6_addr_state(netif, addr_idx))); + addr_idx, netif->name[0], netif->name[1], ip6addr_ntoa(netif_ip6_addr(netif, addr_idx)), + netif_ip6_addr_state(netif, addr_idx))); } /** @@ -1493,10 +1493,10 @@ netif_index_to_name(u8_t idx, char *name) * * @param idx index of netif to find */ -struct netif* +struct netif * netif_get_by_index(u8_t idx) { - struct netif* netif; + struct netif *netif; if (idx != NETIF_NO_INDEX) { NETIF_FOREACH(netif) { @@ -1530,8 +1530,8 @@ netif_find(const char *name) NETIF_FOREACH(netif) { if (num == netif->num && - name[0] == netif->name[0] && - name[1] == netif->name[1]) { + name[0] == netif->name[0] && + name[1] == netif->name[1]) { LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1])); return netif; } @@ -1547,7 +1547,7 @@ netif_find(const char *name) * @param callback pointer to listener structure * @param fn callback function */ -void netif_add_ext_callback(netif_ext_callback_t* callback, netif_ext_callback_fn fn) +void netif_add_ext_callback(netif_ext_callback_t *callback, netif_ext_callback_fn fn) { LWIP_ASSERT("callback must be != NULL", callback != NULL); LWIP_ASSERT("fn must be != NULL", fn != NULL); @@ -1563,9 +1563,9 @@ void netif_add_ext_callback(netif_ext_callback_t* callback, netif_ext_callback_f * @param reason change reason * @param args depends on reason, see reason description */ -void netif_invoke_ext_callback(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args) +void netif_invoke_ext_callback(struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args) { - netif_ext_callback_t* callback = ext_callback; + netif_ext_callback_t *callback = ext_callback; LWIP_ASSERT("netif must be != NULL", netif != NULL); diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 814127f8..0ecffd22 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -124,7 +124,7 @@ static void pbuf_free_ooseq(void) { - struct tcp_pcb* pcb; + struct tcp_pcb *pcb; SYS_ARCH_SET(pbuf_free_ooseq_pending, 0); for (pcb = tcp_active_pcbs; NULL != pcb; pcb = pcb->next) { @@ -173,7 +173,7 @@ pbuf_pool_is_empty(void) /* Initialize members of struct pbuf after allocation */ static void -pbuf_init_alloced_pbuf(struct pbuf *p, void* payload, u16_t tot_len, u16_t len, pbuf_type type, u8_t flags) +pbuf_init_alloced_pbuf(struct pbuf *p, void *payload, u16_t tot_len, u16_t len, pbuf_type type, u8_t flags) { p->next = NULL; p->payload = payload; @@ -225,12 +225,11 @@ pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type) LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F")\n", length)); switch (type) { - case PBUF_REF: /* fall through */ - case PBUF_ROM: - p = pbuf_alloc_reference(NULL, length, type); - break; - case PBUF_POOL: - { + case PBUF_REF: /* fall through */ + case PBUF_ROM: + p = pbuf_alloc_reference(NULL, length, type); + break; + case PBUF_POOL: { struct pbuf *q, *last; u16_t rem_len; /* remaining length */ p = NULL; @@ -250,11 +249,11 @@ pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type) } qlen = LWIP_MIN(rem_len, (u16_t)(PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset))); pbuf_init_alloced_pbuf(q, LWIP_MEM_ALIGN((void *)((u8_t *)q + SIZEOF_STRUCT_PBUF + offset)), - rem_len, qlen, type, 0); + rem_len, qlen, type, 0); LWIP_ASSERT("pbuf_alloc: pbuf q->payload properly aligned", - ((mem_ptr_t)q->payload % MEM_ALIGNMENT) == 0); + ((mem_ptr_t)q->payload % MEM_ALIGNMENT) == 0); LWIP_ASSERT("PBUF_POOL_BUFSIZE must be bigger than MEM_ALIGNMENT", - (PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset)) > 0 ); + (PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset)) > 0 ); if (p == NULL) { /* allocated head of pbuf chain (into p) */ p = q; @@ -268,8 +267,7 @@ pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type) } while (rem_len > 0); break; } - case PBUF_RAM: - { + case PBUF_RAM: { u16_t payload_len = (u16_t)(LWIP_MEM_ALIGN_SIZE(offset) + LWIP_MEM_ALIGN_SIZE(length)); mem_size_t alloc_len = (mem_size_t)(LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF) + payload_len); @@ -280,19 +278,19 @@ pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type) } /* If pbuf is to be allocated in RAM, allocate memory for it. */ - p = (struct pbuf*)mem_malloc(alloc_len); + p = (struct pbuf *)mem_malloc(alloc_len); if (p == NULL) { return NULL; } pbuf_init_alloced_pbuf(p, LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset)), - length, length, type, 0); + length, length, type, 0); LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned", - ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0); + ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0); break; } - default: - LWIP_ASSERT("pbuf_alloc: erroneous type", 0); - return NULL; + default: + LWIP_ASSERT("pbuf_alloc: erroneous type", 0); + return NULL; } LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F") == %p\n", length, (void *)p)); return p; @@ -332,7 +330,7 @@ pbuf_alloc_reference(void *payload, u16_t length, pbuf_type type) if (p == NULL) { LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("pbuf_alloc_reference: Could not allocate MEMP_PBUF for PBUF_%s.\n", - (type == PBUF_ROM) ? "ROM" : "REF")); + (type == PBUF_ROM) ? "ROM" : "REF")); return NULL; } pbuf_init_alloced_pbuf(p, payload, length, length, type, 0); @@ -358,7 +356,7 @@ pbuf_alloc_reference(void *payload, u16_t length, pbuf_type type) * @param payload_mem_len the size of the 'payload_mem' buffer, must be at least * big enough to hold 'length' plus the header size */ -struct pbuf* +struct pbuf * pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, struct pbuf_custom *p, void *payload_mem, u16_t payload_mem_len) { @@ -495,12 +493,12 @@ pbuf_add_header_impl(struct pbuf *p, size_t header_size_increment, u8_t force) /* boundary check fails? */ if ((u8_t *)payload < (u8_t *)p + SIZEOF_STRUCT_PBUF) { LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, - ("pbuf_add_header: failed as %p < %p (not enough space for new header size)\n", - (void *)payload, (void *)((u8_t *)p + SIZEOF_STRUCT_PBUF))); + ("pbuf_add_header: failed as %p < %p (not enough space for new header size)\n", + (void *)payload, (void *)((u8_t *)p + SIZEOF_STRUCT_PBUF))); /* bail out unsuccessfully */ return 1; } - /* pbuf types referring to external payloads? */ + /* pbuf types referring to external payloads? */ } else { /* hide a header in the payload? */ if (force) { @@ -512,7 +510,7 @@ pbuf_add_header_impl(struct pbuf *p, size_t header_size_increment, u8_t force) } } LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_add_header: old %p new %p (%"U16_F")\n", - (void *)p->payload, (void *)payload, increment_magnitude)); + (void *)p->payload, (void *)payload, increment_magnitude)); /* modify pbuf fields */ p->payload = payload; @@ -600,7 +598,7 @@ pbuf_remove_header(struct pbuf *p, size_t header_size_decrement) p->tot_len = (u16_t)(p->tot_len - increment_magnitude); LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_remove_header: old %p new %p (%"U16_F")\n", - (void *)payload, (void *)p->payload, increment_magnitude)); + (void *)payload, (void *)p->payload, increment_magnitude)); return 0; } @@ -609,7 +607,7 @@ static u8_t pbuf_header_impl(struct pbuf *p, s16_t header_size_increment, u8_t force) { if (header_size_increment < 0) { - return pbuf_remove_header(p, (size_t)-header_size_increment); + return pbuf_remove_header(p, (size_t) - header_size_increment); } else { return pbuf_add_header_impl(p, (size_t)header_size_increment, force); } @@ -638,7 +636,7 @@ pbuf_header_impl(struct pbuf *p, s16_t header_size_increment, u8_t force) u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment) { - return pbuf_header_impl(p, header_size_increment, 0); + return pbuf_header_impl(p, header_size_increment, 0); } /** @@ -648,7 +646,7 @@ pbuf_header(struct pbuf *p, s16_t header_size_increment) u8_t pbuf_header_force(struct pbuf *p, s16_t header_size_increment) { - return pbuf_header_impl(p, header_size_increment, 1); + return pbuf_header_impl(p, header_size_increment, 1); } /** Similar to pbuf_header(-size) but de-refs header pbufs for (size >= p->len) @@ -660,7 +658,7 @@ pbuf_header_force(struct pbuf *p, s16_t header_size_increment) * takes an u16_t not s16_t! * @return the new head pbuf */ -struct pbuf* +struct pbuf * pbuf_free_header(struct pbuf *q, u16_t size) { struct pbuf *p = q; @@ -725,7 +723,7 @@ pbuf_free(struct pbuf *p) LWIP_ASSERT("p != NULL", p != NULL); /* if assertions are disabled, proceed with debug output */ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_LEVEL_SERIOUS, - ("pbuf_free(p == NULL) was called.\n")); + ("pbuf_free(p == NULL) was called.\n")); return 0; } LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free(%p)\n", (void *)p)); @@ -756,7 +754,7 @@ pbuf_free(struct pbuf *p) #if LWIP_SUPPORT_CUSTOM_PBUF /* is this a custom pbuf? */ if ((p->flags & PBUF_FLAG_IS_CUSTOM) != 0) { - struct pbuf_custom *pc = (struct pbuf_custom*)p; + struct pbuf_custom *pc = (struct pbuf_custom *)p; LWIP_ASSERT("pc->custom_free_function != NULL", pc->custom_free_function != NULL); pc->custom_free_function(p); } else @@ -765,10 +763,10 @@ pbuf_free(struct pbuf *p) /* is this a pbuf from the pool? */ if (alloc_src == PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL) { memp_free(MEMP_PBUF_POOL, p); - /* is this a ROM or RAM referencing pbuf? */ + /* is this a ROM or RAM referencing pbuf? */ } else if (alloc_src == PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF) { memp_free(MEMP_PBUF, p); - /* type == PBUF_RAM */ + /* type == PBUF_RAM */ } else if (alloc_src == PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP) { mem_free(p); } else { @@ -779,8 +777,8 @@ pbuf_free(struct pbuf *p) count++; /* proceed to next pbuf */ p = q; - /* p->ref > 0, this pbuf is still referenced to */ - /* (and so the remaining pbufs in chain as well) */ + /* p->ref > 0, this pbuf is still referenced to */ + /* (and so the remaining pbufs in chain as well) */ } else { LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: %p has ref %"U16_F", ending here.\n", (void *)p, ref)); /* stop walking through the chain */ @@ -956,15 +954,14 @@ pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from) size_t offset_to = 0, offset_from = 0, len; LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy(%p, %p)\n", - (const void*)p_to, (const void*)p_from)); + (const void *)p_to, (const void *)p_from)); /* is the target big enough to hold the source? */ LWIP_ERROR("pbuf_copy: target not big enough to hold source", ((p_to != NULL) && (p_from != NULL) && (p_to->tot_len >= p_from->tot_len)), return ERR_ARG;); /* iterate through pbuf chain */ - do - { + do { /* copy one part of the original chain */ if ((p_to->len - offset_to) >= (p_from->len - offset_from)) { /* complete current p_from fits into current p_to */ @@ -973,7 +970,7 @@ pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from) /* current p_from does not fit into current p_to */ len = p_to->len - offset_to; } - MEMCPY((u8_t*)p_to->payload + offset_to, (u8_t*)p_from->payload + offset_from, len); + MEMCPY((u8_t *)p_to->payload + offset_to, (u8_t *)p_from->payload + offset_from, len); offset_to += len; offset_from += len; LWIP_ASSERT("offset_to <= p_to->len", offset_to <= p_to->len); @@ -987,7 +984,7 @@ pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from) /* on to next p_to (if any) */ offset_to = 0; p_to = p_to->next; - LWIP_ERROR("p_to != NULL", (p_to != NULL) || (p_from == NULL) , return ERR_ARG;); + LWIP_ERROR("p_to != NULL", (p_to != NULL) || (p_from == NULL), return ERR_ARG;); } if ((p_from != NULL) && (p_from->len == p_from->tot_len)) { @@ -998,7 +995,7 @@ pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from) if ((p_to != NULL) && (p_to->len == p_to->tot_len)) { /* don't copy more than one packet! */ LWIP_ERROR("pbuf_copy() does not allow packet queues!", - (p_to->next == NULL), return ERR_VAL;); + (p_to->next == NULL), return ERR_VAL;); } } while (p_from); LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy: end of chain reached.\n")); @@ -1040,7 +1037,7 @@ pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset buf_copy_len = len; } /* copy the necessary parts of the buffer */ - MEMCPY(&((char*)dataptr)[left], &((char*)p->payload)[offset], buf_copy_len); + MEMCPY(&((char *)dataptr)[left], &((char *)p->payload)[offset], buf_copy_len); copied_total = (u16_t)(copied_total + buf_copy_len); left = (u16_t)(left + buf_copy_len); len = (u16_t)(len - buf_copy_len); @@ -1080,7 +1077,7 @@ pbuf_get_contiguous(const struct pbuf *p, void *buffer, size_t bufsize, u16_t le } else { if (q->len >= (offset + len)) { /* all data in this pbuf, return zero-copy */ - return (u8_t*)q->payload + offset; + return (u8_t *)q->payload + offset; } /* need to copy */ if (pbuf_copy_partial(q, buffer, len, offset) != len) { @@ -1145,11 +1142,11 @@ void pbuf_split_64k(struct pbuf *p, struct pbuf **rest) #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */ /* Actual implementation of pbuf_skip() but returning const pointer... */ -static const struct pbuf* -pbuf_skip_const(const struct pbuf* in, u16_t in_offset, u16_t* out_offset) +static const struct pbuf * +pbuf_skip_const(const struct pbuf *in, u16_t in_offset, u16_t *out_offset) { u16_t offset_left = in_offset; - const struct pbuf* q = in; + const struct pbuf *q = in; /* get the correct pbuf */ while ((q != NULL) && (q->len <= offset_left)) { @@ -1171,11 +1168,11 @@ pbuf_skip_const(const struct pbuf* in, u16_t in_offset, u16_t* out_offset) * @param out_offset resulting offset in the returned pbuf * @return the pbuf in the queue where the offset is */ -struct pbuf* -pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset) +struct pbuf * +pbuf_skip(struct pbuf *in, u16_t in_offset, u16_t *out_offset) { - const struct pbuf* out = pbuf_skip_const(in, in_offset, out_offset); - return LWIP_CONST_CAST(struct pbuf*, out); + const struct pbuf *out = pbuf_skip_const(in, in_offset, out_offset); + return LWIP_CONST_CAST(struct pbuf *, out); } /** @@ -1214,7 +1211,7 @@ pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len) buf_copy_len = p->len; } /* copy the necessary parts of the buffer */ - MEMCPY(p->payload, &((const char*)dataptr)[copied_total], buf_copy_len); + MEMCPY(p->payload, &((const char *)dataptr)[copied_total], buf_copy_len); total_copy_len -= buf_copy_len; copied_total += buf_copy_len; } @@ -1237,17 +1234,17 @@ err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset) { u16_t target_offset; - struct pbuf* q = pbuf_skip(buf, offset, &target_offset); + struct pbuf *q = pbuf_skip(buf, offset, &target_offset); /* return requested data if pbuf is OK */ if ((q != NULL) && (q->tot_len >= target_offset + len)) { u16_t remaining_len = len; - const u8_t* src_ptr = (const u8_t*)dataptr; + const u8_t *src_ptr = (const u8_t *)dataptr; /* copy the part that goes into the first pbuf */ u16_t first_copy_len; LWIP_ASSERT("chekc pbuf_skip result", target_offset < q->len); first_copy_len = (u16_t)LWIP_MIN(q->len - target_offset, len); - MEMCPY(((u8_t*)q->payload) + target_offset, dataptr, first_copy_len); + MEMCPY(((u8_t *)q->payload) + target_offset, dataptr, first_copy_len); remaining_len = (u16_t)(remaining_len - first_copy_len); src_ptr += first_copy_len; if (remaining_len > 0) { @@ -1271,7 +1268,7 @@ pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset) * @return a new, single pbuf (p->next is NULL) * or the old pbuf if allocation fails */ -struct pbuf* +struct pbuf * pbuf_coalesce(struct pbuf *p, pbuf_layer layer) { struct pbuf *q; @@ -1343,7 +1340,7 @@ pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, return ERR_ARG; } - dst_ptr = ((char*)p->payload) + start_offset; + dst_ptr = ((char *)p->payload) + start_offset; copy_chksum = LWIP_CHKSUM_COPY(dst_ptr, dataptr, len); if ((start_offset & 1) != 0) { copy_chksum = SWAP_BYTES_IN_WORD(copy_chksum); @@ -1365,7 +1362,7 @@ pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, * @return byte at an offset into p OR ZERO IF 'offset' >= p->tot_len */ u8_t -pbuf_get_at(const struct pbuf* p, u16_t offset) +pbuf_get_at(const struct pbuf *p, u16_t offset) { int ret = pbuf_try_get_at(p, offset); if (ret >= 0) { @@ -1383,14 +1380,14 @@ pbuf_get_at(const struct pbuf* p, u16_t offset) * @return byte at an offset into p [0..0xFF] OR negative if 'offset' >= p->tot_len */ int -pbuf_try_get_at(const struct pbuf* p, u16_t offset) +pbuf_try_get_at(const struct pbuf *p, u16_t offset) { u16_t q_idx; - const struct pbuf* q = pbuf_skip_const(p, offset, &q_idx); + const struct pbuf *q = pbuf_skip_const(p, offset, &q_idx); /* return requested data if pbuf is OK */ if ((q != NULL) && (q->len > q_idx)) { - return ((u8_t*)q->payload)[q_idx]; + return ((u8_t *)q->payload)[q_idx]; } return -1; } @@ -1405,14 +1402,14 @@ pbuf_try_get_at(const struct pbuf* p, u16_t offset) * @param data byte to write at an offset into p */ void -pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data) +pbuf_put_at(struct pbuf *p, u16_t offset, u8_t data) { u16_t q_idx; - struct pbuf* q = pbuf_skip(p, offset, &q_idx); + struct pbuf *q = pbuf_skip(p, offset, &q_idx); /* write requested data if pbuf is OK */ if ((q != NULL) && (q->len > q_idx)) { - ((u8_t*)q->payload)[q_idx] = data; + ((u8_t *)q->payload)[q_idx] = data; } } @@ -1428,30 +1425,30 @@ pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data) * (0xffff if p is too short, diffoffset+1 otherwise) */ u16_t -pbuf_memcmp(const struct pbuf* p, u16_t offset, const void* s2, u16_t n) +pbuf_memcmp(const struct pbuf *p, u16_t offset, const void *s2, u16_t n) { u16_t start = offset; - const struct pbuf* q = p; + const struct pbuf *q = p; u16_t i; - + /* pbuf long enough to perform check? */ - if(p->tot_len < (offset + n)) { + if (p->tot_len < (offset + n)) { return 0xffff; } - + /* get the correct pbuf from chain. We know it succeeds because of p->tot_len check above. */ while ((q != NULL) && (q->len <= start)) { start = (u16_t)(start - q->len); q = q->next; } - + /* return requested data if pbuf is OK */ for (i = 0; i < n; i++) { /* We know pbuf_get_at() succeeds because of p->tot_len check above. */ u8_t a = pbuf_get_at(q, (u16_t)(start + i)); - u8_t b = ((const u8_t*)s2)[i]; + u8_t b = ((const u8_t *)s2)[i]; if (a != b) { - return (u16_t)LWIP_MIN(i+1, 0xFFFF); + return (u16_t)LWIP_MIN(i + 1, 0xFFFF); } } return 0; @@ -1470,7 +1467,7 @@ pbuf_memcmp(const struct pbuf* p, u16_t offset, const void* s2, u16_t n) * @return 0xFFFF if substr was not found in p or the index where it was found */ u16_t -pbuf_memfind(const struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset) +pbuf_memfind(const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset) { u16_t i; u16_t max_cmp_start = (u16_t)(p->tot_len - mem_len); @@ -1497,7 +1494,7 @@ pbuf_memfind(const struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_o * @return 0xFFFF if substr was not found in p or the index where it was found */ u16_t -pbuf_strstr(const struct pbuf* p, const char* substr) +pbuf_strstr(const struct pbuf *p, const char *substr) { size_t substr_len; if ((substr == NULL) || (substr[0] == 0) || (p->tot_len == 0xFFFF)) { diff --git a/src/core/raw.c b/src/core/raw.c index be5214e0..b3a0ba2c 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -4,7 +4,7 @@ * different types of protocols besides (or overriding) those * already available in lwIP.\n * See also @ref raw_raw - * + * * @defgroup raw_raw RAW * @ingroup callbackstyle_api * Implementation of raw protocol PCBs for low-level handling of @@ -68,7 +68,7 @@ static u8_t raw_input_local_match(struct raw_pcb *pcb, u8_t broadcast) { LWIP_UNUSED_ARG(broadcast); /* in IPv6 only case */ - + /* check if PCB is bound to specific netif */ if ((pcb->netif_idx != NETIF_NO_INDEX) && (pcb->netif_idx != netif_get_index(ip_data.current_input_netif))) { @@ -103,11 +103,11 @@ raw_input_local_match(struct raw_pcb *pcb, u8_t broadcast) } } else #endif /* LWIP_IPV4 */ - /* Handle IPv4 and IPv6: catch all or exact match */ - if (ip_addr_isany(&pcb->local_ip) || - ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) { - return 1; - } + /* Handle IPv4 and IPv6: catch all or exact match */ + if (ip_addr_isany(&pcb->local_ip) || + ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) { + return 1; + } } return 0; @@ -165,11 +165,11 @@ raw_input(struct pbuf *p, struct netif *inp) while ((eaten == 0) && (pcb != NULL)) { if ((pcb->protocol == proto) && raw_input_local_match(pcb, broadcast) && (((pcb->flags & RAW_FLAGS_CONNECTED) == 0) || - ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()))) { + ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()))) { /* receive callback function available? */ if (pcb->recv != NULL) { #ifndef LWIP_NOASSERT - void* old_payload = p->payload; + void *old_payload = p->payload; #endif /* the receive callback function did not eat the packet? */ eaten = pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr()); @@ -178,8 +178,8 @@ raw_input(struct pbuf *p, struct netif *inp) p = NULL; eaten = 1; if (prev != NULL) { - /* move the pcb to the front of raw_pcbs so that is - found faster next time */ + /* move the pcb to the front of raw_pcbs so that is + found faster next time */ prev->next = pcb->next; pcb->next = raw_pcbs; raw_pcbs = pcb; @@ -187,7 +187,7 @@ raw_input(struct pbuf *p, struct netif *inp) } else { /* sanity-check that the receive callback did not alter the pbuf */ LWIP_ASSERT("raw pcb recv callback altered pbuf payload pointer without eating packet", - p->payload == old_payload); + p->payload == old_payload); } } /* no receive callback function was set for this raw PCB */ @@ -410,7 +410,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr) */ err_t raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, - struct netif *netif, const ip_addr_t *src_ip) + struct netif *netif, const ip_addr_t *src_ip) { err_t err; struct pbuf *q; /* q will be sent down the stack */ @@ -424,11 +424,11 @@ raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, header_size = ( #if LWIP_IPV4 && LWIP_IPV6 - IP_IS_V6(dst_ip) ? IP6_HLEN : IP_HLEN); + IP_IS_V6(dst_ip) ? IP6_HLEN : IP_HLEN); #elif LWIP_IPV4 - IP_HLEN); + IP_HLEN); #else - IP6_HLEN); + IP6_HLEN); #endif /* Handle the HDRINCL option as an exception: none of the code below applies @@ -475,8 +475,7 @@ raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, } #if IP_SOF_BROADCAST - if (IP_IS_V4(dst_ip)) - { + if (IP_IS_V4(dst_ip)) { /* broadcast filter? */ if (!ip_get_option(pcb, SOF_BROADCAST) && ip_addr_isbroadcast(dst_ip, netif)) { LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb)); @@ -640,9 +639,9 @@ raw_new_ip_type(u8_t type, u8_t proto) * @param old_addr IP address of the netif before change * @param new_addr IP address of the netif after change */ -void raw_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr) +void raw_netif_ip_addr_changed(const ip_addr_t *old_addr, const ip_addr_t *new_addr) { - struct raw_pcb* rpcb; + struct raw_pcb *rpcb; if (!ip_addr_isany(old_addr) && !ip_addr_isany(new_addr)) { for (rpcb = raw_pcbs; rpcb != NULL; rpcb = rpcb->next) { diff --git a/src/core/tcp.c b/src/core/tcp.c index 5a911544..bf21a06c 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -1,5 +1,5 @@ /** - * @file + * @file * Transmission Control Protocol for IP * See also @ref tcp_raw * @@ -89,7 +89,7 @@ #define INITIAL_MSS TCP_MSS #endif -static const char * const tcp_state_str[] = { +static const char *const tcp_state_str[] = { "CLOSED", "LISTEN", "SYN_SENT", @@ -109,8 +109,8 @@ static u16_t tcp_port = TCP_LOCAL_PORT_RANGE_START; /* Incremented every coarse grained timer shot (typically every 500 ms). */ u32_t tcp_ticks; static const u8_t tcp_backoff[13] = - { 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7}; - /* Times per slowtmr hits */ +{ 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7}; +/* Times per slowtmr hits */ static const u8_t tcp_persist_backoff[7] = { 3, 6, 12, 24, 48, 96, 120 }; /* The TCP PCB lists. */ @@ -126,8 +126,9 @@ struct tcp_pcb *tcp_active_pcbs; struct tcp_pcb *tcp_tw_pcbs; /** An array with all (non-temporary) PCB lists, mainly used for smaller code size */ -struct tcp_pcb ** const tcp_pcb_lists[] = {&tcp_listen_pcbs.pcbs, &tcp_bound_pcbs, - &tcp_active_pcbs, &tcp_tw_pcbs}; +struct tcp_pcb **const tcp_pcb_lists[] = {&tcp_listen_pcbs.pcbs, &tcp_bound_pcbs, + &tcp_active_pcbs, &tcp_tw_pcbs +}; u8_t tcp_active_pcbs_changed; @@ -172,12 +173,12 @@ tcp_tmr(void) static void tcp_remove_listener(struct tcp_pcb *list, struct tcp_pcb_listen *lpcb) { - struct tcp_pcb *pcb; - for (pcb = list; pcb != NULL; pcb = pcb->next) { - if (pcb->listener == lpcb) { - pcb->listener = NULL; - } - } + struct tcp_pcb *pcb; + for (pcb = list; pcb != NULL; pcb = pcb->next) { + if (pcb->listener == lpcb) { + pcb->listener = NULL; + } + } } #endif @@ -192,7 +193,7 @@ tcp_listen_closed(struct tcp_pcb *pcb) LWIP_ASSERT("pcb != NULL", pcb != NULL); LWIP_ASSERT("pcb->state == LISTEN", pcb->state == LISTEN); for (i = 1; i < LWIP_ARRAYSIZE(tcp_pcb_lists); i++) { - tcp_remove_listener(*tcp_pcb_lists[i], (struct tcp_pcb_listen*)pcb); + tcp_remove_listener(*tcp_pcb_lists[i], (struct tcp_pcb_listen *)pcb); } #endif LWIP_UNUSED_ARG(pcb); @@ -210,7 +211,7 @@ tcp_listen_closed(struct tcp_pcb *pcb) * @param pcb the connection pcb which is not fully accepted yet */ void -tcp_backlog_delayed(struct tcp_pcb* pcb) +tcp_backlog_delayed(struct tcp_pcb *pcb) { LWIP_ASSERT("pcb != NULL", pcb != NULL); if ((pcb->flags & TF_BACKLOGPEND) == 0) { @@ -232,7 +233,7 @@ tcp_backlog_delayed(struct tcp_pcb* pcb) * @param pcb the connection pcb which is now fully accepted (or closed/aborted) */ void -tcp_backlog_accepted(struct tcp_pcb* pcb) +tcp_backlog_accepted(struct tcp_pcb *pcb) { LWIP_ASSERT("pcb != NULL", pcb != NULL); if ((pcb->flags & TF_BACKLOGPEND) != 0) { @@ -273,7 +274,7 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) /* don't call tcp_abort here: we must not deallocate the pcb since that might not be expected when calling tcp_close */ tcp_rst(pcb, pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip, - pcb->local_port, pcb->remote_port); + pcb->local_port, pcb->remote_port); tcp_pcb_purge(pcb); TCP_RMV_ACTIVE(pcb); @@ -297,31 +298,31 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) /* - states which free the pcb are handled here, - states which send FIN and change state are handled in tcp_close_shutdown_fin() */ switch (pcb->state) { - case CLOSED: - /* Closing a pcb in the CLOSED state might seem erroneous, - * however, it is in this state once allocated and as yet unused - * and the user needs some way to free it should the need arise. - * Calling tcp_close() with a pcb that has already been closed, (i.e. twice) - * or for a pcb that has been used and then entered the CLOSED state - * is erroneous, but this should never happen as the pcb has in those cases - * been freed, and so any remaining handles are bogus. */ - if (pcb->local_port != 0) { - TCP_RMV(&tcp_bound_pcbs, pcb); - } - memp_free(MEMP_TCP_PCB, pcb); - break; - case LISTEN: - tcp_listen_closed(pcb); - tcp_pcb_remove(&tcp_listen_pcbs.pcbs, pcb); - memp_free(MEMP_TCP_PCB_LISTEN, pcb); - break; - case SYN_SENT: - TCP_PCB_REMOVE_ACTIVE(pcb); - memp_free(MEMP_TCP_PCB, pcb); - MIB2_STATS_INC(mib2.tcpattemptfails); - break; - default: - return tcp_close_shutdown_fin(pcb); + case CLOSED: + /* Closing a pcb in the CLOSED state might seem erroneous, + * however, it is in this state once allocated and as yet unused + * and the user needs some way to free it should the need arise. + * Calling tcp_close() with a pcb that has already been closed, (i.e. twice) + * or for a pcb that has been used and then entered the CLOSED state + * is erroneous, but this should never happen as the pcb has in those cases + * been freed, and so any remaining handles are bogus. */ + if (pcb->local_port != 0) { + TCP_RMV(&tcp_bound_pcbs, pcb); + } + memp_free(MEMP_TCP_PCB, pcb); + break; + case LISTEN: + tcp_listen_closed(pcb); + tcp_pcb_remove(&tcp_listen_pcbs.pcbs, pcb); + memp_free(MEMP_TCP_PCB_LISTEN, pcb); + break; + case SYN_SENT: + TCP_PCB_REMOVE_ACTIVE(pcb); + memp_free(MEMP_TCP_PCB, pcb); + MIB2_STATS_INC(mib2.tcpattemptfails); + break; + default: + return tcp_close_shutdown_fin(pcb); } return ERR_OK; } @@ -333,31 +334,31 @@ tcp_close_shutdown_fin(struct tcp_pcb *pcb) LWIP_ASSERT("pcb != NULL", pcb != NULL); switch (pcb->state) { - case SYN_RCVD: - err = tcp_send_fin(pcb); - if (err == ERR_OK) { - tcp_backlog_accepted(pcb); - MIB2_STATS_INC(mib2.tcpattemptfails); - pcb->state = FIN_WAIT_1; - } - break; - case ESTABLISHED: - err = tcp_send_fin(pcb); - if (err == ERR_OK) { - MIB2_STATS_INC(mib2.tcpestabresets); - pcb->state = FIN_WAIT_1; - } - break; - case CLOSE_WAIT: - err = tcp_send_fin(pcb); - if (err == ERR_OK) { - MIB2_STATS_INC(mib2.tcpestabresets); - pcb->state = LAST_ACK; - } - break; - default: - /* Has already been closed, do nothing. */ - return ERR_OK; + case SYN_RCVD: + err = tcp_send_fin(pcb); + if (err == ERR_OK) { + tcp_backlog_accepted(pcb); + MIB2_STATS_INC(mib2.tcpattemptfails); + pcb->state = FIN_WAIT_1; + } + break; + case ESTABLISHED: + err = tcp_send_fin(pcb); + if (err == ERR_OK) { + MIB2_STATS_INC(mib2.tcpestabresets); + pcb->state = FIN_WAIT_1; + } + break; + case CLOSE_WAIT: + err = tcp_send_fin(pcb); + if (err == ERR_OK) { + MIB2_STATS_INC(mib2.tcpestabresets); + pcb->state = LAST_ACK; + } + break; + default: + /* Has already been closed, do nothing. */ + return ERR_OK; } if (err == ERR_OK) { @@ -445,14 +446,14 @@ tcp_shutdown(struct tcp_pcb *pcb, int shut_rx, int shut_tx) /* This can't happen twice since if it succeeds, the pcb's state is changed. Only close in these states as the others directly deallocate the PCB */ switch (pcb->state) { - case SYN_RCVD: - case ESTABLISHED: - case CLOSE_WAIT: - return tcp_close_shutdown(pcb, (u8_t)shut_rx); - default: - /* Not (yet?) connected, cannot shutdown the TX side as that would bring us - into CLOSED state, where the PCB is deallocated. */ - return ERR_CONN; + case SYN_RCVD: + case ESTABLISHED: + case CLOSE_WAIT: + return tcp_close_shutdown(pcb, (u8_t)shut_rx); + default: + /* Not (yet?) connected, cannot shutdown the TX side as that would bring us + into CLOSED state, where the PCB is deallocated. */ + return ERR_CONN; } } return ERR_OK; @@ -477,7 +478,7 @@ tcp_abandon(struct tcp_pcb *pcb, int reset) /* pcb->state LISTEN not allowed here */ LWIP_ASSERT("don't call tcp_abort/tcp_abandon for listen-pcbs", - pcb->state != LISTEN); + pcb->state != LISTEN); /* Figure out on which TCP PCB list we are, and remove us. If we are in an active state, call the receive function associated with the PCB with a NULL argument, and send an RST to the remote end. */ @@ -626,8 +627,8 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) /* @todo: check accept_any_ip_version */ if ((IP_IS_V6(ipaddr) == IP_IS_V6_VAL(cpcb->local_ip)) && (ip_addr_isany(&cpcb->local_ip) || - ip_addr_isany(ipaddr) || - ip_addr_cmp(&cpcb->local_ip, ipaddr))) { + ip_addr_isany(ipaddr) || + ip_addr_cmp(&cpcb->local_ip, ipaddr))) { return ERR_USE; } } @@ -729,7 +730,7 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err) /* already listening? */ if (pcb->state == LISTEN) { - lpcb = (struct tcp_pcb_listen*)pcb; + lpcb = (struct tcp_pcb_listen *)pcb; res = ERR_ALREADY; goto done; } @@ -834,7 +835,7 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len) /* pcb->state LISTEN not allowed here */ LWIP_ASSERT("don't call tcp_recved for listen-pcbs", - pcb->state != LISTEN); + pcb->state != LISTEN); pcb->rcv_wnd = (tcpwnd_size_t)(pcb->rcv_wnd + len); if (pcb->rcv_wnd > TCP_WND_MAX(pcb)) { @@ -863,7 +864,7 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len) } LWIP_DEBUGF(TCP_DEBUG, ("tcp_recved: received %"U16_F" bytes, wnd %"TCPWNDSIZE_F" (%"TCPWNDSIZE_F").\n", - len, pcb->rcv_wnd, (u16_t)(TCP_WND_MAX(pcb) - pcb->rcv_wnd))); + len, pcb->rcv_wnd, (u16_t)(TCP_WND_MAX(pcb) - pcb->rcv_wnd))); } /** @@ -914,7 +915,7 @@ again: */ err_t tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, - tcp_connected_fn connected) + tcp_connected_fn connected) { struct netif *netif = NULL; err_t ret; @@ -1075,8 +1076,7 @@ tcp_slowtmr_start: if (pcb->state == SYN_SENT && pcb->nrtx >= TCP_SYNMAXRTX) { ++pcb_remove; LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max SYN retries reached\n")); - } - else if (pcb->nrtx >= TCP_MAXRTX) { + } else if (pcb->nrtx >= TCP_MAXRTX) { ++pcb_remove; LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max DATA retries reached\n")); } else { @@ -1086,7 +1086,7 @@ tcp_slowtmr_start: if (pcb->persist_probe >= TCP_MAXRTX) { ++pcb_remove; /* max probes reached */ } else { - u8_t backoff_cnt = tcp_persist_backoff[pcb->persist_backoff-1]; + u8_t backoff_cnt = tcp_persist_backoff[pcb->persist_backoff - 1]; if (pcb->persist_cnt < backoff_cnt) { pcb->persist_cnt++; } @@ -1097,12 +1097,12 @@ tcp_slowtmr_start: if (tcp_zero_window_probe(pcb) != ERR_OK) { next_slot = 0; /* try probe again with current slot */ } - /* snd_wnd not fully closed, split unsent head and fill window */ + /* snd_wnd not fully closed, split unsent head and fill window */ } else { if (tcp_split_unsent_seg(pcb, (u16_t)pcb->snd_wnd) == ERR_OK) { if (tcp_output(pcb) == ERR_OK) { - /* sending will cancel persist timer, else retry with current slot */ - next_slot = 0; + /* sending will cancel persist timer, else retry with current slot */ + next_slot = 0; } } } @@ -1129,7 +1129,7 @@ tcp_slowtmr_start: /* Double retransmission time-out unless we are trying to * connect to somebody (i.e., we are in SYN_SENT). */ if (pcb->state != SYN_SENT) { - u8_t backoff_idx = LWIP_MIN(pcb->nrtx, sizeof(tcp_backoff)-1); + u8_t backoff_idx = LWIP_MIN(pcb->nrtx, sizeof(tcp_backoff) - 1); int calc_rto = ((pcb->sa >> 3) + pcb->sv) << tcp_backoff[backoff_idx]; pcb->rto = (s16_t)LWIP_MIN(calc_rto, 0x7FFF); } @@ -1172,11 +1172,10 @@ tcp_slowtmr_start: /* Check if KEEPALIVE should be sent */ if (ip_get_option(pcb, SOF_KEEPALIVE) && - ((pcb->state == ESTABLISHED) || - (pcb->state == CLOSE_WAIT))) { + ((pcb->state == ESTABLISHED) || + (pcb->state == CLOSE_WAIT))) { if ((u32_t)(tcp_ticks - pcb->tmr) > - (pcb->keep_idle + TCP_KEEP_DUR(pcb)) / TCP_SLOW_INTERVAL) - { + (pcb->keep_idle + TCP_KEEP_DUR(pcb)) / TCP_SLOW_INTERVAL) { LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to ")); ip_addr_debug_print_val(TCP_DEBUG, pcb->remote_ip); LWIP_DEBUGF(TCP_DEBUG, ("\n")); @@ -1184,9 +1183,8 @@ tcp_slowtmr_start: ++pcb_remove; ++pcb_reset; } else if ((u32_t)(tcp_ticks - pcb->tmr) > - (pcb->keep_idle + pcb->keep_cnt_sent * TCP_KEEP_INTVL(pcb)) - / TCP_SLOW_INTERVAL) - { + (pcb->keep_idle + pcb->keep_cnt_sent * TCP_KEEP_INTVL(pcb)) + / TCP_SLOW_INTERVAL) { err = tcp_keepalive(pcb); if (err == ERR_OK) { pcb->keep_cnt_sent++; @@ -1550,7 +1548,7 @@ tcp_kill_prio(u8_t prio) inactive = NULL; for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { if (pcb->prio <= mprio && - (u32_t)(tcp_ticks - pcb->tmr) >= inactivity) { + (u32_t)(tcp_ticks - pcb->tmr) >= inactivity) { inactivity = tcp_ticks - pcb->tmr; inactive = pcb; mprio = pcb->prio; @@ -1558,7 +1556,7 @@ tcp_kill_prio(u8_t prio) } if (inactive != NULL) { LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_prio: killing oldest PCB %p (%"S32_F")\n", - (void *)inactive, inactivity)); + (void *)inactive, inactivity)); tcp_abort(inactive); } } @@ -1589,7 +1587,7 @@ tcp_kill_state(enum tcp_state state) } if (inactive != NULL) { LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_closing: killing oldest %s PCB %p (%"S32_F")\n", - tcp_state_str[state], (void *)inactive, inactivity)); + tcp_state_str[state], (void *)inactive, inactivity)); /* Don't send a RST, since no data is lost. */ tcp_abandon(inactive, 0); } @@ -1616,7 +1614,7 @@ tcp_kill_timewait(void) } if (inactive != NULL) { LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_timewait: killing oldest TIME-WAIT PCB %p (%"S32_F")\n", - (void *)inactive, inactivity)); + (void *)inactive, inactivity)); tcp_abort(inactive); } } @@ -1752,7 +1750,7 @@ tcp_new(void) struct tcp_pcb * tcp_new_ip_type(u8_t type) { - struct tcp_pcb * pcb; + struct tcp_pcb *pcb; pcb = tcp_alloc(TCP_PRIO_NORMAL); #if LWIP_IPV4 && LWIP_IPV6 if (pcb != NULL) { @@ -1824,7 +1822,7 @@ tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent) * has occurred on the connection. * * @note The corresponding pcb is already freed when this callback is called! - * + * * @param pcb tcp_pcb to set the err callback * @param err callback function to call for this pcb when a fatal error * has occurred on the connection @@ -1851,7 +1849,7 @@ void tcp_accept(struct tcp_pcb *pcb, tcp_accept_fn accept) { if ((pcb != NULL) && (pcb->state == LISTEN)) { - struct tcp_pcb_listen *lpcb = (struct tcp_pcb_listen*)pcb; + struct tcp_pcb_listen *lpcb = (struct tcp_pcb_listen *)pcb; lpcb->accept = accept; } } @@ -1887,8 +1885,8 @@ void tcp_pcb_purge(struct tcp_pcb *pcb) { if (pcb->state != CLOSED && - pcb->state != TIME_WAIT && - pcb->state != LISTEN) { + pcb->state != TIME_WAIT && + pcb->state != LISTEN) { LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge\n")); @@ -1994,7 +1992,7 @@ tcp_eff_send_mss_netif(u16_t sendmss, struct netif *outif, const ip_addr_t *dest u16_t mtu; LWIP_UNUSED_ARG(dest); /* in case IPv6 is disabled */ - + #if LWIP_IPV6 #if LWIP_IPV4 if (IP_IS_V6(dest)) @@ -2047,7 +2045,7 @@ tcp_eff_send_mss_netif(u16_t sendmss, struct netif *outif, const ip_addr_t *dest /** Helper function for tcp_netif_ip_addr_changed() that iterates a pcb list */ static void -tcp_netif_ip_addr_changed_pcblist(const ip_addr_t* old_addr, struct tcp_pcb* pcb_list) +tcp_netif_ip_addr_changed_pcblist(const ip_addr_t *old_addr, struct tcp_pcb *pcb_list) { struct tcp_pcb *pcb; pcb = pcb_list; @@ -2055,10 +2053,10 @@ tcp_netif_ip_addr_changed_pcblist(const ip_addr_t* old_addr, struct tcp_pcb* pcb /* PCB bound to current local interface address? */ if (ip_addr_cmp(&pcb->local_ip, old_addr) #if LWIP_AUTOIP - /* connections to link-local addresses must persist (RFC3927 ch. 1.9) */ - && (!IP_IS_V4_VAL(pcb->local_ip) || !ip4_addr_islinklocal(ip_2_ip4(&pcb->local_ip))) + /* connections to link-local addresses must persist (RFC3927 ch. 1.9) */ + && (!IP_IS_V4_VAL(pcb->local_ip) || !ip4_addr_islinklocal(ip_2_ip4(&pcb->local_ip))) #endif /* LWIP_AUTOIP */ - ) { + ) { /* this connection must be aborted */ struct tcp_pcb *next = pcb->next; LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb)); @@ -2076,7 +2074,7 @@ tcp_netif_ip_addr_changed_pcblist(const ip_addr_t* old_addr, struct tcp_pcb* pcb * @param new_addr IP address of the netif after change or NULL if netif has been removed */ void -tcp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr) +tcp_netif_ip_addr_changed(const ip_addr_t *old_addr, const ip_addr_t *new_addr) { struct tcp_pcb_listen *lpcb, *next; @@ -2099,7 +2097,7 @@ tcp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr) } } -const char* +const char * tcp_debug_state_str(enum tcp_state s) { return tcp_state_str[s]; @@ -2156,28 +2154,28 @@ tcp_debug_print(struct tcp_hdr *tcphdr) LWIP_DEBUGF(TCP_DEBUG, ("TCP header:\n")); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(TCP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n", - lwip_ntohs(tcphdr->src), lwip_ntohs(tcphdr->dest))); + lwip_ntohs(tcphdr->src), lwip_ntohs(tcphdr->dest))); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(TCP_DEBUG, ("| %010"U32_F" | (seq no)\n", - lwip_ntohl(tcphdr->seqno))); + lwip_ntohl(tcphdr->seqno))); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(TCP_DEBUG, ("| %010"U32_F" | (ack no)\n", - lwip_ntohl(tcphdr->ackno))); + lwip_ntohl(tcphdr->ackno))); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(TCP_DEBUG, ("| %2"U16_F" | |%"U16_F"%"U16_F"%"U16_F"%"U16_F"%"U16_F"%"U16_F"| %5"U16_F" | (hdrlen, flags (", - TCPH_HDRLEN(tcphdr), - (u16_t)(TCPH_FLAGS(tcphdr) >> 5 & 1), - (u16_t)(TCPH_FLAGS(tcphdr) >> 4 & 1), - (u16_t)(TCPH_FLAGS(tcphdr) >> 3 & 1), - (u16_t)(TCPH_FLAGS(tcphdr) >> 2 & 1), - (u16_t)(TCPH_FLAGS(tcphdr) >> 1 & 1), - (u16_t)(TCPH_FLAGS(tcphdr) & 1), - lwip_ntohs(tcphdr->wnd))); + TCPH_HDRLEN(tcphdr), + (u16_t)(TCPH_FLAGS(tcphdr) >> 5 & 1), + (u16_t)(TCPH_FLAGS(tcphdr) >> 4 & 1), + (u16_t)(TCPH_FLAGS(tcphdr) >> 3 & 1), + (u16_t)(TCPH_FLAGS(tcphdr) >> 2 & 1), + (u16_t)(TCPH_FLAGS(tcphdr) >> 1 & 1), + (u16_t)(TCPH_FLAGS(tcphdr) & 1), + lwip_ntohs(tcphdr->wnd))); tcp_debug_print_flags(TCPH_FLAGS(tcphdr)); LWIP_DEBUGF(TCP_DEBUG, ("), win)\n")); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(TCP_DEBUG, ("| 0x%04"X16_F" | %5"U16_F" | (chksum, urgp)\n", - lwip_ntohs(tcphdr->chksum), lwip_ntohs(tcphdr->urgp))); + lwip_ntohs(tcphdr->chksum), lwip_ntohs(tcphdr->urgp))); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); } @@ -2239,8 +2237,8 @@ tcp_debug_print_pcbs(void) LWIP_DEBUGF(TCP_DEBUG, ("Active PCB states:\n")); for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ", - pcb->local_port, pcb->remote_port, - pcb->snd_nxt, pcb->rcv_nxt)); + pcb->local_port, pcb->remote_port, + pcb->snd_nxt, pcb->rcv_nxt)); tcp_debug_print_state(pcb->state); } @@ -2253,8 +2251,8 @@ tcp_debug_print_pcbs(void) LWIP_DEBUGF(TCP_DEBUG, ("TIME-WAIT PCB states:\n")); for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) { LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ", - pcb->local_port, pcb->remote_port, - pcb->snd_nxt, pcb->rcv_nxt)); + pcb->local_port, pcb->remote_port, + pcb->snd_nxt, pcb->rcv_nxt)); tcp_debug_print_state(pcb->state); } } diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 3f5c1e11..dd089bec 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -71,7 +71,7 @@ static struct tcp_seg inseg; static struct tcp_hdr *tcphdr; static u16_t tcphdr_optlen; static u16_t tcphdr_opt1len; -static u8_t* tcphdr_opt2; +static u8_t *tcphdr_opt2; static u16_t tcp_optidx; static u32_t seqno, ackno; static tcpwnd_size_t recv_acked; @@ -154,10 +154,10 @@ tcp_input(struct pbuf *p, struct netif *inp) IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_CHECK_TCP) { /* Verify TCP checksum. */ u16_t chksum = ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len, - ip_current_src_addr(), ip_current_dest_addr()); + ip_current_src_addr(), ip_current_dest_addr()); if (chksum != 0) { - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packet discarded due to failing checksum 0x%04"X16_F"\n", - chksum)); + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packet discarded due to failing checksum 0x%04"X16_F"\n", + chksum)); tcp_debug_print(tcphdr); TCP_STATS_INC(tcp.chkerr); goto dropped; @@ -207,7 +207,7 @@ tcp_input(struct pbuf *p, struct netif *inp) } /* remember the pointer to the second part of the options */ - tcphdr_opt2 = (u8_t*)p->next->payload; + tcphdr_opt2 = (u8_t *)p->next->payload; /* advance p->next to point after the options, and manually adjust p->tot_len to keep it consistent with the changed p->next */ @@ -310,7 +310,7 @@ tcp_input(struct pbuf *p, struct netif *inp) prev = (struct tcp_pcb *)lpcb; continue; } - + if (lpcb->local_port == tcphdr->dest) { if (IP_IS_ANY_TYPE_VAL(lpcb->local_ip)) { /* found an ANY TYPE (IPv4/IPv6) match */ @@ -351,9 +351,9 @@ tcp_input(struct pbuf *p, struct netif *inp) arrivals). */ if (prev != NULL) { ((struct tcp_pcb_listen *)prev)->next = lpcb->next; - /* our successor is the remainder of the listening list */ + /* our successor is the remainder of the listening list */ lpcb->next = tcp_listen_pcbs.listen_pcbs; - /* put this listening pcb at the head of the listening list */ + /* put this listening pcb at the head of the listening list */ tcp_listen_pcbs.listen_pcbs = lpcb; } else { TCP_STATS_INC(tcp.cachehit); @@ -396,7 +396,7 @@ tcp_input(struct pbuf *p, struct netif *inp) /* If there is data which was previously "refused" by upper layer */ if (pcb->refused_data != NULL) { if ((tcp_process_refused_data(pcb) == ERR_ABRT) || - ((pcb->refused_data != NULL) && (tcplen > 0))) { + ((pcb->refused_data != NULL) && (tcplen > 0))) { /* pcb has been aborted or refused data is still refused and the new segment contains data */ if (pcb->rcv_ann_wnd == 0) { @@ -540,8 +540,7 @@ aborted: recv_data = NULL; /* give up our reference to inseg.p */ - if (inseg.p != NULL) - { + if (inseg.p != NULL) { pbuf_free(inseg.p); inseg.p = NULL; } @@ -553,7 +552,7 @@ aborted: TCP_STATS_INC(tcp.proterr); TCP_STATS_INC(tcp.drop); tcp_rst(NULL, ackno, seqno + tcplen, ip_current_dest_addr(), - ip_current_src_addr(), tcphdr->dest, tcphdr->src); + ip_current_src_addr(), tcphdr->dest, tcphdr->src); } pbuf_free(p); } @@ -618,8 +617,8 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) /* For incoming segments with the ACK flag set, respond with a RST. */ LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_listen_input: ACK in LISTEN, sending reset\n")); - tcp_rst((const struct tcp_pcb*)pcb, ackno, seqno + tcplen, ip_current_dest_addr(), - ip_current_src_addr(), tcphdr->dest, tcphdr->src); + tcp_rst((const struct tcp_pcb *)pcb, ackno, seqno + tcplen, ip_current_dest_addr(), + ip_current_src_addr(), tcphdr->dest, tcphdr->src); } else if (flags & TCP_SYN) { LWIP_DEBUGF(TCP_DEBUG, ("TCP connection request %"U16_F" -> %"U16_F".\n", tcphdr->src, tcphdr->dest)); #if TCP_LISTEN_BACKLOG @@ -718,7 +717,7 @@ tcp_timewait_input(struct tcp_pcb *pcb) if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, pcb->rcv_nxt + pcb->rcv_wnd)) { /* If the SYN is in the window it is an error, send a reset */ tcp_rst(pcb, ackno, seqno + tcplen, ip_current_dest_addr(), - ip_current_src_addr(), tcphdr->dest, tcphdr->src); + ip_current_src_addr(), tcphdr->dest, tcphdr->src); return; } } else if (flags & TCP_FIN) { @@ -787,9 +786,9 @@ tcp_process(struct tcp_pcb *pcb) return ERR_RST; } else { LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_process: unacceptable reset seqno %"U32_F" rcv_nxt %"U32_F"\n", - seqno, pcb->rcv_nxt)); + seqno, pcb->rcv_nxt)); LWIP_DEBUGF(TCP_DEBUG, ("tcp_process: unacceptable reset seqno %"U32_F" rcv_nxt %"U32_F"\n", - seqno, pcb->rcv_nxt)); + seqno, pcb->rcv_nxt)); return ERR_OK; } } @@ -811,192 +810,192 @@ tcp_process(struct tcp_pcb *pcb) /* Do different things depending on the TCP state. */ switch (pcb->state) { - case SYN_SENT: - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("SYN-SENT: ackno %"U32_F" pcb->snd_nxt %"U32_F" unacked %"U32_F"\n", ackno, - pcb->snd_nxt, lwip_ntohl(pcb->unacked->tcphdr->seqno))); - /* received SYN ACK with expected sequence number? */ - if ((flags & TCP_ACK) && (flags & TCP_SYN) - && (ackno == pcb->lastack + 1)) { - pcb->rcv_nxt = seqno + 1; - pcb->rcv_ann_right_edge = pcb->rcv_nxt; - pcb->lastack = ackno; - pcb->snd_wnd = tcphdr->wnd; - pcb->snd_wnd_max = pcb->snd_wnd; - pcb->snd_wl1 = seqno - 1; /* initialise to seqno - 1 to force window update */ - pcb->state = ESTABLISHED; + case SYN_SENT: + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("SYN-SENT: ackno %"U32_F" pcb->snd_nxt %"U32_F" unacked %"U32_F"\n", ackno, + pcb->snd_nxt, lwip_ntohl(pcb->unacked->tcphdr->seqno))); + /* received SYN ACK with expected sequence number? */ + if ((flags & TCP_ACK) && (flags & TCP_SYN) + && (ackno == pcb->lastack + 1)) { + pcb->rcv_nxt = seqno + 1; + pcb->rcv_ann_right_edge = pcb->rcv_nxt; + pcb->lastack = ackno; + pcb->snd_wnd = tcphdr->wnd; + pcb->snd_wnd_max = pcb->snd_wnd; + pcb->snd_wl1 = seqno - 1; /* initialise to seqno - 1 to force window update */ + pcb->state = ESTABLISHED; #if TCP_CALCULATE_EFF_SEND_MSS - pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip); + pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip); #endif /* TCP_CALCULATE_EFF_SEND_MSS */ - pcb->cwnd = LWIP_TCP_CALC_INITIAL_CWND(pcb->mss); - LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_process (SENT): cwnd %"TCPWNDSIZE_F - " ssthresh %"TCPWNDSIZE_F"\n", - pcb->cwnd, pcb->ssthresh)); - LWIP_ASSERT("pcb->snd_queuelen > 0", (pcb->snd_queuelen > 0)); - --pcb->snd_queuelen; - LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_process: SYN-SENT --queuelen %"TCPWNDSIZE_F"\n", (tcpwnd_size_t)pcb->snd_queuelen)); - rseg = pcb->unacked; - if (rseg == NULL) { - /* might happen if tcp_output fails in tcp_rexmit_rto() - in which case the segment is on the unsent list */ - rseg = pcb->unsent; - LWIP_ASSERT("no segment to free", rseg != NULL); - pcb->unsent = rseg->next; - } else { - pcb->unacked = rseg->next; - } - tcp_seg_free(rseg); - - /* If there's nothing left to acknowledge, stop the retransmit - timer, otherwise reset it to start again */ - if (pcb->unacked == NULL) { - pcb->rtime = -1; - } else { - pcb->rtime = 0; - pcb->nrtx = 0; - } - - /* Call the user specified function to call when successfully - * connected. */ - TCP_EVENT_CONNECTED(pcb, ERR_OK, err); - if (err == ERR_ABRT) { - return ERR_ABRT; - } - tcp_ack_now(pcb); - } - /* received ACK? possibly a half-open connection */ - else if (flags & TCP_ACK) { - /* send a RST to bring the other side in a non-synchronized state. */ - tcp_rst(pcb, ackno, seqno + tcplen, ip_current_dest_addr(), - ip_current_src_addr(), tcphdr->dest, tcphdr->src); - /* Resend SYN immediately (don't wait for rto timeout) to establish - connection faster, but do not send more SYNs than we otherwise would - have, or we might get caught in a loop on loopback interfaces. */ - if (pcb->nrtx < TCP_SYNMAXRTX) { - pcb->rtime = 0; - tcp_rexmit_rto(pcb); - } - } - break; - case SYN_RCVD: - if (flags & TCP_ACK) { - /* expected ACK number? */ - if (TCP_SEQ_BETWEEN(ackno, pcb->lastack+1, pcb->snd_nxt)) { - pcb->state = ESTABLISHED; - LWIP_DEBUGF(TCP_DEBUG, ("TCP connection established %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); -#if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG - if (pcb->listener == NULL) { - /* listen pcb might be closed by now */ - err = ERR_VAL; - } else -#endif /* LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG */ - { -#if LWIP_CALLBACK_API - LWIP_ASSERT("pcb->listener->accept != NULL", pcb->listener->accept != NULL); -#endif - tcp_backlog_accepted(pcb); - /* Call the accept function. */ - TCP_EVENT_ACCEPT(pcb->listener, pcb, pcb->callback_arg, ERR_OK, err); - } - if (err != ERR_OK) { - /* If the accept function returns with an error, we abort - * the connection. */ - /* Already aborted? */ - if (err != ERR_ABRT) { - tcp_abort(pcb); - } - return ERR_ABRT; - } - /* If there was any data contained within this ACK, - * we'd better pass it on to the application as well. */ - tcp_receive(pcb); - - /* Prevent ACK for SYN to generate a sent event */ - if (recv_acked != 0) { - recv_acked--; - } - pcb->cwnd = LWIP_TCP_CALC_INITIAL_CWND(pcb->mss); - LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_process (SYN_RCVD): cwnd %"TCPWNDSIZE_F + LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_process (SENT): cwnd %"TCPWNDSIZE_F " ssthresh %"TCPWNDSIZE_F"\n", pcb->cwnd, pcb->ssthresh)); - - if (recv_flags & TF_GOT_FIN) { - tcp_ack_now(pcb); - pcb->state = CLOSE_WAIT; + LWIP_ASSERT("pcb->snd_queuelen > 0", (pcb->snd_queuelen > 0)); + --pcb->snd_queuelen; + LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_process: SYN-SENT --queuelen %"TCPWNDSIZE_F"\n", (tcpwnd_size_t)pcb->snd_queuelen)); + rseg = pcb->unacked; + if (rseg == NULL) { + /* might happen if tcp_output fails in tcp_rexmit_rto() + in which case the segment is on the unsent list */ + rseg = pcb->unsent; + LWIP_ASSERT("no segment to free", rseg != NULL); + pcb->unsent = rseg->next; + } else { + pcb->unacked = rseg->next; } - } else { - /* incorrect ACK number, send RST */ - tcp_rst(pcb, ackno, seqno + tcplen, ip_current_dest_addr(), - ip_current_src_addr(), tcphdr->dest, tcphdr->src); + tcp_seg_free(rseg); + + /* If there's nothing left to acknowledge, stop the retransmit + timer, otherwise reset it to start again */ + if (pcb->unacked == NULL) { + pcb->rtime = -1; + } else { + pcb->rtime = 0; + pcb->nrtx = 0; + } + + /* Call the user specified function to call when successfully + * connected. */ + TCP_EVENT_CONNECTED(pcb, ERR_OK, err); + if (err == ERR_ABRT) { + return ERR_ABRT; + } + tcp_ack_now(pcb); } - } else if ((flags & TCP_SYN) && (seqno == pcb->rcv_nxt - 1)) { - /* Looks like another copy of the SYN - retransmit our SYN-ACK */ - tcp_rexmit(pcb); - } - break; - case CLOSE_WAIT: + /* received ACK? possibly a half-open connection */ + else if (flags & TCP_ACK) { + /* send a RST to bring the other side in a non-synchronized state. */ + tcp_rst(pcb, ackno, seqno + tcplen, ip_current_dest_addr(), + ip_current_src_addr(), tcphdr->dest, tcphdr->src); + /* Resend SYN immediately (don't wait for rto timeout) to establish + connection faster, but do not send more SYNs than we otherwise would + have, or we might get caught in a loop on loopback interfaces. */ + if (pcb->nrtx < TCP_SYNMAXRTX) { + pcb->rtime = 0; + tcp_rexmit_rto(pcb); + } + } + break; + case SYN_RCVD: + if (flags & TCP_ACK) { + /* expected ACK number? */ + if (TCP_SEQ_BETWEEN(ackno, pcb->lastack + 1, pcb->snd_nxt)) { + pcb->state = ESTABLISHED; + LWIP_DEBUGF(TCP_DEBUG, ("TCP connection established %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); +#if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG + if (pcb->listener == NULL) { + /* listen pcb might be closed by now */ + err = ERR_VAL; + } else +#endif /* LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG */ + { +#if LWIP_CALLBACK_API + LWIP_ASSERT("pcb->listener->accept != NULL", pcb->listener->accept != NULL); +#endif + tcp_backlog_accepted(pcb); + /* Call the accept function. */ + TCP_EVENT_ACCEPT(pcb->listener, pcb, pcb->callback_arg, ERR_OK, err); + } + if (err != ERR_OK) { + /* If the accept function returns with an error, we abort + * the connection. */ + /* Already aborted? */ + if (err != ERR_ABRT) { + tcp_abort(pcb); + } + return ERR_ABRT; + } + /* If there was any data contained within this ACK, + * we'd better pass it on to the application as well. */ + tcp_receive(pcb); + + /* Prevent ACK for SYN to generate a sent event */ + if (recv_acked != 0) { + recv_acked--; + } + + pcb->cwnd = LWIP_TCP_CALC_INITIAL_CWND(pcb->mss); + LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_process (SYN_RCVD): cwnd %"TCPWNDSIZE_F + " ssthresh %"TCPWNDSIZE_F"\n", + pcb->cwnd, pcb->ssthresh)); + + if (recv_flags & TF_GOT_FIN) { + tcp_ack_now(pcb); + pcb->state = CLOSE_WAIT; + } + } else { + /* incorrect ACK number, send RST */ + tcp_rst(pcb, ackno, seqno + tcplen, ip_current_dest_addr(), + ip_current_src_addr(), tcphdr->dest, tcphdr->src); + } + } else if ((flags & TCP_SYN) && (seqno == pcb->rcv_nxt - 1)) { + /* Looks like another copy of the SYN - retransmit our SYN-ACK */ + tcp_rexmit(pcb); + } + break; + case CLOSE_WAIT: /* FALLTHROUGH */ - case ESTABLISHED: - tcp_receive(pcb); - if (recv_flags & TF_GOT_FIN) { /* passive close */ - tcp_ack_now(pcb); - pcb->state = CLOSE_WAIT; - } - break; - case FIN_WAIT_1: - tcp_receive(pcb); - if (recv_flags & TF_GOT_FIN) { - if ((flags & TCP_ACK) && (ackno == pcb->snd_nxt) && - pcb->unsent == NULL) { - LWIP_DEBUGF(TCP_DEBUG, - ("TCP connection closed: FIN_WAIT_1 %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); + case ESTABLISHED: + tcp_receive(pcb); + if (recv_flags & TF_GOT_FIN) { /* passive close */ + tcp_ack_now(pcb); + pcb->state = CLOSE_WAIT; + } + break; + case FIN_WAIT_1: + tcp_receive(pcb); + if (recv_flags & TF_GOT_FIN) { + if ((flags & TCP_ACK) && (ackno == pcb->snd_nxt) && + pcb->unsent == NULL) { + LWIP_DEBUGF(TCP_DEBUG, + ("TCP connection closed: FIN_WAIT_1 %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); + tcp_ack_now(pcb); + tcp_pcb_purge(pcb); + TCP_RMV_ACTIVE(pcb); + pcb->state = TIME_WAIT; + TCP_REG(&tcp_tw_pcbs, pcb); + } else { + tcp_ack_now(pcb); + pcb->state = CLOSING; + } + } else if ((flags & TCP_ACK) && (ackno == pcb->snd_nxt) && + pcb->unsent == NULL) { + pcb->state = FIN_WAIT_2; + } + break; + case FIN_WAIT_2: + tcp_receive(pcb); + if (recv_flags & TF_GOT_FIN) { + LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: FIN_WAIT_2 %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); tcp_ack_now(pcb); tcp_pcb_purge(pcb); TCP_RMV_ACTIVE(pcb); pcb->state = TIME_WAIT; TCP_REG(&tcp_tw_pcbs, pcb); - } else { - tcp_ack_now(pcb); - pcb->state = CLOSING; } - } else if ((flags & TCP_ACK) && (ackno == pcb->snd_nxt) && - pcb->unsent == NULL) { - pcb->state = FIN_WAIT_2; - } - break; - case FIN_WAIT_2: - tcp_receive(pcb); - if (recv_flags & TF_GOT_FIN) { - LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: FIN_WAIT_2 %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); - tcp_ack_now(pcb); - tcp_pcb_purge(pcb); - TCP_RMV_ACTIVE(pcb); - pcb->state = TIME_WAIT; - TCP_REG(&tcp_tw_pcbs, pcb); - } - break; - case CLOSING: - tcp_receive(pcb); - if ((flags & TCP_ACK) && ackno == pcb->snd_nxt && pcb->unsent == NULL) { - LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: CLOSING %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); - tcp_pcb_purge(pcb); - TCP_RMV_ACTIVE(pcb); - pcb->state = TIME_WAIT; - TCP_REG(&tcp_tw_pcbs, pcb); - } - break; - case LAST_ACK: - tcp_receive(pcb); - if ((flags & TCP_ACK) && ackno == pcb->snd_nxt && pcb->unsent == NULL) { - LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: LAST_ACK %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); - /* bugfix #21699: don't set pcb->state to CLOSED here or we risk leaking segments */ - recv_flags |= TF_CLOSED; - } - break; - default: - break; + break; + case CLOSING: + tcp_receive(pcb); + if ((flags & TCP_ACK) && ackno == pcb->snd_nxt && pcb->unsent == NULL) { + LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: CLOSING %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); + tcp_pcb_purge(pcb); + TCP_RMV_ACTIVE(pcb); + pcb->state = TIME_WAIT; + TCP_REG(&tcp_tw_pcbs, pcb); + } + break; + case LAST_ACK: + tcp_receive(pcb); + if ((flags & TCP_ACK) && ackno == pcb->snd_nxt && pcb->unsent == NULL) { + LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: LAST_ACK %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); + /* bugfix #21699: don't set pcb->state to CLOSED here or we risk leaking segments */ + recv_flags |= TF_CLOSED; + } + break; + default: + break; } return ERR_OK; } @@ -1021,7 +1020,7 @@ tcp_oos_insert_segment(struct tcp_seg *cseg, struct tcp_seg *next) oos queue may have segments with FIN flag */ while (next && TCP_SEQ_GEQ((seqno + cseg->len), - (next->tcphdr->seqno + next->len))) { + (next->tcphdr->seqno + next->len))) { /* cseg with FIN already processed */ if (TCPH_FLAGS(next->tcphdr) & TCP_FIN) { TCPH_SET_FLAG(cseg->tcphdr, TCP_FIN); @@ -1043,7 +1042,7 @@ tcp_oos_insert_segment(struct tcp_seg *cseg, struct tcp_seg *next) /** Remove segments from a list if the incoming ACK acknowledges them */ static struct tcp_seg * -tcp_free_acked_segments(struct tcp_pcb *pcb, struct tcp_seg *seg_list, const char* dbg_list_name, +tcp_free_acked_segments(struct tcp_pcb *pcb, struct tcp_seg *seg_list, const char *dbg_list_name, struct tcp_seg *dbg_other_seg_list) { struct tcp_seg *next; @@ -1053,8 +1052,8 @@ tcp_free_acked_segments(struct tcp_pcb *pcb, struct tcp_seg *seg_list, const cha LWIP_UNUSED_ARG(dbg_other_seg_list); while (seg_list != NULL && - TCP_SEQ_LEQ(lwip_ntohl(seg_list->tcphdr->seqno) + - TCP_TCPLEN(seg_list), ackno)) { + TCP_SEQ_LEQ(lwip_ntohl(seg_list->tcphdr->seqno) + + TCP_TCPLEN(seg_list), ackno)) { LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: removing %"U32_F":%"U32_F" from pcb->%s\n", lwip_ntohl(seg_list->tcphdr->seqno), lwip_ntohl(seg_list->tcphdr->seqno) + TCP_TCPLEN(seg_list), @@ -1119,8 +1118,8 @@ tcp_receive(struct tcp_pcb *pcb) /* Update window. */ if (TCP_SEQ_LT(pcb->snd_wl1, seqno) || - (pcb->snd_wl1 == seqno && TCP_SEQ_LT(pcb->snd_wl2, ackno)) || - (pcb->snd_wl2 == ackno && (u32_t)SND_WND_SCALE(pcb, tcphdr->wnd) > pcb->snd_wnd)) { + (pcb->snd_wl1 == seqno && TCP_SEQ_LT(pcb->snd_wl2, ackno)) || + (pcb->snd_wl2 == ackno && (u32_t)SND_WND_SCALE(pcb, tcphdr->wnd) > pcb->snd_wnd)) { pcb->snd_wnd = SND_WND_SCALE(pcb, tcphdr->wnd); /* keep track of the biggest window announced by the remote host to calculate the maximum segment size */ @@ -1192,7 +1191,7 @@ tcp_receive(struct tcp_pcb *pcb) if (!found_dupack) { pcb->dupacks = 0; } - } else if (TCP_SEQ_BETWEEN(ackno, pcb->lastack+1, pcb->snd_nxt)) { + } else if (TCP_SEQ_BETWEEN(ackno, pcb->lastack + 1, pcb->snd_nxt)) { /* We come here when the ACK acknowledges new data. */ tcpwnd_size_t acked; @@ -1241,10 +1240,10 @@ tcp_receive(struct tcp_pcb *pcb) } LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: ACK for %"U32_F", unacked->seqno %"U32_F":%"U32_F"\n", ackno, - pcb->unacked != NULL? - lwip_ntohl(pcb->unacked->tcphdr->seqno): 0, - pcb->unacked != NULL? - lwip_ntohl(pcb->unacked->tcphdr->seqno) + TCP_TCPLEN(pcb->unacked): 0)); + pcb->unacked != NULL ? + lwip_ntohl(pcb->unacked->tcphdr->seqno) : 0, + pcb->unacked != NULL ? + lwip_ntohl(pcb->unacked->tcphdr->seqno) + TCP_TCPLEN(pcb->unacked) : 0)); /* Remove segment from the unacknowledged list if the incoming ACK acknowledges them. */ @@ -1320,7 +1319,7 @@ tcp_receive(struct tcp_pcb *pcb) m = (s16_t)(m - (pcb->sa >> 3)); pcb->sa = (s16_t)(pcb->sa + m); if (m < 0) { - m = (s16_t)-m; + m = (s16_t) - m; } m = (s16_t)(m - (pcb->sv >> 2)); pcb->sv = (s16_t)(pcb->sv + m); @@ -1408,8 +1407,7 @@ tcp_receive(struct tcp_pcb *pcb) /* cannot fail... */ pbuf_remove_header(p, off); inseg.tcphdr->seqno = seqno = pcb->rcv_nxt; - } - else { + } else { if (TCP_SEQ_LT(seqno, pcb->rcv_nxt)) { /* the whole segment is < rcv_nxt */ /* must be a duplicate of a packet that has already been correctly handled */ @@ -1684,7 +1682,7 @@ tcp_receive(struct tcp_pcb *pcb) } else { /*if (TCP_SEQ_LT(prev->tcphdr->seqno, seqno) && TCP_SEQ_LT(seqno, next->tcphdr->seqno)) {*/ - if (TCP_SEQ_BETWEEN(seqno, prev->tcphdr->seqno+1, next->tcphdr->seqno-1)) { + if (TCP_SEQ_BETWEEN(seqno, prev->tcphdr->seqno + 1, next->tcphdr->seqno - 1)) { /* The sequence number of the incoming segment is in between the sequence numbers of the previous and the next segment on ->ooseq. We trim trim the previous @@ -1771,7 +1769,7 @@ tcp_receive(struct tcp_pcb *pcb) sackbeg = next->tcphdr->seqno; } } else { - next = NULL; + next = NULL; } if (next != NULL) { u32_t sackend = next->tcphdr->seqno; @@ -1796,21 +1794,21 @@ tcp_receive(struct tcp_pcb *pcb) if ((ooseq_blen > TCP_OOSEQ_MAX_BYTES) || (ooseq_qlen > TCP_OOSEQ_MAX_PBUFS)) { #if LWIP_TCP_SACK_OUT - if (pcb->flags & TF_SACK) { - /* Let's remove all SACKs from next's seqno up. */ - tcp_remove_sacks_gt(pcb, next->tcphdr->seqno); - } + if (pcb->flags & TF_SACK) { + /* Let's remove all SACKs from next's seqno up. */ + tcp_remove_sacks_gt(pcb, next->tcphdr->seqno); + } #endif /* LWIP_TCP_SACK_OUT */ - /* too much ooseq data, dump this and everything after it */ - tcp_segs_free(next); - if (prev == NULL) { - /* first ooseq segment is too much, dump the whole queue */ - pcb->ooseq = NULL; - } else { - /* just dump 'next' and everything after it */ - prev->next = NULL; - } - break; + /* too much ooseq data, dump this and everything after it */ + tcp_segs_free(next); + if (prev == NULL) { + /* first ooseq segment is too much, dump the whole queue */ + pcb->ooseq = NULL; + } else { + /* just dump 'next' and everything after it */ + prev->next = NULL; + } + break; } } #endif /* TCP_OOSEQ_MAX_BYTES || TCP_OOSEQ_MAX_PBUFS */ @@ -1838,7 +1836,7 @@ tcp_get_next_optbyte(void) { u16_t optidx = tcp_optidx++; if ((tcphdr_opt2 == NULL) || (optidx < tcphdr_opt1len)) { - u8_t* opts = (u8_t *)tcphdr + TCP_HLEN; + u8_t *opts = (u8_t *)tcphdr + TCP_HLEN; return opts[optidx]; } else { u8_t idx = (u8_t)(optidx - tcphdr_opt1len); @@ -1868,105 +1866,105 @@ tcp_parseopt(struct tcp_pcb *pcb) for (tcp_optidx = 0; tcp_optidx < tcphdr_optlen; ) { u8_t opt = tcp_get_next_optbyte(); switch (opt) { - case LWIP_TCP_OPT_EOL: - /* End of options. */ - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: EOL\n")); - return; - case LWIP_TCP_OPT_NOP: - /* NOP option. */ - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: NOP\n")); - break; - case LWIP_TCP_OPT_MSS: - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: MSS\n")); - if (tcp_get_next_optbyte() != LWIP_TCP_OPT_LEN_MSS || (tcp_optidx - 2 + LWIP_TCP_OPT_LEN_MSS) > tcphdr_optlen) { - /* Bad length */ - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n")); + case LWIP_TCP_OPT_EOL: + /* End of options. */ + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: EOL\n")); return; - } - /* An MSS option with the right option length. */ - mss = (u16_t)(tcp_get_next_optbyte() << 8); - mss |= tcp_get_next_optbyte(); - /* Limit the mss to the configured TCP_MSS and prevent division by zero */ - pcb->mss = ((mss > TCP_MSS) || (mss == 0)) ? TCP_MSS : mss; - break; -#if LWIP_WND_SCALE - case LWIP_TCP_OPT_WS: - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: WND_SCALE\n")); - if (tcp_get_next_optbyte() != LWIP_TCP_OPT_LEN_WS || (tcp_optidx - 2 + LWIP_TCP_OPT_LEN_WS) > tcphdr_optlen) { - /* Bad length */ - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n")); - return; - } - /* An WND_SCALE option with the right option length. */ - data = tcp_get_next_optbyte(); - /* If syn was received with wnd scale option, - activate wnd scale opt, but only if this is not a retransmission */ - if ((flags & TCP_SYN) && !(pcb->flags & TF_WND_SCALE)) { - pcb->snd_scale = data; - if (pcb->snd_scale > 14U) { - pcb->snd_scale = 14U; + case LWIP_TCP_OPT_NOP: + /* NOP option. */ + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: NOP\n")); + break; + case LWIP_TCP_OPT_MSS: + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: MSS\n")); + if (tcp_get_next_optbyte() != LWIP_TCP_OPT_LEN_MSS || (tcp_optidx - 2 + LWIP_TCP_OPT_LEN_MSS) > tcphdr_optlen) { + /* Bad length */ + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n")); + return; } - pcb->rcv_scale = TCP_RCV_SCALE; - tcp_set_flags(pcb, TF_WND_SCALE); - /* window scaling is enabled, we can use the full receive window */ - LWIP_ASSERT("window not at default value", pcb->rcv_wnd == TCPWND_MIN16(TCP_WND)); - LWIP_ASSERT("window not at default value", pcb->rcv_ann_wnd == TCPWND_MIN16(TCP_WND)); - pcb->rcv_wnd = pcb->rcv_ann_wnd = TCP_WND; - } - break; + /* An MSS option with the right option length. */ + mss = (u16_t)(tcp_get_next_optbyte() << 8); + mss |= tcp_get_next_optbyte(); + /* Limit the mss to the configured TCP_MSS and prevent division by zero */ + pcb->mss = ((mss > TCP_MSS) || (mss == 0)) ? TCP_MSS : mss; + break; +#if LWIP_WND_SCALE + case LWIP_TCP_OPT_WS: + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: WND_SCALE\n")); + if (tcp_get_next_optbyte() != LWIP_TCP_OPT_LEN_WS || (tcp_optidx - 2 + LWIP_TCP_OPT_LEN_WS) > tcphdr_optlen) { + /* Bad length */ + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n")); + return; + } + /* An WND_SCALE option with the right option length. */ + data = tcp_get_next_optbyte(); + /* If syn was received with wnd scale option, + activate wnd scale opt, but only if this is not a retransmission */ + if ((flags & TCP_SYN) && !(pcb->flags & TF_WND_SCALE)) { + pcb->snd_scale = data; + if (pcb->snd_scale > 14U) { + pcb->snd_scale = 14U; + } + pcb->rcv_scale = TCP_RCV_SCALE; + tcp_set_flags(pcb, TF_WND_SCALE); + /* window scaling is enabled, we can use the full receive window */ + LWIP_ASSERT("window not at default value", pcb->rcv_wnd == TCPWND_MIN16(TCP_WND)); + LWIP_ASSERT("window not at default value", pcb->rcv_ann_wnd == TCPWND_MIN16(TCP_WND)); + pcb->rcv_wnd = pcb->rcv_ann_wnd = TCP_WND; + } + break; #endif /* LWIP_WND_SCALE */ #if LWIP_TCP_TIMESTAMPS - case LWIP_TCP_OPT_TS: - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: TS\n")); - if (tcp_get_next_optbyte() != LWIP_TCP_OPT_LEN_TS || (tcp_optidx - 2 + LWIP_TCP_OPT_LEN_TS) > tcphdr_optlen) { - /* Bad length */ - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n")); - return; - } - /* TCP timestamp option with valid length */ - tsval = tcp_get_next_optbyte(); - tsval |= (tcp_get_next_optbyte() << 8); - tsval |= (tcp_get_next_optbyte() << 16); - tsval |= (tcp_get_next_optbyte() << 24); - if (flags & TCP_SYN) { - pcb->ts_recent = lwip_ntohl(tsval); - /* Enable sending timestamps in every segment now that we know - the remote host supports it. */ - tcp_set_flags(pcb, TF_TIMESTAMP); - } else if (TCP_SEQ_BETWEEN(pcb->ts_lastacksent, seqno, seqno+tcplen)) { - pcb->ts_recent = lwip_ntohl(tsval); - } - /* Advance to next option (6 bytes already read) */ - tcp_optidx += LWIP_TCP_OPT_LEN_TS - 6; - break; + case LWIP_TCP_OPT_TS: + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: TS\n")); + if (tcp_get_next_optbyte() != LWIP_TCP_OPT_LEN_TS || (tcp_optidx - 2 + LWIP_TCP_OPT_LEN_TS) > tcphdr_optlen) { + /* Bad length */ + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n")); + return; + } + /* TCP timestamp option with valid length */ + tsval = tcp_get_next_optbyte(); + tsval |= (tcp_get_next_optbyte() << 8); + tsval |= (tcp_get_next_optbyte() << 16); + tsval |= (tcp_get_next_optbyte() << 24); + if (flags & TCP_SYN) { + pcb->ts_recent = lwip_ntohl(tsval); + /* Enable sending timestamps in every segment now that we know + the remote host supports it. */ + tcp_set_flags(pcb, TF_TIMESTAMP); + } else if (TCP_SEQ_BETWEEN(pcb->ts_lastacksent, seqno, seqno + tcplen)) { + pcb->ts_recent = lwip_ntohl(tsval); + } + /* Advance to next option (6 bytes already read) */ + tcp_optidx += LWIP_TCP_OPT_LEN_TS - 6; + break; #endif /* LWIP_TCP_TIMESTAMPS */ #if LWIP_TCP_SACK_OUT - case LWIP_TCP_OPT_SACK_PERM: - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: SACK_PERM\n")); - if (tcp_get_next_optbyte() != LWIP_TCP_OPT_LEN_SACK_PERM || (tcp_optidx - 2 + LWIP_TCP_OPT_LEN_SACK_PERM) > tcphdr_optlen) { - /* Bad length */ - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n")); - return; - } - /* TCP SACK_PERM option with valid length */ - if (flags & TCP_SYN) { - /* We only set it if we receive it in a SYN (or SYN+ACK) packet */ - tcp_set_flags(pcb, TF_SACK); - } - break; + case LWIP_TCP_OPT_SACK_PERM: + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: SACK_PERM\n")); + if (tcp_get_next_optbyte() != LWIP_TCP_OPT_LEN_SACK_PERM || (tcp_optidx - 2 + LWIP_TCP_OPT_LEN_SACK_PERM) > tcphdr_optlen) { + /* Bad length */ + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n")); + return; + } + /* TCP SACK_PERM option with valid length */ + if (flags & TCP_SYN) { + /* We only set it if we receive it in a SYN (or SYN+ACK) packet */ + tcp_set_flags(pcb, TF_SACK); + } + break; #endif /* LWIP_TCP_SACK_OUT */ - default: - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: other\n")); - data = tcp_get_next_optbyte(); - if (data < 2) { - LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n")); - /* If the length field is zero, the options are malformed - and we don't process them further. */ - return; - } - /* All other options have a length field, so that we easily - can skip past them. */ - tcp_optidx += data - 2; + default: + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: other\n")); + data = tcp_get_next_optbyte(); + if (data < 2) { + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n")); + /* If the length field is zero, the options are malformed + and we don't process them further. */ + return; + } + /* All other options have a length field, so that we easily + can skip past them. */ + tcp_optidx += data - 2; } } } @@ -2025,14 +2023,14 @@ tcp_add_sack(struct tcp_pcb *pcb, u32_t left, u32_t right) So let's just iterate from the back, and set each entry to the one to the left if it's valid, or to 0 if it is not. */ for (i = LWIP_TCP_MAX_SACK_NUM - 1; i > 0; --i) { - /* [i] is the index we are setting, and the value should be at index [i-1], - or 0 if that index is unused (>= unused_idx). */ - if (i-1 >= unused_idx) { - /* [i-1] is unused. Let's clear [i]. */ - pcb->rcv_sacks[i].left = pcb->rcv_sacks[i].right = 0; - } else { - pcb->rcv_sacks[i] = pcb->rcv_sacks[i-1]; - } + /* [i] is the index we are setting, and the value should be at index [i-1], + or 0 if that index is unused (>= unused_idx). */ + if (i - 1 >= unused_idx) { + /* [i-1] is unused. Let's clear [i]. */ + pcb->rcv_sacks[i].left = pcb->rcv_sacks[i].right = 0; + } else { + pcb->rcv_sacks[i] = pcb->rcv_sacks[i - 1]; + } } /* And now we can store the newest SACK */ diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index e5216787..f72c03a5 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -119,13 +119,13 @@ tcp_route(const struct tcp_pcb *pcb, const ip_addr_t *src, const ip_addr_t *dst) */ static struct pbuf * tcp_output_alloc_header(struct tcp_pcb *pcb, u16_t optlen, u16_t datalen, - u32_t seqno_be /* already in network byte order */) + u32_t seqno_be /* already in network byte order */) { struct tcp_hdr *tcphdr; struct pbuf *p = pbuf_alloc(PBUF_IP, TCP_HLEN + optlen + datalen, PBUF_RAM); if (p != NULL) { LWIP_ASSERT("check that first pbuf can hold struct tcp_hdr", - (p->len >= TCP_HLEN + optlen)); + (p->len >= TCP_HLEN + optlen)); tcphdr = (struct tcp_hdr *)p->payload; tcphdr->src = lwip_htons(pcb->local_port); tcphdr->dest = lwip_htons(pcb->remote_port); @@ -333,7 +333,7 @@ tcp_write_checks(struct tcp_pcb *pcb, u16_t len) /* fail on too much data */ if (len > pcb->snd_buf) { LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("tcp_write: too much data (len=%"U16_F" > snd_buf=%"TCPWNDSIZE_F")\n", - len, pcb->snd_buf)); + len, pcb->snd_buf)); tcp_set_flags(pcb, TF_NAGLEMEMERR); return ERR_MEM; } @@ -345,17 +345,17 @@ tcp_write_checks(struct tcp_pcb *pcb, u16_t len) /* check for configured max queuelen and possible overflow */ if ((pcb->snd_queuelen >= TCP_SND_QUEUELEN) || (pcb->snd_queuelen > TCP_SNDQUEUELEN_OVERFLOW)) { LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("tcp_write: too long queue %"U16_F" (max %"U16_F")\n", - pcb->snd_queuelen, (u16_t)TCP_SND_QUEUELEN)); + pcb->snd_queuelen, (u16_t)TCP_SND_QUEUELEN)); TCP_STATS_INC(tcp.memerr); tcp_set_flags(pcb, TF_NAGLEMEMERR); return ERR_MEM; } if (pcb->snd_queuelen != 0) { LWIP_ASSERT("tcp_write: pbufs on queue => at least one queue non-empty", - pcb->unacked != NULL || pcb->unsent != NULL); + pcb->unacked != NULL || pcb->unsent != NULL); } else { LWIP_ASSERT("tcp_write: no pbufs on queue => both queues empty", - pcb->unacked == NULL && pcb->unsent == NULL); + pcb->unacked == NULL && pcb->unsent == NULL); } return ERR_OK; } @@ -401,7 +401,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) #endif /* TCP_CHECKSUM_ON_COPY */ err_t err; /* don't allocate segments bigger than half the maximum window we ever received */ - u16_t mss_local = LWIP_MIN(pcb->mss, TCPWND_MIN16(pcb->snd_wnd_max/2)); + u16_t mss_local = LWIP_MIN(pcb->mss, TCPWND_MIN16(pcb->snd_wnd_max / 2)); mss_local = mss_local ? mss_local : pcb->mss; #if LWIP_NETIF_TX_SINGLE_PBUF @@ -410,7 +410,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_write(pcb=%p, data=%p, len=%"U16_F", apiflags=%"U16_F")\n", - (void *)pcb, arg, len, (u16_t)apiflags)); + (void *)pcb, arg, len, (u16_t)apiflags)); LWIP_ERROR("tcp_write: arg == NULL (programmer violates API)", arg != NULL, return ERR_ARG;); @@ -528,7 +528,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) #if TCP_OVERSIZE_DBGCHECK oversize_add = oversize; #endif /* TCP_OVERSIZE_DBGCHECK */ - TCP_DATA_COPY2(concat_p->payload, (const u8_t*)arg + pos, seglen, &concat_chksum, &concat_chksum_swapped); + TCP_DATA_COPY2(concat_p->payload, (const u8_t *)arg + pos, seglen, &concat_chksum, &concat_chksum_swapped); #if TCP_CHECKSUM_ON_COPY concat_chksummed += seglen; #endif /* TCP_CHECKSUM_ON_COPY */ @@ -538,7 +538,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) /* If the last unsent pbuf is of type PBUF_ROM, try to extend it. */ struct pbuf *p; for (p = last_unsent->p; p->next != NULL; p = p->next); - if (((p->type_internal & (PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS|PBUF_TYPE_FLAG_DATA_VOLATILE)) == 0) && + if (((p->type_internal & (PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_FLAG_DATA_VOLATILE)) == 0) && (const u8_t *)p->payload + p->len == (const u8_t *)arg) { LWIP_ASSERT("tcp_write: ROM pbufs cannot be oversized", pos == 0); extendlen = seglen; @@ -549,13 +549,13 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) goto memerr; } /* reference the non-volatile payload data */ - ((struct pbuf_rom*)concat_p)->payload = (const u8_t*)arg + pos; + ((struct pbuf_rom *)concat_p)->payload = (const u8_t *)arg + pos; queuelen += pbuf_clen(concat_p); } #if TCP_CHECKSUM_ON_COPY /* calculate the checksum of nocopy-data */ - tcp_seg_add_chksum(~inet_chksum((const u8_t*)arg + pos, seglen), seglen, - &concat_chksum, &concat_chksum_swapped); + tcp_seg_add_chksum(~inet_chksum((const u8_t *)arg + pos, seglen), seglen, + &concat_chksum, &concat_chksum_swapped); concat_chksummed += seglen; #endif /* TCP_CHECKSUM_ON_COPY */ } @@ -595,7 +595,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) } LWIP_ASSERT("tcp_write: check that first pbuf can hold the complete seglen", (p->len >= seglen)); - TCP_DATA_COPY2((char *)p->payload + optlen, (const u8_t*)arg + pos, seglen, &chksum, &chksum_swapped); + TCP_DATA_COPY2((char *)p->payload + optlen, (const u8_t *)arg + pos, seglen, &chksum, &chksum_swapped); } else { /* Copy is not set: First allocate a pbuf for holding the data. * Since the referenced data is available at least until it is @@ -612,14 +612,14 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) } #if TCP_CHECKSUM_ON_COPY /* calculate the checksum of nocopy-data */ - chksum = ~inet_chksum((const u8_t*)arg + pos, seglen); + chksum = ~inet_chksum((const u8_t *)arg + pos, seglen); if (seglen & 1) { chksum_swapped = 1; chksum = SWAP_BYTES_IN_WORD(chksum); } #endif /* TCP_CHECKSUM_ON_COPY */ /* reference the non-volatile payload data */ - ((struct pbuf_rom*)p2)->payload = (const u8_t*)arg + pos; + ((struct pbuf_rom *)p2)->payload = (const u8_t *)arg + pos; /* Second, allocate a pbuf for the headers. */ if ((p = pbuf_alloc(PBUF_TRANSPORT, optlen, PBUF_RAM)) == NULL) { @@ -640,7 +640,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) * overflows. */ if ((queuelen > TCP_SND_QUEUELEN) || (queuelen > TCP_SNDQUEUELEN_OVERFLOW)) { LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("tcp_write: queue too long %"U16_F" (%d)\n", - queuelen, (int)TCP_SND_QUEUELEN)); + queuelen, (int)TCP_SND_QUEUELEN)); pbuf_free(p); goto memerr; } @@ -669,8 +669,8 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) prev_seg = seg; LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_TRACE, ("tcp_write: queueing %"U32_F":%"U32_F"\n", - lwip_ntohl(seg->tcphdr->seqno), - lwip_ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg))); + lwip_ntohl(seg->tcphdr->seqno), + lwip_ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg))); pos += seglen; } @@ -716,13 +716,13 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) */ if (concat_p != NULL) { LWIP_ASSERT("tcp_write: cannot concatenate when pcb->unsent is empty", - (last_unsent != NULL)); + (last_unsent != NULL)); pbuf_cat(last_unsent->p, concat_p); last_unsent->len += concat_p->tot_len; } else if (extendlen > 0) { struct pbuf *p; LWIP_ASSERT("tcp_write: extension of reference requires reference", - last_unsent != NULL && last_unsent->p != NULL); + last_unsent != NULL && last_unsent->p != NULL); for (p = last_unsent->p; p->next != NULL; p = p->next) { p->tot_len += extendlen; } @@ -734,13 +734,13 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) #if TCP_CHECKSUM_ON_COPY if (concat_chksummed) { LWIP_ASSERT("tcp_write: concat checksum needs concatenated data", - concat_p != NULL || extendlen > 0); + concat_p != NULL || extendlen > 0); /*if concat checksumm swapped - swap it back */ if (concat_chksum_swapped) { concat_chksum = SWAP_BYTES_IN_WORD(concat_chksum); } tcp_seg_add_chksum(concat_chksum, concat_chksummed, &last_unsent->chksum, - &last_unsent->chksum_swapped); + &last_unsent->chksum_swapped); last_unsent->flags |= TF_SEG_DATA_CHECKSUMMED; } #endif /* TCP_CHECKSUM_ON_COPY */ @@ -763,14 +763,14 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) pcb->snd_queuelen = queuelen; LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_write: %"S16_F" (after enqueued)\n", - pcb->snd_queuelen)); + pcb->snd_queuelen)); if (pcb->snd_queuelen != 0) { LWIP_ASSERT("tcp_write: valid queue length", pcb->unacked != NULL || pcb->unsent != NULL); } /* Set the PSH flag in the last segment that we enqueued. */ - if (seg != NULL && seg->tcphdr != NULL && ((apiflags & TCP_WRITE_FLAG_MORE)==0)) { + if (seg != NULL && seg->tcphdr != NULL && ((apiflags & TCP_WRITE_FLAG_MORE) == 0)) { TCPH_SET_FLAG(seg->tcphdr, TCP_PSH); } @@ -787,7 +787,7 @@ memerr: } if (pcb->snd_queuelen != 0) { LWIP_ASSERT("tcp_write: valid queue length", pcb->unacked != NULL || - pcb->unsent != NULL); + pcb->unsent != NULL); } LWIP_DEBUGF(TCP_QLEN_DEBUG | LWIP_DBG_STATE, ("tcp_write: %"S16_F" (with mem err)\n", pcb->snd_queuelen)); return ERR_MEM; @@ -818,7 +818,7 @@ tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags) if (((pcb->snd_queuelen >= TCP_SND_QUEUELEN) || (pcb->snd_queuelen > TCP_SNDQUEUELEN_OVERFLOW)) && ((flags & TCP_FIN) == 0)) { LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("tcp_enqueue_flags: too long queue %"U16_F" (max %"U16_F")\n", - pcb->snd_queuelen, (u16_t)TCP_SND_QUEUELEN)); + pcb->snd_queuelen, (u16_t)TCP_SND_QUEUELEN)); TCP_STATS_INC(tcp.memerr); tcp_set_flags(pcb, TF_NAGLEMEMERR); return ERR_MEM; @@ -901,7 +901,7 @@ tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags) LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue_flags: %"S16_F" (after enqueued)\n", pcb->snd_queuelen)); if (pcb->snd_queuelen != 0) { LWIP_ASSERT("tcp_enqueue_flags: invalid queue length", - pcb->unacked != NULL || pcb->unsent != NULL); + pcb->unacked != NULL || pcb->unsent != NULL); } return ERR_OK; @@ -1071,12 +1071,12 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) #if CHECKSUM_GEN_TCP IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_TCP) { tcphdr->chksum = ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len, - &pcb->local_ip, &pcb->remote_ip); + &pcb->local_ip, &pcb->remote_ip); } #endif NETIF_SET_HINTS(netif, &(pcb->netif_hints)); err = ip_output_if(p, &pcb->local_ip, &pcb->remote_ip, - pcb->ttl, pcb->tos, IP_PROTO_TCP, netif); + pcb->ttl, pcb->tos, IP_PROTO_TCP, netif); NETIF_RESET_HINTS(netif); } pbuf_free(p); @@ -1113,7 +1113,7 @@ tcp_output(struct tcp_pcb *pcb) /* pcb->state LISTEN not allowed here */ LWIP_ASSERT("don't call tcp_output for listen-pcbs", - pcb->state != LISTEN); + pcb->state != LISTEN); /* First, check if we are invoked by the TCP input processing code. If so, we do not output anything. Instead, we rely on the @@ -1129,14 +1129,14 @@ tcp_output(struct tcp_pcb *pcb) if (seg == NULL) { LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: nothing to send (%p)\n", - (void*)pcb->unsent)); + (void *)pcb->unsent)); LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"TCPWNDSIZE_F ", cwnd %"TCPWNDSIZE_F", wnd %"U32_F ", seg == NULL, ack %"U32_F"\n", pcb->snd_wnd, pcb->cwnd, wnd, pcb->lastack)); - /* If the TF_ACK_NOW flag is set and the ->unsent queue is empty, construct - * an empty ACK segment and send it. */ + /* If the TF_ACK_NOW flag is set and the ->unsent queue is empty, construct + * an empty ACK segment and send it. */ if (pcb->flags & TF_ACK_NOW) { return tcp_send_empty_ack(pcb); } @@ -1167,12 +1167,12 @@ tcp_output(struct tcp_pcb *pcb) /* Handle the current segment not fitting within the window */ if (lwip_ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > wnd) { - /* We need to start the persistent timer when the next unsent segment does not fit - * within the remaining (could be 0) send window and RTO timer is not running (we - * have no in-flight data). If window is still too small after persist timer fires, - * then we split the segment. We don't consider the congestion window since a cwnd - * smaller than 1 SMSS implies in-flight data - */ + /* We need to start the persistent timer when the next unsent segment does not fit + * within the remaining (could be 0) send window and RTO timer is not running (we + * have no in-flight data). If window is still too small after persist timer fires, + * then we split the segment. We don't consider the congestion window since a cwnd + * smaller than 1 SMSS implies in-flight data + */ if (wnd == pcb->snd_wnd && pcb->unacked == NULL && pcb->persist_backoff == 0) { pcb->persist_cnt = 0; pcb->persist_backoff = 1; @@ -1186,7 +1186,7 @@ tcp_output(struct tcp_pcb *pcb) } /* Stop persist timer, above conditions are not active */ pcb->persist_backoff = 0; - + /* useg should point to last segment on unacked queue */ useg = pcb->unacked; if (useg != NULL) { @@ -1205,15 +1205,15 @@ tcp_output(struct tcp_pcb *pcb) * RST is no sent using tcp_write/tcp_output. */ if ((tcp_do_output_nagle(pcb) == 0) && - ((pcb->flags & (TF_NAGLEMEMERR | TF_FIN)) == 0)) { + ((pcb->flags & (TF_NAGLEMEMERR | TF_FIN)) == 0)) { break; } #if TCP_CWND_DEBUG LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"TCPWNDSIZE_F", cwnd %"TCPWNDSIZE_F", wnd %"U32_F", effwnd %"U32_F", seq %"U32_F", ack %"U32_F", i %"S16_F"\n", - pcb->snd_wnd, pcb->cwnd, wnd, - lwip_ntohl(seg->tcphdr->seqno) + seg->len - - pcb->lastack, - lwip_ntohl(seg->tcphdr->seqno), pcb->lastack, i)); + pcb->snd_wnd, pcb->cwnd, wnd, + lwip_ntohl(seg->tcphdr->seqno) + seg->len - + pcb->lastack, + lwip_ntohl(seg->tcphdr->seqno), pcb->lastack, i)); ++i; #endif /* TCP_CWND_DEBUG */ @@ -1245,7 +1245,7 @@ tcp_output(struct tcp_pcb *pcb) if (pcb->unacked == NULL) { pcb->unacked = seg; useg = seg; - /* unacked list is not empty? */ + /* unacked list is not empty? */ } else { /* In the case of fast retransmit, the packet should not go to the tail * of the unacked queue, but rather somewhere before it. We need to check for @@ -1254,8 +1254,8 @@ tcp_output(struct tcp_pcb *pcb) /* add segment to before tail of unacked list, keeping the list sorted */ struct tcp_seg **cur_seg = &(pcb->unacked); while (*cur_seg && - TCP_SEQ_LT(lwip_ntohl((*cur_seg)->tcphdr->seqno), lwip_ntohl(seg->tcphdr->seqno))) { - cur_seg = &((*cur_seg)->next ); + TCP_SEQ_LT(lwip_ntohl((*cur_seg)->tcphdr->seqno), lwip_ntohl(seg->tcphdr->seqno))) { + cur_seg = &((*cur_seg)->next ); } seg->next = (*cur_seg); (*cur_seg) = seg; @@ -1265,7 +1265,7 @@ tcp_output(struct tcp_pcb *pcb) useg = useg->next; } } - /* do not queue empty segments on the unacked list */ + /* do not queue empty segments on the unacked list */ } else { tcp_seg_free(seg); } @@ -1323,7 +1323,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif if (tcp_output_segment_busy(seg)) { /* This should not happen: rexmit functions should have checked this. However, since this function modifies p->len, we must not continue in this case. */ - LWIP_DEBUGF(TCP_RTO_DEBUG|LWIP_DBG_LEVEL_SERIOUS, ("tcp_output_segment: segment busy\n")); + LWIP_DEBUGF(TCP_RTO_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("tcp_output_segment: segment busy\n")); return ERR_OK; } @@ -1397,8 +1397,8 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_output_segment: rtseq %"U32_F"\n", pcb->rtseq)); } LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output_segment: %"U32_F":%"U32_F"\n", - lwip_htonl(seg->tcphdr->seqno), lwip_htonl(seg->tcphdr->seqno) + - seg->len)); + lwip_htonl(seg->tcphdr->seqno), lwip_htonl(seg->tcphdr->seqno) + + seg->len)); len = (u16_t)((u8_t *)seg->tcphdr - (u8_t *)seg->p->payload); if (len == 0) { @@ -1418,16 +1418,16 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif u32_t acc; #if TCP_CHECKSUM_ON_COPY_SANITY_CHECK u16_t chksum_slow = ip_chksum_pseudo(seg->p, IP_PROTO_TCP, - seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip); + seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip); #endif /* TCP_CHECKSUM_ON_COPY_SANITY_CHECK */ if ((seg->flags & TF_SEG_DATA_CHECKSUMMED) == 0) { LWIP_ASSERT("data included but not checksummed", - seg->p->tot_len == TCPH_HDRLEN_BYTES(seg->tcphdr)); + seg->p->tot_len == TCPH_HDRLEN_BYTES(seg->tcphdr)); } /* rebuild TCP header checksum (TCP header changes for retransmissions!) */ acc = ip_chksum_pseudo_partial(seg->p, IP_PROTO_TCP, - seg->p->tot_len, TCPH_HDRLEN_BYTES(seg->tcphdr), &pcb->local_ip, &pcb->remote_ip); + seg->p->tot_len, TCPH_HDRLEN_BYTES(seg->tcphdr), &pcb->local_ip, &pcb->remote_ip); /* add payload checksum */ if (seg->chksum_swapped) { seg->chksum = SWAP_BYTES_IN_WORD(seg->chksum); @@ -1438,14 +1438,14 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif #if TCP_CHECKSUM_ON_COPY_SANITY_CHECK if (chksum_slow != seg->tcphdr->chksum) { TCP_CHECKSUM_ON_COPY_SANITY_CHECK_FAIL( - ("tcp_output_segment: calculated checksum is %"X16_F" instead of %"X16_F"\n", - seg->tcphdr->chksum, chksum_slow)); + ("tcp_output_segment: calculated checksum is %"X16_F" instead of %"X16_F"\n", + seg->tcphdr->chksum, chksum_slow)); seg->tcphdr->chksum = chksum_slow; } #endif /* TCP_CHECKSUM_ON_COPY_SANITY_CHECK */ #else /* TCP_CHECKSUM_ON_COPY */ seg->tcphdr->chksum = ip_chksum_pseudo(seg->p, IP_PROTO_TCP, - seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip); + seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip); #endif /* TCP_CHECKSUM_ON_COPY */ } #endif /* CHECKSUM_GEN_TCP */ @@ -1453,7 +1453,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif NETIF_SET_HINTS(netif, &(pcb->netif_hints)); err = ip_output_if(seg->p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, - pcb->tos, IP_PROTO_TCP, netif); + pcb->tos, IP_PROTO_TCP, netif); NETIF_RESET_HINTS(netif); return err; } @@ -1481,8 +1481,8 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif */ void tcp_rst(const struct tcp_pcb *pcb, u32_t seqno, u32_t ackno, - const ip_addr_t *local_ip, const ip_addr_t *remote_ip, - u16_t local_port, u16_t remote_port) + const ip_addr_t *local_ip, const ip_addr_t *remote_ip, + u16_t local_port, u16_t remote_port) { struct pbuf *p; struct tcp_hdr *tcphdr; @@ -1500,7 +1500,7 @@ tcp_rst(const struct tcp_pcb *pcb, u32_t seqno, u32_t ackno, tcphdr->dest = lwip_htons(remote_port); tcphdr->seqno = lwip_htonl(seqno); tcphdr->ackno = lwip_htonl(ackno); - TCPH_HDRLEN_FLAGS_SET(tcphdr, TCP_HLEN/4, TCP_RST | TCP_ACK); + TCPH_HDRLEN_FLAGS_SET(tcphdr, TCP_HLEN / 4, TCP_RST | TCP_ACK); #if LWIP_WND_SCALE tcphdr->wnd = PP_HTONS(((TCP_WND >> TCP_RCV_SCALE) & 0xFFFF)); #else @@ -1645,8 +1645,8 @@ tcp_rexmit(struct tcp_pcb *pcb) cur_seg = &(pcb->unsent); while (*cur_seg && - TCP_SEQ_LT(lwip_ntohl((*cur_seg)->tcphdr->seqno), lwip_ntohl(seg->tcphdr->seqno))) { - cur_seg = &((*cur_seg)->next ); + TCP_SEQ_LT(lwip_ntohl((*cur_seg)->tcphdr->seqno), lwip_ntohl(seg->tcphdr->seqno))) { + cur_seg = &((*cur_seg)->next ); } seg->next = *cur_seg; *cur_seg = seg; @@ -1697,7 +1697,7 @@ tcp_rexmit_fast(struct tcp_pcb *pcb) LWIP_DEBUGF(TCP_FR_DEBUG, ("tcp_receive: The minimum value for ssthresh %"TCPWNDSIZE_F " should be min 2 mss %"U16_F"...\n", - pcb->ssthresh, (u16_t)(2*pcb->mss))); + pcb->ssthresh, (u16_t)(2 * pcb->mss))); pcb->ssthresh = 2 * pcb->mss; } @@ -1747,7 +1747,7 @@ tcp_keepalive(struct tcp_pcb *pcb) IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_TCP) { struct tcp_hdr *tcphdr = (struct tcp_hdr *)p->payload; tcphdr->chksum = ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len, - &pcb->local_ip, &pcb->remote_ip); + &pcb->local_ip, &pcb->remote_ip); } #endif /* CHECKSUM_GEN_TCP */ TCP_STATS_INC(tcp.xmit); @@ -1828,22 +1828,22 @@ tcp_split_unsent_seg(struct tcp_pcb *pcb, u16_t split) p = pbuf_alloc(PBUF_TRANSPORT, remainder + optlen, PBUF_RAM); if (p == NULL) { LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS, - ("tcp_split_unsent_seg: could not allocate memory for pbuf remainder %u\n", remainder)); + ("tcp_split_unsent_seg: could not allocate memory for pbuf remainder %u\n", remainder)); goto memerr; } /* Offset into the original pbuf is past TCP/IP headers, options, and split amount */ offset = useg->p->tot_len - useg->len + split; /* Copy remainder into new pbuf, headers and options will not be filled out */ - if (pbuf_copy_partial(useg->p, (u8_t*)p->payload + optlen, remainder, offset ) != remainder) { + if (pbuf_copy_partial(useg->p, (u8_t *)p->payload + optlen, remainder, offset ) != remainder) { LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS, - ("tcp_split_unsent_seg: could not copy pbuf remainder %u\n", remainder)); + ("tcp_split_unsent_seg: could not copy pbuf remainder %u\n", remainder)); goto memerr; } #if TCP_CHECKSUM_ON_COPY /* calculate the checksum on remainder data */ - tcp_seg_add_chksum(~inet_chksum((const u8_t*)p->payload + optlen, remainder), remainder, - &chksum, &chksum_swapped); + tcp_seg_add_chksum(~inet_chksum((const u8_t *)p->payload + optlen, remainder), remainder, + &chksum, &chksum_swapped); #endif /* TCP_CHECKSUM_ON_COPY */ /* Options are created when calling tcp_output() */ @@ -1865,7 +1865,7 @@ tcp_split_unsent_seg(struct tcp_pcb *pcb, u16_t split) seg = tcp_create_segment(pcb, p, remainder_flags, lwip_ntohl(useg->tcphdr->seqno) + split, optflags); if (seg == NULL) { LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS, - ("tcp_split_unsent_seg: could not create new TCP segment\n")); + ("tcp_split_unsent_seg: could not create new TCP segment\n")); goto memerr; } @@ -1896,8 +1896,8 @@ tcp_split_unsent_seg(struct tcp_pcb *pcb, u16_t split) LWIP_ASSERT("Found start of payload pbuf", q != NULL); /* Checksum the first payload pbuf accounting for offset, then other pbufs are all payload */ for (; q != NULL; offset = 0, q = q->next) { - tcp_seg_add_chksum(~inet_chksum((const u8_t*)q->payload + offset, q->len - offset), q->len - offset, - &useg->chksum, &useg->chksum_swapped); + tcp_seg_add_chksum(~inet_chksum((const u8_t *)q->payload + offset, q->len - offset), q->len - offset, + &useg->chksum, &useg->chksum_swapped); } #endif /* TCP_CHECKSUM_ON_COPY */ @@ -2004,7 +2004,7 @@ tcp_zero_window_probe(struct tcp_pcb *pcb) #if CHECKSUM_GEN_TCP IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_TCP) { tcphdr->chksum = ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len, - &pcb->local_ip, &pcb->remote_ip); + &pcb->local_ip, &pcb->remote_ip); } #endif TCP_STATS_INC(tcp.xmit); @@ -2012,7 +2012,7 @@ tcp_zero_window_probe(struct tcp_pcb *pcb) /* Send output to IP */ NETIF_SET_HINTS(netif, &(pcb->netif_hints)); err = ip_output_if(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, - 0, IP_PROTO_TCP, netif); + 0, IP_PROTO_TCP, netif); NETIF_RESET_HINTS(netif); } diff --git a/src/core/timeouts.c b/src/core/timeouts.c index 28f8d0f5..1290661d 100644 --- a/src/core/timeouts.c +++ b/src/core/timeouts.c @@ -164,7 +164,7 @@ tcp_timer_needed(void) static void cyclic_timer(void *arg) { - const struct lwip_cyclic_timer* cyclic = (const struct lwip_cyclic_timer*)arg; + const struct lwip_cyclic_timer *cyclic = (const struct lwip_cyclic_timer *)arg; #if LWIP_DEBUG_TIMERNAMES LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: %s()\n", cyclic->handler_name)); #endif @@ -180,7 +180,7 @@ void sys_timeouts_init(void) for (i = (LWIP_TCP ? 1 : 0); i < LWIP_ARRAYSIZE(lwip_cyclic_timers); i++) { /* we have to cast via size_t to get rid of const warning (this is OK as cyclic_timer() casts back to const* */ - sys_timeout(lwip_cyclic_timers[i].interval_ms, cyclic_timer, LWIP_CONST_CAST(void*, &lwip_cyclic_timers[i])); + sys_timeout(lwip_cyclic_timers[i].interval_ms, cyclic_timer, LWIP_CONST_CAST(void *, &lwip_cyclic_timers[i])); } /* Initialise timestamp for sys_check_timeouts */ @@ -199,7 +199,7 @@ void sys_timeouts_init(void) */ #if LWIP_DEBUG_TIMERNAMES void -sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char* handler_name) +sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char *handler_name) #else /* LWIP_DEBUG_TIMERNAMES */ void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg) @@ -229,7 +229,7 @@ sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg) #if LWIP_DEBUG_TIMERNAMES timeout->handler_name = handler_name; LWIP_DEBUGF(TIMERS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" handler=%s arg=%p\n", - (void *)timeout, msecs, handler_name, (void *)arg)); + (void *)timeout, msecs, handler_name, (void *)arg)); #endif /* LWIP_DEBUG_TIMERNAMES */ if (next_timeout == NULL) { @@ -339,7 +339,7 @@ sys_check_timeouts(void) #if LWIP_DEBUG_TIMERNAMES if (handler != NULL) { LWIP_DEBUGF(TIMERS_DEBUG, ("sct calling h=%s arg=%p\n", - tmptimeout->handler_name, arg)); + tmptimeout->handler_name, arg)); } #endif /* LWIP_DEBUG_TIMERNAMES */ memp_free(MEMP_SYS_TIMEOUT, tmptimeout); @@ -356,7 +356,7 @@ sys_check_timeouts(void) } LWIP_TCPIP_THREAD_ALIVE(); } - /* repeat until all expired timers have been called */ + /* repeat until all expired timers have been called */ } while (had_one); } } diff --git a/src/core/udp.c b/src/core/udp.c index d2d80d37..e255735f 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -3,7 +3,7 @@ * User Datagram Protocol module\n * The code for the User Datagram Protocol UDP & UDPLite (RFC 3828).\n * See also @ref udp_raw - * + * * @defgroup udp_raw UDP * @ingroup callbackstyle_api * User Datagram Protocol module\n @@ -137,7 +137,7 @@ udp_input_local_match(struct udp_pcb *pcb, struct netif *inp, u8_t broadcast) (pcb->netif_idx != netif_get_index(ip_data.current_input_netif))) { return 0; } - + /* Dual-stack: PCBs listening to any IP type also listen to any IP address */ if (IP_IS_ANY_TYPE_VAL(pcb->local_ip)) { #if LWIP_IPV4 && IP_SOF_BROADCAST_RECV @@ -159,17 +159,17 @@ udp_input_local_match(struct udp_pcb *pcb, struct netif *inp, u8_t broadcast) #endif /* IP_SOF_BROADCAST_RECV */ { if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip)) || - ((ip4_current_dest_addr()->addr == IPADDR_BROADCAST)) || - ip4_addr_netcmp(ip_2_ip4(&pcb->local_ip), ip4_current_dest_addr(), netif_ip4_netmask(inp))) { + ((ip4_current_dest_addr()->addr == IPADDR_BROADCAST)) || + ip4_addr_netcmp(ip_2_ip4(&pcb->local_ip), ip4_current_dest_addr(), netif_ip4_netmask(inp))) { return 1; } } } else #endif /* LWIP_IPV4 */ - /* Handle IPv4 and IPv6: all or exact match */ - if (ip_addr_isany(&pcb->local_ip) || ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) { - return 1; - } + /* Handle IPv4 and IPv6: all or exact match */ + if (ip_addr_isany(&pcb->local_ip) || ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) { + return 1; + } } return 0; @@ -256,8 +256,8 @@ udp_input(struct pbuf *p, struct netif *inp) if (((pcb->flags & UDP_FLAGS_CONNECTED) == 0) && ((uncon_pcb == NULL) #if SO_REUSE - /* prefer specific IPs over cath-all */ - || !ip_addr_isany(&pcb->local_ip) + /* prefer specific IPs over cath-all */ + || !ip_addr_isany(&pcb->local_ip) #endif /* SO_REUSE */ )) { /* the first unconnected matching PCB */ @@ -267,7 +267,7 @@ udp_input(struct pbuf *p, struct netif *inp) /* compare PCB remote addr+port to UDP source addr+port */ if ((pcb->remote_port == src) && (ip_addr_isany_val(pcb->remote_ip) || - ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()))) { + ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()))) { /* the first fully matching PCB */ if (prev != NULL) { /* move the pcb to the front of udp_pcbs so that is @@ -325,8 +325,8 @@ udp_input(struct pbuf *p, struct netif *inp) } } if (ip_chksum_pseudo_partial(p, IP_PROTO_UDPLITE, - p->tot_len, chklen, - ip_current_src_addr(), ip_current_dest_addr()) != 0) { + p->tot_len, chklen, + ip_current_src_addr(), ip_current_dest_addr()) != 0) { goto chkerr; } } else @@ -466,7 +466,7 @@ udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p, /* send to the packet using remote ip and port stored in the pcb */ return udp_sendto_chksum(pcb, p, &pcb->remote_ip, pcb->remote_port, - have_chksum, chksum); + have_chksum, chksum); } #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */ @@ -490,7 +490,7 @@ udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p, */ err_t udp_sendto(struct udp_pcb *pcb, struct pbuf *p, - const ip_addr_t *dst_ip, u16_t dst_port) + const ip_addr_t *dst_ip, u16_t dst_port) { #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0); @@ -529,19 +529,19 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, #if LWIP_IPV4 else #if LWIP_IPV6 - if (IP_IS_V4(dst_ip)) + if (IP_IS_V4(dst_ip)) #endif /* LWIP_IPV6 */ - { - /* IPv4 does not use source-based routing by default, so we use an - administratively selected interface for multicast by default. - However, this can be overridden by setting an interface address - in pcb->mcast_ip4 that is used for routing. If this routing lookup - fails, we try regular routing as though no override was set. */ - if (!ip4_addr_isany_val(pcb->mcast_ip4) && - !ip4_addr_cmp(&pcb->mcast_ip4, IP4_ADDR_BROADCAST)) { - netif = ip4_route_src(ip_2_ip4(&pcb->local_ip), &pcb->mcast_ip4); + { + /* IPv4 does not use source-based routing by default, so we use an + administratively selected interface for multicast by default. + However, this can be overridden by setting an interface address + in pcb->mcast_ip4 that is used for routing. If this routing lookup + fails, we try regular routing as though no override was set. */ + if (!ip4_addr_isany_val(pcb->mcast_ip4) && + !ip4_addr_cmp(&pcb->mcast_ip4, IP4_ADDR_BROADCAST)) { + netif = ip4_route_src(ip_2_ip4(&pcb->local_ip), &pcb->mcast_ip4); + } } - } #endif /* LWIP_IPV4 */ } @@ -590,7 +590,7 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, */ err_t udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p, - const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif) + const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif) { #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0); @@ -633,21 +633,21 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_i else #endif /* LWIP_IPV4 && LWIP_IPV6 */ #if LWIP_IPV4 - if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip)) || - ip4_addr_ismulticast(ip_2_ip4(&pcb->local_ip))) { - /* if the local_ip is any or multicast - * use the outgoing network interface IP address as source address */ - src_ip = netif_ip_addr4(netif); - } else { - /* check if UDP PCB local IP address is correct - * this could be an old address if netif->ip_addr has changed */ - if (!ip4_addr_cmp(ip_2_ip4(&(pcb->local_ip)), netif_ip4_addr(netif))) { - /* local_ip doesn't match, drop the packet */ - return ERR_RTE; + if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip)) || + ip4_addr_ismulticast(ip_2_ip4(&pcb->local_ip))) { + /* if the local_ip is any or multicast + * use the outgoing network interface IP address as source address */ + src_ip = netif_ip_addr4(netif); + } else { + /* check if UDP PCB local IP address is correct + * this could be an old address if netif->ip_addr has changed */ + if (!ip4_addr_cmp(ip_2_ip4(&(pcb->local_ip)), netif_ip4_addr(netif))) { + /* local_ip doesn't match, drop the packet */ + return ERR_RTE; + } + /* use UDP PCB local IP address as source address */ + src_ip = &pcb->local_ip; } - /* use UDP PCB local IP address as source address */ - src_ip = &pcb->local_ip; - } #endif /* LWIP_IPV4 */ #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum, src_ip); @@ -660,7 +660,7 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_i * Same as @ref udp_sendto_if, but with source address */ err_t udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p, - const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif, const ip_addr_t *src_ip) + const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif, const ip_addr_t *src_ip) { #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0, src_ip); @@ -669,8 +669,8 @@ udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p, /** Same as udp_sendto_if_src(), but with checksum */ err_t udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, - u16_t dst_port, struct netif *netif, u8_t have_chksum, - u16_t chksum, const ip_addr_t *src_ip) + u16_t dst_port, struct netif *netif, u8_t have_chksum, + u16_t chksum, const ip_addr_t *src_ip) { #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */ struct udp_hdr *udphdr; @@ -692,7 +692,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d #endif /* LWIP_IPV6 */ ip_addr_isbroadcast(dst_ip, netif)) { LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, - ("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb)); + ("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb)); return ERR_VAL; } #endif /* LWIP_IPV4 && IP_SOF_BROADCAST */ @@ -781,7 +781,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d } #endif /* LWIP_CHECKSUM_ON_COPY */ udphdr->chksum = ip_chksum_pseudo_partial(q, IP_PROTO_UDPLITE, - q->tot_len, chklen, src_ip, dst_ip); + q->tot_len, chklen, src_ip, dst_ip); #if LWIP_CHECKSUM_ON_COPY if (have_chksum) { u32_t acc; @@ -813,14 +813,14 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d if (have_chksum) { u32_t acc; udpchksum = ip_chksum_pseudo_partial(q, IP_PROTO_UDP, - q->tot_len, UDP_HLEN, src_ip, dst_ip); + q->tot_len, UDP_HLEN, src_ip, dst_ip); acc = udpchksum + (u16_t)~(chksum); udpchksum = FOLD_U32T(acc); } else #endif /* LWIP_CHECKSUM_ON_COPY */ { udpchksum = ip_chksum_pseudo(q, IP_PROTO_UDP, q->tot_len, - src_ip, dst_ip); + src_ip, dst_ip); } /* chksum zero must become 0xffff, as zero means 'no checksum' */ @@ -941,9 +941,9 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) } else { for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) { if (pcb != ipcb) { - /* By default, we don't allow to bind to a port that any other udp - PCB is already bound to, unless *all* PCBs with that port have tha - REUSEADDR flag set. */ + /* By default, we don't allow to bind to a port that any other udp + PCB is already bound to, unless *all* PCBs with that port have tha + REUSEADDR flag set. */ #if SO_REUSE if (!ip_get_option(pcb, SOF_REUSEADDR) || !ip_get_option(ipcb, SOF_REUSEADDR)) @@ -1050,7 +1050,7 @@ udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_connect: connected to ")); ip_addr_debug_print_val(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, - pcb->remote_ip); + pcb->remote_ip); LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->remote_port)); /* Insert UDP PCB into the list of active UDP PCBs. */ @@ -1204,9 +1204,9 @@ udp_new_ip_type(u8_t type) * @param old_addr IP address of the netif before change * @param new_addr IP address of the netif after change */ -void udp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr) +void udp_netif_ip_addr_changed(const ip_addr_t *old_addr, const ip_addr_t *new_addr) { - struct udp_pcb* upcb; + struct udp_pcb *upcb; if (!ip_addr_isany(old_addr) && !ip_addr_isany(new_addr)) { for (upcb = udp_pcbs; upcb != NULL; upcb = upcb->next) {