You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/03/17 10:19:05 UTC

[GitHub] [incubator-nuttx] anchao opened a new pull request #5768: netdb/dns: do not insert the duplicate DNS address

anchao opened a new pull request #5768:
URL: https://github.com/apache/incubator-nuttx/pull/5768


   ## Summary
   
   netdb/dns: do not insert the duplicate DNS address
   
   Signed-off-by: chao.an <an...@xiaomi.com>
   
   ## Impact
   
   N/A
   
   ## Testing
   
   DNS test


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #5768: netdb/dns: do not insert the duplicate DNS address

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #5768:
URL: https://github.com/apache/incubator-nuttx/pull/5768#discussion_r829185991



##########
File path: libs/libc/netdb/lib_dnsaddserver.c
##########
@@ -257,15 +258,27 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
       return -EINVAL;
     }
 
-  memcpy(&g_dns_servers[idx].addr, addr, copylen);
-
   /* A port number of zero means to use the default DNS server port number */
 
   if (*pport == 0)
     {
       *pport = HTONS(DNS_DEFAULT_PORT);
     }
 
+  for (i = 0; i < g_dns_nservers; i++)
+    {
+      if (g_dns_servers[i].addr.sa_family == addr->sa_family)
+        {
+          if (memcmp(&g_dns_servers[i].addr, addr, copylen) == 0)
+            {
+              dns_semgive();
+              return OK;
+            }
+        }
+    }
+
+  memcpy(&g_dns_servers[idx].addr, addr, copylen);

Review comment:
       need update CONFIG_NETDB_RESOLVCONF version at line 65 too

##########
File path: libs/libc/netdb/lib_dnsaddserver.c
##########
@@ -257,15 +258,27 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
       return -EINVAL;
     }
 
-  memcpy(&g_dns_servers[idx].addr, addr, copylen);
-
   /* A port number of zero means to use the default DNS server port number */
 
   if (*pport == 0)
     {
       *pport = HTONS(DNS_DEFAULT_PORT);
     }
 
+  for (i = 0; i < g_dns_nservers; i++)

Review comment:
       let's call let's call dns_foreach_nameserver instead manual loop.

##########
File path: libs/libc/netdb/lib_dnsaddserver.c
##########
@@ -237,7 +238,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
       /* Set up for the IPv6 address copy */
 
       copylen = sizeof(struct sockaddr_in6);
-      pport   = &g_dns_servers[idx].ipv6.sin6_port;
+      pport   = &((FAR struct sockaddr_in6 *)addr)->sin6_port;

Review comment:
       it isn't good to change the const pointer




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 closed pull request #5768: netdb/dns: do not insert the duplicate DNS address

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 closed pull request #5768:
URL: https://github.com/apache/incubator-nuttx/pull/5768


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #5768: netdb/dns: do not insert the duplicate DNS address

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #5768:
URL: https://github.com/apache/incubator-nuttx/pull/5768#discussion_r829185991



##########
File path: libs/libc/netdb/lib_dnsaddserver.c
##########
@@ -257,15 +258,27 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
       return -EINVAL;
     }
 
-  memcpy(&g_dns_servers[idx].addr, addr, copylen);
-
   /* A port number of zero means to use the default DNS server port number */
 
   if (*pport == 0)
     {
       *pport = HTONS(DNS_DEFAULT_PORT);
     }
 
+  for (i = 0; i < g_dns_nservers; i++)
+    {
+      if (g_dns_servers[i].addr.sa_family == addr->sa_family)
+        {
+          if (memcmp(&g_dns_servers[i].addr, addr, copylen) == 0)
+            {
+              dns_semgive();
+              return OK;
+            }
+        }
+    }
+
+  memcpy(&g_dns_servers[idx].addr, addr, copylen);

Review comment:
       need update CONFIG_NETDB_RESOLVCONF version at line 65 too

##########
File path: libs/libc/netdb/lib_dnsaddserver.c
##########
@@ -257,15 +258,27 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
       return -EINVAL;
     }
 
-  memcpy(&g_dns_servers[idx].addr, addr, copylen);
-
   /* A port number of zero means to use the default DNS server port number */
 
   if (*pport == 0)
     {
       *pport = HTONS(DNS_DEFAULT_PORT);
     }
 
+  for (i = 0; i < g_dns_nservers; i++)

Review comment:
       let's call let's call dns_foreach_nameserver instead manual loop.

##########
File path: libs/libc/netdb/lib_dnsaddserver.c
##########
@@ -237,7 +238,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
       /* Set up for the IPv6 address copy */
 
       copylen = sizeof(struct sockaddr_in6);
-      pport   = &g_dns_servers[idx].ipv6.sin6_port;
+      pport   = &((FAR struct sockaddr_in6 *)addr)->sin6_port;

Review comment:
       it isn't good to change the const pointer




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #5768: netdb/dns: do not insert the duplicate DNS address

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #5768:
URL: https://github.com/apache/incubator-nuttx/pull/5768#issuecomment-1086816129


   Close, the new patch will be sent again.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org