On 12/18/20 5:04 PM, Jordan Geoghegan wrote:


On 12/17/20 3:15 AM, Otto Moerbeek wrote:
Hi,

as noted on misc dig does not like to talk to local link addresses.
This fixes that case. While investigating I also found another bug:
selecting v6 or v4 addresses only from resolv.conf via the -4 or -6
command line argument does not work as expected.

This fixes both. I did not test binding to a src address with this.
This is likely as broken as it was before.

    -Otto

Index: dig.c
===================================================================
RCS file: /cvs/src/usr.bin/dig/dig.c,v
retrieving revision 1.18
diff -u -p -r1.18 dig.c
--- dig.c    15 Sep 2020 11:47:42 -0000    1.18
+++ dig.c    17 Dec 2020 11:06:49 -0000
@@ -1358,7 +1358,7 @@ dash_option(char *option, char *next, di
          } else
              srcport = 0;
          if (have_ipv6 && inet_pton(AF_INET6, value, &in6) == 1)
-            isc_sockaddr_fromin6(&bind_address, &in6, srcport);
+            isc_sockaddr_fromin6(&bind_address, &in6, srcport, 0);
          else if (have_ipv4 && inet_pton(AF_INET, value, &in4) == 1)
              isc_sockaddr_fromin(&bind_address, &in4, srcport);
          else
Index: dighost.c
===================================================================
RCS file: /cvs/src/usr.bin/dig/dighost.c,v
retrieving revision 1.34
diff -u -p -r1.34 dighost.c
--- dighost.c    15 Sep 2020 11:47:42 -0000    1.34
+++ dighost.c    17 Dec 2020 11:06:49 -0000
@@ -540,7 +540,7 @@ get_addresses(const char *hostname, in_p
              struct sockaddr_in6 *sin6;
              sin6 = (struct sockaddr_in6 *)tmpai->ai_addr;
              isc_sockaddr_fromin6(&addrs[i], &sin6->sin6_addr,
-                         dstport);
+                         dstport, sin6->sin6_scope_id);
          }
          i++;
  @@ -972,7 +972,7 @@ parse_netprefix(struct sockaddr_storage
        if (inet_pton(AF_INET6, buf, &in6) == 1) {
          parsed = 1;
-        isc_sockaddr_fromin6(sa, &in6, 0);
+        isc_sockaddr_fromin6(sa, &in6, 0, 0);
          if (prefix_length > 128)
              prefix_length = 128;
      } else if (inet_pton(AF_INET, buf, &in4) == 1) {
Index: lib/isc/sockaddr.c
===================================================================
RCS file: /cvs/src/usr.bin/dig/lib/isc/sockaddr.c,v
retrieving revision 1.14
diff -u -p -r1.14 sockaddr.c
--- lib/isc/sockaddr.c    28 Nov 2020 06:33:55 -0000    1.14
+++ lib/isc/sockaddr.c    17 Dec 2020 11:06:49 -0000
@@ -223,7 +223,7 @@ isc_sockaddr_anyofpf(struct sockaddr_sto
    void
  isc_sockaddr_fromin6(struct sockaddr_storage *sockaddr, const struct in6_addr *ina6,
-             in_port_t port)
+             in_port_t port, uint32_t scope)
  {
      struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sockaddr;
      memset(sockaddr, 0, sizeof(*sockaddr));
@@ -231,6 +231,7 @@ isc_sockaddr_fromin6(struct sockaddr_sto
      sin6->sin6_len = sizeof(*sin6);
      sin6->sin6_addr = *ina6;
      sin6->sin6_port = htons(port);
+    sin6->sin6_scope_id = scope;
  }
    int
Index: lib/isc/include/isc/sockaddr.h
===================================================================
RCS file: /cvs/src/usr.bin/dig/lib/isc/include/isc/sockaddr.h,v
retrieving revision 1.7
diff -u -p -r1.7 sockaddr.h
--- lib/isc/include/isc/sockaddr.h    15 Sep 2020 11:47:42 -0000    1.7
+++ lib/isc/include/isc/sockaddr.h    17 Dec 2020 11:06:49 -0000
@@ -91,7 +91,7 @@ isc_sockaddr_fromin(struct sockaddr_stor
    void
  isc_sockaddr_fromin6(struct sockaddr_storage *sockaddr, const struct in6_addr *ina6,
-             in_port_t port);
+             in_port_t port, uint32_t scope);
  /*%<
   * Construct an struct sockaddr_storage from an IPv6 address and port.
   */
Index: lib/lwres/lwconfig.c
===================================================================
RCS file: /cvs/src/usr.bin/dig/lib/lwres/lwconfig.c,v
retrieving revision 1.6
diff -u -p -r1.6 lwconfig.c
--- lib/lwres/lwconfig.c    25 Feb 2020 05:00:43 -0000    1.6
+++ lib/lwres/lwconfig.c    17 Dec 2020 11:06:49 -0000
@@ -231,7 +231,7 @@ lwres_conf_parsenameserver(lwres_conf_t
        res = lwres_create_addr(word, &address, 1);
      use_ipv4 = confdata->flags & LWRES_USEIPV4;
-    use_ipv6 = confdata->flags & LWRES_USEIPV4;
+    use_ipv6 = confdata->flags & LWRES_USEIPV6;
      if (res == LWRES_R_SUCCESS &&
          ((address.family == LWRES_ADDRTYPE_V4 && use_ipv4) ||
          (address.family == LWRES_ADDRTYPE_V6 && use_ipv6))) {


Hi Otto,

I just gave this diff a go and everything seems to be working fine. Dig is now using the proper DNS set in my resolv.conf:

$ ./dig openbsd.org

; <<>> dig 9.10.8-P1 <<>> openbsd.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3506
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;openbsd.org.            IN    A

;; ANSWER SECTION:
openbsd.org.        28800    IN    A    129.128.5.194

;; Query time: 853 msec
;; SERVER: fe80::f29f:c2ff:fe17:b8b2%em0#53(fe80::f29f:c2ff:fe17:b8b2%1)
;; WHEN: Fri Dec 18 19:58:57 EST 2020
;; MSG SIZE  rcvd: 56


This looks good to me, hoping this can go in.

Regards,

Jordan


Hi Otto,

I forgot to mention, I tried out the '-b' option to set source address, and that option still doesn't like the 'fe80::%em0' notation:

$ ./dig -b 'fe80::b62e:99ff:fe32:7136%em0' openbsd.org
./dig: invalid address fe80::b62e:99ff:fe32:7136%em0

Reply via email to