Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ff0d16a authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'listener_refactor'



Eric Dumazet says:

====================
inet: tcp listener refactoring, part 8

These patches prepare request socks being hashed into general ehash
table : We declare 3 aliases (ireq_state, ireq_refcnt, ireq_family)

Note that refcnt is not yet handled, this will be done later.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 54720df1 3f66b083
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <net/sock.h>
#include <net/request_sock.h>
#include <net/netns/hash.h>
#include <net/tcp_states.h>

/** struct ip_options - IP Options
 *
@@ -79,6 +80,9 @@ struct inet_request_sock {
#define ir_iif			req.__req_common.skc_bound_dev_if
#define ir_cookie		req.__req_common.skc_cookie
#define ireq_net		req.__req_common.skc_net
#define ireq_state		req.__req_common.skc_state
#define ireq_refcnt		req.__req_common.skc_refcnt
#define ireq_family		req.__req_common.skc_family

	kmemcheck_bitfield_begin(flags);
	u16			snd_wscale : 4,
@@ -249,6 +253,8 @@ static inline struct request_sock *inet_reqsk_alloc(struct request_sock_ops *ops
	if (req != NULL) {
		kmemcheck_annotate_bitfield(ireq, flags);
		ireq->opt = NULL;
		atomic64_set(&ireq->ir_cookie, 0);
		ireq->ireq_state = TCP_NEW_SYN_RECV;
	}

	return req;
+13 −0
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ int inet_rtx_syn_ack(struct sock *parent, struct request_sock *req);
 */
struct request_sock {
	struct sock_common		__req_common;
#define rsk_refcnt			__req_common.skc_refcnt

	struct request_sock		*dl_next;
	u16				mss;
	u8				num_retrans; /* number of retransmits */
@@ -75,6 +77,11 @@ static inline struct request_sock *reqsk_alloc(const struct request_sock_ops *op
	return req;
}

static inline struct request_sock *inet_reqsk(struct sock *sk)
{
	return (struct request_sock *)sk;
}

static inline void __reqsk_free(struct request_sock *req)
{
	kmem_cache_free(req->rsk_ops->slab, req);
@@ -86,6 +93,12 @@ static inline void reqsk_free(struct request_sock *req)
	__reqsk_free(req);
}

static inline void reqsk_put(struct request_sock *req)
{
	if (atomic_dec_and_test(&req->rsk_refcnt))
		reqsk_free(req);
}

extern int sysctl_max_syn_backlog;

/** struct listen_sock - listen state
+1 −1
Original line number Diff line number Diff line
@@ -1625,7 +1625,7 @@ static inline void sock_put(struct sock *sk)
		sk_free(sk);
}
/* Generic version of sock_put(), dealing with all sockets
 * (TCP_TIMEWAIT, ESTABLISHED...)
 * (TCP_TIMEWAIT, TCP_NEW_SYN_RECV, ESTABLISHED...)
 */
void sock_gen_put(struct sock *sk);

+3 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ enum {
	TCP_LAST_ACK,
	TCP_LISTEN,
	TCP_CLOSING,	/* Now a valid state */
	TCP_NEW_SYN_RECV,

	TCP_MAX_STATES	/* Leave at the end! */
};
@@ -44,7 +45,8 @@ enum {
	TCPF_CLOSE_WAIT	 = (1 << 8),
	TCPF_LAST_ACK	 = (1 << 9),
	TCPF_LISTEN	 = (1 << 10),
	TCPF_CLOSING	 = (1 << 11) 
	TCPF_CLOSING	 = (1 << 11),
	TCPF_NEW_SYN_RECV = (1 << 12),
};

#endif	/* _LINUX_TCP_STATES_H */
+43 −28
Original line number Diff line number Diff line
@@ -1668,6 +1668,8 @@ void sock_edemux(struct sk_buff *skb)

	if (sk->sk_state == TCP_TIME_WAIT)
		inet_twsk_put(inet_twsk(sk));
	else if (sk->sk_state == TCP_NEW_SYN_RECV)
		reqsk_put(inet_reqsk(sk));
	else
		sock_put(sk);
}
@@ -2726,6 +2728,42 @@ static inline void release_proto_idx(struct proto *prot)
}
#endif

static void req_prot_cleanup(struct request_sock_ops *rsk_prot)
{
	if (!rsk_prot)
		return;
	kfree(rsk_prot->slab_name);
	rsk_prot->slab_name = NULL;
	if (rsk_prot->slab) {
		kmem_cache_destroy(rsk_prot->slab);
		rsk_prot->slab = NULL;
	}
}

static int req_prot_init(const struct proto *prot)
{
	struct request_sock_ops *rsk_prot = prot->rsk_prot;

	if (!rsk_prot)
		return 0;

	rsk_prot->slab_name = kasprintf(GFP_KERNEL, "request_sock_%s",
					prot->name);
	if (!rsk_prot->slab_name)
		return -ENOMEM;

	rsk_prot->slab = kmem_cache_create(rsk_prot->slab_name,
					   rsk_prot->obj_size, 0,
					   SLAB_HWCACHE_ALIGN, NULL);

	if (!rsk_prot->slab) {
		pr_crit("%s: Can't create request sock SLAB cache!\n",
			prot->name);
		return -ENOMEM;
	}
	return 0;
}

int proto_register(struct proto *prot, int alloc_slab)
{
	if (alloc_slab) {
@@ -2739,21 +2777,8 @@ int proto_register(struct proto *prot, int alloc_slab)
			goto out;
		}

		if (prot->rsk_prot != NULL) {
			prot->rsk_prot->slab_name = kasprintf(GFP_KERNEL, "request_sock_%s", prot->name);
			if (prot->rsk_prot->slab_name == NULL)
				goto out_free_sock_slab;

			prot->rsk_prot->slab = kmem_cache_create(prot->rsk_prot->slab_name,
								 prot->rsk_prot->obj_size, 0,
								 SLAB_HWCACHE_ALIGN, NULL);

			if (prot->rsk_prot->slab == NULL) {
				pr_crit("%s: Can't create request sock SLAB cache!\n",
					prot->name);
				goto out_free_request_sock_slab_name;
			}
		}
		if (req_prot_init(prot))
			goto out_free_request_sock_slab;

		if (prot->twsk_prot != NULL) {
			prot->twsk_prot->twsk_slab_name = kasprintf(GFP_KERNEL, "tw_sock_%s", prot->name);
@@ -2782,14 +2807,8 @@ int proto_register(struct proto *prot, int alloc_slab)
out_free_timewait_sock_slab_name:
	kfree(prot->twsk_prot->twsk_slab_name);
out_free_request_sock_slab:
	if (prot->rsk_prot && prot->rsk_prot->slab) {
		kmem_cache_destroy(prot->rsk_prot->slab);
		prot->rsk_prot->slab = NULL;
	}
out_free_request_sock_slab_name:
	if (prot->rsk_prot)
		kfree(prot->rsk_prot->slab_name);
out_free_sock_slab:
	req_prot_cleanup(prot->rsk_prot);

	kmem_cache_destroy(prot->slab);
	prot->slab = NULL;
out:
@@ -2809,11 +2828,7 @@ void proto_unregister(struct proto *prot)
		prot->slab = NULL;
	}

	if (prot->rsk_prot != NULL && prot->rsk_prot->slab != NULL) {
		kmem_cache_destroy(prot->rsk_prot->slab);
		kfree(prot->rsk_prot->slab_name);
		prot->rsk_prot->slab = NULL;
	}
	req_prot_cleanup(prot->rsk_prot);

	if (prot->twsk_prot != NULL && prot->twsk_prot->twsk_slab != NULL) {
		kmem_cache_destroy(prot->twsk_prot->twsk_slab);
Loading