提交 788b9ba6 编写于 作者: W Wang Yufen 提交者: Yang Yingliang

tcp_comp: only enable compression for give server ports

hulk inclusion
category: feature
bugzilla: NA
CVE: NA

-------------------------------------------------

Only enable compression for give server ports, this means we will
check either dport when send SYN or sport when send SYN-ACK.
Signed-off-by: NWei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
Reviewed-by: NWei Yongjun <weiyongjun1@huawei.com>
Reviewed-by: NWei Yongjun <weiyongjun1@huawei.com>
Reviewed-by: NYue Haibing <yuehaibing@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 0a91103a
...@@ -2215,7 +2215,7 @@ extern struct static_key_false tcp_have_comp; ...@@ -2215,7 +2215,7 @@ extern struct static_key_false tcp_have_comp;
extern unsigned long *sysctl_tcp_compression_ports; extern unsigned long *sysctl_tcp_compression_ports;
bool tcp_syn_comp_enabled(const struct tcp_sock *tp); bool tcp_syn_comp_enabled(const struct sock *sk, bool active);
void tcp_init_compression(struct sock *sk); void tcp_init_compression(struct sock *sk);
void tcp_cleanup_compression(struct sock *sk); void tcp_cleanup_compression(struct sock *sk);
#else #else
......
...@@ -11,13 +11,27 @@ static unsigned long tcp_compression_ports[65536 / 8]; ...@@ -11,13 +11,27 @@ static unsigned long tcp_compression_ports[65536 / 8];
unsigned long *sysctl_tcp_compression_ports = tcp_compression_ports; unsigned long *sysctl_tcp_compression_ports = tcp_compression_ports;
bool tcp_syn_comp_enabled(const struct tcp_sock *tp) bool tcp_syn_comp_enabled(const struct sock *sk, bool active)
{ {
return true; struct inet_sock *inet = inet_sk(sk);
int port;
if (active)
port = ntohs(inet->inet_dport);
else
port = ntohs(inet->inet_sport);
return test_bit(port, sysctl_tcp_compression_ports);
} }
void tcp_init_compression(struct sock *sk) void tcp_init_compression(struct sock *sk)
{ {
struct tcp_sock *tp = tcp_sk(sk);
if (!tp->rx_opt.smc_ok)
return;
sock_set_flag(sk, SOCK_COMP);
} }
void tcp_cleanup_compression(struct sock *sk) void tcp_cleanup_compression(struct sock *sk)
......
...@@ -587,13 +587,13 @@ static void smc_set_option_cond(const struct tcp_sock *tp, ...@@ -587,13 +587,13 @@ static void smc_set_option_cond(const struct tcp_sock *tp,
#endif #endif
} }
static void comp_set_option(const struct tcp_sock *tp, static void comp_set_option(const struct sock *sk,
struct tcp_out_options *opts, struct tcp_out_options *opts,
unsigned int *remaining) unsigned int *remaining)
{ {
#if IS_ENABLED(CONFIG_TCP_COMP) #if IS_ENABLED(CONFIG_TCP_COMP)
if (static_branch_unlikely(&tcp_have_comp)) { if (static_branch_unlikely(&tcp_have_comp)) {
if (tcp_syn_comp_enabled(tp)) { if (tcp_syn_comp_enabled(sk, true)) {
if (*remaining >= TCPOLEN_EXP_COMP_BASE) { if (*remaining >= TCPOLEN_EXP_COMP_BASE) {
opts->options |= OPTION_COMP; opts->options |= OPTION_COMP;
*remaining -= TCPOLEN_EXP_COMP_BASE; *remaining -= TCPOLEN_EXP_COMP_BASE;
...@@ -603,14 +603,14 @@ static void comp_set_option(const struct tcp_sock *tp, ...@@ -603,14 +603,14 @@ static void comp_set_option(const struct tcp_sock *tp,
#endif #endif
} }
static void comp_set_option_cond(const struct tcp_sock *tp, static void comp_set_option_cond(const struct sock *sk,
const struct inet_request_sock *ireq, const struct inet_request_sock *ireq,
struct tcp_out_options *opts, struct tcp_out_options *opts,
unsigned int *remaining) unsigned int *remaining)
{ {
#if IS_ENABLED(CONFIG_TCP_COMP) #if IS_ENABLED(CONFIG_TCP_COMP)
if (static_branch_unlikely(&tcp_have_comp)) { if (static_branch_unlikely(&tcp_have_comp)) {
if (tcp_syn_comp_enabled(tp) && ireq->comp_ok) { if (tcp_syn_comp_enabled(sk, false) && ireq->comp_ok) {
if (*remaining >= TCPOLEN_EXP_COMP_BASE) { if (*remaining >= TCPOLEN_EXP_COMP_BASE) {
opts->options |= OPTION_COMP; opts->options |= OPTION_COMP;
*remaining -= TCPOLEN_EXP_COMP_BASE; *remaining -= TCPOLEN_EXP_COMP_BASE;
...@@ -688,7 +688,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb, ...@@ -688,7 +688,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
smc_set_option(tp, opts, &remaining); smc_set_option(tp, opts, &remaining);
comp_set_option(tp, opts, &remaining); comp_set_option(sk, opts, &remaining);
return MAX_TCP_OPTION_SPACE - remaining; return MAX_TCP_OPTION_SPACE - remaining;
} }
...@@ -755,7 +755,7 @@ static unsigned int tcp_synack_options(const struct sock *sk, ...@@ -755,7 +755,7 @@ static unsigned int tcp_synack_options(const struct sock *sk,
smc_set_option_cond(tcp_sk(sk), ireq, opts, &remaining); smc_set_option_cond(tcp_sk(sk), ireq, opts, &remaining);
comp_set_option_cond(tcp_sk(sk), ireq, opts, &remaining); comp_set_option_cond(sk, ireq, opts, &remaining);
return MAX_TCP_OPTION_SPACE - remaining; return MAX_TCP_OPTION_SPACE - remaining;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册