Skip to content

Commit

Permalink
mptcp: unify ADD_ADDR and echo suboptions writing
Browse files Browse the repository at this point in the history
There are two differences between ADD_ADDR suboption and ADD_ADDR echo
suboption: The length of the former is 8 octets longer than the length
of the latter. The former's echo-flag is 0, and latter's echo-flag is 1.

This patch added two local variables, len and echo, to unify ADD_ADDR
and ADD_ADDR echo suboptions writing.

Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
  • Loading branch information
geliangtang authored and matttbe committed Nov 19, 2020
1 parent c77dbc7 commit 64db857
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions net/mptcp/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,15 +1068,16 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,

mp_capable_done:
if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
if (opts->ahmac)
*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
TCPOLEN_MPTCP_ADD_ADDR, 0,
opts->addr_id);
else
*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
TCPOLEN_MPTCP_ADD_ADDR_BASE,
MPTCP_ADDR_ECHO,
opts->addr_id);
u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
u8 echo = MPTCP_ADDR_ECHO;

if (opts->ahmac) {
len += sizeof(opts->ahmac);
echo = 0;
}

*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
len, echo, opts->addr_id);
memcpy((u8 *)ptr, (u8 *)&opts->addr.s_addr, 4);
ptr += 1;
if (opts->ahmac) {
Expand All @@ -1087,15 +1088,15 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,

#if IS_ENABLED(CONFIG_MPTCP_IPV6)
if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) {
if (opts->ahmac)
*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
TCPOLEN_MPTCP_ADD_ADDR6, 0,
opts->addr_id);
else
*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
TCPOLEN_MPTCP_ADD_ADDR6_BASE,
MPTCP_ADDR_ECHO,
opts->addr_id);
u8 len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
u8 echo = MPTCP_ADDR_ECHO;

if (opts->ahmac) {
len += sizeof(opts->ahmac);
echo = 0;
}
*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
len, echo, opts->addr_id);
memcpy((u8 *)ptr, opts->addr6.s6_addr, 16);
ptr += 4;
if (opts->ahmac) {
Expand Down

0 comments on commit 64db857

Please sign in to comment.