Skip to content

Commit d93ad36

Browse files
committed
Merge branch 'master' into tcpmig-two-options
2 parents 7592b3a + e506256 commit d93ad36

File tree

5 files changed

+118
-0
lines changed

5 files changed

+118
-0
lines changed

include/linux/tcp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
118118
#if IS_ENABLED(CONFIG_SMC)
119119
rx_opt->smc_ok = 0;
120120
#endif
121+
#if IS_ENABLED(CONFIG_TCP_MIGRATE)
122+
rx_opt->migrate_enabled = 0;
123+
rx_opt->migrate_token = 0;
124+
#endif
121125
}
122126

123127
/* This is the max number of SACKS that we'll generate and process. It's safe
@@ -142,6 +146,10 @@ struct tcp_request_sock {
142146
* FastOpen it's the seq#
143147
* after data-in-SYN.
144148
*/
149+
#if IS_ENABLED(CONFIG_TCP_MIGRATE)
150+
bool migrate_enabled;
151+
u32 migrate_token;
152+
#endif
145153
};
146154

147155
static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req)

include/net/tcp.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,17 @@ int tcp_md5_hash_skb_data(struct tcp_md5sig_pool *, const struct sk_buff *,
16081608
int tcp_md5_hash_key(struct tcp_md5sig_pool *hp,
16091609
const struct tcp_md5sig_key *key);
16101610

1611+
#if IS_ENABLED(CONFIG_TCP_MIGRATE)
1612+
extern int migrate_syn;
1613+
extern int migrate_syn_ack;
1614+
1615+
/* #ifdef CONFIG_PROC_FS */
1616+
/* void tcp_migrate_proc_init(void); */
1617+
/* void tcp_migrate_proc_exit(void); */
1618+
/* #endif */
1619+
#endif
1620+
1621+
16111622
/* From tcp_fastopen.c */
16121623
void tcp_fastopen_cache_get(struct sock *sk, u16 *mss,
16131624
struct tcp_fastopen_cookie *cookie);

net/ipv4/tcp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ EXPORT_SYMBOL(tcp_have_smc);
303303
struct percpu_counter tcp_sockets_allocated;
304304
EXPORT_SYMBOL(tcp_sockets_allocated);
305305

306+
#if IS_ENABLED(CONFIG_TCP_MIGRATE)
307+
int migrate_syn = 0;
308+
int migrate_syn_ack = 0;
309+
#endif
310+
306311
/*
307312
* TCP splice context
308313
*/
@@ -4007,4 +4012,7 @@ void __init tcp_init(void)
40074012
tcp_metrics_init();
40084013
BUG_ON(tcp_register_congestion_control(&tcp_reno) != 0);
40094014
tcp_tasklet_init();
4015+
#if IS_ENABLED(CONFIG_TCP_MIGRATE)
4016+
migrate_syn = migrate_syn_ack = 0;
4017+
#endif
40104018
}

net/ipv4/tcp_input.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6331,6 +6331,10 @@ static void tcp_openreq_init(struct request_sock *req,
63316331
#if IS_ENABLED(CONFIG_SMC)
63326332
ireq->smc_ok = rx_opt->smc_ok;
63336333
#endif
6334+
#if IS_ENABLED(CONFIG_TCP_MIGRATE)
6335+
tcp_rsk(req)->migrate_enabled = 0;
6336+
tcp_rsk(req)->migrate_token = 0;
6337+
#endif
63346338
}
63356339

63366340
struct request_sock *inet_reqsk_alloc(const struct request_sock_ops *ops,
@@ -6482,6 +6486,8 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
64826486
tp->migrate_enabled = true;
64836487
tp->migrate_token = tmp_opt.migrate_token;
64846488
printk(KERN_INFO "[%s] token %u\n", __func__, tp->migrate_token);
6489+
tcp_rsk(req)->migrate_enabled = true;
6490+
tcp_rsk(req)->migrate_token = tmp_opt.migrate_token;
64856491
}
64866492
#endif
64876493

@@ -6523,6 +6529,10 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
65236529
tcp_reqsk_record_syn(sk, req, skb);
65246530
fastopen_sk = tcp_try_fastopen(sk, skb, req, &foc, dst);
65256531
}
6532+
6533+
/* JOSEPH: skipped for putting token in tcp mig for now (will be
6534+
* done in tcp_v4_sync_recv_sock when ACK for SYNACK is received */
6535+
65266536
if (fastopen_sk) {
65276537
af_ops->send_synack(fastopen_sk, dst, &fl, req,
65286538
&foc, TCP_SYNACK_FASTOPEN);

net/ipv4/tcp_ipv4.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,21 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
14771477
}
14781478
#endif
14791479

1480+
#if IS_ENABLED(CONFIG_TCP_MIGRATE)
1481+
if (tcp_rsk(req)->migrate_enabled) {
1482+
/* copy mig info to child socket (returned via accept)
1483+
* currently, assuming that no incoming connection for time
1484+
* between SYN-ACK by server and ACK by client.
1485+
*/
1486+
printk("[%s] setting child token to %u\n", __func__, tcp_rsk(req)->migrate_token);
1487+
newtp->migrate_enabled = tcp_rsk(req)->migrate_enabled;
1488+
newtp->migrate_token = tcp_rsk(req)->migrate_token;
1489+
} else {
1490+
newtp->migrate_enabled = false;
1491+
newtp->migrate_token = 0;
1492+
}
1493+
#endif
1494+
14801495
if (__inet_inherit_port(sk, newsk) < 0)
14811496
goto put_and_exit;
14821497
*own_req = inet_ehash_nolisten(newsk, req_to_sk(req_unhash));
@@ -2514,6 +2529,64 @@ static const struct seq_operations tcp4_seq_ops = {
25142529
.stop = tcp_seq_stop,
25152530
};
25162531

2532+
2533+
#if IS_ENABLED(CONFIG_TCP_MIGRATE)
2534+
static void get_tcp_mig_sock(struct sock *sk, struct seq_file *f, int i)
2535+
{
2536+
const struct tcp_sock *tp = tcp_sk(sk);
2537+
const struct inet_sock *inet = inet_sk(sk);
2538+
__be32 dest = inet->inet_daddr;
2539+
__be32 src = inet->inet_rcv_saddr;
2540+
__u16 destp = ntohs(inet->inet_dport);
2541+
__u16 srcp = ntohs(inet->inet_sport);
2542+
int state;
2543+
bool migrate_enabled = tp->migrate_enabled;
2544+
u32 migrate_token;
2545+
2546+
if (!migrate_enabled)
2547+
goto skip;
2548+
2549+
state = inet_sk_state_load(sk);
2550+
migrate_token = tp->migrate_token;
2551+
2552+
seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %d",
2553+
i, src, srcp, dest, destp, state, migrate_token
2554+
);
2555+
seq_pad(f, '\n');
2556+
2557+
/* TODO: given tcp_mig socket, now put the socket into MIG_SYN state
2558+
*/
2559+
skip:
2560+
return;
2561+
}
2562+
static int tcp_mig_seq_show(struct seq_file *seq, void *v)
2563+
{
2564+
struct tcp_iter_state *st;
2565+
struct sock *sk = v;
2566+
2567+
seq_setwidth(seq, TMPSZ - 1);
2568+
if (v == SEQ_START_TOKEN) {
2569+
seq_puts(seq, " sl local_address rem_address token\n");
2570+
goto out;
2571+
}
2572+
st = seq->private;
2573+
2574+
if (sk->sk_state != TCP_TIME_WAIT && sk->sk_state != TCP_NEW_SYN_RECV)
2575+
get_tcp_mig_sock(v, seq, st->num);
2576+
2577+
out:
2578+
return 0;
2579+
}
2580+
2581+
2582+
static const struct seq_operations tcp_mig_seq_ops = {
2583+
.show = tcp_mig_seq_show,
2584+
.start = tcp_seq_start,
2585+
.next = tcp_seq_next,
2586+
.stop = tcp_seq_stop,
2587+
};
2588+
#endif
2589+
25172590
static struct tcp_seq_afinfo tcp4_seq_afinfo = {
25182591
.family = AF_INET,
25192592
};
@@ -2523,12 +2596,20 @@ static int __net_init tcp4_proc_init_net(struct net *net)
25232596
if (!proc_create_net_data("tcp", 0444, net->proc_net, &tcp4_seq_ops,
25242597
sizeof(struct tcp_iter_state), &tcp4_seq_afinfo))
25252598
return -ENOMEM;
2599+
#if IS_ENABLED(CONFIG_TCP_MIGRATE)
2600+
if (!proc_create_net_data("tcp_mig_syn", 0444, net->proc_net, &tcp_mig_seq_ops,
2601+
sizeof(struct tcp_iter_state), &tcp4_seq_afinfo))
2602+
return -ENOMEM;
2603+
#endif
25262604
return 0;
25272605
}
25282606

25292607
static void __net_exit tcp4_proc_exit_net(struct net *net)
25302608
{
25312609
remove_proc_entry("tcp", net->proc_net);
2610+
#if IS_ENABLED(CONFIG_TCP_MIGRATE)
2611+
remove_proc_entry("tcp_mig_syn", net->proc_net);
2612+
#endif
25322613
}
25332614

25342615
static struct pernet_operations tcp4_net_ops = {

0 commit comments

Comments
 (0)