Commit 956c7831 authored by David S. Miller's avatar David S. Miller

Merge branch 'mptcp-next'

Mat Martineau says:

====================
mptcp: Cleanup, a new test case, and header trimming

Some more patches to include from the MPTCP tree:

Patches 1-6 refactor an address-related data structure and reduce some
duplicate code that handles IPv4 and IPv6 addresses.

Patch 7 adds a test case for the MPTCP netlink interface, passing a
specific ifindex to the kernel.

Patch 8 drops extra header options from IPv4 address echo packets,
improving consistency and testability between IPv4 and IPv6.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 0b35e0de 07f8252f
...@@ -41,20 +41,25 @@ struct mptcp_rm_list { ...@@ -41,20 +41,25 @@ struct mptcp_rm_list {
u8 nr; u8 nr;
}; };
struct mptcp_addr_info {
u8 id;
sa_family_t family;
__be16 port;
union {
struct in_addr addr;
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
struct in6_addr addr6;
#endif
};
};
struct mptcp_out_options { struct mptcp_out_options {
#if IS_ENABLED(CONFIG_MPTCP) #if IS_ENABLED(CONFIG_MPTCP)
u16 suboptions; u16 suboptions;
u64 sndr_key; u64 sndr_key;
u64 rcvr_key; u64 rcvr_key;
union {
struct in_addr addr;
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
struct in6_addr addr6;
#endif
};
u8 addr_id;
u16 port;
u64 ahmac; u64 ahmac;
struct mptcp_addr_info addr;
struct mptcp_rm_list rm_list; struct mptcp_rm_list rm_list;
u8 join_id; u8 join_id;
u8 backup; u8 backup;
......
...@@ -220,45 +220,45 @@ static void mptcp_parse_option(const struct sk_buff *skb, ...@@ -220,45 +220,45 @@ static void mptcp_parse_option(const struct sk_buff *skb,
if (!mp_opt->echo) { if (!mp_opt->echo) {
if (opsize == TCPOLEN_MPTCP_ADD_ADDR || if (opsize == TCPOLEN_MPTCP_ADD_ADDR ||
opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT) opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT)
mp_opt->family = MPTCP_ADDR_IPVERSION_4; mp_opt->addr.family = AF_INET;
#if IS_ENABLED(CONFIG_MPTCP_IPV6) #if IS_ENABLED(CONFIG_MPTCP_IPV6)
else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6 || else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6 ||
opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT) opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT)
mp_opt->family = MPTCP_ADDR_IPVERSION_6; mp_opt->addr.family = AF_INET6;
#endif #endif
else else
break; break;
} else { } else {
if (opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE || if (opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE ||
opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT) opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT)
mp_opt->family = MPTCP_ADDR_IPVERSION_4; mp_opt->addr.family = AF_INET;
#if IS_ENABLED(CONFIG_MPTCP_IPV6) #if IS_ENABLED(CONFIG_MPTCP_IPV6)
else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE || else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE ||
opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT)
mp_opt->family = MPTCP_ADDR_IPVERSION_6; mp_opt->addr.family = AF_INET6;
#endif #endif
else else
break; break;
} }
mp_opt->add_addr = 1; mp_opt->add_addr = 1;
mp_opt->addr_id = *ptr++; mp_opt->addr.id = *ptr++;
if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) { if (mp_opt->addr.family == AF_INET) {
memcpy((u8 *)&mp_opt->addr.s_addr, (u8 *)ptr, 4); memcpy((u8 *)&mp_opt->addr.addr.s_addr, (u8 *)ptr, 4);
ptr += 4; ptr += 4;
if (opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT || if (opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT ||
opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT) { opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT) {
mp_opt->port = get_unaligned_be16(ptr); mp_opt->addr.port = htons(get_unaligned_be16(ptr));
ptr += 2; ptr += 2;
} }
} }
#if IS_ENABLED(CONFIG_MPTCP_IPV6) #if IS_ENABLED(CONFIG_MPTCP_IPV6)
else { else {
memcpy(mp_opt->addr6.s6_addr, (u8 *)ptr, 16); memcpy(mp_opt->addr.addr6.s6_addr, (u8 *)ptr, 16);
ptr += 16; ptr += 16;
if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT || if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT ||
opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) { opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) {
mp_opt->port = get_unaligned_be16(ptr); mp_opt->addr.port = htons(get_unaligned_be16(ptr));
ptr += 2; ptr += 2;
} }
} }
...@@ -268,8 +268,8 @@ static void mptcp_parse_option(const struct sk_buff *skb, ...@@ -268,8 +268,8 @@ static void mptcp_parse_option(const struct sk_buff *skb,
ptr += 8; ptr += 8;
} }
pr_debug("ADD_ADDR%s: id=%d, ahmac=%llu, echo=%d, port=%d", pr_debug("ADD_ADDR%s: id=%d, ahmac=%llu, echo=%d, port=%d",
(mp_opt->family == MPTCP_ADDR_IPVERSION_6) ? "6" : "", (mp_opt->addr.family == AF_INET6) ? "6" : "",
mp_opt->addr_id, mp_opt->ahmac, mp_opt->echo, mp_opt->port); mp_opt->addr.id, mp_opt->ahmac, mp_opt->echo, ntohs(mp_opt->addr.port));
break; break;
case MPTCPOPT_RM_ADDR: case MPTCPOPT_RM_ADDR:
...@@ -335,7 +335,7 @@ void mptcp_get_options(const struct sk_buff *skb, ...@@ -335,7 +335,7 @@ void mptcp_get_options(const struct sk_buff *skb,
mp_opt->add_addr = 0; mp_opt->add_addr = 0;
mp_opt->ahmac = 0; mp_opt->ahmac = 0;
mp_opt->fastclose = 0; mp_opt->fastclose = 0;
mp_opt->port = 0; mp_opt->addr.port = 0;
mp_opt->rm_addr = 0; mp_opt->rm_addr = 0;
mp_opt->dss = 0; mp_opt->dss = 0;
mp_opt->mp_prio = 0; mp_opt->mp_prio = 0;
...@@ -583,39 +583,32 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb, ...@@ -583,39 +583,32 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
return true; return true;
} }
static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id, static u64 add_addr_generate_hmac(u64 key1, u64 key2,
struct in_addr *addr, u16 port) struct mptcp_addr_info *addr)
{
u8 hmac[SHA256_DIGEST_SIZE];
u8 msg[7];
msg[0] = addr_id;
memcpy(&msg[1], &addr->s_addr, 4);
msg[5] = port >> 8;
msg[6] = port & 0xFF;
mptcp_crypto_hmac_sha(key1, key2, msg, 7, hmac);
return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]);
}
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 addr_id,
struct in6_addr *addr, u16 port)
{ {
u16 port = ntohs(addr->port);
u8 hmac[SHA256_DIGEST_SIZE]; u8 hmac[SHA256_DIGEST_SIZE];
u8 msg[19]; u8 msg[19];
int i = 0;
msg[0] = addr_id; msg[i++] = addr->id;
memcpy(&msg[1], &addr->s6_addr, 16); if (addr->family == AF_INET) {
msg[17] = port >> 8; memcpy(&msg[i], &addr->addr.s_addr, 4);
msg[18] = port & 0xFF; i += 4;
}
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
else if (addr->family == AF_INET6) {
memcpy(&msg[i], &addr->addr6.s6_addr, 16);
i += 16;
}
#endif
msg[i++] = port >> 8;
msg[i++] = port & 0xFF;
mptcp_crypto_hmac_sha(key1, key2, msg, 19, hmac); mptcp_crypto_hmac_sha(key1, key2, msg, i, hmac);
return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]); return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]);
} }
#endif
static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *skb, static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *skb,
unsigned int *size, unsigned int *size,
...@@ -626,13 +619,13 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff * ...@@ -626,13 +619,13 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
struct mptcp_sock *msk = mptcp_sk(subflow->conn); struct mptcp_sock *msk = mptcp_sk(subflow->conn);
bool drop_other_suboptions = false; bool drop_other_suboptions = false;
unsigned int opt_size = *size; unsigned int opt_size = *size;
struct mptcp_addr_info saddr;
bool echo; bool echo;
bool port; bool port;
int len; int len;
if ((mptcp_pm_should_add_signal_ipv6(msk) || if ((mptcp_pm_should_add_signal_ipv6(msk) ||
mptcp_pm_should_add_signal_port(msk)) && mptcp_pm_should_add_signal_port(msk) ||
mptcp_pm_should_add_signal_echo(msk)) &&
skb && skb_is_tcp_pure_ack(skb)) { skb && skb_is_tcp_pure_ack(skb)) {
pr_debug("drop other suboptions"); pr_debug("drop other suboptions");
opts->suboptions = 0; opts->suboptions = 0;
...@@ -643,45 +636,24 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff * ...@@ -643,45 +636,24 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
} }
if (!mptcp_pm_should_add_signal(msk) || if (!mptcp_pm_should_add_signal(msk) ||
!(mptcp_pm_add_addr_signal(msk, remaining, &saddr, &echo, &port))) !(mptcp_pm_add_addr_signal(msk, remaining, &opts->addr, &echo, &port)))
return false; return false;
len = mptcp_add_addr_len(saddr.family, echo, port); len = mptcp_add_addr_len(opts->addr.family, echo, port);
if (remaining < len) if (remaining < len)
return false; return false;
*size = len; *size = len;
if (drop_other_suboptions) if (drop_other_suboptions)
*size -= opt_size; *size -= opt_size;
opts->addr_id = saddr.id; opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
if (port) if (!echo) {
opts->port = ntohs(saddr.port); opts->ahmac = add_addr_generate_hmac(msk->local_key,
if (saddr.family == AF_INET) { msk->remote_key,
opts->suboptions |= OPTION_MPTCP_ADD_ADDR; &opts->addr);
opts->addr = saddr.addr;
if (!echo) {
opts->ahmac = add_addr_generate_hmac(msk->local_key,
msk->remote_key,
opts->addr_id,
&opts->addr,
opts->port);
}
} }
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
else if (saddr.family == AF_INET6) {
opts->suboptions |= OPTION_MPTCP_ADD_ADDR6;
opts->addr6 = saddr.addr6;
if (!echo) {
opts->ahmac = add_addr6_generate_hmac(msk->local_key,
msk->remote_key,
opts->addr_id,
&opts->addr6,
opts->port);
}
}
#endif
pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d", pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d",
opts->addr_id, opts->ahmac, echo, opts->port); opts->addr.id, opts->ahmac, echo, ntohs(opts->addr.port));
return true; return true;
} }
...@@ -998,18 +970,9 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk, ...@@ -998,18 +970,9 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk,
if (mp_opt->echo) if (mp_opt->echo)
return true; return true;
if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) hmac = add_addr_generate_hmac(msk->remote_key,
hmac = add_addr_generate_hmac(msk->remote_key, msk->local_key,
msk->local_key, &mp_opt->addr);
mp_opt->addr_id, &mp_opt->addr,
mp_opt->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->addr6,
mp_opt->port);
#endif
pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n", pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n",
msk, (unsigned long long)hmac, msk, (unsigned long long)hmac,
...@@ -1050,30 +1013,16 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) ...@@ -1050,30 +1013,16 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
} }
if (mp_opt.add_addr && add_addr_hmac_valid(msk, &mp_opt)) { if (mp_opt.add_addr && add_addr_hmac_valid(msk, &mp_opt)) {
struct mptcp_addr_info addr;
addr.port = htons(mp_opt.port);
addr.id = mp_opt.addr_id;
if (mp_opt.family == MPTCP_ADDR_IPVERSION_4) {
addr.family = AF_INET;
addr.addr = mp_opt.addr;
}
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
else if (mp_opt.family == MPTCP_ADDR_IPVERSION_6) {
addr.family = AF_INET6;
addr.addr6 = mp_opt.addr6;
}
#endif
if (!mp_opt.echo) { if (!mp_opt.echo) {
mptcp_pm_add_addr_received(msk, &addr); mptcp_pm_add_addr_received(msk, &mp_opt.addr);
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDR); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDR);
} else { } else {
mptcp_pm_add_addr_echoed(msk, &addr); mptcp_pm_add_addr_echoed(msk, &mp_opt.addr);
mptcp_pm_del_add_timer(msk, &addr); mptcp_pm_del_add_timer(msk, &mp_opt.addr);
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADD); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADD);
} }
if (mp_opt.port) if (mp_opt.addr.port)
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_PORTADD); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_PORTADD);
mp_opt.add_addr = 0; mp_opt.add_addr = 0;
...@@ -1204,20 +1153,16 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, ...@@ -1204,20 +1153,16 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
} }
mp_capable_done: mp_capable_done:
if ((OPTION_MPTCP_ADD_ADDR if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
#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 IS_ENABLED(CONFIG_MPTCP_IPV6)
if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) if (opts->addr.family == AF_INET6)
len = TCPOLEN_MPTCP_ADD_ADDR6_BASE; len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
#endif #endif
if (opts->port) if (opts->addr.port)
len += TCPOLEN_MPTCP_PORT_LEN; len += TCPOLEN_MPTCP_PORT_LEN;
if (opts->ahmac) { if (opts->ahmac) {
...@@ -1226,28 +1171,30 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, ...@@ -1226,28 +1171,30 @@ 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);
if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) { if (opts->addr.family == AF_INET) {
memcpy((u8 *)ptr, (u8 *)&opts->addr.s_addr, 4); memcpy((u8 *)ptr, (u8 *)&opts->addr.addr.s_addr, 4);
ptr += 1; ptr += 1;
} }
#if IS_ENABLED(CONFIG_MPTCP_IPV6) #if IS_ENABLED(CONFIG_MPTCP_IPV6)
else if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) { else if (opts->addr.family == AF_INET6) {
memcpy((u8 *)ptr, opts->addr6.s6_addr, 16); memcpy((u8 *)ptr, opts->addr.addr6.s6_addr, 16);
ptr += 4; ptr += 4;
} }
#endif #endif
if (!opts->port) { if (!opts->addr.port) {
if (opts->ahmac) { if (opts->ahmac) {
put_unaligned_be64(opts->ahmac, ptr); put_unaligned_be64(opts->ahmac, ptr);
ptr += 2; ptr += 2;
} }
} else { } else {
u16 port = ntohs(opts->addr.port);
if (opts->ahmac) { if (opts->ahmac) {
u8 *bptr = (u8 *)ptr; u8 *bptr = (u8 *)ptr;
put_unaligned_be16(opts->port, bptr); put_unaligned_be16(port, bptr);
bptr += 2; bptr += 2;
put_unaligned_be64(opts->ahmac, bptr); put_unaligned_be64(opts->ahmac, bptr);
bptr += 8; bptr += 8;
...@@ -1256,7 +1203,7 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, ...@@ -1256,7 +1203,7 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
ptr += 3; ptr += 3;
} else { } else {
put_unaligned_be32(opts->port << 16 | put_unaligned_be32(port << 16 |
TCPOPT_NOP << 8 | TCPOPT_NOP << 8 |
TCPOPT_NOP, ptr); TCPOPT_NOP, ptr);
ptr += 1; ptr += 1;
......
...@@ -25,6 +25,8 @@ static int pm_nl_pernet_id; ...@@ -25,6 +25,8 @@ static int pm_nl_pernet_id;
struct mptcp_pm_addr_entry { struct mptcp_pm_addr_entry {
struct list_head list; struct list_head list;
struct mptcp_addr_info addr; struct mptcp_addr_info addr;
u8 flags;
int ifindex;
struct rcu_head rcu; struct rcu_head rcu;
struct socket *lsk; struct socket *lsk;
}; };
...@@ -168,7 +170,7 @@ select_local_address(const struct pm_nl_pernet *pernet, ...@@ -168,7 +170,7 @@ select_local_address(const struct pm_nl_pernet *pernet,
rcu_read_lock(); rcu_read_lock();
__mptcp_flush_join_list(msk); __mptcp_flush_join_list(msk);
list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
if (!(entry->addr.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)) if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW))
continue; continue;
if (entry->addr.family != sk->sk_family) { if (entry->addr.family != sk->sk_family) {
...@@ -206,7 +208,7 @@ select_signal_address(struct pm_nl_pernet *pernet, unsigned int pos) ...@@ -206,7 +208,7 @@ select_signal_address(struct pm_nl_pernet *pernet, unsigned int pos)
* can lead to additional addresses not being announced. * can lead to additional addresses not being announced.
*/ */
list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
if (!(entry->addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
continue; continue;
if (i++ == pos) { if (i++ == pos) {
ret = entry; ret = entry;
...@@ -459,7 +461,8 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) ...@@ -459,7 +461,8 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
check_work_pending(msk); check_work_pending(msk);
remote_address((struct sock_common *)sk, &remote); remote_address((struct sock_common *)sk, &remote);
spin_unlock_bh(&msk->pm.lock); spin_unlock_bh(&msk->pm.lock);
__mptcp_subflow_connect(sk, &local->addr, &remote); __mptcp_subflow_connect(sk, &local->addr, &remote,
local->flags, local->ifindex);
spin_lock_bh(&msk->pm.lock); spin_lock_bh(&msk->pm.lock);
return; return;
} }
...@@ -514,7 +517,7 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) ...@@ -514,7 +517,7 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
local.family = remote.family; local.family = remote.family;
spin_unlock_bh(&msk->pm.lock); spin_unlock_bh(&msk->pm.lock);
__mptcp_subflow_connect(sk, &local, &remote); __mptcp_subflow_connect(sk, &local, &remote, 0, 0);
spin_lock_bh(&msk->pm.lock); spin_lock_bh(&msk->pm.lock);
add_addr_echo: add_addr_echo:
...@@ -683,7 +686,7 @@ void mptcp_pm_nl_work(struct mptcp_sock *msk) ...@@ -683,7 +686,7 @@ void mptcp_pm_nl_work(struct mptcp_sock *msk)
static bool address_use_port(struct mptcp_pm_addr_entry *entry) static bool address_use_port(struct mptcp_pm_addr_entry *entry)
{ {
return (entry->addr.flags & return (entry->flags &
(MPTCP_PM_ADDR_FLAG_SIGNAL | MPTCP_PM_ADDR_FLAG_SUBFLOW)) == (MPTCP_PM_ADDR_FLAG_SIGNAL | MPTCP_PM_ADDR_FLAG_SUBFLOW)) ==
MPTCP_PM_ADDR_FLAG_SIGNAL; MPTCP_PM_ADDR_FLAG_SIGNAL;
} }
...@@ -735,11 +738,11 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, ...@@ -735,11 +738,11 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
if (entry->addr.id > pernet->next_id) if (entry->addr.id > pernet->next_id)
pernet->next_id = entry->addr.id; pernet->next_id = entry->addr.id;
if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) { if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
addr_max = pernet->add_addr_signal_max; addr_max = pernet->add_addr_signal_max;
WRITE_ONCE(pernet->add_addr_signal_max, addr_max + 1); WRITE_ONCE(pernet->add_addr_signal_max, addr_max + 1);
} }
if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) { if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
addr_max = pernet->local_addr_max; addr_max = pernet->local_addr_max;
WRITE_ONCE(pernet->local_addr_max, addr_max + 1); WRITE_ONCE(pernet->local_addr_max, addr_max + 1);
} }
...@@ -841,10 +844,10 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) ...@@ -841,10 +844,10 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
return -ENOMEM; return -ENOMEM;
entry->addr = skc_local; entry->addr = skc_local;
entry->addr.ifindex = 0;
entry->addr.flags = 0;
entry->addr.id = 0; entry->addr.id = 0;
entry->addr.port = 0; entry->addr.port = 0;
entry->ifindex = 0;
entry->flags = 0;
entry->lsk = NULL; entry->lsk = NULL;
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry); ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
if (ret < 0) if (ret < 0)
...@@ -959,14 +962,14 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info, ...@@ -959,14 +962,14 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX]) { if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX]) {
u32 val = nla_get_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]); u32 val = nla_get_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]);
entry->addr.ifindex = val; entry->ifindex = val;
} }
if (tb[MPTCP_PM_ADDR_ATTR_ID]) if (tb[MPTCP_PM_ADDR_ATTR_ID])
entry->addr.id = nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]); entry->addr.id = nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]);
if (tb[MPTCP_PM_ADDR_ATTR_FLAGS]) if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
entry->addr.flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]); entry->flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
if (tb[MPTCP_PM_ADDR_ATTR_PORT]) if (tb[MPTCP_PM_ADDR_ATTR_PORT])
entry->addr.port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT])); entry->addr.port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
...@@ -1218,11 +1221,11 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info) ...@@ -1218,11 +1221,11 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
spin_unlock_bh(&pernet->lock); spin_unlock_bh(&pernet->lock);
return -EINVAL; return -EINVAL;
} }
if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) { if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
addr_max = pernet->add_addr_signal_max; addr_max = pernet->add_addr_signal_max;
WRITE_ONCE(pernet->add_addr_signal_max, addr_max - 1); WRITE_ONCE(pernet->add_addr_signal_max, addr_max - 1);
} }
if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) { if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
addr_max = pernet->local_addr_max; addr_max = pernet->local_addr_max;
WRITE_ONCE(pernet->local_addr_max, addr_max - 1); WRITE_ONCE(pernet->local_addr_max, addr_max - 1);
} }
...@@ -1338,10 +1341,10 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb, ...@@ -1338,10 +1341,10 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb,
goto nla_put_failure; goto nla_put_failure;
if (nla_put_u8(skb, MPTCP_PM_ADDR_ATTR_ID, addr->id)) if (nla_put_u8(skb, MPTCP_PM_ADDR_ATTR_ID, addr->id))
goto nla_put_failure; goto nla_put_failure;
if (nla_put_u32(skb, MPTCP_PM_ADDR_ATTR_FLAGS, entry->addr.flags)) if (nla_put_u32(skb, MPTCP_PM_ADDR_ATTR_FLAGS, entry->flags))
goto nla_put_failure; goto nla_put_failure;
if (entry->addr.ifindex && if (entry->ifindex &&
nla_put_s32(skb, MPTCP_PM_ADDR_ATTR_IF_IDX, entry->addr.ifindex)) nla_put_s32(skb, MPTCP_PM_ADDR_ATTR_IF_IDX, entry->ifindex))
goto nla_put_failure; goto nla_put_failure;
if (addr->family == AF_INET && if (addr->family == AF_INET &&
...@@ -1569,7 +1572,7 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info) ...@@ -1569,7 +1572,7 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (addr.addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP) if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
bkup = 1; bkup = 1;
list_for_each_entry(entry, &pernet->local_addr_list, list) { list_for_each_entry(entry, &pernet->local_addr_list, list) {
...@@ -1579,9 +1582,9 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info) ...@@ -1579,9 +1582,9 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)
return ret; return ret;
if (bkup) if (bkup)
entry->addr.flags |= MPTCP_PM_ADDR_FLAG_BACKUP; entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
else else
entry->addr.flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP; entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP;
} }
} }
......
...@@ -22,11 +22,10 @@ ...@@ -22,11 +22,10 @@
#define OPTION_MPTCP_MPJ_SYNACK BIT(4) #define OPTION_MPTCP_MPJ_SYNACK BIT(4)
#define OPTION_MPTCP_MPJ_ACK BIT(5) #define OPTION_MPTCP_MPJ_ACK BIT(5)
#define OPTION_MPTCP_ADD_ADDR BIT(6) #define OPTION_MPTCP_ADD_ADDR BIT(6)
#define OPTION_MPTCP_ADD_ADDR6 BIT(7) #define OPTION_MPTCP_RM_ADDR BIT(7)
#define OPTION_MPTCP_RM_ADDR BIT(8) #define OPTION_MPTCP_FASTCLOSE BIT(8)
#define OPTION_MPTCP_FASTCLOSE BIT(9) #define OPTION_MPTCP_PRIO BIT(9)
#define OPTION_MPTCP_PRIO BIT(10) #define OPTION_MPTCP_RST BIT(10)
#define OPTION_MPTCP_RST BIT(11)
/* MPTCP option subtypes */ /* MPTCP option subtypes */
#define MPTCPOPT_MP_CAPABLE 0 #define MPTCPOPT_MP_CAPABLE 0
...@@ -91,8 +90,6 @@ ...@@ -91,8 +90,6 @@
/* MPTCP ADD_ADDR flags */ /* MPTCP ADD_ADDR flags */
#define MPTCP_ADDR_ECHO BIT(0) #define MPTCP_ADDR_ECHO BIT(0)
#define MPTCP_ADDR_IPVERSION_4 4
#define MPTCP_ADDR_IPVERSION_6 6
/* MPTCP MP_PRIO flags */ /* MPTCP MP_PRIO flags */
#define MPTCP_PRIO_BKUP BIT(0) #define MPTCP_PRIO_BKUP BIT(0)
...@@ -134,7 +131,6 @@ struct mptcp_options_received { ...@@ -134,7 +131,6 @@ struct mptcp_options_received {
add_addr : 1, add_addr : 1,
rm_addr : 1, rm_addr : 1,
mp_prio : 1, mp_prio : 1,
family : 4,
echo : 1, echo : 1,
backup : 1; backup : 1;
u32 token; u32 token;
...@@ -149,16 +145,9 @@ struct mptcp_options_received { ...@@ -149,16 +145,9 @@ struct mptcp_options_received {
ack64:1, ack64:1,
mpc_map:1, mpc_map:1,
__unused:2; __unused:2;
u8 addr_id; struct mptcp_addr_info addr;
struct mptcp_rm_list rm_list; struct mptcp_rm_list rm_list;
union {
struct in_addr addr;
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
struct in6_addr addr6;
#endif
};
u64 ahmac; u64 ahmac;
u16 port;
u8 reset_reason:4; u8 reset_reason:4;
u8 reset_transient:1; u8 reset_transient:1;
}; };
...@@ -169,20 +158,6 @@ static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field) ...@@ -169,20 +158,6 @@ static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field)
((nib & 0xF) << 8) | field); ((nib & 0xF) << 8) | field);
} }
struct mptcp_addr_info {
sa_family_t family;
__be16 port;
u8 id;
u8 flags;
int ifindex;
union {
struct in_addr addr;
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
struct in6_addr addr6;
#endif
};
};
enum mptcp_pm_status { enum mptcp_pm_status {
MPTCP_PM_ADD_ADDR_RECEIVED, MPTCP_PM_ADD_ADDR_RECEIVED,
MPTCP_PM_ADD_ADDR_SEND_ACK, MPTCP_PM_ADD_ADDR_SEND_ACK,
...@@ -557,7 +532,8 @@ struct socket *__mptcp_nmpc_socket(const struct mptcp_sock *msk); ...@@ -557,7 +532,8 @@ struct socket *__mptcp_nmpc_socket(const struct mptcp_sock *msk);
/* called with sk socket lock held */ /* called with sk socket lock held */
int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
const struct mptcp_addr_info *remote); const struct mptcp_addr_info *remote,
u8 flags, int ifindex);
int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock); int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
void mptcp_info2sockaddr(const struct mptcp_addr_info *info, void mptcp_info2sockaddr(const struct mptcp_addr_info *info,
struct sockaddr_storage *addr, struct sockaddr_storage *addr,
......
...@@ -1256,7 +1256,8 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info *info, ...@@ -1256,7 +1256,8 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info *info,
} }
int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
const struct mptcp_addr_info *remote) const struct mptcp_addr_info *remote,
u8 flags, int ifindex)
{ {
struct mptcp_sock *msk = mptcp_sk(sk); struct mptcp_sock *msk = mptcp_sk(sk);
struct mptcp_subflow_context *subflow; struct mptcp_subflow_context *subflow;
...@@ -1300,7 +1301,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, ...@@ -1300,7 +1301,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
if (addr.ss_family == AF_INET6) if (addr.ss_family == AF_INET6)
addrlen = sizeof(struct sockaddr_in6); addrlen = sizeof(struct sockaddr_in6);
#endif #endif
ssk->sk_bound_dev_if = loc->ifindex; ssk->sk_bound_dev_if = ifindex;
err = kernel_bind(sf, (struct sockaddr *)&addr, addrlen); err = kernel_bind(sf, (struct sockaddr *)&addr, addrlen);
if (err) if (err)
goto failed; goto failed;
...@@ -1312,7 +1313,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, ...@@ -1312,7 +1313,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
subflow->local_id = local_id; subflow->local_id = local_id;
subflow->remote_id = remote_id; subflow->remote_id = remote_id;
subflow->request_join = 1; subflow->request_join = 1;
subflow->request_bkup = !!(loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP); subflow->request_bkup = !!(flags & MPTCP_PM_ADDR_FLAG_BACKUP);
mptcp_info2sockaddr(remote, &addr, ssk->sk_family); mptcp_info2sockaddr(remote, &addr, ssk->sk_family);
mptcp_add_pending_subflow(msk, subflow); mptcp_add_pending_subflow(msk, subflow);
......
...@@ -777,6 +777,14 @@ subflows_tests() ...@@ -777,6 +777,14 @@ subflows_tests()
ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
run_tests $ns1 $ns2 10.0.1.1 run_tests $ns1 $ns2 10.0.1.1
chk_join_nr "multiple subflows, limited by server" 2 2 1 chk_join_nr "multiple subflows, limited by server" 2 2 1
# single subflow, dev
reset
ip netns exec $ns1 ./pm_nl_ctl limits 0 1
ip netns exec $ns2 ./pm_nl_ctl limits 0 1
ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow dev ns2eth3
run_tests $ns1 $ns2 10.0.1.1
chk_join_nr "single subflow, dev" 1 1 1
} }
signal_address_tests() signal_address_tests()
......
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