* [PATCH bpf-next v3 1/3] sock: move sock_valbool_flag to header
@ 2020-06-02 9:26 Dmitry Yakunin
2020-06-02 9:26 ` [PATCH bpf-next v3 2/3] tcp: expose tcp_sock_set_keepidle_locked Dmitry Yakunin
2020-06-02 9:26 ` [PATCH bpf-next v3 3/3] bpf: add SO_KEEPALIVE and related options to bpf_setsockopt Dmitry Yakunin
0 siblings, 2 replies; 4+ messages in thread
From: Dmitry Yakunin @ 2020-06-02 9:26 UTC (permalink / raw)
To: alexei.starovoitov; +Cc: davem, brakmo, eric.dumazet, kafai, bpf, netdev
This is preparation for usage in bpf_setsockopt.
Signed-off-by: Dmitry Yakunin <zeil@yandex-team.ru>
Acked-by: Martin KaFai Lau <kafai@fb.com>
---
include/net/sock.h | 9 +++++++++
net/core/sock.c | 9 ---------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index c53cc42..8ba438b 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -879,6 +879,15 @@ static inline void sock_reset_flag(struct sock *sk, enum sock_flags flag)
__clear_bit(flag, &sk->sk_flags);
}
+static inline void sock_valbool_flag(struct sock *sk, enum sock_flags bit,
+ int valbool)
+{
+ if (valbool)
+ sock_set_flag(sk, bit);
+ else
+ sock_reset_flag(sk, bit);
+}
+
static inline bool sock_flag(const struct sock *sk, enum sock_flags flag)
{
return test_bit(flag, &sk->sk_flags);
diff --git a/net/core/sock.c b/net/core/sock.c
index 6c4acf1..5ba4753 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -695,15 +695,6 @@ static int sock_getbindtodevice(struct sock *sk, char __user *optval,
return ret;
}
-static inline void sock_valbool_flag(struct sock *sk, enum sock_flags bit,
- int valbool)
-{
- if (valbool)
- sock_set_flag(sk, bit);
- else
- sock_reset_flag(sk, bit);
-}
-
bool sk_mc_loop(struct sock *sk)
{
if (dev_recursion_level())
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH bpf-next v3 2/3] tcp: expose tcp_sock_set_keepidle_locked
2020-06-02 9:26 [PATCH bpf-next v3 1/3] sock: move sock_valbool_flag to header Dmitry Yakunin
@ 2020-06-02 9:26 ` Dmitry Yakunin
2020-06-02 18:38 ` Alexei Starovoitov
2020-06-02 9:26 ` [PATCH bpf-next v3 3/3] bpf: add SO_KEEPALIVE and related options to bpf_setsockopt Dmitry Yakunin
1 sibling, 1 reply; 4+ messages in thread
From: Dmitry Yakunin @ 2020-06-02 9:26 UTC (permalink / raw)
To: alexei.starovoitov; +Cc: davem, brakmo, eric.dumazet, kafai, bpf, netdev
This is preparation for usage in bpf_setsockopt.
Signed-off-by: Dmitry Yakunin <zeil@yandex-team.ru>
---
include/linux/tcp.h | 1 +
net/ipv4/tcp.c | 7 ++++---
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 9aac824..3bdec31 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -499,6 +499,7 @@ int tcp_skb_shift(struct sk_buff *to, struct sk_buff *from, int pcount,
void tcp_sock_set_cork(struct sock *sk, bool on);
int tcp_sock_set_keepcnt(struct sock *sk, int val);
+int tcp_sock_set_keepidle_locked(struct sock *sk, int val);
int tcp_sock_set_keepidle(struct sock *sk, int val);
int tcp_sock_set_keepintvl(struct sock *sk, int val);
void tcp_sock_set_nodelay(struct sock *sk);
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 15d47d5..0e29760 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2901,7 +2901,7 @@ void tcp_sock_set_user_timeout(struct sock *sk, u32 val)
}
EXPORT_SYMBOL(tcp_sock_set_user_timeout);
-static int __tcp_sock_set_keepidle(struct sock *sk, int val)
+int tcp_sock_set_keepidle_locked(struct sock *sk, int val)
{
struct tcp_sock *tp = tcp_sk(sk);
@@ -2922,13 +2922,14 @@ static int __tcp_sock_set_keepidle(struct sock *sk, int val)
return 0;
}
+EXPORT_SYMBOL(tcp_sock_set_keepidle_locked);
int tcp_sock_set_keepidle(struct sock *sk, int val)
{
int err;
lock_sock(sk);
- err = __tcp_sock_set_keepidle(sk, val);
+ err = tcp_sock_set_keepidle_locked(sk, val);
release_sock(sk);
return err;
}
@@ -3127,7 +3128,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
break;
case TCP_KEEPIDLE:
- err = __tcp_sock_set_keepidle(sk, val);
+ err = tcp_sock_set_keepidle_locked(sk, val);
break;
case TCP_KEEPINTVL:
if (val < 1 || val > MAX_TCP_KEEPINTVL)
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH bpf-next v3 3/3] bpf: add SO_KEEPALIVE and related options to bpf_setsockopt
2020-06-02 9:26 [PATCH bpf-next v3 1/3] sock: move sock_valbool_flag to header Dmitry Yakunin
2020-06-02 9:26 ` [PATCH bpf-next v3 2/3] tcp: expose tcp_sock_set_keepidle_locked Dmitry Yakunin
@ 2020-06-02 9:26 ` Dmitry Yakunin
1 sibling, 0 replies; 4+ messages in thread
From: Dmitry Yakunin @ 2020-06-02 9:26 UTC (permalink / raw)
To: alexei.starovoitov; +Cc: davem, brakmo, eric.dumazet, kafai, bpf, netdev
This patch adds support of SO_KEEPALIVE flag and TCP related options
to bpf_setsockopt() routine. This is helpful if we want to enable or tune
TCP keepalive for applications which don't do it in the userspace code.
Signed-off-by: Dmitry Yakunin <zeil@yandex-team.ru>
Acked-by: Martin KaFai Lau <kafai@fb.com>
---
net/core/filter.c | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index ae82bcb..674272c 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4249,10 +4249,10 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
char *optval, int optlen, u32 flags)
{
char devname[IFNAMSIZ];
+ int val, valbool;
struct net *net;
int ifindex;
int ret = 0;
- int val;
if (!sk_fullsock(sk))
return -EINVAL;
@@ -4263,6 +4263,7 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
if (optlen != sizeof(int) && optname != SO_BINDTODEVICE)
return -EINVAL;
val = *((int *)optval);
+ valbool = val ? 1 : 0;
/* Only some socketops are supported */
switch (optname) {
@@ -4324,6 +4325,11 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
ret = sock_bindtoindex(sk, ifindex, false);
#endif
break;
+ case SO_KEEPALIVE:
+ if (sk->sk_prot->keepalive)
+ sk->sk_prot->keepalive(sk, valbool);
+ sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool);
+ break;
default:
ret = -EINVAL;
}
@@ -4384,6 +4390,7 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
ret = tcp_set_congestion_control(sk, name, false,
reinit, true);
} else {
+ struct inet_connection_sock *icsk = inet_csk(sk);
struct tcp_sock *tp = tcp_sk(sk);
if (optlen != sizeof(int))
@@ -4412,6 +4419,33 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
else
tp->save_syn = val;
break;
+ case TCP_KEEPIDLE:
+ ret = tcp_sock_set_keepidle_locked(sk, val);
+ break;
+ case TCP_KEEPINTVL:
+ if (val < 1 || val > MAX_TCP_KEEPINTVL)
+ ret = -EINVAL;
+ else
+ tp->keepalive_intvl = val * HZ;
+ break;
+ case TCP_KEEPCNT:
+ if (val < 1 || val > MAX_TCP_KEEPCNT)
+ ret = -EINVAL;
+ else
+ tp->keepalive_probes = val;
+ break;
+ case TCP_SYNCNT:
+ if (val < 1 || val > MAX_TCP_SYNCNT)
+ ret = -EINVAL;
+ else
+ icsk->icsk_syn_retries = val;
+ break;
+ case TCP_USER_TIMEOUT:
+ if (val < 0)
+ ret = -EINVAL;
+ else
+ icsk->icsk_user_timeout = val;
+ break;
default:
ret = -EINVAL;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next v3 2/3] tcp: expose tcp_sock_set_keepidle_locked
2020-06-02 9:26 ` [PATCH bpf-next v3 2/3] tcp: expose tcp_sock_set_keepidle_locked Dmitry Yakunin
@ 2020-06-02 18:38 ` Alexei Starovoitov
0 siblings, 0 replies; 4+ messages in thread
From: Alexei Starovoitov @ 2020-06-02 18:38 UTC (permalink / raw)
To: Dmitry Yakunin
Cc: David S. Miller, Lawrence Brakmo, Eric Dumazet, Martin KaFai Lau,
bpf, Network Development
On Tue, Jun 2, 2020 at 2:27 AM Dmitry Yakunin <zeil@yandex-team.ru> wrote:
>
> -static int __tcp_sock_set_keepidle(struct sock *sk, int val)
> +int tcp_sock_set_keepidle_locked(struct sock *sk, int val)
> {
> struct tcp_sock *tp = tcp_sk(sk);
>
> @@ -2922,13 +2922,14 @@ static int __tcp_sock_set_keepidle(struct sock *sk, int val)
>
> return 0;
> }
> +EXPORT_SYMBOL(tcp_sock_set_keepidle_locked);
why export it?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-06-02 18:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02 9:26 [PATCH bpf-next v3 1/3] sock: move sock_valbool_flag to header Dmitry Yakunin
2020-06-02 9:26 ` [PATCH bpf-next v3 2/3] tcp: expose tcp_sock_set_keepidle_locked Dmitry Yakunin
2020-06-02 18:38 ` Alexei Starovoitov
2020-06-02 9:26 ` [PATCH bpf-next v3 3/3] bpf: add SO_KEEPALIVE and related options to bpf_setsockopt Dmitry Yakunin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).