summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2015-10-25 12:47:27 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2015-10-25 12:47:27 +0000
commitb976dfe799ad6a51ea0610e588a6eddb4d1c6123 (patch)
treeec8632ed2188e5c4fb0568093115f42d708d7ebe
parentcb4a2414510d30f85c33547fca38c5120fbc2b02 (diff)
Implement ping(8)'s -L option in ping6:
Disable the loopback, so the transmitting host doesn't see the ICMP requests. For multicast pings. OK benno@
-rw-r--r--sbin/ping6/ping6.810
-rw-r--r--sbin/ping6/ping6.c21
2 files changed, 24 insertions, 7 deletions
diff --git a/sbin/ping6/ping6.8 b/sbin/ping6/ping6.8
index b597b934602..cbfa002cf54 100644
--- a/sbin/ping6/ping6.8
+++ b/sbin/ping6/ping6.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ping6.8,v 1.57 2015/10/17 13:08:14 florian Exp $
+.\" $OpenBSD: ping6.8,v 1.58 2015/10/25 12:47:26 florian Exp $
.\" $KAME: ping6.8,v 1.57 2002/05/26 13:18:25 itojun Exp $
.\"
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -28,7 +28,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: October 17 2015 $
+.Dd $Mdocdate: October 25 2015 $
.Dt PING6 8
.Os
.Sh NAME
@@ -36,7 +36,7 @@
.Nd send ICMPv6 ECHO_REQUEST packets to network hosts
.Sh SYNOPSIS
.Nm ping6
-.Op Fl dEefHmnqv
+.Op Fl dEefHLmnqv
.Op Fl c Ar count
.Op Fl g Ar gateway
.Op Fl h Ar hoplimit
@@ -132,6 +132,10 @@ The default is to wait for one second between each packet.
This option is incompatible with the
.Fl f
option.
+.It Fl L
+Disable the loopback, so the transmitting host doesn't see the ICMP
+requests.
+For multicast pings.
.It Fl l Ar preload
If
.Ar preload
diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c
index 47ab09dbace..02d0dc6f948 100644
--- a/sbin/ping6/ping6.c
+++ b/sbin/ping6/ping6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ping6.c,v 1.131 2015/10/24 16:59:15 florian Exp $ */
+/* $OpenBSD: ping6.c,v 1.132 2015/10/25 12:47:26 florian Exp $ */
/* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */
/*
@@ -148,6 +148,10 @@ struct payload {
#define F_AUD_MISS 0x400000
u_int options;
+/* multicast options */
+int moptions;
+#define MULTICAST_NOLOOP 0x001
+
#define DUMMY_PORT 10101
/*
@@ -235,7 +239,7 @@ main(int argc, char *argv[])
struct cmsghdr *scmsgp = NULL;
struct in6_pktinfo *pktinfo = NULL;
double intval;
- int mflag = 0;
+ int mflag = 0, loop = 1;
uid_t uid;
u_int rtableid = 0;
@@ -250,7 +254,7 @@ main(int argc, char *argv[])
preload = 0;
datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN];
while ((ch = getopt(argc, argv,
- "c:dEefg:Hh:I:i:l:mNnp:qS:s:V:vw:")) != -1) {
+ "c:dEefg:Hh:I:i:Ll:mNnp:qS:s:V:vw:")) != -1) {
switch (ch) {
case 'c':
npackets = strtonum(optarg, 0, INT_MAX, &errstr);
@@ -326,6 +330,10 @@ main(int argc, char *argv[])
}
options |= F_INTERVAL;
break;
+ case 'L':
+ moptions |= MULTICAST_NOLOOP;
+ loop = 0;
+ break;
case 'l':
if (getuid()) {
errno = EPERM;
@@ -463,6 +471,11 @@ main(int argc, char *argv[])
if ((options & F_FLOOD) && (options & (F_AUD_RECV | F_AUD_MISS)))
warnx("No audible output for flood pings");
+ if ((moptions & MULTICAST_NOLOOP) &&
+ setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loop,
+ sizeof(loop)) < 0)
+ err(1, "setsockopt IP6_MULTICAST_LOOP");
+
if (datalen >= sizeof(struct payload)) {
/* we can time transfer */
timing = 1;
@@ -1645,7 +1658,7 @@ void
usage(void)
{
(void)fprintf(stderr,
- "usage: ping6 [-dEefHmnqv] [-c count] [-g gateway] [-h hoplimit] "
+ "usage: ping6 [-dEefHLmnqv] [-c count] [-g gateway] [-h hoplimit] "
"[-I sourceaddr]\n\t[-i wait] [-l preload] [-p pattern] "
"[-s packetsize] [-V rtable]\n\t[-w maxwait] host\n");
exit(1);