Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Apr 2021 23:39:01 -0600
From:      "Jason A. Donenfeld" <Jason@zx2c4.com>
To:        freebsd-net@freebsd.org
Cc:        "Jason A. Donenfeld" <Jason@zx2c4.com>
Subject:   [PATCH 1/2] uipc_socket: add sogetsockaddr convenience function
Message-ID:  <20210423053902.16087-2-Jason@zx2c4.com>
In-Reply-To: <20210423053902.16087-1-Jason@zx2c4.com>
References:  <20210423053902.16087-1-Jason@zx2c4.com>

next in thread | previous in thread | raw e-mail | index | archive | help
It is useful to be able to call pr_usrreqs->pru_sockaddr on a struct
socket, so this commit adds a wrapper around it, analogous to the other
types of socket getters.

Original-author: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 sys/kern/uipc_socket.c | 11 +++++++++++
 sys/sys/socketvar.h    |  1 +
 2 files changed, 12 insertions(+)

diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 92a204aafef..374e2a3abaa 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -3506,6 +3506,17 @@ soopt_mcopyout(struct sockopt *sopt, struct mbuf *m)
 	return (0);
 }
 
+int
+sogetsockaddr(struct socket *so, struct sockaddr **nam)
+{
+	int error;
+
+	CURVNET_SET(so->so_vnet);
+	error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, nam);
+	CURVNET_RESTORE();
+	return (error);
+}
+
 /*
  * sohasoutofband(): protocol notifies socket layer of the arrival of new
  * out-of-band data, which will then notify socket consumers.
diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h
index 295a1cf3d37..ad616a4d893 100644
--- a/sys/sys/socketvar.h
+++ b/sys/sys/socketvar.h
@@ -428,6 +428,7 @@ int	sodisconnect(struct socket *so);
 void	sodtor_set(struct socket *, so_dtor_t *);
 struct	sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags);
 void	sofree(struct socket *so);
+int	sogetsockaddr(struct socket *so, struct sockaddr **nam);
 void	sohasoutofband(struct socket *so);
 int	solisten(struct socket *so, int backlog, struct thread *td);
 void	solisten_proto(struct socket *so, int backlog);
-- 
2.31.1




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20210423053902.16087-2-Jason>