Skip to content

Commit

Permalink
mptcp: Support for IP_TOS for MPTCP setsockopt()
Browse files Browse the repository at this point in the history
SOL_IP provides a way to configure network layer attributes in a
socket. This patch adds support for IP_TOS for setsockopt(.. ,SOL_IP, ..)

Support for SOL_IP is added in mptcp_setsockopt() and IP_TOS is handled in
a private function. The idea here is to take in the value passed for IP_TOS
and set it to the current subflow, open subflows as well new subflows that
might be created after the initial call to setsockopt(). This sync is done
using sync_socket_options(.., ssk) and setting the value of tos using
__ip_sock_set_tos(ssk,..).

The patch has been tested using the packetdrill script here -
#220 (comment)

Closes: #220
Reviewed-by: Mat Martineau <[email protected]>
Signed-off-by: Poorva Sonparote <[email protected]>
  • Loading branch information
Poorva Sonparote authored and matttbe committed Oct 28, 2021
1 parent 2445d8f commit dd03695
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions net/mptcp/sockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,42 @@ static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock *msk, sockptr_t
return ret;
}

static int mptcp_setsockopt_v4_set_tos(struct mptcp_sock *msk, int optname,
sockptr_t optval, unsigned int optlen)
{
struct mptcp_subflow_context *subflow;
struct sock *sk = (struct sock *)msk;
int err, val;

err = ip_setsockopt(sk, SOL_IP, optname, optval, optlen);

if (err != 0)
return err;

lock_sock(sk);
sockopt_seq_inc(msk);
val = inet_sk(sk)->tos;
mptcp_for_each_subflow(msk, subflow) {
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);

__ip_sock_set_tos(ssk, val);
}
release_sock(sk);

return err;
}

static int mptcp_setsockopt_v4(struct mptcp_sock *msk, int optname,
sockptr_t optval, unsigned int optlen)
{
switch (optname) {
case IP_TOS:
return mptcp_setsockopt_v4_set_tos(msk, optname, optval, optlen);
}

return -EOPNOTSUPP;
}

static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
sockptr_t optval, unsigned int optlen)
{
Expand Down Expand Up @@ -637,6 +673,9 @@ int mptcp_setsockopt(struct sock *sk, int level, int optname,
if (ssk)
return tcp_setsockopt(ssk, level, optname, optval, optlen);

if (level == SOL_IP)
return mptcp_setsockopt_v4(msk, optname, optval, optlen);

if (level == SOL_IPV6)
return mptcp_setsockopt_v6(msk, optname, optval, optlen);

Expand Down Expand Up @@ -1003,6 +1042,7 @@ static void sync_socket_options(struct mptcp_sock *msk, struct sock *ssk)
ssk->sk_priority = sk->sk_priority;
ssk->sk_bound_dev_if = sk->sk_bound_dev_if;
ssk->sk_incoming_cpu = sk->sk_incoming_cpu;
__ip_sock_set_tos(ssk, inet_sk(sk)->tos);

if (sk->sk_userlocks & tx_rx_locks) {
ssk->sk_userlocks |= sk->sk_userlocks & tx_rx_locks;
Expand Down

0 comments on commit dd03695

Please sign in to comment.