Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/traceroute6 AS additions from Zafer Aydogan to prin...



details:   https://anonhg.NetBSD.org/src/rev/5006def3e4c4
branches:  trunk
changeset: 764867:5006def3e4c4
user:      christos <christos%NetBSD.org@localhost>
date:      Tue May 10 01:58:58 2011 +0000

description:
AS additions from Zafer Aydogan to print the AS path. Minor cleanups to compile
without WARNS=1 hackery.

diffstat:

 usr.sbin/traceroute6/traceroute6.8 |   11 +-
 usr.sbin/traceroute6/traceroute6.c |  499 ++++++++++++++++--------------------
 2 files changed, 226 insertions(+), 284 deletions(-)

diffs (truncated from 969 to 300 lines):

diff -r f87ab7770633 -r 5006def3e4c4 usr.sbin/traceroute6/traceroute6.8
--- a/usr.sbin/traceroute6/traceroute6.8        Tue May 10 01:52:49 2011 +0000
+++ b/usr.sbin/traceroute6/traceroute6.8        Tue May 10 01:58:58 2011 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: traceroute6.8,v 1.11 2005/09/17 15:16:11 ginsbach Exp $
+.\"    $NetBSD: traceroute6.8,v 1.12 2011/05/10 01:58:58 christos Exp $
 .\"    $KAME: traceroute6.8,v 1.8 2000/06/12 16:29:18 itojun Exp $
 .\"
 .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -39,7 +39,7 @@
 .Sh SYNOPSIS
 .Nm traceroute6
 .Bk -words
-.Op Fl dIlnrv
+.Op Fl adIlnrv
 .Ek
 .Bk -words
 .Op Fl f Ar firsthop
@@ -63,12 +63,19 @@
 .Op Fl w Ar waittime
 .Ek
 .Bk -words
+.Op Fl A Ar as_server
+.Ek
+.Bk -words
 .Ar target
 .Op Ar datalen
 .Ek
 .\"
 .Sh DESCRIPTION
 .Bl -tag -width Ds
+.It Fl a
+Turn on AS# lookups for each hop encountered.
+.It Fl A
+Turn on AS# lookups and use the given server instead of the default.
 .It Fl d
 Debug mode.
 .It Fl f Ar firsthop
diff -r f87ab7770633 -r 5006def3e4c4 usr.sbin/traceroute6/traceroute6.c
--- a/usr.sbin/traceroute6/traceroute6.c        Tue May 10 01:52:49 2011 +0000
+++ b/usr.sbin/traceroute6/traceroute6.c        Tue May 10 01:58:58 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: traceroute6.c,v 1.39 2010/05/13 18:19:18 christos Exp $        */
+/*     $NetBSD: traceroute6.c,v 1.40 2011/05/10 01:58:58 christos Exp $        */
 /*     $KAME: traceroute6.c,v 1.67 2004/01/25 03:24:39 itojun Exp $    */
 
 /*
@@ -75,7 +75,7 @@
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: traceroute6.c,v 1.39 2010/05/13 18:19:18 christos Exp $");
+__RCSID("$NetBSD: traceroute6.c,v 1.40 2011/05/10 01:58:58 christos Exp $");
 #endif
 #endif
 
@@ -282,6 +282,8 @@
 #include <netinet6/ipsec.h>
 #endif
 
+#include "as.h"
+
 #define DUMMY_PORT 10010
 
 #define        MAXPACKET       65535   /* max ip packet size */
@@ -306,68 +308,71 @@
        struct tv32 tv;         /* time packet left */
 } __packed;
 
-u_char packet[512];            /* last inbound (icmp) packet */
-struct opacket *outpacket;     /* last output (udp) packet */
+static u_char  packet[512];            /* last inbound (icmp) packet */
+static struct opacket  *outpacket;     /* last output (udp) packet */
 
-int    main __P((int, char *[]));
-int    wait_for_reply __P((int, struct msghdr *));
+static ssize_t wait_for_reply(int, struct msghdr *);
 #ifdef IPSEC
 #ifdef IPSEC_POLICY_IPSEC
-int    setpolicy __P((int so, char *policy));
+static int     setpolicy(int so, const char *policy);
 #endif
 #endif
-void   send_probe __P((int, u_long));
-struct udphdr *get_udphdr __P((struct ip6_hdr *, u_char *));
-int    get_hoplim __P((struct msghdr *));
-double deltaT __P((struct timeval *, struct timeval *));
-char   *pr_type __P((int));
-int    packet_ok __P((struct msghdr *, int, int));
-void   print __P((struct msghdr *, int));
-const char *inetname __P((struct sockaddr *));
-void   usage __P((void));
+static void send_probe(int, u_long);
+static struct udphdr *get_udphdr(struct ip6_hdr *, u_char *);
+#if 0
+static int get_hoplim(struct msghdr *);
+#endif
+static double deltaT(struct timeval *, struct timeval *);
+static const char *pr_type(int);
+static int packet_ok(struct msghdr *, ssize_t, int);
+static void print(struct msghdr *, int);
+static const char *inetname(struct sockaddr *);
+static void usage(void) __attribute__((__noreturn__));
 
-int rcvsock;                   /* receive (icmp) socket file descriptor */
-int sndsock;                   /* send (udp) socket file descriptor */
+static int rcvsock;            /* receive (icmp) socket file descriptor */
+static int sndsock;            /* send (udp) socket file descriptor */
 
-struct msghdr rcvmhdr;
-struct iovec rcviov[2];
-int rcvhlim;
-struct in6_pktinfo *rcvpktinfo;
+static struct msghdr rcvmhdr;
+static struct iovec rcviov[2];
+static int rcvhlim;
+static struct in6_pktinfo *rcvpktinfo;
 
-struct sockaddr_in6 Src, Dst, Rcv;
-u_long datalen;                        /* How much data */
+static struct sockaddr_in6 Src, Dst, Rcv;
+static u_long datalen;                 /* How much data */
 #define        ICMP6ECHOLEN    8
 /* XXX: 2064 = 127(max hops in type 0 rthdr) * sizeof(ip6_hdr) + 16(margin) */
-char rtbuf[2064];
+static char rtbuf[2064];
 #ifdef USE_RFC3542
-struct ip6_rthdr *rth;
+static struct ip6_rthdr *rth;
 #endif
-struct cmsghdr *cmsg;
+static struct cmsghdr *cmsg;
 
-char *source = 0;
-char *hostname;
+static char *source;
+static char *hostname;
 
-u_long nprobes = 3;
-u_long first_hop = 1;
-u_long max_hops = 30;
-u_int16_t srcport;
-u_int16_t port = 32768+666;    /* start udp dest port # for probe packets */
-u_int16_t ident;
-int options;                   /* socket options */
-int verbose;
-int waittime = 5;              /* time to wait for response (in seconds) */
-int nflag;                     /* print addresses numerically */
-int useicmp;
-int lflag;                     /* print both numerical address & hostname */
+static u_long nprobes = 3;
+static u_long first_hop = 1;
+static u_long max_hops = 30;
+static u_int16_t srcport;
+static u_int16_t port = 32768+666;/* start udp dest port # for probe packets */
+static u_int16_t ident;
+static int options;            /* socket options */
+static int verbose;
+static int waittime = 5;       /* time to wait for response (in seconds) */
+static int nflag;              /* print addresses numerically */
+static int useicmp;
+static int lflag;              /* print both numerical address & hostname */
+static int as_path;            /* print as numbers for each hop */
+static char *as_server = NULL;
+static void *asn;
 
 int
-main(argc, argv)
-       int argc;
-       char *argv[];
+main(int argc, char *argv[])
 {
        int mib[4] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_DEFHLIM };
        char hbuf[NI_MAXHOST], src0[NI_MAXHOST], *ep;
-       int ch, i, on = 1, seq, rcvcmsglen, error, minlen;
+       int ch, i, on = 1, seq, rcvcmsglen, error;
+       u_long minlen;
        struct addrinfo hints, *res;
        static u_char *rcvcmsgbuf;
        u_long probe, hops, lport;
@@ -377,10 +382,8 @@
        /*
         * Receive ICMP
         */
-       if ((rcvsock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
-               perror("socket(ICMPv6)");
-               exit(5);
-       }
+       if ((rcvsock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0)
+               err(5, "socket(ICMPv6)");
 
        /* revoke privs */
        seteuid(getuid());
@@ -414,8 +417,15 @@
 
        seq = 0;
 
-       while ((ch = getopt(argc, argv, "df:g:Ilm:np:q:rs:w:v")) != -1)
+       while ((ch = getopt(argc, argv, "aA:df:g:Ilm:np:q:rs:w:v")) != -1)
                switch (ch) {
+               case 'a':
+                       as_path = 1;
+                       break;
+               case 'A':
+                       as_path = 1;
+                       as_server = optarg;
+                       break;
                case 'd':
                        options |= SO_DEBUG;
                        break;
@@ -423,19 +433,13 @@
                        ep = NULL;
                        errno = 0;
                        first_hop = strtoul(optarg, &ep, 0);
-                       if (errno || !*optarg || *ep|| first_hop > 255) {
-                               fprintf(stderr,
-                                   "traceroute6: invalid min hoplimit.\n");
-                               exit(1);
-                       }
+                       if (errno || !*optarg || *ep|| first_hop > 255)
+                               errx(1, "Invalid min hoplimit `%s'", optarg);
                        break;
                case 'g':
                        hp = getipnodebyname(optarg, AF_INET6, 0, &h_errno);
-                       if (hp == NULL) {
-                               fprintf(stderr,
-                                   "traceroute6: unknown host %s\n", optarg);
-                               exit(1);
-                       }
+                       if (hp == NULL)
+                               errx(1, "Unknown host `%s'", optarg);
 #ifdef USE_RFC3542
                        if (rth == NULL) {
                                /*
@@ -445,21 +449,17 @@
                                if ((rth = inet6_rth_init((void *)rtbuf,
                                    sizeof(rtbuf), IPV6_RTHDR_TYPE_0,
                                    0)) == NULL) {
-                                       fprintf(stderr,
-                                           "inet6_rth_init failed.\n");
-                                       exit(1);
+                                       errx(1, "inet6_rth_init failed");
                                }
                        }
                        if (inet6_rth_add((void *)rth,
-                           (struct in6_addr *)hp->h_addr)) {
-                               fprintf(stderr,
-                                   "inet6_rth_add failed for %s\n",
+                           (struct in6_addr *)hp->h_addr))
+                               errx(1, "inet6_rth_add failed for `%s'",
                                    optarg);
-                               exit(1);
-                       }
 #else  /* old advanced API */
                        if (cmsg == NULL)
-                               cmsg = inet6_rthdr_init(rtbuf, IPV6_RTHDR_TYPE_0);
+                               cmsg = inet6_rthdr_init(rtbuf,
+                                   IPV6_RTHDR_TYPE_0);
                        inet6_rthdr_add(cmsg, (struct in6_addr *)hp->h_addr,
                            IPV6_RTHDR_LOOSE);
 #endif
@@ -477,11 +477,8 @@
                        ep = NULL;
                        errno = 0;
                        max_hops = strtoul(optarg, &ep, 0);
-                       if (errno || !*optarg || *ep || max_hops > 255) {
-                               fprintf(stderr,
-                                   "traceroute6: invalid max hoplimit.\n");
-                               exit(1);
-                       }
+                       if (errno || !*optarg || *ep || max_hops > 255)
+                               errx(1, "Invalid max hoplimit `%s'", optarg);
                        break;
                case 'n':
                        nflag++;
@@ -490,31 +487,20 @@
                        ep = NULL;
                        errno = 0;
                        lport = strtoul(optarg, &ep, 0);
-                       if (errno || !*optarg || *ep) {
-                               fprintf(stderr, "traceroute6: invalid port.\n");
-                               exit(1);
-                       }
-                       if (lport == 0 || lport != (lport & 0xffff)) {
-                               fprintf(stderr,
-                                   "traceroute6: port out of range.\n");
-                               exit(1);
-                       }
+                       if (errno || !*optarg || *ep)
+                               errx(1, "Invalid port `%s'", optarg);
+                       if (lport == 0 || lport != (lport & 0xffff))
+                               errx(1, "Port `%s' out of range", optarg);
                        port = lport & 0xffff;
                        break;
                case 'q':
                        ep = NULL;
                        errno = 0;
                        nprobes = strtoul(optarg, &ep, 0);
-                       if (errno || !*optarg || *ep) {
-                               fprintf(stderr,



Home | Main Index | Thread Index | Old Index