From ca866c0d7da1d6e98f435eeb5f6348d318157318 Mon Sep 17 00:00:00 2001 From: fbernon Date: Wed, 5 Sep 2007 17:20:45 +0000 Subject: [PATCH] Integrate "task #7272 : LWIP_ICMP option". The new option LWIP_ICMP enable/disable ICMP module inside the IP stack (enable per default). Be careful, disabling ICMP make your product non-compliant to RFC1122, but help to reduce footprint, and to reduce "visibility" on the Internet. --- CHANGELOG | 7 +++++++ src/core/ipv4/icmp.c | 4 ++++ src/core/ipv4/ip.c | 6 ++++++ src/core/ipv6/icmp6.c | 9 ++------- src/core/ipv6/ip6.c | 7 ++++++- src/core/udp.c | 2 ++ src/include/ipv4/lwip/icmp.h | 5 ++++- src/include/ipv6/lwip/icmp.h | 6 +++++- src/include/lwip/opt.h | 8 ++++++++ 9 files changed, 44 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 58bf30f0..7288bcc7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,13 @@ HISTORY ++ New features: + 2007-09-05 Frédéric Bernon + * udp.c, ipv4/icmp.c, ipv4/ip.c, ipv6/icmp.c, ipv6/ip6.c, ipv4/icmp.h, + ipv6/icmp.h, opt.h: Integrate "task #7272 : LWIP_ICMP option". The new option + LWIP_ICMP enable/disable ICMP module inside the IP stack (enable per default). + Be careful, disabling ICMP make your product non-compliant to RFC1122, but + help to reduce footprint, and to reduce "visibility" on the Internet. + 2007-09-05 Frédéric Bernon, Bill Florac * opt.h, sys.h, tcpip.c, slipif.c, ppp.c, sys_arch.txt: Change parameters list for sys_thread_new (see "task #7252 : Create sys_thread_new_ex()"). Two new diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c index 49273ae1..6163132b 100644 --- a/src/core/ipv4/icmp.c +++ b/src/core/ipv4/icmp.c @@ -49,6 +49,8 @@ #include "lwip/stats.h" #include "lwip/snmp.h" +#if LWIP_ICMP /* don't build if not configured for use in lwipopts.h */ + /** * Processes ICMP input packets, called from ip_input(). * @@ -298,3 +300,5 @@ icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t) } #endif /* IP_FORWARD */ + +#endif /* LWIP_ICMP */ diff --git a/src/core/ipv4/ip.c b/src/core/ipv4/ip.c index 9a065380..c2117e97 100644 --- a/src/core/ipv4/ip.c +++ b/src/core/ipv4/ip.c @@ -144,10 +144,12 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) /* send ICMP if TTL == 0 */ if (IPH_TTL(iphdr) == 0) { snmp_inc_ipinhdrerrors(); +#if LWIP_ICMP /* Don't send ICMP messages in response to ICMP messages */ if (IPH_PROTO(iphdr) != IP_PROTO_ICMP) { icmp_time_exceeded(p, ICMP_TE_TTL); } +#endif /* LWIP_ICMP */ return (struct netif *)NULL; } @@ -384,22 +386,26 @@ ip_input(struct pbuf *p, struct netif *inp) { tcp_input(p, inp); break; #endif /* LWIP_TCP */ +#if LWIP_ICMP case IP_PROTO_ICMP: snmp_inc_ipindelivers(); icmp_input(p, inp); break; +#endif /* LWIP_ICMP */ #if LWIP_IGMP case IP_PROTO_IGMP: igmp_input(p,inp,&(iphdr->dest)); break; #endif /* LWIP_IGMP */ default: +#if LWIP_ICMP /* send ICMP destination protocol unreachable unless is was a broadcast */ if (!ip_addr_isbroadcast(&(iphdr->dest), inp) && !ip_addr_ismulticast(&(iphdr->dest))) { p->payload = iphdr; icmp_dest_unreach(p, ICMP_DUR_PROTO); } +#endif /* LWIP_ICMP */ pbuf_free(p); LWIP_DEBUGF(IP_DEBUG | 2, ("Unsupported transport protocol %"U16_F"\n", IPH_PROTO(iphdr))); diff --git a/src/core/ipv6/icmp6.c b/src/core/ipv6/icmp6.c index 5d2c3a9f..ec5d2adb 100644 --- a/src/core/ipv6/icmp6.c +++ b/src/core/ipv6/icmp6.c @@ -42,6 +42,7 @@ #include "lwip/stats.h" +#if LWIP_ICMP /* don't build if not configured for use in lwipopts.h */ void icmp_input(struct pbuf *p, struct netif *inp) @@ -192,10 +193,4 @@ icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t) pbuf_free(q); } - - - - - - - +#endif /* LWIP_ICMP */ diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index 06035a15..5caa1583 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -111,10 +111,12 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr) } /* Decrement TTL and send ICMP if ttl == 0. */ if (--iphdr->hoplim == 0) { +#if LWIP_ICMP /* Don't send ICMP messages in response to ICMP messages */ if (iphdr->nexthdr != IP_PROTO_ICMP) { icmp_time_exceeded(p, ICMP_TE_TTL); } +#endif /* LWIP_ICMP */ pbuf_free(p); return; } @@ -232,12 +234,16 @@ ip_input(struct pbuf *p, struct netif *inp) { case IP_PROTO_TCP: tcp_input(p, inp); break; +#if LWIP_ICMP case IP_PROTO_ICMP: icmp_input(p, inp); break; +#endif /* LWIP_ICMP */ default: +#if LWIP_ICMP /* send ICMP destination protocol unreachable */ icmp_dest_unreach(p, ICMP_DUR_PROTO); +#endif /* LWIP_ICMP */ pbuf_free(p); LWIP_DEBUGF(IP_DEBUG, ("Unsupported transport protocol %"U16_F"\n", iphdr->nexthdr)); @@ -382,4 +388,3 @@ ip_debug_print(struct pbuf *p) LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); } #endif /* IP_DEBUG */ - diff --git a/src/core/udp.c b/src/core/udp.c index 7e23881d..95dda50c 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -256,6 +256,7 @@ udp_input(struct pbuf *p, struct netif *inp) } else { LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: not for us.\n")); +#if LWIP_ICMP /* No match was found, send ICMP destination port unreachable unless destination address was broadcast/multicast. */ if (!ip_addr_isbroadcast(&iphdr->dest, inp) && @@ -265,6 +266,7 @@ udp_input(struct pbuf *p, struct netif *inp) LWIP_ASSERT("p->payload == iphdr", (p->payload == iphdr)); icmp_dest_unreach(p, ICMP_DUR_PORT); } +#endif /* LWIP_ICMP */ UDP_STATS_INC(udp.proterr); UDP_STATS_INC(udp.drop); snmp_inc_udpnoports(); diff --git a/src/include/ipv4/lwip/icmp.h b/src/include/ipv4/lwip/icmp.h index d3cc153d..072e17e4 100644 --- a/src/include/ipv4/lwip/icmp.h +++ b/src/include/ipv4/lwip/icmp.h @@ -40,6 +40,8 @@ #include "lwip/ip_addr.h" #include "lwip/netif.h" +#if LWIP_ICMP /* don't build if not configured for use in lwipopts.h */ + #ifdef __cplusplus extern "C" { #endif @@ -116,5 +118,6 @@ PACK_STRUCT_END } #endif +#endif /* LWIP_ICMP */ + #endif /* __LWIP_ICMP_H__ */ - diff --git a/src/include/ipv6/lwip/icmp.h b/src/include/ipv6/lwip/icmp.h index 0df99344..987e3eb3 100644 --- a/src/include/ipv6/lwip/icmp.h +++ b/src/include/ipv6/lwip/icmp.h @@ -39,6 +39,8 @@ #include "lwip/netif.h" +#if LWIP_ICMP /* don't build if not configured for use in lwipopts.h */ + #ifdef __cplusplus extern "C" { #endif @@ -94,5 +96,7 @@ struct icmp_te_hdr { } #endif +#endif /* LWIP_ICMP */ + #endif /* __LWIP_ICMP_H__ */ - + diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 2d1c964a..734baa32 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -403,6 +403,14 @@ ---------- ICMP options ---------- ---------------------------------- */ +/** + * LWIP_ICMP==1: Enable ICMP module inside the IP stack. + * Be careful, disable that make your product non-compliant to RFC1122 + */ +#ifndef LWIP_ICMP +#define LWIP_ICMP 1 +#endif + /** * ICMP_TTL: Default value for Time-To-Live used by ICMP packets. */