Module Name: src Committed By: pooka Date: Wed Dec 15 00:09:42 UTC 2010
Modified Files: src/usr.sbin/traceroute: Makefile traceroute.c Added Files: src/usr.sbin/traceroute: prog_ops.h traceroute_hostops.c traceroute_rumpops.c Log Message: Use RUMPPRG. I think it's safe to say there's not going to be a new upstream version of traceroute to import. AS# lookup is still done using host networking. Rationale: the relevance to where that data comes from with respect to network tracing is zero (be it socket, local file, db, whatever). To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/traceroute/Makefile cvs rdiff -u -r0 -r1.1 src/usr.sbin/traceroute/prog_ops.h \ src/usr.sbin/traceroute/traceroute_hostops.c \ src/usr.sbin/traceroute/traceroute_rumpops.c cvs rdiff -u -r1.75 -r1.76 src/usr.sbin/traceroute/traceroute.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/traceroute/Makefile diff -u src/usr.sbin/traceroute/Makefile:1.16 src/usr.sbin/traceroute/Makefile:1.17 --- src/usr.sbin/traceroute/Makefile:1.16 Wed Apr 22 15:23:09 2009 +++ src/usr.sbin/traceroute/Makefile Wed Dec 15 00:09:41 2010 @@ -1,10 +1,10 @@ -# $NetBSD: Makefile,v 1.16 2009/04/22 15:23:09 lukem Exp $ +# $NetBSD: Makefile,v 1.17 2010/12/15 00:09:41 pooka Exp $ WARNS?= 1 # XXX: out of date third-party program USE_FORT?= yes # network client -PROG= traceroute +RUMPPRG=traceroute MAN= traceroute.8 CPPFLAGS+=-DHAVE_MALLOC_H=1 -DHAVE_SYS_SELECT_H=1 -DHAVE_SYS_SOCKIO_H=1 @@ -21,6 +21,10 @@ SRCS= traceroute.c ifaddrlist.c SRCS+= version.c as.c +.PATH: ${.CURDIR}/../../lib/libc/net +RUMPSRCS= getifaddrs.c +CPPFLAGS+= -DRUMP_ACTION + AWKS= median.awk mean.awk .include <bsd.prog.mk> Index: src/usr.sbin/traceroute/traceroute.c diff -u src/usr.sbin/traceroute/traceroute.c:1.75 src/usr.sbin/traceroute/traceroute.c:1.76 --- src/usr.sbin/traceroute/traceroute.c:1.75 Fri Jul 2 12:13:11 2010 +++ src/usr.sbin/traceroute/traceroute.c Wed Dec 15 00:09:41 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: traceroute.c,v 1.75 2010/07/02 12:13:11 kefren Exp $ */ +/* $NetBSD: traceroute.c,v 1.76 2010/12/15 00:09:41 pooka Exp $ */ /* * Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997 @@ -29,7 +29,7 @@ #else __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997\ The Regents of the University of California. All rights reserved."); -__RCSID("$NetBSD: traceroute.c,v 1.75 2010/07/02 12:13:11 kefren Exp $"); +__RCSID("$NetBSD: traceroute.c,v 1.76 2010/12/15 00:09:41 pooka Exp $"); #endif #endif @@ -222,6 +222,7 @@ #include <arpa/inet.h> #include <ctype.h> +#include <err.h> #include <errno.h> #ifdef HAVE_MALLOC_H #include <malloc.h> @@ -245,6 +246,7 @@ #include "ifaddrlist.h" #include "as.h" +#include "prog_ops.h" /* Maximum number of gateways (include room for one noop) */ #define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(u_int32_t))) @@ -453,7 +455,10 @@ setprogname(argv[0]); prog = getprogname(); - if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) { + if (prog_init && prog_init() == -1) + err(1, "init failed"); + + if ((s = prog_socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) { Fprintf(stderr, "%s: icmp socket: %s\n", prog, strerror(errno)); exit(1); } @@ -463,7 +468,7 @@ * running our traceroute code will forgive us. */ #ifndef __hpux - sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); + sndsock = prog_socket(AF_INET, SOCK_RAW, IPPROTO_RAW); #else sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW useicmp ? IPPROTO_ICMP : IPPROTO_UDP); @@ -476,7 +481,7 @@ /* Revert to non-privileged user after opening sockets */ setuid(getuid()); - (void) sysctl(mib, sizeof(mib)/sizeof(mib[0]), &max_ttl, &size, + (void) prog_sysctl(mib, sizeof(mib)/sizeof(mib[0]), &max_ttl, &size, NULL, 0); opterr = 0; @@ -711,7 +716,7 @@ } if (options & SO_DEBUG) - (void)setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&on, + (void)prog_setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof(on)); #ifdef IPSEC #ifdef IPSEC_POLICY_IPSEC @@ -727,19 +732,19 @@ { int level = IPSEC_LEVEL_AVAIL; - (void)setsockopt(s, IPPROTO_IP, IP_ESP_TRANS_LEVEL, &level, + (void)prog_setsockopt(s, IPPROTO_IP, IP_ESP_TRANS_LEVEL, &level, sizeof(level)); - (void)setsockopt(s, IPPROTO_IP, IP_ESP_NETWORK_LEVEL, &level, + (void)prog_setsockopt(s, IPPROTO_IP, IP_ESP_NETWORK_LEVEL, &level, sizeof(level)); #ifdef IP_AUTH_TRANS_LEVEL - (void)setsockopt(s, IPPROTO_IP, IP_AUTH_TRANS_LEVEL, &level, + (void)prog_setsockopt(s, IPPROTO_IP, IP_AUTH_TRANS_LEVEL, &level, sizeof(level)); #else - (void)setsockopt(s, IPPROTO_IP, IP_AUTH_LEVEL, &level, + (void)prog_setsockopt(s, IPPROTO_IP, IP_AUTH_LEVEL, &level, sizeof(level)); #endif #ifdef IP_AUTH_NETWORK_LEVEL - (void)setsockopt(s, IPPROTO_IP, IP_AUTH_NETWORK_LEVEL, &level, + (void)prog_setsockopt(s, IPPROTO_IP, IP_AUTH_NETWORK_LEVEL, &level, sizeof(level)); #endif } @@ -760,19 +765,19 @@ { int level = IPSEC_LEVEL_BYPASS; - (void)setsockopt(sndsock, IPPROTO_IP, IP_ESP_TRANS_LEVEL, &level, + (void)prog_setsockopt(sndsock, IPPROTO_IP, IP_ESP_TRANS_LEVEL, &level, sizeof(level)); - (void)setsockopt(sndsock, IPPROTO_IP, IP_ESP_NETWORK_LEVEL, &level, + (void)prog_setsockopt(sndsock, IPPROTO_IP, IP_ESP_NETWORK_LEVEL, &level, sizeof(level)); #ifdef IP_AUTH_TRANS_LEVEL - (void)setsockopt(sndsock, IPPROTO_IP, IP_AUTH_TRANS_LEVEL, &level, + (void)prog_setsockopt(sndsock, IPPROTO_IP, IP_AUTH_TRANS_LEVEL, &level, sizeof(level)); #else - (void)setsockopt(sndsock, IPPROTO_IP, IP_AUTH_LEVEL, &level, + (void)prog_setsockopt(sndsock, IPPROTO_IP, IP_AUTH_LEVEL, &level, sizeof(level)); #endif #ifdef IP_AUTH_NETWORK_LEVEL - (void)setsockopt(sndsock, IPPROTO_IP, IP_AUTH_NETWORK_LEVEL, &level, + (void)prog_setsockopt(sndsock, IPPROTO_IP, IP_AUTH_NETWORK_LEVEL, &level, sizeof(level)); #endif } @@ -797,7 +802,7 @@ optlist[3] = IPOPT_MINOFF; memcpy(optlist + 4, gwlist, i); - if ((setsockopt(sndsock, IPPROTO_IP, IP_OPTIONS, optlist, + if ((prog_setsockopt(sndsock, IPPROTO_IP, IP_OPTIONS, optlist, i + sizeof(gwlist[0]))) < 0) { Fprintf(stderr, "%s: IP_OPTIONS: %s\n", prog, strerror(errno)); @@ -807,21 +812,21 @@ #endif #ifdef SO_SNDBUF - if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&packlen, + if (prog_setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&packlen, sizeof(packlen)) < 0) { Fprintf(stderr, "%s: SO_SNDBUF: %s\n", prog, strerror(errno)); exit(1); } #endif #ifdef IP_HDRINCL - if (setsockopt(sndsock, IPPROTO_IP, IP_HDRINCL, (char *)&on, + if (prog_setsockopt(sndsock, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)) < 0) { Fprintf(stderr, "%s: IP_HDRINCL: %s\n", prog, strerror(errno)); exit(1); } #else #ifdef IP_TOS - if (settos && setsockopt(sndsock, IPPROTO_IP, IP_TOS, + if (settos && prog_setsockopt(sndsock, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(tos)) < 0) { Fprintf(stderr, "%s: setsockopt tos %d: %s\n", prog, tos, strerror(errno)); @@ -830,10 +835,10 @@ #endif #endif if (options & SO_DEBUG) - (void)setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, (char *)&on, + (void)prog_setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof(on)); if (options & SO_DONTROUTE) - (void)setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE, (char *)&on, + (void)prog_setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE, (char *)&on, sizeof(on)); /* Get the interface address list */ @@ -1100,14 +1105,14 @@ wait.tv_usec = 0; } - retval = poll(set, 1, wait.tv_sec * 1000 + wait.tv_usec / 1000); + retval = prog_poll(set, 1, wait.tv_sec * 1000 + wait.tv_usec / 1000); if (retval < 0) { /* If we continue, we probably just flood the remote host. */ Fprintf(stderr, "%s: poll: %s\n", prog, strerror(errno)); exit(1); } if (retval > 0) { - cc = recvfrom(s, (char *)packet, sizeof(packet), 0, + cc = prog_recvfrom(s, (char *)packet, sizeof(packet), 0, (struct sockaddr *)fromp, &fromlen); } @@ -1349,7 +1354,7 @@ } #if !defined(IP_HDRINCL) && defined(IP_TTL) - if (setsockopt(sndsock, IPPROTO_IP, IP_TTL, + if (prog_setsockopt(sndsock, IPPROTO_IP, IP_TTL, (char *)&ttl, sizeof(ttl)) < 0) { Fprintf(stderr, "%s: setsockopt ttl %d: %s\n", prog, ttl, strerror(errno)); @@ -1365,7 +1370,7 @@ if (cc > 0) cc += sizeof(*outip) + optlen; #else - cc = sendto(sndsock, (char *)outip, + cc = prog_sendto(sndsock, (char *)outip, packlen, 0, &whereto, sizeof(whereto)); #endif if (cc < 0 || cc != packlen) { @@ -1828,7 +1833,7 @@ struct sockaddr_in help; socklen_t help_len; - sock = socket(AF_INET, SOCK_DGRAM, 0); + sock = prog_socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) return (0); help.sin_family = AF_INET; @@ -1838,20 +1843,20 @@ */ help.sin_port = 42; help.sin_addr.s_addr = to->sin_addr.s_addr; - if (connect(sock, (struct sockaddr *)&help, sizeof(help)) < 0) { - (void)close(sock); + if (prog_connect(sock, (struct sockaddr *)&help, sizeof(help)) < 0) { + (void)prog_close(sock); return (0); } help_len = sizeof(help); - if (getsockname(sock, (struct sockaddr *)&help, &help_len) < 0 || + if (prog_getsockname(sock, (struct sockaddr *)&help, &help_len) < 0 || help_len != sizeof(help) || help.sin_addr.s_addr == INADDR_ANY) { - (void)close(sock); + (void)prog_close(sock); return (0); } - (void)close(sock); + (void)prog_close(sock); setsin(from, help.sin_addr.s_addr); return (1); } @@ -1870,7 +1875,7 @@ Fprintf(stderr, "%s: %s\n", prog, ipsec_strerror()); return -1; } - (void)setsockopt(so, IPPROTO_IP, IP_IPSEC_POLICY, + (void)prog_setsockopt(so, IPPROTO_IP, IP_IPSEC_POLICY, buf, ipsec_get_policylen(buf)); free(buf); Added files: Index: src/usr.sbin/traceroute/prog_ops.h diff -u /dev/null src/usr.sbin/traceroute/prog_ops.h:1.1 --- /dev/null Wed Dec 15 00:09:42 2010 +++ src/usr.sbin/traceroute/prog_ops.h Wed Dec 15 00:09:41 2010 @@ -0,0 +1,72 @@ +/* $NetBSD: prog_ops.h,v 1.1 2010/12/15 00:09:41 pooka Exp $ */ + +/* + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _PROG_OPS_H_ +#define _PROG_OPS_H_ + +#include <sys/types.h> +#include <sys/socket.h> +#include <poll.h> + +struct prog_ops { + int (*op_init)(void); + + int (*op_socket)(int, int, int); + int (*op_setsockopt)(int, int, int, const void *, socklen_t); + int (*op_shutdown)(int, int); + + int (*op_poll)(struct pollfd *, nfds_t, int); + + ssize_t (*op_recvfrom)(int, void *, size_t, int, + struct sockaddr *, socklen_t *); + ssize_t (*op_sendto)(int, const void *, size_t, int, + const struct sockaddr *, socklen_t); + + int (*op_close)(int); + + int (*op_connect)(int, const struct sockaddr *, socklen_t); + int (*op_getsockname)(int, struct sockaddr *, socklen_t *); + + int (*op_sysctl)(const int *, u_int, void *, size_t *, + const void *, size_t); +}; +extern const struct prog_ops prog_ops; + +#define prog_init prog_ops.op_init +#define prog_socket prog_ops.op_socket +#define prog_setsockopt prog_ops.op_setsockopt +#define prog_shutdown prog_ops.op_shutdown +#define prog_poll prog_ops.op_poll +#define prog_recvfrom prog_ops.op_recvfrom +#define prog_sendto prog_ops.op_sendto +#define prog_close prog_ops.op_close +#define prog_connect prog_ops.op_connect +#define prog_getsockname prog_ops.op_getsockname +#define prog_sysctl prog_ops.op_sysctl + +#endif /* _PROG_OPS_H_ */ Index: src/usr.sbin/traceroute/traceroute_hostops.c diff -u /dev/null src/usr.sbin/traceroute/traceroute_hostops.c:1.1 --- /dev/null Wed Dec 15 00:09:42 2010 +++ src/usr.sbin/traceroute/traceroute_hostops.c Wed Dec 15 00:09:41 2010 @@ -0,0 +1,55 @@ +/* $NetBSD: traceroute_hostops.c,v 1.1 2010/12/15 00:09:41 pooka Exp $ */ + +/*- + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: traceroute_hostops.c,v 1.1 2010/12/15 00:09:41 pooka Exp $"); +#endif /* !lint */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <sys/sysctl.h> + +#include <poll.h> +#include <unistd.h> + +#include "prog_ops.h" + +const struct prog_ops prog_ops = { + .op_socket = socket, + .op_setsockopt = setsockopt, + .op_shutdown = shutdown, + .op_poll = poll, + .op_recvfrom = recvfrom, + .op_sendto = sendto, + .op_close = close, + .op_connect = connect, + .op_getsockname = getsockname, + .op_sysctl = sysctl, +}; Index: src/usr.sbin/traceroute/traceroute_rumpops.c diff -u /dev/null src/usr.sbin/traceroute/traceroute_rumpops.c:1.1 --- /dev/null Wed Dec 15 00:09:42 2010 +++ src/usr.sbin/traceroute/traceroute_rumpops.c Wed Dec 15 00:09:42 2010 @@ -0,0 +1,59 @@ +/* $NetBSD: traceroute_rumpops.c,v 1.1 2010/12/15 00:09:42 pooka Exp $ */ + +/*- + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: traceroute_rumpops.c,v 1.1 2010/12/15 00:09:42 pooka Exp $"); +#endif /* !lint */ + +#include <sys/types.h> +#include <sys/socket.h> + +#include <poll.h> +#include <unistd.h> + +#include <rump/rump.h> +#include <rump/rump_syscalls.h> +#include <rump/rumpclient.h> + +#include "prog_ops.h" + +const struct prog_ops prog_ops = { + .op_init = rumpclient_init, + + .op_socket = rump_sys_socket, + .op_setsockopt= rump_sys_setsockopt, + .op_shutdown = rump_sys_shutdown, + .op_poll = rump_sys_poll, + .op_recvfrom = rump_sys_recvfrom, + .op_sendto = rump_sys_sendto, + .op_close = rump_sys_close, + .op_connect = rump_sys_connect, + .op_getsockname=rump_sys_getsockname, + .op_sysctl = rump_sys___sysctl, +};