From 1fd49f5ef9b95648a11884b02fdd75091cdefaf8 Mon Sep 17 00:00:00 2001 From: Mahno Date: Sun, 9 Feb 2025 18:01:40 +0800 Subject: [PATCH] add files --- Makefile | 5 +++++ tcp_const.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 Makefile create mode 100644 tcp_const.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e451047 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +obj-m += tcp_const.o + +all: + make -C /lib/modules/`uname -r`/build M=`pwd` modules + diff --git a/tcp_const.c b/tcp_const.c new file mode 100644 index 0000000..f4bdbbb --- /dev/null +++ b/tcp_const.c @@ -0,0 +1,62 @@ +#include +#include + +static u32 const_cwnd = 1000; +module_param(const_cwnd, uint, 0664); + +static void const_main(struct sock *sk, u32,int,const struct rate_sample *rs) +{ + tcp_sk(sk)->snd_cwnd = const_cwnd; +} + +static void const_cong_avoid(struct sock *sk, u32 ack, u32 acked) +{ + tcp_sk(sk)->snd_cwnd = const_cwnd; +} + +static void const_init(struct sock *sk) +{ + tcp_sk(sk)->snd_cwnd = const_cwnd; +} + +static u32 const_ssthresh(struct sock *sk) +{ + return const_cwnd; +} + +static void const_set_state(struct sock *sk, u8 new_state) +{ + if (new_state == TCP_CA_Loss) { + tcp_sk(sk)->snd_cwnd = const_cwnd; + } +} + +static u32 const_undo(struct sock *sk) +{ + return tcp_sk(sk)->snd_cwnd; +} + +static struct tcp_congestion_ops tcp_const_cong_ops __read_mostly = { + .name = "const", + .undo_cwnd = const_undo, + .init = const_init, + .cong_control = const_main, + /*.cong_avoid = const_cong_avoid,*/ + .ssthresh = const_ssthresh, + .set_state = const_set_state, +}; + +static int __init const_register(void) +{ + return tcp_register_congestion_control(&tcp_const_cong_ops); +} + +static void __exit const_unregister(void) +{ + tcp_unregister_congestion_control(&tcp_const_cong_ops); +} + +module_init(const_register); +module_exit(const_unregister); + +MODULE_LICENSE("GPL");