From: Matthieu Baerts <matttbe@kernel.org>
To: Geliang Tang <geliang@kernel.org>, mptcp@lists.linux.dev
Cc: Geliang Tang <tanggeliang@kylinos.cn>
Subject: Re: [PATCH mptcp-next 07/10] selftests: mptcp: add endpoint_ops API helper
Date: Wed, 13 Mar 2024 19:50:24 +0100 [thread overview]
Message-ID: <bc95bd09-8b32-4a4a-ae87-0cd4fbfc6e4c@kernel.org> (raw)
In-Reply-To: <d327fe8645094080a922dc5075a0d2b45166a5f8.1710121590.git.tanggeliang@kylinos.cn>
Hi Geliang,
On 11/03/2024 02:48, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> This patch moves six endpoint operation helpers with the pm_nl_ prefix:
>
> pm_nl_limits(),
> pm_nl_add_endpoint(),
> pm_nl_del_endpoint(),
> pm_nl_flush_endpoint(),
> pm_nl_show_endpoints() and
> pm_nl_change_endpoint()
>
> from mptcp_join.sh into mptcp_lib.sh as public functions, and renamed each
> of them with a mptcp_lib_ prefix.
>
> Add a new helper mptcp_lib_endpoint_ops() in mptcp_lib.sh as the API for
> all endpoint operation helpers, which invokes each of mptcp_lib_ prefix
> helpers according to the first argument of it is "limits", "add", "del",
> "flush", "show" or "change".
>
> Usage:
> mptcp_lib_endpoint_ops limits $ns $addrs $subflows
> mptcp_lib_endpoint_ops add $ns $addr
> mptcp_lib_endpoint_ops del $ns $id $addr
> mptcp_lib_endpoint_ops flush $ns
> mptcp_lib_endpoint_ops show $ns
> mptcp_lib_endpoint_ops change $ns $id $flags
I'm not sure to understand why you called this helper "endpoint". With
"pm_nl", it means it is linked to the Path Manager, the Netlink
interface. Maybe best to use 'mptcp_lib_pm_nl_ops'?
(...)
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> index c465f1d59419..d395692fac0d 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> @@ -523,3 +523,151 @@ mptcp_lib_is_ip_mptcp() {
>
> [ ${mptcp_lib_ip_mptcp} -eq 1 ]
> }
> +
> +mptcp_lib_limits() {
Same here for the prefix, "limits" is too vague:
mptcp_lib_pm_nl_limits()
> + local ns=${1}
> + local addrs=${2}
> + local subflows=${3}
> +
> + if mptcp_lib_is_ip_mptcp; then
> + local limits="limits"
> +
> + if [ -n "${addrs}" ] && [ -n "${subflows}" ]; then
> + limits+=" set add_addr_accepted ${addrs} subflows ${subflows}"
> + fi
> + # shellcheck disable=SC2086
Please *always* *always* justify why you ignore a rule, e.g.
# shellcheck disable=SCXXXX ## <reason>
or
# <long description>
# <on multiple lines>
# shellcheck disable=SCXXXX
(I guess you don't need to ignore that if you look at my comment on
patch 2/10, same below)
> + ip -n "${ns}" mptcp ${limits}
> + else
> + # shellcheck disable=SC2086
> + ip netns exec "${ns}" ./pm_nl_ctl limits "${addrs}" ${subflows}
> + fi
> +}
> +
> +mptcp_lib_add_endpoint() {
> + local ns=${1}
> + local addr=${2}
> + local flags _flags
> + local port _port
> + local dev _dev
> + local id _id
> + local nr=2
> +
> + local p
> + for p in "${@}"
> + do
> + if [ "${p}" = "flags" ]; then
> + eval _flags=\$"${nr}"
> + [ -n "${_flags}" ]; flags="flags ${_flags}"
> + fi
> + if [ "${p}" = "dev" ]; then
> + eval _dev=\$"${nr}"
> + [ -n "${_dev}" ]; dev="dev ${_dev}"
> + fi
> + if [ "${p}" = "id" ]; then
> + eval _id=\$"${nr}"
> + [ -n "${_id}" ]; id="id ${_id}"
> + fi
> + if [ "${p}" = "port" ]; then
> + eval _port=\$"${nr}"
> + [ -n "${_port}" ]; port="port ${_port}"
> + fi
> +
> + nr=$((nr + 1))
> + done
> +
> + if mptcp_lib_is_ip_mptcp; then
> + # shellcheck disable=SC2086
I wonder if you couldn't use arrays:
dev=(dev "${_dev}")
(...)
ip (...) "${dev[@]}")
> + ip -n "${ns}" mptcp endpoint add "${addr}" ${_flags//","/" "} ${dev} ${id} ${port}
> + else
> + # shellcheck disable=SC2086
> + ip netns exec "${ns}" ./pm_nl_ctl add "${addr}" ${flags} ${dev} ${id} ${port}
> + fi
> +}
> +
> +mptcp_lib_del_endpoint() {
> + local ns=${1}
> + local id=${2}
> + local addr=${3}
> +
> + if mptcp_lib_is_ip_mptcp; then
> + [ "${id}" -ne 0 ] && addr=''
> + # shellcheck disable=SC2086
> + ip -n "${ns}" mptcp endpoint delete id "${id}" ${addr}
or something like that to avoid the disable:
${addr:+"${addr}"}
> + else
> + ip netns exec "${ns}" ./pm_nl_ctl del "${id}" "${addr}"
> + fi
> +}
> +
> +mptcp_lib_flush_endpoint() {
> + local ns=${1}
> +
> + if mptcp_lib_is_ip_mptcp; then
> + ip -n "${ns}" mptcp endpoint flush
> + else
> + ip netns exec "${ns}" ./pm_nl_ctl flush
> + fi
> +}
> +
> +mptcp_lib_show_endpoints() {
(I guess this one is only needed in pm_netlink.sh, no?)
> + local ns=${1}
> + local id=${2}
> +
> + if mptcp_lib_is_ip_mptcp; then
> + local show="show"
> +
> + [ -n "${id}" ] && show+=" id ${id}"
> + # shellcheck disable=SC2086
> + ip -n "${ns}" mptcp endpoint ${show}
Maybe this to avoid the disable:
ip -n "${ns}" mptcp endpoint show ${id:+id "${id}"}
Same below
> + else
> + local dump="dump"
> +
> + [ -n "${id}" ] && dump="get ${id}"
> + # shellcheck disable=SC2086
> + ip netns exec "${ns}" ./pm_nl_ctl ${dump}
> + fi
> +}
> +
> +mptcp_lib_change_endpoint() {
(I guess this one is only needed in pm_netlink.sh, no?)
> + local ns=${1}
> + local addr=${2}
> + local flags=${3}
> +
> + if ! mptcp_lib_is_addr "${addr}"; then
> + [ "${addr}" -gt 0 ] && [ "${addr}" -lt 256 ] && addr="id ${addr}"
use an array?
XX=("${addr}")
XX=("id ${addr}")
${XX[@]}
> + fi
> +
> + if mptcp_lib_is_ip_mptcp; then
> + # shellcheck disable=SC2086
> + ip -n "${ns}" mptcp endpoint change ${addr} ${flags//","/" "}
> + else
> + # shellcheck disable=SC2086
> + ip netns exec "${ns}" ./pm_nl_ctl set ${addr} flags "${flags}"
> + fi
> +}
> +
> +mptcp_lib_endpoint_ops() {
> + [ "$#" -lt 2 ] && return 1
> +
> + case "$1" in
(missing {} → ${1})
> + "limits")
> + mptcp_lib_limits "${@:2}"
> + ;;
> + "add")
> + mptcp_lib_add_endpoint "${@:2}"
> + ;;
> + "del")
> + mptcp_lib_del_endpoint "${@:2}"
> + ;;
> + "flush")
> + mptcp_lib_flush_endpoint "${@:2}"
> + ;;
> + "show")
> + mptcp_lib_show_endpoints "${@:2}"
> + ;;
> + "change")
> + mptcp_lib_change_endpoint "${@:2}"
> + ;;
> + *)
> + ;;
> + esac
> +}
I'm not sure to see the advantage of using mptcp_lib_endpoint_ops(), why
not directly calling mptcp_lib_pm_nl_limits, etc.?
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
next prev parent reply other threads:[~2024-03-13 18:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-11 1:48 [PATCH mptcp-next 00/10] add helpers and vars in mptcp_lib.sh, final Geliang Tang
2024-03-11 1:48 ` [PATCH mptcp-next 01/10] selftests: mptcp: export ip_mptcp to mptcp_lib Geliang Tang
2024-03-13 18:47 ` Matthieu Baerts
2024-03-11 1:48 ` [PATCH mptcp-next 02/10] selftests: mptcp: get support for limits Geliang Tang
2024-03-13 18:47 ` Matthieu Baerts
2024-03-11 1:48 ` [PATCH mptcp-next 03/10] selftests: mptcp: id support for show_endpoints Geliang Tang
2024-03-13 18:47 ` Matthieu Baerts
2024-03-11 1:48 ` [PATCH mptcp-next 04/10] selftests: mptcp: addr support for change_endpoint Geliang Tang
2024-03-13 18:48 ` Matthieu Baerts
2024-03-11 1:48 ` [PATCH mptcp-next 05/10] selftests: mptcp: netlink: fix positions of newline Geliang Tang
2024-03-11 1:48 ` [PATCH mptcp-next 06/10] selftests: mptcp: netlink: add outputs for ip_mptcp Geliang Tang
2024-03-13 18:49 ` Matthieu Baerts
2024-03-11 1:48 ` [PATCH mptcp-next 07/10] selftests: mptcp: add endpoint_ops API helper Geliang Tang
2024-03-13 18:50 ` Matthieu Baerts [this message]
2024-03-11 1:48 ` [PATCH mptcp-next 08/10] selftests: mptcp: use mptcp_lib_endpoint_ops Geliang Tang
2024-03-11 1:48 ` [PATCH mptcp-next 09/10] selftests: mptcp: add ip_mptcp option for more scripts Geliang Tang
2024-03-11 1:48 ` [PATCH mptcp-next 10/10] selftests: mptcp: netlink: drop disable=SC2086 Geliang Tang
2024-03-11 2:06 ` selftests: mptcp: netlink: drop disable=SC2086: Build Failure MPTCP CI
2024-03-11 2:44 ` selftests: mptcp: netlink: drop disable=SC2086: Tests Results MPTCP CI
2024-03-13 15:18 ` [PATCH mptcp-next 10/10] selftests: mptcp: netlink: drop disable=SC2086 MPTCP CI
2024-03-13 18:46 ` [PATCH mptcp-next 00/10] add helpers and vars in mptcp_lib.sh, final Matthieu Baerts
2024-03-16 3:56 ` Geliang Tang
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=bc95bd09-8b32-4a4a-ae87-0cd4fbfc6e4c@kernel.org \
--to=matttbe@kernel.org \
--cc=geliang@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=tanggeliang@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.