summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhaesbaert <haesbaert@openbsd.org>2011-09-17 14:10:05 +0000
committerhaesbaert <haesbaert@openbsd.org>2011-09-17 14:10:05 +0000
commit68ddffc5297781f6308b15cc99b235c70ee6482e (patch)
tree12b11210a0486fa222ca54852cabf4c606e0c26f
parentAdd SMALL infrastructure to ping. (diff)
downloadwireguard-openbsd-68ddffc5297781f6308b15cc99b235c70ee6482e.tar.xz
wireguard-openbsd-68ddffc5297781f6308b15cc99b235c70ee6482e.zip
Standarize the ToS option across nc/ping/traceroute so that they'll
accept the same values as pf.conf. It accepts decimal, hexadecimal and the dscp/tos keywords. The ping option was ripped of in SMALL. ok mcbride@ sthen@
-rw-r--r--sbin/ping/ping.823
-rw-r--r--sbin/ping/ping.c79
-rw-r--r--usr.bin/nc/nc.129
-rw-r--r--usr.bin/nc/netcat.c76
-rw-r--r--usr.sbin/traceroute/traceroute.828
-rw-r--r--usr.sbin/traceroute/traceroute.c71
6 files changed, 251 insertions, 55 deletions
diff --git a/sbin/ping/ping.8 b/sbin/ping/ping.8
index a34319fd2c5..3bd9bc1928d 100644
--- a/sbin/ping/ping.8
+++ b/sbin/ping/ping.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ping.8,v 1.45 2010/07/03 04:44:51 guenther Exp $
+.\" $OpenBSD: ping.8,v 1.46 2011/09/17 14:10:05 haesbaert Exp $
.\" $NetBSD: ping.8,v 1.10 1995/12/31 04:55:35 ghudson Exp $
.\"
.\" Copyright (c) 1985, 1991, 1993
@@ -30,7 +30,7 @@
.\"
.\" @(#)ping.8 8.2 (Berkeley) 12/11/93
.\"
-.Dd $Mdocdate: July 3 2010 $
+.Dd $Mdocdate: September 17 2011 $
.Dt PING 8
.Os
.Sh NAME
@@ -46,7 +46,7 @@
.Op Fl l Ar preload
.Op Fl p Ar pattern
.Op Fl s Ar packetsize
-.Op Fl T Ar tos
+.Op Fl T Ar toskeyword
.Op Fl t Ar ttl
.Op Fl V Ar rtable
.Op Fl w Ar maxwait
@@ -180,8 +180,21 @@ Specifies the number of data bytes to be sent.
The default is 56,
which translates into 64 ICMP data bytes
when combined with the 8 bytes of ICMP header data.
-.It Fl T Ar tos
-Use the specified type of service.
+.It Fl T Ar toskeyword
+Change IPv4 TOS value.
+.Ar toskeyword
+may be one of
+.Ar critical ,
+.Ar inetcontrol ,
+.Ar lowdelay ,
+.Ar netcontrol ,
+.Ar throughput ,
+.Ar reliability ,
+or one of the DiffServ Code Points:
+.Ar ef ,
+.Ar af11 ... af43 ,
+.Ar cs0 ... cs7 ;
+or a number in either hex or decimal.
.It Fl t Ar ttl
Use the specified time-to-live.
.It Fl V Ar rtable
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index ec63faf5353..604fd1d883e 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ping.c,v 1.89 2011/06/21 17:31:07 mikeb Exp $ */
+/* $OpenBSD: ping.c,v 1.90 2011/09/17 14:10:05 haesbaert Exp $ */
/* $NetBSD: ping.c,v 1.20 1995/08/11 22:37:58 cgd Exp $ */
/*
@@ -168,6 +168,9 @@ void pr_pack(char *, int, struct sockaddr_in *);
void pr_retip(struct ip *);
quad_t qsqrt(quad_t);
void pr_iph(struct ip *);
+#ifndef SMALL
+int map_tos(char *, int *);
+#endif /* SMALL */
void usage(void);
int
@@ -293,12 +296,23 @@ main(int argc, char *argv[])
errx(1, "packet size is %s: %s",
errstr, optarg);
break;
+#ifndef SMALL
case 'T':
options |= F_HDRINCL;
- tos = (int)strtonum(optarg, 0, 0xff, &errstr);
- if (errstr)
- errx(1, "tos value is %s: %s", errstr, optarg);
+ errno = 0;
+ errstr = NULL;
+ if (map_tos(optarg, &tos))
+ break;
+ if (strlen(optarg) > 1 && optarg[0] == '0' &&
+ optarg[1] == 'x')
+ tos = (int)strtol(optarg, NULL, 16);
+ else
+ tos = (int)strtonum(optarg, 0, 255,
+ &errstr);
+ if (tos < 0 || tos > 255 || errstr || errno)
+ errx(1, "illegal tos value %s", optarg);
break;
+#endif /* SMALL */
case 't':
options |= F_TTL;
ttl = (u_char)strtonum(optarg, 1, 255, &errstr);
@@ -1359,12 +1373,65 @@ check_icmph(struct ip *iph)
return 1;
}
+#ifndef SMALL
+int
+map_tos(char *s, int *val)
+{
+ /* DiffServ Codepoints and other TOS mappings */
+ const struct toskeywords {
+ const char *keyword;
+ int val;
+ } *t, toskeywords[] = {
+ { "af11", IPTOS_DSCP_AF11 },
+ { "af12", IPTOS_DSCP_AF12 },
+ { "af13", IPTOS_DSCP_AF13 },
+ { "af21", IPTOS_DSCP_AF21 },
+ { "af22", IPTOS_DSCP_AF22 },
+ { "af23", IPTOS_DSCP_AF23 },
+ { "af31", IPTOS_DSCP_AF31 },
+ { "af32", IPTOS_DSCP_AF32 },
+ { "af33", IPTOS_DSCP_AF33 },
+ { "af41", IPTOS_DSCP_AF41 },
+ { "af42", IPTOS_DSCP_AF42 },
+ { "af43", IPTOS_DSCP_AF43 },
+ { "critical", IPTOS_PREC_CRITIC_ECP },
+ { "cs0", IPTOS_DSCP_CS0 },
+ { "cs1", IPTOS_DSCP_CS1 },
+ { "cs2", IPTOS_DSCP_CS2 },
+ { "cs3", IPTOS_DSCP_CS3 },
+ { "cs4", IPTOS_DSCP_CS4 },
+ { "cs5", IPTOS_DSCP_CS5 },
+ { "cs6", IPTOS_DSCP_CS6 },
+ { "cs7", IPTOS_DSCP_CS7 },
+ { "ef", IPTOS_DSCP_EF },
+ { "inetcontrol", IPTOS_PREC_INTERNETCONTROL },
+ { "lowdelay", IPTOS_LOWDELAY },
+ { "netcontrol", IPTOS_PREC_NETCONTROL },
+ { "reliability", IPTOS_RELIABILITY },
+ { "throughput", IPTOS_THROUGHPUT },
+ { NULL, -1 },
+ };
+
+ for (t = toskeywords; t->keyword != NULL; t++) {
+ if (strcmp(s, t->keyword) == 0) {
+ *val = t->val;
+ return (1);
+ }
+ }
+
+ return (0);
+}
+#endif /* SMALL */
+
void
usage(void)
{
(void)fprintf(stderr,
"usage: ping [-DdEefLnqRrv] [-c count] [-I ifaddr] [-i wait]\n"
- "\t[-l preload] [-p pattern] [-s packetsize] [-T tos] [-t ttl]\n"
- "\t[-V rtable] [-w maxwait] host\n");
+ "\t[-l preload] [-p pattern] [-s packetsize]"
+#ifndef SMALL
+ " [-T toskeyword]"
+#endif /* SMALL */
+ "\n\t[-t ttl] [-V rtable] [-w maxwait] host\n");
exit(1);
}
diff --git a/usr.bin/nc/nc.1 b/usr.bin/nc/nc.1
index f9bd5b153ea..6a1538cb456 100644
--- a/usr.bin/nc/nc.1
+++ b/usr.bin/nc/nc.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: nc.1,v 1.57 2011/01/09 22:16:46 jeremy Exp $
+.\" $OpenBSD: nc.1,v 1.58 2011/09/17 14:10:05 haesbaert Exp $
.\"
.\" Copyright (c) 1996 David Sacerdote
.\" All rights reserved.
@@ -25,7 +25,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: January 9 2011 $
+.Dd $Mdocdate: September 17 2011 $
.Dt NC 1
.Os
.Sh NAME
@@ -41,7 +41,7 @@
.Op Fl P Ar proxy_username
.Op Fl p Ar source_port
.Op Fl s Ar source
-.Op Fl T Ar ToS
+.Op Fl T Ar toskeyword
.Op Fl V Ar rtable
.Op Fl w Ar timeout
.Op Fl X Ar proxy_protocol
@@ -164,14 +164,21 @@ to create and use so that datagrams can be received.
It is an error to use this option in conjunction with the
.Fl l
option.
-.It Fl T Ar ToS
-Specifies IP Type of Service (ToS) for the connection.
-Valid values are the tokens
-.Dq lowdelay ,
-.Dq throughput ,
-.Dq reliability ,
-or an 8-bit hexadecimal value preceded by
-.Dq 0x .
+.It Fl T Ar toskeyword
+Change IPv4 TOS value.
+.Ar toskeyword
+may be one of
+.Ar critical ,
+.Ar inetcontrol ,
+.Ar lowdelay ,
+.Ar netcontrol ,
+.Ar throughput ,
+.Ar reliability ,
+or one of the DiffServ Code Points:
+.Ar ef ,
+.Ar af11 ... af43 ,
+.Ar cs0 ... cs7 ;
+or a number in either hex or decimal.
.It Fl t
Causes
.Nm
diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
index a5f5745f3ad..952bfb7dda0 100644
--- a/usr.bin/nc/netcat.c
+++ b/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netcat.c,v 1.101 2011/06/21 17:31:07 mikeb Exp $ */
+/* $OpenBSD: netcat.c,v 1.102 2011/09/17 14:10:05 haesbaert Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
*
@@ -105,7 +105,7 @@ int unix_bind(char *);
int unix_connect(char *);
int unix_listen(char *);
void set_common_sockopts(int);
-int parse_iptos(char *);
+int map_tos(char *, int *);
void usage(int);
int
@@ -234,7 +234,18 @@ main(int argc, char *argv[])
Sflag = 1;
break;
case 'T':
- Tflag = parse_iptos(optarg);
+ errstr = NULL;
+ errno = 0;
+ if (map_tos(optarg, &Tflag))
+ break;
+ if (strlen(optarg) > 1 && optarg[0] == '0' &&
+ optarg[1] == 'x')
+ Tflag = (int)strtol(optarg, NULL, 16);
+ else
+ Tflag = (int)strtonum(optarg, 0, 255,
+ &errstr);
+ if (Tflag < 0 || Tflag > 255 || errstr || errno)
+ errx(1, "illegal tos value %s", optarg);
break;
default:
usage(1);
@@ -874,20 +885,51 @@ set_common_sockopts(int s)
}
int
-parse_iptos(char *s)
+map_tos(char *s, int *val)
{
- int tos = -1;
-
- if (strcmp(s, "lowdelay") == 0)
- return (IPTOS_LOWDELAY);
- if (strcmp(s, "throughput") == 0)
- return (IPTOS_THROUGHPUT);
- if (strcmp(s, "reliability") == 0)
- return (IPTOS_RELIABILITY);
-
- if (sscanf(s, "0x%x", &tos) != 1 || tos < 0 || tos > 0xff)
- errx(1, "invalid IP Type of Service");
- return (tos);
+ /* DiffServ Codepoints and other TOS mappings */
+ const struct toskeywords {
+ const char *keyword;
+ int val;
+ } *t, toskeywords[] = {
+ { "af11", IPTOS_DSCP_AF11 },
+ { "af12", IPTOS_DSCP_AF12 },
+ { "af13", IPTOS_DSCP_AF13 },
+ { "af21", IPTOS_DSCP_AF21 },
+ { "af22", IPTOS_DSCP_AF22 },
+ { "af23", IPTOS_DSCP_AF23 },
+ { "af31", IPTOS_DSCP_AF31 },
+ { "af32", IPTOS_DSCP_AF32 },
+ { "af33", IPTOS_DSCP_AF33 },
+ { "af41", IPTOS_DSCP_AF41 },
+ { "af42", IPTOS_DSCP_AF42 },
+ { "af43", IPTOS_DSCP_AF43 },
+ { "critical", IPTOS_PREC_CRITIC_ECP },
+ { "cs0", IPTOS_DSCP_CS0 },
+ { "cs1", IPTOS_DSCP_CS1 },
+ { "cs2", IPTOS_DSCP_CS2 },
+ { "cs3", IPTOS_DSCP_CS3 },
+ { "cs4", IPTOS_DSCP_CS4 },
+ { "cs5", IPTOS_DSCP_CS5 },
+ { "cs6", IPTOS_DSCP_CS6 },
+ { "cs7", IPTOS_DSCP_CS7 },
+ { "ef", IPTOS_DSCP_EF },
+ { "inetcontrol", IPTOS_PREC_INTERNETCONTROL },
+ { "lowdelay", IPTOS_LOWDELAY },
+ { "netcontrol", IPTOS_PREC_NETCONTROL },
+ { "reliability", IPTOS_RELIABILITY },
+ { "throughput", IPTOS_THROUGHPUT },
+ { NULL, -1 },
+ };
+
+ for (t = toskeywords; t->keyword != NULL; t++) {
+ if (strcmp(s, t->keyword) == 0) {
+ *val = t->val;
+ return (1);
+ }
+ }
+
+ return (0);
}
void
@@ -911,7 +953,7 @@ help(void)
\t-r Randomize remote ports\n\
\t-S Enable the TCP MD5 signature option\n\
\t-s addr\t Local source address\n\
- \t-T ToS\t Set IP Type of Service\n\
+ \t-T toskeyword\tSet IP Type of Service\n\
\t-t Answer TELNET negotiation\n\
\t-U Use UNIX domain socket\n\
\t-u UDP mode\n\
diff --git a/usr.sbin/traceroute/traceroute.8 b/usr.sbin/traceroute/traceroute.8
index 685d7272765..a41cc201491 100644
--- a/usr.sbin/traceroute/traceroute.8
+++ b/usr.sbin/traceroute/traceroute.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: traceroute.8,v 1.45 2011/04/06 12:05:00 sthen Exp $
+.\" $OpenBSD: traceroute.8,v 1.46 2011/09/17 14:10:05 haesbaert 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: April 6 2011 $
+.Dd $Mdocdate: September 17 2011 $
.Dt TRACEROUTE 8
.Os
.Sh NAME
@@ -50,7 +50,7 @@
.Op Fl p Ar port
.Op Fl q Ar nqueries
.Op Fl s Ar src_addr
-.Op Fl t Ar tos
+.Op Fl t Ar toskeyword
.Op Fl V Ar rtable
.Op Fl w Ar waittime
.Ar host
@@ -170,11 +170,22 @@ of the interface the probe packet is sent on.
If the IP address
is not one of this machine's interface addresses and the user is
not the superuser, an error is returned and nothing is sent.
-.It Fl t Ar tos
+.It Fl t Ar toskeyword
Set the
.Em type-of-service
in probe packets to the following value (default zero).
-The value must be a decimal integer in the range 0 to 255.
+The value may be one of
+.Ar critical ,
+.Ar inetcontrol ,
+.Ar lowdelay ,
+.Ar netcontrol ,
+.Ar throughput ,
+.Ar reliability ,
+or one of the DiffServ Code Points:
+.Ar ef ,
+.Ar af11 ... af43 ,
+.Ar cs0 ... cs7 ;
+or a number in either hex or decimal.
This option can be used to
see if different types-of-service result in different paths.
If this option is used, changes to the type-of-service in the
@@ -189,10 +200,9 @@ Not all values of
are legal or
meaningful \- see the IP spec for definitions.
Useful values are probably
-.Ql -t 16
-(low delay) and
-.Ql -t 8
-(high throughput).
+.Ar lowdelay
+and
+.Ar throughput.
.It Fl V Ar rtable
Set the routing table to be used.
The default is 0.
diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c
index fef9d8d2db7..e55cfa4a26c 100644
--- a/usr.sbin/traceroute/traceroute.c
+++ b/usr.sbin/traceroute/traceroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: traceroute.c,v 1.77 2011/06/21 17:31:07 mikeb Exp $ */
+/* $OpenBSD: traceroute.c,v 1.78 2011/09/17 14:10:05 haesbaert Exp $ */
/* $NetBSD: traceroute.c,v 1.10 1995/05/21 15:50:45 mycroft Exp $ */
/*-
@@ -261,6 +261,7 @@ void print_exthdr(u_char *, int);
void print(u_char *, int, struct sockaddr_in *);
char *inetname(struct in_addr);
u_short in_cksum(u_short *, int);
+int map_tos(char *, int *);
void usage(void);
int s; /* receive (icmp) socket file descriptor */
@@ -425,13 +426,21 @@ main(int argc, char *argv[])
source = optarg;
break;
case 't':
+ if (!map_tos(optarg, &tos)) {
errno = 0;
- ep = NULL;
- l = strtol(optarg, &ep, 10);
- if (errno || !*optarg || *ep || l < 0 || l > 255)
- errx(1, "tos must be 0 to 255.");
- last_tos = tos = (int)l;
+ errstr = NULL;
+ if (strlen(optarg) > 1 && optarg[0] == '0' &&
+ optarg[1] == 'x')
+ tos = (int)strtol(optarg, NULL, 16);
+ else
+ tos = (int)strtonum(optarg, 0, 255,
+ &errstr);
+ if (tos < 0 || tos > 255 || errstr || errno)
+ errx(1, "illegal tos value %s",
+ optarg);
+ }
tflag = 1;
+ last_tos = tos;
break;
case 'v':
verbose++;
@@ -1174,6 +1183,54 @@ inetname(struct in_addr in)
return (inet_ntoa(in));
}
+int
+map_tos(char *s, int *val)
+{
+ /* DiffServ Codepoints and other TOS mappings */
+ const struct toskeywords {
+ const char *keyword;
+ int val;
+ } *t, toskeywords[] = {
+ { "af11", IPTOS_DSCP_AF11 },
+ { "af12", IPTOS_DSCP_AF12 },
+ { "af13", IPTOS_DSCP_AF13 },
+ { "af21", IPTOS_DSCP_AF21 },
+ { "af22", IPTOS_DSCP_AF22 },
+ { "af23", IPTOS_DSCP_AF23 },
+ { "af31", IPTOS_DSCP_AF31 },
+ { "af32", IPTOS_DSCP_AF32 },
+ { "af33", IPTOS_DSCP_AF33 },
+ { "af41", IPTOS_DSCP_AF41 },
+ { "af42", IPTOS_DSCP_AF42 },
+ { "af43", IPTOS_DSCP_AF43 },
+ { "critical", IPTOS_PREC_CRITIC_ECP },
+ { "cs0", IPTOS_DSCP_CS0 },
+ { "cs1", IPTOS_DSCP_CS1 },
+ { "cs2", IPTOS_DSCP_CS2 },
+ { "cs3", IPTOS_DSCP_CS3 },
+ { "cs4", IPTOS_DSCP_CS4 },
+ { "cs5", IPTOS_DSCP_CS5 },
+ { "cs6", IPTOS_DSCP_CS6 },
+ { "cs7", IPTOS_DSCP_CS7 },
+ { "ef", IPTOS_DSCP_EF },
+ { "inetcontrol", IPTOS_PREC_INTERNETCONTROL },
+ { "lowdelay", IPTOS_LOWDELAY },
+ { "netcontrol", IPTOS_PREC_NETCONTROL },
+ { "reliability", IPTOS_RELIABILITY },
+ { "throughput", IPTOS_THROUGHPUT },
+ { NULL, -1 },
+ };
+
+ for (t = toskeywords; t->keyword != NULL; t++) {
+ if (strcmp(s, t->keyword) == 0) {
+ *val = t->val;
+ return (1);
+ }
+ }
+
+ return (0);
+}
+
void
usage(void)
{
@@ -1181,7 +1238,7 @@ usage(void)
fprintf(stderr,
"usage: %s [-cDdIlnrSvx] [-f first_ttl] [-g gateway_addr] [-m max_ttl]\n"
- "\t[-P proto] [-p port] [-q nqueries] [-s src_addr] [-t tos]\n"
+ "\t[-P proto] [-p port] [-q nqueries] [-s src_addr] [-t toskeyword]\n"
"\t[-V rtable] [-w waittime] host [packetsize]\n", __progname);
exit(1);
}