Skip to content

Commit

Permalink
mptcp: add the outgoing ADD_ADDR port support
Browse files Browse the repository at this point in the history
This patch added a new add_addr_signal type named MPTCP_ADD_ADDR_PORT,
to identify it is an address with port to be added.

It also added a new parameter 'port' for both mptcp_add_addr_len and
mptcp_pm_add_addr_signal.

In mptcp_established_options_add_addr, we check whether the announced
address is added with port. If it is, we put this port number to
mptcp_out_options's port field.

Reviewed-by: Mat Martineau <[email protected]>
Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
geliangtang authored and jenkins-tessares committed Nov 20, 2020
1 parent 3820b27 commit 935c768
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
10 changes: 7 additions & 3 deletions net/mptcp/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
unsigned int opt_size = *size;
struct mptcp_addr_info saddr;
bool echo;
bool port;
int len;

if (mptcp_pm_should_add_signal_ipv6(msk) &&
Expand All @@ -598,17 +599,19 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
}

if (!mptcp_pm_should_add_signal(msk) ||
!(mptcp_pm_add_addr_signal(msk, remaining, &saddr, &echo)))
!(mptcp_pm_add_addr_signal(msk, remaining, &saddr, &echo, &port)))
return false;

len = mptcp_add_addr_len(saddr.family, echo);
len = mptcp_add_addr_len(saddr.family, echo, port);
if (remaining < len)
return false;

*size = len;
if (drop_other_suboptions)
*size -= opt_size;
opts->addr_id = saddr.id;
if (port)
opts->port = ntohs(saddr.port);
if (saddr.family == AF_INET) {
opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
opts->addr = saddr.addr;
Expand All @@ -631,7 +634,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
}
}
#endif
pr_debug("addr_id=%d, ahmac=%llu, echo=%d", opts->addr_id, opts->ahmac, echo);
pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d",
opts->addr_id, opts->ahmac, echo, opts->port);

return true;
}
Expand Down
5 changes: 3 additions & 2 deletions net/mptcp/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id)
/* path manager helpers */

bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
struct mptcp_addr_info *saddr, bool *echo)
struct mptcp_addr_info *saddr, bool *echo, bool *port)
{
int ret = false;

Expand All @@ -199,8 +199,9 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
goto out_unlock;

*echo = mptcp_pm_should_add_signal_echo(msk);
*port = mptcp_pm_should_add_signal_port(msk);

if (remaining < mptcp_add_addr_len(msk->pm.local.family, *echo))
if (remaining < mptcp_add_addr_len(msk->pm.local.family, *echo, *port))
goto out_unlock;

*saddr = msk->pm.local;
Expand Down
12 changes: 10 additions & 2 deletions net/mptcp/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ enum mptcp_add_addr_status {
MPTCP_ADD_ADDR_SIGNAL,
MPTCP_ADD_ADDR_ECHO,
MPTCP_ADD_ADDR_IPV6,
MPTCP_ADD_ADDR_PORT,
};

struct mptcp_pm_data {
Expand Down Expand Up @@ -547,25 +548,32 @@ static inline bool mptcp_pm_should_add_signal_ipv6(struct mptcp_sock *msk)
return READ_ONCE(msk->pm.add_addr_signal) & BIT(MPTCP_ADD_ADDR_IPV6);
}

static inline bool mptcp_pm_should_add_signal_port(struct mptcp_sock *msk)
{
return READ_ONCE(msk->pm.add_addr_signal) & BIT(MPTCP_ADD_ADDR_PORT);
}

static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
{
return READ_ONCE(msk->pm.rm_addr_signal);
}

static inline unsigned int mptcp_add_addr_len(int family, bool echo)
static inline unsigned int mptcp_add_addr_len(int family, bool echo, bool port)
{
u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;

if (family == AF_INET6)
len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
if (!echo)
len += TCPOLEN_MPTCP_ADD_ADDR_HMAC;
if (port)
len += TCPOLEN_MPTCP_PORT_LEN;

return len;
}

bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
struct mptcp_addr_info *saddr, bool *echo);
struct mptcp_addr_info *saddr, bool *echo, bool *port);
bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
u8 *rm_id);
int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
Expand Down

0 comments on commit 935c768

Please sign in to comment.