Source-Changes-HG archive

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

[src/netbsd-1-5]: src/sbin/ping6 Pull up revisions 1.23-1.24, 1.26-1.32 (via p...



details:   https://anonhg.NetBSD.org/src/rev/050521fc8282
branches:  netbsd-1-5
changeset: 490816:050521fc8282
user:      he <he%NetBSD.org@localhost>
date:      Sun Mar 11 20:44:36 2001 +0000

description:
Pull up revisions 1.23-1.24,1.26-1.32 (via patch, requested by itojun):
  Correct buffer management.  Fix handling of short packets.  More
  robust signal handling.  Print icmp6 name lookup packets better.
This syncs up to the current head of the trunk.

diffstat:

 sbin/ping6/ping6.c |  664 ++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 457 insertions(+), 207 deletions(-)

diffs (truncated from 1301 to 300 lines):

diff -r adbb4a7de0f0 -r 050521fc8282 sbin/ping6/ping6.c
--- a/sbin/ping6/ping6.c        Sun Mar 11 20:43:51 2001 +0000
+++ b/sbin/ping6/ping6.c        Sun Mar 11 20:44:36 2001 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: ping6.c,v 1.15.2.4 2000/12/15 05:01:30 he Exp $        */
-/*     $KAME: ping6.c,v 1.91 2000/10/07 06:23:06 itojun Exp $  */
+/*     $NetBSD: ping6.c,v 1.15.2.5 2001/03/11 20:44:36 he Exp $        */
+/*     $KAME: ping6.c,v 1.121 2001/02/01 16:43:01 itojun Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -81,7 +81,7 @@
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ping6.c,v 1.15.2.4 2000/12/15 05:01:30 he Exp $");
+__RCSID("$NetBSD: ping6.c,v 1.15.2.5 2001/03/11 20:44:36 he Exp $");
 #endif
 #endif
 
@@ -103,8 +103,8 @@
 /*
  * NOTE:
  * USE_SIN6_SCOPE_ID assumes that sin6_scope_id has the same semantics
- * as IPV6_PKTINFO.  Some people object it (sin6_scope_id specifies *link* while
- * IPV6_PKTINFO specifies *interface*.  Link is defined as collection of
+ * as IPV6_PKTINFO.  Some people object it (sin6_scope_id specifies *link*
+ * while IPV6_PKTINFO specifies *interface*.  Link is defined as collection of
  * network attached to 1 or more interfaces)
  */
 
@@ -197,9 +197,9 @@
 
 #define IN6LEN         sizeof(struct in6_addr)
 #define SA6LEN         sizeof(struct sockaddr_in6)
-#define DUMMY_PORT      10101
+#define DUMMY_PORT     10101
 
-#define SIN6(s) ((struct sockaddr_in6 *)(s))
+#define SIN6(s)        ((struct sockaddr_in6 *)(s))
 
 /*
  * MAX_DUP_CHK is the number of bits in received table, i.e. the maximum
@@ -210,9 +210,9 @@
 int mx_dup_ck = MAX_DUP_CHK;
 char rcvd_tbl[MAX_DUP_CHK / 8];
 
-struct addrinfo *res;  
-struct sockaddr_in6 dst;        /* who to ping6 */
-struct sockaddr_in6 src;        /* src addr of this packet */
+struct addrinfo *res;
+struct sockaddr_in6 dst;       /* who to ping6 */
+struct sockaddr_in6 src;       /* src addr of this packet */
 int datalen = DEFDATALEN;
 int s;                         /* socket file descriptor */
 u_char outpack[MAXPACKETLEN];
@@ -222,6 +222,7 @@
 int ident;                     /* process id to identify our packets */
 u_int8_t nonce[8];             /* nonce field for node information */
 struct in6_addr srcaddr;
+int hoplimit = -1;             /* hoplimit */
 
 /* counters */
 long npackets;                 /* max packets to transmit */
@@ -229,7 +230,6 @@
 long nrepeats;                 /* number of duplicates */
 long ntransmitted;             /* sequence # for outbound packets = #sent */
 struct timeval interval = {1, 0}; /* interval between packets */
-int hoplimit = -1;             /* hoplimit */
 
 /* timing */
 int timing;                    /* flag to do timing */
@@ -248,17 +248,25 @@
 struct iovec smsgiov;
 char *scmsg = 0;
 
+volatile int signo;
+volatile sig_atomic_t seenalrm;
+volatile sig_atomic_t seenint;
+#ifdef SIGINFO
+volatile sig_atomic_t seeninfo;
+#endif
+
 int     main __P((int, char *[]));
 void    fill __P((char *, char *));
 int     get_hoplim __P((struct msghdr *));
 struct in6_pktinfo *get_rcvpktinfo __P((struct msghdr *));
-void    onalrm __P((int));
-void    oninfo __P((int));
+void    onsignal __P((int));
+void    retransmit __P((void));
 void    onint __P((int));
 void    pinger __P((void));
-const char *pr_addr __P((struct sockaddr_in6 *));
+const char *pr_addr __P((struct sockaddr *, int));
 void    pr_icmph __P((struct icmp6_hdr *, u_char *));
 void    pr_iph __P((struct ip6_hdr *));
+void    pr_suptypes __P((struct icmp6_nodeinfo *, size_t));
 void    pr_nodeaddr __P((struct icmp6_nodeinfo *, int));
 int     myechoreply __P((const struct icmp6_hdr *));
 int     mynireply __P((const struct icmp6_nodeinfo *));
@@ -268,6 +276,7 @@
 void    pr_exthdrs __P((struct msghdr *));
 void    pr_ip6opt __P((void *));
 void    pr_rthdr __P((void *));
+int     pr_bitrange __P((u_int32_t, int, int));
 void    pr_retip __P((struct ip6_hdr *, u_char *));
 void    summary __P((void));
 void    tvsub __P((struct timeval *, struct timeval *));
@@ -282,7 +291,7 @@
 {
        struct itimerval itimer;
        struct sockaddr_in6 from;
-       struct timeval timeout;
+       struct timeval timeout, *tv;
        struct addrinfo hints;
        fd_set *fdmaskp;
        int fdmasks;
@@ -298,9 +307,6 @@
 #ifdef USE_RFC2292BIS
        struct ip6_rthdr *rthdr = NULL;
 #endif
-#ifndef __OpenBSD__
-       struct timeval tv;
-#endif
 #ifdef IPSEC_POLICY_IPSEC
        char *policy_in = NULL;
        char *policy_out = NULL;
@@ -315,15 +321,17 @@
        preload = 0;
        datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN];
 #ifndef IPSEC
-       while ((ch = getopt(argc, argv, "a:b:c:dfHh:I:i:l:nNp:qRS:s:tvwW")) != EOF)
+#define ADDOPTS
 #else
 #ifdef IPSEC_POLICY_IPSEC
-       while ((ch = getopt(argc, argv, "a:b:c:dfHh:I:i:l:nNp:qRS:s:tvwWP:")) != EOF)
+#define ADDOPTS        "P:"
 #else
-       while ((ch = getopt(argc, argv, "a:b:c:dfHh:I:i:l:nNp:qRS:s:tvwWAE")) != EOF)
+#define ADDOPTS        "AE"
 #endif /*IPSEC_POLICY_IPSEC*/
 #endif
-       {
+       while ((ch = getopt(argc, argv,
+           "a:b:c:dfHh:I:i:l:nNp:qRS:s:tvwW" ADDOPTS)) != EOF) {
+#undef ADDOPTS
                switch (ch) {
                case 'a':
                {
@@ -353,8 +361,14 @@
                                        naflags |= NI_NODEADDR_FLAG_GLOBAL;
                                        break;
                                case 'A': /* experimental. not in the spec */
+#ifdef NI_NODEADDR_FLAG_ANYCAST
                                        naflags |= NI_NODEADDR_FLAG_ANYCAST;
                                        break;
+#else
+                                       errx(1,
+"-a A is not supported on the platform");
+                                       /*NOTREACHED*/
+#endif
                                default:
                                        usage();
                                        /*NOTREACHED*/
@@ -559,24 +573,67 @@
                hostname = res->ai_canonname;
        else
                hostname = target;
-               
+
        if (!res->ai_addr)
                errx(1, "getaddrinfo failed");
 
        (void)memcpy(&dst, res->ai_addr, res->ai_addrlen);
 
+       if ((s = socket(res->ai_family, res->ai_socktype,
+           res->ai_protocol)) < 0)
+               err(1, "socket");
+
+       /*
+        * let the kerel pass extension headers of incoming packets,
+        * for privileged socket options
+        */
+       if ((options & F_VERBOSE) != 0) {
+               int opton = 1;
+
+#ifdef IPV6_RECVHOPOPTS
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVHOPOPTS, &opton,
+                   sizeof(opton)))
+                       err(1, "setsockopt(IPV6_RECVHOPOPTS)");
+#else  /* old adv. API */
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_HOPOPTS, &opton,
+                   sizeof(opton)))
+                       err(1, "setsockopt(IPV6_HOPOPTS)");
+#endif
+#ifdef IPV6_RECVDSTOPTS
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVDSTOPTS, &opton,
+                   sizeof(opton)))
+                       err(1, "setsockopt(IPV6_RECVDSTOPTS)");
+#else  /* old adv. API */
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_DSTOPTS, &opton,
+                   sizeof(opton)))
+                       err(1, "setsockopt(IPV6_DSTOPTS)");
+#endif
+#ifdef IPV6_RECVRTHDRDSTOPTS
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVRTHDRDSTOPTS, &opton,
+                   sizeof(opton)))
+                       err(1, "setsockopt(IPV6_RECVRTHDRDSTOPTS)");
+#endif
+       }
+
+       /* revoke root privilege */
+       seteuid(getuid());
+       setuid(getuid());
+
        if (options & F_FLOOD && options & F_INTERVAL)
                errx(1, "-f and -i incompatible options");
 
-       if ((options & F_NOUSERDATA) == 0 &&
-           datalen >= sizeof(struct timeval)) {
-               /* can we time transfer */
-               timing = 1;
+       if ((options & F_NOUSERDATA) == 0) {
+               if (datalen >= sizeof(struct timeval)) {
+                       /* we can time transfer */
+                       timing = 1;
+               } else
+                       timing = 0;
        } else {
                /* suppress timing for node information query */
                timing = 0;
                datalen = 2048;
        }
+
        packlen = datalen + IP6LEN + ICMP6ECHOLEN + EXTRA;
        if (!(packet = (u_char *)malloc((u_int)packlen)))
                err(1, "Unable to allocate packet");
@@ -586,8 +643,8 @@
 
        ident = getpid() & 0xFFFF;
 #ifndef __OpenBSD__
-       gettimeofday(&tv, NULL);
-       srand((unsigned int)(tv.tv_sec ^ tv.tv_usec ^ (long)ident));
+       gettimeofday(&timeout, NULL);
+       srand((unsigned int)(timeout.tv_sec ^ timeout.tv_usec ^ (long)ident));
        memset(nonce, 0, sizeof(nonce));
        for (i = 0; i < sizeof(nonce); i += sizeof(int))
                *((int *)&nonce[i]) = rand();
@@ -597,9 +654,6 @@
                *((u_int32_t *)&nonce[i]) = arc4random();
 #endif
 
-       if ((s = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0)
-               err(1, "socket");
-
        hold = 1;
 
        if (options & F_SO_DEBUG)
@@ -608,8 +662,24 @@
        optval = IPV6_DEFHLIM;
        if (IN6_IS_ADDR_MULTICAST(&dst.sin6_addr))
                if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
-                              &optval, sizeof(optval)) == -1)
+                   &optval, sizeof(optval)) == -1)
                        err(1, "IPV6_MULTICAST_HOPS");
+#ifdef IPV6_USE_MIN_MTU
+       if ((options & F_NOMINMTU) == 0) {
+               optval = 1;
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_USE_MIN_MTU,
+                   &optval, sizeof(optval)) == -1)
+                       err(1, "setsockopt(IPV6_USE_MIN_MTU)");
+       }
+#ifdef IPV6_RECVPATHMTU
+       else {
+               optval = 1;
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVPATHMTU,
+                   &optval, sizeof(optval)) == -1)
+                       err(1, "setsockopt(IPV6_RECVPATHMTU)");
+       }
+#endif /* IPV6_RECVPATHMTU */
+#endif /* IPV6_USE_MIN_MTU */
 
 #ifdef IPSEC
 #ifdef IPSEC_POLICY_IPSEC
@@ -624,18 +694,18 @@
                optval = IPSEC_LEVEL_REQUIRE;
 #ifdef IPV6_AUTH_TRANS_LEVEL
                if (setsockopt(s, IPPROTO_IPV6, IPV6_AUTH_TRANS_LEVEL,
-                               &optval, sizeof(optval)) == -1)
+                   &optval, sizeof(optval)) == -1)
                        err(1, "setsockopt(IPV6_AUTH_TRANS_LEVEL)");
 #else /* old def */
                if (setsockopt(s, IPPROTO_IPV6, IPV6_AUTH_LEVEL,
-                               &optval, sizeof(optval)) == -1)
+                   &optval, sizeof(optval)) == -1)
                        err(1, "setsockopt(IPV6_AUTH_LEVEL)");
 #endif
        }
        if (options & F_ENCRYPT) {



Home | Main Index | Thread Index | Old Index