git: 80a5b26871e9 - main - sbin/ping: allow normal users to specify larger packets
Date: Wed, 16 Oct 2024 01:06:52 UTC
The branch main has been updated by pfg:
URL: https://cgit.FreeBSD.org/src/commit/?id=80a5b26871e90a0ad99d95bd129343471a7a36e3
commit 80a5b26871e90a0ad99d95bd129343471a7a36e3
Author: Pedro F. Giffuni <pfg@FreeBSD.org>
AuthorDate: 2024-10-15 20:50:04 +0000
Commit: Pedro F. Giffuni <pfg@FreeBSD.org>
CommitDate: 2024-10-16 01:05:50 +0000
sbin/ping: allow normal users to specify larger packets
Only super-user could specify a packet size larger than the default 56 bytes.
This restriction was added by Matt Dillon in 1998 during the BEST days [0].
This restriction doesn't exist in ping IPV6 or on NetBSD, OpenBSD and Linux.
UMS [1] uses this feature to estimate the client's bandwidth to optimize the
streaming experience.
[0] DFGit 526f06b278d9252add168aa18b60242c08771165
[1] UMS: https://github.com/UniversalMediaServer/UniversalMediaServer
Obtained from: DragonFlyBSD
Differential Revision: https://reviews.freebsd.org/D45774
---
sbin/ping/ping.8 | 3 +--
sbin/ping/ping.c | 11 +++++------
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/sbin/ping/ping.8 b/sbin/ping/ping.8
index 0eaec196e1e3..951049d0f252 100644
--- a/sbin/ping/ping.8
+++ b/sbin/ping/ping.8
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd September 15, 2023
+.Dd October 15, 2024
.Dt PING 8
.Os
.Sh NAME
@@ -312,7 +312,6 @@ with the 8 bytes of
ICMP
header data.
.Pp
-For IPv4, only the super-user may specify values more than default.
This option cannot be used with ping sweeps.
.Pp
For IPv6, you may need to specify
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index d9d544bc75c8..e6b1247af497 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -96,8 +96,8 @@
#define DEFDATALEN 56 /* default data length */
#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */
/* runs out of buffer space */
-#define MAXIPLEN (sizeof(struct ip) + MAX_IPOPTLEN)
-#define MAXICMPLEN (ICMP_ADVLENMIN + MAX_IPOPTLEN)
+#define MAXIPLEN ((int)sizeof(struct ip) + MAX_IPOPTLEN)
+#define MAXPAYLOAD (IP_MAXPACKET - MAXIPLEN - ICMP_MINLEN)
#define MAXWAIT 10000 /* max ms to wait for response */
#define MAXALARM (60 * 60) /* max seconds for alarm timeout */
#define MAXTOS 255
@@ -458,11 +458,10 @@ ping(int argc, char *const *argv)
errx(EX_USAGE, "invalid packet size: `%s'",
optarg);
datalen = (int)ltmp;
- if (uid != 0 && datalen > DEFDATALEN) {
- errno = EPERM;
- err(EX_NOPERM,
+ if (datalen > MAXPAYLOAD) {
+ errx(EX_USAGE,
"packet size too large: %d > %u",
- datalen, DEFDATALEN);
+ datalen, MAXPAYLOAD);
}
break;
case 'T': /* multicast TTL */