]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: dns: Remove useless test on ns->dgram in dns_connect_nameserver()
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 4 Mar 2021 15:58:35 +0000 (16:58 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 4 Mar 2021 15:58:36 +0000 (16:58 +0100)
When dns_connect_nameserver() is called, the nameserver has always a dgram
field properly defined. The caller, dns_send_nameserver(), already performed
the appropriate verification.

src/dns.c

index d360f2cdcfd33400f8708f2636f90d090ca27a30..6e39d6ba40a05b8e704f7b9ee36f38510c9451e5 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -41,44 +41,40 @@ DECLARE_STATIC_POOL(dns_query_pool, "dns_query", sizeof(struct dns_query));
 DECLARE_STATIC_POOL(dns_msg_buf, "dns_msg_buf", DNS_TCP_MSG_RING_MAX_SIZE);
 
 /* Opens an UDP socket on the namesaver's IP/Port, if required. Returns 0 on
- * success, -1 otherwise.
+ * success, -1 otherwise. ns->dgram must be defined.
  */
 static int dns_connect_nameserver(struct dns_nameserver *ns)
 {
-       if (ns->dgram) {
-               struct dgram_conn *dgram = &ns->dgram->conn;
-               int fd;
-
-               /* Already connected */
-               if (dgram->t.sock.fd != -1)
-                       return 0;
-
-               /* Create an UDP socket and connect it on the nameserver's IP/Port */
-               if ((fd = socket(dgram->addr.to.ss_family, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
-                       send_log(NULL, LOG_WARNING,
-                                "DNS : section '%s': can't create socket for nameserver '%s'.\n",
-                                ns->counters->pid, ns->id);
-                       return -1;
-               }
-               if (connect(fd, (struct sockaddr*)&dgram->addr.to, get_addr_len(&dgram->addr.to)) == -1) {
-                       send_log(NULL, LOG_WARNING,
-                                "DNS : section '%s': can't connect socket for nameserver '%s'.\n",
-                                ns->counters->id, ns->id);
-                       close(fd);
-                       return -1;
-               }
-
-               /* Make the socket non blocking */
-               fcntl(fd, F_SETFL, O_NONBLOCK);
+       struct dgram_conn *dgram = &ns->dgram->conn;
+       int fd;
 
-               /* Add the fd in the fd list and update its parameters */
-               dgram->t.sock.fd = fd;
-               fd_insert(fd, dgram, dgram_fd_handler, MAX_THREADS_MASK);
-               fd_want_recv(fd);
+       /* Already connected */
+       if (dgram->t.sock.fd != -1)
                return 0;
+
+       /* Create an UDP socket and connect it on the nameserver's IP/Port */
+       if ((fd = socket(dgram->addr.to.ss_family, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
+               send_log(NULL, LOG_WARNING,
+                        "DNS : section '%s': can't create socket for nameserver '%s'.\n",
+                        ns->counters->pid, ns->id);
+               return -1;
+       }
+       if (connect(fd, (struct sockaddr*)&dgram->addr.to, get_addr_len(&dgram->addr.to)) == -1) {
+               send_log(NULL, LOG_WARNING,
+                        "DNS : section '%s': can't connect socket for nameserver '%s'.\n",
+                        ns->counters->id, ns->id);
+               close(fd);
+               return -1;
        }
 
-       return -1;
+       /* Make the socket non blocking */
+       fcntl(fd, F_SETFL, O_NONBLOCK);
+
+       /* Add the fd in the fd list and update its parameters */
+       dgram->t.sock.fd = fd;
+       fd_insert(fd, dgram, dgram_fd_handler, MAX_THREADS_MASK);
+       fd_want_recv(fd);
+       return 0;
 }
 
 /* Sends a message to a name server