]> git.dujemihanovic.xyz Git - linux.git/commitdiff
appletalk: Improve handling of broadcast packets
authorVincent Duvert <vincent.ldev@duvert.net>
Sun, 5 May 2024 18:54:57 +0000 (11:54 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 8 May 2024 11:17:19 +0000 (12:17 +0100)
When a broadcast AppleTalk packet is received, prefer queuing it on the
socket whose address matches the address of the interface that received
the packet (and is listening on the correct port). Userspace
applications that handle such packets will usually send a response on
the same socket that received the packet; this fix allows the response
to be sent on the correct interface.

If a socket matching the interface's address is not found, an arbitrary
socket listening on the correct port will be used, if any. This matches
the implementation's previous behavior.

Fixes atalkd's responses to network information requests when multiple
network interfaces are configured to use AppleTalk.

Link: https://lore.kernel.org/netdev/20200722113752.1218-2-vincent.ldev@duvert.net/
Link: https://gist.github.com/VinDuv/4db433b6dce39d51a5b7847ee749b2a4
Signed-off-by: Vincent Duvert <vincent.ldev@duvert.net>
Signed-off-by: Doug Brown <doug@schmorgal.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/appletalk/ddp.c

index 198f5ba2feae6662cd7363b72db6d412f03b48c7..b068651984fe3dec6c23337ae095a6f13a14ffa3 100644 (file)
@@ -88,6 +88,7 @@ static inline void atalk_remove_socket(struct sock *sk)
 static struct sock *atalk_search_socket(struct sockaddr_at *to,
                                        struct atalk_iface *atif)
 {
+       struct sock *def_socket = NULL;
        struct sock *s;
 
        read_lock_bh(&atalk_sockets_lock);
@@ -98,8 +99,20 @@ static struct sock *atalk_search_socket(struct sockaddr_at *to,
                        continue;
 
                if (to->sat_addr.s_net == ATADDR_ANYNET &&
-                   to->sat_addr.s_node == ATADDR_BCAST)
-                       goto found;
+                   to->sat_addr.s_node == ATADDR_BCAST) {
+                       if (atif->address.s_node == at->src_node &&
+                           atif->address.s_net == at->src_net) {
+                               /* This socket's address matches the address of the interface
+                                * that received the packet -- use it
+                                */
+                               goto found;
+                       }
+
+                       /* Continue searching for a socket matching the interface address,
+                        * but use this socket by default if no other one is found
+                        */
+                       def_socket = s;
+               }
 
                if (to->sat_addr.s_net == at->src_net &&
                    (to->sat_addr.s_node == at->src_node ||
@@ -116,7 +129,7 @@ static struct sock *atalk_search_socket(struct sockaddr_at *to,
                        goto found;
                }
        }
-       s = NULL;
+       s = def_socket;
 found:
        read_unlock_bh(&atalk_sockets_lock);
        return s;