Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
mptcp: allow to fix the source port when establishing a subflow
Browse files Browse the repository at this point in the history
By default, when establishing a subflow the source port is selected
randomly. This patch allows path managers to specify a source port to
use when establishing a subflow by calling __mptcp_init*_subsocket()
instead of mptcp_init*_subsocket() (which behavior is unchanged).

__mptcp_init*_subsocket() also returns the newly created socket if
there were no errors.

Signed-off-by: Gregory Detal <gregory.detal@tessares.net>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Christoph Paasch <cpaasch@apple.com>
  • Loading branch information
gdetal authored and cpaasch committed Jan 23, 2019
1 parent ed30364 commit 68031f0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
12 changes: 10 additions & 2 deletions include/net/mptcp_v4.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ extern struct tcp_request_sock_ops mptcp_join_request_sock_ipv4_ops;
int mptcp_v4_do_rcv(struct sock *meta_sk, struct sk_buff *skb);
struct sock *mptcp_v4_search_req(const __be16 rport, const __be32 raddr,
const __be32 laddr, const struct net *net);
int mptcp_init4_subsockets(struct sock *meta_sk, const struct mptcp_loc4 *loc,
struct mptcp_rem4 *rem);
int __mptcp_init4_subsockets(struct sock *meta_sk, const struct mptcp_loc4 *loc,
__be16 sport, struct mptcp_rem4 *rem,
struct sock **subsk);
int mptcp_pm_v4_init(void);
void mptcp_pm_v4_undo(void);
u32 mptcp_v4_get_nonce(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport);
u64 mptcp_v4_get_key(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport,
u32 seed);

static inline int mptcp_init4_subsockets(struct sock *meta_sk,
const struct mptcp_loc4 *loc,
struct mptcp_rem4 *rem)
{
return __mptcp_init4_subsockets(meta_sk, loc, 0, rem, NULL);
}

#else

static inline int mptcp_v4_do_rcv(const struct sock *meta_sk,
Expand Down
12 changes: 10 additions & 2 deletions include/net/mptcp_v6.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,23 @@ extern struct tcp_request_sock_ops mptcp_join_request_sock_ipv6_ops;
int mptcp_v6_do_rcv(struct sock *meta_sk, struct sk_buff *skb);
struct sock *mptcp_v6_search_req(const __be16 rport, const struct in6_addr *raddr,
const struct in6_addr *laddr, const struct net *net);
int mptcp_init6_subsockets(struct sock *meta_sk, const struct mptcp_loc6 *loc,
struct mptcp_rem6 *rem);
int __mptcp_init6_subsockets(struct sock *meta_sk, const struct mptcp_loc6 *loc,
__be16 sport, struct mptcp_rem6 *rem,
struct sock **subsk);
int mptcp_pm_v6_init(void);
void mptcp_pm_v6_undo(void);
__u32 mptcp_v6_get_nonce(const __be32 *saddr, const __be32 *daddr,
__be16 sport, __be16 dport);
u64 mptcp_v6_get_key(const __be32 *saddr, const __be32 *daddr,
__be16 sport, __be16 dport, u32 seed);

static inline int mptcp_init6_subsockets(struct sock *meta_sk,
const struct mptcp_loc6 *loc,
struct mptcp_rem6 *rem)
{
return __mptcp_init6_subsockets(meta_sk, loc, 0, rem, NULL);
}

#else /* CONFIG_MPTCP */

#define mptcp_v6_mapped ipv6_mapped
Expand Down
12 changes: 8 additions & 4 deletions net/mptcp/mptcp_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,9 @@ int mptcp_v4_do_rcv(struct sock *meta_sk, struct sk_buff *skb)
*
* We are in user-context and meta-sock-lock is hold.
*/
int mptcp_init4_subsockets(struct sock *meta_sk, const struct mptcp_loc4 *loc,
struct mptcp_rem4 *rem)
int __mptcp_init4_subsockets(struct sock *meta_sk, const struct mptcp_loc4 *loc,
__be16 sport, struct mptcp_rem4 *rem,
struct sock **subsk)
{
struct tcp_sock *tp;
struct sock *sk;
Expand Down Expand Up @@ -299,7 +300,7 @@ int mptcp_init4_subsockets(struct sock *meta_sk, const struct mptcp_loc4 *loc,
/** Then, connect the socket to the peer */
loc_in.sin_family = AF_INET;
rem_in.sin_family = AF_INET;
loc_in.sin_port = 0;
loc_in.sin_port = sport;
if (rem->port)
rem_in.sin_port = rem->port;
else
Expand Down Expand Up @@ -341,6 +342,9 @@ int mptcp_init4_subsockets(struct sock *meta_sk, const struct mptcp_loc4 *loc,
sk_set_socket(sk, meta_sk->sk_socket);
sk->sk_wq = meta_sk->sk_wq;

if (subsk)
*subsk = sk;

return 0;

error:
Expand All @@ -354,7 +358,7 @@ int mptcp_init4_subsockets(struct sock *meta_sk, const struct mptcp_loc4 *loc,
}
return ret;
}
EXPORT_SYMBOL(mptcp_init4_subsockets);
EXPORT_SYMBOL(__mptcp_init4_subsockets);

const struct inet_connection_sock_af_ops mptcp_v4_specific = {
.queue_xmit = ip_queue_xmit,
Expand Down
12 changes: 8 additions & 4 deletions net/mptcp/mptcp_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,9 @@ int mptcp_v6_do_rcv(struct sock *meta_sk, struct sk_buff *skb)
*
* We are in user-context and meta-sock-lock is hold.
*/
int mptcp_init6_subsockets(struct sock *meta_sk, const struct mptcp_loc6 *loc,
struct mptcp_rem6 *rem)
int __mptcp_init6_subsockets(struct sock *meta_sk, const struct mptcp_loc6 *loc,
__be16 sport, struct mptcp_rem6 *rem,
struct sock **subsk)
{
struct tcp_sock *tp;
struct sock *sk;
Expand Down Expand Up @@ -327,7 +328,7 @@ int mptcp_init6_subsockets(struct sock *meta_sk, const struct mptcp_loc6 *loc,
/** Then, connect the socket to the peer */
loc_in.sin6_family = AF_INET6;
rem_in.sin6_family = AF_INET6;
loc_in.sin6_port = 0;
loc_in.sin6_port = sport;
if (rem->port)
rem_in.sin6_port = rem->port;
else
Expand Down Expand Up @@ -369,6 +370,9 @@ int mptcp_init6_subsockets(struct sock *meta_sk, const struct mptcp_loc6 *loc,
sk_set_socket(sk, meta_sk->sk_socket);
sk->sk_wq = meta_sk->sk_wq;

if (subsk)
*subsk = sk;

return 0;

error:
Expand All @@ -382,7 +386,7 @@ int mptcp_init6_subsockets(struct sock *meta_sk, const struct mptcp_loc6 *loc,
}
return ret;
}
EXPORT_SYMBOL(mptcp_init6_subsockets);
EXPORT_SYMBOL(__mptcp_init6_subsockets);

const struct inet_connection_sock_af_ops mptcp_v6_specific = {
.queue_xmit = inet6_csk_xmit,
Expand Down

0 comments on commit 68031f0

Please sign in to comment.