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
This commit is contained in:
Gleb Smirnoff 2025-07-25 13:09:59 -07:00
parent 183d093056
commit b9fa99600a

View file

@ -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