TCP states are swaped between "server" context and the new connection
context. But in any case the "server" context should loose the
information that makes it able to accept other new connections.
The swap was badly made, as the "server" context was loosing the
accept_cb (!) and the user data pointer. Instead the new connection
context was unrelevantly inheriting those.
Change-Id: Icc877449e1d4c4e59553dcbfd41718c5006edca0
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
It is useful that the user API can know whether the connection
was established properly or not. So this commit adds status
parameter to connect callback in net_context API.
The call to connect callback needs to be set properly in TCP
code. This commit does not fix the connect callback call which
is not properly done right now in net_context.c.
Change-Id: I284a60ddd658ceef9e65022e96591f467a936a09
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Wrong pool pointer was used when printing pool information during
the unref in nbuf.c. During nbuf init, wrong pool pointer was used
when printing memory pool sizes.
Change-Id: I9ed08cf7afa3c841c97ea981b97fff37aa40a984
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If the parameter "timeout" is set in net_context_connect(), the
assumption by the user is that the function would wait for SYNACK
to be received before returning to the caller.
Currently this is not the case. The timeout parameter is handed
off to net_l2_offload_ip_connect() if CONFIG_NET_L2_OFFLOAD_IP is
defined but never handled in a normal call.
To implement the timeout, let's use a semaphore to wait for
tcp_synack_received() to get a SYNACK before returning from
net_context_connect().
Change-Id: I7565550ed5545e6410b2d99c429367c1fb539970
Signed-off-by: Michael Scott <michael.scott@linaro.org>
net_context is used for more than just TCP contexts. However,
the accept_cb field is only used for TCP. Let's move it from
the generic net_context structure to the TCP specific net_tcp
structure.
Change-Id: If923c7aba1355cf5f91c07a7e7e469d385c7c365
Signed-off-by: Michael Scott <michael.scott@linaro.org>
When SYNACK is received we dont hand off the netbuf to anything
which will call net_nbuf_unref, so let's not mark it NET_OK.
Instead let the code path fall through to mark it NET_DROP.
Change-Id: I1f883e1a13c53c930bf50c07ff701e3db6f02d8a
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Now that the TCP_FIN block is after a potential packet_received()
tcp->send_ack should be appropriately set to the last sequence
processed.
In the case of a TCP_FIN buffer, we should advance it by 1 or else
the destination will continue to retry to send the last block.
Change-Id: I9c97d35a87ad6cc1a50f928b237780bff4cd2877
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Since we default to a return value of NET_DROP, we
can remove the automatic NET_DROP in the TCP_FIN block.
The return value will be set to NET_OK by packet_received()
if appropriate data is found which needs to be sent to
the callback.
Change-Id: Ib2634ba34440ca7053a4e98bf80f12cf6fbbd361
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Buffers marked TCP_FIN may still have data attached to them
which needs to be processed and handed back to the callback.
Let's move the TCP_FIN handling to after the data processing
section now that we have a copy of the TCP flags to do this.
Change-Id: I90f53b10e393024ebffebe1837b8866764b8a7ac
Signed-off-by: Michael Scott <michael.scott@linaro.org>
buffer TCP flags can be cleared during packet_received so let's
save a copy of them for later.
Change-Id: I401e99c1ed2723dac4e86da58635b548a5645c13
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Allow building the IP stack with newlib by enabling linux extensions.
Jira: ZEP-1592
Change-Id: I6714b73c7666a6f56c5203e2754ce1d7d94af0f1
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
CONFIG_STDOUT_CONSOLE is anyway disabled by default so printf() will not
output anything without it.
Change-Id: I8013e4efa5cb760215316e9413734281fb576f4d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
In some situations, for example, when the remote side sends a RESET
message indicating that it is no longer interested in observing a
resource, it is helpful to have a way to obtain the obverser
representation.
Change-Id: Ifbf627f9170be844fd525c557dda8cb722ac7aff
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
When retrieving options that represent an integer, the order of the
bytes being considered was inverted, resulting in invalid values being
returned.
Change-Id: I8ba84f77e3402066632c0ba650939266c87a8ea2
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
For example, when a RESET packet is passed to zoap_handle_request(),
there's nothing it can do, and it's not an error, so it returns
success silently.
Change-Id: I025bb44733521d6132999c219aaa292a3de302d7
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
When parser encouter DHCPV4_OPTIONS_END, it immediately returns NET_OK.
No need to maintain end variable here.
Coverity-CID: 157584
Change-Id: I4c8b91f37ae882845c280dab1a8204966aaac00a
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Pointer udp will be NULL when (!(CIPHC[0] & NET_6LO_IPHC_NH_1))
condition is true.
Coverity-CID: 157588
Change-Id: I8aa1eb2e4d4aee8039631d76ad0ecc345247d6b5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
When contex information provided and DAC bit is not set and vice versa
are invalid cases.
Coverity-CID: 157569
Change-Id: I1b798703cbbb6155a7bdf734d0fcde9ce48c409c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
In net_nbuf_get(), check that context pointer value is not
null before accessing data via it.
Coverity-CID: 157600
Change-Id: I7e7ea19a85f6fbef129e9ce699ea740d3be84cb8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If neighbor is not found, then ignore the timeout.
Coverity-CID: 157583
Change-Id: Ia2199970bd862e43901f5717025271c11c74af5e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We need to allocate separate fragment to store the IP
protocol headers.
Coverity-CID: 157582
Change-Id: Ib0dd5d28cd6876a0cf2de3b063c030ef64da998c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Callback cannot be null so no need to check its value.
Coverity-CID: 157572
Change-Id: I26e4b24c41d30aa9007b78895975035e6bf8807f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The context parameter might be NULL so we need to check
its value before accessing its content.
Coverity-CID: 157571
Change-Id: I7f75323d9d261a77421688f37a40bb44ff3ca2bd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The link layer dereferences a buffer right after it is transmitted.
If this extra reference is not held, the second time a buffer is
retransmitted, the reference that TCP holds when keeping the buffer in
the `sent_list` will be taken, and retransmission won't happen reliably
anymore.
As soon as the TCP fragment is acknowledged by the peer, the
`sent_list` reference is taken, and the buffer is freed.
Change-Id: Ie50f9acf02c1dff74248a5dfbec3785a91ff90f7
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
No more than 4 bits are necessary to store the state of a TCP connection,
so better pack it using bitfields so that it uses only 4 bits instead of
32, by sharing space with `retry_timeout_shift` and `flags` fields.
There are 12 (or 14, if you count the 2 unused bits in the `flags`
field) bits remaining in the same dword, but I don't know what to to
stuff there yet.
This also changes all direct field access for the `state` field to
function calls. These functions are provided as `static inline`
functions and they perform only casts, so there's no function call
overhead.
Change-Id: I0197462caa0b71b287c0773ec5cd2dd4101a4766
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
This frees up some more memory as well, by computing the maximum segment
size whenever needed. A flag is set in the TCP context to signal if
the value has been already computed.
Change-Id: Idb228d4682540f92b269e3878fcee45cbc28038a
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
This value is never set (always zero), so it's safe to remove it from
the net_tcp struct.
Change-Id: Ie4c1d90204a9834f2223b09828af42ee101bd045
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
Rename the variable to `retry_timeout_shift`, and shift-right the value
each time there's a timeout. This saves some memory in that structure
by using the holes left due to alignment.
Change-Id: I18f45d00ecc434a588758a8d331921db902f4419
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
Cancel all delayed work timers: FIN, ACK, and retry timers. Also, do
that unconditionally regardless of which state the machine is in, as
that's a no-op if the timer has not been started yet.
Change-Id: Ia36b97c6823943976447fbd6389ae04862c19ff9
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
The net_tcp struct was being cleaned up and destroyed when the
outbound FIN packet is sent on a connection that already received an
inbound FIN. That's not right, per spec we need to wait for the ACK
(though this would be benign cheating). And worse: there were code
paths which were themselves spec-compliant where the net_tcp struct
(now a NULL pointer) would be used after this spot leading to
occasional crazy behavior on socket close.
Don't do it this way. Clean up the TCP struct at the same time we
destroy the net_context. Much saner that way.
Change-Id: I4bc6b97eb0b71a7fa8faea02c1eb4c4d3bd3ae6d
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
The TCP stack inherited msot of the user_data management from UDP, but
it doesn't quite work. It's not possible to have a single pointer in
the general case, as e.g. a net_context_send() call may happen
synchronously underneath a recv callback and clobber the pointer, even
though there will be much more data coming later on the active stream.
Put a recv_user_data field into the TCP struct and use that. Long
term, it would be good to revisit this and come up with a unified
solution that works for both. There is yet another "user_data"
pointer in net_connection that seem likely to overlap too.
Change-Id: Id3a8eca64fc680e0e80b74944c4d621d7810a8fe
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Let's drop the lladdr variable and get the link address and
length from the net_linkaddr_storage variable instead.
Change-Id: I75a5d08527cda7df102db897ade9015d39f10caf
Signed-off-by: Michael Scott <michael.scott@linaro.org>
lladdr.addr doesn't point to any storage value when it's
handed off to the net_nbuf_read function. This results
in a write to an undefined area of memory.
Fix this by pointing lladdr.addr to a net_linkaddr_storage
structure's byte storage array which can handle the maximum
specified length.
Change-Id: I05e0a0420b262ba1e5ac95cebe1f0d91f54878ce
Signed-off-by: Michael Scott <michael.scott@linaro.org>
The net_linkaddr_storage structure contains an array of bytes used
to store the link address. This array can be different sizes
depending on the CONFIG options used when building. To facilitate
consistency and error checking let's introduce a new helper function
to copy the addr and len values to this structure.
Also move all uses of memcpy related to net_link_storage structures to
the new helper function.
Change-Id: Ic547d86b07e62e5ac3bc330d4eaeb4508a143200
Signed-off-by: Michael Scott <michael.scott@linaro.org>
- Introduce NET_LINK_ADDR_MAX_LENGTH which is either 6 or 8
depending on whether CONFIG_NET_L2_IEEE802154 is used
- Instead of being a placeholder single index array of uint8_t,
let's use NET_LINK_ADDR_MAX_LENGTH to assign the size of the
"addr" array field in the net_linkaddr_storage structure.
- Now that the "addr" field of net_linkaddr_storage contains the
true size of the link address, we can remove "storage" field
which was hard coded to 8 bytes (2 uint32_t's).
- Fix 2 references to the "storage" field of the net_linkaddr_storage
structure.
Change-Id: I2ea12058280b289f65085964eb7d503d4fd260c2
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.
Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.
Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file. Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.
Jira: ZEP-1457
Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Be nice and inform user about unsupported and dropped frames.
Change-Id: Iaf0e7ed660a926c45dac9fc36b788c4c786eac11
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
This adds NET_REQUEST_BT_DISCONNECT which can be used to disconnect
IPSP in case it is connected.
Change-Id: I8da00b02ee08611bef5f4c0708936b2d31fd2a93
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds NET_REQUEST_BT_SCAN which can be used to scan peripherals
advertising IPSS UUID.
Change-Id: I2463079d182b4da080e6ef94d883c7c1e24a454c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds a shell module called "net_bt" that exposes Bluetooth L2
management commands.
Change-Id: Ia6da1d38cfd51502119758a8f6abbb6d1cd31743
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Connect command can be used to initiate a connection, which in IPSP
terminology refer to a router role.
Change-Id: I12b9428924c88a9c68d3adbfe9016a0dd690aade
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Including logging/sys_log.h before net_core.h prevents SYS_LOG_LEVEL,
etc, to be set properly.
Change-Id: Iaa7aa98110aa455162836be1d9560fbfc03569df
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This decodes the event layer, code and type when debugging is enabled.
Change-Id: I23c6fb200f3287a138e46df9f472c9982898675d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net_context_put() forgot to release the conn_handler field causing
subsequent failures in net_conn_register() when they ran out.
Change-Id: I0d306b5035199422fa8788338ac9da8d1900d5f9
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
TCP didn't actually have a way to signal synchronous receipt of a FIN
packet. Extend the recv_cb API to allow a NULL buf argument with
status==0 (by analogy to Unix's zero-length read) to signal EOF.
Update docs too, and also echo_server which wasn't prepared to handle
this situation.
Change-Id: I7dc08f9e262a81dcad9c670c6471898889f0b05d
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
In icmpv4, after calling setup_ipv4_header() function,
only calculate ICMP chksum, not calculate ipv4 header chksum,
ipv4 header chksum still 0, the other side will drop this pack.
Change-Id: I1550a4c8c7ab63132d70ba6ce19a7caf78ad84e6
Signed-off-by: li zj <279939902@qq.com>