Commit e1ef6832 authored by Geliang Tang's avatar Geliang Tang Committed by David S. Miller

mptcp: unify ADD_ADDR and ADD_ADDR6 suboptions writing

The length of ADD_ADDR6 is 12 octets longer than ADD_ADDR. That's the
only difference between them.

This patch dropped the duplicate code between ADD_ADDR and ADD_ADDR6
suboptions writing, and unify them into one.
Signed-off-by: default avatarGeliang Tang <geliangtang@gmail.com>
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6eb3d1e3
...@@ -1070,10 +1070,19 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, ...@@ -1070,10 +1070,19 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
} }
mp_capable_done: mp_capable_done:
if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) { if ((OPTION_MPTCP_ADD_ADDR
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
| OPTION_MPTCP_ADD_ADDR6
#endif
) & opts->suboptions) {
u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE; u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
u8 echo = MPTCP_ADDR_ECHO; u8 echo = MPTCP_ADDR_ECHO;
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions)
len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
#endif
if (opts->ahmac) { if (opts->ahmac) {
len += sizeof(opts->ahmac); len += sizeof(opts->ahmac);
echo = 0; echo = 0;
...@@ -1081,33 +1090,21 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, ...@@ -1081,33 +1090,21 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR, *ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
len, echo, opts->addr_id); len, echo, opts->addr_id);
memcpy((u8 *)ptr, (u8 *)&opts->addr.s_addr, 4); if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
ptr += 1; memcpy((u8 *)ptr, (u8 *)&opts->addr.s_addr, 4);
if (opts->ahmac) { ptr += 1;
put_unaligned_be64(opts->ahmac, ptr);
ptr += 2;
} }
}
#if IS_ENABLED(CONFIG_MPTCP_IPV6) #if IS_ENABLED(CONFIG_MPTCP_IPV6)
if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) { else if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) {
u8 len = TCPOLEN_MPTCP_ADD_ADDR6_BASE; memcpy((u8 *)ptr, opts->addr6.s6_addr, 16);
u8 echo = MPTCP_ADDR_ECHO; ptr += 4;
if (opts->ahmac) {
len += sizeof(opts->ahmac);
echo = 0;
} }
*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR, #endif
len, echo, opts->addr_id);
memcpy((u8 *)ptr, opts->addr6.s6_addr, 16);
ptr += 4;
if (opts->ahmac) { if (opts->ahmac) {
put_unaligned_be64(opts->ahmac, ptr); put_unaligned_be64(opts->ahmac, ptr);
ptr += 2; ptr += 2;
} }
} }
#endif
if (OPTION_MPTCP_RM_ADDR & opts->suboptions) { if (OPTION_MPTCP_RM_ADDR & opts->suboptions) {
*ptr++ = mptcp_option(MPTCPOPT_RM_ADDR, *ptr++ = mptcp_option(MPTCPOPT_RM_ADDR,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment