From: Matthieu Baerts <matttbe@kernel.org>
To: Gang Yan <yangang@kylinos.cn>, mptcp@lists.linux.dev
Subject: Re: [PATCH 2/2] BCC: python: add a useful tool for mptcp
Date: Mon, 7 Apr 2025 11:09:59 +0200 [thread overview]
Message-ID: <a4df5346-ecaf-4dda-99ea-9652e2db484c@kernel.org> (raw)
In-Reply-To: <df79879bf4e8c5c73ffcc557cdb6f517e29ccae7.1743988616.git.yangang@kylinos.cn>
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.
next prev parent reply other threads:[~2025-04-07 9:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a4df5346-ecaf-4dda-99ea-9652e2db484c@kernel.org \
--to=matttbe@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=yangang@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.