mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-08 14:13:53 +00:00
udp: add encap_destroy callback
Users of udp encapsulation currently have an encap_rcv callback which they can use to hook into the udp receive path. In situations where a encapsulation user allocates resources associated with a udp encap socket, it may be convenient to be able to also hook the proto .destroy operation. For example, if an encap user holds a reference to the udp socket, the destroy hook might be used to relinquish this reference. This patch adds a socket destroy hook into udp, which is set and enabled in the same way as the existing encap_rcv hook. Signed-off-by: Tom Parkin <tparkin@katalix.com> Signed-off-by: James Chapman <jchapman@katalix.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
f1e79e2080
commit
44046a593e
@ -68,6 +68,7 @@ struct udp_sock {
|
|||||||
* For encapsulation sockets.
|
* For encapsulation sockets.
|
||||||
*/
|
*/
|
||||||
int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
|
int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
|
||||||
|
void (*encap_destroy)(struct sock *sk);
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline struct udp_sock *udp_sk(const struct sock *sk)
|
static inline struct udp_sock *udp_sk(const struct sock *sk)
|
||||||
|
@ -1762,9 +1762,16 @@ int udp_rcv(struct sk_buff *skb)
|
|||||||
|
|
||||||
void udp_destroy_sock(struct sock *sk)
|
void udp_destroy_sock(struct sock *sk)
|
||||||
{
|
{
|
||||||
|
struct udp_sock *up = udp_sk(sk);
|
||||||
bool slow = lock_sock_fast(sk);
|
bool slow = lock_sock_fast(sk);
|
||||||
udp_flush_pending_frames(sk);
|
udp_flush_pending_frames(sk);
|
||||||
unlock_sock_fast(sk, slow);
|
unlock_sock_fast(sk, slow);
|
||||||
|
if (static_key_false(&udp_encap_needed) && up->encap_type) {
|
||||||
|
void (*encap_destroy)(struct sock *sk);
|
||||||
|
encap_destroy = ACCESS_ONCE(up->encap_destroy);
|
||||||
|
if (encap_destroy)
|
||||||
|
encap_destroy(sk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1285,10 +1285,18 @@ int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk,
|
|||||||
|
|
||||||
void udpv6_destroy_sock(struct sock *sk)
|
void udpv6_destroy_sock(struct sock *sk)
|
||||||
{
|
{
|
||||||
|
struct udp_sock *up = udp_sk(sk);
|
||||||
lock_sock(sk);
|
lock_sock(sk);
|
||||||
udp_v6_flush_pending_frames(sk);
|
udp_v6_flush_pending_frames(sk);
|
||||||
release_sock(sk);
|
release_sock(sk);
|
||||||
|
|
||||||
|
if (static_key_false(&udpv6_encap_needed) && up->encap_type) {
|
||||||
|
void (*encap_destroy)(struct sock *sk);
|
||||||
|
encap_destroy = ACCESS_ONCE(up->encap_destroy);
|
||||||
|
if (encap_destroy)
|
||||||
|
encap_destroy(sk);
|
||||||
|
}
|
||||||
|
|
||||||
inet6_destroy_sock(sk);
|
inet6_destroy_sock(sk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user