Skip to content

Commit 55c42fa

Browse files
Florian Westphaldavem330
authored andcommitted
mptcp: add MPTCP_INFO getsockopt
Its not compatible with multipath-tcp.org kernel one. 1. The out-of-tree implementation defines a different 'struct mptcp_info', with embedded __user addresses for additional data such as endpoint addresses. 2. Mat Martineau points out that embedded __user addresses doesn't work with BPF_CGROUP_RUN_PROG_GETSOCKOPT() which assumes that copying in optsize bytes from optval provides all data that got copied to userspace. This provides mptcp_info data for the given mptcp socket. Userspace sets optlen to the size of the structure it expects. The kernel updates it to contain the number of bytes that it copied. This allows to append more information to the structure later. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 61bc6e8 commit 55c42fa

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

include/linux/socket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ struct ucred {
364364
#define SOL_KCM 281
365365
#define SOL_TLS 282
366366
#define SOL_XDP 283
367+
#define SOL_MPTCP 284
367368

368369
/* IPX options */
369370
#define IPX_TYPE 1

include/uapi/linux/mptcp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,7 @@ enum mptcp_event_attr {
193193
#define MPTCP_RST_EBADPERF 5
194194
#define MPTCP_RST_EMIDDLEBOX 6
195195

196+
/* MPTCP socket options */
197+
#define MPTCP_INFO 1
198+
196199
#endif /* _UAPI_MPTCP_H */

net/mptcp/sockopt.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,14 @@ static int mptcp_getsockopt_first_sf_only(struct mptcp_sock *msk, int level, int
673673
void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
674674
{
675675
struct sock *sk = &msk->sk.icsk_inet.sk;
676-
bool slow = lock_sock_fast(sk);
677676
u32 flags = 0;
677+
bool slow;
678678
u8 val;
679679

680+
memset(info, 0, sizeof(*info));
681+
682+
slow = lock_sock_fast(sk);
683+
680684
info->mptcpi_subflows = READ_ONCE(msk->pm.subflows);
681685
info->mptcpi_add_addr_signal = READ_ONCE(msk->pm.add_addr_signaled);
682686
info->mptcpi_add_addr_accepted = READ_ONCE(msk->pm.add_addr_accepted);
@@ -702,6 +706,27 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
702706
}
703707
EXPORT_SYMBOL_GPL(mptcp_diag_fill_info);
704708

709+
static int mptcp_getsockopt_info(struct mptcp_sock *msk, char __user *optval, int __user *optlen)
710+
{
711+
struct mptcp_info m_info;
712+
int len;
713+
714+
if (get_user(len, optlen))
715+
return -EFAULT;
716+
717+
len = min_t(unsigned int, len, sizeof(struct mptcp_info));
718+
719+
mptcp_diag_fill_info(msk, &m_info);
720+
721+
if (put_user(len, optlen))
722+
return -EFAULT;
723+
724+
if (copy_to_user(optval, &m_info, len))
725+
return -EFAULT;
726+
727+
return 0;
728+
}
729+
705730
static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
706731
char __user *optval, int __user *optlen)
707732
{
@@ -716,6 +741,17 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
716741
return -EOPNOTSUPP;
717742
}
718743

744+
static int mptcp_getsockopt_sol_mptcp(struct mptcp_sock *msk, int optname,
745+
char __user *optval, int __user *optlen)
746+
{
747+
switch (optname) {
748+
case MPTCP_INFO:
749+
return mptcp_getsockopt_info(msk, optval, optlen);
750+
}
751+
752+
return -EOPNOTSUPP;
753+
}
754+
719755
int mptcp_getsockopt(struct sock *sk, int level, int optname,
720756
char __user *optval, int __user *option)
721757
{
@@ -738,6 +774,8 @@ int mptcp_getsockopt(struct sock *sk, int level, int optname,
738774

739775
if (level == SOL_TCP)
740776
return mptcp_getsockopt_sol_tcp(msk, optname, optval, option);
777+
if (level == SOL_MPTCP)
778+
return mptcp_getsockopt_sol_mptcp(msk, optname, optval, option);
741779
return -EOPNOTSUPP;
742780
}
743781

0 commit comments

Comments
 (0)