xref: /openbmc/linux/include/net/timewait_sock.h (revision 1eb4c977)
1 /*
2  * NET		Generic infrastructure for Network protocols.
3  *
4  * Authors:	Arnaldo Carvalho de Melo <acme@conectiva.com.br>
5  *
6  *		This program is free software; you can redistribute it and/or
7  *		modify it under the terms of the GNU General Public License
8  *		as published by the Free Software Foundation; either version
9  *		2 of the License, or (at your option) any later version.
10  */
11 #ifndef _TIMEWAIT_SOCK_H
12 #define _TIMEWAIT_SOCK_H
13 
14 #include <linux/slab.h>
15 #include <linux/bug.h>
16 #include <net/sock.h>
17 
18 struct timewait_sock_ops {
19 	struct kmem_cache	*twsk_slab;
20 	char		*twsk_slab_name;
21 	unsigned int	twsk_obj_size;
22 	int		(*twsk_unique)(struct sock *sk,
23 				       struct sock *sktw, void *twp);
24 	void		(*twsk_destructor)(struct sock *sk);
25 	void		*(*twsk_getpeer)(struct sock *sk);
26 };
27 
28 static inline int twsk_unique(struct sock *sk, struct sock *sktw, void *twp)
29 {
30 	if (sk->sk_prot->twsk_prot->twsk_unique != NULL)
31 		return sk->sk_prot->twsk_prot->twsk_unique(sk, sktw, twp);
32 	return 0;
33 }
34 
35 static inline void twsk_destructor(struct sock *sk)
36 {
37 	BUG_ON(sk == NULL);
38 	BUG_ON(sk->sk_prot == NULL);
39 	BUG_ON(sk->sk_prot->twsk_prot == NULL);
40 	if (sk->sk_prot->twsk_prot->twsk_destructor != NULL)
41 		sk->sk_prot->twsk_prot->twsk_destructor(sk);
42 }
43 
44 static inline void *twsk_getpeer(struct sock *sk)
45 {
46 	if (sk->sk_prot->twsk_prot->twsk_getpeer)
47 		return sk->sk_prot->twsk_prot->twsk_getpeer(sk);
48 	return NULL;
49 }
50 
51 #endif /* _TIMEWAIT_SOCK_H */
52