diff options
author | Sami Kerola <kerolasa@iki.fi> | 2019-07-22 07:28:36 +0100 |
---|---|---|
committer | Sami Kerola <kerolasa@iki.fi> | 2019-07-22 07:28:36 +0100 |
commit | 918b876a5eb1e8bffe1a56c5697064c6dc80a141 (patch) | |
tree | be6c0566a99a0319bbc8e1ead0c4f631ca995c27 | |
parent | 737d8a91e394518d2ccdaf398bb16283eb8e4a81 (diff) | |
download | iputils-918b876a5eb1e8bffe1a56c5697064c6dc80a141.tar.gz |
ping: suppress duplicate reply messages in context of multicast
Bug report asks to suppress duplicate messages when pinging multicast
address. This commit does that, and allows one to re-enable duplicates with
verbose option. After all ping is debugging tool, so there needs to be a
way to debug.
Addresses: https://github.com/iputils/iputils/issues/195
Bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=498429
Reported-by: Noah Meyerhans <noahm@debian.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r-- | doc/ping.xml | 3 | ||||
-rw-r--r-- | ping.c | 4 | ||||
-rw-r--r-- | ping.h | 2 | ||||
-rw-r--r-- | ping6_common.c | 10 | ||||
-rw-r--r-- | ping_common.c | 4 |
5 files changed, 15 insertions, 8 deletions
diff --git a/doc/ping.xml b/doc/ping.xml index f567523..75eadcf 100644 --- a/doc/ping.xml +++ b/doc/ping.xml @@ -643,7 +643,8 @@ xml:id="man.ping"> <option>-v</option> </term> <listitem> - <para>Verbose output.</para> + <para>Verbose output. Do not suppress DUP replies when pinging + multicast address.</para> </listitem> </varlistentry> <varlistentry> @@ -85,6 +85,7 @@ static int optlen = 0; static int settos = 0; /* Set TOS, Precedence or other QOS options */ static int broadcast_pings = 0; +static int multicast; static void pr_options(unsigned char *cp, int hlen); static void pr_iph(struct iphdr *ip); @@ -708,6 +709,7 @@ int ping4_run(int argc, char **argv, struct addrinfo *ai, socket_st *sock) } if (broadcast_pings || IN_MULTICAST(ntohl(whereto.sin_addr.s_addr))) { + multicast = 1; if (uid) { if (interval < 1000) error(2, 0, _("broadcast ping with too short interval: %d"), interval); @@ -1061,7 +1063,7 @@ ping4_parse_reply(struct socket_st *sock, struct msghdr *msg, int cc, void *addr if (gather_statistics((uint8_t *)icp, sizeof(*icp), cc, ntohs(icp->un.echo.sequence), reply_ttl, 0, tv, pr_addr(from, sizeof *from), - pr_echo_reply)) { + pr_echo_reply, multicast)) { fflush(stdout); return 0; } @@ -312,7 +312,7 @@ extern void common_options(int ch); extern int gather_statistics(uint8_t *ptr, int icmplen, int cc, uint16_t seq, int hops, int csfailed, struct timeval *tv, char *from, - void (*pr_reply)(uint8_t *ptr, int cc)); + void (*pr_reply)(uint8_t *ptr, int cc), int multicast); extern void print_timestamp(void); void fill(char *patp, unsigned char *packet, unsigned packet_size); diff --git a/ping6_common.c b/ping6_common.c index 330b87a..4e083c1 100644 --- a/ping6_common.c +++ b/ping6_common.c @@ -78,6 +78,7 @@ uint32_t tclass; static struct sockaddr_in6 whereto; static struct sockaddr_in6 firsthop; +static int multicast; static unsigned char cmsgbuf[4096]; static size_t cmsglen = 0; @@ -697,7 +698,8 @@ int ping6_run(int argc, char **argv, struct addrinfo *ai, struct socket_st *sock ipi->ipi6_ifindex = if_name2index(device); } - if ((whereto.sin6_addr.s6_addr16[0] & htons(0xff00)) == htons(0xff00)) { + if (IN6_IS_ADDR_MULTICAST(&whereto.sin6_addr)) { + multicast = 1; if (uid) { if (interval < 1000) error(2, 0, _("multicast ping with too short interval: %d"), interval); @@ -1209,7 +1211,8 @@ ping6_parse_reply(socket_st *sock, struct msghdr *msg, int cc, void *addr, struc if (gather_statistics((uint8_t *)icmph, sizeof(*icmph), cc, ntohs(icmph->icmp6_seq), hops, 0, tv, pr_addr(from, sizeof *from), - pr_echo_reply)) { + pr_echo_reply, + multicast)) { fflush(stdout); return 0; } @@ -1221,7 +1224,8 @@ ping6_parse_reply(socket_st *sock, struct msghdr *msg, int cc, void *addr, struc if (gather_statistics((uint8_t *)icmph, sizeof(*icmph), cc, seq, hops, 0, tv, pr_addr(from, sizeof *from), - pr_niquery_reply)) + pr_niquery_reply, + multicast)) return 0; } else { int nexthdr; diff --git a/ping_common.c b/ping_common.c index 73b76fa..e91d15c 100644 --- a/ping_common.c +++ b/ping_common.c @@ -781,7 +781,7 @@ void main_loop(ping_func_set_st *fset, socket_st *sock, uint8_t *packet, int pac int gather_statistics(uint8_t *icmph, int icmplen, int cc, uint16_t seq, int hops, int csfailed, struct timeval *tv, char *from, - void (*pr_reply)(uint8_t *icmph, int cc)) + void (*pr_reply)(uint8_t *icmph, int cc), int multicast) { int dupflag = 0; long triptime = 0; @@ -874,7 +874,7 @@ restamp: printf(_(" time=%ld.%03ld ms"), triptime / 1000, triptime % 1000); } - if (dupflag) + if (dupflag && (!multicast || options & F_VERBOSE)) printf(_(" (DUP!)")); if (csfailed) printf(_(" (BAD CHECKSUM!)")); |