Commit graph

1749 commits

Author SHA1 Message Date
Ruslan Mstoi 59c21ad3cf net: tcp2: Fix reading TCP options
This patch fixes an issue with TCP options reading. Previous approach
was accessing the options with pointers (th + 1). This does not work if
TCP options span multiple net_pkt buffer fragments. Instead net_pkt
functions must be used.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2020-04-22 13:15:58 +03:00
Ravi kumar Veeramally 184a2d5197 net: tcp2: Handle FIN_WAIT_2 and CLOSING
Added support for FIN_WAIT_2 and CLOSING states.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-04-22 12:41:39 +03:00
Oleg Zhurakivskyy 61a1dc934c net: tcp2: Acknowledge the incoming FIN+ACK in FIN_WAIT_1
In order to avoid retransmissions from the peer's side
on active connection close, acknowledge the incoming FIN+ACK
in FIN_WAIT_1 state.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-04-21 16:57:22 +03:00
Jukka Rissanen d70363f13e net: tcp2: Local address in net_context needs special handling
We cannot directly use the local address in net_context when
registering the connection as it is not proper type. So create
temp address variable for that purposes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-21 16:55:41 +03:00
Jukka Rissanen 76a7fdd213 net: tcp2: No dynamic allocation for TCP connection endpoint
Avoid dynamic allocations and all the issues if we run out of
memory, by placing the connection endpoint directly to TCP
connection struct.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-21 16:55:41 +03:00
Jukka Rissanen 7c23c47c0e net: tcp2: Avoid extra memory allocation in endpoint cmp
In tcp_endpoint_cmd() we allocate and then almost immediately
destroy the allocated endpoint. This is quite inefficient so
use a endpoint from stack in the compare.

Separate endpoint allocation from value setting so the caller
can decide how the endpoint union values are set.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-19 11:10:37 +03:00
Ravi kumar Veeramally 08e65e8684 net: tcp2: Rename SRC, DST enums
Some other part of Zephyr has similar defines (SRC)
causing build failures.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-04-17 14:49:18 +03:00
Ravi kumar Veeramally c655624f8a net: tcp2: Fix format specifier
len is ssize_t variable type, %zd should be there.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-04-17 14:49:18 +03:00
Oleg Zhurakivskyy b6372ea406 net: tcp2: Fix the IPv4 endpoint assignment in net_tcp_connect()
Assigning the allocated IPv4 endpoint as struct sockaddr
leads to the memory overwrite, assign the correct structure,
i.e. struct sockaddr_in.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-04-17 12:30:22 +03:00
Oleg Zhurakivskyy 4fbf3c3672 net: tcp2: On active connection close go to FIN_WAIT_1
In order to implement active connection close with the
TIME_WAIT state, send FIN and enter FIN_WAIT_1 state.

We actually send FIN+ACK as most of the implementations do.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-04-16 11:10:36 +03:00
Oleg Zhurakivskyy 40799bc986 net: tcp2: Implement FIN_WAIT_1 state
On active close, wait for FIN+ACK and subsequently
enter TIME_WAIT state.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-04-16 11:10:36 +03:00
Oleg Zhurakivskyy 52fca0a8d2 net: tcp2: Add a TIME_WAIT timer and state
In order to support TIME_WAIT state during the TCP connection
termination, add a TIME_WAIT timer and the corresponding state.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-04-16 11:10:36 +03:00
Oleg Zhurakivskyy f95ceec35b net: tcp2: Remove extra flags reset in TCP_CLOSED
After the check for unconsumed flags was removed,
this is no longer needed.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-04-16 11:10:36 +03:00
Oleg Zhurakivskyy 3dc72dffb0 net: tcp2: Readability rename of TCP_FIN_WAIT states
In order to improve readability, rename TCP_FIN_WAIT
states into TCP_FIN_WAIT_1, TCP_FIN_WAIT_2.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-04-16 11:10:36 +03:00
Jukka Rissanen 053dcaa494 net: shell: Convert k_sleep() to k_msleep()
Needed because of k_timeout_t changes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen b9cbf8a5ed net: pkt: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 76d07ccd00 net: dhcpv4: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 406bdb1fc6 net: promisc: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 9e3778f89d net: ipv4: autoconf: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 38dd9bc299 net: mgmt: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 08d532489c net: trickle: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen edb39cb40c net: tcp2: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 35dbe1c7d5 net: tcp: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 005ee2f768 net: ipv6: nbr: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 63a7b92fd8 net: if: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen e56fa75ade net: context: Refactor because of timeout overhaul
The net_context API will change, the s32_t timeout parameter
will be changed to k_timeout_t. All the Zephyr users of this API will
be changed in subsequent commits. This is internal Zephyr API only,
so the API is not deprecated etc.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen ab5aba4f8f net: ppp: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen a49741ff66 net: dns: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Peter Bigot 55daa79ba3 net: context: fix return with held lock
An internal early return left a mutex locked.

See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 15.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Peter Bigot cbce6dde4c net: tcp: validate pointer before dereferencing it
See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 8.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Ruslan Mstoi bffd6576f9 net: tcp2: Fix handling single octet option at the EOL
This patch enables handling of a single octet of option-kind at the end
of the option list (EOL). Also, add functionality to drop a segment with
an invalid single octet option-kind at the EOL.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2020-04-06 15:13:21 +03:00
Ravi kumar Veeramally b9d8884c25 net: tcp2: tp: Simplify pkt creation in test protocol
Use existing network stack calls to create net pkt,
ip header and udp header creation. Also simplify
finalize api calls.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-04-03 17:12:21 +03:00
Ravi kumar Veeramally 69551b4681 net: tcp2: Simplify TCP pkt creation
Use existing network stack calls to create net pkt,
ip header and tcp header creation. Also simplify
finalize api calls.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-04-03 17:12:21 +03:00
Ravi kumar Veeramally a4d4485c0e net: context: Move asserts to proper place
net_context local sin/sin6 addresses are used only
when input src is not available. So ASSERT should
be inside if block.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-04-03 17:12:21 +03:00
Jukka Rissanen e1f06e26b2 net: tcp2: Check pointer before use in accept
The conn pointer NULL value was checked too late.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-02 23:03:37 -04:00
Tomasz Bursztyka e9bcf5e32b net/shell: Add PM suspend statistics print-out
Along with other statistics.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-04-02 11:07:45 +03:00
Tomasz Bursztyka 00926e3899 net/iface: Add PM suspend state statistics
Counting how many times it went suspended, for how long on the last one
and on overage.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-04-02 11:07:45 +03:00
Ruslan Mstoi e5f714575e net: tcp2: Fix handling of the END TCP option
End option indicates the end of the option list. Hence, correct way to
handle it is to break out of the option parsing routine.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2020-04-01 20:58:40 +03:00
Ruslan Mstoi 4171220405 net: tcp2: Fix option name PAD to END
According to RFC 793 and IANA "TCP Option Kind Numbers" an option with
kind 0 is an End of Option List option and not a PAD.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2020-04-01 11:29:39 +03:00
Oleg Zhurakivskyy b1e1f64d14 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-31 07:18:06 +02:00
Tomasz Bursztyka cb0da79e7f net/shell: Add a quick way to suspend/resume a network interface
Meaningful for testing purpose only.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Tomasz Bursztyka 4322c66e4b net: Expose a way to know if the network interface is suspended or not
And use it in the shell to display such information then.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Tomasz Bursztyka 80917ec16f net: Add preliminaly support for suspending/resuming a net interface
Such state needs to be set _from_ the PM API functions and not the other
way round. So if a network device driver does not support such API, it
will not be able to set the core net_if on PM state, obviously.

Currently, these functions only set/unset NET_IF_SUSPENDED flag.

More logic will be added later, to decide whether the net_if can be
actually set to suspend mode or not and also to take care of all timers
related to the interface.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Jukka Rissanen dee07c9e0a net: if: Add function to check any pending TX packets
This function can be used for example by network power management
to check if the network interface can be suspended or not.
If there are network packets in transmit queue, then the network
interface cannot be suspended yet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-27 14:48:30 +02:00
Jukka Rissanen 15dfa28c2e net: tc: Return information whether TX pkt was queued
We need to know whether the net_pkt was successfully placed
to transmit queue. It is possible in TX side, that the net_pkt
is already in TX queue when for example TCP packet is
re-transmitted, in which case the queue submit will fail.
This cannot happen in RX side as there are no timers involved.

It is required to check about such pending flag before trying to submit
it into the queue. Indeed, the work queue could be scheduled right after
such queuing, thus checking for the pending flag afterwards would
provide a false information.

It is unfortunate k_work_submit_to_queue() does not return anything as
it would simplify the code then.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Carles Cufi 4b37a8f3a4 Revert "global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()"
This reverts commit 8739517107.

Pull Request #23437 was merged by mistake with an invalid manifest.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-19 18:45:13 +01:00
Oleg Zhurakivskyy 8739517107 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-19 15:47:53 +01:00
Jukka Rissanen 907dede475 net: iface: Make sure we access valid ll address
It is possible that net_pkt will disappear while we are sending
it, so save link address if we need that information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Jukka Rissanen 9325109cbc net: pkt: Print size of the failed net_buf allocation
This information is useful when debugging things.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Jukka Rissanen 65d8429d29 net: pkt: Print caller and line when allocation fails
It is useful to know who called the net_pkt allocator when
we run out of buffers.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
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