Remove changes from tcp_v4(6)_reqsk_destructor

As we now have our own mptcp_request_sock_ops, we can change the
callback to our custom mptcp_v4(6)_reqsk_destructor and thus reduce our
impact on the regular TCP stack.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Group exports in tcp.h

That way it's easier to see what has been modified in the tcp-stack
exclusively for MPTCP.

Additionally, I simplify tcp_push, by making the same trick as in
473232bfc050f. tcp_push is always called from the meta-sk if it is MPTCP
- thus, no worries here.

This patch largely reduces the modifications to the regular TCP stack.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Always call tcp_should_expand_sndbuf with the meta-sk

If it's TCP-only, it will still be the tcp-socket.
If it's MPTCP we don't really need the subsk.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Minor cleanup in the tcp-push code

tcp_push_pending_frames will always be called with the meta-sk if we are
doing MPTCP. Thus, no need to call mptcp_meta_sk.

mptcp_push_frames is no more used. We can remove it.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Simplify ofo-queue

We cannot increase the size of the sk_buff. Thus, the pointers and
fields in sk_buff have to be removed.

Ofo-queue handling follows now this algorithm in try_shortcut():

First, we check the shortcut of the receiving subflow.
Then, we check the shortcut of the other subflows, and look for the skb
in the ofo-queue who is closest to the point where we want to insert the
skb. That way we reduce the lookup-time as we start iterating over the
ofo-queue from this point on.

This also removes the allocation of the mptcp_node in the ofo-algo and
thus reduces the number of cache-misses.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Trivial - remove useless changes to the tcp-stack

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Trivial - Reorganize sock.c/h to reduce changes

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Trivial - use mptcp_is_data_fin

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Trivial

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Fix: Free mptcp_tcp_sock also for the meta-sk

Otherwise we have a memory-leak.

Why didn't kmemleak report it... ???

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Fix: Check for mptcp_is_data_seq in mptcp_verif_dss_csum

dss_off is set in mptcp_parse_options, irregardless of whether a
data-seq is present, or not.
Thus, we have to check in mptcp_verif_dss_csum based on the data-seq
number. Otherwise we will have problems if the mapping covers multiple
segments, with one of them holding the data-seq and the others just
data-acks.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Fix: Always lock the socket in mptcp_inherit_sk

Previously we did not lock if it was the meta-sk on the server-side.

This creates the following race:
In mptcp_check_req_master we allocate the mpcb and set child_tp->mpc to
1. Thus, if a new segment comes in while still being inside
mptcp_check_req_master, this segment will take the meta-lock in
tcp_v4_rcv. So, we are processing the third ack and this new segment in
the master-sk at the same time.

Fix is easy:
Always take the lock in mptcp_inherit_sk and unlock it again in
tcp_child_process.

There is one problem with lockdep-checks. As we take the meta-lock we
take three locks of the same class: The listener-sock in tcp_v4_rcv, the
master-sk in sk_clone and finally the meta-sk in mptcp_inherit_sk. Thus,
lockdep will complain.

We create a custom lock-class for the meta-sk. That way lockdep won't
complain anymore.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Fix: Fully destroy the socket if mptcp_check_req_child/master fails

The refcnt is initialized to 2 by sk_clone. Thus, we have to do a
sock_put, before calling tcp_done, who will do the final sock_put in
inet_csk_destroy_sock.

Additionally, unlock the sockets - their lock has been taken in
mptcp_inherit_sk

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Fix: Don't always set treq->pktopts in mptcp_v6_join_request

It is only allowed, if the socket accepts IPv6-options.

Generally mptcp_v6_join_request needs a review. See Bug#82 on the
bugzilla.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Fix: Don't modify reinjected skb if tcp_transmit_skb fails.

If there was a reinjection, subskb == skb. As we call kfree_skb() or
mptcp_wmem_free_skb on the subskb, we cannot access skb anymore.
Otherwise we have data-corruption of the skb.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Fix: Correctly check if the meta-sk still accepts new subflows.

In mptcp_close() we remove the collide_tk from the token-table. By
calling list_del_init() we ensure that list_empty() will return True and
thus can correctly check in mptcp_v4_do_rcv if the socket is still ready
to accept new subflows.

sock_orphan is not enough, because in mptcp_close we may call
release_sock before sock_orphan in sk_stream_wait_close.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Fix: Remove reqsk from request-queue in case of error

mptcp_v4_join_request did not really remove the request-sock from the
reqsk-queue in case of failure. Thus, the queue was corrupted, because
the req-sk was freed but not removed from the list.

We have to call inet_csk_search_req to get the prev-pointer. Then we can
remove it with a call to drop.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Fix: Purge reinject-queue in tcp_disconnect

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
sock_alloc_send_pskb doesn't need to handle mptcp

When it is called, we may come from tcp_v4_send_ack or
tcp_v4_send_reset. In that case, the socket is always the one from
init_net and thus non-mptcp.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>
Integrate MPTCP in the proto-infrastructure

The mptcp_cb-cache is now created by a call to proto_register. That way,
we have our own proto-struct for the mptcp_cb and this allows us to
remove the mptcp-code out of __sk_free.

Additionally, we can now specify our own callbacks in the mptcp_prot.
E.g., tcp_close doesn't need anymore to check for 'is_meta_sk', as
mptcp_prot directly points to mptcp_close.

Maybe further cleanup of this kind will be possible.

Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Reviewed-by: Octavian Purdila <octavian.purdila@intel.com>