]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
afs: check for duplicate servers in VL server list
authorYuto Ohnuki <ytohnuki@amazon.com>
Mon, 22 Jun 2026 09:08:43 +0000 (10:08 +0100)
committerChristian Brauner <brauner@kernel.org>
Wed, 1 Jul 2026 13:26:20 +0000 (15:26 +0200)
The DNS response may contain the same server more than once. Check for
duplicates by name and port before inserting into the list to avoid
duplicate entries.

Addresses the TODO comment in afs_extract_vlserver_list().

Signed-off-by: Yuto Ohnuki <ytohnuki@amazon.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Link: https://patch.msgid.link/20260622090856.2746629-10-dhowells@redhat.com
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
fs/afs/vl_list.c

index 003889cf0f18dcf4af5bb3dde43260802cc967d7..8e1cf6cdcf71342c107721222694bfbef041d749 100644 (file)
@@ -289,8 +289,20 @@ struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *cell,
                        afs_put_addrlist(old, afs_alist_trace_put_vlserver_old);
                }
 
+               /* Check for duplicates in the server list */
+               for (j = 0; j < vllist->nr_servers; j++) {
+                       struct afs_vlserver *s = vllist->servers[j].server;
 
-               /* TODO: Might want to check for duplicates */
+                       if (s->name_len == server->name_len &&
+                           s->port == server->port &&
+                           strncasecmp(s->name, server->name, server->name_len) == 0) {
+                               afs_put_vlserver(cell->net, server);
+                               server = NULL;
+                               break;
+                       }
+               }
+               if (!server)
+                       continue;
 
                /* Insertion-sort by priority and weight */
                for (j = 0; j < vllist->nr_servers; j++) {