The branch main has been updated by glebius:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=b9fa99600a78c66dce9040595f04bfe2ba25652c

commit b9fa99600a78c66dce9040595f04bfe2ba25652c
Author:     Gleb Smirnoff <gleb...@freebsd.org>
AuthorDate: 2025-07-25 20:09:59 +0000
Commit:     Gleb Smirnoff <gleb...@freebsd.org>
CommitDate: 2025-07-25 20:09:59 +0000

    bsnmpd: fix unix/stream socket operation
    
    With new send method, that gives us directly port_input pointer, we know
    the correct file descriptor right away, no matter are we in SOCK_DGRAM or
    in SOCK_STREAM mode.  Previously, the function tried to search for the
    socket, and that was totally wrong.  With several simultaneous connections
    this end up with sending a reply to incorrect socket.
    
    Reviewed by:            harti
    Differential Revision:  https://reviews.freebsd.org/D51361
---
 contrib/bsnmp/snmpd/trans_lsock.c | 23 ++---------------------
 1 file changed, 2 insertions(+), 21 deletions(-)

diff --git a/contrib/bsnmp/snmpd/trans_lsock.c 
b/contrib/bsnmp/snmpd/trans_lsock.c
index 4a850d434d7c..01beb01927ec 100644
--- a/contrib/bsnmp/snmpd/trans_lsock.c
+++ b/contrib/bsnmp/snmpd/trans_lsock.c
@@ -395,29 +395,10 @@ lsock_init_port(struct tport *tp)
  * Send something
  */
 static ssize_t
-lsock_send(struct tport *tp, const u_char *buf, size_t len,
+lsock_send(struct tport *tp __unused, const u_char *buf, size_t len,
     struct port_input *pi)
 {
-       struct lsock_port *p = __containerof(tp, struct lsock_port, tport);
-       struct lsock_peer *peer;
-
-       if (p->type == LOCP_DGRAM_PRIV || p->type == LOCP_DGRAM_UNPRIV) {
-               peer = LIST_FIRST(&p->peers);
-
-       } else {
-               /* search for the peer */
-               LIST_FOREACH(peer, &p->peers, link)
-                       if (peer->input.peerlen == pi->peerlen &&
-                           memcmp(peer->input.peer, pi->peer, pi->peerlen) == 
0)
-                               break;
-               if (peer == NULL) {
-                       errno = ENOTCONN;
-                       return (-1);
-               }
-       }
-
-       return (sendto(peer->input.fd, buf, len, MSG_NOSIGNAL, pi->peer,
-           pi->peerlen));
+       return (sendto(pi->fd, buf, len, MSG_NOSIGNAL, pi->peer, pi->peerlen));
 }
 
 static void

Reply via email to