Skip to content

Commit

Permalink
Support for SOL_IP for MPTCP setsockopt
Browse files Browse the repository at this point in the history
This patch adds support for IP_TOS for setsockopt(.. ,SOL_IP, ..)
multipath-tcp/mptcp_net-next#220

Closes: multipath-tcp/mptcp_net-next#220

Signed-off-by: Poorva Sonparote <[email protected]>
  • Loading branch information
Poorva Sonparote authored and intel-lab-lkp committed Oct 25, 2021
1 parent 3fb59a5 commit ed825e6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
3 changes: 1 addition & 2 deletions include/net/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,6 @@ void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port,
u32 info, u8 *payload);
void ip_local_error(struct sock *sk, int err, __be32 daddr, __be16 dport,
u32 info);

static inline void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
{
ip_cmsg_recv_offset(msg, skb->sk, skb, 0, 0);
Expand All @@ -789,5 +788,5 @@ int ip_sock_set_mtu_discover(struct sock *sk, int val);
void ip_sock_set_pktinfo(struct sock *sk);
void ip_sock_set_recverr(struct sock *sk);
void ip_sock_set_tos(struct sock *sk, int val);

void __ip_sock_set_tos(struct sock *sk, int val);
#endif /* _IP_H */
2 changes: 1 addition & 1 deletion net/ipv4/ip_sockglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
return err;
}

static void __ip_sock_set_tos(struct sock *sk, int val)
void __ip_sock_set_tos(struct sock *sk, int val)
{
if (sk->sk_type == SOCK_STREAM) {
val &= ~INET_ECN_MASK;
Expand Down
41 changes: 41 additions & 0 deletions net/mptcp/sockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,43 @@ static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock *msk, sockptr_t
return ret;
}

static int mptcp_setsockopt_sol_ip_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 ret, val = 0;
int err;

err = ip_setsockopt(sk, SOL_IP, optname, optval, optlen);
val = inet_sk(sk)->tos;

if (err != 0)
return err;

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

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

return ret;
}

static int mptcp_setsockopt_sol_ip(struct mptcp_sock *msk, int optname,
sockptr_t optval, unsigned int optlen)
{
switch (optname) {
case IP_TOS:
return mptcp_setsockopt_sol_ip_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 +674,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_sol_ip(msk, optname, optval, optlen);

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

Expand Down Expand Up @@ -1003,6 +1043,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 ed825e6

Please sign in to comment.