[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r5328 - branches/OpenDNSSEC-1.2/signer/src/tools

Matthijs Mekking matthijs at nlnetlabs.nl
Wed Jul 13 15:58:56 CEST 2011


Author: matthijs
Date: 2011-07-13 15:58:56 +0200 (Wed, 13 Jul 2011)
New Revision: 5328

Modified:
   branches/OpenDNSSEC-1.2/signer/src/tools/zone_fetcher.c
   branches/OpenDNSSEC-1.2/signer/src/tools/zone_fetcher.h
Log:
backport from 1.3 (#3)



Modified: branches/OpenDNSSEC-1.2/signer/src/tools/zone_fetcher.c
===================================================================
--- branches/OpenDNSSEC-1.2/signer/src/tools/zone_fetcher.c	2011-07-13 13:58:11 UTC (rev 5327)
+++ branches/OpenDNSSEC-1.2/signer/src/tools/zone_fetcher.c	2011-07-13 13:58:56 UTC (rev 5328)
@@ -38,6 +38,8 @@
 #include <signal.h>
 #include <syslog.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
 
 #include <libxml/tree.h>
 #include <libxml/parser.h>
@@ -325,10 +327,10 @@
                        if (ipv4 || ipv6 || port) {
                            if (!ipv4 && !ipv6) {
                                if (notifylist == NULL) {
-                                   notifylist = new_server("", NULL, port);
+                                   notifylist = new_server(NULL, "", port);
                                    cfg->notifylist = notifylist;
 
-                                   notifylist->next = new_server(NULL, "", port);
+                                   notifylist->next = new_server("", NULL, port);
                                    notifylist = notifylist->next;
                                }
                                else {
@@ -632,13 +634,15 @@
         port = walk->port ? walk->port : DNS_PORT_STRING;
         if (node != NULL)
             hints[i].ai_flags |= AI_NUMERICHOST;
+        else
+            hints[i].ai_family = walk->family;
         /* UDP */
         hints[i].ai_socktype = SOCK_DGRAM;
         /* getaddrinfo */
         if ((r = getaddrinfo(node, port, &hints[i],
             &(sockets->udp[i].addr))) != 0) {
             if (hints[i].ai_family == AF_INET6 && errno == EAFNOSUPPORT) {
-                se_log_error("zone fetcher fallback to UDP4, no IPv6: "
+                se_log_error("zone fetcher udp fallback to ipv4, no ipv6: "
                     " not supported");
                 ip6_support = 0;
                 continue;
@@ -653,29 +657,32 @@
         if ((sockets->udp[i].s = socket(sockets->udp[i].addr->ai_family,
             SOCK_DGRAM, 0)) == -1) {
             if (sockets->udp[i].addr->ai_family == AF_INET6 && errno == EAFNOSUPPORT) {
-                se_log_error("zone fetcher fallback to UDP4, no IPv6: "
+                se_log_error("zone fetcher udp fallback to ipv4, no ipv6: "
                     " not supported");
                 ip6_support = 0;
             }
             else {
-                se_log_error("zone fetcher can't create UDP socket: %s",
+                se_log_error("zone fetcher can't create udp/4 socket for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
                     strerror(errno));
                 ret = -1;
                 break;
             }
         }
 
-        if (sockets->udp[i].addr->ai_family != AF_INET6) {
+        if (sockets->udp[i].addr->ai_family == AF_INET) {
             if (fcntl(sockets->udp[i].s, F_SETFL,
                 O_NONBLOCK) == -1) {
-                se_log_error("zone fetcher cannot fcntl "
-                "UDP: %s", strerror(errno));
+                se_log_error("zone fetcher cannot fcntl udp/4 socket for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
+                    strerror(errno));
             }
             if (bind(sockets->udp[i].s,
                 (struct sockaddr *) sockets->udp[i].addr->ai_addr,
                 sockets->udp[i].addr->ai_addrlen) != 0)
             {
-                se_log_error("zone fetcher can't bind udp/ipv4 socket: %s",
+                se_log_error("zone fetcher can't bind udp/4 socket for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
                     strerror(errno));
                 ret = -1;
                 break;
@@ -684,24 +691,29 @@
         else if (ip6_support) {
 #ifdef IPV6_V6ONLY
 #if defined(IPPROTO_IPV6)
+            se_log_verbose("zone fetcher setsockopt ipv6_v6only...");
             if (setsockopt(sockets->udp[i].s, IPPROTO_IPV6, IPV6_V6ONLY, &on,
                 sizeof(on)) < 0)
             {
                 se_log_error("zone fetcher setsockopt(..., IPV6_V6ONLY, "
-                "...) failed: %s", strerror(errno));
+                "...) failed for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
+                    strerror(errno));
                 ret = -1;
                 break;
             }
 #endif
 #endif /* IPV6_V6ONLY */
             if (fcntl(sockets->udp[i].s, F_SETFL, O_NONBLOCK) == -1) {
-                se_log_error("zone fetcher cannot fcntl UDP: %s",
+                se_log_error("zone fetcher cannot fcntl udp/6 socket for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
                     strerror(errno));
             }
             if (bind(sockets->udp[i].s,
                 (struct sockaddr *) sockets->udp[i].addr->ai_addr,
                 sockets->udp[i].addr->ai_addrlen) != 0) {
-                se_log_error("zone fetcher can't bind UDP socket: %s",
+                se_log_error("zone fetcher can't bind udp/6 socket for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
                     strerror(errno));
                 ret = -1;
                 break;
@@ -714,7 +726,7 @@
         if ((r = getaddrinfo(node, port, &hints[i],
             &(sockets->tcp[i].addr))) != 0) {
             if (hints[i].ai_family == AF_INET6 && errno == EAFNOSUPPORT) {
-                se_log_error("zone fetcher fallback to UDP4, no IPv6: "
+                se_log_error("zone fetcher tcp fallback to ipv4, no ipv6: "
                     " not supported");
                 ip6_support = 0;
                 continue;
@@ -729,42 +741,48 @@
             SOCK_STREAM, 0)) == -1) {
             if (sockets->tcp[i].addr->ai_family == AF_INET6 &&
                 errno == EAFNOSUPPORT) {
-                se_log_error("zone fetcher fallback to TCP4, no IPv6: "
+                se_log_error("zone fetcher tcp fallback to ipv4, no ipv6: "
                     " not supported");
                 ip6_support = 0;
             }
             else {
-                se_log_error("zone fetcher can't create TCP socket: %s",
+                se_log_error("zone fetcher can't create tcp socket for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
                     strerror(errno));
                 ret = -1;
                 break;
             }
         }
         /* setsockopt */
-        if (sockets->tcp[i].addr->ai_family != AF_INET6) {
+        if (sockets->tcp[i].addr->ai_family == AF_INET) {
             if (setsockopt(sockets->tcp[i].s, SOL_SOCKET, SO_REUSEADDR, &on,
                 sizeof(on)) < 0) {
                 se_log_error("zone fetcher setsockopt(..., SO_REUSEADDR, ...) "
-                    "failed: %s", strerror(errno));
+                    "failed for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
+                    strerror(errno));
             }
             /* fcntl */
             if (fcntl(sockets->tcp[i].s, F_SETFL, O_NONBLOCK) == -1) {
-                se_log_error("zone fetcher cannot fcntl TCP: %s",
+                se_log_error("zone fetcher cannot fcntl tcp/4 for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
                     strerror(errno));
             }
             /* bind */
             if (bind(sockets->tcp[i].s,
                 (struct sockaddr *) sockets->tcp[i].addr->ai_addr,
                 sockets->tcp[i].addr->ai_addrlen) != 0) {
-                se_log_error("zone fetcher can't bind TCP socket: %s",
+                se_log_error("zone fetcher can't bind tcp/4 socket for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
                     strerror(errno));
                 ret = -1;
                 break;
             }
             /* listen */
             if (listen(sockets->tcp[i].s, 5) == -1) {
-                se_log_error("zone fetcher can't listen to TCP socket: "
-                    "%s", strerror(errno));
+                se_log_error("zone fetcher can't listen to tcp/4 socket for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
+                    strerror(errno));
                 ret = -1;
                 break;
             }
@@ -777,7 +795,9 @@
                     sizeof(on)) < 0)
                 {
                     se_log_error("zone fetcher setsockopt(..., IPV6_V6ONLY, "
-                        "...) failed: %s", strerror(errno));
+                        "...) failed for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
+                    strerror(errno));
                     ret = -1;
                     break;
                 }
@@ -787,26 +807,31 @@
             if (setsockopt(sockets->tcp[i].s, SOL_SOCKET, SO_REUSEADDR, &on,
                 sizeof(on)) < 0) {
                 se_log_error("zone fetcher setsockopt(..., SO_REUSEADDR, ...) "
-                    "failed: %s", strerror(errno));
+                    "failed for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
+                    strerror(errno));
             }
             /* fcntl */
             if (fcntl(sockets->tcp[i].s, F_SETFL, O_NONBLOCK) == -1) {
-                se_log_error("zone fetcher cannot fcntl TCP: %s",
+                se_log_error("zone fetcher cannot fcntl tcp/6 for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
                     strerror(errno));
             }
             /* bind */
             if (bind(sockets->tcp[i].s,
                 (struct sockaddr *) sockets->tcp[i].addr->ai_addr,
                 sockets->tcp[i].addr->ai_addrlen) != 0) {
-                se_log_error("zone fetcher can't bind TCP socket: %s",
+                se_log_error("zone fetcher can't bind tcp/6 socket for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
                     strerror(errno));
                 ret = -1;
                 break;
             }
             /* listen */
             if (listen(sockets->tcp[i].s, 5) == -1) {
-                se_log_error("zone fetcher can't listen to TCP socket: "
-                    "%s", strerror(errno));
+                se_log_error("zone fetcher can't listen to tcp/6 socket for "
+                    "%s:%s (%s)", node?node:"(null)", port?port:"(null)",
+                    strerror(errno));
                 ret = -1;
                 break;
             }
@@ -974,8 +999,6 @@
             fclose(fd);
 
             /* moving and kicking */
-            snprintf(dest_file, sizeof(dest_file), "%s.axfr",
-                zone->input_file?zone->input_file:"(null)");
             snprintf(lock_file, sizeof(lock_file), "%s.lock",
                 zone->input_file?zone->input_file:"(null)");
 
@@ -996,7 +1019,12 @@
             }
             assert(fd); /* locked */
 
+            snprintf(dest_file, sizeof(dest_file), "%s.axfr",
+                zone->input_file?zone->input_file:"(null)");
             if(rename(axfr_file, dest_file) == 0) {
+                fclose(fd);
+                (void) unlink(lock_file); /* unlocked */
+
                 if (kick_signer) {
                     snprintf(engine_sign_cmd, sizeof(engine_sign_cmd),
                         "%s sign %s > /dev/null 2>&1",
@@ -1008,13 +1036,12 @@
                     }
                 }
             } else {
+                fclose(fd);
+                (void) unlink(lock_file); /* unlocked */
+
                 se_log_error("zone fetcher could not move AXFR to %s",
                     dest_file);
             }
-
-            fclose(fd);
-            (void) unlink(lock_file); /* unlocked */
-
             ldns_resolver_deep_free(xfrd);
             return 0;
         }
@@ -1450,9 +1477,13 @@
         fprintf(out, "interfaces: %s\n", config->notifylist?"":"none");
         servers = config->notifylist;
         while (servers) {
-            fprintf(out, "\t%s\n", servers->ipaddr?servers->ipaddr:"(null)");
+            fprintf(out, "\t%s %s:%s\n",
+                servers->family==AF_INET6?"ipv6":"ipv4",
+                servers->ipaddr?servers->ipaddr:"(null)",
+                servers->port?servers->port:"(null)");
             servers = servers->next;
         }
+        fprintf(out, "list zone fetcher settings done.\n");
     }
     else fprintf(out, "no config\n");
 }

Modified: branches/OpenDNSSEC-1.2/signer/src/tools/zone_fetcher.h
===================================================================
--- branches/OpenDNSSEC-1.2/signer/src/tools/zone_fetcher.h	2011-07-13 13:58:11 UTC (rev 5327)
+++ branches/OpenDNSSEC-1.2/signer/src/tools/zone_fetcher.h	2011-07-13 13:58:56 UTC (rev 5328)
@@ -43,7 +43,6 @@
 #ifndef TOOLS_ZONEFETCHER_H
 #define TOOLS_ZONEFETCHER_H
 
-
 #define DNS_PORT_STRING "53"
 #define INBUF_SIZE      4096 /* max size for incoming queries */
 #define MAX_INTERFACES  128
@@ -134,8 +133,7 @@
  */
 int
 tools_zone_fetcher(const char* config_file, const char* zonelist_file,
-    const char* group, const char* user, const char* chroot, const char* log_file,
-    int use_syslog, int verbosity);
+    const char* group, const char* user, const char* chroot,
+    const char* log_file, int use_syslog, int verbosity);
 
 #endif /* TOOLS_ZONEFETCHER_H */
-




More information about the Opendnssec-commits mailing list