Skip to contentSkip to conversation

BCC: python: support fmod_ret

PATCH Superseded Gang Yan 2 participants 11 messages Apr 7, 2025 – Apr 8, 2025 Networking MPTCP

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Gang Yan

author
#0 lore raw

cover BCC: python: support fmod_ret

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
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/2 BCC: Python: Support 'fmod_ret' method for eBPF

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.

---
 src/python/bcc/__init__.py | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
src/python/bcc/__init__.py +43 -0
index 8bc85516..96de3d40 100644
@@ -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())
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF

Hi Gang,

Quoted 27 lines · 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.

---
 src/python/bcc/__init__.py | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
src/python/bcc/__init__.py +2 -0
index 8bc85516..96de3d40 100644
@@ -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

src/python/bcc/__init__.py class BPF(object): · line 1171

Quoted 10 lines
src/python/bcc/__init__.py +10 -0
+    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/[email protected]

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

Signature · 1 line
Sponsored by the NGI0 Core fund.
author
#3 lore raw

Re: [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF

On Mon, Apr 07, 2025 at 11:07:41AM +0200, Matthieu Baerts wrote:
Hi Matt,

Quoted 43 lines

Hi Gang,

Quoted 27 lines · 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.

---
 src/python/bcc/__init__.py | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
src/python/bcc/__init__.py +2 -0
index 8bc85516..96de3d40 100644
@@ -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

src/python/bcc/__init__.py class BPF(object): · line 1171

Quoted 10 lines
src/python/bcc/__init__.py +10 -0
+    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?

Quoted 2 lines

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?

Quoted 7 lines

https://lore.kernel.org/[email protected]

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?

Quoted 6 lines

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#4 lore raw

Re: [PATCH 1/2] BCC: Python: Support 'fmod_ret' method for eBPF

Hi Gang,

Quoted 33 lines · Gang Yan

On Mon, Apr 07, 2025 at 11:07:41AM +0200, Matthieu Baerts wrote:
Hi Matt,

Quoted 29 lines

Hi Gang,

Quoted 26 lines · 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.

---
 src/python/bcc/__init__.py | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
src/python/bcc/__init__.py +1 -0
index 8bc85516..96de3d40 100644
@@ -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
 
Quoted 3 lines
Quoted 3 lines

src/python/bcc/__init__.py class BPF(object): · line 1163

Quoted 3 lines
src/python/bcc/__init__.py +3 -0
+    @staticmethod
+    def support_fmod_ret():
+        if not BPF.support_kfunc():

(I don't know if this dependence is needed here.)

Quoted 11 lines
Quoted 11 lines

src/python/bcc/__init__.py class BPF(object): · line 1171

Quoted 8 lines
src/python/bcc/__init__.py +8 -0
+            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?

Quoted 8 lines
Quoted 2 lines

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.

Quoted 8 lines
Quoted 6 lines

https://lore.kernel.org/[email protected]

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

Signature · 1 line
Sponsored by the NGI0 Core fund.
author
#5 lore raw

PATCH 2/2 BCC: python: add a useful tool for mptcp

In reply to 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.

---
 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
tools/mptcpboost.py new file +82 -0
new file mode 100644
index 00000000..0ddd731a
@@ -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)
+
tools/mptcpboost.txt new file +22 -0
new file mode 100644
index 00000000..114a1c8b
@@ -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'
+
Signature · 1 line
2.25.1
maintainer
#6 lore raw

Re: [PATCH 2/2] BCC: python: add a useful tool for mptcp

Hi Gang,

Quoted 5 lines · 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.

Quoted 8 lines

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.

---
 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

Quoted 22 lines
 2 files changed, 104 insertions(+)
 create mode 100644 tools/mptcpboost.py
 create mode 100644 tools/mptcpboost.txt
tools/mptcpboost.py new file +12 -0
new file mode 100644
index 00000000..0ddd731a
@@ -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.
+

tools/mptcpboost.py line 22

Quoted 10 lines
tools/mptcpboost.py new file +10 -0
+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'?

tools/mptcpboost.py line 24

Quoted 2 lines
tools/mptcpboost.py new file +2 -0
+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)

tools/mptcpboost.py line 31

Quoted 7 lines
tools/mptcpboost.py new file +7 -0
+
+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?

Quoted 17 lines
tools/mptcpboost.py new file +17 -0
+    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];
+};
+

tools/mptcpboost.py line 58

Quoted 10 lines
tools/mptcpboost.py new file +10 -0
+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 '=='

Quoted 10 lines
tools/mptcpboost.py new file +10 -0
+        support_apps.lookup(&target))
+        return IPPROTO_MPTCP;
+
+    return protocol;
+
+}
+
+"""
+
+b = BPF(text=prog)

tools/mptcpboost.py line 78

Quoted 10 lines
tools/mptcpboost.py new file +10 -0
+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:

tools/mptcpboost.py line 81

Quoted 3 lines
tools/mptcpboost.py new file +3 -0
+signal.pause()
+#while(1):
+#   time.sleep(200)

I guess you can remove the comments.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author
#7 lore raw

Re: [PATCH 2/2] BCC: python: add a useful tool for mptcp

On Mon, Apr 07, 2025 at 11:09:59AM +0200, Matthieu Baerts wrote:
Hi Matt,

Quoted 12 lines

Hi Gang,

Quoted 9 lines · 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.

Quoted 7 lines
Quoted 4 lines
---
 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.

Quoted 43 lines

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

Quoted 22 lines
 2 files changed, 104 insertions(+)
 create mode 100644 tools/mptcpboost.py
 create mode 100644 tools/mptcpboost.txt
tools/mptcpboost.py new file +12 -0
new file mode 100644
index 00000000..0ddd731a
@@ -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.
+

tools/mptcpboost.py line 22

Quoted 10 lines
tools/mptcpboost.py new file +10 -0
+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

Quoted 1 line

Maybe clearer if we add 'instead of TCP'?

Thanks for your suggestion, it sounds good.

Quoted 7 lines

tools/mptcpboost.py line 24

Quoted 2 lines
tools/mptcpboost.py new file +2 -0
+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?

Quoted 6 lines

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.

Quoted 31 lines

tools/mptcpboost.py line 31

Quoted 7 lines
tools/mptcpboost.py new file +7 -0
+
+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?

Quoted 21 lines
tools/mptcpboost.py new file +21 -0
+    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)
+{
Quoted 8 lines

tools/mptcpboost.py line 58

Quoted 6 lines
tools/mptcpboost.py new file +6 -0
+    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!

Quoted 14 lines
Quoted 14 lines
tools/mptcpboost.py new file +14 -0
+        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:
Quoted 9 lines

tools/mptcpboost.py line 78

Quoted 6 lines
tools/mptcpboost.py new file +6 -0
+    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!

Quoted 5 lines

tools/mptcpboost.py line 81

Quoted 3 lines
tools/mptcpboost.py new file +3 -0
+signal.pause()
+#while(1):
+#   time.sleep(200)

I guess you can remove the comments.

Sure, that's my fault.

Quoted 7 lines

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#8 lore raw
In reply to Gang Yan

Hi Gang,

Quoted 6 lines · 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

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

Signature · 1 line
Sponsored by the NGI0 Core fund.
author
#9 lore raw

On Mon, Apr 07, 2025 at 11:07:04AM +0200, Matthieu Baerts wrote:
Hi Matt,

Quoted 10 lines

Hi Gang,

Quoted 6 lines · 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

Quoted 8 lines

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?

Quoted 6 lines

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#10 lore raw

Hi Gang,

Quoted 17 lines · Gang Yan

On Mon, Apr 07, 2025 at 11:07:04AM +0200, Matthieu Baerts wrote:
Hi Matt,

Quoted 15 lines

Hi Gang,

Quoted 6 lines · 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

Thank you for looking at this!

Personally, I don't know how BCC is working internally, but the modifications seem to make sense.

Quoted 7 lines
Quoted 3 lines

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

Signature · 1 line
Sponsored by the NGI0 Core fund.