inet: add rsk_refcnt/ireq_refcnt to request socks
authorEric Dumazet <edumazet@google.com>
Thu, 12 Mar 2015 23:44:06 +0000 (16:44 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 13 Mar 2015 02:58:13 +0000 (22:58 -0400)
When request socks will be in ehash, they'll need to be refcounted.

This patch adds rsk_refcnt/ireq_refcnt macros, and adds
reqsk_put() function, but nothing yet use them.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/inet_sock.h
include/net/request_sock.h

index b31f01de5cd6df103ae7dbe3bcea844d4e1af7ab..9d6470c16a27097802a19a2dfd18cc3c204a8d79 100644 (file)
@@ -81,6 +81,7 @@ struct inet_request_sock {
 #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
 
        kmemcheck_bitfield_begin(flags);
        u16                     snd_wscale : 4,
index 7f830ff67f08c318717e809221d1586f17948185..e255ecf8bb400322bfae55a3a09df71752f9a5b8 100644 (file)
@@ -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 */
@@ -86,6 +88,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