Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/traceroute Use RUMPPRG. I think it's safe to say t...



details:   https://anonhg.NetBSD.org/src/rev/63b1a3e828a6
branches:  trunk
changeset: 759697:63b1a3e828a6
user:      pooka <pooka%NetBSD.org@localhost>
date:      Wed Dec 15 00:09:41 2010 +0000

description:
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).

diffstat:

 usr.sbin/traceroute/Makefile             |   8 ++-
 usr.sbin/traceroute/prog_ops.h           |  72 ++++++++++++++++++++++++++++++++
 usr.sbin/traceroute/traceroute.c         |  71 ++++++++++++++++--------------
 usr.sbin/traceroute/traceroute_hostops.c |  55 ++++++++++++++++++++++++
 usr.sbin/traceroute/traceroute_rumpops.c |  59 ++++++++++++++++++++++++++
 5 files changed, 230 insertions(+), 35 deletions(-)

diffs (truncated from 474 to 300 lines):

diff -r 4cdc79e9de5d -r 63b1a3e828a6 usr.sbin/traceroute/Makefile
--- a/usr.sbin/traceroute/Makefile      Wed Dec 15 00:08:43 2010 +0000
+++ b/usr.sbin/traceroute/Makefile      Wed Dec 15 00:09:41 2010 +0000
@@ -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>
diff -r 4cdc79e9de5d -r 63b1a3e828a6 usr.sbin/traceroute/prog_ops.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/traceroute/prog_ops.h    Wed Dec 15 00:09:41 2010 +0000
@@ -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_ */
diff -r 4cdc79e9de5d -r 63b1a3e828a6 usr.sbin/traceroute/traceroute.c
--- a/usr.sbin/traceroute/traceroute.c  Wed Dec 15 00:08:43 2010 +0000
+++ b/usr.sbin/traceroute/traceroute.c  Wed Dec 15 00:09:41 2010 +0000
@@ -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 @@



Home | Main Index | Thread Index | Old Index