History log of /haiku/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp
Revision Date Author Comments
# 51bce128 12-Apr-2024 Jérôme Duval <jerome.duval@gmail.com>

tcp: don't allow read on listening sockets

fix #18884

Change-Id: If4e337316ea4faa2f00fa73295c57e93de0a2cbc
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7616
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Rene Gollent <rene@gollent.com>


# c9eb52ae 23-Mar-2024 Augustin Cavalier <waddlesplash@gmail.com>

TCP: Check return value of ProtocolSocket::Open().


# 49d736ca 04-Mar-2024 Jérôme Duval <jerome.duval@gmail.com>

tcp: actually send finish when needed by the state

fix #18327 after hrev57546

Change-Id: I352a325f3c2068d06996c278246f7a30f5bfcbe0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7504
Reviewed-by: nephele nephele <nep-git@packageloss.eu>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# fe8f7e31 28-Feb-2024 Augustin Cavalier <waddlesplash@gmail.com>

TCP: Let EndpointManager set Local and Peer addresses.

The Local address will apparently be set by the module->bind() call
in EndpointManager::_Bind(), while the Peer address will be set by
EndpointManager::SetConnection().

This means that if BindChild() fails for some reason, we will now not
be left in a state where the LocalAddress is set but we are unbound.
That could be the cause of #17058, as that panic occurs when
TCPEndpoint::IsBound() returns true, but we have not been added to
the bound hash.
Change-Id: I3121d0d99289d8cf83c7ed3c3e2d413feb6dad70
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7490
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# 4fec8175 29-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

TCP: Refactor sending logic.

* Break segment setup out into its own method.

* Break the actual sending logic out into its own method.
- While at it, remove some old/obsolete comments and
rearrange some of the logic to match.

* Separate the send-pure-ACK and send-data methods.
- This way, the "force" parameters will act differently,
specifying "force" to SendAcknowledge() may generate
a duplicate ACK, while to SendQueued() it will either
send data smaller than a segment size, or do nothing.

Functional changes should be minor, and the code
meanwhile should be much easier to read.

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


# c4f37b00 29-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

TCP: Initiate a send before waiting in SendData().

Otherwise, we will sit around here waiting forever,
with the send queue full but nothing actually sending
data.


# 141cc593 30-Dec-2023 Augustin Cavalier <waddlesplash@gmail.com>

TCP: Actually invoke SendQueued when the window widens.

IMMEDIATE_ACKNOWLEDGE invokes SendQueued ... but with
a send window size forced to 0, so it just generates an
ACK (or a duplicate ACK as the case may be), and doesn't
actually trigger sending of data.

So, adjust the check, introduce a new action flag, and
invoke it properly.

Fixes traffic stalls caused by waiting for the
persist timeout to occur.

This amends hrev51540 (yes, from 2017.)

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


# d7c71d7b 30-Dec-2023 Augustin Cavalier <waddlesplash@gmail.com>

TCP: Coalesce more ACKs in DelayedAcknowledge.

First, we don't need to generate ACKs for every other
segment received, only every second full-size segment
or within 500ms, as the comment notes. So check the
receive window size before deciding to send an ACK
immediately.

Second, let the timeout routine handle sending the ACK
even in the immediate invocation case. This way, we
don't spend time in receive routines waiting for the
send path locks, and also multiple packets received in
quick succession will have one ACK generated instead of
many.

Also, following the previous commit, the timeout routine
will avoid generating duplicate ACKs now. In the case
where a duplicate ACK really needs to be generated,
DelayedAcknowledge won't be used anyway.

Inspired by ambroff's remarks and patch in
comment:14 of #18203.

Greatly reduces the number of ACKs generated,
and increases throughput due to less duplicate ACKs
causing congestion logic to kick in.

Change-Id: I37991464b1a802aceb3e2b453df8dc4cb2e14ce5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7284
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 5e7d399e 30-Dec-2023 Augustin Cavalier <waddlesplash@gmail.com>

TCP: Check state in Persist and DelayedAcknowledge timeouts.

As the comment already notes, it's possible that we wind up
in the timeout routine despite the timer being cancelled, if
the cancellation was done after execution was in progress.

In either case, do not invoke Send if there is nothing to do,
as invoking Send...(force = true) will generate a duplicate ACK.
Duplicate ACKs will be noticed by the remote end as a sign of
congestion, so we don't want that to happen.

Change-Id: Iac30c140c322ccf0b0477e434459e7674bc24e1a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7283
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>


# 265e1e4d 30-Dec-2023 Augustin Cavalier <waddlesplash@gmail.com>

TCP: Update implementation comment at the top of the file.

A variety of things marked "not implemented" actually are,
at least partially, but the comment was not adjusted.

Change-Id: I760cca8ef3f601d27c0143f7dc75f5049d02f899
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7282
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>


# 973f6d33 22-Nov-2023 Augustin Cavalier <waddlesplash@gmail.com>

network: Migrate SIGPIPE generation into the socket module.

This removes the burden of determining whether to and then
actually sending SIGPIPE from the protocol modules, meaning
the MSG_NOSIGNAL flag can now be implemented entirely in
the socket module and not even passed further down the chain.

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


# fca1b0ec 21-Nov-2023 Augustin Cavalier <waddlesplash@gmail.com>

protocols/tcp: Return EOPNOTSUPP when unhandled flags are specified.

Same as was done for UNIX domain sockets in 74a44f5aedcaac30d812a922af4586d505031bc7.


# 93a6528d 21-Nov-2023 Augustin Cavalier <waddlesplash@gmail.com>

protocols/tcp: Correct implementation of MSG_DONTWAIT.

Waiting for state changes correctly checked MSG_DONTWAIT,
but the overall data timeout only did in ReadData, not
SendData. This corrects that and makes the implementation
more consistent overall.


# f860cfc7 21-Nov-2023 Augustin Cavalier <waddlesplash@gmail.com>

protocols/tcp: Correct implementation of MSG_NOSIGNAL.

The other send_signal invocation correctly checked NOSIGNAL already.


# ec97248c 15-May-2023 Jérôme Duval <jerome.duval@gmail.com>

tcp: handle linger with zero timeout

ReadData() should return the current error on closed state, not always not connected.

Change-Id: I286ac1dd9ded127e8658ceb61088783b9993eacf
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6459
Reviewed-by: Rene Gollent <rene@gollent.com>


# 9c1af36c 06-May-2023 Jérôme Duval <jerome.duval@gmail.com>

tcp: report disconnected events for tcp

* FIONREAD shouldn't report errors, only EINVAL when listening
* read available data in closing and closing-wait states
* fix #18327

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


# 7c58a5a3 15-Apr-2023 Jérôme Duval <jerome.duval@gmail.com>

tcp: avoid overflow of the advertised window with window scaling enabled

tcp_segment_header.advertised_window is 16 bits.

Previously, instead of using the maximum window, zero would be sent, thus
the partner wouldn't send anything.

fix #18337

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


# 0ab42081 27-Jan-2023 Christof Meerwald <cmeerw@cmeerw.org>

kernel/network: Limit send MSS by interface MTU

see RFC9293 3.7.1. Maximum Segment Size Option

The maximum size of a segment that a TCP endpoint really sends, the
"effective send MSS", MUST be the smaller of the send MSS (that
reflects the available reassembly buffer size at the remote host)
and the largest transmission size permitted by the IP layer.

Previously, instead of just choosing a lower send MSS, we would
(try to) fragment those packets.

With this change I now get a 10/10 score from test-ipv6.com when
setting the local MTU to 1280 (this is needed as a workaround as we
don't implement Path MTU Discovery).

Change-Id: I27bdfebe2f94a55951407136ab7c4dd9626cdcea
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6043
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# 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>


# 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>


# 44a4bc5f 22-May-2020 Kyle Ambroff-Kao <kyle@ambroffkao.com>

tcp: Remove sanity checks from BufferQueue in release builds

Each TCPEndpoint has two BufferQueue members, one for the send queue
and one for the receive queue.

If DEBUG_BUFFER_QUEUE is enabled, then most methods of BufferQueue
call BufferQueue::Verify(), sometimes twice. This member function
performs some sanity checking which requires iterating through every
net_buffer in the queue.

Disabling this in a debug build improved throughput by a factor of 5x
over the loopback interface on my laptop. Using iperf the measured
throughput went from 900Mbps to around 4.8Gbps.

This patch turns this sanity checking off for release builds.

* Rename DEBUG_BUFFER_QUEUE to DEBUG_TCP_BUFFER_QUEUE
* Change the default in BufferQueue.h to disabled
* Set DEBUG_TCP_BUFFER_QUEUE to KDEBUG_LEVEL_2 in
kernel_debug_config.h

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


# 86ff706f 02-May-2020 Jérôme Duval <jerome.duval@gmail.com>

tcp: set is_connected flag on our socket without parent too.

a client non-blocking socket would otherwise looks non connected.

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


# f0ba8f6a 10-Mar-2019 François Revol <revol@free.fr>

TCP: Fix Zero Window Probes.

I did some tcpdump recording, and I believe we confuse the receiver
with our Zero Window Probe, because we don't resent even though it only
ACKs the previous segment, and we keep sending things after it:

* we send the last segment before window is closed, next seg = N,
* we get ACK for N, with window=0
* we send Zero Window Probe with 1 byte, next seg = N+1,
* we eventually get a window>0 ACK still at N,
* we start sending stuff again, but starting from N+1,
* receiver keeps ACKing N because it never accepted it.

It seems sending either 1 or 0 byte is valid for a ZWP, although I'm not
entirely sure. At least it's easier to handle 0 than 1, and it seems to work.
Wireshark shows them as duplicate ACKs, but they get the thing going.

References:
* RFC 793: https://tools.ietf.org/html/rfc793#section-3.7
* RFC 6429: https://tools.ietf.org/html/rfc6429
* Wireshark wiki: https://www.wireshark.org/docs/wsug_html_chunked/ChAdvTCPAnalysis.html

Should fix #13769.

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


# cd6365c7 17-May-2018 Jérôme Duval <jerome.duval@gmail.com>

style fixes


# bf1a86c1 04-Dec-2017 A-star-ayush <myselfthebest@yahoo.com>

TCP: Fixed RTO update and dup ACKs generation.

i) there was an integer promotion problem in updating the retransmission
timeout : a signed int was being divided by an unsigned int. This was causing
the values to overflow. Thus leading to huge values for timeout which
manifested in the perception of pause in data flow.

ii) for an ack to be recognised as a duplicate ack, the advertised window
must remain same. This was not taken care of in the code so I added it.

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>

Helps with #13769 but does not fix it completely (upload gets
farther but still stalls.)


# 272e1a2f 09-Nov-2017 A-star-ayush <myselfthebest@yahoo.com>

tcp: fixed no response from window update, removed ideal timer

The reason for the erratic behavior was that the tcp implementation
silently drops window update messages after noting the update but without
triggering any data send event. Before the new TCP patches were applied,
the implementation relied on a retransmission timeout to trigger a send event
after a window update. One of the new patches dealing with the ideal timer
changed the semantic of the restransmit function call and caused the behavior
witnessed.

But a retransmission timeout is not the correct solution to window update. In
fact a retransmission is not a desired effect of window update. So in the patch
attached, I have changed the behavior of the implementation to immediately
acknowledge the window update (along with data from SendQueue) and thus solving
the problem of complete halt in data transmission.

The patch also has the changes re-implemented that were reverted back but had
nothing to do with the issue at hand. For the time being, I have also removed
the "ideal timer" part from the patch (although it wasn't creating any
conflict). I initially decided to implement the ideal timer using the same
timer used for retransmission to avoid adding an additional timer. But as I
have seen, it can be problematic. So I will be re-implementing the ideal timer
and thus it was not included in this patch.

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
Fixes #13704.


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

Revert "tcp: rfc 2018: implemented SACK option"

This reverts commit 5c31f5a67a0aa37c8f2a1464252b2c5b0a959f33.


# e736356c 12-Sep-2017 Augustin Cavalier <waddlesplash@gmail.com>

Revert "tcp: slow start@rfc5681 : updated rules for congestion window"

This reverts commit 05743f6a13319a9dc332603eb5d98ba4c5374b25
(and the portions of following commits that were layered on top of it.)


# 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>


# 515cda72 18-Aug-2017 A-star-ayush <myselfthebest@yahoo.com>

tcp: rfc 6582: implemented NewReno modification

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


# 15c58f0c 29-Jul-2017 A-star-ayush <myselfthebest@yahoo.com>

tcp: rfc 5681: implemented ideal timer

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


# 30982ed7 29-Jul-2017 A-star-ayush <myselfthebest@yahoo.com>

tcp: rfc 6298 & 7323: updated rto calculations and semantics

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>


# 39bba929 14-Aug-2017 A-star-ayush <myselfthebest@yahoo.com>

tcp: rfc 3042: implemented limited transmit

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


# ec63a329 14-Aug-2017 A-star-ayush <myselfthebest@yahoo.com>

tcp: rfc 5681: implemented fast retransmit and recovery

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


# 05743f6a 14-Aug-2017 A-star-ayush <myselfthebest@yahoo.com>

tcp: slow start@rfc5681 : updated rules for congestion window

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


# d7842252 11-Aug-2017 Jérôme Duval <jerome.duval@gmail.com>

tcp: Subsequent connect() call should return EALREADY.

* should fix #13662.


# 7dffccc3 24-Nov-2016 Alexander von Gluck IV <kallisti5@unixzen.com>

tcp: Update comment to reflect we support window scaling

* No functional change


# 89822930 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Whitespace cleanup, move a define to header and fix a typo.


# bed94ebc 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Change timestamp factor from 1024 to 1000.

It is the conversion factor between the milliseconds tcp time and the
microseconds system time, so 1024 does not make much sense.


# 94fb06bf 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Fix early cancellation of timers on socket free.

TCPEndpoint::Free() uses _EnterTimeWait() to start the time-wait timer
for later cleanup. The latter did call _CancelConnectionTimers()
unconditionally however, also cancelling a retransmit timer that was
possibly still needed for the retransmission of the FIN packet. If the
FIN packet got lost, the connection would be left open on the other end.


# bc49140b 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Add APICall trace entry and move TRACEs into locked parts.

The APICall trace entry just records the function name but this is
enough to deduce where some of the state changes come from.

Also move the TRACE macros past the MutexLockers to ensure that their
output happens at the time when the methods actually run.


# 05220224 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Split Timer trace entry into Timer{Set|Triggered}.

Trace whenever a timer is (re-)set as well as when it triggers. A value
of -1 denotes the cancellation of the timer.


# 01b0f935 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Move persist timeout value to a define in the header.


# 5f774907 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Fix retransmit logic to avoid lots of spurious retransmits.

The retransmit timer was only stopped when all in flight data was
acknowledged and never updated on individual acknowledgements. This
caused a lot of erroneous retransmits whenever the buffer was filled
fast enough so that the acknowledgements never caught up, i.e. whenever
uploading or streaming data.

Move setting of the initial retransmit timer inside the send loop so it
is closer to the actual time the segment is sent out and simplify the
logic a bit.

Limit the minimal retransmit timeout to 200 msecs to avoid spurious
retransmit in the face of delayed acknowledgements. This is lower than
the 1 second minimum the RFCs suggest. Other stacks use various other
sub-second timeouts, the 200 msecs follows what Linux does.

Also add the exponential back off of the retransmit timeout when
retransmits are triggered. This is bounded by a 60 seconds maximum
according to RFC6298.


# da8fbe0e 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Replace custom WaitList with ConditionVariable.

The WaitList implementation had a race condition between checking for
the condition and acquiering the semaphore. If a thread was rescheduled
at that point, the signal could be missed due to the use of
release_sem_etc() with the B_RELEASE_ALL flag while the thread was not
yet waiting for the semaphore. The transfer would subsequently stall.


# 2fdea65c 01-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Fix 64 bit build with debugging features enabled.


# ea54368e 11-Jun-2015 Jérôme Duval <jerome.duval@gmail.com>

tcp: remove extraneous parenthesis.


# 79985c3d 10-Jun-2015 Adrien Destugues <pulkomandy@gmail.com>

Fix reversed logic in MSG_NOSIGNAL

This should work better. Thanks to Korli for spotting the issue.


# 2da6584a 09-Jun-2015 Augustin Cavalier <waddlesplash@gmail.com>

tcp: fix build breakage caused by hrev49265.

There's currently a debate on the ML as to whether this should
be '== 0' or '!= 0', though.


# 4b2d018b 10-Jun-2015 Adrien Destugues <pulkomandy@gmail.com>

Implement MSG_NOSIGNAL

* Part of latest POSIX specification, this prevents send() on a closed
socket to raise a SIGPIPE signal (but EPIPE is returned).


# 162ae620 30-May-2015 Hamish Morrison <hamishm53@gmail.com>

tcp: wait for connection to complete before notifying B_SELECT_WRITE


# 64f6fcbc 17-Jan-2015 Hamish Morrison <hamishm53@gmail.com>

TCP, UNIX sockets: allow multiple calls to listen

* Subsequent calls to listen on an already-listening socket can resize
the backlog.
* While not explicitly spelled out by POSIX, this behaviour is
consistent with FreeBSD and Linux.


# 6235b496 12-Jan-2015 Adrien Destugues <pulkomandy@gmail.com>

More useless inclusions of khash.h


# 6d796a84 10-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Fixed up network stack and drivers for x86_64.

* Various compilation fixes.
* Fixes to the FreeBSD compatibility layer (from comparing the x86-
specific bits with the equivalent amd64 sources in FreeBSD).
* Compile all the Ethernet drivers except for sis900 and wb840, these
require a bit more work to fix (will file a ticket soon). Tested
ipro1000 and rtl81xx, no issues.


# 24a15a69 03-Dec-2011 Michael Lotz <mmlr@mlotz.ch>

Fix use of a potentially freed net_buffer.

The buffer may have been freed if its data was added to the queue, but
later the buffer size was still read from the object. A spurious
acknowledge may have been sent, or one would have gone missing,
depending on what happened with the allocation after it was freed.


# 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


# eddec292 21-Jul-2010 Oliver Tappe <zooey@hirschkaefer.de>

* applied patch by kaliber that fixes more than 100 warnings - thanks a lot!
Closes #6349

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


# 56f097eb 12-Apr-2010 Oliver Tappe <zooey@hirschkaefer.de>

Applying patch by Atis Elsts:
* fix connecting to INADDR_ANY work for tcp (effectively will
connect to INADDR_LOOPBACK)
* add same behaviour to udp
* move some ipv4-specific code out of tcp into ipv4 address module
* bind() and connect() now reject addresses from non-matching
families
* myself: minor cleanup in udp.cpp with respect to 80 chars limit
Closes #5716 - many thanks!


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


# e572c323 10-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* When receiving an out of sequence FIN we must ignore it until its part of
our available buffer (we might want to move this into the BufferQueue class).
* Now, _AddData() remembers the flag (and its position), and will alter the
segment's flags field to reflect the current state.
* This fixes not being able to login into mmlr.dyndns.org.
* Fixed warnings when TCP_PROBE is defined.


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


# 965abdeb 15-Feb-2010 Axel Dörfler <axeld@pinc-software.de>

* BufferQueue::Free() no longer will return negative values. As is, the max
bytes restriction is only a soft limit. This fixes stalling TCP connections
because everything received would be out of window once this happened.
* Added a TODO to look into TCP's window management - it doesn't seem to be
right.
* Fixed build with tracing turned on.
* Made the fNumber member of tcp_sequence private.


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


# 2416d6ae 18-Jan-2010 Michael Lotz <mmlr@mlotz.ch>

anevilyak+mmlr:
accept() is supposed to return B_WOULD_BLOCK when SO_NONBLOCK is set.


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


# 6f440aed 24-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* net_socket_module_info::acquire_socket() now returns whether or not the
socket could be acquired, ie. when its reference count is 0, it cannot be
acquired anymore. This requires the protocol to do proper locking, though.
* The TCP EndpointManager now checks the return value of acquire_socket(), and
only returns the endpoint if that succeeded.
* This fixes bug #2197.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30363 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


# 68dd93a6 06-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* Fixed TCPEndpoint::Listen() never setting the backlog on its socket, causing
only a single pending connection to be accepted at once.
* Fixed discarding endpoints that still had a parent, but were closed before
they could be accepted (or even established). Previously, these were never
deleted, slowly filling up the socket's backlog.


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


# 865dbe34 06-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* This should fix the tcp build when tracing is turned on.


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


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

bonefish + axeld:
* There was one incorrect check in BufferQueue::Get() that happened because
the wrong operator was used due to the uint32 cast operator.
* Consequently, we removed the uint32 cast operator, and changed the code
to deal with this. Fortunately, no other bugs were observed.


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


# 0a5c6763 04-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* Now it works.


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


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

* Improved tracing.


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


# 49509985 12-Jan-2009 Axel Dörfler <axeld@pinc-software.de>

* Applied another patch by Adrian: the route used by TCP was never given back.


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


# b3cb15e2 11-Jan-2009 Axel Dörfler <axeld@pinc-software.de>

* Applied most parts of Adrian's patch in #2594, applied our coding style.
* Cleaned the net_buffer::sequence handling, and fixed a few more problems of
maintaining it in Add().
* Extended Verify() to check everything that's possible, and call it
conditionally on several places, depending on DEBUG_BUFFER_QUEUE. It's turned
on for now which means that any remaining problems should show up when they
happened.
* Call Dump() from TCPEndpoint::Dump().


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


# fad11a1c 26-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Strongly typed languages ftw.


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


# 1894a0a9 20-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Consistently use KDEBUG. It is always defined and therefore must be
checked with "#if".


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


# c5e91552 15-Aug-2008 Axel Dörfler <axeld@pinc-software.de>

* Now uses the new wait_for_timer() stack function on destruction - this fixes
bug #2143.


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


# 1a199814 20-May-2008 Axel Dörfler <axeld@pinc-software.de>

* If we don't add a buffer because of FLAG_NO_RECEIVE, we still have to
maintain our fReceiveNext member, or else the other endpoint never gets its
data acknowledged. This fixes the ssl_closure test of the neon test suite,
all tests finally go through.
* Use is_writable() in SendData() instead of checking all the states manually.
* Also bail out when the endpoint stops being writable when we were waiting
for it to become writable.


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


# 30a396ab 19-May-2008 Axel Dörfler <axeld@pinc-software.de>

* Made the endpoint manager wait on bind() if the existing connection is
local, and is about to close.
* This fixes several race conditions with the neon test suite that relied
on TCP sockets being gone after close, and their port being available again
(note, that is not what the TCP spec says, anyway, but it makes sense to
do so, since we already removed the time wait state for local connections).
* The endpoint manager is now using a mutex instead of a semaphore.
* TCPEndpoint::_Close() now notifies the senders/receivers instead of
_HandleReset().
* Besides ssl_closure(), all tests of the neon test suite seem to pass now.


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


# ec1f43f3 17-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

axeld + bonefish:
* Small style changes.
* Currently ifdef'ed out potentially correct changes, that break Neon
tests which otherwise succeed. Axel will investigate this further.


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


# 25d0a084 17-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

axeld + bonefish:
_WaitForEstablished() must also accept states implying that the state
has been established at some point. Fixes bug #2172.


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


# 5947a3be 15-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Fixed read() on a read-shutdown socket. It must never wait.
* Added TODO regarding read/write shutdown.


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


# 03298f9d 02-May-2008 Axel Dörfler <axeld@pinc-software.de>

* The WaitList now always notifies all waiters.
* In SendData(), TCP will now split the buffer into smaller parts if it
can send data (ie. there is free space in the buffer queue left, but
not enough to send the whole buffer, and the free space is more than
the send low water mark of the socket).
* Both of these changes together let TCP now pass the "forwarding" test
of the OpenSSH suite.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25294 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


# 63368af5 01-May-2008 Axel Dörfler <axeld@pinc-software.de>

* As Ingo pointed out to me earlier, TCP could now delete its socket too early
when using the shutdown() command.
* If TCP no longer needs a socket, it will now set the flag FLAG_DELETE_ON_CLOSE;
when the socket is closed from the upper layers, it will set the FLAG_CLOSED
flag - and only if both are set, TCP will now delete the socket itself on
receive.
* This fixes bug #2189.


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


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

* Followed Ingo's suggestion, and retricted sending SIGPIPE only to userland
API clients.


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


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

* Implemented sending of urgent data. Seems to work fine, but of course only
if the other end is not a Haiku host (retrieving of urgent data is still
missing).
* Resolved TODO: SendData() now sends a SIGPIPE when trying to send on a
closed connection.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25245 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


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

* Minor cleanup.


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


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

* For local connections, we no longer use the TIME_WAIT state; in this case,
we know that the connection was torn down cleanly, and there are no inflight
segments floating around anymore.


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


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

* Closed endpoints are now deleted directly, they no longer get into the
2MSL wait.
* Accidently left on debug output.


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


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

* TIME_WAIT endpoints must not send an acknowledgement for known data; this
fixes the "endless discussions" when closing a local connection - only
happened on a simultaneous close.
* A FIN in TIME_WAIT now updates the time-wait timer, as required by the
TCP specification.
* Entering TIME_WAIT now cancels all connection timers. We might want to
think about putting time wait connections into a separate hash, and delete
the socket early on.
* Added tracing support for send/receive, timers, and state changes.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25236 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


# 05bc1e89 27-Apr-2008 Axel Dörfler <axeld@pinc-software.de>

* Added _CancelConnectionTimers() that does what its name suggests, and is
now used from various places that previously did not cancel all timers
they should have.
* When a connection moves to the CLOSED state, it should cancel all timers;
this prevents from sending a reset at the end of a connection.
* If the persist/delayed acknowledge timers were canceled too late, they might
still have tried to send something (which would eventually cause a reset
sent to the peer).
* Follow RFC 1337 with respect to time wait assassination prevention (ie.
we now ignore resets from peers in time wait state).
* _SegmentReceived() must not check the sequence of a time wait connection;
it prevented sending a reset when that was due (a new connection request
would time out, instead of fail immediately).
* Also, that method must never be called in the LISTEN or SYNCHRONIZE_SENT
states, so we don't need to check for those.
* We don't have to wait in Close() until the connection is actually closed -
removed a TODO. TCP should handle this internally.
* Renamed _ShutdownEgress() to _Shutdown().


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


# 2838616b 24-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Translate connect()s to INADDR_ANY to INADDR_LOOPBACK. Not sure, if that
is required, but Linux seems to do it. It also allows us to create
AF_INET socketpair()s -- not really needed, but probably nice for
testing.


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


# 05849428 17-Feb-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

axeld + bonefish:
* Added syscall restart support for connect(), accept(), send(), recv(),
which are implemented via ioctl()s. The actual restart support is done
in the net stack driver's ioctl() hook. Lower layers need to correctly
deal with socket timeouts, though, for which the stack module provides
support functions.
* TCPEndpoint::_WaitForEstablished() does abort now when an error
occurred earlier, so that trying to connect to an unused port fails
immediately, as it should.
* Fixed and refactored TCP connection reset handling. The new
TCPEndpoint::_HandleReset() does the job. Got rid of
TCPEndpoint::fError.
* Fixed sequence numbers for SYNC/FINI packets.
* The former two fix the problem that connections wouldn't be closed
correctly and could even be reused when trying to connect again (as
was reproducible with svnserve + svn).
* Some style cleanup in CPEndpoint.h.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23984 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


# 45479140 05-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

* TCP must not lock the endpoint's lock in _TimeWaitTimer() - it will deadlock
with its destructor when the socket is deleted. This effectively stopped all
network timers from working. This will not only fix bug #1693, but also many
other networking problems I've seen so far.
* Minor cleanup (mostly line breaks, strange indenting and superfluous
parentheses).


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


# 5c3cf263 03-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

Got rid of DeleteSocket().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23236 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


# abbff8b9 22-Oct-2007 Axel Dörfler <axeld@pinc-software.de>

SendQueued() could send empty buffers in case fSendQueue.Get() failed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22674 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


# 1002cfa0 27-May-2007 Hugo Santos <hugosantos@nowhere.fake>

tcp: we should send an ACK for at least each two received segments. Jerome helped debug this one.


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


# 34c53bac 26-May-2007 Hugo Santos <hugosantos@nowhere.fake>

tcp: fixed an issue where the socket could be waken from ReadData() even when no new data was added to the queue (due to lost packets). Also make sure we only break from the receive loop where there is at least a byte of data to be consumed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21248 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


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

net_buffer: prevent modules from messing with metadata too much


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21211 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


# 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


# 62a21143 04-May-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a race condition in TCP's WaitList Wait/Signal that was preventing Connect() from awake when it should. Reported by Francois Revol.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21024 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


# 9cd3b980 27-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a long standing binding issue with spawned sockets and TCP. also fixed bind() address checking rules.


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


# e2200e34 27-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

call ProtocolSocket::Open() for accept()ed sockets. This fixes a regression introduced earlier today.


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


# 4b55736d 27-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added new helper ProtocolSocket. Moved some stuff together to achieve better inlining.


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


# 2586c25e 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

use Chaining in OpenHashTable.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20822 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


# 585195c2 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

introduced SocketAddress wrappers and use them in TCP.


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


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

tiny TCP cleanups


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20815 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


# f8486a02 24-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed an issue where a TCP connection would fail if the first expected segment of data was lost. Reported by Axel.


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


# 006e498f 23-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

transmit our timestamp in network order. Fixes a problem with sending data to Linux and BSD hosts which Travis helped debug. Also only update SRTT when data has been acknowledged.


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


# 39faeeba 20-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

when sending pure ACKs, use an artificial window of 0.


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


# 204aa45b 20-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

allow window updates to be sent after consuming data from the receive buffer. This fixes an issue where people were experiencing hangs in TCP downloads.


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


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

fixed an issue with TCP where it possibly could not recover from a retransmission as the RCV.NXT was wrongly updated. When appending data we now set it to the sequence in the end of the receive queue.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20776 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


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

more TCP fixes, we should now be able to send large amounts of data through congestioned links.

- fixed BufferQueue's RemoveUntil.
- reset SND.NXT on third duplicate ACK (fast retransmit).
- on retransmit reset SND.NXT to SND.UNA (it will be updated back when we get good ACKs).
- fixed effective window calculation.
- relaxed SWS checking a bit, don't send partial packets on retransmission as the window might have been reduced due to congestion.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20769 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


# 421a4def 19-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some TCP tweaks.

- check the effective window against the flight size.
- start the RTT estimates relatively high.
- introduced a TCP PROBE debug message for offline processing and TCP debugging.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20750 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


# 5534294c 17-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

TCP: only set FIN after the send queue has been exausted and we are in a state that requires it.


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


# 7d524fb7 16-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

implemented TCP's slow start and congestion avoidance.


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


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

reorganized some of the TCP logic so we have common init paths for receive and send.


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


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

update Window Scaling variables when a simultaneous open is ACKed.


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


# 58bef2f4 16-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

support TCP Window Scale on sent segments.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20729 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


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

fixed an issue where TCP would RST a connection when a peer trying to connect us re-sent their SYN.

- In fact our SYN/ACK reply is being lost due to ARP resolving as we are waiting in the device's receive path, thus we never get replies before timing out. This requires queueing during ARP resolving.


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


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

don't do MSS segmentation in TCP's SendData(), _SendQueue() already does the appropriate work.


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


# 83ecc795 11-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

non-writeable states are always non-blockable from a write() POV.


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


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

update buffer size when prepending buffers.


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


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

even more TCP fixage.

- don't try to remove spawned sockets from Endpoints hashtable.
- return B_WOULD_BLOCK (EAGAIN) when we time out in acquire_sem().
- use B_RELEASE_IF_WAITING_ONLY in the TCP WaitList.
- fixed a off by one issue in ReadData() which could result in more than needed iterations (and waiting).
- implemented prepending new buffers to a net_buffer.


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


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

Fixed some more TCP issues.

- Properly flag sockets using non-blocking connects() when in SYN SENT.
- and when in LISTEN, we should use the socket's connection queue size.


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


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

A couple more TCP fixes.

- ipv4_bind() was broken when binding to addresses not INADDR_ANY, as it wasn't copying the address to the socket, fixed.
- fixed a small issue in TCP's BindToEphemeral where the correct address might not have been bound to the socket.
- some assorted TCP wait lists fixes.
- fixed TCP's Connect() over the loopback interface, we might already be ESTABLISHED after _SendQueue() returns.
- fixed the amount of time we wait in TCP's Accept().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20629 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


# 7e6e645a 08-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

Fixed a TCP issue reported by Stephan. Make sure we have enough PSH'ed bytes in the receive buffer before breaking the RX loop.


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


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

check if receive timeout is infinite before doing the usual preparation for ABSOLUTE_TIMEOUT


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


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

The Open Group base specification mentions that EINTR should be returned if the recv() is interrupted before _any data_ is available. So we actually check if there is data, and if so, push it to the user.


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


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

tiny TCP cleanups, move the read notifications to _NotifyReader().

- Also fixed the buffer size check in UDP's SendData() since UDP's length field includes the size of the header we need to check that as well. IPv4 is correct since we check for the size after prepending the header (due to it being possibly already included).


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


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

Sigh, ignore previous commit, Open Group Specification is ambiguous. Now we properly support MSG_WAITALL.


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


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

support MSG_WAITALL in TCP


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20584 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


# 2cff90bf 04-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a critical issue with TCP's FIN handling: if FIN was set on a packet with data, fReceiveNext would be rewritten with the queue's LastSeuence which would be effectively the required sequence - 1. Increment instead fReceiveNext with the buffer's size.


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


# fcd6d8cd 04-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

keep PUSH'ed pointer in receiver side of TCP so we can wait for more data in recv()


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


# 8c438149 04-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fix locking in TCP's ReadData()


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


# 52e75b62 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

TCP: initial shutdown() implementation and some general fixes

* set FLAG_NO_RECEIVE/FLAG_NO_SEND on shutdown() and send FIN on SHUT_WR
* if a send() is attempted with FLAG_NO_SEND set return EPIPE
* proper handling of recv timeout in ReadData(), using absolute timeout instead of relative
* if FLAG_NO_RECEIVE is set, don't attached more segments to the receive queue, drop them instead


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


# 0c88e5ee 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

implemented SO_LINGER support in TCP


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


# 71bca39b 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some more cleanups to TCP TRACE() facility


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


# 3537f096 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a bug in TCP where applications weren't properly signaled when the connection was terminated by the server and there was no more data to be read from the buffer.


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


# 2d1f81eb 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

cleaned up the TRACE() calls in TCPEndPoint a bit.


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


# 868583b5 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a potential problem in TCP's accept() with the init'ing of new connections' MSS


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


# bbf8311d 07-Feb-2007 Axel Dörfler <axeld@pinc-software.de>

* Fixed a race condition between deletion of the endpoint and canceling its timers;
the timer functions could access invalid memory.
* The endpoint manager now panics if a bound endpoint is not in the hash.


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


# 4062fe7c 15-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

fReceiveNext was not maintained correctly in case of out of order packets.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19813 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


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

* Connect() now sets the initial send queue sequence before calling _SendQueued()
so that it's already correct at this point (even though it's currently not
possible to queue data before connecting, it might be in some point in the future).
* ListenReceive() did not initialize the initial send queue sequence of the new
endpoint correctly; it took the values from the wrong endpoint (itself).
* Suppressed the debug output "FIN ack'd" when the connection was not even established
yet.
* Minor debug output improvements.


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


# e19a0bfa 31-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

Could not connect locally anymore, as fSendNext and fSendMax must be set before
the segment is sent in this case (as receive/send will currently stack up in a
single thread).


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


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

* Header prediction was a bit too generous (and thus used too often)
* SendData() could return an error and still wanted to own the buffer passed in
* Removed the timeout computations from SendData() - looks like it's usually
done the simple way when the data has to be submitted in smaller packets.
* ReadData() no longer blocks in case the peer has closed the connection.
* More debug output.


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


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

We shouldn't try to unlock a no-longer-existing endpoint.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19425 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


# 8982293017b132c73aff734fa8baa7afd261e125 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Whitespace cleanup, move a define to header and fix a typo.


# bed94ebc49e2b99d39a4a1ef1880d4d7a47a0c6d 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Change timestamp factor from 1024 to 1000.

It is the conversion factor between the milliseconds tcp time and the
microseconds system time, so 1024 does not make much sense.


# 94fb06bfce1f654a262e988fe224be42ffa4f8f1 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Fix early cancellation of timers on socket free.

TCPEndpoint::Free() uses _EnterTimeWait() to start the time-wait timer
for later cleanup. The latter did call _CancelConnectionTimers()
unconditionally however, also cancelling a retransmit timer that was
possibly still needed for the retransmission of the FIN packet. If the
FIN packet got lost, the connection would be left open on the other end.


# bc49140bab90e562dfff8a30f99e647c11779b30 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Add APICall trace entry and move TRACEs into locked parts.

The APICall trace entry just records the function name but this is
enough to deduce where some of the state changes come from.

Also move the TRACE macros past the MutexLockers to ensure that their
output happens at the time when the methods actually run.


# 05220224ffc203b62a13169288c178553e98ccb8 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Split Timer trace entry into Timer{Set|Triggered}.

Trace whenever a timer is (re-)set as well as when it triggers. A value
of -1 denotes the cancellation of the timer.


# 01b0f935ec6177b7f20eeaf0955df0600ced66c3 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Move persist timeout value to a define in the header.


# 5f7749078e1cf1c7ea9fa091a1c1f1d94ec37ce2 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Fix retransmit logic to avoid lots of spurious retransmits.

The retransmit timer was only stopped when all in flight data was
acknowledged and never updated on individual acknowledgements. This
caused a lot of erroneous retransmits whenever the buffer was filled
fast enough so that the acknowledgements never caught up, i.e. whenever
uploading or streaming data.

Move setting of the initial retransmit timer inside the send loop so it
is closer to the actual time the segment is sent out and simplify the
logic a bit.

Limit the minimal retransmit timeout to 200 msecs to avoid spurious
retransmit in the face of delayed acknowledgements. This is lower than
the 1 second minimum the RFCs suggest. Other stacks use various other
sub-second timeouts, the 200 msecs follows what Linux does.

Also add the exponential back off of the retransmit timeout when
retransmits are triggered. This is bounded by a 60 seconds maximum
according to RFC6298.


# da8fbe0e5974bef73324b4297e7cc471b942b679 02-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Replace custom WaitList with ConditionVariable.

The WaitList implementation had a race condition between checking for
the condition and acquiering the semaphore. If a thread was rescheduled
at that point, the signal could be missed due to the use of
release_sem_etc() with the B_RELEASE_ALL flag while the thread was not
yet waiting for the semaphore. The transfer would subsequently stall.


# 2fdea65c3a0b5f8680eee251c794c231ee507ce3 01-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

tcp: Fix 64 bit build with debugging features enabled.


# ea54368ece42133c3c54f2577d04c00f1b000626 11-Jun-2015 Jérôme Duval <jerome.duval@gmail.com>

tcp: remove extraneous parenthesis.


# 79985c3d86bbd83ca878da6e86711a89e4e97d25 10-Jun-2015 Adrien Destugues <pulkomandy@gmail.com>

Fix reversed logic in MSG_NOSIGNAL

This should work better. Thanks to Korli for spotting the issue.


# 2da6584ad096f37a243bf090458a00534429ea0e 09-Jun-2015 Augustin Cavalier <waddlesplash@gmail.com>

tcp: fix build breakage caused by hrev49265.

There's currently a debate on the ML as to whether this should
be '== 0' or '!= 0', though.


# 4b2d018be4c848b0cfb8d401185fa998ab6cfd90 10-Jun-2015 Adrien Destugues <pulkomandy@gmail.com>

Implement MSG_NOSIGNAL

* Part of latest POSIX specification, this prevents send() on a closed
socket to raise a SIGPIPE signal (but EPIPE is returned).


# 162ae6204b1c58e28bbeac66a2ee3de8ce745bc2 30-May-2015 Hamish Morrison <hamishm53@gmail.com>

tcp: wait for connection to complete before notifying B_SELECT_WRITE


# 64f6fcbccd78defbc9785f88423b6800028f5d0e 17-Jan-2015 Hamish Morrison <hamishm53@gmail.com>

TCP, UNIX sockets: allow multiple calls to listen

* Subsequent calls to listen on an already-listening socket can resize
the backlog.
* While not explicitly spelled out by POSIX, this behaviour is
consistent with FreeBSD and Linux.


# 6235b4967bb0a99752efd18eee62a47834c79946 12-Jan-2015 Adrien Destugues <pulkomandy@gmail.com>

More useless inclusions of khash.h


# 6d796a84bd484ccc4fb072a29c663b660180ae51 10-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Fixed up network stack and drivers for x86_64.

* Various compilation fixes.
* Fixes to the FreeBSD compatibility layer (from comparing the x86-
specific bits with the equivalent amd64 sources in FreeBSD).
* Compile all the Ethernet drivers except for sis900 and wb840, these
require a bit more work to fix (will file a ticket soon). Tested
ipro1000 and rtl81xx, no issues.


# 24a15a69a8b9d3079cdecbf65329ec0e2e97bd61 03-Dec-2011 Michael Lotz <mmlr@mlotz.ch>

Fix use of a potentially freed net_buffer.

The buffer may have been freed if its data was added to the queue, but
later the buffer size was still read from the object. A spurious
acknowledge may have been sent, or one would have gone missing,
depending on what happened with the allocation after it was freed.


# 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


# eddec292d5dd8251a00851880e16e6a5c07c1e3f 21-Jul-2010 Oliver Tappe <zooey@hirschkaefer.de>

* applied patch by kaliber that fixes more than 100 warnings - thanks a lot!
Closes #6349

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


# 56f097ebd91d9b6369407d2bbfcc19718788d182 12-Apr-2010 Oliver Tappe <zooey@hirschkaefer.de>

Applying patch by Atis Elsts:
* fix connecting to INADDR_ANY work for tcp (effectively will
connect to INADDR_LOOPBACK)
* add same behaviour to udp
* move some ipv4-specific code out of tcp into ipv4 address module
* bind() and connect() now reject addresses from non-matching
families
* myself: minor cleanup in udp.cpp with respect to 80 chars limit
Closes #5716 - many thanks!


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


# e572c3233547f29a65ef4e2108b62aaee82d825e 10-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* When receiving an out of sequence FIN we must ignore it until its part of
our available buffer (we might want to move this into the BufferQueue class).
* Now, _AddData() remembers the flag (and its position), and will alter the
segment's flags field to reflect the current state.
* This fixes not being able to login into mmlr.dyndns.org.
* Fixed warnings when TCP_PROBE is defined.


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


# 965abdebd5f3175836079520f618977d2c889407 15-Feb-2010 Axel Dörfler <axeld@pinc-software.de>

* BufferQueue::Free() no longer will return negative values. As is, the max
bytes restriction is only a soft limit. This fixes stalling TCP connections
because everything received would be out of window once this happened.
* Added a TODO to look into TCP's window management - it doesn't seem to be
right.
* Fixed build with tracing turned on.
* Made the fNumber member of tcp_sequence private.


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


# 2416d6ae42b5f0fab8e9d977ed454c9278990074 18-Jan-2010 Michael Lotz <mmlr@mlotz.ch>

anevilyak+mmlr:
accept() is supposed to return B_WOULD_BLOCK when SO_NONBLOCK is set.


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


# 6f440aed2ce4661713c3ac19a16bfdceaeccbeb4 24-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* net_socket_module_info::acquire_socket() now returns whether or not the
socket could be acquired, ie. when its reference count is 0, it cannot be
acquired anymore. This requires the protocol to do proper locking, though.
* The TCP EndpointManager now checks the return value of acquire_socket(), and
only returns the endpoint if that succeeded.
* This fixes bug #2197.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30363 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


# 68dd93a65246c912ba098a3fd6eb388de4e33b3b 06-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* Fixed TCPEndpoint::Listen() never setting the backlog on its socket, causing
only a single pending connection to be accepted at once.
* Fixed discarding endpoints that still had a parent, but were closed before
they could be accepted (or even established). Previously, these were never
deleted, slowly filling up the socket's backlog.


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


# 865dbe341ea9f6cbf7f88f13833680706ad3f0bd 06-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* This should fix the tcp build when tracing is turned on.


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


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

bonefish + axeld:
* There was one incorrect check in BufferQueue::Get() that happened because
the wrong operator was used due to the uint32 cast operator.
* Consequently, we removed the uint32 cast operator, and changed the code
to deal with this. Fortunately, no other bugs were observed.


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


# 0a5c6763e3349778d07a60e8fb58e582bdba6b58 04-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* Now it works.


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


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

* Improved tracing.


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


# 49509985cf2b41cfc63ee94582e416f113f699e2 12-Jan-2009 Axel Dörfler <axeld@pinc-software.de>

* Applied another patch by Adrian: the route used by TCP was never given back.


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


# b3cb15e21ee6d6793d23f809db75438fde5d8558 11-Jan-2009 Axel Dörfler <axeld@pinc-software.de>

* Applied most parts of Adrian's patch in #2594, applied our coding style.
* Cleaned the net_buffer::sequence handling, and fixed a few more problems of
maintaining it in Add().
* Extended Verify() to check everything that's possible, and call it
conditionally on several places, depending on DEBUG_BUFFER_QUEUE. It's turned
on for now which means that any remaining problems should show up when they
happened.
* Call Dump() from TCPEndpoint::Dump().


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


# fad11a1c88301a5d8f136cd7c75f02ebfdd22c98 26-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Strongly typed languages ftw.


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


# 1894a0a98b5b2102f83c00b7273ba7654334f469 20-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Consistently use KDEBUG. It is always defined and therefore must be
checked with "#if".


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


# c5e91552e130091c06e7e6831103b8889b0d6505 15-Aug-2008 Axel Dörfler <axeld@pinc-software.de>

* Now uses the new wait_for_timer() stack function on destruction - this fixes
bug #2143.


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


# 1a1998141120a9d44d33814c533339e7f51fa116 20-May-2008 Axel Dörfler <axeld@pinc-software.de>

* If we don't add a buffer because of FLAG_NO_RECEIVE, we still have to
maintain our fReceiveNext member, or else the other endpoint never gets its
data acknowledged. This fixes the ssl_closure test of the neon test suite,
all tests finally go through.
* Use is_writable() in SendData() instead of checking all the states manually.
* Also bail out when the endpoint stops being writable when we were waiting
for it to become writable.


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


# 30a396ab4211fe07b7d90e6c48a3eadd301a78db 19-May-2008 Axel Dörfler <axeld@pinc-software.de>

* Made the endpoint manager wait on bind() if the existing connection is
local, and is about to close.
* This fixes several race conditions with the neon test suite that relied
on TCP sockets being gone after close, and their port being available again
(note, that is not what the TCP spec says, anyway, but it makes sense to
do so, since we already removed the time wait state for local connections).
* The endpoint manager is now using a mutex instead of a semaphore.
* TCPEndpoint::_Close() now notifies the senders/receivers instead of
_HandleReset().
* Besides ssl_closure(), all tests of the neon test suite seem to pass now.


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


# ec1f43f30465ee4700c4a8a85dfb99ad6eaf8706 17-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

axeld + bonefish:
* Small style changes.
* Currently ifdef'ed out potentially correct changes, that break Neon
tests which otherwise succeed. Axel will investigate this further.


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


# 25d0a0841f2d3b322da2bef879dcaf6887e4a2a8 17-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

axeld + bonefish:
_WaitForEstablished() must also accept states implying that the state
has been established at some point. Fixes bug #2172.


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


# 5947a3be5a902c477d00e9343dfe63ba57bdbf33 15-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Fixed read() on a read-shutdown socket. It must never wait.
* Added TODO regarding read/write shutdown.


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


# 03298f9d20fe782497471b9e3e131ee00d3fa526 02-May-2008 Axel Dörfler <axeld@pinc-software.de>

* The WaitList now always notifies all waiters.
* In SendData(), TCP will now split the buffer into smaller parts if it
can send data (ie. there is free space in the buffer queue left, but
not enough to send the whole buffer, and the free space is more than
the send low water mark of the socket).
* Both of these changes together let TCP now pass the "forwarding" test
of the OpenSSH suite.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25294 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


# 63368af591b79c2e59e4c806a4fab7805819b0dc 01-May-2008 Axel Dörfler <axeld@pinc-software.de>

* As Ingo pointed out to me earlier, TCP could now delete its socket too early
when using the shutdown() command.
* If TCP no longer needs a socket, it will now set the flag FLAG_DELETE_ON_CLOSE;
when the socket is closed from the upper layers, it will set the FLAG_CLOSED
flag - and only if both are set, TCP will now delete the socket itself on
receive.
* This fixes bug #2189.


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


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

* Followed Ingo's suggestion, and retricted sending SIGPIPE only to userland
API clients.


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


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

* Implemented sending of urgent data. Seems to work fine, but of course only
if the other end is not a Haiku host (retrieving of urgent data is still
missing).
* Resolved TODO: SendData() now sends a SIGPIPE when trying to send on a
closed connection.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25245 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


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

* Minor cleanup.


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


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

* For local connections, we no longer use the TIME_WAIT state; in this case,
we know that the connection was torn down cleanly, and there are no inflight
segments floating around anymore.


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


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

* Closed endpoints are now deleted directly, they no longer get into the
2MSL wait.
* Accidently left on debug output.


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


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

* TIME_WAIT endpoints must not send an acknowledgement for known data; this
fixes the "endless discussions" when closing a local connection - only
happened on a simultaneous close.
* A FIN in TIME_WAIT now updates the time-wait timer, as required by the
TCP specification.
* Entering TIME_WAIT now cancels all connection timers. We might want to
think about putting time wait connections into a separate hash, and delete
the socket early on.
* Added tracing support for send/receive, timers, and state changes.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25236 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


# 05bc1e89735f8cdbfa314202fcbd88ce5bcdf047 27-Apr-2008 Axel Dörfler <axeld@pinc-software.de>

* Added _CancelConnectionTimers() that does what its name suggests, and is
now used from various places that previously did not cancel all timers
they should have.
* When a connection moves to the CLOSED state, it should cancel all timers;
this prevents from sending a reset at the end of a connection.
* If the persist/delayed acknowledge timers were canceled too late, they might
still have tried to send something (which would eventually cause a reset
sent to the peer).
* Follow RFC 1337 with respect to time wait assassination prevention (ie.
we now ignore resets from peers in time wait state).
* _SegmentReceived() must not check the sequence of a time wait connection;
it prevented sending a reset when that was due (a new connection request
would time out, instead of fail immediately).
* Also, that method must never be called in the LISTEN or SYNCHRONIZE_SENT
states, so we don't need to check for those.
* We don't have to wait in Close() until the connection is actually closed -
removed a TODO. TCP should handle this internally.
* Renamed _ShutdownEgress() to _Shutdown().


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


# 2838616b170848f88b30409fe7c39982126e8804 24-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Translate connect()s to INADDR_ANY to INADDR_LOOPBACK. Not sure, if that
is required, but Linux seems to do it. It also allows us to create
AF_INET socketpair()s -- not really needed, but probably nice for
testing.


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


# 058494285aafd433af5618aeb52abd76a4b39c6a 17-Feb-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

axeld + bonefish:
* Added syscall restart support for connect(), accept(), send(), recv(),
which are implemented via ioctl()s. The actual restart support is done
in the net stack driver's ioctl() hook. Lower layers need to correctly
deal with socket timeouts, though, for which the stack module provides
support functions.
* TCPEndpoint::_WaitForEstablished() does abort now when an error
occurred earlier, so that trying to connect to an unused port fails
immediately, as it should.
* Fixed and refactored TCP connection reset handling. The new
TCPEndpoint::_HandleReset() does the job. Got rid of
TCPEndpoint::fError.
* Fixed sequence numbers for SYNC/FINI packets.
* The former two fix the problem that connections wouldn't be closed
correctly and could even be reused when trying to connect again (as
was reproducible with svnserve + svn).
* Some style cleanup in CPEndpoint.h.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23984 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


# 45479140879876af0ee688cc453edbd2caa82e50 05-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

* TCP must not lock the endpoint's lock in _TimeWaitTimer() - it will deadlock
with its destructor when the socket is deleted. This effectively stopped all
network timers from working. This will not only fix bug #1693, but also many
other networking problems I've seen so far.
* Minor cleanup (mostly line breaks, strange indenting and superfluous
parentheses).


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


# 5c3cf2631067f21d72880b245c0ec0e23c3791c7 03-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

Got rid of DeleteSocket().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23236 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


# abbff8b909ea62cfba762a280aa8f77b362655e4 22-Oct-2007 Axel Dörfler <axeld@pinc-software.de>

SendQueued() could send empty buffers in case fSendQueue.Get() failed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22674 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


# 1002cfa0bb6d016a09c46347cf0a77596a15e99f 27-May-2007 Hugo Santos <hugosantos@nowhere.fake>

tcp: we should send an ACK for at least each two received segments. Jerome helped debug this one.


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


# 34c53bacf49f84ef2b18ea80c0238d73ee2d56de 26-May-2007 Hugo Santos <hugosantos@nowhere.fake>

tcp: fixed an issue where the socket could be waken from ReadData() even when no new data was added to the queue (due to lost packets). Also make sure we only break from the receive loop where there is at least a byte of data to be consumed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21248 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


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

net_buffer: prevent modules from messing with metadata too much


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21211 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


# 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


# 62a21143be0010e6f9681394cfa9e93960169dcb 04-May-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a race condition in TCP's WaitList Wait/Signal that was preventing Connect() from awake when it should. Reported by Francois Revol.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21024 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


# 9cd3b980fd431d2fc4cabfdae2b572b866686ee9 27-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a long standing binding issue with spawned sockets and TCP. also fixed bind() address checking rules.


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


# e2200e347d0040ec9123c47cf8ae2a8ebf692b49 27-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

call ProtocolSocket::Open() for accept()ed sockets. This fixes a regression introduced earlier today.


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


# 4b55736dde3c03e6732d2d550b53218b35c37e21 27-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added new helper ProtocolSocket. Moved some stuff together to achieve better inlining.


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


# 2586c25e318e1f71ff45889b9b0d047ce03043d1 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

use Chaining in OpenHashTable.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20822 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


# 585195c28d3d06ee7726b04a420145dda0bd875a 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

introduced SocketAddress wrappers and use them in TCP.


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


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

tiny TCP cleanups


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20815 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


# f8486a02193b03f654a8cc563ec83888e072d08f 24-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed an issue where a TCP connection would fail if the first expected segment of data was lost. Reported by Axel.


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


# 006e498fa9a6f4f9525f4f0957d77751dd145c0b 23-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

transmit our timestamp in network order. Fixes a problem with sending data to Linux and BSD hosts which Travis helped debug. Also only update SRTT when data has been acknowledged.


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


# 39faeeba3871ea8cd6a41a043cf564ecd68c45e2 20-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

when sending pure ACKs, use an artificial window of 0.


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


# 204aa45b0b9d3f97b5619f1940c24b4853073387 20-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

allow window updates to be sent after consuming data from the receive buffer. This fixes an issue where people were experiencing hangs in TCP downloads.


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


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

fixed an issue with TCP where it possibly could not recover from a retransmission as the RCV.NXT was wrongly updated. When appending data we now set it to the sequence in the end of the receive queue.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20776 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


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

more TCP fixes, we should now be able to send large amounts of data through congestioned links.

- fixed BufferQueue's RemoveUntil.
- reset SND.NXT on third duplicate ACK (fast retransmit).
- on retransmit reset SND.NXT to SND.UNA (it will be updated back when we get good ACKs).
- fixed effective window calculation.
- relaxed SWS checking a bit, don't send partial packets on retransmission as the window might have been reduced due to congestion.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20769 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


# 421a4def574d9735cd25ea1ed9ea367870f14197 19-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some TCP tweaks.

- check the effective window against the flight size.
- start the RTT estimates relatively high.
- introduced a TCP PROBE debug message for offline processing and TCP debugging.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20750 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


# 5534294ca18769f4f6c75d7367c88cd1405c7ab6 17-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

TCP: only set FIN after the send queue has been exausted and we are in a state that requires it.


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


# 7d524fb79bfb32d55883b36e8208a6f7f12d7034 16-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

implemented TCP's slow start and congestion avoidance.


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


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

reorganized some of the TCP logic so we have common init paths for receive and send.


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


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

update Window Scaling variables when a simultaneous open is ACKed.


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


# 58bef2f444947af261189df60c5231ab69a9601d 16-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

support TCP Window Scale on sent segments.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20729 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


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

fixed an issue where TCP would RST a connection when a peer trying to connect us re-sent their SYN.

- In fact our SYN/ACK reply is being lost due to ARP resolving as we are waiting in the device's receive path, thus we never get replies before timing out. This requires queueing during ARP resolving.


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


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

don't do MSS segmentation in TCP's SendData(), _SendQueue() already does the appropriate work.


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


# 83ecc79510d22d11841466c4c0838fc42df14b2d 11-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

non-writeable states are always non-blockable from a write() POV.


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


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

update buffer size when prepending buffers.


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


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

even more TCP fixage.

- don't try to remove spawned sockets from Endpoints hashtable.
- return B_WOULD_BLOCK (EAGAIN) when we time out in acquire_sem().
- use B_RELEASE_IF_WAITING_ONLY in the TCP WaitList.
- fixed a off by one issue in ReadData() which could result in more than needed iterations (and waiting).
- implemented prepending new buffers to a net_buffer.


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


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

Fixed some more TCP issues.

- Properly flag sockets using non-blocking connects() when in SYN SENT.
- and when in LISTEN, we should use the socket's connection queue size.


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


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

A couple more TCP fixes.

- ipv4_bind() was broken when binding to addresses not INADDR_ANY, as it wasn't copying the address to the socket, fixed.
- fixed a small issue in TCP's BindToEphemeral where the correct address might not have been bound to the socket.
- some assorted TCP wait lists fixes.
- fixed TCP's Connect() over the loopback interface, we might already be ESTABLISHED after _SendQueue() returns.
- fixed the amount of time we wait in TCP's Accept().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20629 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


# 7e6e645a873321f329835d4a4d34e278d139bd06 08-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

Fixed a TCP issue reported by Stephan. Make sure we have enough PSH'ed bytes in the receive buffer before breaking the RX loop.


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


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

check if receive timeout is infinite before doing the usual preparation for ABSOLUTE_TIMEOUT


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


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

The Open Group base specification mentions that EINTR should be returned if the recv() is interrupted before _any data_ is available. So we actually check if there is data, and if so, push it to the user.


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


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

tiny TCP cleanups, move the read notifications to _NotifyReader().

- Also fixed the buffer size check in UDP's SendData() since UDP's length field includes the size of the header we need to check that as well. IPv4 is correct since we check for the size after prepending the header (due to it being possibly already included).


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


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

Sigh, ignore previous commit, Open Group Specification is ambiguous. Now we properly support MSG_WAITALL.


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


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

support MSG_WAITALL in TCP


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20584 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


# 2cff90bf947743248997bea984afd72aa1fe1e97 04-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a critical issue with TCP's FIN handling: if FIN was set on a packet with data, fReceiveNext would be rewritten with the queue's LastSeuence which would be effectively the required sequence - 1. Increment instead fReceiveNext with the buffer's size.


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


# fcd6d8cd9271e99bd92cf4e0b70efa8c7b984931 04-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

keep PUSH'ed pointer in receiver side of TCP so we can wait for more data in recv()


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


# 8c43814982950e778fcc8f1edf0928ace9eef479 04-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fix locking in TCP's ReadData()


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


# 52e75b62362812a53a8d7d9502feb7a9c91bad7f 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

TCP: initial shutdown() implementation and some general fixes

* set FLAG_NO_RECEIVE/FLAG_NO_SEND on shutdown() and send FIN on SHUT_WR
* if a send() is attempted with FLAG_NO_SEND set return EPIPE
* proper handling of recv timeout in ReadData(), using absolute timeout instead of relative
* if FLAG_NO_RECEIVE is set, don't attached more segments to the receive queue, drop them instead


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


# 0c88e5eea37c5b342b9b5cecbe7085b191590de0 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

implemented SO_LINGER support in TCP


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


# 71bca39bbe796de867bff145355064dec68a16b4 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some more cleanups to TCP TRACE() facility


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


# 3537f0967f24705ec2ce6ac113c6cbada14a7571 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a bug in TCP where applications weren't properly signaled when the connection was terminated by the server and there was no more data to be read from the buffer.


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


# 2d1f81eb1d09c070776a3ceadbe6af507b54fc53 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

cleaned up the TRACE() calls in TCPEndPoint a bit.


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


# 868583b54a8fb3706b5e68c3ed5420d70f4d3d45 03-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

fixed a potential problem in TCP's accept() with the init'ing of new connections' MSS


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


# bbf8311d159baf236b3355cb3cf1aee05732f4d4 07-Feb-2007 Axel Dörfler <axeld@pinc-software.de>

* Fixed a race condition between deletion of the endpoint and canceling its timers;
the timer functions could access invalid memory.
* The endpoint manager now panics if a bound endpoint is not in the hash.


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


# 4062fe7ce3a21b929e01e422f00d4d28bede8618 15-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

fReceiveNext was not maintained correctly in case of out of order packets.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19813 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


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

* Connect() now sets the initial send queue sequence before calling _SendQueued()
so that it's already correct at this point (even though it's currently not
possible to queue data before connecting, it might be in some point in the future).
* ListenReceive() did not initialize the initial send queue sequence of the new
endpoint correctly; it took the values from the wrong endpoint (itself).
* Suppressed the debug output "FIN ack'd" when the connection was not even established
yet.
* Minor debug output improvements.


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


# e19a0bfa1b996109522c62e5784fe792eb0113d8 31-Dec-2006 Axel Dörfler <axeld@pinc-software.de>

Could not connect locally anymore, as fSendNext and fSendMax must be set before
the segment is sent in this case (as receive/send will currently stack up in a
single thread).


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


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

* Header prediction was a bit too generous (and thus used too often)
* SendData() could return an error and still wanted to own the buffer passed in
* Removed the timeout computations from SendData() - looks like it's usually
done the simple way when the data has to be submitted in smaller packets.
* ReadData() no longer blocks in case the peer has closed the connection.
* More debug output.


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


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

We shouldn't try to unlock a no-longer-existing endpoint.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19425 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