History log of /haiku/src/add-ons/kernel/network/protocols/tcp/tcp.cpp
Revision Date Author Comments
# 5c2c391d 29-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

TCP: Remove overridden default buffer size.

The default of 65535 now seems to work OK,
following previous commits.


# 3285dcae 17-Dec-2021 Jérôme Duval <jerome.duval@gmail.com>

tcp: reset receive.low_water_mark when nothing to read anymore

the socket interface module checks the receive.low_water_mark to automatically
notify a read event. available_data will be zero, thus enabling the notification.

fixes the test poll_nm in NSPR.

Change-Id: I5354faec439df96671506550cdb144a45f6082b1
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4820
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# f0a567c4 17-Oct-2021 Jérôme Duval <jerome.duval@gmail.com>

tcp: combine timestamp and sack_permitted options when possible

any ordering is legal, but some devices don't cope with what we do.
thus we reorder sack_permitted before timestamp, this doesn't cost us anything.
noticed by Sikk: https://dev.haiku-os.org/ticket/13681#comment:11

Change-Id: Ic2e1589945dd74e3034a653427a2ff45626b3a76
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4598
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# f1ec6962 11-May-2021 Jérôme Duval <jerome.duval@gmail.com>

tcp: several fixes for SACK handling:

* kMaxOptionSize: TCP header size is 60 bytes. process_options() would have
accepted a longer header as permitted. add_options() would have possibly added
more options or SACK entries as permitted.
* tcp_segment: reserve memory for sack entries.
* _SendQueued(): "fLastAcknowledgeSent <= fReceiveNext": also send SACK entries
for received data when acknowledging a missing segment.
* _SendQueue(): after acknowledging, cancel the delayed acknowledgment timer.
* _Receive(): if calling Acknowledged() already triggered sending a segment
including an acknowledgement (piggy-back), remove "immediate acknowledge"
from the action. This helps to reduce empty ACKs for bidirectional streams.

Change-Id: I32808fbe549be0f5b25bcf4be17cd91a640b8ec4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3906
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# 745830a0 25-Aug-2017 A-star-ayush <myselfthebest@yahoo.com>

tcp: rfc 2018: implemented SACK option

Change-Id: I269ad2682446c4d37bae21dcf9f3036de964ff2c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/53
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# 51dd385e 23-May-2020 Kyle Ambroff-Kao <kyle@ambroffkao.com>

tcp: Don't skip TIME_WAIT state for loopback sockets

This fixes a SEGFAULT in the tcp add-on reported in issue #15952. See
that issue for some analysis.

The short version is that, when closing a session over the loopback
interface, there is a special branch which skips the TIME_WAIT state
and instead just releases the socket while handling a RST/ACK
segment. If the timing is right this can lead to the reference
counts becoming imbalanced, leading to the code in tcp_receive_data
segfaulting when it tries to release the reference it acquired from
EndpointManager::FindConnection.

I can't find any other systems which skip the TIME_WAIT state with
loopback sessions, and I'm not entirely certain that it's a totally
safe thing to do anyway. This patch instead just treats local sessions
the same way it does a remote session and uses the TIME_WAIT state.

Any workload which creates and discards lots of ephemeral sockets can
just use SO_REUSEADDR to handle this situation like any other system.

To add a final bit of safety, the only place where a net_socket can be
used after calling gSocketModule->release_socket(net_socket*) is in
tcp_receive_data(). release_socket() returns true if the reference
count falls to zero, deleting the socket. There was an unused segment
action flag DELETE_ENDPOINT that I renamed to DELETED_ENDPOINT, which
is used by tcp_receive_data to know whether its safe to release its
reference to the socket after calling TCPEndpoint::SegmentReceived().

Change-Id: I2652fb225c3c8419234cfd627f74ff2de8402003
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2793
Reviewed-by: Axel Dörfler <axeld@pinc-software.de>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 8844a67e 10-Dec-2018 Augustin Cavalier <waddlesplash@gmail.com>

More trivial syntax and logic cleanup.

Spotted by Clang. No functional change intended.


# d815bbcb 04-Oct-2017 Jérôme Duval <jerome.duval@gmail.com>

Revert "tcp: rfc 2018: implemented SACK option"

This reverts commit 5c31f5a67a0aa37c8f2a1464252b2c5b0a959f33.


# 5c31f5a6 25-Aug-2017 A-star-ayush <myselfthebest@yahoo.com>

tcp: rfc 2018: implemented SACK option

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>


# aaa7cebc 16-Aug-2017 A-star-ayush <myselfthebest@yahoo.com>

tcp: rfc 7323: added PAWS timestamp check on Receive

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>


# 3eee68eb 02-Jul-2017 Fredrik Holmqvist <fredrik.holmqvist@gmail.com>

Revert "Check needs extra paranthesis to aviod ambiguity."

This reverts commit 4e219110d4becb28907b6840cbf4f7914a5e7c43.
The commit also added the mask that caused ambiguity.
It shouldn't be there.


# 4e219110 02-Jul-2017 Fredrik Holmqvist <fredrik.holmqvist@gmail.com>

Check needs extra paranthesis to aviod ambiguity.

Build fails with an ambiguity warning on x86_64 cross compile otherwise.


# 75bb8dc6 05-Nov-2010 Axel Dörfler <axeld@pinc-software.de>

* Applied kaliber's patch part of ticket #6789, thanks! This makes the code not
only more readable, but also working correctly.
* Solved the problem stippi outlined differently, by checking whether length is
greater size for unsupported options.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39311 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 21c8f94c 05-Nov-2010 Stephan Aßmus <superstippi@gmx.de>

I don't understand much about the code in question, but the ticket #6789
hints at a possible problem: Within the process_options() function, the
code does not make sure that size is a multiple of the option length
(unless I missed something) and thus the loop could wrap the unsigned
size variable, and not exit as intended. Make size an ssize_t and cast
where appropriate, after making sure it's initially a positive value.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39309 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2b415445 04-Aug-2010 Axel Dörfler <axeld@pinc-software.de>

* Finished groundwork on ICMP by introducing a completely protocol agnostic
error mechanism.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37896 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 61729d93 28-Jul-2010 Axel Dörfler <axeld@pinc-software.de>

* Reworked the complete stack to allow more than one address per network
interface - this caused quite a number of changes.
* Network interfaces, and its addresses are now reference counted (not yet
complete, though, InterfaceAddresses need to hold references to their
interface as well).
* There are two known regressions of this commit that I will fix later:
- you cannot remove interfaces anymore
- IPv4 multicast was broken anyway, but now it's disabled, too.
* Moved a device_interfaces.cpp|h out of interfaces.cpp.
* The datalink layer chain is now instantiated per domain per interface,
not just per interface anymore.
* When a buffer reaches the network layer, it has no known interface yet, ie.
the ipv4|6|whatever modules need to set this manually.
* Added more debug output, and some new debugger commands, the control option
is now printed in clear text.
* Added hash_address() function to the address modules. Added "const" to
set_to_defaults() where needed.
* Fixed net_buffer's restore header functions offset use as reported by Atis.
* Improved buffer dump output, use the domain module to print the address if
available.
* Moved net_buffer::type into the union, as it's not needed by the upper layers
anymore.
* Moved IPv6 specific code from {add|remove}_default_route() to where it
belongs, but disabled it for the time being.
* Completely discarded useless ipv4_datagram module.
* Added ping6 to the build.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37794 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b216fbd0 28-Jul-2010 Axel Dörfler <axeld@pinc-software.de>

* Applied next work in progress patch by Atis that takes into account most of
my comments so far. Thanks!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37793 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 78888c44 15-Jul-2009 Axel Dörfler <axeld@pinc-software.de>

Applied patch by Ma Jie adding functionality needed by mDNSResponder:
* added new protocol method process_ancillary_data_no_container() that does not
need a container to fill the cmsghdr data.
* Added support for the IP_RECVDSTADDR option using this call.
* Implemented support for IP_MULTICAST_IF.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31585 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9871124e 17-Jun-2009 Axel Dörfler <axeld@pinc-software.de>

* Added missing hooks with a description of what's missing for clarity.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31077 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 11112327 07-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* Sockets now inherit from WeakReferenceable.
* This fixes the problem when a socket changes something with regards to its
parent.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30000 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f964cf07 15-Feb-2009 Axel Dörfler <axeld@pinc-software.de>

* No longer leaks the EndpointManagers at unload.
* Now uses an array instead of a doubly linked list to find the endpoint
manager for a domain.
* No longer locks the endpoint managers during TCP processing, which actually
made all TCP input serialized.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29210 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 276aa463 24-Jun-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Replaced the useless InitCheck() method in {Open,Multi}HashTable (it
always returned B_OK) by a Init() method, which sets the initial size
and returns an error, if that fails.
* Adjusted code using the classes accordingly. Replaced a few
InitCheck() methods in the network code by Init().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26127 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0c615a01 01-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed old mutex implementation and renamed cutex to mutex.
* Trivial adjustments of code using mutexes. Mostly removing the
mutex_init() return value check.
* Added mutex_lock_threads_locked(), which is called with the threads
spinlock being held. The spinlock is released while waiting, of
course. This function is useful in cases where the existence of the
mutex object is ensured by holding the threads spinlock.
* Changed the two instances in the VFS code where an IO context of
another team needs to be locked to use mutex_lock_threads_locked().
Before it required a semaphore-based mutex implementation.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25283 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 63cf3426 28-Apr-2008 Axel Dörfler <axeld@pinc-software.de>

* tcp_header::urgent_offset must be set in network byte order as well.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25243 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 895d7215 29-Apr-2008 Axel Dörfler <axeld@pinc-software.de>

* Added TCPEndpoint::GetOption(), currently only supports TCP_NODELAY, and
TCP_MAXSEG.
* Note, TCP_MAXSEG cannot be set yet.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25241 a95241bf-73f2-0310-859d-f6bbb57e9c96


# db4b6bc4 28-Apr-2008 Axel Dörfler <axeld@pinc-software.de>

* Merged _Receive() and _SegmentReceived().
* Cleanup, shuffled methods around, renamed methods, etc. - no functional changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25223 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6f58064f 07-Feb-2008 Axel Dörfler <axeld@pinc-software.de>

* Added flags field in net_protocol_module_info; there is currently a single
defined flag: NET_PROTOCOL_ATOMIC_MESSAGES.
* socket_send() now honours NET_PROTOCOL_ATOMIC_MESSAGES and returns either
EMSGSIZE if the data to be send is larger than net_socket::send::buffer_size,
or divides the data in appropriately sized chunks.
* This fixes sending >=64K over a TCP socket at once (TCP would just have
returned an error in that case).
* TCP now overrides the default send buffer size (to 32768 for now).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23915 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1d0b34fa 23-Oct-2007 Axel Dörfler <axeld@pinc-software.de>

* If a new buffer had its last part in common with an existing larger buffer,
BufferQueue::Add() tried to remove a negative amount of bytes. This could
bring a download to a complete halt (as could the other one due to the list
link mixup).
* While the RTT computation still seems to work not that good (with a drop quote
of 50% I would easily reach retransmit timeouts of 80 secs), TCP should now
work a lot better on a flaky connection.
* Renamed _GetMSS() to _MaxSegmentSize().
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22677 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 15ab0bcf 21-Oct-2007 Axel Dörfler <axeld@pinc-software.de>

* int32_t, uint32_t are now of type "int", and no longer of type "long".
This should help to reduce the number of warnings imported code will throw
during compilation (helps a lot with tcpdump, for example).
* Since long is 64 bit on 64 bit platforms, we might want to think about doing
that change for the Haiku types int32 and uint32 as well.
* Fixed several occurences of hidden type problems.
* Fixed build of the stack and TCP under BeOS.
* Fixed incorrect typedef in socket_interface.h.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22643 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fe0ab286 23-May-2007 Hugo Santos <hugosantos@nowhere.fake>

tcp: no longer need recursive locking.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21216 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 79a0d252 22-May-2007 Hugo Santos <hugosantos@nowhere.fake>

net_buffer: preparing for better metadata management


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21210 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 98eb7f44 20-May-2007 Hugo Santos <hugosantos@nowhere.fake>

TCP: getsockopt was missing. fixes #1225


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21176 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a0a553ca 08-May-2007 Hugo Santos <hugosantos@nowhere.fake>

tcp: allow TCP_NODELAY to be set


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21069 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8c5520d6 03-May-2007 Hugo Santos <hugosantos@nowhere.fake>

use a appropriate naming for structure fields.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21016 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 785e7ef7 04-May-2007 Hugo Santos <hugosantos@nowhere.fake>

renamed TCP's TSval/TSecr


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21014 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 15945a11 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added 'tcp_endpoints' and 'tcp_endpoint' debugger commands.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20909 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 226bb7a9 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a nice C-induced issue which was making us rewrite stuff.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20823 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 66a4a428 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added Recv-Q/Send-Q output to netstat.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20819 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 53f23f85 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

partially rewrote TCP's endpoint manager. Fixes #1173


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20814 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 739e9942 20-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

TCP: added SACK definitions and option processing.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20775 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 530017c6 20-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

check option length when processing TCP options.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20774 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2445c00e 19-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some internal reorganization of getsockopt()/setsockopt() handling. TCP is now able to fully use the application requested sender/receiver buffer sizes for improved performance.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20764 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1d63ea33 18-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some TCP performance improvements.

- support TCP fast retransmit/fast recovery.
- maintain the RTT average time and update the retransmit timeout accordingly.
- improvements to TCP Slow start / congestion avoidance.
- better handling of the retransmission timer.
- properly size segments taking the TCP options length into consideration.
- as an interim fix, update the SendQ/RecvQ sizes on Connect().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20748 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4ee08841 16-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

assorted TCP fixes.

- fixed the locking for spawned connections and accept()s.
- return EMSGSIZE if the user is trying to write more data than the send buffer can hold.
- fixed a crash when receiving a RST while the connection is being closed.
- don't wake up readers when the connection gets established.
- endpoint managers lock must be recursive to properly work with spawn'ed sockets.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20727 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ca1b900b 15-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

support RFC 1323's TCP Timestamps (we are still not updating our estimator though).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20719 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 03d7f17e 15-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

made TCP handle multiple domains.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20718 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d5b5a2c2 15-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

introduced Checksum::PseudoHeader helper.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20717 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6a606180 15-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

glued the multicast filter handling to the receive path: we are now capable of receiving multicast frames in datagram sockets.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20695 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 658a5506 13-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

use module_dependencies to load the required modules by udp, tcp, ipv4, icmp and arp.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20676 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d438fa4c 12-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added buffer, datalink and socket module references to the stack module so we don't have to load them in each other module.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20673 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6c353509 11-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

moved address selection logic to a new 'get_buffer_route'.

- IPv4 now assumes the addresses it is supplied in send_routed_data are already the appropriate ones.
- made the Data(), operator* and operator-> methods in NetBufferFieldReader const so we can use them in the same expression as the constructor.
- fixed an issue with UDP where the wrong source address could be used in the calculating the checksum.
- changed ipv4_print_address to use the more common 0.0.0.0 format.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20660 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 87001e05 11-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some NetBufferUtility revamp.

- introduced base NetBufferFieldReader which deals with obtaining a continuguous field to deal with.
- renamed Detach() to Sync() to better express the fact that we may be writing to the buffer.
- Fixed IPv4's and ICMP's checksum calculation as it assumed the underlying header was contiguous.
- ICMP is now able to reply to ICMP Echo Requests which were split across data nodes.
- in split_buffer(), make sure we were able to trim() the new buffer before damaging the original one.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20657 a95241bf-73f2-0310-859d-f6bbb57e9c96


# af56b5b2 10-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed add_tcp_header() as it wasn't considering the possibility that prepending data would not result in a contiguous buffer. This would result in wrong checksums for apparent no reason.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20643 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a7edede4 09-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed multiple TCP issues.

- Moved FIN handling to after Segment Text handling, it matches the RFC and fixes a possible issue with a user missing some final segment data when receiving a FIN.
- Fixed the FIN handling to better terminate connections (no more senseless chatter in the end with RSTs etc).
- When Bind()ing, set the socket address so a call to getsockname() gets the allocated port correctly.
- After reaching the ESTABLISHED state, try to wake all pending threads (still needs work).
- Corrected the maximum amount of time we wait in SendData() to respect socket->send.timeout.
- Now ReadData() behaves correctly in all possible states.
- There was a missing handling of MSG_DONTWAIT, fixed.
- Better internal handling of PSH.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20624 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f2893088 05-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed another TCP issue: if we were in TIME_WAIT and we received a retransmission or delayed ack, TCP would wrongly bindly immediatly acknowledge.

* Moved TIME_WAIT and CLOSED handling to common Receive() path that does Sequence checking and further tests.
* Moved setting FLAG_NO_RECEIVE to the end of Receive() when FIN is set so we can check for NO_RECEIVE before processing the segment text just after processing FIN.
* Added a new action DELETE to be used when in TIME_WAIT and we receive a good RST


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20572 a95241bf-73f2-0310-859d-f6bbb57e9c96


# af3a31f7 01-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

Calmed down the networking stack a lot - since it basically works, there is no
reason to slow it down with debug output that much; this will also help investigating
some issues where you just aren't interested in most of the output.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19672 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c304c8ee 01-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

Added some more (optional) debug output.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19665 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8dfd7ea7 18-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

* Implemented a basic infrastructure for a netstat command.
* Started a netstat command.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19560 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9299a7ff 04-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

Now use a random (based on system_time()) initial sequence number - this also
revealed a bug in the recognition of faulty SYNs.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19419 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 442c0979 04-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

Renamed class TCPConnection to TCPEndpoint.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19418 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9cbe6ce2 04-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

Rewrote how bind() works:
* there are now two hash tables: one for connections, and one for ports
* the first one is used to find the endpoint for incoming connections
* the latter is used to check if the address to bind() to is still available
(incl. support for SO_REUSEADDR, and SO_REUSEPORT). Specialising an existing
socket is not allowed, though; wildcard sockets need to be started last.
* the TCPConnection class now has a pointer to the next endpoint with the
same port number - this list is scanned for the existing bound sockets
on that port.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19416 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 78e96e0c 01-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

* If you send more than the maximum buffer size at once, TCP will now block
until it could send all the data.
* The window shift option can now also be send if the actual option is zero to
indicate we support this option.
* If the window shift is not specified, we'll fall back to 0 for our receive
window as well now.
* _SendQueued() now resets the segment options after SYN.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19407 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 02894e36 30-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Reintroduced the accept semaphore: it will be inherited by the new connections
of a LISTEN socket.
* Reading data should now more or less work, too.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19401 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 75dc7cb5 28-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Renamed _SendQueuedData() to _SendQueued(), and made it independent from the
"flags" parameter - this can't be used with retransmitting anyway, and since
the flags are actually fixed per state, the previous solution didn't really
make much sense.
* Made _SendQueued() work a lot more like BSD's tcp_output().
* We can now send even large buffers that need more than one segment at once.
* Added a simple recursive locking mechanism for now - this should be done
differently, though, as we want to have good performance in full duplex mode.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19384 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 85359054 27-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

Some more work-in-progress:
* the TCPConnection::Receive() method is now more or less working as it should;
of course, there are a number of missing things (like round-trip time estimation,
retransmit timers, receive window update, ...).
* reply_with_reset() was broken, and accidently always send the segment it should
answer with reset... (causing an endless loop during connect)
* BufferQueue::RemoveUntil() must always set the fFirstSequence member to the new
sequence, or you will never be able to send anything with that queue (as the
data in it would be no longer contiguous).
* connects, sendings (only single segments), and receiving data is working now
basically (but very incomplete); retransmits or even subsequent transmits (if
the data to be sent doesn't fit in one segment) doesn't work yet, so you better
don't lose any segments :-)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19378 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1166a4f9 26-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

Work-in-progress on TCP:
* Changed the implementation to be more BSD like; state variables are now
the same set as usual.
* The BufferQueue didn't use the initial sequence correctly (problems with
SYN sequence).
* It now also removes data out of the current data set (ie. data that was
already read by the application).
* BufferQueue::Get() also didn't work correctly (the version used by sending
data).
* Fixed various issues around the code like incorrect handling of unexpected
data.
* TCP options don't need the end-of-options marker in case they fill up the
data already, also, the end-of-options marker doesn't need to be padded.
* Options are now only processed during SYN - other options may come
later (timestamps are candidate number one).
* Also broke what was working before: connections do no longer work!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19376 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3567d0cb 25-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

Added more than one option was broken.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19371 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 75743fcd 20-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Implemented adding/processing TCP options; so far only "max segment size" (MSS)
is really supported.
* Added TCP option fields to the tcp_segment_header structure - they are filled
in on receive, and add_tcp_header() now gets a tcp_segment_header as well, and
will add any options automatically.
* Fixed some minor bugs (connection with passive open had wrong state after connect).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19333 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 30ea523a 19-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Big rework of TCP - doesn't have any additional features yet, though, even
though it can now connect to itself (and should, in theory, also be able
to connect to other TCP implemenations).
* Separated the big state machine from ReceiveData() into several smaller sized
methods.
* Moved reset and acknowledgement handling for all kind of receives to a common
place in tcp_receive_data().
* Removed locking for now - the previous locking approach was wrong due to a
number of reasons: the previous version deadlocked when it had to connect
locally, and it also didn't take into account that TCP is a full-duplex
protocol; it's not wise to only be able to manage one direction at a time
if that's not really needed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19329 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 31d3ef17 06-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Some cleanup, renamed some flags/constants to be a bit clearer (even though the states
now deviate from what other use to have, ie. FreeBSD).
* Replaced macros with inline methods.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19215 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c35b04de 02-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Moved the TCPConnection class into its own file.
* Added some missing result checks, mostly for allocations.
* Fixed a wrong precendence with the ?: operator
* Some minor cleanup.
* Renamed sBufferModule to gBufferModule - the header expects it to be a global,
so it should be named like one.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19178 a95241bf-73f2-0310-859d-f6bbb57e9c96


# db893fd8 05-Oct-2006 Andrew Galante <agalante@nowhere.fake>

Sending data over TCP should work now. Receiving is still MIA.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19007 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7bfdb02e 31-Aug-2006 Andrew Galante <agalante@nowhere.fake>

The full TCP state machine should be working now, with the exception of the LISTEN state. It cannot yet transfer data though - that will be implemented next. Connections are only made from port 40000 though, ephemeral ports are not yet implemented.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18729 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 806e2ef6 28-Aug-2006 Andrew Galante <agalante@nowhere.fake>

Three way handshake is now functional. Need to add error conditions and graceful cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18682 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b6117592 24-Aug-2006 Andrew Galante <agalante@nowhere.fake>

TCP module now refuses connections to closed ports.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18616 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 171ee972 21-Aug-2006 Andrew Galante <agalante@nowhere.fake>

TCP Socket creation and destruction implemented, as well as the beginning of the TCP state-machine

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18558 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 804ee69a 11-Aug-2006 Axel Dörfler <axeld@pinc-software.de>

* Fixed crashing bug on startup.
Andrew, TCP is actually used in the build, so please test if it crashes before
committing.
* Fixed some minor style issues.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18486 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6bfaab8a 10-Aug-2006 Andrew Galante <agalante@nowhere.fake>

Beginning of TCP implementation

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18478 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c22d69bf 08-Aug-2006 Axel Dörfler <axeld@pinc-software.de>

* Completed the previous commit and merger of the team/network/new_stack branch.
* Removed ppp_up and pppcontrol from the image for now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18457 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 75bb8dc65079b280895c369e7b339387e25ebcdf 05-Nov-2010 Axel Dörfler <axeld@pinc-software.de>

* Applied kaliber's patch part of ticket #6789, thanks! This makes the code not
only more readable, but also working correctly.
* Solved the problem stippi outlined differently, by checking whether length is
greater size for unsupported options.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39311 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 21c8f94c7de6babd0528731872c6a728bb52986b 05-Nov-2010 Stephan Aßmus <superstippi@gmx.de>

I don't understand much about the code in question, but the ticket #6789
hints at a possible problem: Within the process_options() function, the
code does not make sure that size is a multiple of the option length
(unless I missed something) and thus the loop could wrap the unsigned
size variable, and not exit as intended. Make size an ssize_t and cast
where appropriate, after making sure it's initially a positive value.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39309 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2b4154458a820aa0b55b2800de9f0a13ea6ec1e2 04-Aug-2010 Axel Dörfler <axeld@pinc-software.de>

* Finished groundwork on ICMP by introducing a completely protocol agnostic
error mechanism.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37896 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 61729d9323a555b9025ef6ebeb85dc1627f8acf7 28-Jul-2010 Axel Dörfler <axeld@pinc-software.de>

* Reworked the complete stack to allow more than one address per network
interface - this caused quite a number of changes.
* Network interfaces, and its addresses are now reference counted (not yet
complete, though, InterfaceAddresses need to hold references to their
interface as well).
* There are two known regressions of this commit that I will fix later:
- you cannot remove interfaces anymore
- IPv4 multicast was broken anyway, but now it's disabled, too.
* Moved a device_interfaces.cpp|h out of interfaces.cpp.
* The datalink layer chain is now instantiated per domain per interface,
not just per interface anymore.
* When a buffer reaches the network layer, it has no known interface yet, ie.
the ipv4|6|whatever modules need to set this manually.
* Added more debug output, and some new debugger commands, the control option
is now printed in clear text.
* Added hash_address() function to the address modules. Added "const" to
set_to_defaults() where needed.
* Fixed net_buffer's restore header functions offset use as reported by Atis.
* Improved buffer dump output, use the domain module to print the address if
available.
* Moved net_buffer::type into the union, as it's not needed by the upper layers
anymore.
* Moved IPv6 specific code from {add|remove}_default_route() to where it
belongs, but disabled it for the time being.
* Completely discarded useless ipv4_datagram module.
* Added ping6 to the build.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37794 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b216fbd0774446feb184ec1be17bb52bcbd75bbe 28-Jul-2010 Axel Dörfler <axeld@pinc-software.de>

* Applied next work in progress patch by Atis that takes into account most of
my comments so far. Thanks!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37793 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 78888c44da518b5a28135c7b3e79013e283789d4 15-Jul-2009 Axel Dörfler <axeld@pinc-software.de>

Applied patch by Ma Jie adding functionality needed by mDNSResponder:
* added new protocol method process_ancillary_data_no_container() that does not
need a container to fill the cmsghdr data.
* Added support for the IP_RECVDSTADDR option using this call.
* Implemented support for IP_MULTICAST_IF.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31585 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9871124eb2ceffad94e7c5bb54b9dd25250f8cb1 17-Jun-2009 Axel Dörfler <axeld@pinc-software.de>

* Added missing hooks with a description of what's missing for clarity.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31077 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1111232758bd76e4ce4e7f6daddd7334249db818 07-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* Sockets now inherit from WeakReferenceable.
* This fixes the problem when a socket changes something with regards to its
parent.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30000 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f964cf077283ad2f5b381de0c0374dac760bd615 15-Feb-2009 Axel Dörfler <axeld@pinc-software.de>

* No longer leaks the EndpointManagers at unload.
* Now uses an array instead of a doubly linked list to find the endpoint
manager for a domain.
* No longer locks the endpoint managers during TCP processing, which actually
made all TCP input serialized.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29210 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 276aa463efb0cc5b6562c46b540c01df679f77ba 24-Jun-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Replaced the useless InitCheck() method in {Open,Multi}HashTable (it
always returned B_OK) by a Init() method, which sets the initial size
and returns an error, if that fails.
* Adjusted code using the classes accordingly. Replaced a few
InitCheck() methods in the network code by Init().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26127 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0c615a01ae49634aaf59fbe35b3d55b3bb8890df 01-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed old mutex implementation and renamed cutex to mutex.
* Trivial adjustments of code using mutexes. Mostly removing the
mutex_init() return value check.
* Added mutex_lock_threads_locked(), which is called with the threads
spinlock being held. The spinlock is released while waiting, of
course. This function is useful in cases where the existence of the
mutex object is ensured by holding the threads spinlock.
* Changed the two instances in the VFS code where an IO context of
another team needs to be locked to use mutex_lock_threads_locked().
Before it required a semaphore-based mutex implementation.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25283 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 63cf34266431f41da827431ceed82e7bc2bb48a4 28-Apr-2008 Axel Dörfler <axeld@pinc-software.de>

* tcp_header::urgent_offset must be set in network byte order as well.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25243 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 895d7215fbb32fc62277f028b21adcda9320fcd6 29-Apr-2008 Axel Dörfler <axeld@pinc-software.de>

* Added TCPEndpoint::GetOption(), currently only supports TCP_NODELAY, and
TCP_MAXSEG.
* Note, TCP_MAXSEG cannot be set yet.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25241 a95241bf-73f2-0310-859d-f6bbb57e9c96


# db4b6bc46caaeb073a5e176a89ea695c0b52b70e 28-Apr-2008 Axel Dörfler <axeld@pinc-software.de>

* Merged _Receive() and _SegmentReceived().
* Cleanup, shuffled methods around, renamed methods, etc. - no functional changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25223 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6f58064f104ef231faed3c2259885065c4242eaa 07-Feb-2008 Axel Dörfler <axeld@pinc-software.de>

* Added flags field in net_protocol_module_info; there is currently a single
defined flag: NET_PROTOCOL_ATOMIC_MESSAGES.
* socket_send() now honours NET_PROTOCOL_ATOMIC_MESSAGES and returns either
EMSGSIZE if the data to be send is larger than net_socket::send::buffer_size,
or divides the data in appropriately sized chunks.
* This fixes sending >=64K over a TCP socket at once (TCP would just have
returned an error in that case).
* TCP now overrides the default send buffer size (to 32768 for now).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23915 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1d0b34faae63ccea578c5f8f51038afa16fb825a 23-Oct-2007 Axel Dörfler <axeld@pinc-software.de>

* If a new buffer had its last part in common with an existing larger buffer,
BufferQueue::Add() tried to remove a negative amount of bytes. This could
bring a download to a complete halt (as could the other one due to the list
link mixup).
* While the RTT computation still seems to work not that good (with a drop quote
of 50% I would easily reach retransmit timeouts of 80 secs), TCP should now
work a lot better on a flaky connection.
* Renamed _GetMSS() to _MaxSegmentSize().
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22677 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 15ab0bcf01ef7bd7323d9b2da55906bafbb40fd3 21-Oct-2007 Axel Dörfler <axeld@pinc-software.de>

* int32_t, uint32_t are now of type "int", and no longer of type "long".
This should help to reduce the number of warnings imported code will throw
during compilation (helps a lot with tcpdump, for example).
* Since long is 64 bit on 64 bit platforms, we might want to think about doing
that change for the Haiku types int32 and uint32 as well.
* Fixed several occurences of hidden type problems.
* Fixed build of the stack and TCP under BeOS.
* Fixed incorrect typedef in socket_interface.h.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22643 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fe0ab2867a7f7d03b8bdc231592807553aee72f3 23-May-2007 Hugo Santos <hugosantos@nowhere.fake>

tcp: no longer need recursive locking.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21216 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 79a0d25245275ef5f65afd610279dc9befffd65e 22-May-2007 Hugo Santos <hugosantos@nowhere.fake>

net_buffer: preparing for better metadata management


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21210 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 98eb7f44f39218037f7809dca5d71d1f638f75c0 20-May-2007 Hugo Santos <hugosantos@nowhere.fake>

TCP: getsockopt was missing. fixes #1225


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21176 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a0a553caa3d17608dcda994338aa3f8ca81cb674 08-May-2007 Hugo Santos <hugosantos@nowhere.fake>

tcp: allow TCP_NODELAY to be set


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21069 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8c5520d67a885acaff48203692b88f0707c88ff4 03-May-2007 Hugo Santos <hugosantos@nowhere.fake>

use a appropriate naming for structure fields.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21016 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 785e7ef7dd751385821998a5cf513d14f2456b3e 04-May-2007 Hugo Santos <hugosantos@nowhere.fake>

renamed TCP's TSval/TSecr


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21014 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 15945a11c67002b10f04a6207eea5637e6c17b45 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added 'tcp_endpoints' and 'tcp_endpoint' debugger commands.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20909 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 226bb7a9d4269c6d5d1dad119fa57a57edd0629e 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a nice C-induced issue which was making us rewrite stuff.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20823 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 66a4a428020db4e26cda68ffe4b3dd6f1bed88c2 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added Recv-Q/Send-Q output to netstat.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20819 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 53f23f85a2725c8fc31c7a874256084c7c623d86 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

partially rewrote TCP's endpoint manager. Fixes #1173


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20814 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 739e99427818f50d79c5de012db1d4c53727dcbc 20-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

TCP: added SACK definitions and option processing.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20775 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 530017c6c9abcba7415cdf0ac1a7717b7622da24 20-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

check option length when processing TCP options.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20774 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2445c00e6420e2b365cba47c758b66fc04e75f59 19-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some internal reorganization of getsockopt()/setsockopt() handling. TCP is now able to fully use the application requested sender/receiver buffer sizes for improved performance.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20764 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1d63ea33723fa8f3afac5a98fdb36b5bfe6839ee 18-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some TCP performance improvements.

- support TCP fast retransmit/fast recovery.
- maintain the RTT average time and update the retransmit timeout accordingly.
- improvements to TCP Slow start / congestion avoidance.
- better handling of the retransmission timer.
- properly size segments taking the TCP options length into consideration.
- as an interim fix, update the SendQ/RecvQ sizes on Connect().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20748 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4ee088419f8fdc733b6cb0606e2556b176316788 16-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

assorted TCP fixes.

- fixed the locking for spawned connections and accept()s.
- return EMSGSIZE if the user is trying to write more data than the send buffer can hold.
- fixed a crash when receiving a RST while the connection is being closed.
- don't wake up readers when the connection gets established.
- endpoint managers lock must be recursive to properly work with spawn'ed sockets.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20727 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ca1b900bdb8cd280418ade417a2f81b5b4b50a91 15-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

support RFC 1323's TCP Timestamps (we are still not updating our estimator though).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20719 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 03d7f17e07da19253587845073315010febc031a 15-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

made TCP handle multiple domains.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20718 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d5b5a2c2f8c70f0e24cdf2e3a7fc9c4faa22e4c3 15-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

introduced Checksum::PseudoHeader helper.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20717 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6a60618094d288e845e7384ec6ab5b4e63f742e5 15-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

glued the multicast filter handling to the receive path: we are now capable of receiving multicast frames in datagram sockets.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20695 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 658a550639d1b3ec33c934583d065c81bee46298 13-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

use module_dependencies to load the required modules by udp, tcp, ipv4, icmp and arp.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20676 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d438fa4c124c7dd113ccfb6f9badae5d18354af0 12-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added buffer, datalink and socket module references to the stack module so we don't have to load them in each other module.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20673 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6c35350908905903b5c150154b0da9698ca8943a 11-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

moved address selection logic to a new 'get_buffer_route'.

- IPv4 now assumes the addresses it is supplied in send_routed_data are already the appropriate ones.
- made the Data(), operator* and operator-> methods in NetBufferFieldReader const so we can use them in the same expression as the constructor.
- fixed an issue with UDP where the wrong source address could be used in the calculating the checksum.
- changed ipv4_print_address to use the more common 0.0.0.0 format.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20660 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 87001e059c8012ef40c462709833b5ae4212fb4a 11-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some NetBufferUtility revamp.

- introduced base NetBufferFieldReader which deals with obtaining a continuguous field to deal with.
- renamed Detach() to Sync() to better express the fact that we may be writing to the buffer.
- Fixed IPv4's and ICMP's checksum calculation as it assumed the underlying header was contiguous.
- ICMP is now able to reply to ICMP Echo Requests which were split across data nodes.
- in split_buffer(), make sure we were able to trim() the new buffer before damaging the original one.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20657 a95241bf-73f2-0310-859d-f6bbb57e9c96


# af56b5b233a200d83b427d967bac7453f4043f6f 10-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed add_tcp_header() as it wasn't considering the possibility that prepending data would not result in a contiguous buffer. This would result in wrong checksums for apparent no reason.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20643 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a7edede46f377bf9b0f2710079a09f22df2771ca 09-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed multiple TCP issues.

- Moved FIN handling to after Segment Text handling, it matches the RFC and fixes a possible issue with a user missing some final segment data when receiving a FIN.
- Fixed the FIN handling to better terminate connections (no more senseless chatter in the end with RSTs etc).
- When Bind()ing, set the socket address so a call to getsockname() gets the allocated port correctly.
- After reaching the ESTABLISHED state, try to wake all pending threads (still needs work).
- Corrected the maximum amount of time we wait in SendData() to respect socket->send.timeout.
- Now ReadData() behaves correctly in all possible states.
- There was a missing handling of MSG_DONTWAIT, fixed.
- Better internal handling of PSH.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20624 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f2893088ba25b514acf67d0fdf0d965d6aa4b317 05-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed another TCP issue: if we were in TIME_WAIT and we received a retransmission or delayed ack, TCP would wrongly bindly immediatly acknowledge.

* Moved TIME_WAIT and CLOSED handling to common Receive() path that does Sequence checking and further tests.
* Moved setting FLAG_NO_RECEIVE to the end of Receive() when FIN is set so we can check for NO_RECEIVE before processing the segment text just after processing FIN.
* Added a new action DELETE to be used when in TIME_WAIT and we receive a good RST


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20572 a95241bf-73f2-0310-859d-f6bbb57e9c96


# af3a31f770fcd8b7e8c5171342cba155bef6dc9e 01-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

Calmed down the networking stack a lot - since it basically works, there is no
reason to slow it down with debug output that much; this will also help investigating
some issues where you just aren't interested in most of the output.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19672 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c304c8ee1ae5f290ff4a329caf2f02a5e51a246f 01-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

Added some more (optional) debug output.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19665 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8dfd7ea7bf7714ff094a69f120771e6c6465262e 18-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

* Implemented a basic infrastructure for a netstat command.
* Started a netstat command.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19560 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9299a7ff2a49158a70c21a5b3988e6afbf5d6ef7 04-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

Now use a random (based on system_time()) initial sequence number - this also
revealed a bug in the recognition of faulty SYNs.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19419 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 442c0979467981e68c45820d6e5d931a13c2ad82 04-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

Renamed class TCPConnection to TCPEndpoint.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19418 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9cbe6ce20025d6de096cbd167bb1f83669d1032a 04-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

Rewrote how bind() works:
* there are now two hash tables: one for connections, and one for ports
* the first one is used to find the endpoint for incoming connections
* the latter is used to check if the address to bind() to is still available
(incl. support for SO_REUSEADDR, and SO_REUSEPORT). Specialising an existing
socket is not allowed, though; wildcard sockets need to be started last.
* the TCPConnection class now has a pointer to the next endpoint with the
same port number - this list is scanned for the existing bound sockets
on that port.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19416 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 78e96e0cfef40fd01d5ca4663c8e1cebba82ba5c 01-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

* If you send more than the maximum buffer size at once, TCP will now block
until it could send all the data.
* The window shift option can now also be send if the actual option is zero to
indicate we support this option.
* If the window shift is not specified, we'll fall back to 0 for our receive
window as well now.
* _SendQueued() now resets the segment options after SYN.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19407 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 02894e3670b7aac5ae57c6576b9a3e83c24dcf4f 30-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Reintroduced the accept semaphore: it will be inherited by the new connections
of a LISTEN socket.
* Reading data should now more or less work, too.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19401 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 75dc7cb58a6c6210dd12c07cdad7ba961fb19cd8 28-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Renamed _SendQueuedData() to _SendQueued(), and made it independent from the
"flags" parameter - this can't be used with retransmitting anyway, and since
the flags are actually fixed per state, the previous solution didn't really
make much sense.
* Made _SendQueued() work a lot more like BSD's tcp_output().
* We can now send even large buffers that need more than one segment at once.
* Added a simple recursive locking mechanism for now - this should be done
differently, though, as we want to have good performance in full duplex mode.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19384 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8535905415b70f3516daef470a219d38eafd9097 27-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

Some more work-in-progress:
* the TCPConnection::Receive() method is now more or less working as it should;
of course, there are a number of missing things (like round-trip time estimation,
retransmit timers, receive window update, ...).
* reply_with_reset() was broken, and accidently always send the segment it should
answer with reset... (causing an endless loop during connect)
* BufferQueue::RemoveUntil() must always set the fFirstSequence member to the new
sequence, or you will never be able to send anything with that queue (as the
data in it would be no longer contiguous).
* connects, sendings (only single segments), and receiving data is working now
basically (but very incomplete); retransmits or even subsequent transmits (if
the data to be sent doesn't fit in one segment) doesn't work yet, so you better
don't lose any segments :-)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19378 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1166a4f9b5ac1afc8c89751b2f5158624173cacf 26-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

Work-in-progress on TCP:
* Changed the implementation to be more BSD like; state variables are now
the same set as usual.
* The BufferQueue didn't use the initial sequence correctly (problems with
SYN sequence).
* It now also removes data out of the current data set (ie. data that was
already read by the application).
* BufferQueue::Get() also didn't work correctly (the version used by sending
data).
* Fixed various issues around the code like incorrect handling of unexpected
data.
* TCP options don't need the end-of-options marker in case they fill up the
data already, also, the end-of-options marker doesn't need to be padded.
* Options are now only processed during SYN - other options may come
later (timestamps are candidate number one).
* Also broke what was working before: connections do no longer work!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19376 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3567d0cb1b9d04782b834d5ec426f93568d5a051 25-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

Added more than one option was broken.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19371 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 75743fcd65f5fbef6d19fcbff98b16b681036132 20-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Implemented adding/processing TCP options; so far only "max segment size" (MSS)
is really supported.
* Added TCP option fields to the tcp_segment_header structure - they are filled
in on receive, and add_tcp_header() now gets a tcp_segment_header as well, and
will add any options automatically.
* Fixed some minor bugs (connection with passive open had wrong state after connect).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19333 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 30ea523ad10945ebf4562595952e78f9ae95878d 19-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Big rework of TCP - doesn't have any additional features yet, though, even
though it can now connect to itself (and should, in theory, also be able
to connect to other TCP implemenations).
* Separated the big state machine from ReceiveData() into several smaller sized
methods.
* Moved reset and acknowledgement handling for all kind of receives to a common
place in tcp_receive_data().
* Removed locking for now - the previous locking approach was wrong due to a
number of reasons: the previous version deadlocked when it had to connect
locally, and it also didn't take into account that TCP is a full-duplex
protocol; it's not wise to only be able to manage one direction at a time
if that's not really needed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19329 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 31d3ef17d8bc8425cb15b76b9dc48547533d1499 06-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Some cleanup, renamed some flags/constants to be a bit clearer (even though the states
now deviate from what other use to have, ie. FreeBSD).
* Replaced macros with inline methods.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19215 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c35b04de314ab7f18763546366ea30eb8ae53997 02-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

* Moved the TCPConnection class into its own file.
* Added some missing result checks, mostly for allocations.
* Fixed a wrong precendence with the ?: operator
* Some minor cleanup.
* Renamed sBufferModule to gBufferModule - the header expects it to be a global,
so it should be named like one.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19178 a95241bf-73f2-0310-859d-f6bbb57e9c96


# db893fd8d8c415c8a10ef78707df502095d01054 05-Oct-2006 Andrew Galante <agalante@nowhere.fake>

Sending data over TCP should work now. Receiving is still MIA.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19007 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7bfdb02ea8a995d84262d444f52bb1f2d829f7bb 31-Aug-2006 Andrew Galante <agalante@nowhere.fake>

The full TCP state machine should be working now, with the exception of the LISTEN state. It cannot yet transfer data though - that will be implemented next. Connections are only made from port 40000 though, ephemeral ports are not yet implemented.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18729 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 806e2ef627cbcf37cc7e2ab394c351a398b300df 28-Aug-2006 Andrew Galante <agalante@nowhere.fake>

Three way handshake is now functional. Need to add error conditions and graceful cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18682 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b611759230abb8e1a794a6d68c239e66d54ea4d8 24-Aug-2006 Andrew Galante <agalante@nowhere.fake>

TCP module now refuses connections to closed ports.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18616 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 171ee97271e81914be576ad9121cea12353a7fb4 21-Aug-2006 Andrew Galante <agalante@nowhere.fake>

TCP Socket creation and destruction implemented, as well as the beginning of the TCP state-machine

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18558 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 804ee69a783f5c96157b586ed2d74e28e937ef82 11-Aug-2006 Axel Dörfler <axeld@pinc-software.de>

* Fixed crashing bug on startup.
Andrew, TCP is actually used in the build, so please test if it crashes before
committing.
* Fixed some minor style issues.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18486 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6bfaab8ab3f48a0b8c9ea8ebb6d3a5fe715e26f3 10-Aug-2006 Andrew Galante <agalante@nowhere.fake>

Beginning of TCP implementation

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18478 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c22d69bf1f5f60f7ebddd79108a53c8f97f300fe 08-Aug-2006 Axel Dörfler <axeld@pinc-software.de>

* Completed the previous commit and merger of the team/network/new_stack branch.
* Removed ppp_up and pppcontrol from the image for now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18457 a95241bf-73f2-0310-859d-f6bbb57e9c96