Add a socket destructor callback. This allows kernel providers to set
callbacks to perform additional cleanup actions at the time a socket is closed. Michio Honda presented a use for this at BSDCan 2018. (See https://www.bsdcan.org/2018/schedule/events/965.en.html .) Submitted by: Michio Honda <micchie at sfc.wide.ad.jp> (previous version) Reviewed by: lstewart (previous version) Differential Revision: https://reviews.freebsd.org/D15706
This commit is contained in:
parent
239f5f541b
commit
1fbe13cf4b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334853
@ -26,7 +26,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd May 26, 2014
|
.Dd June 8, 2018
|
||||||
.Dt SOCKET 9
|
.Dt SOCKET 9
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -54,6 +54,11 @@
|
|||||||
.Fc
|
.Fc
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn sodisconnect "struct socket *so"
|
.Fn sodisconnect "struct socket *so"
|
||||||
|
.Ft void
|
||||||
|
.Fo sodtor_set
|
||||||
|
.Fa "struct socket *so"
|
||||||
|
.Fa "void (*func)(struct socket *)"
|
||||||
|
.Fc
|
||||||
.Ft struct sockaddr *
|
.Ft struct sockaddr *
|
||||||
.Fn sodupsockaddr "const struct sockaddr *sa" "int mflags"
|
.Fn sodupsockaddr "const struct sockaddr *sa" "int mflags"
|
||||||
.Ft void
|
.Ft void
|
||||||
@ -369,6 +374,13 @@ be cleared, with
|
|||||||
.Dv SO_RCV
|
.Dv SO_RCV
|
||||||
or
|
or
|
||||||
.Dv SO_SND .
|
.Dv SO_SND .
|
||||||
|
.Ss Socket Destructor Callback
|
||||||
|
A kernel system can use the
|
||||||
|
.Fn sodtor_set
|
||||||
|
function to set a destructor for a socket.
|
||||||
|
The destructor is called when the socket is closed.
|
||||||
|
The destructor is called after the protocol close routine has completed.
|
||||||
|
The destructor can serve as a callback to initiate additional cleanup actions.
|
||||||
.Ss Socket I/O
|
.Ss Socket I/O
|
||||||
The
|
The
|
||||||
.Fn soreceive
|
.Fn soreceive
|
||||||
|
@ -1101,6 +1101,8 @@ soclose(struct socket *so)
|
|||||||
drop:
|
drop:
|
||||||
if (so->so_proto->pr_usrreqs->pru_close != NULL)
|
if (so->so_proto->pr_usrreqs->pru_close != NULL)
|
||||||
(*so->so_proto->pr_usrreqs->pru_close)(so);
|
(*so->so_proto->pr_usrreqs->pru_close)(so);
|
||||||
|
if (so->so_dtor != NULL)
|
||||||
|
so->so_dtor(so);
|
||||||
|
|
||||||
SOCK_LOCK(so);
|
SOCK_LOCK(so);
|
||||||
if ((listening = (so->so_options & SO_ACCEPTCONN))) {
|
if ((listening = (so->so_options & SO_ACCEPTCONN))) {
|
||||||
@ -3812,6 +3814,17 @@ sodupsockaddr(const struct sockaddr *sa, int mflags)
|
|||||||
return sa2;
|
return sa2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Register per-socket destructor.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
sodtor_set(struct socket *so, so_dtor_t *func)
|
||||||
|
{
|
||||||
|
|
||||||
|
SOCK_LOCK_ASSERT(so);
|
||||||
|
so->so_dtor = func;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Register per-socket buffer upcalls.
|
* Register per-socket buffer upcalls.
|
||||||
*/
|
*/
|
||||||
|
@ -63,6 +63,7 @@ struct vnet;
|
|||||||
* private data and error information.
|
* private data and error information.
|
||||||
*/
|
*/
|
||||||
typedef int so_upcall_t(struct socket *, void *, int);
|
typedef int so_upcall_t(struct socket *, void *, int);
|
||||||
|
typedef void so_dtor_t(struct socket *);
|
||||||
|
|
||||||
struct socket;
|
struct socket;
|
||||||
|
|
||||||
@ -99,6 +100,7 @@ struct socket {
|
|||||||
/* NB: generation count must not be first. */
|
/* NB: generation count must not be first. */
|
||||||
so_gen_t so_gencnt; /* (h) generation count */
|
so_gen_t so_gencnt; /* (h) generation count */
|
||||||
void *so_emuldata; /* (b) private data for emulators */
|
void *so_emuldata; /* (b) private data for emulators */
|
||||||
|
so_dtor_t *so_dtor; /* (b) optional destructor */
|
||||||
struct osd osd; /* Object Specific extensions */
|
struct osd osd; /* Object Specific extensions */
|
||||||
/*
|
/*
|
||||||
* so_fibnum, so_user_cookie and friends can be used to attach
|
* so_fibnum, so_user_cookie and friends can be used to attach
|
||||||
@ -397,6 +399,7 @@ int soconnect2(struct socket *so1, struct socket *so2);
|
|||||||
int socreate(int dom, struct socket **aso, int type, int proto,
|
int socreate(int dom, struct socket **aso, int type, int proto,
|
||||||
struct ucred *cred, struct thread *td);
|
struct ucred *cred, struct thread *td);
|
||||||
int sodisconnect(struct socket *so);
|
int sodisconnect(struct socket *so);
|
||||||
|
void sodtor_set(struct socket *, so_dtor_t *);
|
||||||
struct sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags);
|
struct sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags);
|
||||||
void sofree(struct socket *so);
|
void sofree(struct socket *so);
|
||||||
void sohasoutofband(struct socket *so);
|
void sohasoutofband(struct socket *so);
|
||||||
|
Loading…
Reference in New Issue
Block a user