IPv6 support
Subsystems (3)
Peter Krystad
cover IPv6 support
Sharing IPv6 work so far. Simple test shows connection establishment and data transfer works for a single subflow over link-local IPv6 between two VMs.
Still to do:
- Add selftests.
- Multiple subflows. ADD_ADDR option does not fit in TCP header with DSS, need to send independent ACK to carry it.
- Possibly split IPv4 and IPv6-specific portions into separate files, or at least reduce some of the excessive copy-paste in this version.
- Is special handling needed for IPv4-mapped addresses.
Peter Krystad (2):
mptcp: Export low-level routines for IPv6
mptcp: Add IPv6 support
include/net/mptcp.h | 3 + include/net/tcp.h | 8 ++ net/ipv6/tcp_ipv6.c | 29 ++++-- net/mptcp/ctrl.c | 11 +++ net/mptcp/protocol.c | 152 ++++++++++++++++++++++++++--- net/mptcp/protocol.h | 9 +- net/mptcp/subflow.c | 225 +++++++++++++++++++++++++++++++++++++------ 7 files changed, 388 insertions(+), 49 deletions(-)
Signature · 1 line
2.17.2
Peter Krystad
RFC 1/2 mptcp: Export low-level routines for IPv6
All routines exported already have their IPv4 counterparts exported. tcp_request_sock_ipv6_ops will be referenced during TCP subflow creation.
--- include/net/tcp.h | 8 ++++++++ net/ipv6/tcp_ipv6.c | 22 +++++++++++++--------- net/mptcp/protocol.h | 3 +++ 3 files changed, 24 insertions(+), 9 deletions(-)
include/net/tcp.h +8 -0
@@ -464,6 +464,13 @@ void tcp_finish_connect(struct sock *sk, struct sk_buff *skb);int tcp_send_rcvq (struct sock *sk,struct msghdr *msg,size_t size);void inet_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb); +struct sock *tcp_v6_syn_recv_sock (const struct sock *sk,struct sk_buff *skb, +struct request_sock *req, +struct dst_entry *dst, +struct request_sock *req_unhash, +bool *own_req); +void inet6_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb); +/* From syncookies.c */ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb, struct request_sock *req,
@@ -1987,6 +1994,7 @@ struct tcp_request_sock_ops { };extern const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops; +extern const struct tcp_request_sock_ops tcp_request_sock_ipv6_ops;#ifdef CONFIG_SYN_COOKIES static inline __u32 cookie_init_sequence(const struct tcp_request_sock_ops *ops,
net/ipv6/tcp_ipv6.c +13 -9
@@ -75,7 +75,7 @@ static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,static int tcp_v6_do_rcv (struct sock *sk,struct sk_buff *skb);static const struct inet_connection_sock_af_ops ipv6_mapped; -static const struct inet_connection_sock_af_ops ipv6_specific; +const struct inet_connection_sock_af_ops ipv6_specific;#ifdef CONFIG_TCP_MD5SIG static const struct tcp_sock_af_ops tcp_sock_ipv6_specific;static const struct tcp_sock_af_ops tcp_sock_ipv6_mapped_specific;
@@ -99,7 +99,7 @@ static struct ipv6_pinfo *tcp_inet6_sk(const struct sock *sk)return (struct ipv6_pinfo *)(((u8 *)sk) + offset); } -static void inet6_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb) +void inet6_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb);
@@ -111,6 +111,7 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)tcp_inet6_sk (sk)->rx_dst_cookie =rt6_get_cookie (rt); } } +EXPORT_SYMBOL (inet6_sk_rx_dst_set);static u32 tcp_v6_init_seq (const struct sk_buff *skb) {
@@ -784,7 +785,7 @@ struct request_sock_ops tcp6_request_sock_ops __read_mostly = { .syn_ack_timeout = tcp_syn_ack_timeout, }; -static const struct tcp_request_sock_ops tcp_request_sock_ipv6_ops = { +const struct tcp_request_sock_ops tcp_request_sock_ipv6_ops = { .mss_clamp =IPV6_MIN_MTU -sizeof (struct tcphdr ) -sizeof (struct ipv6hdr ), #ifdef CONFIG_TCP_MD5SIG
@@ -800,6 +801,7 @@ static const struct tcp_request_sock_ops tcp_request_sock_ipv6_ops = { .init_ts_off = tcp_v6_init_ts_off, .send_synack = tcp_v6_send_synack, }; +EXPORT_SYMBOL (tcp_request_sock_ipv6_ops); static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32 seq, u32 ack, u32 win, u32 tsval, u32 tsecr,
@@ -1110,11 +1112,11 @@ static void tcp_v6_restore_cb(struct sk_buff *skb) sizeof(struct inet6_skb_parm)); } -static struct sock *tcp_v6_syn_recv_sock (const struct sock *sk,struct sk_buff *skb, -struct request_sock *req, -struct dst_entry *dst, -struct request_sock *req_unhash, -bool *own_req) +struct sock *tcp_v6_syn_recv_sock (const struct sock *sk,struct sk_buff *skb, +struct request_sock *req, +struct dst_entry *dst, +struct request_sock *req_unhash, +bool *own_req) {struct inet_request_sock *ireq;struct ipv6_pinfo *newnp;
@@ -1314,6 +1316,7 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *tcp_listendrop (sk);return NULL ; } +EXPORT_SYMBOL (tcp_v6_syn_recv_sock);/* The socket must have it's spinlock held when we get * here, unless it is a TCP_LISTEN socket.
@@ -1738,7 +1741,7 @@ static struct timewait_sock_ops tcp6_timewait_sock_ops = { .twsk_destructor = tcp_twsk_destructor, }; -static const struct inet_connection_sock_af_ops ipv6_specific = { +const struct inet_connection_sock_af_ops ipv6_specific = { .queue_xmit = inet6_csk_xmit, .send_check = tcp_v6_send_check, .rebuild_header = inet6_sk_rebuild_header,
@@ -1757,6 +1760,7 @@ static const struct inet_connection_sock_af_ops ipv6_specific = {#endif .mtu_reduced = tcp_v6_mtu_reduced, }; +EXPORT_SYMBOL (ipv6_specific);#ifdef CONFIG_TCP_MD5SIG static const struct tcp_sock_af_ops tcp_sock_ipv6_specific = {
net/mptcp/protocol.h +3 -0
@@ -268,6 +268,9 @@ int mptcp_subflow_connect(struct sock *sk, struct sockaddr *local,int mptcp_subflow_create_socket (struct sock *sk,struct socket **new_sock);extern const struct inet_connection_sock_af_ops ipv4_specific; +#if IS_ENABLED (CONFIG_IPV6 ) +extern const struct inet_connection_sock_af_ops ipv6_specific; +#endif void mptcp_proto_init (void );
Signature · 1 line
2.17.2
Paolo Abeni
[MPTCP] Re: [RFC 1/2] mptcp: Export low-level routines for IPv6
Hi,
Quoted 5 lines · Peter Krystad
All routines exported already have their IPv4 counterparts exported.
tcp_request_sock_ipv6_opswill be referenced during TCP subflow creation.Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
I guess this could be squashed into "tcp: Export TCP functions and ops struct", right?
[...]
Quoted 23 lines
net/ipv6/tcp_ipv6.c +2
-2@@ -75,7 +75,7 @@ static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,static int tcp_v6_do_rcv (struct sock *sk,struct sk_buff *skb);static const struct inet_connection_sock_af_ops ipv6_mapped; -static const struct inet_connection_sock_af_ops ipv6_specific; +const struct inet_connection_sock_af_ops ipv6_specific;#ifdef CONFIG_TCP_MD5SIG static const struct tcp_sock_af_ops tcp_sock_ipv6_specific;static const struct tcp_sock_af_ops tcp_sock_ipv6_mapped_specific;@@ -99,7 +99,7 @@ static struct ipv6_pinfo *tcp_inet6_sk(const struct sock *sk)return (struct ipv6_pinfo *)(((u8 *)sk) + offset); } -static void inet6_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb) +void inet6_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb);
net/ipv6/tcp_ipv6.c static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb) · line 114
Quoted 4 lines
net/ipv6/tcp_ipv6.c +1
-0@@ -111,6 +111,7 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)tcp_inet6_sk (sk)->rx_dst_cookie =rt6_get_cookie (rt); } } +EXPORT_SYMBOL (inet6_sk_rx_dst_set);
I think this is not needed, as we don't build mptcp as a module. Dropping the 'static' scope should suffice. This should apply also to tcp_request_sock_ipv6_ops, tcp_v6_syn_recv_sock and ipv6_specific below.
[...]
Quoted 5 lines
net/mptcp/protocol.h +0
-0
net/mptcp/protocol.h int mptcp_subflow_connect(struct sock *sk, struct sockaddr *local, · line 276
Quoted 9 lines
net/mptcp/protocol.h +3
-0@@ -268,6 +268,9 @@ int mptcp_subflow_connect(struct sock *sk, struct sockaddr *local,int mptcp_subflow_create_socket (struct sock *sk,struct socket **new_sock);extern const struct inet_connection_sock_af_ops ipv4_specific; +#if IS_ENABLED (CONFIG_IPV6 ) +extern const struct inet_connection_sock_af_ops ipv6_specific; +#endif void mptcp_proto_init (void );
uhmm.. _if_ we want to squash these patches, this chunk should likely go to a different patch than all the above - possibly "mptcp: Handle MP_CAPABLE options for outgoing connections". Perhaps squashing is not a good idea in this case.
Cheers,
Paolo
Florian Westphal
[MPTCP] Re: [RFC 1/2] mptcp: Export low-level routines for IPv6
Quoted 5 lines · Paolo Abeni
Quoted 5 lines
net/ipv6/tcp_ipv6.c +1
-1-static void inet6_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb) +void inet6_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb);
Quoted 10 lines
net/ipv6/tcp_ipv6.c static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb) · line 114
Quoted 5 lines
net/ipv6/tcp_ipv6.c +1
-0@@ -111,6 +111,7 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)tcp_inet6_sk (sk)->rx_dst_cookie =rt6_get_cookie (rt); } } +EXPORT_SYMBOL (inet6_sk_rx_dst_set);I think this is not needed, as we don't build mptcp as a module. Dropping the 'static' scope should suffice. This should apply also to
tcp_request_sock_ipv6_ops,tcp_v6_syn_recv_sockandipv6_specificbelow.
Yes, but ipv6 can be built as a module, i.e. mptcp cannot call any ipv6 related symbol directly.
This will need rather ugly indirections, similar to include/linux/netfilter_ipv6.h / "struct nf_ipv6_ops".
Paolo Abeni
[MPTCP] Re: [RFC 1/2] mptcp: Export low-level routines for IPv6
Quoted 17 lines · Florian Westphal
Quoted 5 lines · Paolo Abeni
Quoted 5 lines
net/ipv6/tcp_ipv6.c +1
-1-static void inet6_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb) +void inet6_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb);Quoted 10 lines
net/ipv6/tcp_ipv6.c static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb) · line 114
Quoted 5 lines
net/ipv6/tcp_ipv6.c +1
-0@@ -111,6 +111,7 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)tcp_inet6_sk (sk)->rx_dst_cookie =rt6_get_cookie (rt); } } +EXPORT_SYMBOL (inet6_sk_rx_dst_set);I think this is not needed, as we don't build mptcp as a module. Dropping the 'static' scope should suffice. This should apply also to
tcp_request_sock_ipv6_ops,tcp_v6_syn_recv_sockandipv6_specificbelow.
Quoted 2 lines
Yes, but ipv6 can be built as a module, i.e. mptcp cannot call any ipv6 related symbol directly.
whoops, I always forgot about that :(
On the plus side, we don't actually need to touch the scope of tcp_v6_syn_recv_sock and inet6_sk_rx_dst_set, as we can access them via 'ipv6_specific', which we need to access no-matter-what.
On the flip side, hooking mptcpv6_init() in the next patch looks even more messy :(
What if we make MPTCP IPv6 support depending on IPV6 = y ?
Cheers,
Paolo
Peter Krystad
[MPTCP] Re: [RFC 1/2] mptcp: Export low-level routines for IPv6
In reply to Paolo AbeniHi Paolo -
Quoted 11 lines · Paolo Abeni
Hi,
Quoted 5 lines · Peter Krystad
All routines exported already have their IPv4 counterparts exported.
tcp_request_sock_ipv6_opswill be referenced during TCP subflow creation.Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>I guess this could be squashed into "tcp: Export TCP functions and ops struct", right?
Maybe, see my last comment.
Quoted 24 lines
[...]
Quoted 22 lines
net/ipv6/tcp_ipv6.c +2
-2@@ -75,7 +75,7 @@ static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,static int tcp_v6_do_rcv (struct sock *sk,struct sk_buff *skb);static const struct inet_connection_sock_af_ops ipv6_mapped; -static const struct inet_connection_sock_af_ops ipv6_specific; +const struct inet_connection_sock_af_ops ipv6_specific;#ifdef CONFIG_TCP_MD5SIG static const struct tcp_sock_af_ops tcp_sock_ipv6_specific;static const struct tcp_sock_af_ops tcp_sock_ipv6_mapped_specific;@@ -99,7 +99,7 @@ static struct ipv6_pinfo *tcp_inet6_sk(const struct sock *sk)return (struct ipv6_pinfo *)(((u8 *)sk) + offset); } -static void inet6_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb) +void inet6_sk_rx_dst_set (struct sock *sk,const struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb);
Quoted 10 lines
net/ipv6/tcp_ipv6.c static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb) · line 114
Quoted 5 lines
net/ipv6/tcp_ipv6.c +1
-0@@ -111,6 +111,7 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)tcp_inet6_sk (sk)->rx_dst_cookie =rt6_get_cookie (rt); } } +EXPORT_SYMBOL (inet6_sk_rx_dst_set);I think this is not needed, as we don't build mptcp as a module. Dropping the 'static' scope should suffice. This should apply also to
tcp_request_sock_ipv6_ops,tcp_v6_syn_recv_sockandipv6_specificbelow.
Correct, and I'll do the same for the others.
Quoted 14 lines
[...]
Quoted 12 lines
net/mptcp/protocol.h +3
-0@@ -268,6 +268,9 @@ int mptcp_subflow_connect(struct sock *sk, struct sockaddr *local,int mptcp_subflow_create_socket (struct sock *sk,struct socket **new_sock);extern const struct inet_connection_sock_af_ops ipv4_specific; +#if IS_ENABLED (CONFIG_IPV6 ) +extern const struct inet_connection_sock_af_ops ipv6_specific; +#endif
Quoted 6 lines
net/mptcp/protocol.h int mptcp_subflow_connect(struct sock *sk, struct sockaddr *local, · line 276
Quoted 2 lines
net/mptcp/protocol.h +0
-0void mptcp_proto_init (void );uhmm.. _if_ we want to squash these patches, this chunk should likely go to a different patch than all the above - possibly "mptcp: Handle
MP_CAPABLEoptions for outgoing connections". Perhaps squashing is not a good idea in this case.
Squashing depends on if we want the patch sequence to look like we did v6 at the same time as v4, i.e. as each feature is introduced it has both v4 and v6. I'm in favor of not squashing this patch.
Peter.
Quoted 4 lines
Cheers,
Paolo
Paolo Abeni
[MPTCP] Re: [RFC 1/2] mptcp: Export low-level routines for IPv6
Quoted 21 lines · Peter Krystad
Quoted 13 lines · Paolo Abeni
Quoted 12 lines · Peter Krystad
net/mptcp/protocol.h +3
-0@@ -268,6 +268,9 @@ int mptcp_subflow_connect(struct sock *sk, struct sockaddr *local,int mptcp_subflow_create_socket (struct sock *sk,struct socket **new_sock);extern const struct inet_connection_sock_af_ops ipv4_specific; +#if IS_ENABLED (CONFIG_IPV6 ) +extern const struct inet_connection_sock_af_ops ipv6_specific; +#endif Quoted 6 lines
net/mptcp/protocol.h int mptcp_subflow_connect(struct sock *sk, struct sockaddr *local, · line 276
Quoted 2 lines
net/mptcp/protocol.h +0
-0void mptcp_proto_init (void );uhmm.. _if_ we want to squash these patches, this chunk should likely go to a different patch than all the above - possibly "mptcp: Handle
MP_CAPABLEoptions for outgoing connections". Perhaps squashing is not a good idea in this case.
Quoted 3 lines
Squashing depends on if we want the patch sequence to look like we did v6 at the same time as v4, i.e. as each feature is introduced it has both v4 and v6. I'm in favor of not squashing this patch.
Ok, not a big deal. We just need to double check the total patch count when we will be near to the submission shape - to make the series as palatable as possible.
Cheers,
Paolo
Peter Krystad
RFC 2/2 mptcp: Add IPv6 support
In reply to Peter KrystadMimic hooks and option handling for IPv6 as was done for IPv4 MPTCP sockets.
--- include/net/mptcp.h | 3 + net/ipv6/tcp_ipv6.c | 7 ++ net/mptcp/ctrl.c | 11 +++ net/mptcp/protocol.c | 152 ++++++++++++++++++++++++++--- net/mptcp/protocol.h | 6 +- net/mptcp/subflow.c | 225 +++++++++++++++++++++++++++++++++++++------ 6 files changed, 364 insertions(+), 40 deletions(-)
include/net/mptcp.h +3 -0
@@ -53,6 +53,9 @@ struct mptcp_out_options {#ifdef CONFIG_MPTCP void mptcp_init (void ); +#if IS_ENABLED (CONFIG_IPV6 ) +int mptcpv6_init (void ); +#endif static inline bool sk_is_mptcp (const struct sock *sk) {
net/ipv6/tcp_ipv6.c +7 -0
@@ -2110,9 +2110,16 @@ int __init tcpv6_init(void) ret =register_pernet_subsys (&tcpv6_net_ops);if (ret) goto out_tcpv6_protosw; + + ret =mptcpv6_init (); +if (ret) + goto out_mptcpv6_init; + out:return ret; +out_mptcpv6_init: +unregister_pernet_subsys (&tcpv6_net_ops); out_tcpv6_protosw:inet6_unregister_protosw (&tcpv6_protosw); out_tcpv6_protocol:
net/mptcp/ctrl.c +11 -0
@@ -117,3 +117,14 @@ void __init mptcp_init(void)if (register_pernet_subsys (&mptcp_pernet_ops) <0 )panic ("Failed to register MPTCP pernet subsystem.\n" ); } + +#if IS_ENABLED (CONFIG_IPV6 ) +int __init mptcpv6_init (void ) +{ +int err; + + err =mptcp_proto_v6_init (); + +return err; +} +#endif
net/mptcp/protocol.c +140 -12
217 lines not on this page · raw message
net/mptcp/protocol.h +5 -1
@@ -265,7 +265,8 @@ bool mptcp_subflow_data_available(struct sock *sk);void mptcp_subflow_init (void );int mptcp_subflow_connect (struct sock *sk,struct sockaddr *local,struct sockaddr *remote,u8 remote_id); -int mptcp_subflow_create_socket (struct sock *sk,struct socket **new_sock); +int mptcp_subflow_create_socket (struct sock *sk,sa_family_t family, +struct socket **new_sock);extern const struct inet_connection_sock_af_ops ipv4_specific;#if IS_ENABLED (CONFIG_IPV6 )
@@ -273,6 +274,9 @@ extern const struct inet_connection_sock_af_ops ipv6_specific;#endif void mptcp_proto_init (void ); +#if IS_ENABLED (CONFIG_IPV6 ) +int mptcp_proto_v6_init (void ); +#endif struct mptcp_read_arg {struct msghdr *msg;
net/mptcp/subflow.c +198 -27
336 lines not on this page · raw message
Signature · 1 line
2.17.2
Paolo Abeni
[MPTCP] Re: [RFC 2/2] mptcp: Add IPv6 support
Hi,
Quoted 14 lines · Peter Krystad
net/mptcp/protocol.c +8
-0@@ -1182,6 +1214,53 @@ static int mptcp_getname(struct socket *sock, struct sockaddr *uaddr,return ret; } +#if IS_ENABLED (CONFIG_IPV6 ) +static int mptcp_v6_getname (struct socket *sock,struct sockaddr *uaddr, +int peer) +{ +struct mptcp_sock *msk =mptcp_sk (sock->sk); +struct socket *ssock; +struct sock *ssk; +int ret;
net/mptcp/protocol.c static int mptcp_getname(struct socket *sock, struct sockaddr *uaddr, · line 1234
Quoted 10 lines
net/mptcp/protocol.c +10
-0+ +if (sock->sk->sk_prot == &tcpv6_prot) { +/* we are being invoked from __sys_accept4, after +* mptcp_accept() has just accepted a non-mp-capable +* flow: sk is a tcp_sk, not an mptcp one. +* +* Hand the socket over to tcp so all further socket ops +* bypass mptcp. +*/ + sock->ops = &inet_stream_ops;
Should we have &inet6_stream_ops here ^^^^^^ ???
Possibly the comments should be adjusted as well.
[...]
Quoted 20 lines
net/mptcp/protocol.c +16
-0@@ -1311,3 +1409,33 @@ void mptcp_proto_init(void)inet_register_protosw (&mptcp_protosw); } + +#if IS_ENABLED (CONFIG_IPV6 ) +static struct proto_ops mptcp_v6_stream_ops; + +static struct inet_protosw mptcp_v6_protosw = { + .type =SOCK_STREAM , + .protocol =IPPROTO_MPTCP , + .prot = &mptcp_prot, + .ops = &mptcp_v6_stream_ops, + .flags =INET_PROTOSW_ICSK , +}; + +int mptcp_proto_v6_init (void ) +{ +int err; +
net/mptcp/protocol.c void mptcp_proto_init(void) · line 1437
Quoted 10 lines
net/mptcp/protocol.c +10
-0+ mptcp_v6_stream_ops = inet6_stream_ops; + mptcp_v6_stream_ops.bind = mptcp_v6_bind; + mptcp_v6_stream_ops.connect = mptcp_v6_stream_connect; + mptcp_v6_stream_ops.poll = mptcp_poll; + mptcp_v6_stream_ops.accept = mptcp_stream_accept; + mptcp_v6_stream_ops.getname = mptcp_v6_getname; + mptcp_v6_stream_ops.listen = mptcp_v6_listen; + mptcp_v6_stream_ops.shutdown = mptcp_shutdown; + + err =inet6_register_protosw (&mptcp_v6_protosw);
For IPv4 we currently do panic, if we can't register the protosw struct, possibly we could explicitly handle the failure even there?
Overall this looks nice and clean! What about moving the ipv6 protocol.c support into a separate file, to reduce the preprocessor conditionals?
[...]
net/mptcp/protocol.c static int subflow_conn_request(struct sock *sk, struct sk_buff *skb) · line 297
Quoted 9 lines
net/mptcp/protocol.c +5
-0@@ -226,6 +290,26 @@ static int subflow_conn_request(struct sock *sk, struct sk_buff *skb)return 0 ; } +static int subflow_v6_conn_request (struct sock *sk,struct sk_buff *skb) +{ +struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk); + +pr_debug ("subflow=%p" , subflow);
Just to avoid duplicate debug messages for IPv4 packets, what about moving this one below the next if?
[...]
Quoted 52 lines
net/mptcp/protocol.c +47
-1@@ -309,7 +393,70 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,return NULL ; } -static struct inet_connection_sock_af_ops subflow_specific; +#if IS_ENABLED (CONFIG_IPV6 ) +static struct sock *subflow_v6_syn_recv_sock (const struct sock *sk, +struct sk_buff *skb, +struct request_sock *req, +struct dst_entry *dst, +struct request_sock *req_unhash, +bool *own_req) +{ +struct mptcp_subflow_context *listener =mptcp_subflow_ctx (sk); +struct mptcp_subflow_request_sock *subflow_req; +struct tcp_options_received opt_rx; +struct sock *child; + +pr_debug ("listener=%p, req=%p, conn=%p" , listener, req, listener->conn); + +/* if the sk is MP_CAPABLE, we already received the client key */ + subflow_req =mptcp_subflow_rsk (req); +if (!subflow_req->mp_capable && subflow_req->mp_join) { + opt_rx.mptcp.mp_join =0 ; +mptcp_get_options (skb, &opt_rx); +if (!opt_rx.mptcp.mp_join || + !subflow_hmac_valid (req, &opt_rx)) +return NULL ; + } + + child =tcp_v6_syn_recv_sock (sk, skb, req, dst, req_unhash, own_req); + +if (child && *own_req) { +struct mptcp_subflow_context *ctx =mptcp_subflow_ctx (child); + +if (!ctx) + goto close_child; + +if (ctx->mp_capable) { +if (mptcp_token_new_accept (ctx->token)) + goto close_child; + }else if (ctx->mp_join) { +struct mptcp_sock *owner; + + owner =mptcp_token_get_sock (ctx->token); +if (!owner) + goto close_child; + + ctx->conn = (struct sock *)owner; +mptcp_finish_join (child); + } + }
net/mptcp/protocol.c static struct sock *subflow_syn_recv_sock(const struct sock *sk, · line 452
Quoted 10 lines
net/mptcp/protocol.c +10
-0+ +return child; + +close_child: +pr_debug ("closing child socket" ); +inet_sk_set_state (child,TCP_CLOSE ); +sock_set_flag (child,SOCK_DEAD ); +inet_csk_destroy_sock (child); +return NULL ; +}
As this looks quite alike the ipv4 counter part, except for the tcp_v4_syn_recv_sock() call, replaced here by tcp_v6_syn_recv_sock(), what about using a function pointer and the same overall code?
If the additional indirect call overhead is a concern, we can leverage the indirect call infrastructure ;) [shameless self-promotion;)]
How about moving even the subflow ipv6 code to a separate, ipv6 specific file ? (possibly the same used for ipv6 protocol.c code)
Overall this looks much more clean and self-contained than expected!
Thank you,
Paolo
Matthieu Baerts
[MPTCP] Re: [RFC 2/2] mptcp: Add IPv6 support
Hi Peter, Paolo,
Quoted 5 lines · Paolo Abeni
Hi,
Quoted 2 lines · Peter Krystad
net/mptcp/protocol.c +0
-0
[...]
Quoted 25 lines
Quoted 25 lines
net/mptcp/protocol.c +21
-0@@ -1311,3 +1409,33 @@ void mptcp_proto_init(void)inet_register_protosw (&mptcp_protosw); } + +#if IS_ENABLED (CONFIG_IPV6 ) +static struct proto_ops mptcp_v6_stream_ops; + +static struct inet_protosw mptcp_v6_protosw = { + .type =SOCK_STREAM , + .protocol =IPPROTO_MPTCP , + .prot = &mptcp_prot, + .ops = &mptcp_v6_stream_ops, + .flags =INET_PROTOSW_ICSK , +}; + +int mptcp_proto_v6_init (void ) +{ +int err; + + mptcp_v6_stream_ops = inet6_stream_ops; + mptcp_v6_stream_ops.bind = mptcp_v6_bind; + mptcp_v6_stream_ops.connect = mptcp_v6_stream_connect; + mptcp_v6_stream_ops.poll = mptcp_poll; + mptcp_v6_stream_ops.accept = mptcp_stream_accept;
Quoted 8 lines
net/mptcp/protocol.c void mptcp_proto_init(void) · line 1437
Quoted 5 lines
net/mptcp/protocol.c +5
-0+ mptcp_v6_stream_ops.getname = mptcp_v6_getname; + mptcp_v6_stream_ops.listen = mptcp_v6_listen; + mptcp_v6_stream_ops.shutdown = mptcp_shutdown; + + err =inet6_register_protosw (&mptcp_v6_protosw);For IPv4 we currently do panic, if we can't register the protosw struct, possibly we could explicitly handle the failure even there?
Is it not safer to report this error and free what has been register just in case IPv6 is loaded as a module?
Quoted 3 lines
Overall this looks nice and clean! What about moving the ipv6
protocol.csupport into a separate file, to reduce the preprocessor conditionals?
Or force IPV6 support? :-)
Quoted 75 lines
[...]
net/mptcp/protocol.c static int subflow_conn_request(struct sock *sk, struct sk_buff *skb) · line 297
Quoted 9 lines
net/mptcp/protocol.c +5
-0@@ -226,6 +290,26 @@ static int subflow_conn_request(struct sock *sk, struct sk_buff *skb)return 0 ; } +static int subflow_v6_conn_request (struct sock *sk,struct sk_buff *skb) +{ +struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk); + +pr_debug ("subflow=%p" , subflow);Just to avoid duplicate debug messages for IPv4 packets, what about moving this one below the next if?
[...]
Quoted 58 lines
net/mptcp/protocol.c +53
-1@@ -309,7 +393,70 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,return NULL ; } -static struct inet_connection_sock_af_ops subflow_specific; +#if IS_ENABLED (CONFIG_IPV6 ) +static struct sock *subflow_v6_syn_recv_sock (const struct sock *sk, +struct sk_buff *skb, +struct request_sock *req, +struct dst_entry *dst, +struct request_sock *req_unhash, +bool *own_req) +{ +struct mptcp_subflow_context *listener =mptcp_subflow_ctx (sk); +struct mptcp_subflow_request_sock *subflow_req; +struct tcp_options_received opt_rx; +struct sock *child; + +pr_debug ("listener=%p, req=%p, conn=%p" , listener, req, listener->conn); + +/* if the sk is MP_CAPABLE, we already received the client key */ + subflow_req =mptcp_subflow_rsk (req); +if (!subflow_req->mp_capable && subflow_req->mp_join) { + opt_rx.mptcp.mp_join =0 ; +mptcp_get_options (skb, &opt_rx); +if (!opt_rx.mptcp.mp_join || + !subflow_hmac_valid (req, &opt_rx)) +return NULL ; + } + + child =tcp_v6_syn_recv_sock (sk, skb, req, dst, req_unhash, own_req); + +if (child && *own_req) { +struct mptcp_subflow_context *ctx =mptcp_subflow_ctx (child); + +if (!ctx) + goto close_child; + +if (ctx->mp_capable) { +if (mptcp_token_new_accept (ctx->token)) + goto close_child; + }else if (ctx->mp_join) { +struct mptcp_sock *owner; + + owner =mptcp_token_get_sock (ctx->token); +if (!owner) + goto close_child; + + ctx->conn = (struct sock *)owner; +mptcp_finish_join (child); + } + } + +return child; + +close_child: +pr_debug ("closing child socket" ); +inet_sk_set_state (child,TCP_CLOSE );
Quoted 8 lines
net/mptcp/protocol.c static struct sock *subflow_syn_recv_sock(const struct sock *sk, · line 452
Quoted 4 lines
net/mptcp/protocol.c +4
-0+sock_set_flag (child,SOCK_DEAD ); +inet_csk_destroy_sock (child); +return NULL ; +}As this looks quite alike the ipv4 counter part, except for the
tcp_v4_syn_recv_sock()call, replaced here bytcp_v6_syn_recv_sock(), what about using a function pointer and the same overall code?
We might be able to do that for a few other functions. Would be the goal to avoid duplication? Or readability.
Quoted 2 lines
If the additional indirect call overhead is a concern, we can leverage the indirect call infrastructure ;) [shameless self-promotion;)]
:-)
But a good idea!
Quoted 2 lines
How about moving even the subflow ipv6 code to a separate, ipv6 specific file ? (possibly the same used for ipv6
protocol.ccode)
By having specific IPv6 code in another file, that might force us to duplicate more code sometimes, not to have to read from one file to another. But it might help for the readability. I guess you guys have experience about what is best here :-)
Quoted 1 line
Overall this looks much more clean and self-contained than expected!
That's true, very good, thank you for sharing this!
I just have an additional comment about the modified TCP code, a detail:
Quoted 7 lines
net/ipv6/tcp_ipv6.c +0
-0@@ -2110,9 +2110,16 @@ int __init tcpv6_init(void) ret =register_pernet_subsys (&tcpv6_net_ops);if (ret)
net/ipv6/tcp_ipv6.c int __init tcpv6_init(void) · line 2121
Quoted 10 lines
net/ipv6/tcp_ipv6.c +6
-0goto out_tcpv6_protosw; + + ret =mptcpv6_init (); +if (ret) + goto out_mptcpv6_init; + out:return ret; +out_mptcpv6_init:
Detail: I guess the label should be renamed to something like "out_tcp6_pernet_subsys" to keep the same logic.
net/ipv6/tcp_ipv6.c int __init tcpv6_init(void) · line 2125
Quoted 4 lines
net/ipv6/tcp_ipv6.c +1
-0+unregister_pernet_subsys (&tcpv6_net_ops); out_tcpv6_protosw:inet6_unregister_protosw (&tcpv6_protosw); out_tcpv6_protocol:
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Peter Krystad
[MPTCP] Re: [RFC 2/2] mptcp: Add IPv6 support
In reply to Paolo AbeniHi Paolo -
Thanks for the review, sorry for the slow response.
Quoted 22 lines · Paolo Abeni
Hi,
Quoted 19 lines · Peter Krystad
net/mptcp/protocol.c +13
-0@@ -1182,6 +1214,53 @@ static int mptcp_getname(struct socket *sock, struct sockaddr *uaddr,return ret; } +#if IS_ENABLED (CONFIG_IPV6 ) +static int mptcp_v6_getname (struct socket *sock,struct sockaddr *uaddr, +int peer) +{ +struct mptcp_sock *msk =mptcp_sk (sock->sk); +struct socket *ssock; +struct sock *ssk; +int ret; + +if (sock->sk->sk_prot == &tcpv6_prot) { +/* we are being invoked from __sys_accept4, after +* mptcp_accept() has just accepted a non-mp-capable +* flow: sk is a tcp_sk, not an mptcp one.
Quoted 8 lines
net/mptcp/protocol.c static int mptcp_getname(struct socket *sock, struct sockaddr *uaddr, · line 1234
Quoted 5 lines
net/mptcp/protocol.c +5
-0+* +* Hand the socket over to tcp so all further socket ops +* bypass mptcp. +*/ + sock->ops = &inet_stream_ops;Should we have
&inet6_stream_opshere ^^^^^^ ???
Possibly the comments should be adjusted as well.
Yes, nice catch. Comment, at least the __sys_accept4 part, is OK, I think the 4 refers to a version of accept, not the protocol.
Quoted 27 lines
[...]
Quoted 25 lines
net/mptcp/protocol.c +21
-0@@ -1311,3 +1409,33 @@ void mptcp_proto_init(void)inet_register_protosw (&mptcp_protosw); } + +#if IS_ENABLED (CONFIG_IPV6 ) +static struct proto_ops mptcp_v6_stream_ops; + +static struct inet_protosw mptcp_v6_protosw = { + .type =SOCK_STREAM , + .protocol =IPPROTO_MPTCP , + .prot = &mptcp_prot, + .ops = &mptcp_v6_stream_ops, + .flags =INET_PROTOSW_ICSK , +}; + +int mptcp_proto_v6_init (void ) +{ +int err; + + mptcp_v6_stream_ops = inet6_stream_ops; + mptcp_v6_stream_ops.bind = mptcp_v6_bind; + mptcp_v6_stream_ops.connect = mptcp_v6_stream_connect; + mptcp_v6_stream_ops.poll = mptcp_poll; + mptcp_v6_stream_ops.accept = mptcp_stream_accept;
Quoted 8 lines
net/mptcp/protocol.c void mptcp_proto_init(void) · line 1437
Quoted 5 lines
net/mptcp/protocol.c +5
-0+ mptcp_v6_stream_ops.getname = mptcp_v6_getname; + mptcp_v6_stream_ops.listen = mptcp_v6_listen; + mptcp_v6_stream_ops.shutdown = mptcp_shutdown; + + err =inet6_register_protosw (&mptcp_v6_protosw);For IPv4 we currently do panic, if we can't register the protosw struct, possibly we could explicitly handle the failure even there?
Sorry, are suggesting getting rid of the panic()'s in IPv4? Or adding them here?
Quoted 3 lines
Overall this looks nice and clean! What about moving the ipv6
protocol.csupport into a separate file, to reduce the preprocessor conditionals?
Thanks. Next step to is split the IPv6 into a seperate file, then I'll submit as a PATCH.
Peter.
Quoted 96 lines
[...]
net/mptcp/protocol.c static int subflow_conn_request(struct sock *sk, struct sk_buff *skb) · line 297
Quoted 9 lines
net/mptcp/protocol.c +5
-0@@ -226,6 +290,26 @@ static int subflow_conn_request(struct sock *sk, struct sk_buff *skb)return 0 ; } +static int subflow_v6_conn_request (struct sock *sk,struct sk_buff *skb) +{ +struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk); + +pr_debug ("subflow=%p" , subflow);Just to avoid duplicate debug messages for IPv4 packets, what about moving this one below the next if?
[...]
Quoted 52 lines
net/mptcp/protocol.c +47
-1@@ -309,7 +393,70 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,return NULL ; } -static struct inet_connection_sock_af_ops subflow_specific; +#if IS_ENABLED (CONFIG_IPV6 ) +static struct sock *subflow_v6_syn_recv_sock (const struct sock *sk, +struct sk_buff *skb, +struct request_sock *req, +struct dst_entry *dst, +struct request_sock *req_unhash, +bool *own_req) +{ +struct mptcp_subflow_context *listener =mptcp_subflow_ctx (sk); +struct mptcp_subflow_request_sock *subflow_req; +struct tcp_options_received opt_rx; +struct sock *child; + +pr_debug ("listener=%p, req=%p, conn=%p" , listener, req, listener->conn); + +/* if the sk is MP_CAPABLE, we already received the client key */ + subflow_req =mptcp_subflow_rsk (req); +if (!subflow_req->mp_capable && subflow_req->mp_join) { + opt_rx.mptcp.mp_join =0 ; +mptcp_get_options (skb, &opt_rx); +if (!opt_rx.mptcp.mp_join || + !subflow_hmac_valid (req, &opt_rx)) +return NULL ; + } + + child =tcp_v6_syn_recv_sock (sk, skb, req, dst, req_unhash, own_req); + +if (child && *own_req) { +struct mptcp_subflow_context *ctx =mptcp_subflow_ctx (child); + +if (!ctx) + goto close_child; + +if (ctx->mp_capable) { +if (mptcp_token_new_accept (ctx->token)) + goto close_child; + }else if (ctx->mp_join) { +struct mptcp_sock *owner; + + owner =mptcp_token_get_sock (ctx->token); +if (!owner) + goto close_child; + + ctx->conn = (struct sock *)owner; +mptcp_finish_join (child); + } + }net/mptcp/protocol.c static struct sock *subflow_syn_recv_sock(const struct sock *sk, · line 452
Quoted 10 lines
net/mptcp/protocol.c +10
-0+ +return child; + +close_child: +pr_debug ("closing child socket" ); +inet_sk_set_state (child,TCP_CLOSE ); +sock_set_flag (child,SOCK_DEAD ); +inet_csk_destroy_sock (child); +return NULL ; +}As this looks quite alike the ipv4 counter part, except for the
tcp_v4_syn_recv_sock()call, replaced here bytcp_v6_syn_recv_sock(), what about using a function pointer and the same overall code?If the additional indirect call overhead is a concern, we can leverage the indirect call infrastructure ;) [shameless self-promotion;)]
How about moving even the subflow ipv6 code to a separate, ipv6 specific file ? (possibly the same used for ipv6
protocol.ccode)Overall this looks much more clean and self-contained than expected!
Thank you,
Paolo
Paolo Abeni
[MPTCP] Re: [RFC 2/2] mptcp: Add IPv6 support
Quoted 36 lines · Peter Krystad
Hi Paolo -
Thanks for the review, sorry for the slow response.
Quoted 22 lines · Paolo Abeni
Hi,
Quoted 19 lines · Peter Krystad
net/mptcp/protocol.c +13
-0@@ -1182,6 +1214,53 @@ static int mptcp_getname(struct socket *sock, struct sockaddr *uaddr,return ret; } +#if IS_ENABLED (CONFIG_IPV6 ) +static int mptcp_v6_getname (struct socket *sock,struct sockaddr *uaddr, +int peer) +{ +struct mptcp_sock *msk =mptcp_sk (sock->sk); +struct socket *ssock; +struct sock *ssk; +int ret; + +if (sock->sk->sk_prot == &tcpv6_prot) { +/* we are being invoked from __sys_accept4, after +* mptcp_accept() has just accepted a non-mp-capable +* flow: sk is a tcp_sk, not an mptcp one. Quoted 8 lines
net/mptcp/protocol.c static int mptcp_getname(struct socket *sock, struct sockaddr *uaddr, · line 1234
Quoted 5 lines
net/mptcp/protocol.c +5
-0+* +* Hand the socket over to tcp so all further socket ops +* bypass mptcp. +*/ + sock->ops = &inet_stream_ops;Should we have
&inet6_stream_opshere ^^^^^^ ???
Possibly the comments should be adjusted as well.
Quoted 2 lines
Yes, nice catch. Comment, at least the
__sys_accept4part, is OK, I think the 4 refers to a version of accept, not the protocol.
Oh, nice! I really missed the real meaning of the trailing '4' in __sys_accept4(), thanks for pointing that out.
Switching to inet6_stream_ops should be ok anyway, right?
Quoted 37 lines
Quoted 28 lines
[...]
Quoted 25 lines
net/mptcp/protocol.c +21
-0@@ -1311,3 +1409,33 @@ void mptcp_proto_init(void)inet_register_protosw (&mptcp_protosw); } + +#if IS_ENABLED (CONFIG_IPV6 ) +static struct proto_ops mptcp_v6_stream_ops; + +static struct inet_protosw mptcp_v6_protosw = { + .type =SOCK_STREAM , + .protocol =IPPROTO_MPTCP , + .prot = &mptcp_prot, + .ops = &mptcp_v6_stream_ops, + .flags =INET_PROTOSW_ICSK , +}; + +int mptcp_proto_v6_init (void ) +{ +int err; + + mptcp_v6_stream_ops = inet6_stream_ops; + mptcp_v6_stream_ops.bind = mptcp_v6_bind; + mptcp_v6_stream_ops.connect = mptcp_v6_stream_connect; + mptcp_v6_stream_ops.poll = mptcp_poll; + mptcp_v6_stream_ops.accept = mptcp_stream_accept;Quoted 8 lines
net/mptcp/protocol.c void mptcp_proto_init(void) · line 1437
Quoted 5 lines
net/mptcp/protocol.c +5
-0+ mptcp_v6_stream_ops.getname = mptcp_v6_getname; + mptcp_v6_stream_ops.listen = mptcp_v6_listen; + mptcp_v6_stream_ops.shutdown = mptcp_shutdown; + + err =inet6_register_protosw (&mptcp_v6_protosw);For IPv4 we currently do panic, if we can't register the protosw struct, possibly we could explicitly handle the failure even there?
Quoted 2 lines
Sorry, are suggesting getting rid of the panic()'s in IPv4? Or adding them here?
In my previous email I suggested getting rid of the panic in IPv4 - just to harmoize the ipv4 and ipv6 behavior - but it's not a big deal:
for simplicity we can stick to the current implementation.
Quoted 6 lines
Quoted 3 lines
Overall this looks nice and clean! What about moving the ipv6
protocol.csupport into a separate file, to reduce the preprocessor conditionals?Thanks. Next step to is split the IPv6 into a seperate file, then I'll submit as a PATCH.
Excellent! looking forward to it!
Paolo