Commit Graph

80 Commits

Author SHA1 Message Date
Richard Scheffenegger
6034024dad Add -z "TOS" option to ping6, to test DSCP/ECN values
ping has the option to add the (deprecated) TOS byte
using the -z option. Adding the same option, with the
same (deprecated) Traffic Class Byte (nowadays actually
DSCP and ECN fields) to ping6 to validate proper QoS
processing in network switches.

Reviewed by:	tuexen
MFC after:	2 weeks
Sponsored by:	NetApp, Inc.
Differential Revision:	https://reviews.freebsd.org/D26384
2020-09-10 00:50:18 +00:00
Alexander V. Chernikov
af14123601 Make ping6(1) return code consistent with the man page.
When every sendto() call originated by ping6(1) fails, current code always
 returns 2 ("transmission was successful but no responses were received")
 which is incorrect. Return EX_OSERR instead as in many cases it indicates
 some kernel-level problems.

MFC after:	3 weeks
2020-02-15 15:39:53 +00:00
Alan Somers
2eb6acc277 ping, ping6: Use setitimer(2) instead of obsolete alarm(3)
Submitted by:	Ján Sučan <sucanjan@gmail.com>
Differential Revision:	https://reviews.freebsd.org/D22103
2019-11-26 05:06:25 +00:00
Mark Johnston
d395e985b2 ping6: Use caph_rights_limit(3) for STDIN_FILENO
Update some error messages while here.

Reported by:	olivier
MFC after:	3 days
2019-09-23 22:20:11 +00:00
Alan Somers
208ae7b7b4 ping6: Rename options for better consistency with ping
Now equivalent options have the same flags, and nonequivalent options have
different flags.  This is a prelude to merging the two commands.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC:		Never
Sponsored by:	Google LLC (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21345
2019-08-23 15:22:20 +00:00
Alan Somers
818f498f29 ping6: revert r350857
Some socket options require root privileges to set.  The old code did indeed
drop privileges at the earliest opportunity.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	Never
Sponsored by:	Google, Inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21319
2019-08-19 14:20:26 +00:00
Alan Somers
62da1eef7f ping6: Fix dnsdecode() bug introduced by r350859
Revision 350859 removed level of indirection that was needed for setting the
caller's `cp' pointer. dnsdecode() uses return value to indicate error or
success. It returns pointer to a buffer holding a decompressed DNS name or
NULL. The caller uses that value only to find out the result, not for accessing
the buffer.

We use the return value to propagate the new value of `cp' pointer to
the caller instead of using an output argument.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
MFC-With:	350859
Sponsored by:	Google, Inc (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21266
2019-08-17 14:28:32 +00:00
Alan Somers
2933651bf4 ping6: Fix alignment errors
This fixes -Wcast-align errors when compiled with WARNS=6.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21217
2019-08-15 19:52:32 +00:00
Alan Somers
8a3107c8f3 ping6: fix uninitialized variable warnings when MK_CASPER=no
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21273
2019-08-15 19:27:36 +00:00
Alan Somers
0b894a06bd ping6: Fix data type of the buffer for ancillary data of a received message
The old code worked, but wasted some stack space.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21275
2019-08-15 17:24:10 +00:00
Alan Somers
631b873cd8 ping6: fix uninitialized variable warning for intvl
GCC isn't smart enough to realize that this variable was always initialized.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21271
2019-08-15 16:09:27 +00:00
Alan Somers
899ecf0904 ping6: quiet an undefined variable warning
GCC 4.2 isn't smart enough to know that this variable is already defined by
the time it's used.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21269
2019-08-15 15:55:01 +00:00
Alan Somers
dab7253c41 ping6: quiet warning about unused copyright variable
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21270
2019-08-15 15:49:01 +00:00
Alan Somers
42bf965528 ping6: use the monotonic clock to measure durations
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21226
2019-08-13 19:24:17 +00:00
Alan Somers
354c349080 Consistently use the byteorder functions in the correct direction
Though ntohs and htons are functionally identical, they have different meanings.Using the correct one helps to document the code.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21219
2019-08-13 16:22:43 +00:00
Alan Somers
5e9c6b7239 ping6: Fix data type of a variable for a packet sequence number
Submitted by:   Ján Sučan <sucanjan@gmail.com>
MFC after:      2 weeks
Sponsored by:   Google, inc. (Google Summer of Code 2019)
Differential Revision:  https://reviews.freebsd.org/D21218
2019-08-13 15:30:29 +00:00
Alan Somers
17e49888f6 ping6: Fix data type of a variable for a packet sequence number
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D21218
2019-08-12 19:14:11 +00:00
Alan Somers
401d89a9e2 ping6: Remove unnecessary level of indirection from dnsdecode() parameter
The `sp' pointer doesn't need to be modified in the caller of
dnsdecode().

This fixes -Wcast-qual error (`must have all intermediate pointers
const qualified to be safe') when compiled with WARNS=6.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21215
2019-08-11 15:36:18 +00:00
Alan Somers
5e35df9474 ping6: Add missing static keyword for a global variable
This fixes -Wmissing-variable-declarations error when compiled with
WARNS=6.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21214
2019-08-11 15:27:34 +00:00
Alan Somers
0ef7ac044a ping6: Revoke root privilege earlier
It can be done just after the sockets have been created.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21213
2019-08-11 15:22:53 +00:00
Alan Somers
2943ddcf51 Capsicumize ping6
Add capsicum support to ping6, mostly copying the strategy used for ping.

Submitted by:	Ján Sučan <jansucan@gmail.com>
Reviewed by:	markj
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21050
2019-08-03 13:53:14 +00:00
Alan Somers
af58a3c6bf Remove the USE_RFC2292BIS option and reap dead code
This option was imported as part of the KAME project in r62627 (in 2000).
It was turned on unconditionally in r121472 (in 2003) and has been on ever
since. The old alternative code has bitrotted. Reap the dead code.

Reported by:	Ján Sučan <jansucan@gmail.com>
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D20938
2019-07-22 20:11:33 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Marcelo Araujo
8ac248ea27 Fix a regression introduced on revision r271909, when using argument -g
or several hops we have segmentation fault because we overwrite the same
structure to store information for host and gateway.

Submitted by:	Maryse Levavasseur <maryse.levavasseur@stormshield.eu>
Reworked by:	hrs
Approved by:	re (hrs)
Differential Revision:	https://reviews.freebsd.org/D6980
2016-07-05 07:01:42 +00:00
Marcelo Araujo
798a749aae For pointers use NULL instead of 0.
MFC after:	2 weeks.
2016-05-16 00:35:39 +00:00
Marcelo Araujo
1068140988 Use nitems() from sys/param.h.
MFC after:	2 weeks.
2016-04-19 06:34:31 +00:00
Marcelo Araujo
028d447b59 Use NULL instead of 0 for pointers.
malloc will return NULL if it cannot allocate memory.

MFC after:	2 weeks.
2016-04-19 01:57:56 +00:00
Xin LI
1ae1bd497f Use arc4random_buf(). While there, unifdef the code for HAVE_ARC4RANDOM.
MFC after:	2 weeks
2015-08-16 23:23:58 +00:00
Andrey V. Elsukov
8150c3ec36 Add ability to not specify a zone identifier twice, when both source and
destination addresses are specified.
For example:
	# ping6 -S fe80::1%ix0 ff02::1
or
	# ping6 -S fe80::1 fe80::2%ix0

Obtained from:	Yandex LLC
Sponsored by:	Yandex LLC
2014-12-16 14:59:20 +00:00
Hiroki Sato
7e9489e0f6 WARNS=3 and style fixes. No functionality change. 2014-10-20 00:27:40 +00:00
Hiroki Sato
b021de9cd7 Add -x waittime and -X timeout options for feature parity. These are
equivalent to -W and -t options of ping(8).  Different letters are used
because both have already been used for another purposes in ping6(8).
2014-10-17 09:33:09 +00:00
Hiroki Sato
0ecaa7ed05 Fix a problem that reply packets are not received when -i T option is set
and (T < RTT).

- Use select(2) for timeout instead of interval timer. Remove poll(2) support.
- Use sigaction(2) instead of signal(3).
- Exit in SIGINT handler when two signals are received and doing reverse DNS
  lookup as ping(8) does.
- Remove redundant variables used for getaddrinfo(3).

PR:	151023
2014-09-20 19:54:19 +00:00
Hiroki Sato
58da716138 Revert changes in r269180. It could cause -c N option to enter an
infinite loop if no reply packet is received.

PR:	151023
2014-09-20 18:48:50 +00:00
Xin LI
dc91b5609a When interval is set to very small value with limited amount of packets,
ping6(8) would quit before the remote side gets a chance to respond.

Solve this by resetting the itimer when we have reached the maximum packet
number have reached, but let the other handling to continue.

PR:		bin/151023
Submitted by:	tjmao at tjmao.net
MFC after:	2 weeks
2014-07-28 08:22:08 +00:00
Hiroki Sato
5df1b6b57e Use FF02:0:0:0:0:2:FF00::/104 prefix for IPv6 Node Information Group
Address.  Although KAME implementation used FF02:0:0:0:0:2::/96 based on
older versions of draft-ietf-ipngwg-icmp-name-lookup, it has been changed
in RFC 4620.

The kernel always joins the /104-prefixed address, and additionally does
/96-prefixed one only when net.inet6.icmp6.nodeinfo_oldmcprefix=1.
The default value of the sysctl is 1.

ping6(8) -N flag now uses /104-prefixed one.  When this flag is specified
twice, it uses /96-prefixed one instead.

Reviewed by:		ume
Based on work by:	Thomas Scheffler
PR:			conf/174957
MFC after:		2 weeks
2013-05-04 19:16:26 +00:00
Eitan Adler
1d1d4a4727 Check the return error of set[ug]id. While this can never fail in the
current version of FreeBSD, this isn't guarenteed by the API.  Custom
security modules, or future implementations of the setuid and setgid
may fail.

PR:		bin/172289
PR:		bin/172290
PR:		bin/172291
Submittud by:	Erik Cederstrand <erik@cederstrand.dk>
Discussed by:	freebsd-security
Approved by:	cperciva
MFC after:	1 week
2012-10-22 03:31:22 +00:00
Eitan Adler
dc70efcef7 Fix warning when compiling with gcc46:
error: variable 'origextlen' set but not used

Approved by:	dim
MFC after:	3 days
2012-01-10 02:59:01 +00:00
Ulrich Spörlein
4b85a12f71 Spelling fixes for sbin/ 2012-01-07 16:09:33 +00:00
Philippe Charnier
fe71384015 Add __unused. Ansi prototypes. 2010-12-19 13:40:38 +00:00
Joel Dahl
f041f6a7b7 Remove the advertising clause from UCB copyrighted files in sbin. This
is in accordance with the information at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
2010-12-12 21:26:12 +00:00
Rebecca Cran
99c1ee64f0 Call free and freeaddrinfo before exiting.
PR: bin/144730
PR: bin/144974
Submitted by: Earl R. Lapus <earl.lapus at gmail.com>
Approved by: rrs (mentor)
MFC after: 1 month
2010-06-16 15:49:17 +00:00
Maxim Konovalov
a8734ffdb3 o Add do-not-fragment option support to ping6(8).
PR:		bin/145759
Submitted by:	pluknet
MFC after:	1 month
2010-04-20 06:10:05 +00:00
Matteo Riondato
865bdc6208 Implement -R support, similar to ping(8)'s -A.
ping(8)'s -a was mapped to -e, but -E was already taken in ping6 (old
option) so rename -e to -r.
Now:
ping -a => ping6 -r
ping -A => ping6 -R

MFC after:	2 days
2008-08-27 15:01:23 +00:00
Matteo Riondato
248e5e18af Add -e to usage()
MFC after:	2 days
2008-08-27 13:29:43 +00:00
Matteo Riondato
155dac2fdc Implement audible support similar to ping(8) -a option. Since -a was already taken, I chose -e (no real argument for this) but I'm willing to change to a different character if needed/desired.
PR:	bin/123752 (inspired by)
MFC after:	2 days
2008-08-26 14:34:09 +00:00
Bjoern A. Zeeb
115737b173 Change the exit status for 0 and 2 to be the same as with ping(1)
and be usable in scripts, etc.

This also changes the semantics in case when we lose one of n packets.
In that case, before we exited by SIG, now we exit with return(0).

Submitted by:	Gert Doering (gert space.net)
MFC after:	10 days
2008-05-27 10:51:19 +00:00
Mike Silbersack
de625c605d Decrease ping6's minimum allowed interval
from .01 to .000001.

Note that due to the architecture of ping6,
you are still limited to kern.hz pings per
second.

MFC after: 2 weeks
2008-02-25 10:45:25 +00:00
Dima Dorfman
3ad1a3ea69 Add -o option to match ping(8)
Reviewed by:	dwmalone, maxim
MFC after:	2 weeks
2007-11-20 01:58:34 +00:00
George V. Neville-Neil
8409aedfa6 Commit IPv6 support for FAST_IPSEC to the tree.
This commit includes all remaining changes for the time being including
user space updates.

Submitted by:    bz
Approved by:    re
2007-07-01 12:08:08 +00:00