]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Allow interface names as scope-id in IPv6 link-local addresses. 555/head
authorFlorian Obser <florian@narrans.de>
Sun, 24 Oct 2021 13:55:17 +0000 (15:55 +0200)
committerFlorian Obser <florian@narrans.de>
Sun, 24 Oct 2021 14:06:55 +0000 (16:06 +0200)
For example, this makes
forward-zone:
    name: "."
    forward-addr: fe80::20d:b9ff:fe46:c7f4%vio0
    forward-first: yes

work instead of fe80::20d:b9ff:fe46:c7f4%1.

config.h.in
configure
configure.ac
util/net_help.c

index da25a2928f0bcedb365dceea8bf2bc98d3135741..e8a26735d2d3bbf210cb5814692a9ec4c995f22a 100644 (file)
 /* Define to 1 if you have the <ifaddrs.h> header file. */
 #undef HAVE_IFADDRS_H
 
+/* Define to 1 if you have the `if_nametoindex' function. */
+#undef HAVE_IF_NAMETOINDEX
+
 /* Define to 1 if you have the `inet_aton' function. */
 #undef HAVE_INET_ATON
 
index ec8a25499a32210c72aa0b73c62b659302710fcf..e8dc11f2e888db4054f68411e210f0ac5c67198c 100755 (executable)
--- a/configure
+++ b/configure
@@ -21730,6 +21730,12 @@ if test "${with_libunbound_only+set}" = set; then :
                INSTALLTARGET="install-lib"
        fi
 
+fi
+ac_fn_c_check_func "$LINENO" "if_nametoindex" "ac_cv_func_if_nametoindex"
+if test "x$ac_cv_func_if_nametoindex" = xyes
+then :
+  printf "%s\n" "#define HAVE_IF_NAMETOINDEX 1" >>confdefs.h
+
 fi
 
 if test $ALLTARGET = "alltargets"; then
index 99d57c41215a1b6c59abf7d52e56f5383424c1cd..f42fc314b5b111033b4a5ff87350f75f4e8e218c 100644 (file)
@@ -1601,7 +1601,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([
   AC_MSG_RESULT(no))
 
 AC_SEARCH_LIBS([setusercontext], [util])
-AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam endpwent getrlimit setrlimit setsid chroot kill chown sleep usleep random srandom recvmsg sendmsg writev socketpair glob initgroups strftime localtime_r setusercontext _beginthreadex endservent endprotoent fsync shmget accept4 getifaddrs])
+AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam endpwent getrlimit setrlimit setsid chroot kill chown sleep usleep random srandom recvmsg sendmsg writev socketpair glob initgroups strftime localtime_r setusercontext _beginthreadex endservent endprotoent fsync shmget accept4 getifaddrs if_nametoindex])
 AC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])])
 AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])])
 
index 3a671777cfd58df0ecb742aebffd06c8cf59736e..c266e35515eb8560a602976a13a0525c30069a8d 100644 (file)
  */
 
 #include "config.h"
+#ifdef HAVE_SYS_TYPES_H
+#  include <sys/types.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
 #include "util/net_help.h"
 #include "util/log.h"
 #include "util/data/dname.h"
@@ -266,7 +272,10 @@ ipstrtoaddr(const char* ip, int port, struct sockaddr_storage* addr,
                                return 0;
                        (void)strlcpy(buf, ip, sizeof(buf));
                        buf[s-ip]=0;
-                       sa->sin6_scope_id = (uint32_t)atoi(s+1);
+#ifdef HAVE_IF_NAMETOINDEX
+                       if (!(sa->sin6_scope_id = if_nametoindex(s+1)))
+#endif /* HAVE_IF_NAMETOINDEX */
+                               sa->sin6_scope_id = (uint32_t)atoi(s+1);
                        ip = buf;
                }
                if(inet_pton((int)sa->sin6_family, ip, &sa->sin6_addr) <= 0) {