multipath-tcp / mptcp

⚠️⚠️⚠️ Deprecated 🚫 Out-of-tree Linux Kernel implementation of MultiPath TCP. 👉 Use https://github.com/multipath-tcp/mptcp_net-next repo instead ⚠️⚠️⚠️
https://github.com/multipath-tcp/mptcp_net-next
Other
889 stars 336 forks source link

Websocket on MPTCP keep raising warning: getsockopt: Bad Address. #489

Open ArthurCChen opened 2 years ago

ArthurCChen commented 2 years ago

Hi, My MPTCP pair: AWS EC2(as the server) & PC(as the client) (Both Ubuntu18.04 and Linux 4.19.234) works correctly according to the Wireshark. However, after adding the module:

  struct mptcp_info minfo;
  struct mptcp_meta_info meta_info;
  struct tcp_info initial;
  struct tcp_info *others; // increase it if needed
  struct mptcp_sub_info others_info[3]; // same
  socklen_t len;
  len = sizeof(minfo);
  minfo.tcp_info_len = sizeof(struct tcp_info);
  minfo.sub_len = sizeof(others);
  minfo.meta_len = sizeof(struct mptcp_meta_info);
  minfo.meta_info = &meta_info;
  minfo.initial = &initial;
  minfo.subflows = others;
  minfo.sub_info_len = sizeof(struct mptcp_sub_info);
  minfo.total_sub_info_len = sizeof(others_info);
  minfo.subflow_info = others_info;

  cout << 'Before getting the MPTCP_INFO, minfo: ' << minfo.total_sub_info_len << endl;

  #define MPTCP_INFO_FLAG_SAVE_MASTER 0x01
  int val = MPTCP_INFO_FLAG_SAVE_MASTER;
  CheckSystemCall( "setsockopt", ::setsockopt( fd_num(), IPPROTO_TCP, MPTCP_INFO,
                                                 &val, sizeof( val ) ) );

  getsockopt(<fd num>, IPPROTO_TCP, MPTCP_INFO, &minfo &len);

it now continuously closes my WebSocket connection and reconnect. Exactly at this line: getsockopt(<fd num>, IPPROTO_TCP, MPTCP_INFO, &minfo &len);

matttbe commented 2 years ago

Hello,

EFAULT error, also known as Bad address error, is returned if there is not enough space for the kernel to write data in.

You issue might come from:

  struct tcp_info *others; // increase it if needed

You should not have a pointer here but an array that is big enough to store info for each subflows, e.g. others[3].

Note that another common source of issue is when your system has kernel C headers for an older kernel versions and structure are not big enough. You can debug that by printing the sizeof sizes but also by looking at what the kernel has managed to write. You can find the order the kernel is writing info in by looking at where copy_from_user() functions are used in mptcp_get_info() https://github.com/multipath-tcp/mptcp/blob/7fa887be95fd36df097c92ff869e99f4f3c8a302/net/mptcp/mptcp_ctrl.c#L2791-L2909