From 6cf2cbbbc9bc15854b3eb466cbed03be251c17cc Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 13 Oct 2015 16:26:54 +0000 Subject: [PATCH] Remove -b flag and let ping6 set the socket buffer size automatically like ping. Suggested by deraadt@, OK dlg --- sbin/ping6/ping6.8 | 7 ++---- sbin/ping6/ping6.c | 61 +++++++++++++++++----------------------------- 2 files changed, 25 insertions(+), 43 deletions(-) diff --git a/sbin/ping6/ping6.8 b/sbin/ping6/ping6.8 index 50693a23c9a..0bd6703442b 100644 --- a/sbin/ping6/ping6.8 +++ b/sbin/ping6/ping6.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ping6.8,v 1.50 2015/10/12 18:32:18 deraadt Exp $ +.\" $OpenBSD: ping6.8,v 1.51 2015/10/13 16:26:54 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 12 2015 $ +.Dd $Mdocdate: October 13 2015 $ .Dt PING6 8 .Os .Sh NAME @@ -38,7 +38,6 @@ .Nm ping6 .Op Fl dEefHmNnqtvw .Op Fl a Ar addrtype -.Op Fl b Ar bufsiz .Op Fl c Ar count .Op Fl g Ar gateway .Op Fl h Ar hoplimit @@ -96,8 +95,6 @@ Requests responder's link-local addresses. .It Ic s Requests responder's site-local addresses. .El -.It Fl b Ar bufsiz -Set the socket buffer size. .It Fl c Ar count Stop after sending .Pq and receiving diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index 76d83fbabf5..fcb028a34fd 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.121 2015/10/12 18:32:18 deraadt Exp $ */ +/* $OpenBSD: ping6.c,v 1.122 2015/10/13 16:26:54 florian Exp $ */ /* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */ /* @@ -244,14 +244,13 @@ main(int argc, char *argv[]) struct itimerval itimer; struct sockaddr_in6 from; struct addrinfo hints; - int ch, i, packlen, preload, optval, error; + int ch, i, maxsize, packlen, preload, optval, error; + socklen_t maxsizelen; u_char *datap, *packet; char *e, *target, *ifname = NULL, *gateway = NULL; const char *errstr; int ip6optlen = 0; struct cmsghdr *scmsgp = NULL; - u_long lsockbufsize; - int sockbufsize = 0; int usepktinfo = 0; struct in6_pktinfo *pktinfo = NULL; double intval; @@ -270,7 +269,7 @@ main(int argc, char *argv[]) preload = 0; datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN]; while ((ch = getopt(argc, argv, - "a:b:c:dEefHg:h:I:i:l:mnNp:qS:s:tvV:w")) != -1) { + "a:c:dEefHg:h:I:i:l:mnNp:qS:s:tvV:w")) != -1) { switch (ch) { case 'a': { @@ -309,15 +308,6 @@ main(int argc, char *argv[]) } break; } - case 'b': - errno = 0; - e = NULL; - lsockbufsize = strtoul(optarg, &e, 10); - sockbufsize = lsockbufsize; - if (errno || !*optarg || *e || - sockbufsize != lsockbufsize) - errx(1, "invalid socket buffer size"); - break; case 'c': npackets = strtonum(optarg, 0, INT_MAX, &errstr); if (errstr) @@ -568,6 +558,24 @@ main(int argc, char *argv[]) if (!(packet = malloc(packlen))) err(1, "Unable to allocate packet"); + + /* + * When trying to send large packets, you must increase the + * size of both the send and receive buffers... + */ + maxsizelen = sizeof maxsize; + if (getsockopt(s, SOL_SOCKET, SO_SNDBUF, &maxsize, &maxsizelen) < 0) + err(1, "getsockopt"); + if (maxsize < packlen && + setsockopt(s, SOL_SOCKET, SO_SNDBUF, &packlen, sizeof(maxsize)) < 0) + err(1, "setsockopt"); + + if (getsockopt(s, SOL_SOCKET, SO_RCVBUF, &maxsize, &maxsizelen) < 0) + err(1, "getsockopt"); + if (maxsize < packlen && + setsockopt(s, SOL_SOCKET, SO_RCVBUF, &packlen, sizeof(maxsize)) < 0) + err(1, "setsockopt"); + if (!(options & F_PINGFILLED)) for (i = ICMP6ECHOLEN; i < packlen; ++i) *datap++ = i; @@ -710,29 +718,6 @@ main(int argc, char *argv[]) close(dummy); } - if (sockbufsize) { - if (datalen > sockbufsize) - warnx("you need -b to increase socket buffer size"); - if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &sockbufsize, - (socklen_t)sizeof(sockbufsize)) < 0) - err(1, "setsockopt(SO_SNDBUF)"); - if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &sockbufsize, - (socklen_t)sizeof(sockbufsize)) < 0) - err(1, "setsockopt(SO_RCVBUF)"); - } else { - if (datalen > 8 * 1024) /*XXX*/ - warnx("you need -b to increase socket buffer size"); - /* - * When pinging the broadcast address, you can get a lot of - * answers. Doing something so evil is useful if you are trying - * to stress the ethernet, or just want to fill the arp cache - * to get some stuff for /etc/ethers. - */ - optval = 48 * 1024; - setsockopt(s, SOL_SOCKET, SO_RCVBUF, &optval, - (socklen_t)sizeof(optval)); - } - optval = 1; if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &optval, (socklen_t)sizeof(optval)) < 0) @@ -2355,7 +2340,7 @@ usage(void) "usage: ping6 [-dEefH" "m" "Nnqtvw" - "] [-a addrtype] [-b bufsiz] [-c count] [-g gateway]\n\t" + "] [-a addrtype] [-c count] [-g gateway]\n\t" "[-h hoplimit] [-I interface] [-i wait] [-l preload] [-p pattern]" "\n\t[-S sourceaddr] [-s packetsize] [-V rtable] host\n"); exit(1); -- 2.20.1