Skip to content

Commit

Permalink
reduce dup checks
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
  • Loading branch information
matttbe committed Mar 21, 2024
1 parent 26828b6 commit cf400cd
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions net/mptcp/sockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,48 +623,24 @@ static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock *msk, sockptr_t
}

static int __mptcp_setsockopt_sol_tcp_keepalive(struct mptcp_sock *msk,
int optname, int val)
int max,
int (*set_val)(struct sock *, int),
unsigned int *msk_val, int val)
{
struct mptcp_subflow_context *subflow;
int ret = 0;

switch (optname) {
case TCP_KEEPIDLE:
if (val < 1 || val > MAX_TCP_KEEPIDLE)
return -EINVAL;

msk->keepalive_idle = val;
break;
case TCP_KEEPINTVL:
if (val < 1 || val > MAX_TCP_KEEPINTVL)
return -EINVAL;

msk->keepalive_intvl = val;
break;
case TCP_KEEPCNT:
if (val < 1 || val > MAX_TCP_KEEPCNT)
return -EINVAL;
if (val < 1 || val > max)
return -EINVAL;

msk->keepalive_cnt = val;
break;
}
*msk_val = val;
sockopt_seq_inc(msk);

mptcp_for_each_subflow(msk, subflow) {
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);

lock_sock(ssk);
switch (optname) {
case TCP_KEEPIDLE:
ret |= tcp_sock_set_keepidle_locked(ssk, val);
break;
case TCP_KEEPINTVL:
ret |= tcp_sock_set_keepintvl(ssk, val);
break;
case TCP_KEEPCNT:
ret |= tcp_sock_set_keepcnt(ssk, val);
break;
}
ret |= set_val(ssk, val);
release_sock(ssk);
}

Expand Down Expand Up @@ -868,9 +844,23 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
ret = __mptcp_setsockopt_sol_tcp_nodelay(msk, val);
break;
case TCP_KEEPIDLE:
ret= __mptcp_setsockopt_sol_tcp_keepalive(msk, MAX_TCP_KEEPIDLE,
&tcp_sock_set_keepidle_locked,
&msk->keepalive_idle,
val);
break;
case TCP_KEEPINTVL:
ret= __mptcp_setsockopt_sol_tcp_keepalive(msk, MAX_TCP_KEEPINTVL,
&tcp_sock_set_keepintvl,
&msk->keepalive_intvl,
val);
break;
case TCP_KEEPCNT:
return __mptcp_setsockopt_sol_tcp_keepalive(msk, optname, val);
ret= __mptcp_setsockopt_sol_tcp_keepalive(msk, MAX_TCP_KEEPCNT,
&tcp_sock_set_keepcnt,
(unsigned int *)&msk->keepalive_cnt,
val);
break;
default:
ret = -ENOPROTOOPT;
}
Expand Down

0 comments on commit cf400cd

Please sign in to comment.