diff mbox series

[mptcp-next,2/3] Squash to "mptcp: use mptcp_addr_info in mptcp_options_received"

Message ID 20210322162132.2471823-2-matthieu.baerts@tessares.net
State Accepted, archived
Commit 4b727db7b8d81f2579fac007be9a58c52e9a4928
Delegated to: Matthieu Baerts
Headers show
Series [mptcp-next,1/3] Squash to "mptcp: use mptcp_addr_info in mptcp_out_options" | expand

Commit Message

Matthieu Baerts March 22, 2021, 4:21 p.m. UTC
Fix issues reported by sparse because we were doing non explicit casting
from __be16 to u16 and the opposite.

  net/mptcp/options.c:251:51: warning: incorrect type in assignment (different base types)
  net/mptcp/options.c:251:51:    expected restricted __be16 [usertype] port
  net/mptcp/options.c:251:51:    got unsigned short
  net/mptcp/options.c:261:51: warning: incorrect type in assignment (different base types)
  net/mptcp/options.c:261:51:    expected restricted __be16 [usertype] port
  net/mptcp/options.c:261:51:    got unsigned short
  net/mptcp/options.c:998:59: warning: incorrect type in argument 5 (different base types)
  net/mptcp/options.c:998:59:    expected unsigned short [usertype] port
  net/mptcp/options.c:998:59:    got restricted __be16 [usertype] port
  net/mptcp/options.c:1004:60: warning: incorrect type in argument 5 (different base types)
  net/mptcp/options.c:1004:60:    expected unsigned short [usertype] port
  net/mptcp/options.c:1004:60:    got restricted __be16 [usertype] port

Before the mentioned commit, we were using port in u16 in
mptcp_options_received, everything was OK.

Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
---
 net/mptcp/options.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Geliang Tang March 23, 2021, 4:02 a.m. UTC | #1
Hi Matt,

Please update the commit log too:

---
Since the port number became as a big-endian order now, use ntohs to
convert it before printing it out.
---

 ->

---
Since the port number became big-endian now, use htons to convert the
incoming port number to it. Also use ntohs to convert it when passing
it to add_addr_generate_hmac or printing it out.
---

Thanks.

-Geliang

Matthieu Baerts <matthieu.baerts@tessares.net> 于2021年3月23日周二 上午12:21写道:
>
> Fix issues reported by sparse because we were doing non explicit casting
> from __be16 to u16 and the opposite.
>
>   net/mptcp/options.c:251:51: warning: incorrect type in assignment (different base types)
>   net/mptcp/options.c:251:51:    expected restricted __be16 [usertype] port
>   net/mptcp/options.c:251:51:    got unsigned short
>   net/mptcp/options.c:261:51: warning: incorrect type in assignment (different base types)
>   net/mptcp/options.c:261:51:    expected restricted __be16 [usertype] port
>   net/mptcp/options.c:261:51:    got unsigned short
>   net/mptcp/options.c:998:59: warning: incorrect type in argument 5 (different base types)
>   net/mptcp/options.c:998:59:    expected unsigned short [usertype] port
>   net/mptcp/options.c:998:59:    got restricted __be16 [usertype] port
>   net/mptcp/options.c:1004:60: warning: incorrect type in argument 5 (different base types)
>   net/mptcp/options.c:1004:60:    expected unsigned short [usertype] port
>   net/mptcp/options.c:1004:60:    got restricted __be16 [usertype] port
>
> Before the mentioned commit, we were using port in u16 in
> mptcp_options_received, everything was OK.
>
> Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
> ---
>  net/mptcp/options.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> index 7fd40512df7f..43b85f2a5be1 100644
> --- a/net/mptcp/options.c
> +++ b/net/mptcp/options.c
> @@ -248,7 +248,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
>                         ptr += 4;
>                         if (opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT ||
>                             opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT) {
> -                               mp_opt->addr.port = get_unaligned_be16(ptr);
> +                               mp_opt->addr.port = cpu_to_be16(get_unaligned_be16(ptr));
>                                 ptr += 2;
>                         }
>                 }
> @@ -258,7 +258,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
>                         ptr += 16;
>                         if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT ||
>                             opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) {
> -                               mp_opt->addr.port = get_unaligned_be16(ptr);
> +                               mp_opt->addr.port = cpu_to_be16(get_unaligned_be16(ptr));
>                                 ptr += 2;
>                         }
>                 }
> @@ -995,13 +995,13 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk,
>                 hmac = add_addr_generate_hmac(msk->remote_key,
>                                               msk->local_key,
>                                               mp_opt->addr.id, &mp_opt->addr.addr,
> -                                             mp_opt->addr.port);
> +                                             be16_to_cpu(mp_opt->addr.port));
>  #if IS_ENABLED(CONFIG_MPTCP_IPV6)
>         else
>                 hmac = add_addr6_generate_hmac(msk->remote_key,
>                                                msk->local_key,
>                                                mp_opt->addr.id, &mp_opt->addr.addr6,
> -                                              mp_opt->addr.port);
> +                                              be16_to_cpu(mp_opt->addr.port));
>  #endif
>
>         pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n",
> --
> 2.30.2
>
diff mbox series

Patch

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 7fd40512df7f..43b85f2a5be1 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -248,7 +248,7 @@  static void mptcp_parse_option(const struct sk_buff *skb,
 			ptr += 4;
 			if (opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT ||
 			    opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT) {
-				mp_opt->addr.port = get_unaligned_be16(ptr);
+				mp_opt->addr.port = cpu_to_be16(get_unaligned_be16(ptr));
 				ptr += 2;
 			}
 		}
@@ -258,7 +258,7 @@  static void mptcp_parse_option(const struct sk_buff *skb,
 			ptr += 16;
 			if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT ||
 			    opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) {
-				mp_opt->addr.port = get_unaligned_be16(ptr);
+				mp_opt->addr.port = cpu_to_be16(get_unaligned_be16(ptr));
 				ptr += 2;
 			}
 		}
@@ -995,13 +995,13 @@  static bool add_addr_hmac_valid(struct mptcp_sock *msk,
 		hmac = add_addr_generate_hmac(msk->remote_key,
 					      msk->local_key,
 					      mp_opt->addr.id, &mp_opt->addr.addr,
-					      mp_opt->addr.port);
+					      be16_to_cpu(mp_opt->addr.port));
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
 	else
 		hmac = add_addr6_generate_hmac(msk->remote_key,
 					       msk->local_key,
 					       mp_opt->addr.id, &mp_opt->addr.addr6,
-					       mp_opt->addr.port);
+					       be16_to_cpu(mp_opt->addr.port));
 #endif
 
 	pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n",