Commit graph

1749 commits

Author SHA1 Message Date
Jukka Rissanen aee31bb7c1 net: tcp: Print information when proper ACK is received
It is useful to know that we received ACK when debugging the
TCP code.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Jukka Rissanen 8fd677e9e1 net: tcp: Fix memory leak when lot of incoming packets
The code was leaking memory in TX side when there was lot of
incoming packets. The reason was that the net_pkt_sent() flag
was manipulated in two threads which caused races. The solution
is to move the sent flag check only to tcp.c.

Fixes #23246

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Andrew Boie 760644041c net: purge NET_STACK and other stack APIs
The current design of the network-specific stack dumping APIs
is fundamentally unsafe. You cannot properly dump stack data
without information which is only available in the thread object.

In addition, this infrastructure is unnecessary. There is already
a core shell command which dumps stack information for all
active threads.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-14 13:10:19 -04:00
Stephanos Ioannidis 5aa62369d4 net: shell: Handle ENETUNREACH for IPv4 ping
This commit updates the the IPv4 ping command to handle the ENETUNREACH
error number returned by `net_icmpv4_send_echo_request` function when
IPv4 is unavailable.

The `net_icmpv4_send_echo_request` function previously returned EINVAL
when IPv4 is unavailable and this caused the shell command to report
"Invalid IP address" even when the provided IP address is correct; this
problem was corrected by returning ENETUNREACH instead of EINVAL in the
aforementioned function.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-11 13:25:55 -05:00
Stephanos Ioannidis 2c733d5195 net: icmpv4: Return ENETUNREACH when IPv4 is unavailable
net_icmpv4_send_echo_request currently returns EINVAL (invalid
argument) when IPv4 is unavailable.

Since the availability of IPv4 has nothing to do with the arguments
provided to this function and the meaning of EINVAL in this case is
ambiguous, return the ENETUNREACH (network is unreachable) error
number instead.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-11 13:25:55 -05:00
Oleg Zhurakivskyy bedd4e01fd net: tcp2: Add a mutex to TCP connection
The TCP connection might be concurrently modified from the
TR/TX threads, so add a mutex to protect from the concurrent
modification.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy fad38b12a3 net: tcp2: Update test protocol functions
After removing the test windows, update test protocol
functions for the TTCN-3 sanity check.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 615d73b2c9 net: tcp2: Set TCP connection endpoints in net_tcp_connect()
Initialize and set IPv4/IPv6 connection endpoints in net_tcp_connect().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy a156d76f8e net: tcp2: Do not base the incoming data evaluation on PSH
Do not base the incoming data evaluation on PSH.

Also, reduce the condition branches.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy f149eb7b14 net: tcp2: Remove obsolete test window functions
These test receive windows were used by TTCN-3 sanity check,
but it's possible to do without them.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 16b8244cf8 net: tcp2: Eliminate the need for a test send window
In order to drop dependency on a heap, drop the
test send window.

Use net_tcp_queue_data() to receive the outgoing data
from the socket layer.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy b25faa6159 net: tcp2: Eliminate the need for a test receive window
In order to drop dependency on a heap, drop the test
receive window.

The receive window was needed for TTCN-3 sanity check,
but it's possible to do without it.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 4c81935c2e net: tcp2: Don't instantiate an extra connection on SYN+ACK
On incoming SYN+ACK, use the existing TCP connection.

This problem was overlooked earlier and was found while
testing TCP2 client side.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy b0381bc80e net: tcp2: Check the ack number in SYN_SENT
In SYN_SENT check the ack number of the incoming TCP message
against our sequence number.

This problem was overlooked earlier and was found while
testing TCP2 client side.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 038618dbc8 net: tcp2: Guard against th_get() on NULL pkt
This problem was overlooked earlier and was found while
testing TCP2 client side.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 1eccf22526 net: tcp2: Add log_strdup() where necessary
In case the log output involves the content of the static
buffer, add log_strdup().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy ebbb7f3d56 net: tcp2: Don't instantiate an extra connection on connect
Don't erroneously instantiate an extra TCP connection
on TCP connect.

This problem was overlooked earlier and found while testing
TCP2 client side.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy d6f1937fbb net: tcp2: Switch from k_timer to k_delayed_work
k_timer callback is executed from ISR context, which isn't
currenty compatible with Zephyr's shell implementation.

This problem was found while testing TCP2 client side.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy bab5e7bd96 net: tp: Add IPv6 support for test protocol
In order to suport using test protocol over IPv6,
add IPv6 support.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 27a12b78cb net: tcp2: Drop obsolete ip_get(), ip6_get() macros
After adding IPv6 support, there's no need for them.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy e301397af1 net: tcp2: Use net_tcp_finalize() for checksum calculation
In order to support IPv6, use net_tcp_finalize() for checksum
calculation.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 9292ce9efc net: tcp2: Add IPv6 support for outgoing packets
Add IPv6 support for outgoing packets.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 75820c9bdf net: tcp2: Register test inputs for TTCN-3 based TCP2 sanity check
In order to support TTCN-3 based TCP2 sanity check,
register test inputs with net_conn_register() and adjust
test functions to account for this.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy f5c1ee03b8 net: tcp2: Add support for a IPv6
In order to support IPv4/IPv6, work with packet through
net_pkt_ip_hdr_len(), net_pkt_ip_opts_len() which account
for IPv4/IPv6, IPv4 options and IPv6 extension headers.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 6be5935f17 net: ipv4: Remove temporary interception of TCP, UDP for TCP2
Remove temporary interception of TCP, UDP for TTCN-3 based
TCP2 sanity check.

As a part of adding IPv6 support, TCP2 will register test
callbacks/inputs with net_conn_register().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Patrik Flykt 794b32a4fc net: tcp2: Allocate endpoints before using
Allocate tcp2.c endpoints before storing port numbers or addresses.
Select the IPv4 source address since net_context_create_ipv4_new()
is not currently called on packet output.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2020-03-11 16:24:52 +02:00
Marcin Niestroj f15ac65254 net: icmpv4: drop requests on NET_OFFLOAD interfaces
NET_OFFLOAD interfaces do not handle ICMP request. Request to send ICMP
packet resulted in NULL pointer dereference in net_if_tx() later
on. Prevent that by detecting NET_OFFLOAD interfaces early in icmpv4
module.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-03-10 16:44:13 +02:00
Jukka Rissanen 505e306b72 net: context: Allow binding AF_PACKET multiple times
If the system has more than one network interface, then it should
be possible to bind a AF_PACKET socket to each interface if the
network interface index is set when bind() is called. This was
not possible earlier as the code was always using default network
interface with AF_PACKET socket bind().

Fixes #23153

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-10 14:58:30 +02:00
Luuk Bosma 9587a271f6 net/ip/dhcpv4: Set Host Name in DHCP Request
This option specifies the name of the client.
See https://tools.ietf.org/html/rfc2132#section-3.14

This is useful for identification when looking in DHCP lease table.

Signed-off-by: Luuk Bosma <l.bosma@interay.com>
2020-03-10 14:10:01 +02:00
Jukka Rissanen 2d992baa42 net: ipv6: Add network interface to various debug prints
Useful when figuring out where the device is sending the
network packet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-10 12:39:13 +02:00
Ravi kumar Veeramally 491367115d net: ipv4: Fix compilation errors
opts_len renamed to total_opts_len in previous changes.
But it's not replaced at one place.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-03-03 16:50:32 +02:00
Ravi kumar Veeramally 22f93b35ab net: ipv4: Fix parsing of IPv4 header options
If IPv4 header options has wrong options length
(e.g. options length is more that actual data),
then parser decrements opts_len without checking
actual data length. Which crashes the network stack.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-02-28 22:34:11 +02:00
Ravi kumar Veeramally 3ce7f89a8a net: pkt: Restore pkt cursor after cloning
net_pkt_clone() initializes the original packet cursor
and clone the packet. But it doesn't restore the cursor
back to original position.

Issue noticed when mDNS resolving fails when mdns responder
is also enabled.

net_conn_input(), in case of multicast packet, connection
handler clone the packet and deliver to matching handler.

Example case: dns_resolver and mdns_responder both register
handlers for 5353 port. After first clone original packet
cursor moved back to starting position. But first cloned
packet cursor is set properly. Second time cloning makes
cursor position to set to zero. Which makes second packet
handler header unpacking goes wrong.

Fixes #21970.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-02-21 16:49:14 +02:00
Ulf Magnusson 378d6b137a kconfig: Replace non-defconfig single-symbol 'if's with 'depends on'
Same deal as in commit eddd98f811 ("kconfig: Replace some single-symbol
'if's with 'depends on'"), for the remaining cases outside defconfig
files. See that commit for an explanation.

Will do the defconfigs separately in case there are any complaints
there.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-02-12 10:32:34 -06:00
David D 3de967749a net: pkt: Fixed packet buffer corruption in net_pkt_pull()
Changed size related variables type to size_t to handle
large packet buffers correctly

Signed-off-by: David D <a8961713@gmail.com>
2020-02-03 10:47:08 +02:00
Jukka Rissanen 4cad0dda44 net: ipv6: When sending NS, use correct destination address
When we are about to send a NS, we should not use the destination
address as that is typically the multicast address. We should use
the target address instead.

This fixes the case where a neighbor is in incomplete state, and
we send a neighbor solicitation to find out whether the neighbor
is reachable. In this case the destination address is the solicited
node multicast address which is no use when trying to figure out
the source address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-01-30 09:42:07 +02:00
Alexander Wachter cd2ff16a50 net: icmpv6: fix add own IP addr to nbr cache
This commit fixes a problem where our own IP address
is added to the cache instead of the senders.
This bug was due to a swap of the address in the original packet.
The swapping of the address is now removed.

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
2020-01-29 11:39:50 +02:00
Jonas Norling 5f2d038410 net: ipv6: nbr: Add neighbor when responding to NS
A neighbor solicitation packet for an address that is not ours should
not cause the sender to be added to the neighbor cache. See RFC 4861
section 7.2.3.

Add the neighbor to the cache when we have decided to respond to the
NS packet.

Fixes #21869.

Signed-off-by: Jonas Norling <jonas.norling@greeneggs.se>
2020-01-23 21:10:48 +02:00
Jonas Norling 744665f5f4 net: ipv6: nbr: Factor out parsing of ll address option
Use the same code when parsing source link-layer address option for
both RA and NS packets. It looked like handle_ns_neighbor() could
actually read too much data into lladdr.addr when handling 8-byte
addresses (802.15.4).

Signed-off-by: Jonas Norling <jonas.norling@greeneggs.se>
2020-01-23 21:10:48 +02:00
Robert Lubos 799a8401e7 net: 6lo: Fix memory corruption during uncompression
A memory corruption could happen in `uncompress_IPHC_header` function,
when data was moved to make place in the net buffer for the uncompressed
IPv6/UDP header.

The size of data being moved should only contain the original data size,
not incremented by the amount of space needed to expand the header,
which was already added to the net buffer size. In result, the `memmove`
operation could exceed the allocated net buffer and cause memory
corruption.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-22 11:57:11 -06:00
Christian Taedcke 2d9750734c net: ipv6: Add routing according to interface prefix
If no other route is found, the network interface prefixes are
evaluated. If a matching interface is found, the packet is sent out on
this interface.

Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
2020-01-20 17:22:49 +02:00
Christian Taedcke 6dc1904b9d net: ipv6: Set INET6 addr family before routing the rx packet
The address family of the received packet must be set, before routing
it. E.g. the ethernet driver would drop the packet if this is not
done.

Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
2020-01-20 17:22:49 +02:00
Christian Taedcke 275d8558c6 net: if: Add option to set ppp as default network if
Now the ppp interface can be selected as the default network interface.

Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
2020-01-17 06:44:32 -06:00
Oleg Zhurakivskyy 33929cb960 net: tcp2: Guard on th being NULL in SYN_RECEIVED
The transition from LISTEN to SYN_SENT nullifies the th,
guard on th being NULL in SYN_SENT.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy ff2d4737d6 net: tcp2: Immediately ACK the data in SYN_RECEIVED
In case the final ACK contains the data in SYN_RECEIVED,
immediately ACK the data.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 2abe76f1d6 net: tcp2: Drop the restriction on PSH in SYN_RECEIVED
Data doesn't imply PSH set, such a check is wrong.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 9b30ca4e76 net: tcp2: Evaluate the sequence number in SYN_RECEIVED
In case the final ACK for the connection establishment arrives
out of order, evaluate the sequence number in SYN_RECEIVED,
so the data packet isn't false identified as a final ACK.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy f3936dc880 net: tcp2: Turn on ACK for the outgoing data packet
This is a workaround for tools that don't particularly
like such packets.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 175b45e768 net: tcp2: Add len and evaluate data for the incoming packet
In order to simplify the evaluation of the incoming data,
add len and evaluate the data for the incoming packet once.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy df4ffb3d83 net: tcp2: Add the interrupt locking in _tcp_send()
_tcp_send() can be preempted by the incoming data,
add the interrupt locking.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 9abccf911c net: tcp2: Update tcp_recv() logic
Create a new connection only for the SYN packet,
otherwise pass a packet into existing connection.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 9378ac784b net: tcp2: Fix the diagnostic in tcp_options_check()
Report the correct length for PAD and NOP.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 44b2529998 net: tcp2: Refactor tcp_data_len()
- Rename data_len to len
- Add a diagnostic print

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy dc0c313bb1 net: tcp2: Do not bail-out on unconsumed flags
The initial logic with this check is too restrictive,
do not bail-out on unconsumed flags.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 3d898ccf16 net: tcp2: Do not access freed TCP connection in tcp_conn_unref()
Fix a potentially problematic access of the slab's data
after the slab was freed.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy c4b87ce7fc net: tcp2: Nullify the packet pointer on a state change
Nullify the packet pointer on a state change.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy ab88912a27 net: tcp2: Add diagnostic information to tcp_chain()
Add a diagnostic information on network buffer sizes
and the total length of the packet.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy d99133c4f5 net: tcp2: Set the net_context to NET_CONTEXT_CONNECTED once
Set the net_context to NET_CONTEXT_CONNECTED state only once
in transitions to TCP_ESTABLISHED.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 5847694a1d net: tcp2: Update tcp_conn_state()
Make the reporting of the sequence and acknowledgement numbers
more descriptive.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 86bdab62aa net: tcp2: Support arbitrary length in tcp_win_append()
This change adds a support arbitrary data lengths.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy b0b7b02f2a net: tcp2: Support arbitrary requests in tcp_win_pop()
This change adds a support arbitrary data lengths
for tcp_win_pop().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy b384355dd9 net: tcp2: Refactor tcp_th()
1. Use tcp_flags() for flags
2. Add len

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 85a69a219d net: tcp2: Refactor tcp_flags()
1. Reduce the internal buffer
2. Eliminate extra string pointer
3. Add a comment on deleting the last comma

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 225dc48d5b net: tcp2: Rename tcp_pkt_received() into tcp_recv()
In order to unify with tcp_send(), rename tcp_pkt_received()
into tcp_recv().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 2c436740cf net: tp: Rename tcp_recv() into tp_tcp_recv()
In order to avoid naming collision with tcp_recv(),
rename tcp_recv() into tp_tcp_recv().

This function is used by the test protocol.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 50d7efbdbc net: tp: Add a support for arbitrary payloads in tp_output()
Remove the limitation of a data fitting into the single network buffer.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-17 10:24:06 +02:00
Oleg Zhurakivskyy 63ae98f29c net: tcp2: Drop snprintf() and use snprintk()
Drop snprintf() and use snprintk() as snprintk()
is more suitable for the networking code.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Oleg Zhurakivskyy 043b4368b8 net: tcp2: Use CONFIG_NET_TCP_INIT_RETRANSMISSION_TIMEOUT
Use CONFIG_NET_TCP_INIT_RETRANSMISSION_TIMEOUT for the
retransmission timeout value.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Oleg Zhurakivskyy cbfc50ef37 net: tcp2: Use CONFIG_NET_BUF_DATA_SIZE for network buffer size
Use CONFIG_NET_BUF_DATA_SIZE for the maximum network buffer size
in TCP windows.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Oleg Zhurakivskyy 2928b52988 net: tcp2: Delete unused tcp_pkt_linearize()
Delete unused tcp_pkt_linearize().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Oleg Zhurakivskyy 78c39d511b net: tcp2: Support arbitrary payloads in tcp_csum().
Support arbitrary payloads in tcp_csum().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Oleg Zhurakivskyy 0d67e3cb32 net: tcp2: Support tracking of net_buf_clone()
Support tracking of net_buf_clone().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Oleg Zhurakivskyy 78dd50bae4 net: tcp2: Support arbitrary payloads in TCP windows
Support arbitrary payloads in TCP windows.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Oleg Zhurakivskyy b3eb69ecf9 net: tcp2: Add a support for net_buf reservation
This simplifies the error handling in buffer allocation.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Oleg Zhurakivskyy fe1b0d067f net: tcp2: Fix the snprintf() format specification
Zephyr's snprintf() doesn't support %zd.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Oleg Zhurakivskyy c329e22f13 net: tcp2: Fix the clang compilation warnigs for native_posix
Fix the clang compilation warnigs for the native_posix target:

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Oleg Zhurakivskyy 8a77b53053 net: core: Drop NET_ASSERT_INFO() macro
A single assert macro can serve a purpose here.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Ulf Magnusson bd9962d8d9 kconfig: Remove '# hidden' comments on promptless symbols
Same deal as in commit 41713244b3 ("kconfig: Remove '# Hidden' comments
on promptless symbols"). I forgot to do a case-insensitive search.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-03 11:38:40 +01:00
Jukka Rissanen 9d8f12b2dd net: stats: Fix RX traffic class time statistics update
The commit 8892406c1d ("kernel/sys_clock.h: Deprecate and convert
uses of old conversions") changed code to not use deprecated macro.
Unfortunately there was some changes done to RX TC stats update that
were missing from that commit. This commit fixes the issue and removes
the last user of the deprecated SYS_CLOCK_HW_CYCLES_TO_NS64() macro.

This is follow up to commit 5bbdf56769 ("net: stats: Fix RX time
statistics update") which failed to remove all users of the deprecated
macro.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-12-18 17:59:54 +02:00
Jukka Rissanen 5bbdf56769 net: stats: Fix RX time statistics update
The commit 8892406c1d ("kernel/sys_clock.h: Deprecate and convert
uses of old conversions") changed code to not use deprecated macro.
Unfortunately there was some changes done to RX stats update that were
missing from that commit. This commit fixes the issue and removes use
of the deprecated SYS_CLOCK_HW_CYCLES_TO_NS64() macro.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-12-17 13:06:55 -05:00
Ravi kumar Veeramally 1c33951318 net: icmpv4: Add support for Timestamp and RR
Timestamp and RecordRoute options are supported
in only ICMPv4 EchoRequest call as per
RFC 1122 3.2.2.6.

Fixes #14668

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-12-16 11:35:24 +02:00
Ravi kumar Veeramally cf9ad748ba net: ipv4: Add IPv4 options length to net pkt
IPv4 header options length will be stored in ipv4_opts_len
in net_pkt structure. Now IPv4 header length will be in
net_pkt ip_hdr_len + ipv4_opts_len. So modified relevant
places of ip header length calculation for IPv4.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-12-16 11:35:24 +02:00
Jonas Norling 0ef4634bc5 net: iface: Remove expired router from list of active routers
An expired IPv6 router would cause an infinite loop where
iface_router_run_timer() repeatedly scheduled a work item. In some
conditions it would schedule with negative delay, in other conditions
the infinite loop wouldn't happen until a router was added again.

Get rid of the router from active_router_timers when it is removed.

Fixes #21339

Signed-off-by: Jonas Norling <jonas.norling@greeneggs.se>
2019-12-13 14:00:44 +02:00
Ulf Magnusson 984bfae831 global: Remove leading/trailing blank lines in files
Remove leading/trailing blank lines in .c, .h, .py, .rst, .yml, and
.yaml files.

Will avoid failures with the new CI test in
https://github.com/zephyrproject-rtos/ci-tools/pull/112, though it only
checks changed files.

Move the 'target-notes' target in boards/xtensa/odroid_go/doc/index.rst
to get rid of the trailing blank line there. It was probably misplaced.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-11 19:17:27 +01:00
Kumar Gala 9415a114a0 include: Fix use of <json.h> -> <data/json.h>
Fix #include <json.h> as it has been deprecated and
should be #include <data/json.h>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-10 08:39:37 -05:00
Ulf Magnusson 87e917a925 kconfig: Remove redundant 'default n' and 'prompt' properties
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Also replace some

    config
    	prompt "foo"
    	bool/int

with the more common shorthand

    config
    	bool/int "foo"

See the 'Style recommendations and shorthands' section in
https://docs.zephyrproject.org/latest/guides/kconfig/index.html.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-09 16:14:50 +01:00
Alexander Wachter 052e79ec53 net: ip: 6lo: Add NULL ptr check for dst context
This commit adds a NULL pointer check for the destination
context pointer. The pointer is NULL in case the context
does not exist.

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
2019-11-21 12:49:20 +01:00
Piotr Zierhoffer bb66b298e9 net: ip: ipv6_nbr: Fix uninitialized variable in ipv6_nbr
Setting it to UINT32_MAX, as it is subsequently overwritten with
MIN(oldest, something_else).

Signed-off-by: Piotr Zierhoffer <pzierhoffer@antmicro.com>
2019-11-12 16:12:10 +01:00
Peter Bigot 80faac41bc coccinelle: update int literal to timeout
Re-run the int_literal_to_timeout script to update calls introduced
since the last cleanup.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-11-08 19:30:42 -05:00
Andy Ross 8892406c1d kernel/sys_clock.h: Deprecate and convert uses of old conversions
Mark the old time conversion APIs deprecated, leave compatibility
macros in place, and replace all usage with the new API.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-11-08 11:08:58 +01:00
Stephanos Ioannidis 2d7460482d headers: Refactor kernel and arch headers.
This commit refactors kernel and arch headers to establish a boundary
between private and public interface headers.

The refactoring strategy used in this commit is detailed in the issue

This commit introduces the following major changes:

1. Establish a clear boundary between private and public headers by
  removing "kernel/include" and "arch/*/include" from the global
  include paths. Ideally, only kernel/ and arch/*/ source files should
  reference the headers in these directories. If these headers must be
  used by a component, these include paths shall be manually added to
  the CMakeLists.txt file of the component. This is intended to
  discourage applications from including private kernel and arch
  headers either knowingly and unknowingly.

  - kernel/include/ (PRIVATE)
    This directory contains the private headers that provide private
   kernel definitions which should not be visible outside the kernel
   and arch source code. All public kernel definitions must be added
   to an appropriate header located under include/.

  - arch/*/include/ (PRIVATE)
    This directory contains the private headers that provide private
   architecture-specific definitions which should not be visible
   outside the arch and kernel source code. All public architecture-
   specific definitions must be added to an appropriate header located
   under include/arch/*/.

  - include/ AND include/sys/ (PUBLIC)
    This directory contains the public headers that provide public
   kernel definitions which can be referenced by both kernel and
   application code.

  - include/arch/*/ (PUBLIC)
    This directory contains the public headers that provide public
   architecture-specific definitions which can be referenced by both
   kernel and application code.

2. Split arch_interface.h into "kernel-to-arch interface" and "public
  arch interface" divisions.

  - kernel/include/kernel_arch_interface.h
    * provides private "kernel-to-arch interface" definition.
    * includes arch/*/include/kernel_arch_func.h to ensure that the
     interface function implementations are always available.
    * includes sys/arch_interface.h so that public arch interface
     definitions are automatically included when including this file.

  - arch/*/include/kernel_arch_func.h
    * provides architecture-specific "kernel-to-arch interface"
     implementation.
    * only the functions that will be used in kernel and arch source
     files are defined here.

  - include/sys/arch_interface.h
    * provides "public arch interface" definition.
    * includes include/arch/arch_inlines.h to ensure that the
     architecture-specific public inline interface function
     implementations are always available.

  - include/arch/arch_inlines.h
    * includes architecture-specific arch_inlines.h in
     include/arch/*/arch_inline.h.

  - include/arch/*/arch_inline.h
    * provides architecture-specific "public arch interface" inline
     function implementation.
    * supersedes include/sys/arch_inline.h.

3. Refactor kernel and the existing architecture implementations.

  - Remove circular dependency of kernel and arch headers. The
   following general rules should be observed:

    * Never include any private headers from public headers
    * Never include kernel_internal.h in kernel_arch_data.h
    * Always include kernel_arch_data.h from kernel_arch_func.h
    * Never include kernel.h from kernel_struct.h either directly or
     indirectly. Only add the kernel structures that must be referenced
     from public arch headers in this file.

  - Relocate syscall_handler.h to include/ so it can be used in the
   public code. This is necessary because many user-mode public codes
   reference the functions defined in this header.

  - Relocate kernel_arch_thread.h to include/arch/*/thread.h. This is
   necessary to provide architecture-specific thread definition for
   'struct k_thread' in kernel.h.

  - Remove any private header dependencies from public headers using
   the following methods:

    * If dependency is not required, simply omit
    * If dependency is required,
      - Relocate a portion of the required dependencies from the
       private header to an appropriate public header OR
      - Relocate the required private header to make it public.

This commit supersedes #20047, addresses #19666, and fixes #3056.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-11-06 16:07:32 -08:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00
Ulf Magnusson 975de21858 kconfig: Global whitespace/consistency cleanup
Clean up space errors and use a consistent style throughout the Kconfig
files. This makes reading the Kconfig files more distraction-free, helps
with grepping, and encourages the same style getting copied around
everywhere (meaning another pass hopefully won't be needed).

Go for the most common style:

 - Indent properties with a single tab, including for choices.

   Properties on choices work exactly the same syntactically as
   properties on symbols, so not sure how the no-indentation thing
   happened.

 - Indent help texts with a tab followed by two spaces

 - Put a space between 'config' and the symbol name, not a tab. This
   also helps when grepping for definitions.

 - Do '# A comment' instead of '#A comment'

I tweaked Kconfiglib a bit to find most of the stuff.

Some help texts were reflowed to 79 columns with 'gq' in Vim as well,
though not all, because I was afraid I'd accidentally mess up
formatting.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-01 15:53:23 +01:00
Jukka Rissanen 1274850041 net: tcp: No need to unref pkt if it was not sent
In order to avoid net_pkt ref count going to <0, do not unref
the packet if it was not sent in the first place. This can happen
if the connection was closed while we are waiting packets to be sent.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-28 13:58:59 +02:00
Jukka Rissanen 44dc3a2ebb net: tcp: Allow state transition when socket is closed
Do not print warning if transitioning from LISTEN -> CLOSED which
happens when the socket is closed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-28 13:58:59 +02:00
Jukka Rissanen 21c10e50df net: tcp: Allow initial state to be set by net_tcp_change_state()
The initial state from CLOSED -> ESTABLISHED caused error
to be printed by state validator. This is unnecessary, so add
this as a valid state to validator.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-28 13:58:59 +02:00
Jukka Rissanen d88f25bd76 net: tcp: Handle special case where accepted socket is closed
Handle this corner case with TCP connection closing:

1) Client A connects, it is accepted and can send data to us
2) Client B connects, the application needs to call accept()
   before we will receive any data from client A to the application.
   The app has not yet called accept() at this point (for
   whatever reason).
3) Client B then disconnects and we receive FIN. The connection
   cleanup is a bit tricky as the client is in half-connected state
   meaning that the connection is in established state but the
   accept_q in socket queue contains still data which needs to be
   cleared.
4) Client A then disconnects, all data is sent etc

The above was not working correctly as the system did not handle the
step 3) properly. The client B was accepted in the application even
if the connection was closing.

After this commit, the commit called "net: tcp: Accept connections
only in LISTENING state" and related other commits are no longer
needed and are reverted.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-28 13:58:59 +02:00
Jukka Rissanen f093b710b5 net: tcp: Add Kconfig option for auto-accepting clients
Add CONFIG_NET_TCP_AUTO_ACCEPT option which can be used to
automatically accept incoming data connection even if the
application has not yet called accept(). This can speed up
data transfer from peer to the application.
Problem with this is that if the peer sends lot of data and
we have limited amount of net_buf's available, then we can
run out of them which is very bad situation and can lead to
deadlocks. Because of this, the setting is turned off by default.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-28 13:58:59 +02:00
Jukka Rissanen e73d5a6479 Revert "net: tcp: Accept connections only in LISTENING state"
This reverts commit 1a6f4a6368.

Let's try to fix the backlog handling instead of this.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-28 13:58:59 +02:00
Oleg Zhurakivskyy 446f50f382 net: tcp2: Use net_context to access TCP data
In order to properly remove struct tcp and its data, net_context
needs to be supplied as k_timer user data. Modify net_tcp_unref()
to take a net_context argument when removing, and add ifdefs
around code that after this will only be used by TCP testing
functionality.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy 851042e8e6 net: tcp2: Send TCP data to caller
Add a net_context backpointer and receiver user data to the tcp
structure. Once the desired callback and user data is set in
net_tcp_recv(), net_context_packet_received() can be called at
TCP reception in tcp_data_get(), moving the TCP data to the
recipient. IP and TCP protocol headers are sent as NULL, they
are not used by e.g. the socket code.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy 2eb1bef4c8 net: tcp2: Implement TCP data sending
Since TCP needs to be able to decide how much data is to be sent
in a TCP segment and when the segment needs to be sent, the TCP
data buffer needs to be passed down to the TCP stack. For tcp2
this causes a new function handling the data as a buffer or as an
iov to be implemented and only that function is called when
sending data out via the new TCP stack. net_tcp_send_data() is
invoked as the caller expects to be informed when the data has
been sent.

For the current stack keep the sending functions as is.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Patrik Flykt bc69ae4f22 net: tcp2: Add functionality for close()
Call TCP stack net_close() when net_tcp_put() is called. Pass in
the tcp struct as argument.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy c8a1b35987 net: tcp2: Implement accept() and connect()
Register the TCP connection when accept() and connect() is called.
With the connection registration net_context will have the necessary
callback pointer set up, whereby net_context can call the proper
function when receiving packets for the TCP connecton.

With the new TCP stack this callback is always the same function.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Patrik Flykt a4ac0b024b net: tcp2: Update net_context state on established TCP connection
Update net_context state to NET_CONTEXT_CONNECTED when TCP
ESTABLISHED state is reached.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy e3d3af2768 net: tcp2: Implement net_tcp_input()
Implement net_tcp_input().

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy fd2f26ba14 net: tcp2: Implement net_tcp_finalize()
Implement net_tcp_finalize().

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Jukka Rissanen 28547b8507 net: tcp2: Logging strings need to use log_strdup()
In order not to point to stack variable, use log_strdup() for
strings that are logged.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy deb5a4c72a net: shell: Disable TCP commands for TCP2
Currently the TCP commands work only for legacy TCP.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy c7c2495682 net: context: Document net_context_packet_received()
Document net_context_packet_received().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy 32040ce4df net: tcp2: Intercept TCP
Intercept TCP.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy 7ca983e6d3 net: tcp2: Add Kconfig and CMakeLists.txt entries
Add Kconfig and CMakeLists.txt entries.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy fb9288bf39 net: tp: Add test protocol
Add test protocol.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy 133fa0fb84 net: tcp2: Add experimental TCP
Add experimental TCP.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Markus Fuchs 4ff6c69233 net: dhcpv4: Cancel pending DNS queries on DNS server update
On processing a DNS server option, which re-initializes the DNS resolve
context, also cancel all pending DNS queries before closing the old DNS
resolve context. Otherwise, `z_clock_announce()` will later work on the
re-initialized context once the queries expire and crash because the
reference to the timeout function `query_timeout()` has been cleared.

Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
2019-10-22 15:06:51 +03:00
Jukka Rissanen f98684cbcf net: shell: Unify info print when an option is not enabled
Use same format string when printing information that certain
config option is not enabled. This saves some flash as the
same string can be shared in the shell.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-22 09:11:07 +03:00
Jukka Rissanen 97b6588976 net: tcp: When closing the connection send FIN without extra delays
The earlier code was always queuing the FIN that is sent when
connection is closed. This caused long delay (200 ms) before the peer at
the other end noticed that the connection was actually closed.
Now check if there is nothing in the queue, then send the FIN
immediately. If there is some data in the queue, flush it when a valid
ack has been received.

Fixes #19678

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-17 17:02:18 +03:00
Robert Lubos 047969c0d0 net: if: Fix interface initialization with socket offloading
A socket-offloaded interface should bypass interface initialization in
the same way as net-offloaded interface does.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-10-15 11:06:40 +03:00
Jukka Rissanen 0464caef6a net: shell: Add command to clear network statistics
Needed when testing the amount of bytes transferred.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-14 16:34:48 +03:00
Jukka Rissanen a779185133 net: stats: Add functions to reset the statistics
This function will be useful in shell when we want to monitor
the amount of bytes transferred and want to clear earlier
statistics.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-14 16:34:48 +03:00
Jukka Rissanen 8a0c917c92 net: shell: Print TX packet timings
Print information about how long network packets took from
application to the network device driver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-14 16:34:48 +03:00
Jukka Rissanen d03cb7367c net: Add statistics how long packets have spent in TX path
Calculate how long on average net_pkt has spent on its way from
application to the network device driver. The data is calculated
for all network packets and not just for UDP or TCP ones like in
RX statistics.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-14 16:34:48 +03:00
Jukka Rissanen 4f92b7b648 net: shell: Print RX packet timings
Print information about how long network packets took from
network device driver to the application.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-14 16:34:48 +03:00
Jukka Rissanen 8d3b74ab61 net: Add statistics how long packets have spent in RX path
Calculate how long on average net_pkt has spent on its way from
network device driver to the application. The data is only
calculated for UDP and TCP network packets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-14 16:34:48 +03:00
Peter Bigot e28f330a8e coccinelle: standardize k_thread create/define calls with integer timeouts
Re-run with updated script to convert integer literal delay arguments
to k_thread_create and K_THREAD_DEFINE to use the standard timeout
macros.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-09 08:38:10 -04:00
Jukka Rissanen 6933248e0c net: shell: ping: Figure out the output network interface
Try to figure out where the ping reply should be sent if there
are multiple network interfaces in the system.

Fixes #19612

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-07 12:51:38 +03:00
Benjamin Lindqvist 81ccbd96c9 net: coap: Add internal init function to seed message_id
Randomly generating ID the first time coap_next_id() is called is more
in accordance with CoAP recommendations (see
https://tools.ietf.org/html/draft-ietf-core-coap-18, section 4.4)

"It is strongly recommended that the initial value of the
variable (e.g., on startup) be randomized, in order to make successful
off-path attacks on the protocol less likely."

Doing this in a dedicated init function is the cleanest and most
idiomatic approach. This init function is not exposed publically which
means it will be called only once, by the network stack init procedure.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2019-10-04 21:22:55 +03:00
Jukka Rissanen f06fa770a6 net: shell: Print info about websocket
Add "net websocket" command that displays websocket information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-04 16:38:34 +03:00
Jukka Rissanen 6af987646f net: websocket: client: Simple API for Websocket client
Implement simple API to do Websocket client requests.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-04 16:38:34 +03:00
Andrew Boie fe031611fd kernel: rename main/idle thread/stacks
The main and idle threads, and their associated stacks,
were being referenced in various parts of the kernel
with no central definition. Expose these in kernel_internal.h
and namespace with z_ appropriately.

The main and idle threads were being defined statically,
with another variable exposed to contain their pointer
value. This wastes a bit of memory and isn't accessible
to user threads anyway, just expose the actual thread
objects.

Redundance MAIN_STACK_SIZE and IDLE_STACK_SIZE defines
in init.c removed, just use the Kconfigs they derive
from.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-09-30 15:25:55 -04:00
Wayne Ren 6bdeeca6f5 net: offload: When NET_OFFLOAD is enabled bypass some net_tcp functions
* The issue is found in supporting offload module esp8266
* For device like esp8266, it's responsible for tcp/udp handling,
  no need of net_tcp related functions
* This commit is only tested for esp8266, no gurantee for other
  modules

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-09-23 10:36:01 +03:00
Jukka Rissanen 2ec7e70509 net: routing: Hide routing option temporarily
Currently the CONFIG_NET_ROUTING option has limited use as there
would be some entity that populates routing table. Previously it
was RPL that did it but RPL support was removed some time ago.

Fixes #16320

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-23 10:25:11 +03:00
Jukka Rissanen 1593de9642 net: socket: Init net_context when taken into use
If we are getting an old net_context, clear the content of it
in order to make sure we do not have old data in it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-18 23:47:36 +03:00
Jan Van Winkel a4eba66ff4 net: Added missing do to net_route_info macro
Added missing do statement of the enclosing do {} while(0) statement to
net_route_info macro

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-09-17 11:27:19 +02:00
Jukka Rissanen 207943c2a7 net: pkt: Clone cursor position in net_pkt_clone()
We need to make sure that net_pkt_clone() sets cursor correctly.
This cursor position is needed so that we can skip IP header
for incoming packet properly. Not all applications need to know
the cursor position of the cloned packet. Unfortunately we cannot
know that in advance so just set the cursor to correct position in
the cloned packet.

Fixes #19135

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-13 16:30:02 +03:00
Jukka Rissanen 99e0ae6fd9 net: conn: Deliver multicast pkt to all interested parties
If we receive a multicast IPv4 or IPv6 packet, then we need to
deliver it to all sockets that have installed a handler for it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-12 17:33:44 +03:00
Andy Ross 643701aaf8 kernel: syscalls: Whitespace fixups
The semi-automated API changes weren't checkpatch aware.  Fix up
whitespace warnings that snuck into the previous patches.  Really this
should be squashed, but that's somewhat difficult given the structure
of the series.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-09-12 11:31:50 +08:00
Andy Ross 6564974bae userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words.  So
passing wider values requires splitting them into two registers at
call time.  This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.

Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths.  So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.

Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types.  So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*().  The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function.  It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.

This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs.  Future commits will port the less testable code.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-09-12 11:31:50 +08:00
Ravi kumar Veeramally 1a6f4a6368 net: tcp: Accept connections only in LISTENING state
Issue noticed with following scenario.

 1) TCP server is listening for connections but will handle
    only one connection at a time (e.g. echo-server sample)
 2) Client A connects, and the connection is accepted.
 3) Client B connects, instead of denying a connection,
    it is "auto" accepted (this is the actual bug) even
    if the application has not called accept().
 4) After the connection A is closed, the connection B
    gets accepted by application but now the closed
    connection A will cause confusion in the net-stack
 5) This confusion can cause memory leak or double free
    in the TCP core.

It is not easy to trigger this issue because it depends
on timing of the connections A & B.

Fixes: #18308

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-09-10 22:57:48 +03:00
Jukka Rissanen 29cae7e2fa net: tcp: Cleanup context if connection is not established
If we are closing connection before the connection was established,
then unref the context so that the cleanup is done properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-10 22:53:12 +03:00
Jukka Rissanen 6cf1da486d net: Add CONFIG_NET_NATIVE option for selecting native IP
Allow user to disable native IP stack and use offloaded IP
stack instead. It is also possible to enable both at the same
time if needed.

Fixes #18105

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-10 12:45:38 +03:00
Michael Scott a4f4f6d6f3 net: net_if: avoid deref of NULL L2
When using offloaded network, an L2 is never assigned to the net_if.
Only certain portions of the net_if code are referenced such as:
net_if_up()
net_if_down()

And these functions make use of several L2 references:
get_flags()
enable()

Let's add checks to make sure we don't deref a NULL when using these
functions.

Fixes the following exception on K64F and other HW which can make
use of offloaded network HW:
FATAL: ***** Reserved Exception ( -16) *****
FATAL: r0/a1:  0x00000010  r1/a2:  0x0000644f  r2/a3:  0x00000000
FATAL: r3/a4:  0x00000000 r12/ip:  0x2000474c r14/lr:  0x0001475b
FATAL:  xpsr:  0x00000000
FATAL: Faulting instruction address (r15/pc): 0x0001b1cd
FATAL: >>> ZEPHYR FATAL ERROR 0: CPU exception
FATAL: Current thread: 0x20004c4c (unknown)

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/18957

Signed-off-by: Michael Scott <mike@foundries.io>
2019-09-08 22:08:02 -04:00
Jan Van Winkel a219710760 net: ip: utils: Corrected memcpy length for port in parse_ipv6
Corrected the amount of bytes copied for port handling in parse_ipv6
to prevent reading past the boundaries of the input string.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-09-08 12:37:16 +02:00
Jukka Rissanen 0049c52651 net: ipv6: Check sub-option length
Make sure that the extension, like HBHO, sub-option length is
not too large.

Fixes #16323

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-27 14:02:32 +02:00
Alexander Wachter 210455a0ae net: ip: ipv6_nbr: Make LLAO length calculation more universal
This commit changes the Link-Layer Address Option length calculation
from hardcoded values to a numerical rounding up to full 8.
The length is calculated according to rfc4861 section 4.6.1.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-09 15:11:45 +03:00
Cami Carballo 7b3cd7d371 tests: net: increase stack size
fixes issues with tests/net when code coverage is enabled in qemu_x86

Signed-off-by: Cami Carballo <cami.carballo@intel.com>
2019-08-08 13:50:32 -07:00
Jukka Rissanen c80407d30e net: context: sendmsg: Allow use of connected UDP sockets
If the UDP socket is connected, then allow the user to leave
out the remote address in msghdr struct.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-08 23:13:51 +03:00
Alexander Wachter 8a69b83d3f net: ip: ipv6_nbr: use temp variables for ntoh conversion
The network to host byte order conversion is actually in place
on the network buffer. This prevents the reuse and forwarding of
RA packets. This commit uses temporary variables instead.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03:00
Alexander Wachter 64d495df45 net: ip: ipv6_nbr: take TLLAO length from src lladdres
Take the targer link layer address option link laxer addres lenght
from net packets source addres instead if the interface.
This is usefull for 6LoCAN border translator (6LoCAN to Ethernet).

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03:00
Alexander Wachter 95863a73da net: ip: net_pkt: Implement net_pkt_shallow_clone
This commit implements net_pkt_shallow_clone. A shallow clone clones
the net_pkt but not the buffers. The buffers are only referenced and
therefor only freed when both copies of the net_pkt are freed.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03:00