Skip to content

Commit 2e82a58

Browse files
VinDuvdavem330
authored andcommitted
appletalk: Improve handling of broadcast packets
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/[email protected]/ Link: https://gist.github.com/VinDuv/4db433b6dce39d51a5b7847ee749b2a4 Signed-off-by: Vincent Duvert <[email protected]> Signed-off-by: Doug Brown <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 86b29d8 commit 2e82a58

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

net/appletalk/ddp.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static inline void atalk_remove_socket(struct sock *sk)
8888
static struct sock *atalk_search_socket(struct sockaddr_at *to,
8989
struct atalk_iface *atif)
9090
{
91+
struct sock *def_socket = NULL;
9192
struct sock *s;
9293

9394
read_lock_bh(&atalk_sockets_lock);
@@ -98,8 +99,20 @@ static struct sock *atalk_search_socket(struct sockaddr_at *to,
9899
continue;
99100

100101
if (to->sat_addr.s_net == ATADDR_ANYNET &&
101-
to->sat_addr.s_node == ATADDR_BCAST)
102-
goto found;
102+
to->sat_addr.s_node == ATADDR_BCAST) {
103+
if (atif->address.s_node == at->src_node &&
104+
atif->address.s_net == at->src_net) {
105+
/* This socket's address matches the address of the interface
106+
* that received the packet -- use it
107+
*/
108+
goto found;
109+
}
110+
111+
/* Continue searching for a socket matching the interface address,
112+
* but use this socket by default if no other one is found
113+
*/
114+
def_socket = s;
115+
}
103116

104117
if (to->sat_addr.s_net == at->src_net &&
105118
(to->sat_addr.s_node == at->src_node ||
@@ -116,7 +129,7 @@ static struct sock *atalk_search_socket(struct sockaddr_at *to,
116129
goto found;
117130
}
118131
}
119-
s = NULL;
132+
s = def_socket;
120133
found:
121134
read_unlock_bh(&atalk_sockets_lock);
122135
return s;

0 commit comments

Comments
 (0)