[PATCH 1/2] uipc_socket: add sogetsockaddr convenience function
Jason A. Donenfeld
Jason at zx2c4.com
Fri Apr 23 05:39:13 UTC 2021
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 at FreeBSD.org>
Signed-off-by: Jason A. Donenfeld <Jason at 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
More information about the freebsd-net
mailing list