net/ipv4/tcp_ipv4.c | 7 ++----- net/ipv6/tcp_ipv6.c | 9 +++------ 2 files changed, 5 insertions(+), 11 deletions(-)
From: Geliang Tang <tanggeliang@kylinos.cn>
The l3flag variable was redundant as it duplicated the value of
the 'flags' variable which already contains the interface index flag
status from cmd.tcpm_flags. This cleanup simplifies the code by
eliminating unnecessary variable duplication.
Changes:
1. Remove l3flag variable declarations
2. Replace l3flag usage with existing 'flags' variable
3. Maintain identical functionality with reduced complexity
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/ipv4/tcp_ipv4.c | 7 ++-----
net/ipv6/tcp_ipv6.c | 9 +++------
2 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 84d3d556ed80..e04cd0652ab3 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1519,7 +1519,6 @@ static int tcp_v4_parse_md5_keys(struct sock *sk, int optname,
const union tcp_md5_addr *addr;
u8 prefixlen = 32;
int l3index = 0;
- bool l3flag;
u8 flags;
if (optlen < sizeof(cmd))
@@ -1532,7 +1531,6 @@ static int tcp_v4_parse_md5_keys(struct sock *sk, int optname,
return -EINVAL;
flags = cmd.tcpm_flags & TCP_MD5SIG_FLAG_IFINDEX;
- l3flag = cmd.tcpm_flags & TCP_MD5SIG_FLAG_IFINDEX;
if (optname == TCP_MD5SIG_EXT &&
cmd.tcpm_flags & TCP_MD5SIG_FLAG_PREFIX) {
@@ -1541,8 +1539,7 @@ static int tcp_v4_parse_md5_keys(struct sock *sk, int optname,
return -EINVAL;
}
- if (optname == TCP_MD5SIG_EXT && cmd.tcpm_ifindex &&
- cmd.tcpm_flags & TCP_MD5SIG_FLAG_IFINDEX) {
+ if (optname == TCP_MD5SIG_EXT && cmd.tcpm_ifindex && flags) {
struct net_device *dev;
rcu_read_lock();
@@ -1570,7 +1567,7 @@ static int tcp_v4_parse_md5_keys(struct sock *sk, int optname,
/* Don't allow keys for peers that have a matching TCP-AO key.
* See the comment in tcp_ao_add_cmd()
*/
- if (tcp_ao_required(sk, addr, AF_INET, l3flag ? l3index : -1, false))
+ if (tcp_ao_required(sk, addr, AF_INET, flags ? l3index : -1, false))
return -EKEYREJECTED;
return tcp_md5_do_add(sk, addr, AF_INET, prefixlen, l3index, flags,
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 7577e7eb2c97..b2bfc5f03393 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -610,7 +610,6 @@ static int tcp_v6_parse_md5_keys(struct sock *sk, int optname,
union tcp_ao_addr *addr;
int l3index = 0;
u8 prefixlen;
- bool l3flag;
u8 flags;
if (optlen < sizeof(cmd))
@@ -623,7 +622,6 @@ static int tcp_v6_parse_md5_keys(struct sock *sk, int optname,
return -EINVAL;
flags = cmd.tcpm_flags & TCP_MD5SIG_FLAG_IFINDEX;
- l3flag = cmd.tcpm_flags & TCP_MD5SIG_FLAG_IFINDEX;
if (optname == TCP_MD5SIG_EXT &&
cmd.tcpm_flags & TCP_MD5SIG_FLAG_PREFIX) {
@@ -635,8 +633,7 @@ static int tcp_v6_parse_md5_keys(struct sock *sk, int optname,
prefixlen = ipv6_addr_v4mapped(&sin6->sin6_addr) ? 32 : 128;
}
- if (optname == TCP_MD5SIG_EXT && cmd.tcpm_ifindex &&
- cmd.tcpm_flags & TCP_MD5SIG_FLAG_IFINDEX) {
+ if (optname == TCP_MD5SIG_EXT && cmd.tcpm_ifindex && flags) {
struct net_device *dev;
rcu_read_lock();
@@ -671,7 +668,7 @@ static int tcp_v6_parse_md5_keys(struct sock *sk, int optname,
* See the comment in tcp_ao_add_cmd()
*/
if (tcp_ao_required(sk, addr, AF_INET,
- l3flag ? l3index : -1, false))
+ flags ? l3index : -1, false))
return -EKEYREJECTED;
return tcp_md5_do_add(sk, addr,
AF_INET, prefixlen, l3index, flags,
@@ -683,7 +680,7 @@ static int tcp_v6_parse_md5_keys(struct sock *sk, int optname,
/* Don't allow keys for peers that have a matching TCP-AO key.
* See the comment in tcp_ao_add_cmd()
*/
- if (tcp_ao_required(sk, addr, AF_INET6, l3flag ? l3index : -1, false))
+ if (tcp_ao_required(sk, addr, AF_INET6, flags ? l3index : -1, false))
return -EKEYREJECTED;
return tcp_md5_do_add(sk, addr, AF_INET6, prefixlen, l3index, flags,
--
2.48.1
Hi Geliang, On 10/08/2025 17:38, Geliang Tang wrote: > From: Geliang Tang <tanggeliang@kylinos.cn> > > The l3flag variable was redundant as it duplicated the value of > the 'flags' variable which already contains the interface index flag > status from cmd.tcpm_flags. This cleanup simplifies the code by > eliminating unnecessary variable duplication. > > Changes: > 1. Remove l3flag variable declarations > 2. Replace l3flag usage with existing 'flags' variable > 3. Maintain identical functionality with reduced complexity Thank you for sharing this, but because this is not related to MPTCP, do not hesitate to send that directly to the Netdev mailing list. Cheers, Matt -- Sponsored by the NGI0 Core fund.
Hi Geliang, Thank you for your modifications, that's great! Our CI did some validations and here is its report: - KVM Validation: normal: Success! ✅ - KVM Validation: debug: Unstable: 1 failed test(s): packetdrill_mp_capable 🔴 - KVM Validation: btf-normal (only bpftest_all): Success! ✅ - KVM Validation: btf-debug (only bpftest_all): Success! ✅ - Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/16863566400 Initiator: Patchew Applier Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/e7e90a01cbe5 Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=989719 If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.: $ cd [kernel source code] $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \ --pull always mptcp/mptcp-upstream-virtme-docker:latest \ auto-normal For more details: https://github.com/multipath-tcp/mptcp-upstream-virtme-docker Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-) Cheers, MPTCP GH Action bot Bot operated by Matthieu Baerts (NGI0 Core)
© 2016 - 2025 Red Hat, Inc.