Skip to content

Commit

Permalink
tw sock key inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
vlolteanu committed Nov 4, 2018
1 parent 9e83228 commit 1816713
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/linux/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ struct tcp_request_sock {
* FastOpen it's the seq#
* after data-in-SYN.
*/

struct tcp_ao_session_key *ao_session_key;
};

static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req)
Expand Down Expand Up @@ -362,6 +364,8 @@ struct tcp_sock {
struct tcp_md5sig_info __rcu *md5sig_info;
#endif
struct tcp_md5sig_info __rcu *ao_info;

struct tcp_ao_session_key *ao_session_key;

/* TCP fastopen related information */
struct tcp_fastopen_request *fastopen_req;
Expand Down Expand Up @@ -412,6 +416,7 @@ struct tcp_timewait_sock {
#ifdef CONFIG_TCP_MD5SIG
struct tcp_md5sig_key *tw_md5_key;
#endif
struct tcp_ao_session_key *tw_ao_key;
};

static inline struct tcp_timewait_sock *tcp_twsk(const struct sock *sk)
Expand Down
12 changes: 11 additions & 1 deletion net/ipv4/tcp_minisocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
}
} while (0);
#endif
if (tp->ao_session_key) {
tcptw->tw_ao_key = kmemdup(tp->ao_session_key, sizeof(*tp->ao_session_key), GFP_ATOMIC);
if (tcptw->tw_ao_key)
tcp_ao_master_key_use(tcptw->tw_ao_key->master);
}

/* Get the TIME_WAIT timeout firing. */
if (timeo < rto)
Expand Down Expand Up @@ -330,12 +335,17 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)

void tcp_twsk_destructor(struct sock *sk)
{
#ifdef CONFIG_TCP_MD5SIG
struct tcp_timewait_sock *twsk = tcp_twsk(sk);

#ifdef CONFIG_TCP_MD5SIG
if (twsk->tw_md5_key)
kfree_rcu(twsk->tw_md5_key, rcu);
#endif

if (!twsk->tw_ao_key)
return;
tcp_ao_master_key_unuse(twsk->tw_ao_key->master);
kfree(twsk->tw_ao_key);
}
EXPORT_SYMBOL_GPL(tcp_twsk_destructor);

Expand Down

0 comments on commit 1816713

Please sign in to comment.