* [PATCH 0/2] BCC: python: support fmod_ret
@ 2025-04-07 2:37 Gang Yan
2025-04-07 2:37 ` [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF Gang Yan
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Gang Yan @ 2025-04-07 2:37 UTC (permalink / raw)
To: mptcp; +Cc: Gang Yan
Support fmod_ret, and add a useful tool for mptcp, also
the interface can be verified with this function.
Gang Yan (2):
BCC: Python: Support 'fmod_ret' method for eBPF
BCC: python: add a useful tool for mptcp
src/python/bcc/__init__.py | 43 ++++++++++++++++++++
tools/mptcpboost.py | 82 ++++++++++++++++++++++++++++++++++++++
tools/mptcpboost.txt | 22 ++++++++++
3 files changed, 147 insertions(+)
create mode 100644 tools/mptcpboost.py
create mode 100644 tools/mptcpboost.txt
--
2.25.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF 2025-04-07 2:37 [PATCH 0/2] BCC: python: support fmod_ret Gang Yan @ 2025-04-07 2:37 ` Gang Yan 2025-04-07 9:07 ` Matthieu Baerts 2025-04-07 2:37 ` [PATCH 2/2] BCC: python: add a useful tool for mptcp Gang Yan 2025-04-07 9:07 ` [PATCH 0/2] BCC: python: support fmod_ret Matthieu Baerts 2 siblings, 1 reply; 11+ messages in thread From: Gang Yan @ 2025-04-07 2:37 UTC (permalink / raw) To: mptcp; +Cc: Gang Yan In kernel, there exists a lot of 'fmod_ret' functions, such as 'update_socket_protocol'. But it cannot be attached in BCC-python directly, so this patch provides an interface for Python to use 'fmod_ret' attaching method. Signed-off-by: Gang Yan <yangang@kylinos.cn> --- src/python/bcc/__init__.py | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/python/bcc/__init__.py b/src/python/bcc/__init__.py index 8bc85516..96de3d40 100644 --- a/src/python/bcc/__init__.py +++ b/src/python/bcc/__init__.py @@ -461,6 +461,7 @@ class BPF(object): self.raw_tracepoint_fds = {} self.kfunc_entry_fds = {} self.kfunc_exit_fds = {} + self.fmod_ret_fds = {} self.lsm_fds = {} self.perf_buffers = {} self.open_perf_events = {} @@ -1157,6 +1158,21 @@ class BPF(object): return True return False + @staticmethod + def support_fmod_ret(): + if not BPF.support_kfunc(): + return False + + kernel_version = platform.release() + major, minor, _ = kernel_version.split(".") + + if int(major) > 5: + return True + elif int(major) ==5 and int(minor) >= 6: + return True + else: + return False + def detach_kfunc(self, fn_name=b""): fn_name = _assert_is_bytes(fn_name) fn_name = BPF.add_prefix(b"kfunc__", fn_name) @@ -1166,6 +1182,15 @@ class BPF(object): os.close(self.kfunc_entry_fds[fn_name]) del self.kfunc_entry_fds[fn_name] + def detach_fmod_ret(self, fn_name=b""): + fn_name = _assert_is_bytes(fn_name) + fn_name = BPF.add_prefix(b"kmod_ret__", fn_name) + + if fn_name not in self.fmod_ret_fds: + raise Exception("Fmod_ret func %s is not attached" % fn_name) + os.close(self.fmod_ret_fds[fn_name]) + del self.fmod_ret_fds[fn_name] + def detach_kretfunc(self, fn_name=b""): fn_name = _assert_is_bytes(fn_name) fn_name = BPF.add_prefix(b"kretfunc__", fn_name) @@ -1189,6 +1214,22 @@ class BPF(object): self.kfunc_entry_fds[fn_name] = fd return self + def attach_fmod_ret(self, fn_name=b""): + fn_name = _assert_is_bytes(fn_name) + fn_name = BPF.add_prefix(b"kmod_ret__", fn_name) + + if fn_name in self.fmod_ret_fds: + raise Exception("Fmod_ret func %s has been attached" % fn_name) + + fn = self.load_func(fn_name, BPF.TRACING) + fd = lib.bpf_attach_kfunc(fn.fd) + + if fd < 0: + raise Exception("Failed to attach BPF to fmod_ret kernel func") + self.fmod_ret_fds[fn_name] = fd + + return self + def attach_kretfunc(self, fn_name=b""): fn_name = _assert_is_bytes(fn_name) fn_name = BPF.add_prefix(b"kretfunc__", fn_name) @@ -1824,6 +1865,8 @@ class BPF(object): self.detach_kretfunc(k) for k, v in list(self.lsm_fds.items()): self.detach_lsm(k) + for k, v in list(self.fmod_ret_fds.items()): + self.detach_fmod_ret(k) # Clean up opened perf ring buffer and perf events table_keys = list(self.tables.keys()) -- 2.25.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF 2025-04-07 2:37 ` [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF Gang Yan @ 2025-04-07 9:07 ` Matthieu Baerts 2025-04-08 1:56 ` Gang Yan 0 siblings, 1 reply; 11+ messages in thread From: Matthieu Baerts @ 2025-04-07 9:07 UTC (permalink / raw) To: Gang Yan, mptcp Hi Gang, On 07/04/2025 04:37, Gang Yan wrote: > In kernel, there exists a lot of 'fmod_ret' functions, such as > 'update_socket_protocol'. But it cannot be attached in BCC-python > directly, so this patch provides an interface for Python to use > 'fmod_ret' attaching method. > > Signed-off-by: Gang Yan <yangang@kylinos.cn> > --- > src/python/bcc/__init__.py | 43 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) > > diff --git a/src/python/bcc/__init__.py b/src/python/bcc/__init__.py > index 8bc85516..96de3d40 100644 > --- a/src/python/bcc/__init__.py > +++ b/src/python/bcc/__init__.py > @@ -461,6 +461,7 @@ class BPF(object): > self.raw_tracepoint_fds = {} > self.kfunc_entry_fds = {} > self.kfunc_exit_fds = {} > + self.fmod_ret_fds = {} > self.lsm_fds = {} > self.perf_buffers = {} > self.open_perf_events = {} > @@ -1157,6 +1158,21 @@ class BPF(object): > return True > return False > > + @staticmethod > + def support_fmod_ret(): > + if not BPF.support_kfunc(): > + return False > + > + kernel_version = platform.release() > + major, minor, _ = kernel_version.split(".") > + > + if int(major) > 5: > + return True > + elif int(major) ==5 and int(minor) >= 6: Was it not introduced in v5.7 instead of v5.6? return int(major) > 5 or (int(major) == 5 and int(minor) >= 7) https://lore.kernel.org/20200304191853.1529-1-kpsingh@chromium.org But also, it feels wrong to look at the kernel version, in case of backports, etc. Can you not look at something else? e.g. kallsyms? Cheers, Matt -- Sponsored by the NGI0 Core fund. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF 2025-04-07 9:07 ` Matthieu Baerts @ 2025-04-08 1:56 ` Gang Yan 2025-04-08 10:02 ` Matthieu Baerts 0 siblings, 1 reply; 11+ messages in thread From: Gang Yan @ 2025-04-08 1:56 UTC (permalink / raw) To: Matthieu Baerts; +Cc: mptcp On Mon, Apr 07, 2025 at 11:07:41AM +0200, Matthieu Baerts wrote: Hi Matt, > Hi Gang, > > On 07/04/2025 04:37, Gang Yan wrote: > > In kernel, there exists a lot of 'fmod_ret' functions, such as > > 'update_socket_protocol'. But it cannot be attached in BCC-python > > directly, so this patch provides an interface for Python to use > > 'fmod_ret' attaching method. > > > > Signed-off-by: Gang Yan <yangang@kylinos.cn> > > --- > > src/python/bcc/__init__.py | 43 ++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 43 insertions(+) > > > > diff --git a/src/python/bcc/__init__.py b/src/python/bcc/__init__.py > > index 8bc85516..96de3d40 100644 > > --- a/src/python/bcc/__init__.py > > +++ b/src/python/bcc/__init__.py > > @@ -461,6 +461,7 @@ class BPF(object): > > self.raw_tracepoint_fds = {} > > self.kfunc_entry_fds = {} > > self.kfunc_exit_fds = {} > > + self.fmod_ret_fds = {} > > self.lsm_fds = {} > > self.perf_buffers = {} > > self.open_perf_events = {} > > @@ -1157,6 +1158,21 @@ class BPF(object): > > return True > > return False > > > > + @staticmethod > > + def support_fmod_ret(): > > + if not BPF.support_kfunc(): > > + return False > > + > > + kernel_version = platform.release() > > + major, minor, _ = kernel_version.split(".") > > + > > + if int(major) > 5: > > + return True > > + elif int(major) ==5 and int(minor) >= 6: > > Was it not introduced in v5.7 instead of v5.6? > > return int(major) > 5 or (int(major) == 5 and int(minor) >= 7) > I think v5.7 is right, the 5.6 is from the bcc repo: bcc/example/cpp/KModRetExample.cc: * Kfunc modify_ret support is only available at kernel version 5.6 and later. Maybe this is also need to be fixed later? > > https://lore.kernel.org/20200304191853.1529-1-kpsingh@chromium.org > > > But also, it feels wrong to look at the kernel version, in case of > backports, etc. Can you not look at something else? e.g. kallsyms? > Do you think we can do this after making a PR first? > Cheers, > Matt > -- > Sponsored by the NGI0 Core fund. > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF 2025-04-08 1:56 ` Gang Yan @ 2025-04-08 10:02 ` Matthieu Baerts 0 siblings, 0 replies; 11+ messages in thread From: Matthieu Baerts @ 2025-04-08 10:02 UTC (permalink / raw) To: Gang Yan; +Cc: mptcp Hi Gang, On 08/04/2025 03:56, Gang Yan wrote: > On Mon, Apr 07, 2025 at 11:07:41AM +0200, Matthieu Baerts wrote: > Hi Matt, > > >> Hi Gang, >> >> On 07/04/2025 04:37, Gang Yan wrote: >>> In kernel, there exists a lot of 'fmod_ret' functions, such as >>> 'update_socket_protocol'. But it cannot be attached in BCC-python >>> directly, so this patch provides an interface for Python to use >>> 'fmod_ret' attaching method. >>> >>> Signed-off-by: Gang Yan <yangang@kylinos.cn> >>> --- >>> src/python/bcc/__init__.py | 43 ++++++++++++++++++++++++++++++++++++++ >>> 1 file changed, 43 insertions(+) >>> >>> diff --git a/src/python/bcc/__init__.py b/src/python/bcc/__init__.py >>> index 8bc85516..96de3d40 100644 >>> --- a/src/python/bcc/__init__.py >>> +++ b/src/python/bcc/__init__.py >>> @@ -461,6 +461,7 @@ class BPF(object): >>> self.raw_tracepoint_fds = {} >>> self.kfunc_entry_fds = {} >>> self.kfunc_exit_fds = {} >>> + self.fmod_ret_fds = {} >>> self.lsm_fds = {} >>> self.perf_buffers = {} >>> self.open_perf_events = {} >>> @@ -1157,6 +1158,21 @@ class BPF(object): >>> return True >>> return False >>> >>> + @staticmethod >>> + def support_fmod_ret(): >>> + if not BPF.support_kfunc(): (I don't know if this dependence is needed here.) >>> + return False >>> + >>> + kernel_version = platform.release() >>> + major, minor, _ = kernel_version.split(".") >>> + >>> + if int(major) > 5: >>> + return True >>> + elif int(major) ==5 and int(minor) >= 6: >> >> Was it not introduced in v5.7 instead of v5.6? >> >> return int(major) > 5 or (int(major) == 5 and int(minor) >= 7) >> > I think v5.7 is right, the 5.6 is from the bcc repo: > > bcc/example/cpp/KModRetExample.cc: > * Kfunc modify_ret support is only available at kernel version 5.6 and later. > > Maybe this is also need to be fixed later? Maybe this bit is supported since v5.6 and fmod_ret from 5.7? I didn't check. >> https://lore.kernel.org/20200304191853.1529-1-kpsingh@chromium.org >> >> >> But also, it feels wrong to look at the kernel version, in case of >> backports, etc. Can you not look at something else? e.g. kallsyms? >> > > Do you think we can do this after making a PR first? I don't know the BCC project, but I think checking the version will not be accepted. I think it would be better to do something like that instead: @staticmethod def support_fmod_ret(): # It is not clear what can be used to check if 'fmod_ret' # supported by the kernel. Assuming checking kfunc is enough. return BPF.support_kfunc(): And add a note about that in the commit message, asking BCC devs for ideas. You can also say you considered checking the kernel version. Cheers, Matt -- Sponsored by the NGI0 Core fund. ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/2] BCC: python: add a useful tool for mptcp 2025-04-07 2:37 [PATCH 0/2] BCC: python: support fmod_ret Gang Yan 2025-04-07 2:37 ` [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF Gang Yan @ 2025-04-07 2:37 ` Gang Yan 2025-04-07 9:09 ` Matthieu Baerts 2025-04-07 9:07 ` [PATCH 0/2] BCC: python: support fmod_ret Matthieu Baerts 2 siblings, 1 reply; 11+ messages in thread From: Gang Yan @ 2025-04-07 2:37 UTC (permalink / raw) To: mptcp; +Cc: Gang Yan Multipath TCP (MPTCP) is an extension of the standard TCP protocol that allows a single transport connection to use multiple network interfaces. MPTCP is useful for applications like bandwidth aggregation, failover, and more resilient connections. Linux kernel starts to support MPTCP since v5.6, this patch provides a method which can easily force applications use MPTCP socket without modifing its code. Signed-off-by: Gang Yan <yangang@kylinos.cn> --- tools/mptcpboost.py | 82 ++++++++++++++++++++++++++++++++++++++++++++ tools/mptcpboost.txt | 22 ++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 tools/mptcpboost.py create mode 100644 tools/mptcpboost.txt diff --git a/tools/mptcpboost.py b/tools/mptcpboost.py new file mode 100644 index 00000000..0ddd731a --- /dev/null +++ b/tools/mptcpboost.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +# +# mptcpboost Make the applications to use MPTCP. +# For Linux, uses BCC, eBPF. Embedded C. +# +# USAGE: mptcpboost -t +# +# Copyright 2025 Kylin Software, Inc. +# Licensed under the Apache License, Version 2.0 (the "License") +# +# 05-Apr-2025 Gang Yan Created this. + +import ctypes as ct +import argparse +import signal +import time + +from bcc import BPF + +#arguments +parser = argparse.ArgumentParser( + description="mptcpboost try to force applications use MPTCP") +parser.add_argument("-t", "--targets", required=True, type=str, + help="use ',' for multi targets, eg: 'iperf3,rsync'") + +args_str = parser.parse_args() +args_list = [t.strip() for t in args_str.targets.split(',')] + +if (not BPF.support_fmod_ret()): + print("Your kernel version is too old," + " fmod_ret method is only support kernel v5.6 and later.") + exit() + +TASK_COMM_LEN = 18 + +class app_name(ct.Structure): + _fields_ = [("str", ct.c_char * TASK_COMM_LEN)] + +# define BPF program +prog = """ +#include <linux/net.h> +#include <uapi/linux/in.h> +#include <linux/string.h> + +struct app_name { + char name[TASK_COMM_LEN]; +}; + +BPF_HASH(support_apps, struct app_name); + +KMOD_RET(update_socket_protocol, int family, int type, int protocol, int ret) +{ + struct app_name target = {}; + bpf_get_current_comm(&target.name, TASK_COMM_LEN); + + if ((family == AF_INET || family == AF_INET6) && + type == SOCK_STREAM && + (!protocol || protocol ==IPPROTO_TCP) && + support_apps.lookup(&target)) + return IPPROTO_MPTCP; + + return protocol; + +} + +""" + +b = BPF(text=prog) +b.attach_fmod_ret("update_socket_protocol") + +support_apps = b.get_table("support_apps") +for i in args_list: + app = i.encode() + name = app_name() + name.str = app[:TASK_COMM_LEN-1].ljust(TASK_COMM_LEN, b'\0') + support_apps[name] = ct.c_uint32(1) + +print("MPTCP is been applied in ", args_list); +signal.pause() +#while(1): +# time.sleep(200) + diff --git a/tools/mptcpboost.txt b/tools/mptcpboost.txt new file mode 100644 index 00000000..114a1c8b --- /dev/null +++ b/tools/mptcpboost.txt @@ -0,0 +1,22 @@ +Demonstrations of mptcpboost, the Linux eBPF/bcc version. + + +mptcpboost forces the application to use MPTCP instead of TCP. + +mptcpboost has been verified with iperf3 and rsync[TCP module]. It can be used +for incresing the speed of transferring data with rsync. + +The MPTCP configuration is decribed in +https://www.mptcp.dev/pm.html + +USAGE message: + +usage: test.py [-h] -t TARGETS + +mptcpboost try to force applications use MPTCP + +options: + -h, --help show this help message and exit + -t TARGETS, --targets TARGETS + use ',' for multi targets, eg: 'iperf3,rsync' + -- 2.25.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] BCC: python: add a useful tool for mptcp 2025-04-07 2:37 ` [PATCH 2/2] BCC: python: add a useful tool for mptcp Gang Yan @ 2025-04-07 9:09 ` Matthieu Baerts 2025-04-08 2:00 ` Gang Yan 0 siblings, 1 reply; 11+ messages in thread From: Matthieu Baerts @ 2025-04-07 9:09 UTC (permalink / raw) To: Gang Yan, mptcp Hi Gang, On 07/04/2025 04:37, Gang Yan wrote: > Multipath TCP (MPTCP) is an extension of the standard TCP protocol > that allows a single transport connection to use multiple network > interfaces. MPTCP is useful for applications like bandwidth > aggregation, failover, and more resilient connections. > > Linux kernel starts to support MPTCP since v5.6, this patch provides > a method which can easily force applications use MPTCP socket without > modifing its code. > > Signed-off-by: Gang Yan <yangang@kylinos.cn> > --- > tools/mptcpboost.py | 82 ++++++++++++++++++++++++++++++++++++++++++++ > tools/mptcpboost.txt | 22 ++++++++++++ Small detail: what about re-using the "mptcpify" name https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/bpf/progs/mptcpify.c https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=ddba122428a7 Once applied on BCC side, we could update our website to point to this program: https://www.mptcp.dev/setup.html#force-applications-to-use-mptcp > 2 files changed, 104 insertions(+) > create mode 100644 tools/mptcpboost.py > create mode 100644 tools/mptcpboost.txt > > diff --git a/tools/mptcpboost.py b/tools/mptcpboost.py > new file mode 100644 > index 00000000..0ddd731a > --- /dev/null > +++ b/tools/mptcpboost.py > @@ -0,0 +1,82 @@ > +#!/usr/bin/env python > +# > +# mptcpboost Make the applications to use MPTCP. > +# For Linux, uses BCC, eBPF. Embedded C. > +# > +# USAGE: mptcpboost -t > +# > +# Copyright 2025 Kylin Software, Inc. > +# Licensed under the Apache License, Version 2.0 (the "License") > +# > +# 05-Apr-2025 Gang Yan Created this. > + > +import ctypes as ct > +import argparse > +import signal > +import time > + > +from bcc import BPF > + > +#arguments > +parser = argparse.ArgumentParser( > + description="mptcpboost try to force applications use MPTCP") detail: 'to' missing: try to force applications *to* use MPTCP Maybe clearer if we add 'instead of TCP'? > +parser.add_argument("-t", "--targets", required=True, type=str, > + help="use ',' for multi targets, eg: 'iperf3,rsync'") Could it be eventually optional to force all apps from the same CGroup to use MPTCP instead of TCP? Another idea is to restrict this transformation to the app passed in argument, e.g. mptcpify -- iperf3 -s (but can be done later if this makes sense) > + > +args_str = parser.parse_args() > +args_list = [t.strip() for t in args_str.targets.split(',')] > + > +if (not BPF.support_fmod_ret()): > + print("Your kernel version is too old," > + " fmod_ret method is only support kernel v5.6 and later.") v5.7? > + exit() > + > +TASK_COMM_LEN = 18 > + > +class app_name(ct.Structure): > + _fields_ = [("str", ct.c_char * TASK_COMM_LEN)] > + > +# define BPF program > +prog = """ > +#include <linux/net.h> > +#include <uapi/linux/in.h> > +#include <linux/string.h> > + > +struct app_name { > + char name[TASK_COMM_LEN]; > +}; > + > +BPF_HASH(support_apps, struct app_name); > + > +KMOD_RET(update_socket_protocol, int family, int type, int protocol, int ret) > +{ > + struct app_name target = {}; > + bpf_get_current_comm(&target.name, TASK_COMM_LEN); > + > + if ((family == AF_INET || family == AF_INET6) && > + type == SOCK_STREAM && > + (!protocol || protocol ==IPPROTO_TCP) && detail: space missing after '==' > + support_apps.lookup(&target)) > + return IPPROTO_MPTCP; > + > + return protocol; > + > +} > + > +""" > + > +b = BPF(text=prog) > +b.attach_fmod_ret("update_socket_protocol") > + > +support_apps = b.get_table("support_apps") > +for i in args_list: > + app = i.encode() > + name = app_name() > + name.str = app[:TASK_COMM_LEN-1].ljust(TASK_COMM_LEN, b'\0') > + support_apps[name] = ct.c_uint32(1) > + > +print("MPTCP is been applied in ", args_list); detail: MPTCP is being forced for: > +signal.pause() > +#while(1): > +# time.sleep(200) I guess you can remove the comments. Cheers, Matt -- Sponsored by the NGI0 Core fund. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] BCC: python: add a useful tool for mptcp 2025-04-07 9:09 ` Matthieu Baerts @ 2025-04-08 2:00 ` Gang Yan 0 siblings, 0 replies; 11+ messages in thread From: Gang Yan @ 2025-04-08 2:00 UTC (permalink / raw) To: Matthieu Baerts; +Cc: mptcp On Mon, Apr 07, 2025 at 11:09:59AM +0200, Matthieu Baerts wrote: Hi Matt, > Hi Gang, > > On 07/04/2025 04:37, Gang Yan wrote: > > Multipath TCP (MPTCP) is an extension of the standard TCP protocol > > that allows a single transport connection to use multiple network > > interfaces. MPTCP is useful for applications like bandwidth > > aggregation, failover, and more resilient connections. > > > > Linux kernel starts to support MPTCP since v5.6, this patch provides > > a method which can easily force applications use MPTCP socket without > > modifing its code. > > > > Signed-off-by: Gang Yan <yangang@kylinos.cn> > > --- > > tools/mptcpboost.py | 82 ++++++++++++++++++++++++++++++++++++++++++++ > > tools/mptcpboost.txt | 22 ++++++++++++ > > Small detail: what about re-using the "mptcpify" name > OK, I'll use this name in v2. > https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/bpf/progs/mptcpify.c > https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=ddba122428a7 > > Once applied on BCC side, we could update our website to point to this > program: > > https://www.mptcp.dev/setup.html#force-applications-to-use-mptcp > > > 2 files changed, 104 insertions(+) > > create mode 100644 tools/mptcpboost.py > > create mode 100644 tools/mptcpboost.txt > > > > diff --git a/tools/mptcpboost.py b/tools/mptcpboost.py > > new file mode 100644 > > index 00000000..0ddd731a > > --- /dev/null > > +++ b/tools/mptcpboost.py > > @@ -0,0 +1,82 @@ > > +#!/usr/bin/env python > > +# > > +# mptcpboost Make the applications to use MPTCP. > > +# For Linux, uses BCC, eBPF. Embedded C. > > +# > > +# USAGE: mptcpboost -t > > +# > > +# Copyright 2025 Kylin Software, Inc. > > +# Licensed under the Apache License, Version 2.0 (the "License") > > +# > > +# 05-Apr-2025 Gang Yan Created this. > > + > > +import ctypes as ct > > +import argparse > > +import signal > > +import time > > + > > +from bcc import BPF > > + > > +#arguments > > +parser = argparse.ArgumentParser( > > + description="mptcpboost try to force applications use MPTCP") > > detail: 'to' missing: try to force applications *to* use MPTCP > > Maybe clearer if we add 'instead of TCP'? Thanks for your suggestion, it sounds good. > > +parser.add_argument("-t", "--targets", required=True, type=str, > > + help="use ',' for multi targets, eg: 'iperf3,rsync'") > > Could it be eventually optional to force all apps from the same CGroup > to use MPTCP instead of TCP? > > > Another idea is to restrict this transformation to the app passed in > argument, e.g. > > mptcpify -- iperf3 -s > > (but can be done later if this makes sense) Yeah, I think this can be done later. > > + > > +args_str = parser.parse_args() > > +args_list = [t.strip() for t in args_str.targets.split(',')] > > + > > +if (not BPF.support_fmod_ret()): > > + print("Your kernel version is too old," > > + " fmod_ret method is only support kernel v5.6 and later.") > > v5.7? > > > + exit() > > + > > +TASK_COMM_LEN = 18 > > + > > +class app_name(ct.Structure): > > + _fields_ = [("str", ct.c_char * TASK_COMM_LEN)] > > + > > +# define BPF program > > +prog = """ > > +#include <linux/net.h> > > +#include <uapi/linux/in.h> > > +#include <linux/string.h> > > + > > +struct app_name { > > + char name[TASK_COMM_LEN]; > > +}; > > + > > +BPF_HASH(support_apps, struct app_name); > > + > > +KMOD_RET(update_socket_protocol, int family, int type, int protocol, int ret) > > +{ > > + struct app_name target = {}; > > + bpf_get_current_comm(&target.name, TASK_COMM_LEN); > > + > > + if ((family == AF_INET || family == AF_INET6) && > > + type == SOCK_STREAM && > > + (!protocol || protocol ==IPPROTO_TCP) && > > detail: space missing after '==' Thanks! > > + support_apps.lookup(&target)) > > + return IPPROTO_MPTCP; > > + > > + return protocol; > > + > > +} > > + > > +""" > > + > > +b = BPF(text=prog) > > +b.attach_fmod_ret("update_socket_protocol") > > + > > +support_apps = b.get_table("support_apps") > > +for i in args_list: > > + app = i.encode() > > + name = app_name() > > + name.str = app[:TASK_COMM_LEN-1].ljust(TASK_COMM_LEN, b'\0') > > + support_apps[name] = ct.c_uint32(1) > > + > > +print("MPTCP is been applied in ", args_list); > > detail: MPTCP is being forced for: > OK! > > +signal.pause() > > +#while(1): > > +# time.sleep(200) > > I guess you can remove the comments. Sure, that's my fault. > > Cheers, > Matt > -- > Sponsored by the NGI0 Core fund. > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/2] BCC: python: support fmod_ret 2025-04-07 2:37 [PATCH 0/2] BCC: python: support fmod_ret Gang Yan 2025-04-07 2:37 ` [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF Gang Yan 2025-04-07 2:37 ` [PATCH 2/2] BCC: python: add a useful tool for mptcp Gang Yan @ 2025-04-07 9:07 ` Matthieu Baerts 2025-04-08 2:02 ` Gang Yan 2 siblings, 1 reply; 11+ messages in thread From: Matthieu Baerts @ 2025-04-07 9:07 UTC (permalink / raw) To: Gang Yan, mptcp Hi Gang, On 07/04/2025 04:37, Gang Yan wrote: > Support fmod_ret, and add a useful tool for mptcp, also > the interface can be verified with this function. > > Gang Yan (2): > BCC: Python: Support 'fmod_ret' method for eBPF > BCC: python: add a useful tool for mptcp Thank you for looking at this! Personally, I don't know how BCC is working internally, but the modifications seem to make sense. I have a few comments, but apart from that, feel free to create the PR on BCC repo. Cheers, Matt -- Sponsored by the NGI0 Core fund. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/2] BCC: python: support fmod_ret 2025-04-07 9:07 ` [PATCH 0/2] BCC: python: support fmod_ret Matthieu Baerts @ 2025-04-08 2:02 ` Gang Yan 2025-04-08 10:04 ` Matthieu Baerts 0 siblings, 1 reply; 11+ messages in thread From: Gang Yan @ 2025-04-08 2:02 UTC (permalink / raw) To: Matthieu Baerts; +Cc: mptcp On Mon, Apr 07, 2025 at 11:07:04AM +0200, Matthieu Baerts wrote: Hi Matt, > Hi Gang, > > On 07/04/2025 04:37, Gang Yan wrote: > > Support fmod_ret, and add a useful tool for mptcp, also > > the interface can be verified with this function. > > > > Gang Yan (2): > > BCC: Python: Support 'fmod_ret' method for eBPF > > BCC: python: add a useful tool for mptcp > > Thank you for looking at this! > > Personally, I don't know how BCC is working internally, but the > modifications seem to make sense. > > I have a few comments, but apart from that, feel free to create the PR > on BCC repo. > Thanks for the comments! Can I add your <Reviewd-by> in this PR? > Cheers, > Matt > -- > Sponsored by the NGI0 Core fund. > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/2] BCC: python: support fmod_ret 2025-04-08 2:02 ` Gang Yan @ 2025-04-08 10:04 ` Matthieu Baerts 0 siblings, 0 replies; 11+ messages in thread From: Matthieu Baerts @ 2025-04-08 10:04 UTC (permalink / raw) To: Gang Yan; +Cc: mptcp Hi Gang, On 08/04/2025 04:02, Gang Yan wrote: > On Mon, Apr 07, 2025 at 11:07:04AM +0200, Matthieu Baerts wrote: > Hi Matt, >> Hi Gang, >> >> On 07/04/2025 04:37, Gang Yan wrote: >>> Support fmod_ret, and add a useful tool for mptcp, also >>> the interface can be verified with this function. >>> >>> Gang Yan (2): >>> BCC: Python: Support 'fmod_ret' method for eBPF >>> BCC: python: add a useful tool for mptcp >> >> Thank you for looking at this! >> >> Personally, I don't know how BCC is working internally, but the >> modifications seem to make sense. >> >> I have a few comments, but apart from that, feel free to create the PR >> on BCC repo. >> > > Thanks for the comments! > > Can I add your <Reviewd-by> in this PR? I don't think they use these tags in BCC. (If any, it should be more Acked-by). Maybe better to add something like that in the Pull Request message: @matttbe from the MPTCP kernel team had a look at the new tool. Cheers, Matt -- Sponsored by the NGI0 Core fund. ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-04-08 10:04 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-04-07 2:37 [PATCH 0/2] BCC: python: support fmod_ret Gang Yan 2025-04-07 2:37 ` [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF Gang Yan 2025-04-07 9:07 ` Matthieu Baerts 2025-04-08 1:56 ` Gang Yan 2025-04-08 10:02 ` Matthieu Baerts 2025-04-07 2:37 ` [PATCH 2/2] BCC: python: add a useful tool for mptcp Gang Yan 2025-04-07 9:09 ` Matthieu Baerts 2025-04-08 2:00 ` Gang Yan 2025-04-07 9:07 ` [PATCH 0/2] BCC: python: support fmod_ret Matthieu Baerts 2025-04-08 2:02 ` Gang Yan 2025-04-08 10:04 ` Matthieu Baerts
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.