-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace C-calls by structs for better long term #1
Comments
Good news and bad news.
Therefore, I suggest making our own getsockopt C-extension function that can take bytes object from python. |
Are you sure you cannot retrieve bytes? https://stackoverflow.com/a/18189190 |
Hello @matttbe, first of all thanks for joining me here, If you try to run the following code : import socket
import struct
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_MPTCP)
SOL_MPTCP = 284
MPTCP_TCPINFO = 2
returned = sock.getsockopt(SOL_MPTCP, MPTCP_TCPINFO, struct.calcsize("=IIII"))
print(struct.unpack("=IIII", returned)) You get the following error :
I tried to reproduce the same thing in C by commenting out the memset of the #include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdbool.h>
#include <linux/tcp.h>
#include <linux/types.h>
#ifndef SOL_MPTCP
#define SOL_MPTCP 284
#endif
#define IPPROTO_MPTCP 262
#define MPTCPLIB_OPERATION_UNSUPPORTED -2
#define MPTCPLIB_SOCKET_FALLBACK_TCP -1
#define MPTCPLIB_ERROR_FLAG -3
#ifndef _UAPI_MPTCP_H
#define MPTCP_INFO 1
#define MPTCP_TCPINFO 2
struct mptcp_subflow_data {
__u32 size_subflow_data; /* size of this structure in userspace */
__u32 num_subflows; /* must be 0, set by kernel */
__u32 size_kernel; /* must be 0, set by kernel */
__u32 size_user; /* size of one element in data[] */
} __attribute__((aligned(8)));
#endif
int main(int argc, char const *argv[])
{
int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP);
struct mptcp_subflow_data inf;
// memset(&inf, 0, sizeof(inf));
inf.size_subflow_data = sizeof(struct mptcp_subflow_data);
socklen_t optlen = sizeof(inf);
if (getsockopt(fd, SOL_MPTCP, 2, &inf, &optlen) < 0){
perror("The error");
return 1;
}
printf("The number of subflows used are %d\n", inf.num_subflows);
return 0;
} Therefore, I concluded that the reason I get the invalid argument is because we don't initialize the buff as the kernel expects it. |
@vanyingenzi oh OK, sorry, I see what you meant now. For |
Out of curiosity @matttbe, why does for ( |
Because the kernel needs to return X times another structure (X for the number of subflows). Better with an example I guess: struct mptcp_subflow_data # num of subflows + what has been written
struct tcp_info[X] # different types of info, this structure might grow on newer kernels Depending on the kernel version, So you need to tell the kernel:
|
I'm glad I got the courage to ask for help on Python discuss forum, other people advised me to use TL;DR we will no longer need the C-extension for the current supported functionalities. |
On a GitHub issue with mptcp_net-next developer, @matttbe highlighted that it was better to define structs in python instead of having a C function for each attribute as it is currently implemented in the library. At least for the current Linux support. We might use C functions for other features later down the road.
The text was updated successfully, but these errors were encountered: