summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2018-11-10 05:03:23 +0000
committerdlg <dlg@openbsd.org>2018-11-10 05:03:23 +0000
commit73ce99fb33cdab213019b4b2ada628f6cc0283f0 (patch)
treebf7a979f5991d3cb5838426f8f89abec3c8eeaf7
parentClean up and free objects at the completion of the regress test. (diff)
downloadwireguard-openbsd-73ce99fb33cdab213019b4b2ada628f6cc0283f0.tar.xz
wireguard-openbsd-73ce99fb33cdab213019b4b2ada628f6cc0283f0.zip
add support for setting the traffic class on ipv6 packets.
it reuses the toskeyword handling that ipv4 uses for setting the tos field, which is equiavlent to traffic class. ok florian@ denis@
-rw-r--r--sbin/ping/ping.88
-rw-r--r--sbin/ping/ping.c17
-rw-r--r--usr.sbin/traceroute/traceroute.86
-rw-r--r--usr.sbin/traceroute/traceroute.c18
4 files changed, 32 insertions, 17 deletions
diff --git a/sbin/ping/ping.8 b/sbin/ping/ping.8
index 36c3a8237d8..e5f58fdc434 100644
--- a/sbin/ping/ping.8
+++ b/sbin/ping/ping.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ping.8,v 1.59 2016/10/26 16:18:45 jmc Exp $
+.\" $OpenBSD: ping.8,v 1.60 2018/11/10 05:03:23 dlg Exp $
.\" $NetBSD: ping.8,v 1.10 1995/12/31 04:55:35 ghudson Exp $
.\"
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -57,7 +57,7 @@
.\"
.\" @(#)ping.8 8.2 (Berkeley) 12/11/93
.\"
-.Dd $Mdocdate: October 26 2016 $
+.Dd $Mdocdate: November 10 2018 $
.Dt PING 8
.Os
.Sh NAME
@@ -87,6 +87,7 @@
.Op Fl l Ar preload
.Op Fl p Ar pattern
.Op Fl s Ar packetsize
+.Op Fl T Ar toskeyword
.Op Fl V Ar rtable
.Op Fl w Ar maxwait
.Ar host
@@ -221,8 +222,7 @@ which translates into 64 ICMP data bytes
when combined with the 8 bytes of ICMP header data.
The maximum packet size is 65467 for IPv4 and 65527 for IPv6.
.It Fl T Ar toskeyword
-.Pq IPv4 only
-Change the TOS value.
+Change the IPv4 TOS or IPv6 Traffic Class value.
.Ar toskeyword
may be one of
.Cm critical ,
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index 5dfbb02eef7..cde44350a5a 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ping.c,v 1.230 2018/10/14 19:47:53 kn Exp $ */
+/* $OpenBSD: ping.c,v 1.231 2018/11/10 05:03:23 dlg Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -150,7 +150,7 @@ int options;
/* 0x0200 */
#define F_HDRINCL 0x0400
#define F_TTL 0x0800
-/* 0x1000 */
+#define F_TOS 0x1000
#define F_AUD_RECV 0x2000
#define F_AUD_MISS 0x4000
@@ -291,7 +291,7 @@ main(int argc, char *argv[])
preload = 0;
datap = &outpack[ECHOLEN + ECHOTMLEN];
while ((ch = getopt(argc, argv, v6flag ?
- "c:dEefHh:I:i:Ll:mNnp:qS:s:V:vw:" :
+ "c:dEefHh:I:i:Ll:mNnp:qS:s:T:V:vw:" :
"DEI:LRS:c:defHi:l:np:qs:T:t:V:vw:")) != -1) {
switch(ch) {
case 'c':
@@ -386,6 +386,7 @@ main(int argc, char *argv[])
#ifndef SMALL
case 'T':
options |= F_HDRINCL;
+ options |= F_TOS;
errno = 0;
errstr = NULL;
if (map_tos(optarg, &tos))
@@ -673,6 +674,13 @@ main(int argc, char *argv[])
*(int *)(CMSG_DATA(scmsg)) = hoplimit;
}
+ if (options & F_TOS) {
+ optval = tos;
+ if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &optval,
+ (socklen_t)sizeof(optval)) < 0)
+ warn("setsockopt(IPV6_TVAL)"); /* XXX err? */
+ }
+
optval = 1;
if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &optval,
(socklen_t)sizeof(optval)) < 0)
@@ -2160,7 +2168,8 @@ usage(void)
fprintf(stderr,
"usage: ping6 [-dEefHLmnqv] [-c count] [-h hoplimit] "
"[-I sourceaddr]\n\t[-i wait] [-l preload] [-p pattern] "
- "[-s packetsize] [-V rtable]\n\t[-w maxwait] host\n");
+ "[-s packetsize] [-T toskeyword]\n\t"
+ "[-V rtable] [-w maxwait] host\n");
} else {
fprintf(stderr,
"usage: ping [-DdEefHLnqRv] [-c count] [-I ifaddr]"
diff --git a/usr.sbin/traceroute/traceroute.8 b/usr.sbin/traceroute/traceroute.8
index 4422a2d7c0a..835d0e28c4c 100644
--- a/usr.sbin/traceroute/traceroute.8
+++ b/usr.sbin/traceroute/traceroute.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: traceroute.8,v 1.66 2016/10/21 09:26:36 jmc Exp $
+.\" $OpenBSD: traceroute.8,v 1.67 2018/11/10 05:03:23 dlg Exp $
.\" $NetBSD: traceroute.8,v 1.6 1995/10/12 03:05:50 mycroft Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
@@ -33,7 +33,7 @@
.\"
.\" @(#)traceroute.8 8.1 (Berkeley) 6/6/93
.\"
-.Dd $Mdocdate: October 21 2016 $
+.Dd $Mdocdate: November 10 2018 $
.Dt TRACEROUTE 8
.Os
.Sh NAME
@@ -62,6 +62,7 @@
.Op Fl p Ar port
.Op Fl q Ar nqueries
.Op Fl s Ar src_addr
+.Op Fl t Ar toskeyword
.Op Fl V Ar rtable
.Op Fl w Ar waittime
.Ar host
@@ -196,7 +197,6 @@ Useful values are probably
.Cm lowdelay
and
.Cm throughput .
-This option is not available for IPv6.
.It Fl V Ar rtable
Set the routing table to be used.
.It Fl v
diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c
index cd02cd9afa0..02fb48dfb5d 100644
--- a/usr.sbin/traceroute/traceroute.c
+++ b/usr.sbin/traceroute/traceroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: traceroute.c,v 1.157 2018/10/20 19:55:01 kn Exp $ */
+/* $OpenBSD: traceroute.c,v 1.158 2018/11/10 05:03:23 dlg Exp $ */
/* $NetBSD: traceroute.c,v 1.10 1995/05/21 15:50:45 mycroft Exp $ */
/*
@@ -414,7 +414,7 @@ main(int argc, char *argv[])
err(1, "sysctl");
conf->max_ttl = i;
- while ((ch = getopt(argc, argv, v6flag ? "AcDdf:Ilm:np:q:Ss:w:vV:" :
+ while ((ch = getopt(argc, argv, v6flag ? "AcDdf:Ilm:np:q:Ss:t:w:vV:" :
"AcDdf:g:Ilm:nP:p:q:Ss:t:V:vw:x")) != -1)
switch (ch) {
case 'A':
@@ -802,6 +802,12 @@ main(int argc, char *argv[])
0)
err(1, "bind sndsock");
+ if (conf->tflag) {
+ if (setsockopt(sndsock, IPPROTO_IPV6, IPV6_TCLASS,
+ &conf->tos, sizeof(conf->tos)) < 0)
+ err(6, "IPV6_TCLASS");
+ }
+
len = sizeof(from6);
if (getsockname(sndsock, (struct sockaddr *)&from6, &len) < 0)
err(1, "getsockname");
@@ -943,10 +949,10 @@ void
usage(int v6flag)
{
if (v6flag) {
- fprintf(stderr, "usage: traceroute6 [-AcDdIlnSv] [-f first_hop] "
- "[-m max_hop] [-p port]\n"
- "\t[-q nqueries] [-s src_addr] [-V rtable] [-w waittime] "
- "host\n\t[datalen]\n");
+ fprintf(stderr, "usage: %s "
+ "[-AcDdIlnSv] [-f first_hop] [-m max_hop] [-p port]\n"
+ "\t[-q nqueries] [-s src_addr] [-t toskeyword] [-V rtable] "
+ "[-w waittime]\n\thost [datalen]\n", __progname);
} else {
fprintf(stderr,
"usage: %s [-AcDdIlnSvx] [-f first_ttl] [-g gateway_addr] "