From e001a021d5752db8926e7dc936a60b7f3f49689b Mon Sep 17 00:00:00 2001 From: goldsimon Date: Mon, 16 Feb 2009 20:24:29 +0000 Subject: [PATCH] patch #6539: (configurable) response to broadcast- and multicast pings --- CHANGELOG | 8 ++++++-- src/core/ipv4/icmp.c | 29 +++++++++++++++++++++++------ src/include/lwip/opt.h | 14 ++++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 15342e82..93b64896 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,13 +19,17 @@ HISTORY ++ New features: + 2009-02-16 Simon Goldschmidt (patch by Rishi Khan) + * icmp.c, opt.h: patch #6539: (configurable) response to broadcast- and multicast + pings + 2009-02-12 Simon Goldschmidt * init.h: Added LWIP_VERSION to get the current version of the stack 2009-02-11 Simon Goldschmidt (suggested by Gottfried Spitaler) * opt.h, memp.h/.c: added MEMP_MEM_MALLOC to use mem_malloc/mem_free instead - of the pool allocator (can save code size with MEM_LIBC_MALLOC if libc-malloc - is otherwise used) + of the pool allocator (can save code size with MEM_LIBC_MALLOC if libc-malloc + is otherwise used) 2009-01-28 Jonathan Larmour (suggested by Bill Bauerbach) * ipv4/inet_chksum.c, ipv4/lwip/inet_chksum.h: inet_chksum_pseudo_partial() diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c index 6a72c780..b49d6598 100644 --- a/src/core/ipv4/icmp.c +++ b/src/core/ipv4/icmp.c @@ -94,13 +94,30 @@ icmp_input(struct pbuf *p, struct netif *inp) #endif /* LWIP_DEBUG */ switch (type) { case ICMP_ECHO: - /* broadcast or multicast destination address? */ - if (ip_addr_isbroadcast(&iphdr->dest, inp) || ip_addr_ismulticast(&iphdr->dest)) { - LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: Not echoing to multicast or broadcast pings\n")); - ICMP_STATS_INC(icmp.err); - pbuf_free(p); - return; +#if !LWIP_MULTICAST_PING || !LWIP_BROADCAST_PING + { + int accepted = 1; +#if !LWIP_MULTICAST_PING + /* multicast destination address? */ + if (ip_addr_ismulticast(&iphdr->dest)) { + accepted = 0; + } +#endif /* LWIP_MULTICAST_PING */ +#if !LWIP_BROADCAST_PING + /* broadcast destination address? */ + if (ip_addr_isbroadcast(&iphdr->dest, inp)) { + accepted = 0; + } +#endif /* LWIP_BROADCAST_PING */ + /* broadcast or multicast destination address not acceptd? */ + if (!accepted) { + LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: Not echoing to multicast or broadcast pings\n")); + ICMP_STATS_INC(icmp.err); + pbuf_free(p); + return; + } } +#endif /* !LWIP_MULTICAST_PING || !LWIP_BROADCAST_PING */ LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ping\n")); if (p->tot_len < sizeof(struct icmp_echo_hdr)) { LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n")); diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 907a9582..17964f48 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -461,6 +461,20 @@ #define ICMP_TTL (IP_DEFAULT_TTL) #endif +/** + * LWIP_BROADCAST_PING==1: respond to broadcast pings (default is unicast only) + */ +#ifndef LWIP_BROADCAST_PING +#define LWIP_BROADCAST_PING 0 +#endif + +/** + * LWIP_MULTICAST_PING==1: respond to multicast pings (default is unicast only) + */ +#ifndef LWIP_MULTICAST_PING +#define LWIP_MULTICAST_PING 0 +#endif + /* --------------------------------- ---------- RAW options ----------