summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorChristiano F. Haesbaert <haesbaert@cvs.openbsd.org>2011-09-17 14:10:06 +0000
committerChristiano F. Haesbaert <haesbaert@cvs.openbsd.org>2011-09-17 14:10:06 +0000
commit525cf98782a1f8b20ccc43f4eb2d8a58018d3a4e (patch)
treeff730bea809d72a7628e6841abecae3bfd4f49f6 /usr.sbin
parentec1c0005e64d1684b9ceb2a5175645c525d6e3e3 (diff)
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@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/traceroute/traceroute.828
-rw-r--r--usr.sbin/traceroute/traceroute.c71
2 files changed, 83 insertions, 16 deletions
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);
}