Skip to content

Commit

Permalink
mptcp: add port support for ADD_ADDR suboption writing
Browse files Browse the repository at this point in the history
In rfc8684, the length of ADD_ADDR suboption with IPv4 address and port
is 18 octets, but mptcp_write_options is 32-bit aligned, so we need to
pad it to 20 octets. All the other port related option lengths need to
be added up 2 octets similarly.

This patch added a new field 'port' in mptcp_out_options. When this
field is set with a port number, we need to add up 4 octets for the
ADD_ADDR suboption, and put the port number into the suboption.

Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
  • Loading branch information
geliangtang authored and jenkins-tessares committed Dec 9, 2020
1 parent 4021cd8 commit 1690597
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/net/mptcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct mptcp_out_options {
#endif
};
u8 addr_id;
u16 port;
u64 ahmac;
u8 rm_id;
u8 join_id;
Expand Down
30 changes: 27 additions & 3 deletions net/mptcp/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,9 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
#endif

if (opts->port)
len += TCPOLEN_MPTCP_PORT_LEN;

if (opts->ahmac) {
len += sizeof(opts->ahmac);
echo = 0;
Expand All @@ -1105,9 +1108,30 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
ptr += 4;
}
#endif
if (opts->ahmac) {
put_unaligned_be64(opts->ahmac, ptr);
ptr += 2;

if (!opts->port) {
if (opts->ahmac) {
put_unaligned_be64(opts->ahmac, ptr);
ptr += 2;
}
} else {
if (opts->ahmac) {
u8 *bptr = (u8 *)ptr;

put_unaligned_be16(opts->port, bptr);
bptr += 2;
put_unaligned_be64(opts->ahmac, bptr);
bptr += 8;
put_unaligned_be16(TCPOPT_NOP << 8 |
TCPOPT_NOP, bptr);

ptr += 3;
} else {
put_unaligned_be32(opts->port << 16 |
TCPOPT_NOP << 8 |
TCPOPT_NOP, ptr);
ptr += 1;
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions net/mptcp/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
#define TCPOLEN_MPTCP_DSS_MAP64 14
#define TCPOLEN_MPTCP_DSS_CHECKSUM 2
#define TCPOLEN_MPTCP_ADD_ADDR 16
#define TCPOLEN_MPTCP_ADD_ADDR_PORT 18
#define TCPOLEN_MPTCP_ADD_ADDR_PORT 20
#define TCPOLEN_MPTCP_ADD_ADDR_BASE 8
#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 10
#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 12
#define TCPOLEN_MPTCP_ADD_ADDR6 28
#define TCPOLEN_MPTCP_ADD_ADDR6_PORT 30
#define TCPOLEN_MPTCP_ADD_ADDR6_PORT 32
#define TCPOLEN_MPTCP_ADD_ADDR6_BASE 20
#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 22
#define TCPOLEN_MPTCP_PORT_LEN 2
#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 24
#define TCPOLEN_MPTCP_PORT_LEN 4
#define TCPOLEN_MPTCP_RM_ADDR_BASE 4

/* MPTCP MP_JOIN flags */
Expand Down

0 comments on commit 1690597

Please sign in to comment.