[PATCH mptcp-next v6 1/7] tcp: md5: remove redundant l3flag variable

Geliang Tang posted 7 patches 3 weeks, 1 day ago
[PATCH mptcp-next v6 1/7] tcp: md5: remove redundant l3flag variable
Posted by Geliang Tang 3 weeks, 1 day ago
From: Geliang Tang <tanggeliang@kylinos.cn>

The l3flag variable duplicates the value of 'flags' which already
contains TCP_MD5SIG_FLAG_IFINDEX status. Remove it to simplify code.

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 b7526a7888cb..2584ccae01e5 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1512,7 +1512,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))
@@ -1525,7 +1524,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) {
@@ -1534,8 +1532,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();
@@ -1563,7 +1560,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 7df21c1cba21..184b223fa0db 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.43.0