Skip to content

Commit 1fe4c48

Browse files
yuchungchengdavem330
authored andcommitted
net-tcp: Fast Open client - cookie cache
With help from Eric Dumazet, add Fast Open metrics in tcp metrics cache. The basic ones are MSS and the cookies. Later patch will cache more to handle unfriendly middleboxes. Signed-off-by: Yuchung Cheng <ycheng@google.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2100c8d commit 1fe4c48

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

include/net/tcp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ extern void tcp_metrics_init(void);
405405
extern bool tcp_peer_is_proven(struct request_sock *req, struct dst_entry *dst, bool paws_check);
406406
extern bool tcp_remember_stamp(struct sock *sk);
407407
extern bool tcp_tw_remember_stamp(struct inet_timewait_sock *tw);
408+
extern void tcp_fastopen_cache_get(struct sock *sk, u16 *mss,
409+
struct tcp_fastopen_cookie *cookie);
410+
extern void tcp_fastopen_cache_set(struct sock *sk, u16 mss,
411+
struct tcp_fastopen_cookie *cookie);
408412
extern void tcp_fetch_timewait_stamp(struct sock *sk, struct dst_entry *dst);
409413
extern void tcp_disable_fack(struct tcp_sock *tp);
410414
extern void tcp_close(struct sock *sk, long timeout);

net/ipv4/tcp_metrics.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ enum tcp_metric_index {
3030
TCP_METRIC_MAX,
3131
};
3232

33+
struct tcp_fastopen_metrics {
34+
u16 mss;
35+
struct tcp_fastopen_cookie cookie;
36+
};
37+
3338
struct tcp_metrics_block {
3439
struct tcp_metrics_block __rcu *tcpm_next;
3540
struct inetpeer_addr tcpm_addr;
@@ -38,6 +43,7 @@ struct tcp_metrics_block {
3843
u32 tcpm_ts_stamp;
3944
u32 tcpm_lock;
4045
u32 tcpm_vals[TCP_METRIC_MAX];
46+
struct tcp_fastopen_metrics tcpm_fastopen;
4147
};
4248

4349
static bool tcp_metric_locked(struct tcp_metrics_block *tm,
@@ -118,6 +124,8 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm, struct dst_entry *dst)
118124
tm->tcpm_vals[TCP_METRIC_REORDERING] = dst_metric_raw(dst, RTAX_REORDERING);
119125
tm->tcpm_ts = 0;
120126
tm->tcpm_ts_stamp = 0;
127+
tm->tcpm_fastopen.mss = 0;
128+
tm->tcpm_fastopen.cookie.len = 0;
121129
}
122130

123131
static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst,
@@ -633,6 +641,49 @@ bool tcp_tw_remember_stamp(struct inet_timewait_sock *tw)
633641
return ret;
634642
}
635643

644+
static DEFINE_SEQLOCK(fastopen_seqlock);
645+
646+
void tcp_fastopen_cache_get(struct sock *sk, u16 *mss,
647+
struct tcp_fastopen_cookie *cookie)
648+
{
649+
struct tcp_metrics_block *tm;
650+
651+
rcu_read_lock();
652+
tm = tcp_get_metrics(sk, __sk_dst_get(sk), false);
653+
if (tm) {
654+
struct tcp_fastopen_metrics *tfom = &tm->tcpm_fastopen;
655+
unsigned int seq;
656+
657+
do {
658+
seq = read_seqbegin(&fastopen_seqlock);
659+
if (tfom->mss)
660+
*mss = tfom->mss;
661+
*cookie = tfom->cookie;
662+
} while (read_seqretry(&fastopen_seqlock, seq));
663+
}
664+
rcu_read_unlock();
665+
}
666+
667+
668+
void tcp_fastopen_cache_set(struct sock *sk, u16 mss,
669+
struct tcp_fastopen_cookie *cookie)
670+
{
671+
struct tcp_metrics_block *tm;
672+
673+
rcu_read_lock();
674+
tm = tcp_get_metrics(sk, __sk_dst_get(sk), true);
675+
if (tm) {
676+
struct tcp_fastopen_metrics *tfom = &tm->tcpm_fastopen;
677+
678+
write_seqlock_bh(&fastopen_seqlock);
679+
tfom->mss = mss;
680+
if (cookie->len > 0)
681+
tfom->cookie = *cookie;
682+
write_sequnlock_bh(&fastopen_seqlock);
683+
}
684+
rcu_read_unlock();
685+
}
686+
636687
static unsigned long tcpmhash_entries;
637688
static int __init set_tcpmhash_entries(char *str)
638689
{

0 commit comments

Comments
 (0)