From 21a4b68fece384f9e865e56f464831b15780ac0c Mon Sep 17 00:00:00 2001 From: jani Date: Tue, 28 Oct 2003 11:44:43 +0000 Subject: [PATCH] Use #if not #ifdef for all STATS options. They are turned on off by defining them to 1 or 0. Make use of XXX_STATS_INC macros for udp, ip, tcp, ip_frag, link and icmp. Add IPFRAG_STATS option --- src/core/ipv4/icmp.c | 38 +++++++------------------- src/core/ipv4/ip.c | 59 +++++++++++++--------------------------- src/core/ipv4/ip_frag.c | 24 ++++------------ src/core/mem.c | 12 ++++---- src/core/memp.c | 8 +++--- src/core/pbuf.c | 14 +++++----- src/core/raw.c | 2 +- src/core/tcp_in.c | 27 ++++++------------ src/core/tcp_out.c | 20 ++++---------- src/core/udp.c | 40 ++++++++------------------- src/include/lwip/opt.h | 17 ++++++++++++ src/include/lwip/stats.h | 40 +++++++++++++++++++++++++++ src/netif/etharp.c | 4 +-- src/netif/ppp/ppp.c | 36 ++++++++++++------------ src/netif/ppp/vj.c | 31 ++++++++++++++++++++- src/netif/ppp/vj.h | 4 +-- src/netif/slipif.c | 8 ++---- 17 files changed, 188 insertions(+), 196 deletions(-) diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c index bd6876d0..767326da 100644 --- a/src/core/ipv4/icmp.c +++ b/src/core/ipv4/icmp.c @@ -54,9 +54,7 @@ icmp_input(struct pbuf *p, struct netif *inp) struct ip_addr tmpaddr; u16_t hlen; -#ifdef ICMP_STATS - ++lwip_stats.icmp.recv; -#endif /* ICMP_STATS */ + ICMP_STATS_INC(icmp.recv); snmp_inc_icmpinmsgs(); @@ -65,9 +63,7 @@ icmp_input(struct pbuf *p, struct netif *inp) if (pbuf_header(p, -((s16_t)hlen)) || (p->tot_len < sizeof(u16_t)*2)) { LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: short ICMP (%u bytes) received\n", p->tot_len)); pbuf_free(p); -#ifdef ICMP_STATS - ++lwip_stats.icmp.lenerr; -#endif /* ICMP_STATS */ + ICMP_STATS_INC(icmp.lenerr); snmp_inc_icmpinerrors(); return; } @@ -79,9 +75,7 @@ icmp_input(struct pbuf *p, struct netif *inp) if (ip_addr_isbroadcast(&iphdr->dest, &inp->netmask) || ip_addr_ismulticast(&iphdr->dest)) { LWIP_DEBUGF(ICMP_DEBUG, ("Smurf.\n")); -#ifdef ICMP_STATS - ++lwip_stats.icmp.err; -#endif /* ICMP_STATS */ + ICMP_STATS_INC(icmp.err); pbuf_free(p); return; } @@ -90,9 +84,7 @@ icmp_input(struct pbuf *p, struct netif *inp) if (p->tot_len < sizeof(struct icmp_echo_hdr)) { LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n")); pbuf_free(p); -#ifdef ICMP_STATS - ++lwip_stats.icmp.lenerr; -#endif /* ICMP_STATS */ + ICMP_STATS_INC(icmp.lenerr); snmp_inc_icmpinerrors(); return; @@ -101,9 +93,7 @@ icmp_input(struct pbuf *p, struct netif *inp) if (inet_chksum_pbuf(p) != 0) { LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo\n")); pbuf_free(p); -#ifdef ICMP_STATS - ++lwip_stats.icmp.chkerr; -#endif /* ICMP_STATS */ + ICMP_STATS_INC(icmp.chkerr); snmp_inc_icmpinerrors(); return; } @@ -117,9 +107,7 @@ icmp_input(struct pbuf *p, struct netif *inp) } else { iecho->chksum += htons(ICMP_ECHO << 8); } -#ifdef ICMP_STATS - ++lwip_stats.icmp.xmit; -#endif /* ICMP_STATS */ + ICMP_STATS_INC(icmp.xmit); /* increase number of messages attempted to send */ snmp_inc_icmpoutmsgs(); /* increase number of echo replies attempted to send */ @@ -131,10 +119,8 @@ icmp_input(struct pbuf *p, struct netif *inp) break; default: LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type %d code %d not supported.\n", (int)type, (int)code)); -#ifdef ICMP_STATS - ++lwip_stats.icmp.proterr; - ++lwip_stats.icmp.drop; -#endif /* ICMP_STATS */ + ICMP_STATS_INC(icmp.proterr); + ICMP_STATS_INC(icmp.drop); } pbuf_free(p); } @@ -160,9 +146,7 @@ icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t) /* calculate checksum */ idur->chksum = 0; idur->chksum = inet_chksum(idur, q->len); -#ifdef ICMP_STATS - ++lwip_stats.icmp.xmit; -#endif /* ICMP_STATS */ + ICMP_STATS_INC(icmp.xmit); /* increase number of messages attempted to send */ snmp_inc_icmpoutmsgs(); /* increase number of destination unreachable messages attempted to send */ @@ -202,9 +186,7 @@ icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t) /* calculate checksum */ tehdr->chksum = 0; tehdr->chksum = inet_chksum(tehdr, q->len); -#ifdef ICMP_STATS - ++lwip_stats.icmp.xmit; -#endif /* ICMP_STATS */ + ICMP_STATS_INC(icmp.xmit); /* increase number of messages attempted to send */ snmp_inc_icmpoutmsgs(); /* increase number of destination unreachable messages attempted to send */ diff --git a/src/core/ipv4/ip.c b/src/core/ipv4/ip.c index 97c5e186..a9061d91 100644 --- a/src/core/ipv4/ip.c +++ b/src/core/ipv4/ip.c @@ -201,10 +201,8 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) LWIP_DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to 0x%lx\n", iphdr->dest.addr)); -#ifdef IP_STATS - ++lwip_stats.ip.fw; - ++lwip_stats.ip.xmit; -#endif /* IP_STATS */ + IP_STATS_INC(ip.fw); + IP_STATS_INC(ip.xmit); snmp_inc_ipforwdatagrams(); PERF_STOP("ip_forward"); @@ -230,9 +228,7 @@ ip_input(struct pbuf *p, struct netif *inp) { static struct netif *netif; static u16_t iphdrlen; -#ifdef IP_STATS - ++lwip_stats.ip.recv; -#endif /* IP_STATS */ + IP_STATS_INC(ip.recv); snmp_inc_ipinreceives(); /* identify the IP header */ @@ -243,10 +239,8 @@ ip_input(struct pbuf *p, struct netif *inp) { ip_debug_print(p); #endif /* IP_DEBUG */ pbuf_free(p); -#ifdef IP_STATS - ++lwip_stats.ip.err; - ++lwip_stats.ip.drop; -#endif /* IP_STATS */ + IP_STATS_INC(ip.err); + IP_STATS_INC(ip.drop); snmp_inc_ipunknownprotos(); return ERR_OK; } @@ -261,10 +255,8 @@ ip_input(struct pbuf *p, struct netif *inp) { iphdrlen, p->len)); /* free (drop) packet pbufs */ pbuf_free(p); -#ifdef IP_STATS - ++lwip_stats.ip.lenerr; - ++lwip_stats.ip.drop; -#endif /* IP_STATS */ + IP_STATS_INC(ip.lenerr); + IP_STATS_INC(ip.drop); snmp_inc_ipindiscards(); return ERR_OK; } @@ -277,10 +269,8 @@ ip_input(struct pbuf *p, struct netif *inp) { ip_debug_print(p); #endif /* IP_DEBUG */ pbuf_free(p); -#ifdef IP_STATS - ++lwip_stats.ip.chkerr; - ++lwip_stats.ip.drop; -#endif /* IP_STATS */ + IP_STATS_INC(ip.chkerr); + IP_STATS_INC(ip.drop); snmp_inc_ipindiscards(); return ERR_OK; } @@ -365,10 +355,8 @@ ip_input(struct pbuf *p, struct netif *inp) { pbuf_free(p); LWIP_DEBUGF(IP_DEBUG | 2, ("IP packet dropped since it was fragmented (0x%x) (while IP_REASSEMBLY == 0).\n", ntohs(IPH_OFFSET(iphdr)))); -#ifdef IP_STATS - ++lwip_stats.ip.opterr; - ++lwip_stats.ip.drop; -#endif /* IP_STATS */ + IP_STATS_INC(ip.opterr); + IP_STATS_INC(ip.drop); snmp_inc_ipunknownprotos(); return ERR_OK; } @@ -378,10 +366,8 @@ ip_input(struct pbuf *p, struct netif *inp) { if (iphdrlen > IP_HLEN) { LWIP_DEBUGF(IP_DEBUG | 2, ("IP packet dropped since there were IP options (while IP_OPTIONS == 0).\n")); pbuf_free(p); -#ifdef IP_STATS - ++lwip_stats.ip.opterr; - ++lwip_stats.ip.drop; -#endif /* IP_STATS */ + IP_STATS_INC(ip.opterr); + IP_STATS_INC(ip.drop); snmp_inc_ipunknownprotos(); return ERR_OK; } @@ -427,10 +413,8 @@ ip_input(struct pbuf *p, struct netif *inp) { LWIP_DEBUGF(IP_DEBUG | 2, ("Unsupported transport protocol %d\n", IPH_PROTO(iphdr))); -#ifdef IP_STATS - ++lwip_stats.ip.proterr; - ++lwip_stats.ip.drop; -#endif /* IP_STATS */ + IP_STATS_INC(ip.proterr); + IP_STATS_INC(ip.drop); snmp_inc_ipunknownprotos(); } @@ -463,9 +447,7 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, if (pbuf_header(p, IP_HLEN)) { LWIP_DEBUGF(IP_DEBUG | 2, ("ip_output: not enough room for IP header in pbuf\n")); -#ifdef IP_STATS - ++lwip_stats.ip.err; -#endif /* IP_STATS */ + IP_STATS_INC(ip.err); snmp_inc_ipoutdiscards(); return ERR_BUF; } @@ -502,9 +484,8 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, return ip_frag(p,netif,dest); #endif -#ifdef IP_STATS - lwip_stats.ip.xmit++; -#endif /* IP_STATS */ + IP_STATS_INC(ip.xmit); + LWIP_DEBUGF(IP_DEBUG, ("ip_output_if: %c%c%u\n", netif->name[0], netif->name[1], netif->num)); #if IP_DEBUG ip_debug_print(p); @@ -530,9 +511,7 @@ ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, if ((netif = ip_route(dest)) == NULL) { LWIP_DEBUGF(IP_DEBUG | 2, ("ip_output: No route to 0x%lx\n", dest->addr)); -#ifdef IP_STATS - ++lwip_stats.ip.rterr; -#endif /* IP_STATS */ + IP_STATS_INC(ip.rterr); snmp_inc_ipoutdiscards(); return ERR_RTE; } diff --git a/src/core/ipv4/ip_frag.c b/src/core/ipv4/ip_frag.c index 8f0b7299..279e6821 100644 --- a/src/core/ipv4/ip_frag.c +++ b/src/core/ipv4/ip_frag.c @@ -109,9 +109,7 @@ ip_reass(struct pbuf *p) u16_t offset, len; u16_t i; -#ifdef IP_STATS - ++lwip_stats.ip_frag.recv; -#endif /* IP_STATS */ + IPFRAG_STATS_INC(ip_frag.recv); iphdr = (struct ip_hdr *) ip_reassbuf; fraghdr = (struct ip_hdr *) p->payload; @@ -135,9 +133,7 @@ ip_reass(struct pbuf *p) ip_addr_cmp(&iphdr->dest, &fraghdr->dest) && IPH_ID(iphdr) == IPH_ID(fraghdr)) { LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: matching old packet\n")); -#ifdef IP_STATS - ++lwip_stats.ip_frag.cachehit; -#endif /* IP_STATS */ + IPFRAG_STATS_INC(ip_frag.cachehit); /* Find out the offset in the reassembly buffer where we should copy the fragment. */ len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4; @@ -255,13 +251,9 @@ ip_reass(struct pbuf *p) q->len > ip_reasslen - i ? ip_reasslen - i : q->len); i += q->len; } -#ifdef IP_STATS - ++lwip_stats.ip_frag.fw; -#endif /* IP_STATS */ + IPFRAG_STATS_INC(ip_frag.fw); } else { -#ifdef IP_STATS - ++lwip_stats.ip_frag.memerr; -#endif /* IP_STATS */ + IPFRAG_STATS_INC(ip_frag.memerr); } LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: p %p\n", (void*)p)); return p; @@ -269,9 +261,7 @@ ip_reass(struct pbuf *p) } nullreturn: -#ifdef IP_STATS - ++lwip_stats.ip_frag.drop; -#endif /* IP_STATS */ + IPFRAG_STATS_INC(ip_frag.drop); pbuf_free(p); return NULL; } @@ -347,9 +337,7 @@ ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest) header = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM); pbuf_chain(header, rambuf); netif->output(netif, header, dest); -#ifdef IP_STATS - ++lwip_stats.ip_frag.xmit; -#endif /* IP_STATS */ + IPFRAG_STATS_INC(ip_frag.xmit); pbuf_free(header); left -= cop; diff --git a/src/core/mem.c b/src/core/mem.c index 3a8a3f54..32533415 100644 --- a/src/core/mem.c +++ b/src/core/mem.c @@ -127,7 +127,7 @@ mem_init(void) lfree = (struct mem *)ram; -#ifdef MEM_STATS +#if MEM_STATS lwip_stats.mem.avail = MEM_SIZE; #endif /* MEM_STATS */ } @@ -148,7 +148,7 @@ mem_free(void *rmem) if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) { LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_free: illegal memory\n")); -#ifdef MEM_STATS +#if MEM_STATS ++lwip_stats.mem.err; #endif /* MEM_STATS */ sys_sem_signal(mem_sem); @@ -164,7 +164,7 @@ mem_free(void *rmem) lfree = mem; } -#ifdef MEM_STATS +#if MEM_STATS lwip_stats.mem.used -= mem->next - ((u8_t *)mem - ram); #endif /* MEM_STATS */ @@ -215,7 +215,7 @@ mem_realloc(void *rmem, mem_size_t newsize) ptr = (u8_t *)mem - ram; size = mem->next - ptr - SIZEOF_STRUCT_MEM; -#ifdef MEM_STATS +#if MEM_STATS lwip_stats.mem.used -= (size - newsize); #endif /* MEM_STATS */ @@ -273,7 +273,7 @@ mem_malloc(mem_size_t size) mem2->used = 0; mem->used = 1; -#ifdef MEM_STATS +#if MEM_STATS lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM); /* if (lwip_stats.mem.max < lwip_stats.mem.used) { lwip_stats.mem.max = lwip_stats.mem.used; @@ -299,7 +299,7 @@ mem_malloc(mem_size_t size) } } LWIP_DEBUGF(MEM_DEBUG | 2, ("mem_malloc: could not allocate %d bytes\n", (int)size)); -#ifdef MEM_STATS +#if MEM_STATS ++lwip_stats.mem.err; #endif /* MEM_STATS */ sys_sem_signal(mem_sem); diff --git a/src/core/memp.c b/src/core/memp.c index 2ec1241a..5d13d4ae 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -149,7 +149,7 @@ memp_init(void) u16_t i, j; u16_t size; -#ifdef MEMP_STATS +#if MEMP_STATS for(i = 0; i < MEMP_MAX; ++i) { lwip_stats.memp[i].used = lwip_stats.memp[i].max = lwip_stats.memp[i].err = 0; @@ -205,7 +205,7 @@ memp_malloc(memp_t type) if (memp != NULL) { memp_tab[type] = memp->next; memp->next = NULL; -#ifdef MEMP_STATS +#if MEMP_STATS ++lwip_stats.memp[type].used; if (lwip_stats.memp[type].used > lwip_stats.memp[type].max) { lwip_stats.memp[type].max = lwip_stats.memp[type].used; @@ -225,7 +225,7 @@ memp_malloc(memp_t type) return mem; } else { LWIP_DEBUGF(MEMP_DEBUG | 2, ("memp_malloc: out of memory in pool %d\n", type)); -#ifdef MEMP_STATS +#if MEMP_STATS ++lwip_stats.memp[type].err; #endif /* MEMP_STATS */ #if SYS_LIGHTWEIGHT_PROT @@ -256,7 +256,7 @@ memp_free(memp_t type, void *mem) sys_sem_wait(mutex); #endif /* SYS_LIGHTWEIGHT_PROT */ -#ifdef MEMP_STATS +#if MEMP_STATS lwip_stats.memp[type].used--; #endif /* MEMP_STATS */ diff --git a/src/core/pbuf.c b/src/core/pbuf.c index ad5bb6d0..b596b3d7 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -102,7 +102,7 @@ pbuf_init(void) pbuf_pool = (struct pbuf *)&pbuf_pool_memory[0]; LWIP_ASSERT("pbuf_init: pool aligned", (long)pbuf_pool % MEM_ALIGNMENT == 0); -#ifdef PBUF_STATS +#if PBUF_STATS lwip_stats.pbuf.avail = PBUF_POOL_SIZE; #endif /* PBUF_STATS */ @@ -144,7 +144,7 @@ pbuf_pool_alloc(void) /* Next, check the actual pbuf pool, but if the pool is locked, we pretend to be out of buffers and return NULL. */ if (pbuf_pool_free_lock) { -#ifdef PBUF_STATS +#if PBUF_STATS ++lwip_stats.pbuf.alloc_locked; #endif /* PBUF_STATS */ return NULL; @@ -157,7 +157,7 @@ pbuf_pool_alloc(void) pbuf_pool = p->next; } #if !SYS_LIGHTWEIGHT_PROT -#ifdef PBUF_STATS +#if PBUF_STATS } else { ++lwip_stats.pbuf.alloc_locked; #endif /* PBUF_STATS */ @@ -165,7 +165,7 @@ pbuf_pool_alloc(void) pbuf_pool_alloc_lock = 0; #endif /* SYS_LIGHTWEIGHT_PROT */ -#ifdef PBUF_STATS +#if PBUF_STATS if (p != NULL) { ++lwip_stats.pbuf.used; if (lwip_stats.pbuf.used > lwip_stats.pbuf.max) { @@ -244,7 +244,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag) p = pbuf_pool_alloc(); LWIP_DEBUGF(PBUF_DEBUG | DBG_TRACE | 3, ("pbuf_alloc: allocated pbuf %p\n", (void *)p)); if (p == NULL) { -#ifdef PBUF_STATS +#if PBUF_STATS ++lwip_stats.pbuf.err; #endif /* PBUF_STATS */ return NULL; @@ -273,7 +273,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag) q = pbuf_pool_alloc(); if (q == NULL) { LWIP_DEBUGF(PBUF_DEBUG | 2, ("pbuf_alloc: Out of pbufs in pool.\n")); -#ifdef PBUF_STATS +#if PBUF_STATS ++lwip_stats.pbuf.err; #endif /* PBUF_STATS */ /* free chain so far allocated */ @@ -343,7 +343,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag) } -#ifdef PBUF_STATS +#if PBUF_STATS #define DEC_PBUF_STATS do { --lwip_stats.pbuf.used; } while (0) #else /* PBUF_STATS */ #define DEC_PBUF_STATS diff --git a/src/core/raw.c b/src/core/raw.c index 54d8486b..c39a263e 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -209,7 +209,7 @@ raw_send_to(struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *ipaddr) if ((netif = ip_route(ipaddr)) == NULL) { LWIP_DEBUGF(RAW_DEBUG | 1, ("raw_send_to: No route to 0x%lx\n", ipaddr->addr)); -#ifdef RAW_STATS +#if RAW_STATS /* ++lwip_stats.raw.rterr;*/ #endif /* RAW_STATS */ if (q != p) { diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index e6913de7..741e6156 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -110,10 +110,7 @@ tcp_input(struct pbuf *p, struct netif *inp) PERF_START; - -#ifdef TCP_STATS - ++lwip_stats.tcp.recv; -#endif /* TCP_STATS */ + TCP_STATS_INC(tcp.recv); iphdr = p->payload; tcphdr = (struct tcp_hdr *)((u8_t *)p->payload + IPH_HL(iphdr) * 4); @@ -126,10 +123,8 @@ tcp_input(struct pbuf *p, struct netif *inp) if (pbuf_header(p, -((s16_t)(IPH_HL(iphdr) * 4))) || (p->tot_len < sizeof(struct tcp_hdr))) { /* drop short packets */ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: short packet (%u bytes) discarded\n", p->tot_len)); -#ifdef TCP_STATS - ++lwip_stats.tcp.lenerr; - ++lwip_stats.tcp.drop; -#endif /* TCP_STATS */ + TCP_STATS_INC(tcp.lenerr); + TCP_STATS_INC(tcp.drop); pbuf_free(p); return; } @@ -151,10 +146,8 @@ tcp_input(struct pbuf *p, struct netif *inp) #if TCP_DEBUG tcp_debug_print(tcphdr); #endif /* TCP_DEBUG */ -#ifdef TCP_STATS - ++lwip_stats.tcp.chkerr; - ++lwip_stats.tcp.drop; -#endif /* TCP_STATS */ + TCP_STATS_INC(tcp.chkerr); + TCP_STATS_INC(tcp.drop); pbuf_free(p); return; @@ -391,10 +384,8 @@ tcp_input(struct pbuf *p, struct netif *inp) sender. */ LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_input: no PCB match found, resetting.\n")); if (!(TCPH_FLAGS(tcphdr) & TCP_RST)) { -#ifdef TCP_STATS - ++lwip_stats.tcp.proterr; - ++lwip_stats.tcp.drop; -#endif /* TCP_STATS */ + TCP_STATS_INC(tcp.proterr); + TCP_STATS_INC(tcp.drop); tcp_rst(ackno, seqno + tcplen, &(iphdr->dest), &(iphdr->src), tcphdr->dest, tcphdr->src); @@ -437,9 +428,7 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) SYN at a time when we have more memory available. */ if (npcb == NULL) { LWIP_DEBUGF(TCP_DEBUG, ("tcp_listen_input: could not allocate PCB\n")); -#ifdef TCP_STATS - ++lwip_stats.tcp.memerr; -#endif /* TCP_STATS */ + TCP_STATS_INC(tcp.memerr); return ERR_MEM; } /* Set up the new PCB. */ diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 646c709f..0ba851ed 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -234,9 +234,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len, LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: no room for TCP header in pbuf.\n")); -#ifdef TCP_STATS - ++lwip_stats.tcp.err; -#endif /* TCP_STATS */ + TCP_STATS_INC(tcp.err); goto memerr; } seg->tcphdr = seg->p->payload; @@ -332,9 +330,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len, return ERR_OK; memerr: -#ifdef TCP_STATS - ++lwip_stats.tcp.memerr; -#endif /* TCP_STATS */ + TCP_STATS_INC(tcp.memerr); if (queue != NULL) { tcp_segs_free(queue); @@ -524,9 +520,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb) &(pcb->local_ip), &(pcb->remote_ip), IP_PROTO_TCP, seg->p->tot_len); -#ifdef TCP_STATS - ++lwip_stats.tcp.xmit; -#endif /* TCP_STATS */ + TCP_STATS_INC(tcp.xmit); ip_output(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos, IP_PROTO_TCP); @@ -559,9 +553,7 @@ tcp_rst(u32_t seqno, u32_t ackno, tcphdr->chksum = inet_chksum_pseudo(p, local_ip, remote_ip, IP_PROTO_TCP, p->tot_len); -#ifdef TCP_STATS - ++lwip_stats.tcp.xmit; -#endif /* TCP_STATS */ + TCP_STATS_INC(tcp.xmit); /* Send output with hardcoded TTL since we have no access to the pcb */ ip_output(p, local_ip, remote_ip, TCP_TTL, 0, IP_PROTO_TCP); pbuf_free(p); @@ -629,9 +621,7 @@ tcp_keepalive(struct tcp_pcb *pcb) tcphdr->chksum = 0; tcphdr->chksum = inet_chksum_pseudo(p, &pcb->local_ip, &pcb->remote_ip, IP_PROTO_TCP, p->tot_len); -#ifdef TCP_STATS - ++lwip_stats.tcp.xmit; -#endif /* TCP_STATS */ + TCP_STATS_INC(tcp.xmit); /* Send output to IP */ ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP); diff --git a/src/core/udp.c b/src/core/udp.c index 123c5e52..7346fb5e 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -172,19 +172,15 @@ udp_input(struct pbuf *p, struct netif *inp) PERF_START; -#ifdef UDP_STATS - ++lwip_stats.udp.recv; -#endif /* UDP_STATS */ + UDP_STATS_INC(udp.recv); iphdr = p->payload; if (pbuf_header(p, -((s16_t)(UDP_HLEN + IPH_HL(iphdr) * 4)))) { /* drop short packets */ LWIP_DEBUGF(UDP_DEBUG, ("udp_input: short UDP datagram (%u bytes) discarded\n", p->tot_len)); -#ifdef UDP_STATS - ++lwip_stats.udp.lenerr; - ++lwip_stats.udp.drop; -#endif /* UDP_STATS */ + UDP_STATS_INC(udp.lenerr); + UDP_STATS_INC(udp.drop); snmp_inc_udpinerrors(); pbuf_free(p); goto end; @@ -330,10 +326,8 @@ udp_input(struct pbuf *p, struct netif *inp) (struct ip_addr *)&(iphdr->dest), IP_PROTO_UDPLITE, ntohs(udphdr->len)) != 0) { LWIP_DEBUGF(UDP_DEBUG | 2, ("udp_input: UDP Lite datagram discarded due to failing checksum\n")); -#ifdef UDP_STATS - ++lwip_stats.udp.chkerr; - ++lwip_stats.udp.drop; -#endif /* UDP_STATS */ + UDP_STATS_INC(udp.chkerr); + UDP_STATS_INC(udp.drop); snmp_inc_udpinerrors(); pbuf_free(p); goto end; @@ -345,10 +339,8 @@ udp_input(struct pbuf *p, struct netif *inp) IP_PROTO_UDP, p->tot_len) != 0) { LWIP_DEBUGF(UDP_DEBUG | 2, ("udp_input: UDP datagram discarded due to failing checksum\n")); -#ifdef UDP_STATS - ++lwip_stats.udp.chkerr; - ++lwip_stats.udp.drop; -#endif /* UDP_STATS */ + UDP_STATS_INC(udp.chkerr); + UDP_STATS_INC(udp.drop); snmp_inc_udpinerrors(); pbuf_free(p); goto end; @@ -398,10 +390,8 @@ udp_input(struct pbuf *p, struct netif *inp) p->payload = iphdr; icmp_dest_unreach(p, ICMP_DUR_PORT); } -#ifdef UDP_STATS - ++lwip_stats.udp.proterr; - ++lwip_stats.udp.drop; -#endif /* UDP_STATS */ + UDP_STATS_INC(udp.proterr); + UDP_STATS_INC(udp.drop); snmp_inc_udpnoports(); pbuf_free(p); } @@ -474,9 +464,7 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p) if ((netif = ip_route(&(pcb->remote_ip))) == NULL) { LWIP_DEBUGF(UDP_DEBUG | 1, ("udp_send: No route to 0x%lx\n", pcb->remote_ip.addr)); -#ifdef UDP_STATS - ++lwip_stats.udp.rterr; -#endif /* UDP_STATS */ + UDP_STATS_INC(udp.rterr); return ERR_RTE; } /* using IP_ANY_ADDR? */ @@ -525,9 +513,7 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p) pbuf_free(q); } -#ifdef UDP_STATS - ++lwip_stats.udp.xmit; -#endif /* UDP_STATS */ + UDP_STATS_INC(udp.xmit); return err; } @@ -703,9 +689,7 @@ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port) if ((netif = ip_route(&(pcb->remote_ip))) == NULL) { LWIP_DEBUGF(UDP_DEBUG, ("udp_connect: No route to 0x%lx\n", pcb->remote_ip.addr)); -#ifdef UDP_STATS - ++lwip_stats.udp.rterr; -#endif /* UDP_STATS */ + UDP_STATS_INC(udp.rterr); return ERR_RTE; } /** TODO: this will bind the udp pcb locally, to the interface which diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index dd303935..b09e042c 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -348,6 +348,10 @@ a lot of data that needs to be copied, this should be set high. */ #define IP_STATS 1 #endif +#ifndef IPFRAG_STATS +#define IPFRAG_STATS 1 +#endif + #ifndef ICMP_STATS #define ICMP_STATS 1 #endif @@ -376,6 +380,19 @@ a lot of data that needs to be copied, this should be set high. */ #define SYS_STATS 1 #endif +#else + +#define LINK_STATS 0 +#define IP_STATS 0 +#define IPFRAG_STATS 0 +#define ICMP_STATS 0 +#define UDP_STATS 0 +#define TCP_STATS 0 +#define MEM_STATS 0 +#define MEMP_STATS 0 +#define PBUF_STATS 0 +#define SYS_STATS 0 + #endif /* LWIP_STATS */ /* ---------- PPP options ---------- */ diff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h index 3ccc3e75..ac06a6d3 100644 --- a/src/include/lwip/stats.h +++ b/src/include/lwip/stats.h @@ -101,9 +101,49 @@ extern struct stats_ lwip_stats; void stats_init(void); + +#define STATS_INC(x) ++lwip_stats.x #else #define stats_init() +#define STATS_INC(x) #endif /* LWIP_STATS */ + +#if TCP_STATS +#define TCP_STATS_INC(x) STATS_INC(x) +#else +#define TCP_STATS_INC(x) +#endif + +#if UDP_STATS +#define UDP_STATS_INC(x) STATS_INC(x) +#else +#define UDP_STATS_INC(x) +#endif + +#if ICMP_STATS +#define ICMP_STATS_INC(x) STATS_INC(x) +#else +#define ICMP_STATS_INC(x) +#endif + +#if IP_STATS +#define IP_STATS_INC(x) STATS_INC(x) +#else +#define IP_STATS_INC(x) +#endif + +#if IPFRAG_STATS +#define IPFRAG_STATS_INC(x) STATS_INC(x) +#else +#define IPFRAG_STATS_INC(x) +#endif + +#if LINK_STATS +#define LINK_STATS_INC(x) STATS_INC(x) +#else +#define LINK_STATS_INC(x) +#endif + #endif /* __LWIP_STATS_H__ */ diff --git a/src/netif/etharp.c b/src/netif/etharp.c index 62f04a70..fa6e917f 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -535,9 +535,7 @@ etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q) /* The pbuf_header() call shouldn't fail, and we'll just bail out if it does.. */ LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE | 2, ("etharp_output: could not allocate room for header.\n")); -#ifdef LINK_STATS - ++lwip_stats.link.lenerr; -#endif /* LINK_STATS */ + LINK_STATS_INC(link.lenerr); return NULL; } diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 3ac7995a..263e8fb2 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -307,7 +307,7 @@ void pppInit(void) (*protp->init)(i); } -#ifdef LINK_STATS +#if LINK_STATS /* Clear the statistics. */ memset(&lwip_stats.link, 0, sizeof(lwip_stats.link)); #endif @@ -482,7 +482,7 @@ static void nPut(PPPControl *pc, struct pbuf *nb) if((c = sio_write(pc->fd, b->payload, b->len)) != b->len) { PPPDEBUG((LOG_WARNING, "PPP nPut: incomplete sio_write(%d,, %u) = %d\n", pc->fd, b->len, c)); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.err++; #endif /* LINK_STATS */ pc->lastXMit = 0; /* prepend PPP_FLAG to next packet */ @@ -491,7 +491,7 @@ static void nPut(PPPControl *pc, struct pbuf *nb) } pbuf_free(nb); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.xmit++; #endif /* LINK_STATS */ } @@ -515,7 +515,7 @@ static struct pbuf *pppAppend(u_char c, struct pbuf *nb, ext_accm *outACCM) if (tb) { nb->next = tb; } -#ifdef LINK_STATS +#if LINK_STATS else { lwip_stats.link.memerr++; } @@ -552,7 +552,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i if (pd < 0 || pd >= NUM_PPP || !pc->openFlag || !pb) { PPPDEBUG((LOG_WARNING, "pppifOutput[%d]: bad parms prot=%d pb=%p\n", pd, protocol, pb)); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.opterr++; lwip_stats.link.drop++; #endif @@ -562,7 +562,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i /* Check that the link is up. */ if (lcp_phase[pd] == PHASE_DEAD) { PPPDEBUG((LOG_ERR, "pppifOutput[%d]: link not up\n", pd)); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.rterr++; lwip_stats.link.drop++; #endif @@ -573,7 +573,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i headMB = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); if (headMB == NULL) { PPPDEBUG((LOG_WARNING, "pppifOutput[%d]: first alloc fail\n", pd)); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.memerr++; lwip_stats.link.drop++; #endif /* LINK_STATS */ @@ -600,7 +600,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i break; default: PPPDEBUG((LOG_WARNING, "pppifOutput[%d]: bad IP packet\n", pd)); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.proterr++; lwip_stats.link.drop++; #endif @@ -662,7 +662,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i "pppifOutput[%d]: Alloc err - dropping proto=%d\n", pd, protocol)); pbuf_free(headMB); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.memerr++; lwip_stats.link.drop++; #endif @@ -751,7 +751,7 @@ int pppWrite(int pd, const u_char *s, int n) struct pbuf *headMB = NULL, *tailMB; headMB = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); if (headMB == NULL) { -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.memerr++; lwip_stats.link.proterr++; #endif /* LINK_STATS */ @@ -791,7 +791,7 @@ int pppWrite(int pd, const u_char *s, int n) "pppWrite[%d]: Alloc err - dropping pbuf len=%d\n", pd, headMB->len)); /* "pppWrite[%d]: Alloc err - dropping %d:%.*H", pd, headMB->len, LWIP_MIN(headMB->len * 2, 40), headMB->payload)); */ pbuf_free(headMB); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.memerr++; lwip_stats.link.proterr++; #endif /* LINK_STATS */ @@ -1298,7 +1298,7 @@ static void pppInput(void *arg) pbuf_header(nb, -(int)sizeof(struct pppInputHeader)); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.recv++; #endif /* LINK_STATS */ @@ -1388,7 +1388,7 @@ static void pppInput(void *arg) } drop: -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.drop++; #endif @@ -1418,7 +1418,7 @@ static void pppDrop(PPPControl *pc) vj_uncompress_err(&pc->vjComp); #endif -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.drop++; #endif /* LINK_STATS */ } @@ -1456,7 +1456,7 @@ static void pppInProc(int pd, u_char *s, int l) PPPDEBUG((LOG_WARNING, "pppInProc[%d]: Dropping incomplete packet %d\n", pd, pc->inState)); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.lenerr++; #endif pppDrop(pc); @@ -1466,7 +1466,7 @@ static void pppInProc(int pd, u_char *s, int l) PPPDEBUG((LOG_INFO, "pppInProc[%d]: Dropping bad fcs 0x%04X proto=0x%04X\n", pd, pc->inFCS, pc->inProtocol)); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.chkerr++; #endif pppDrop(pc); @@ -1498,7 +1498,7 @@ static void pppInProc(int pd, u_char *s, int l) PPPDEBUG((LOG_ERR, "pppInProc[%d]: tcpip_callback() failed, dropping packet\n", pd)); pbuf_free(pc->inHead); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.drop++; #endif } @@ -1594,7 +1594,7 @@ static void pppInProc(int pd, u_char *s, int l) * higher layers deal with it. Continue processing * the received pbuf chain in case a new packet starts. */ PPPDEBUG((LOG_ERR, "pppInProc[%d]: NO FREE MBUFS!\n", pd)); -#ifdef LINK_STATS +#if LINK_STATS lwip_stats.link.memerr++; #endif /* LINK_STATS */ pppDrop(pc); diff --git a/src/netif/ppp/vj.c b/src/netif/ppp/vj.c index 82f3e341..15c77af0 100644 --- a/src/netif/ppp/vj.c +++ b/src/netif/ppp/vj.c @@ -35,7 +35,7 @@ #if VJ_SUPPORT > 0 -#ifdef LINK_STATS +#if LINK_STATS #define INCR(counter) ++comp->stats.counter #else #define INCR(counter) @@ -574,6 +574,33 @@ int vj_uncompress_tcp( /* Remove the compressed header and prepend the uncompressed header. */ pbuf_header(n0, -vjlen); + if(MEM_ALIGN(n0->payload) != n0->payload) { + struct pbuf *np, *q; + u8_t *bufptr; + + np = pbuf_alloc(PBUF_RAW, n0->len + cs->cs_hlen, PBUF_POOL); + if(!np) { + PPPDEBUG((LOG_WARNING, "vj_uncompress_tcp: realign failed\n")); + *nb = NULL; + goto bad; + } + + pbuf_header(np, -cs->cs_hlen); + + bufptr = n0->payload; + for(q = np; q != NULL; q = q->next) { + memcpy(q->payload, bufptr, q->len); + bufptr += q->len; + } + + if(n0->next) { + pbuf_chain(np, n0->next); + pbuf_dechain(n0); + } + pbuf_free(n0); + n0 = np; + } + if(pbuf_header(n0, cs->cs_hlen)) { struct pbuf *np; @@ -585,8 +612,10 @@ int vj_uncompress_tcp( goto bad; } pbuf_chain(np, n0); + pbuf_free(n0); n0 = np; } + LWIP_ASSERT("n0->len >= cs->cs_hlen", n0->len >= cs->cs_hlen); memcpy(n0->payload, &cs->cs_ip, cs->cs_hlen); *nb = n0; diff --git a/src/netif/ppp/vj.h b/src/netif/ppp/vj.h index e5b60056..501b7dc0 100644 --- a/src/netif/ppp/vj.h +++ b/src/netif/ppp/vj.h @@ -1,7 +1,7 @@ /* * Definitions for tcp compression routines. * - * $Id: vj.h,v 1.2 2003/06/02 11:12:56 jani Exp $ + * $Id: vj.h,v 1.2.6.1 2003/10/28 11:44:45 jani Exp $ * * Copyright (c) 1989 Regents of the University of California. * All rights reserved. @@ -136,7 +136,7 @@ struct vjcompress { u_short flags; u_char maxSlotIndex; u_char compressSlot; /* Flag indicating OK to compress slot ID. */ -#ifdef LINK_STATS +#if LINK_STATS struct vjstat stats; #endif struct cstate tstate[MAX_SLOTS]; /* xmit connection states */ diff --git a/src/netif/slipif.c b/src/netif/slipif.c index ccafa579..53c20237 100644 --- a/src/netif/slipif.c +++ b/src/netif/slipif.c @@ -115,9 +115,7 @@ slipif_input( struct netif * netif ) /* Received whole packet. */ pbuf_realloc(q, recved); -#ifdef LINK_STATS - ++lwip_stats.link.recv; -#endif /* LINK_STATS */ + LINK_STATS_INC(link.recv); LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet\n")); return q; @@ -141,12 +139,10 @@ slipif_input( struct netif * netif ) LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n")); p = pbuf_alloc(PBUF_LINK, PBUF_POOL_BUFSIZE, PBUF_POOL); -#ifdef LINK_STATS if (p == NULL) { - ++lwip_stats.link.drop; + LINK_STATS_INC(link.drop); LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n")); } -#endif /* LINK_STATS */ if (q != NULL) { pbuf_chain(q, p);