The following reply was made to PR bin/187526; it has been noted by GNATS.

From: Eugene Grosbein <[email protected]>
To: [email protected]
Cc:  
Subject: Re: bin/187526: [patch] traceroute -a breaks of "whois" socket timeout
Date: Mon, 31 Mar 2014 23:53:22 +0700

 This is a multi-part message in MIME format.
 --------------040008040404060404030001
 Content-Type: text/plain; charset=us-ascii
 Content-Transfer-Encoding: 7bit
 
 Here comes corrected version of patch that fixes traceroute6 too
 (and unbreaks world building).
 
 
 --------------040008040404060404030001
 Content-Type: text/plain; charset=KOI8-R;
  name="traceroute.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="traceroute.diff"
 
 --- contrib/traceroute/as.h.orig       2013-06-17 11:18:23.000000000 +0700
 +++ contrib/traceroute/as.h    2014-03-13 17:13:48.000000000 +0700
 @@ -31,5 +31,5 @@
   */
  
  void *as_setup(const char *);
 -unsigned int as_lookup(void *, char *, sa_family_t);
 +unsigned int as_lookup(void *, char *, sa_family_t, int *);
  void as_shutdown(void *);
 --- contrib/traceroute/as.c.orig       2013-06-17 11:18:23.000000000 +0700
 +++ contrib/traceroute/as.c    2014-03-13 17:37:51.000000000 +0700
 @@ -119,7 +119,7 @@ as_setup(const char *server)
  }
  
  unsigned int
 -as_lookup(void *_asn, char *addr, sa_family_t family)
 +as_lookup(void *_asn, char *addr, sa_family_t family, int *status)
  {
        struct aslookup *asn = _asn;
        char buf[1024];
 @@ -129,8 +129,17 @@ as_lookup(void *_asn, char *addr, sa_fam
        as = 0;
        rc = dlen = 0;
        plen = (family == AF_INET6) ? 128 : 32;
 -      (void)fprintf(asn->as_f, "!r%s/%d,l\n", addr, plen);
 -      (void)fflush(asn->as_f);
 +      *status = fprintf(asn->as_f, "!r%s/%d,l\n", addr, plen);
 +      if (*status < 0) {
 +              *status = errno;
 +              return 0;
 +      }
 +      *status = fflush(asn->as_f);
 +      if (*status == EOF) {
 +              *status = errno;
 +              return 0;
 +      }
 +      *status = 0;
  
  #ifdef AS_DEBUG_FILE
        if (asn->as_debug) {
 @@ -139,7 +148,14 @@ as_lookup(void *_asn, char *addr, sa_fam
        }
  #endif /* AS_DEBUG_FILE */
  
 -      while (fgets(buf, sizeof(buf), asn->as_f) != NULL) {
 +      while (1) {
 +              if (fgets(buf, sizeof(buf), asn->as_f) == NULL) {
 +                      if(feof(asn->as_f) || ferror(asn->as_f)) {
 +                              *status = EIO;
 +                              return 0;
 +                      }
 +                      break;
 +              }
                buf[sizeof(buf) - 1] = '\0';
  
  #ifdef AS_DEBUG_FILE
 --- contrib/traceroute/traceroute.c.orig       2013-06-17 11:18:23.000000000 
+0700
 +++ contrib/traceroute/traceroute.c    2014-03-13 17:27:14.000000000 +0700
 @@ -931,6 +931,8 @@
                        as_path = 0;
                }
        }
 +      if (as_path)
 +              signal(SIGPIPE, SIG_IGN);
        
  #if   defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
        if (setpolicy(sndsock, "in bypass") < 0)
 @@ -1471,6 +1473,7 @@
  {
        register struct ip *ip;
        register int hlen;
 +      int as, status;
        char addr[INET_ADDRSTRLEN];
  
        ip = (struct ip *) buf;
 @@ -1479,8 +1482,24 @@
  
        strlcpy(addr, inet_ntoa(from->sin_addr), sizeof(addr));
  
 -      if (as_path)
 -              Printf(" [AS%u]", as_lookup(asn, addr, AF_INET));
 +      while(as_path) {
 +              as = as_lookup(asn, addr, AF_INET, &status);
 +              if (status) {
 +                      as_shutdown(asn);
 +                      asn = as_setup(as_server);
 +                      if (asn == NULL) {
 +                              Fprintf(stderr, "%s: as_setup failed, AS# 
lookups"
 +                                              " disabled\n", prog);
 +                              (void)fflush(stderr);
 +                              as_path = 0;
 +                              break;
 +                      }
 +                      else
 +                              continue;
 +              }
 +              Printf(" [AS%u]", as);
 +              break;
 +      }
  
        if (nflag)
                Printf(" %s", addr);
 --- usr.sbin/traceroute6/traceroute6.c.orig    2013-10-21 21:03:06.000000000 
+0700
 +++ usr.sbin/traceroute6/traceroute6.c 2014-03-24 00:25:21.000000000 +0700
 @@ -885,6 +885,8 @@ main(argc, argv)
                        as_path = 0;
                }
        }
 +      if (as_path)
 +              signal(SIGPIPE, SIG_IGN);
  
        /*
         * Message to users
 @@ -1376,13 +1378,30 @@ print(mhdr, cc)
        int cc;
  {
        struct sockaddr_in6 *from = (struct sockaddr_in6 *)mhdr->msg_name;
 +      int as, status;
        char hbuf[NI_MAXHOST];
  
        if (getnameinfo((struct sockaddr *)from, from->sin6_len,
            hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0)
                strlcpy(hbuf, "invalid", sizeof(hbuf));
 -      if (as_path)
 -              printf(" [AS%u]", as_lookup(asn, hbuf, AF_INET6));
 +      while(as_path) {
 +              as = as_lookup(asn, hbuf, AF_INET6, &status);
 +              if (status) {
 +                      as_shutdown(asn);
 +                      asn = as_setup(as_server);
 +                      if (asn == NULL) {
 +                              fprintf(stderr, "traceroute6: as_setup failed, 
AS# lookups"
 +                                              " disabled\n");
 +                              (void)fflush(stderr);
 +                              as_path = 0;
 +                              break;
 +                      }
 +                      else
 +                              continue;
 +              }
 +              printf(" [AS%u]", as);
 +              break;
 +      }
        if (nflag)
                printf(" %s", hbuf);
        else if (lflag)
 
 --------------040008040404060404030001--
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "[email protected]"

Reply via email to