Commit graph

1749 commits

Author SHA1 Message Date
Tomasz Bursztyka eea0f6f8f0 net/dhcpv4: Avoid ifdefs when using net_dhcpv4_init()
Just provide a macro of value 0 in case CONFIG_NET_DHCPV4 is unset.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-04-03 09:32:39 -04:00
Tomasz Bursztyka 26a335c2e8 net/ipv6: Fix IPv6 fragment nexthdr field in case of no option headers
With or without options headers it has to work. Currently it was
setting always hop-by-hop next header which is obviously wrong but
worked on ipv6_fragment test since that one has only packets with
optional headers (hop-by-hop in that case has to be the first optional
header).

Fixes #14622

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-04-02 13:18:46 -04:00
Jukka Rissanen 1eead93a48 net: tcp: Do not mark TCP segment not sent in net_if
If the TCP segment is not sent properly by L2, then do not mark
it "not sent" in net_if.c:net_if_tx(). That "not sent" marking
confused TCP ref counting in tcp.c:tcp_retry_expired() and caused
the packet to be freed too early which then caused free net_buf
access issue during packet resend. This free memory access was
seen with zperf sample application.

From TCP point of view, the packet can be considered sent when
it is given to L2. The TCP timer will resend the packet if needed.

Fixes #15050

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-04-01 12:39:32 -04:00
Jukka Rissanen 30d31936a0 Revert "net: tcp: Fix ref counting for the net_pkt"
This reverts commit 9cd547f53b.

The commit we are reverting, fixed originally the issue that was
seen with zperf. There we freed the net_pkt too early while it was
still waiting for a TCP ACK. The commit 9cd547f5 seemd to fix that
issue but it was causing issues in dump_http_server sample app which
then started to leak memory. No issues were seen with echo-server
with or without the commit 9cd547f5.

So the lessons learned here is that one needs to test with multiple
network sample apps like dump_http_server, echo_server and zperf
before considering TCP fixes valid, especially fixes that touch
ref counting issues.

Fixes #15031

The next commit will fix the zperf free memory access patch.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-04-01 12:39:32 -04:00
Patrik Flykt 21358baa72 all: Update unsigend 'U' suffix due to multiplication
As the multiplication rule is updated, new unsigned suffixes
are added in the code.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Jukka Rissanen 9cd547f53b net: tcp: Fix ref counting for the net_pkt
The network packet ref count was not properly increased when
the TCP was retried. This meant that the second time the packet
was sent, the device driver managed to release the TCP frame even
if we had not got ACK to it.

Somewhat long debug log follows:

The net_pkt 0x08072d5c is created, we write 1K data into it, initial ref
count is 1.

net_pkt_write: pkt 0x08072d5c data 0x08075d40 length 1024
net_tcp_queue_data: Queue 0x08072d5c len 1024
net_tcp_trace: pkt 0x08072d5c src 5001 dst 5001
net_tcp_trace:    seq 0x15d2aa09 (366127625) ack 0x7f67d918
net_tcp_trace:    flags uAPrsf
net_tcp_trace:    win 1280 chk 0x0bea
net_tcp_queue_pkt: pkt 0x08072d5c new ref 2 (net_tcp_queue_pkt:850)

At this point, the ref is 2. Then the packet is sent as you see below.

net_pkt_ref_debug: TX [13] pkt 0x08072d5c ref 2 net_tcp_queue_pkt():850
net_tcp_send_data: Sending pkt 0x08072d5c (1084 bytes)
net_pkt_unref_debug: TX [13] pkt 0x08072d5c ref 1 (ethernet_send():597)

Ref is still correct, packet is still alive. We have not received ACK,
so the packet is resent.

tcp_retry_expired: ref pkt 0x08072d5c new ref 2 (tcp_retry_expired:233)
net_pkt_ref_debug: TX [10] pkt 0x08072d5c ref 2 tcp_retry_expired():233
net_pkt_unref_debug: TX [10] pkt 0x08072d5c ref 1 ... (net_if_tx():173)
net_pkt_unref_debug: TX [10] pkt 0x08072d5c ref 0 ... (net_if_tx():173)

Reference count is now wrong, it should have been 1. This is because we
did not increase the ref count when packet was placed first time into
sent list in tcp.c:tcp_retry_expired().

The fix is quite simple as you can see from this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-26 07:29:26 -05:00
Ravi kumar Veeramally f361859fde net: ipv6: Fix IPv6 neighbor table
This patch fixes following issues.

  * If IPv6 neighbor table is full, stack can not add any new
    neighbors. So stale counter is introduced. Whenever neighbor
    enters into STALE state, stale counter will be incremented
    by one. When table is full and if stack wants to add new
    neighbor, oldest neighbor in STALE state will be removed
    and new neighbor will be added.

  * When neighbor is in PROBE state and when it exceeds max
    number of PROBEs, only neighbor with router is removed.
    As per RFC 4861 Appendix C, entry can be discarded. Now
    neighbor will be removed from the table.

  * Reachability timer has an issue. e.g. if a first entry timer
    is 10 seconds, after 3 seconds, a new entry added with
    only 3 seconds. But current implementation does not check
    whether remaining time of current left over timeout is more
    than new entry timeout or not. In this example, when new entry
    timeout is 3 seconds, left over timeout from first etnry is
    still 7 seconds. If k_delayed_work_remaining_get() returns
    some value then new entry time out was not considered.
    Which is bad. It fixed now.

  * nbr_free is used sometimes to remove the neighbor. Which does
    not remove route if that particulat neighbor is route to some
    other neighbor. net_ipv6_nbr_rm() should be used in such places.

  * Trivial changes which does not affect functionality.

Fixes #14063

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-03-25 22:49:52 -04:00
Jukka Rissanen a8b1dadac5 net: connection: Allow same port number for dest and source
Fix regression and allow incoming packet when source and
destination port numbers are the same.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-25 22:44:43 -04:00
Tomasz Bursztyka c0de64fc59 net/ipv6: Take iface's MTU into account to decide fragmenting or not
In case of Ethernet for instance, the MTU is larger than the minimal
IPv6 MTU, so it is not required to fragment a packet that fits in
Ethernet MTU.

Fixes #14659

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-25 22:33:41 -04:00
Charles E. Youse 8e85d7d6c0 net/ip: fix input packet filtering criteria
The "is this packet for us?" filter in net_ipv4_input() has a minor
logic error which fails to discard many packets which are.. not for us.

Fixes: #14647

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-03-20 16:37:12 -05:00
Jukka Rissanen bf8d391ad4 net: context: Check if we run out of mem
The context_alloc_pkt() might run out of memory, and if that
happens we must not try to set the context pointer in it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-20 16:32:16 -05:00
Paul Sokolovsky 69afd80a3d net: ip: connection: Typo fixes in comment
Fix typos and reword code comment on module dependencies a bit.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-20 16:24:05 -05:00
Tomasz Bursztyka 1a98d4d1fe net: Move the chksum offload verification to relevant places
Since the new packet flow came in, payload comes at the end so udp
length for instance is known only when we "finalize" the packet.
However such finalization was still under the condition of chksum
offload, like it used to be in the former flow (udp headers were
inserted). This is obviously wrong but that was not caught with
existing driver in master as none of these drivers offloading
chksum calculation.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 11:34:14 -05:00
Michael Scott 4f707ae896 net/context: Relocate offload handling in net_context_connect()
Commit fc27a81ed2 ("net: context: Select proper network interface
when binding") moved the bind_default() call to after the remote
address was set for the net_context.

This and a later net_pkt API refactor broke net_offload() handling
so that context->iface wasn't set and context->flags didn't have
NET_CONTEXT_REMOTE_ADDR_SET correctly.

Let's fix this by relocating the net_offload handling to after
these have happened.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 84909970a0 net/pkt: Remove unused legacy net_pkt allocator
Now, only net_pkt_alloc and variants are used.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 89c4a4a26f net/context: Re-enable offloaded send/sendto
net_offload API is left untouched, so it still takes a net_pkt as input
for the buffer. This is under-optimized since offload drivers will copy
the data from that net_pkt back into contiguous buffer again.
Let's tackle this issue another time.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 730b5de6d9 net/pkt: Remove superfluous total_pkt_len attribute
This attribute, in case CONFIG_NET_STATISTICS is enabled, made sense
when L2's send() function did not return the length of the sent packet.
But now, it's a superflous optimization as is it used only to set the
stats on recv or send, where net_pkt_get_len() can be used directly.

This helps to save 2 bytes from struct net_pkt.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 03bfc5dd0f net/context: Remove token parameter from net_context_send/sendto
And also to the relevant callbacks.

That parameter is not used anywhere so it is useless.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 7d97a1871a net/pkt: Remove unused token attribute
Seems like a useless attribute. Since net_context is not being used by
the user directly (socket is the unique interface now) and since no core
parts uses the token parameter of net_context API: let's remove the
attribute.

This helps to save 4 bytes from struct net_pkt.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 39504c2560 net/pkt: Remove legacy net_frag_linear_copy function
This function is now superseded by net_pkt_read() and is no longer
used.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka ec3fe5560b net/pkt: Remove legacy net_pkt_append functions
These were based on the former allocation scheme and are no longer used.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 23b753feed net/pkt: Remove legacy net_frag_read/skip/get_pos functions
These were based on the former allocation scheme and are no longer used.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka d6d52ce9e5 net/pkt: Remove _new suffix to net_pkt_write functions
Suffix is now useless, as these functions are now the only ones.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka a15654980e net/pkt: Remove legacy net_pkt_insert functions
These were based on the former allocation scheme and are no longer used.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka ea518af5dd net/pkt: Remove legacy net_pkt_write functions
These were based on the former allocation scheme and are no longer used.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka a25f054cbd net/pkt: Remove _new suffix to net_pkt_read functions
Suffix is now useless, as these functions are now the only ones.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka f8a091104e net/pkt: Remove _new suffix to net_pkt_get_data_new function
Now that legacy - and unrelated - function named net_pkt_get_data has
been removed, we can rename net_pkt_get_data_new relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 2022aa3484 net/pkt: Remove now useless net_pkt_get_data()
That function was responsible for allocating new buffer element, but it
is now unused and can be removed safely. Buffer allocation is now done
via net_pkt_alloc_buffer().

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 7e4f03aabe net/icmpv4: Remove unused net_icmpv4_set_checksum function
Checksum is now set via net_icmpv4_finalize() function.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 820f3ad006 net/ipv6: Replace legacy net_ipv6_create by the new one
Thus removing the legacy one, and renaming the new one to legacy name.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka ca58b4c761 net/ipv4: Replace legacy net_ipv4_create by the new one
Thus removing the legacy one, and renaming the new one to legacy name.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 172fe5a87b net/context: Remove _new suffix on net_context_send/sendto functions
Now that legacy functions are removew, let's rename the new functions by
removing the _new suffix.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 62ab954251 net/pkt: Remove appdata/appdatalen attributes and related functions
There is no need for these anymore: all is dictated by the position of
the net_pkt's cursor now

- actual cursor position is like the former appdata attribute
- net_pkt_remaining_data() is like the former appdatalen attribute

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 54ac7a43e9 net/udp: Remove net_udp_insert legacy function
It is unused anywhere now.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 0b173e3b77 net/context: Remove legacy API
Former net_context_send/sendto and net_context_create_ipv4/ipv6 are now
unused and can be removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 7ba52eae93 net/ipv6: Set the right protocol when finalizing MLD packet
IPv6 next header might be something else (here NET_IPV6_NEXTHDR_HBHO)
but when finalizing it is mandatory to give the actual last header
protocol type. In this case IPPROTO_ICMPV6, so the checksum can be
computed properly then by net_icmpv6_finalize() called from
net_ipv6_finalize().

Fixes #14663

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-19 09:45:01 -04:00
Jukka Rissanen 20ea069d81 net: if: Init cursor for promiscuous mode after L2
As the L2 layer might have modified the cursor, reset it here
before giving the packet to promiscuous mode API. This way
the application will get a fresh copy of the buffer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-18 11:39:33 -05:00
Paul Sokolovsky bce27220a1 net: context: put: Update for shared TCP context ownership
TCP context is now created with refcount of 2, signifying that it's
jointly owned by an app and stack. Thus, net_context_put()
unconditionally calls net_context_unref() to decrement refcount on
app's behalf, and leaves stack's refcount to internal routines
which handle sending/receiving/timing out FINs, etc.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-18 10:49:25 -05:00
Tomasz Bursztyka f1810c8495 net/icmpv4: Create reply taking taking into account the IPv4 hdr lengh
Now that IPv4 options are handled, ICMPv4 echo reply must be created
taking into account that IPv4 header length can be variable. So instead
of cloning and rewriting (that would copy the useless options), let's
allocate and copy only the payload.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-11 20:57:29 -07:00
Tomasz Bursztyka a567bcb765 net/utils: Use the right IPv4 header length for checksum calculation
IPv4 header length might be bigger than struct net_ipv4_hdr if there are
options appended to it.

Fixes #11618

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-11 20:57:29 -07:00
Tomasz Bursztyka 21c66a8fe1 net/ipv4: Handle options relevantly
IPv4 header might come with options, unlike IPv6, these are not
encapsulated in option header but are fully part of the IPv4 header.

Zephyr must handles these. Now silently ignoring their content and
setting the cursor to the payload properly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-11 20:57:29 -07:00
Tomasz Bursztyka 5594aee9aa net/context: Enable using dedicated slab/pools to allocate a packet
This is probably the only place where net_pkt_alloc_from_slab() is going
to be used.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-11 20:56:44 -07:00
Tomasz Bursztyka 4508e94b4e net/pkt: Enable allocating from external slab and data pool on new API
This is meant for very particular use case as only logging uses that.
Where it makes entirely sense for it to send the logs through its own
slab/pool in order to not drain the core slabs/pools.

So enabling the new API to manage that. That has to be used with
net_context for the buffer pool. So one has to first allocate the
net_pkt from external slab, set the context and then (and only then)
allocate buffer. Basically, only net_context will uses that scheme
anyway.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-11 20:56:44 -07:00
Tomasz Bursztyka dd01e9997f net/context: Add an option so set/unset packet timestamping
Though core system is able to manage packet timestamping internaly (gptp
requires it for instance), it might be necessary to enable/disable
packet timestamping from net context directly.

Currently this will be only used by the tx timestamp test. So this
support is disabled by default. (And gptp does not require it anyway).

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-09 10:09:33 -05:00
Tomasz Bursztyka c7ee54aeab net/context: If enabled, pass the context priority to the packet
This is required if traffic class is enabled, so allocated packets from
net_context do get the right priority set.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-09 10:09:33 -05:00
Tomasz Bursztyka 6c18a27c30 net/pkt: Allow having NULL as iface
That can be useful on some tests which will not have any interface but
still allocate net_pkt. Also, one may allocate a packet with buffer not
knowing yet the interface it will be send through.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-09 10:09:33 -05:00
Ulf Magnusson 214ef00db3 kconfig: subsys: net: Remove redundant dependencies
subsys/net/lib/lwm2m/Kconfig.ipso is 'source'd within an 'if LWM2M', in
subsys/net/lib/lwm2m/Kconfig, so the 'depends on LWM2M' is redundant.

The 'depends on NET_IPV4' and 'depends on NET_L2_OPENTHREAD' are within
corresponding 'if's in the same file.

'if FOO' is just shorthand for adding 'depends on FOO' to each item
within the 'if'. Dependencies on menus work similarly. There are no
"conditional includes" in Kconfig, so 'if FOO' has no special meaning
around a source. Conditional includes wouldn't be possible, because an
if condition could include (directly or indirectly) forward references
to symbols not defined yet.

Tip: When adding a symbol, check its dependencies in the menuconfig
('ninja menuconfig', then / to jump to the symbol). The menuconfig also
shows how the file with the symbol got included, so if you see
duplicated dependencies, it's easy to hunt down where they come from.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-09 09:49:59 -05:00
Ravi kumar Veeramally ecfe1fc7e3 net: dhcpv4: Introduce config option for max delay
As per RFC2131 4.1.1 requires we wait a random period
between 1 and 10 seconds before sending the initial
discover. But tests can not wait that longer. So this
option helps test to configure the value to minimum.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-03-05 08:29:02 -05:00
Jukka Rissanen ea1e4fd0d7 net: tcp: Check TCP ACK flag properly during conn establishment
Multiple flag bits were set so the ACK flag set was not checked
properly which meant that connection establishment was not
successfull.

Fixes #13943

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-01 09:49:02 +01:00
Jukka Rissanen 52dc50dc6b net: lldp: Allow generation of documentation
No need to hide the symbols in the header file if CONFIG_NET_LLDP
is not enabled. This also allows the documentation to be generated
properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-01 09:45:06 +01:00
Jukka Rissanen 8e066aba0f net: ipv6: Extension header length failure not properly checked
The ipv6_handle_ext_hdr_options() can return negative value
but we stored it into unsigned variable and then checked < 0.

Coverity-CID: 190995
Fixes #13830

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-28 08:47:24 -06:00
Jukka Rissanen 4bbcf391c3 net: context: Remove dead code from net_context_connect
The ret=0; statement cannot be reached.

Coverity-CID: 190973
Fixes #13846

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-28 08:46:09 -06:00
David B. Kinder e731bdc81a doc: fix docs, include, and Kconfig misspellings
Fix misspellings missed during regular reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-02-28 09:32:12 +01:00
Ulf Magnusson 9aab5cef96 kconfig: Remove redundant 'default n' properties
Some more were added since the cleanup pass in June 2018. See e.g.
commit 2d50da70a1 ("drivers: ipm: Kconfig: Remove redundant 'default n'
properties") for a motivation. It also avoids people wondering whether
or not they need to put in 'default n'.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 09:25:22 +01:00
Jukka Rissanen 429b6ed68e net: stats: Wrong Kconfig options were used for statistics
The net-shell was using wrong config options for statistics
support. Also net_stats.h had wrong config used for IPv6 MLD
statistics.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-26 02:25:45 +01:00
Tomasz Bursztyka 6435553dea net/context: Add a way to set/get ttl/hop_limit from net_context
Since net_context_sendto_new() does not take a net_pkt anymore, the only
way to set net_pkt's ttl/hop_limit is to pass it through net_context.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-26 01:50:59 +01:00
Tomasz Bursztyka 9104211d9e net/6lo: Add a way to get the difference of hdr size after uncompression
Since we don't want to redo the complex calculation, let's reuse the
uncompress functions, adding a dry_run possibility to those.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-23 07:44:59 -05:00
Tomasz Bursztyka c6f0491606 net/shell: Switch TCP send command to new API
It simplifies things again, as it does not need to create the net_pkt by
itself anymore.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-21 18:06:06 -05:00
david leach b08afdb348 net: sockets: Clean up socket shutdown on listen() socket
When closing the socket, zsock_close_ctx() would call
net_context_accept() when the socket was in "LISTEN" state.
This would result in an error log message for "Identical
connection handler already found" because the connection
context was already created because the initial
zsock_listen_ctx() called net_context_accept() to set up
the socket at the beginning. This change adds a test to
check if the callback is NULL which indicates this
close state and avoids the error message.

Signed-off-by: david leach <david.leach@nxp.com>
2019-02-21 11:58:46 -05:00
david leach 45df09c010 net: tcp: Clean up FIN send on socket shutdown
The sending of the final FIN message was being put on the sent_list
to be handled by the retry logic and being sent directly. But in
the case of a socket that never had a connection, the logic after
the direct send would decrement the reference on the packet which
would cause the retry logic to eventually have a situation where
the pkt is on the sent_list queue but the buffer associated with
the packet is freed back to slab. The code would then get a null
pointer to the tcp header and would fault when setting the crc to
zero on frdm-k64f platform.

Fixes #13489, #13301

Signed-off-by: david leach <david.leach@nxp.com>
2019-02-21 11:58:46 -05:00
Jukka Rissanen 18f9db5381 net: route: Do not access null neighbor
Possible null pointer dereference when looking up the nexthop
neighbor.

Coverity-CID: 190639
Fixes #12294

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-21 09:23:53 -05:00
Robert Lubos 749596659f net: ipv6: Do not pass ICMPv6 packets to net_conn_input
ICMPv6 network packets are processed and consumed (if not dropped)
within `net_icmpv6_input` function. Therefore they shoud not be
passed to the `net_conn_input` function.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-20 12:50:43 -05:00
Krzysztof Chruscinski a64b0fe1e3 shell: Deprecate macros for subcommands creation
Macros are replaced by C++ friendly versions:
- SHELL_CREATE_STATIC_SUBCMD_SET by SHELL_STATIC_SUBCMD_SET_CREATE
- SHELL_CREATE_DYNAMIC_CMD by SHELL_DYNAMIC_CMD_CREATE

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-20 07:31:35 -05:00
Krzysztof Chruscinski 3605e48c44 shell: Modify subcommands to use SHELL_STATIC_SUBCMD_SET_CREATE
It is planned to deprecate SHELL_CREATE_STATIC_SUBCMD_SET macro
which is replaced by SHELL_STATIC_SUBCMD_SET_CREATE.

Additionally, removed irrelevant comments about alphabetical
ordering which is no longer needed.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-20 07:31:35 -05:00
Robert Lubos c47ef5e142 net: icmpv6: Fix echo request packet generation
`net_ipv6_finalize` expects packet cursor to be reinitialized in order
to finalize packet correctly. This commits adds missing cursor
initialization.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-19 17:34:23 -05:00
Jukka Rissanen 3206568e43 net: if: Start index numbering from 1
In order to follow the BSD socket numbering of the network
interfaces, start numbering from 1. The index 0 is reserved
to mean any interface in BSD socket code.

Fixes #13084

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-18 15:10:54 -05:00
Jukka Rissanen ef7081ee44 net: Fix the function API documentation generation
Make sure that network related functions are always documented.
This means keeping the prototype and possible stub together.

Fixes #12615

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-15 16:39:06 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Jukka Rissanen dbf7af7f43 net: context: can: Fix typo in Kconfig option name
The option CONFIG_NET_SOCKETS_RAW name was changed to
CONFIG_NET_SOCKETS_PACKET but two checks using the old name
was left to net_context.c

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-13 09:18:36 -06:00
Tomasz Bursztyka dad4b297f3 net/context: No need to set pkt family as the allocator did already
net_context uses net_pkt_alloc_with_buffer(), which sets the family and
protocol (according to parameters) so no need to set the family again.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-13 06:56:15 -06:00
Tomasz Bursztyka 2b22b71e42 net/pkt: Remove useless legacy net_frag_linearize function
Now that the stack does not use this function, it can be removed
safely.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka bc5411816a net/pkt: Remove useless legacy net_pkt_append_memset function
Now that the stack does not use this function, it can be removed
safely.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 1fab039102 net/pkt: Remove useless legacy net_pkt_split function
Now that the stack does not use this function, it can be removed
safely.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka c71ce193c4 net/pkt: Rename net_pkt_pull_new to net_pkt_pull
Now that legacy net_pkt_pull function has been removed, the new
function can be renamed accordingly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 09b782a82d net/pkt: Remove useless legacy net_pkt_pull function
Now that the stack uses the new API from net_pkt for pulling, no need
to keep the legacy one around.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka c65304f088 net/pkt: Rename net_pkt_copy_new to net_pkt_copy
Now that legacy net_pkt_clone function has been removed, the new
function can be renamed accordingly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 895c8eb0e3 net/pkt: Remove useless legacy net_pkt_copy/_all functions
Now that the stack uses the new API from net_pkt for copying, no need
to keep the legacy one around.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 38a3e79f9b net/pkt: Rename net_pkt_clone_new to net_pkt_clone
Now that legacy net_pkt_clone function has been removed, the new
function can be renamed accordingly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 347e17543f net/pkt: Remove useless legacy net_pkt_clone() function
Now that the stack uses the new API from net_pkt for cloning, no need to
keep the legacy one around.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka f447c47699 net/if: Use new net_pkt API for cloning in case of promiscuous mode
That was the last place where legacy net_pkt_clone() was used.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 40167ad0d9 net/icmpv4: Do not reuse echo request ttl for the echo reply
net_pkt_clone_new() sets the same attributes of the original packet to
the cloned one.

Fixes #13147

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 36740ecec7 net/pkt: Add a function to know the amount of data to read left
It will return the amount of data to be read from current cursor
position. This will prove to be useful to remove appdatalen attribute.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka a905203c57 net/tcp: Remove useless tcp_hdr_len() function
It is now useless as the only function using it
(net_pkt_set_appdata_values) got removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka ea671acadb net/pkt: Remove useless net_pkt_set_appdata_values() function
UDP/TCP are setting the appdata attributes by themselves now.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 5dd657fe4f net/context: Do not set the appadata attributes again
These are already set either by udp or tcp at relevant places.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 8bc8e6f83d net/tcp: Let's set the appdata related attributes by ourselves
Let's not call net_pkt_set_appdata_values() which will be more costly
since it will need to parse all over again the packet to grab the tcp
header. Instead, let's use the tcp header pointer we have already and
set the appdata attributes directly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka cdf4ce51d8 net/udp: Let's set the appdata related attributes once header parsed
No need to do it later as all necessary informations are there already.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 129f93fdd2 net/private: Rename net_print_frags() function
Though unused anywhere, this function seems to have some usage while
debugging.

Let's rename it to a more semantically relevant name.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka a6426620da net/private: Rename net_hexdump_frags to net_pkt_hexdump
And remove the parameter "full" as there is no "ll reserve" distinction
anymore. The parameter was unused since the ll reserve concept removal.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 42b0bbf956 net/utils: Remove net_header_fits() function
It is not used anymore. Instead, use net_pkt_is_contiguous()

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 44577d44f2 net/udp: Remove net_udp_header_fits legacy function.
It not used anymore. If one wants to do the same check, it will require
to place the net_pkt cursor at the relevant position and use
net_pkt_is_contiguous(pkt, sizeof(struct net_udp_hdr))

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 909eb7271a net/udp: Remove net_pkt_udp_data() function
It is now useless and can be replaced by net_udp_get_hdr() directly, in
the 2 unit tests it was used.

Removing as well the dbg function too_short_msg()

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 8ceedafdc4 net/udp: Switch net_udp_get/set_hdr to new net_pkt API
Let's use the new API for these 2 functions. Note that in some places,
using these functions is under-optimized (like in llmnr-responder in
dns: it gets the ip/udp headers already from the recv callback. That
will need to be taken care of later).

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 674d7c47b4 net/udp: Remove useless net_udp_set_chksum
It was only used in ipv6_fragment unit test and could be easily
replaced.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka c079242583 net/icmpv6: Remove useless net_icmpv6_set_chksum
net_ipv6_finalize do not use it anymore.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka d8624513e6 net/icmp: Remove useless icmp functions using legacy net_pkt API
net_pkt_icmp_data was only used in ipv6 unit test and could be easily
replaced.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 04966ac10d net/tcp: Remove useless tcp function using legacy net_pkt API
net_pkt_tcp_data was only used in tcp unit test and could be replaced by
local net_tcp_get_hdr.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka fd1401495b net/tcp: Move net_tcp_set_hdr() away from net core
Only the unit test needs it now, so let's move it there.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 869427c8bc net/tcp: Removing net_tcp_set_chksum function
Now that it's unused, it's useless.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka d5e5f902e7 net/ipv6: No need to finalize icmpv6 twice in MLD generation
net_ipv6_finalize() can take care of this, if net_pkt's ipv6_next_hdr
attribute is set to the right one, as well as ipv6_ext_len one.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 1a54cabe5e net/ipv4: Rename net_ipv4_finalize since legacy version disappeared
s/net_ipv4_finalize_new/net_ipv4_finalize

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 0c80a84bc7 net/ipv6: Rename net_ipv6_finalize since legacy version disappeared
s/net_ipv6_finalize_new/net_ipv6_finalize

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka e080dfc1de net/ipv6: Always return result of the last finalizer
Or we will not know if overall finalization worked.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka f47a9565d7 net/ipv4: Always return result of the last finalizer
Or we will not know if overall finalization worked.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka b93df74fa2 net/context: Let's use the new net_ipv4_finalize
And removing the legacy and unused one.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka b65016f021 net/utils: Backup the cursor at relevant place in chksum calculation
If the family of the packet is not recognized, then do not backup the
cursor.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 31a079023f net/context: Let's use the new net_ipv6_finalize
And removing the legacy and unused one.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka f299c1bb5a net/pkt: Fix legacy and new allocator attribute initialization
Legacy net_pkt allocator was not setting default value for IPv6
next header. And new net_pkt allocator was not setting default value
for TX traffic class and virtual LAN tag.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 78198810ac net/tcp: Move net_tcp_get_hdr() away from net core
Only the unit test needs it now, so let's move it there.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka ef165e7dce net/pkt: Removing transport protocol attribute
It is now unused anywhere: former net_pkt_get_src/dst_addr where the
only one using it and that has been changed since.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 024a7e0502 net/sockets: Adapt net_pkt_get_src_addr to new net_pkt API
This function is only used in sockets, thus making it a private function
of socket library and renaming it relevantly.

Note that sockets should be reviewed at some point to avoid using such
function: zsock_received_cb() already get the ip header and the protocol
header, so it could grab the src addr/port from there. It would be way
more optimized to do so, since net_pkt_get_src_addr is costly as it
parses all over again the ip/protocol headers.

utils unit test is updated and the test of the former
net_pkt_get_src_addr/net_pkt_get_dst_addr are removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Jukka Rissanen 0bf9433344 net: pkt: Check the minimum buf and pkt counts
For networking code, it does not make sense to have zero net_buf
or net_pkt instances. Make sure this is enforced by code.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-12 10:27:28 -05:00
Tomasz Bursztyka 7bcf00dc07 net/pkt: Add a function to trim the buffer
pkt->buffer is represented by 1+ net_buf. If some are unused, this will
deallocates them.

This situation can happen on TCP where net_pkt allocator evaluates the
header size to its maximum size. Which space might not be (fully) used
in the end. On fixed data size buffer, this might end up by having last
buffer(s) not bein used. So better removing those.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 09:46:01 -05:00
Tomasz Bursztyka 16edbbad63 net/context: Update length according to available buffer for payload
UDP was the only one doing the right thing. Let's generalize it
relevantly.

Fixes #13211

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 09:46:01 -05:00
Tomasz Bursztyka b01149f937 net/pkt: Add a function to get the available buffer for payload
This will take into account the family and the protocol, as well as
existing buffer occupation, to return the available buffer space that
can be used for payload.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 09:46:01 -05:00
Paul Sokolovsky cd59e3f32a net: shell: dns: Properly manage lifetime of callback data
DNS callback needs "struct shell *shell" data structure to pass as
a parameter to shell print. How it was achieved previously is that
it was packaged together with cosmetic "bool first" param into
"struct net_shell_user_data" on the stack, and passed to the
callback. The problem was that the original command handler then
returned, so the "struct net_shell_user_data" on the stack was
overwritten, and the callback crashed on accessing it.

An obvious solution was to make that structure static, but that would
leave to issues still, as turns out we allow system shell to be run
as more than one concurrent instances.

Next solution was to keep this structure on the stack, but block the
command handler until callback is finished. However, that hit a
deadlock due to not well thought out use of a mutex in the shell
printing routines.

The solution presented here is due to @nordic-krch, who noticed that
"bool first" param is indeed cosmetic and not really required. Then
we have only "struct shell *shell" to pass to the callback, and can
do that in callback's pointer param directly, ditching
"struct net_shell_user_data" which needs to be stored on the stack.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-12 09:44:38 -05:00
Jukka Rissanen a79e5ab916 net: shell: Add AF_CAN and AF_PACKET support to "net conn" command
Invalid values were printed for CAN or PACKET sockets for
"net conn" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-08 16:01:49 +02:00
Jukka Rissanen 9ac35128e1 net: socket_can: Make sure that things work without IPv4
No need to enable IPv4 any more as that is now optional.
This saves some memory as the application can work without
IPv4, IPv6, UDP or TCP.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-08 16:01:49 +02:00
Tomasz Bursztyka 3610ec71f5 net/pkt: Make sure all attributes are copied while cloning
net_pkt_clone() was missing some attributes.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-08 14:24:03 +02:00
Ravi kumar Veeramally 36aa7d1878 net: Allow disabling IPv4, IPv6, UDP and TCP simultaneously
This commit fixes compilation warnings if user disables
CONFIG_NET_IPV4, CONFIG_NET_IPV6, CONFIG_NET_TCP and
CONFIG_NET_UDP.

E.g Samples like packet-socket doesn't need above configuration.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-08 12:35:03 +02:00
Jukka Rissanen a046a86966 net: context: Use signed value for interface index
As the value 0 is a valid network interface index, we cannot use
unsigned value for interface index as that would not allow to
distinguish an invalid value. So make interface index a signed
8-bit value which is ok as we do not expect to have more than 127
network interfaces in the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Jukka Rissanen 66621791d1 net: can: Add CAN handling to net_context
Make sure that we can work with CANBUS based sockets
in net_context API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Jukka Rissanen bdf6f0cc20 net: utils: Fix net_proto2str() function
The function did not take the address family into account
when printing protocol name. The protocol value depends on
address family.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Jukka Rissanen f610db9453 net: l2: Add CANBUS L2 layer
This is basically a dummy layer that just passes data through.
It is needed so that we can create CANBUS type network interface
to the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Ravi kumar Veeramally a9a2b3ea91 net: sockets: Add socket api to support AF_PACKET
This commit adds packet socket support to socket api.
This version supports basic packet socket features.
Protocol family is AF_PACKET, type of socket is
SOCK_RAW and proto type is ETH_P_ALL. The user will
receive every packet (with L2 header) on the wire.
For TX, the subsystem expects that the user has set
all the protocol headers (L2 and L3) properly.

Networking subsystem doesn't verify or alter the headers while
sending or receiving the packets. This version supports packet
socket over Etherent only. Also combination of other family
and protocols doesn't work (i.e. Application can not open
packet-socket and non packet-socket together).

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-07 14:43:30 +02:00
Ravi kumar Veeramally b458ebf755 net: core: Handle packets when packet sockets are enabled
If CONFIG_NET_SOCKETS_PACKET is enabled, then feed the packet
to net_packet_socket_input() for processing. It will search
for the net_contexts and if proper handler is found, pass
the packet to connection handler.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-07 14:43:30 +02:00
Ravi kumar Veeramally 337b6f9a73 net: context: Add packet socket support
This commit adds basic packet socket support to net_context and
allows application to receive or send network packets in raw
format.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-07 14:43:30 +02:00
Ravi kumar Veeramally f0fb82dce9 net: ip: Add protocol family type to conn handler
As we are adding more protocol families and protocol types
to connection handlers, some values might be same across
different types. Current connection handler only stores
proto type to match the handler, which is not enough if
we add more types. Also combination of family and types
may vary too. So adding family to connection handler to
figure out best match.

Also changing proto variable in net_conn from u8_t to u16_t.
net_context has 16 bit proto.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-07 14:43:30 +02:00
Ravi kumar Veeramally 8de3a62444 net: pkt: Set default data_len to iface MTU
When creating net_pkt, the default value of net_pkt data_len was
set to zero. In case of RAW sockets, when family is AF_PACKET,
the data_len will be zero as there is no higher level protocol
information. So in this case, the default value of data_len
must be set to interface MTU

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-07 14:43:30 +02:00
Tomasz Bursztyka 968d423a44 net/pkt: Allocate relevant size on AF_UNSPEC
In case of Ethernet, if the requested size is larger than MTU and if
AF_UNSPEC is provided, the allocator will need to take into account
the ethernet header size which is not accounted in the MTU.

Other current L2 do not follow that rule as their MTU is based on IP
one (IPv6 most of the time). What they declare as MTU is the full frame
size they handle (minus the FCS for instance in 15.4). So with
AF_UNSPEC, such assumption on L2 header size is unrelevant.
(On 15.4 the header size is variable anyway and cannot be known until
the frame is parsed).

Fixes #12982

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-04 17:15:52 +02:00
Tomasz Bursztyka 522a4e86f3 net/context: Fix mutex unlock issues
2 unlock were missing, one in tcp and one in net_context.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-04 17:13:45 +02:00
Tomasz Bursztyka 212bcfb202 net/context: Lock/unlock mutex on new send/sendto functions
This was forgotten modification as commit 93e5181fbd came in master
though commit 0d519f7bcf was already written.

Thus fixing the missing lock/unlock.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-04 17:13:45 +02:00
Jukka Rissanen 0a6dabb89b net: shell: Remove HTTP command as it is obsolete
HTTP APIs were removed earlier so no need to have HTTP monitor
command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-01 19:05:56 -05:00
Tomasz Bursztyka 4b78a251d7 net/context: Make recv_cb providing the ip and protocol headers
If status is 0, both ip_hdr and proto_hdr will own a pointer to the
relevant IP and Protocol headers. In order to know which of ipv4/ipv6
and udp/tcp one will need to use respectively net_pkt_family(pkt) and
net_context_get_ip_proto(context).

Having access to those headers directly, many callbacks will not need
to parse the packet again no get the src/dst addresses or the src/dst
ports. This will be change after this commit.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka e4ebe486b8 net/ip: Let's make public the 2 utility unions for ip/proto headers
Though these are currently used by the core only, it will be then used
by net_context as well. This one of the steps to get rid of net_pkt's
appdata/appdatalen attributes.

Also normalizing all ip/proto parameters name to ip_hdr and proto_hdr.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 6a5f12b7f8 net/pkt: Add a debug option to track free pkt access more easily
Now that net_pkt are accessed through a common r/w API, using below a
net_pkt_cursor, let's have an option that will reset this cursor once
the net_pkt is freed.

Result is instead of segfaulting on r/w access, these operations will
bail out properly. Subsequent, and logical (unless you have a leak
which is another issue) net_pkt_unref will tell you who/where the pkt
was freed. Without it, you will get a segfault for instance, but that
won't tell you the exact reason. This options can help you then.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 0550b8ee27 net/tcp: Fix net_tcp_print_recv/send_info macros
Context was missing, and anyway the familiy can be grabbed from the
packet.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 1ca48beed8 net/context: Enable support for TCP on new sendto function
Let's enable usage of TCP through net_context on its new sendto
function.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 8d21c68718 net/tcp: Switch rest of TCP to new net_pkt API
Only next to be removed functions like net_tcp_set_checksum() are left
untouched. All the rest is switched.

Adding net_tcp_finalize() to follow the same logic as for UDP and else.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka baa9784008 net/tcp: Apply connection callback signature change
This proovse to drastically reduce runtime overhead as it does not need
to parse IP nor TCP header all over again in a lot of places.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 118a0f0d22 net/conn: Change callback signature to pass TCP/IP headers
As these were parsed already by IPv4/6 input functions let's use them.

Applying the change on trivial UDP usage. TCP usage will have its own
commit.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 199952755d net/tcp: Switch TCP segment preparation to new net_pkt API
Using new functions for net_context, ipv4 and ipv6 as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 40ad4b7e3e net/context: Expose new functions to create ipv4/6 packet from context
These will be specifically needed in TCP, as well as being used in
context internally.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka a9dd6256a4 net/ipv4: Move autoconf to new net_pkt API
Only the allocator needed to be changed here.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka e04914a963 net/ipv6: Switch sending fragmented IPv6 packet to new API
This optimizes the memory quite a bit since we do not need to clone nor
split the original packet at any time.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 2d5f8b9317 net/ipv6: Re-enable support for fragmented packet at input
Now using the new API.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 88f5672e4c net/ipv6: Switch MLD join, leave and report to new net_pkt API
Most of the code had to be reworked due to the new API: it's more
logical to do everything sequentially (first headers, then MLD part)
than the contrary with inserting headers at the end.

Using get_data/set_data as well it makes the code clearer.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka df8fa6400d net/ipv6: Switch IPv6 sending preparation to new net_pkt API
Also, return a verdict instead of a pointer to net_pkt. It's simpler as
it will be up to net_send_data()'s caller to unref the net_pkt in case
of NET_DROP: less places where net_pkt can be unref.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka ec16928d8b net/icmpv6: Remove various useless get/set hdr functions
All of these are unused anywhere now, thus can be safely removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 14f3ae1152 net/ipv6: Switch MLD query msg handler to new net_pkt API
Reworking the logic to reduce the amount of variables.
Introducing a generic struct to acces the common part of MLD queries,
instead of accessing part by part.

Also, returning NET_OK in case parsing went fine. We send an MLD report
anyway, so it's not a good idea to count the message as being dropped in
statistics.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka ae7243b0d5 net/ipv6: Switch RA msg handler to new net_pkt API
Reworking the logic to reduce the amount of variables.
This part was heavier to change as it was not accessing the headers
directly but instead was read parts by parts.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 6dc6499bd5 net/ipv6: Switch NS msg handler to new net_pkt API
Reworking the logic to reduce the amount of variables.

Also taking the opportunity to normalize drop messages.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka f32de35e27 net/ipv6: Switch NA msg handler to new net_pkt API
Reworking the logic to reduce the amount of variables.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 9a6027ba5c net/icmpv6: Improve callback signature to pass icmp header
In nbr part, this is a useful information. Since net_icmpv6_input has
already parsed the icmpv6 header, let's get pass it, instead of
retrieving/parsing it again in various handler functions.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 7a3150ea5e net/ipv6: Removing useless macros in nbr code
append/append_all are unused anywhere.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 9789773ee4 net/ipv6: Switch RS msg sending to new net_pkt API
And let's use net_ipv6_create, net_icmpv6_create, net_ipv6_finalize to
factorize the code better.

Removing useless setup_headers private function now.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 304f913525 net/ipv6: Switch NS msg sending to new net_pkt API
And let's use net_ipv6_create, net_icmpv6_create, net_ipv6_finalize to
factorize the code better.

De-clutter the code by reordering where src/dst are evaluated.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 82f027460a net/ipv6: Switch NA msg sending to new net_pkt API
And let's use net_ipv6_create, net_icmpv6_create, net_ipv6_finalize to
factorize the code better.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka fc38d0929d net/icmpv6: Make header creation function public
This will be used in ipv6_nbr, ipv6_mld and so on...

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 282962bb85 net/context: Add support for IPv6 on the new send/sendto functions
It can now use the new IPv6 function to create IPv6 header.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka c80d0d30e1 net/icmpv6: Switch error message to new API
Logic does not change much, besides using new create/finalize functions
etc...

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 189dc030f6 net/icmpv6: Switch echo request handler to new API
Unlike before, we allocate a new packet for the reply which is a
modified clone of the request.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 47f3b339eb net/icmpv6: Rework relevant signatures to pass ipv6 header pointer
This is meant to remove the need for macro NET_IPV6_HDR(), since we
don't know in future if accessing the header that way will be valid.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 86ac993e0c net/ipv6: Rework input function
Use the new net_pkt API to proceed through IPv6 header and all the
extension header as well.

Use udp/tcp input functions relevantly, and call net_conn_input
afterwards.

Note: This commit temporarly disable IPv6 fragmentation support
in the code directly. Which support will be re-enabled afterwards.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 30e5c516b1 net/icmpv6: Switch echo request to new net pkt allocator and API
This is pretty much the same as in ICMPv4. Actually, when it comes to
the ICMP header, it could probably be put in a common places for both
ICMPv4 and ICMPv6.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 070b4d2da8 net/ipv6: Account for extension headers when finalizing
Extension headers are specific and use nexthdr attribute from net_pkt.
next_header_proto is the user protocol (if any) that might require
finalization too (calculating the checksum).

However, if there are extension header, we need to skip those and jump
to the position where the user protocol starts.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 6ea5a12f4c net/pkt: Use next_hdr field only for IPv6
Also, store the actual next_hdr value and not it's position.
This permits to reduce net_pkt from some bytes.

Such field was unused until now, but it will be soon.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka fa4c52b98f net/ipv6: Add new API to create/finalize IPv6 headers.
This API is meant to work with pre-allocated net_pkt.
It assumes net_pkt's buffer cursor is at the right position where to
create the IPv6 header. Once done, the cursor will be placed right
after the newly created IPv6 header.

Finalizing assumes the same.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 2ad71c7701 net/icmpv6: Add a new function to finalize the ICMPv6 packet
Function names will be normalized then by the couple create/finalize.
This one only sets the checksum.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 7e25568a22 net/udp: Remove now useless net_udp_get_chksum function
It's not used anywhere.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 7d0ed7155c net/ipv4: Rework input function
Use udp/tcp input functions relevantly, and call net_conn_input
afterwards.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 1be2706a93 net/connection: Modify input function
Verifying udp/tcp checksum should be done before calling this function.
Also, up to ipv4 and ipv6 to provide a pointer to their respective
header.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 3d52ff2e34 net/tcp: Add an input function for pre-validation
This will quickly verify the header, its checksum and grab src/dst
ports.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 4937077e48 net/udp: Add an input function
This will be the place where UDP header is parsed: its checksum verified
and src/dst ports grabbed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 0d519f7bcf net/context: Create new send sendto functions using new net_pkt API
It's not anymore up to user to provide the pkt. Context will build the
packet according to its metadata and provided buffer and length.

It currently supports only IPv4 and UDP.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 90e46c6ed1 net/icmpv4: Remove useless create, get and set header functions
These are not needed anymore.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka f9315f8097 net/icmpv4: Switch error message to new API
Logic does not change much, besides using new create/finalize functions
etc...

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 264ce4f6ad net/icmpv4: Switch echo request handler to new API
Unlike before, we allocate a new packet for the reply which is a
modified clone of the request.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 719ab0dab7 net/icmpv4: Rework relevant signatures to pass ipv4 header pointer
This is meant to remove the need for macro NET_IPV4_HDR(), since we
don't know in future if accessing the header that way will be valid.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 17a7f7fef1 net/icmpv4: Add a new function to finalize the ICMPv4 packet
Function names will be normalized then by the couple create/finalize.
This one only sets the checksum.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka d319483a5f net/icmpv4: Input headers are gathered through new API
As before, such header is meant to be in a contiguous area.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 147b2eb498 net/ipv4: Input headers are gathered through new API
As before, such header is meant to be in a contiguous area (beginning
of the buffer, only 20 bytes)

Opportunistically chaning the function name to net_ipv4_input() (all
will be create/finalize/input).

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 1b6a500067 net/core: Set cursor relevantly
Newly received pkt can get their cursor intialized at net_recv_data()
(most of the time, drivers won't mangle with the content before calling
that function).

Right after l2 (net_if_recv_data()) parsing as well. L2s pull the
starting buffer after ll header. Instead of letting L2s updating the
cursor, it's simpler to reinitialize it directly after such parsing.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka aec920ea53 net/core: Each and every received packet are being set to overwrite
This will avoid new API's writing functions to modify the packet's
content. For instance while checking its checksum etc...

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 2caa0b4e43 net: Adapt checksum calculation to new net_pkt API
Let's just use the packet cursor relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 593f957618 net/dhcpv4: Switch to new net_pkt API
Use new allocator and function to r/w dhcp messages.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 999b3740b8 net/icmpv4: Switch echo request to new net pkt allocator and API
This is the easiest piece to change using the new API, and can be used
as showing how this API can be used.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 60b3137508 net/udp: Add new API to create/finalize UDP headers
This API is meant to work with pre-allocated net_pkt.
It assumes net_pkt's buffer cursor is at the right position where to
create the UDP header. Once done, the cursor will be placed right after
the newly created UDP header.

Finalizing assumes the same.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka eb2adf30f3 net/ipv4: Add new API to create/finalize IPv4 headers.
This API is meant to work with pre-allocated net_pkt.
It assumes net_pkt's buffer cursor is at the right position where to
create the IPv4 header. Once done, the cursor will be placed right
after the newly created IPv4 header.

Finalizing assumes the same.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 06037c4d3f net/pkt: Add generic get/set data functions
These ones would support linearizing non-contiguous area, however
requiring a bit more complex type as an "accessor".

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka b039625745 net/pkt: Add an API to read/write into the buffer in a simpler way
Adding a cursor into net_pkt. This is used to read/write data in a much
simpler way, for pre-allocated buffers in net_pkt. This avoids API users
to deal with net_buf below directly.

However, to be used - as for the new allocators - it will require deep
net stack core and API changes.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 8eb9ff72f6 net/pkt: Add new allocators
These struct net_pkt allocators will give the possibility to allocate at
once the net_pkt and the buffer associated with, taking care of the
header space and MTU relevantly.

This enables to use the variable length allocator from net_buf. However,
it is not yet the default and is set as experimental.

As it is provided in parallel to existing allocators, it has to keep a
slab per-direction and thus a pointer in net_pkt, as well as appdata,
appdatalen etc... Resulting in "bloating" net_pkt. This will be solved
when, finally, former allocators will be removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Jukka Rissanen 2ece89f523 net: shell: Remove net-app command
The "net app" command is not needed any more as the API is removed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-01 12:29:21 +02:00
Jukka Rissanen 93e5181fbd net: context: Add locking for concurrent access
If the net_context functions are accessed from preemptive priority,
then we need to protect various internal resources.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-31 11:20:26 +02:00
Jakub Rzeszutko 75ad61f7ef shell: removed foreground command functionality
Removed foreground command functionality from shell source files.
Removed associated example.
Removed enter/exit command functions from the Bluetooth example
Updated project config files.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-30 13:05:56 +01:00
Léonard Bise c8eeb91222 net: tcp: Call cb in case last ACK is not received
After receiving FIN, the TCP stack will send a FIN and start
a timer to track the reception of the associated ACK. In case this
ACK is never received then the context will be released
without calling the associated received callback which leads to
upper layers not being informed that the connection was closed.

This issue was observed when using sockets, the effect is
that in this case the socket would never be closed and stay
in limbo forever.

Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
2019-01-30 12:47:00 +02:00
Jukka Rissanen 09365adced net: shell: Fix network interface type for OpenThread
The "net iface" net-shell command printed "<unknown type>" for
OpenThread based technology. After this commit, the network
interface type is set to "OpenThread".

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-29 16:03:47 +02:00
Daniel Glöckner d678f309b8 net: pkt: convert remaining users of ref to atomic_ref
The previous commit replaced the net_pkt element ref with an element
atomic_ref. CI tests turned up more places where ref was used directly.
This commit converts them to use the new element.

Signed-off-by: Daniel Glöckner <dg@emlix.com>
2019-01-29 09:22:14 +02:00
Daniel Glöckner 5ef825fdf6 net: pkt: fix race condition in packet reference counting
It has been observed that some network drivers, f.ex. the SAM E70 GMAC,
call net_pkt_unref from inside the interrupt that signals the successful
transmission of a packet. This conflicts with the net_pkt_unref call
made by ethernet_send after the packet has been given to the driver.

We fix this by using an atomic_t to hold the reference count as there
might be other, difficult to find cases of net_pkt_(un)ref being used
across threads and interrupts.

The name of the element has been changed from "ref" to "atomic_ref" to
cause a compile error when code still has not been converted to use the
atomic_* functions.

Fixes #12708

Signed-off-by: Daniel Glöckner <dg@emlix.com>
2019-01-29 09:22:14 +02:00
Robert Lubos 83b8abaf8a net: ip: Introduce mesh_local address flag
This commit introduces a concept of mesh-local IPv6 addresses. Such
addresses should only be used for mesh-local communication, therefore
should not be used to communicate with different subnets (i. e.
destinations outside the mesh).

As `addr_type` field already holds different kind of information
(whether address was created automatically/manually) it was not used in
this case.

Instead a mesh_local flag was added, so that we do not lose information
on how address was created. Address with such flag set will only be
selected as a source address automatically if the destination address
is within the same subnet it belongs to.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-28 21:24:26 -05:00
Aurelien Jarno 40b8854705 net: tcp: do not drop successfully received packets
Each time a successfully TCP connection is done, the number of dropped
TCP packets increases by 2. This is happens because when receiving an
initial SYN packet, or an ACK packet following a SYN+ACK packet,
NET_DROP is returned even if there is no error.

Fix that by replacing the two corresponding "return NET_DROP" by
"net_pkt_unref(pkt)" followed by "return 0".

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-16 13:11:39 +02:00
Jukka Rissanen a7afdc3512 net: rpl: Remove the deprecated code
The RPL was deprecated earlier so remove it by this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-13 09:40:36 -05:00
Björn Stenberg d4ef80ec57 net: tcp: Release connect() semaphore if connection is refused
Connecting to a non-open port causes connect() to hang forever.
This patch releases connect() to return error to the caller.

Signed-off-by: Björn Stenberg <bjorn@haxx.se>
2019-01-10 12:32:17 -05:00
Tomasz Bursztyka b04e71901f net/icmpv4: Disable broadcast echo request reply by default
Accepting broadcast echo request and replying to it could provide an
attack vector.

Fixes #12162

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-01-08 13:42:18 +02:00
Jukka Rissanen 69f849235f net: pkt: Only enable debug print when really needed
The NET_LOG_LEVEL is enabled also when allocation debugging is
enabled but when net_pkt debugging is not. Thus we need to use
the CONFIG_NET_PKT_LOG_LEVEL when printing normal debug log
prints.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-08 13:29:18 +02:00
Paul Sokolovsky 3329eb2c4e net: pkt: net_frag_linearize: Make consistent with net_buf_linearize
net_frag_linearize() is just a wrapper for net_buf_linearize(). As
the latter was refactored to never return error, and instead just
return actual copied length, update the former and its usages too.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-08 11:06:56 +02:00
Frank Li 978bdf0d5d net: shell: Fix cmd_net_http_monitor build error
No declar 'count',Enable CONFIG_NET_DEBUG_HTTP_CONN will build error.

Using http_monitor_count replace count.

Fixed #12329

Signed-off-by: Frank Li <lgl88911@163.com>
2019-01-07 16:24:32 -05:00
Frank Li 6b5906b8e9 net: shell: Fix showing ping reply
shell_fprintf() doesn't work in callback handlers.
To fix that, set shell state to SHELL_STATE_COMMAND before using it.

Fixed: #12347

Signed-off-by: Frank Li <lgl88911@163.com>
2019-01-07 16:07:31 -05:00
Tomasz Bursztyka e82e31e351 net/icmpv4: A checksum value of 0 is valid
Introduced by commit id de78a7af28.
If the sum is 0xffff, a ~sum will give 0.

Fixes #12164

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-01-04 10:46:52 -05:00
Andrei Emeltchenko eb6601e5f0 net: logs: Enable logging for NET_RAW
The patch allows to enable logs for NET_RAW configuration.
For example using wpanusb currently breaks build with logging enabled.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-01-03 12:33:54 -05:00
Tomasz Gorochowik 754ab1d1b0 net/pkt: Fix debug logs checking
The slab2str function which is used in the debug log call is not defined
unless NET_LOG_PKT_LOG_LEVEL >= LOG_LEVEL_DEBUG.

It looks like this change was accidentally introduced in #11374.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-12-21 21:00:54 +01:00
Tomasz Bursztyka e97a543e9b net/pkt: Remove parameters to "reserve" some headroom
Such parameter is not used anymore, it was defaulted to 0 previously.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 57a0c55dac net/6lo: Remove fragmentation function parameter on compression
Fragmentation has nothing to do with 6lo. Up to the bearer to do so.

This change is required for futur serialization of 15.4 fragmentation.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 66cc034a34 net/ipv6: Remove any use of ll reserve
As this is now unnecessary, let's ignore that and use 0 instead.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 156213078d net/ipv4: Remove any use of ll reserve
As this is now unnecessary, let's ignore that and use 0 instead.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 0873f8fb20 net/pkt: Let's ignore ll reserve and use 0 instead
ll reserve is of no use as the l2 is allocating what it needs for
filling in its header.

This is another step forward to removing ll reserve concept.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Jukka Rissanen 139aab2975 net: pkt: Show buffer allocations only when needed
The net-shell "net allocs" command should print network buffer
allocations even if network packet debugging is not enabled.
This is how it used to work earlier but the behaviour got lost
at some point. So user needs to set CONFIG_NET_DEBUG_NET_PKT_ALLOC
in order to see the buffer allocations. The option will be enabled
by default if network packet log level is set to DBG.
The reason for a separate option is that the network packet debug
logging prints just too much data and it is very difficult to
track allocations when that happens.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-14 13:49:04 +02:00
Tomasz Bursztyka 2d38c915d0 net/icmpv4: No need of a local variable
Result can be tested right away.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Tomasz Bursztyka d943554df6 net/icmpv4: Avoid input function to access IPv4 header again
IPv4 can pass the broadcast information.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Tomasz Bursztyka cb5d1108d9 net/ipv4: Rework ipv4 processing to clarify drop issues
All IPv4 destination address related drop reasons in one place.
This helps also to have one unique call of net_conn_input().

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Tomasz Bursztyka fc09921b82 net/ipv4: Use existing hdr pointer to get ttl value
Header is already accessible via a local varialbe so let's use it.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Tomasz Bursztyka 8fae4fc620 net/ipv6: Have a unique call for net_conn_input()
As for IPv4, net_conn_input() can be called at one place for udp/tcp.
It will anyway check if given protocol is enabled so no need to check
such support here.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Tomasz Bursztyka bd23754387 net/icmpv6: Refactoring ICMPv6 input end-point
It was weird to pre-parse ICMPv6 headers in IPv6. Moreover parsing
failure of such header would not generate the right statistic.

Instead, centralizing all into net_icmpv6_input relevantly, and adapting
the test cases which were using that function. In RPL test, removing the
dummy dio test was simpler since dio is anyway tested later on.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Ruslan Mstoi a2a7459f23 net: shell: Update info to enable allocs
If relevant configs are not enabled shell allocs command would print
wrong info:

"Enable CONFIG_NET_DEBUG_NET_PKT to see allocations"

CONFIG_NET_DEBUG_NET_PKT is obsolete and an undefined symbol, setting it
causes cmake to fail. This patch fixes this issue by printing up-to-date
information on how to enable allocs command

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-12-10 18:00:01 +02:00
Jukka Rissanen e812b6804a net: if: Make dst address const when selecting src addr
As the functions do not modify the destination address parameter,
it can be made const.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 16:18:24 +02:00
Tomasz Bursztyka 76fa82f7ab net/icmpv6: Optimize how chksum is verified
Just recalculate the chksum without resetting its value to 0, and test
if return value is 0.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-07 13:50:46 +02:00
Vincent van der Locht 58463b7ea7 net: dhcpv4: dhcp start/stop made compatible for multiple interfaces
The net_dhcpv4_stop() function stops the event listener for any IF_UP
events previously. In case multiple interfaces are used and optionally
being switched over, it could result in disabling dhcp unintentionally.

The callback is initialized at the init function and added/removed in
the start/stop function based on the interface list being empty
or not. (first added, last removed)

The event handler checks if the interface is in the list before acting
on it.

Signed-off-by: Vincent van der Locht <vincent@vlotech.nl>
2018-12-07 12:23:46 +02:00
Vincent van der Locht 994a4772ca net: dhcpv4: net_dhcpv4_stop() removing address during renew
In case "net_dhcpv4_stop(..) is called when the interface is
in NET_DHCPV4_RENEWING state, the address is not removed.
When deleting the address in the NET_DHCPV4_RENEWING state
means the status is always equal to the moment before _start
is called.

Signed-off-by: Vincent van der Locht <vincent@vlotech.nl>
2018-12-07 12:22:19 +02:00
Jukka Rissanen 301d342571 net: Move net_analyze_stack() function to net_core.c
No need to this function be inlined so move it to .c file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Jukka Rissanen 86689030e8 net: Clarify logging in networking code
Remove network specific default and max log level setting
and start to use the zephyr logging values for those.

Remove LOG_MODULE_REGISTER() from net_core.h and place the
calls into .c files. This is done in order to avoid weird
compiler errors in some cases and to make the code look similar
as other subsystems.

Fixes #11343
Fixes #11659

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Jakub Rzeszutko e0be6a10b3 shell: printing command's help by shell engine
Removed printing command help from help handler. It is now
realized by the shell engine. This change saves a lot of flash
but still allows to print help in command handler with function
shell_help_print.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko 5451ff2848 shell: remove "options" concept
Removing help "options" from shell API.

Currently SHELL_OPT macro is not used by users. What is more
commit: a89690d10f ignores possible options created in
command handler by the user. As a result they are not printed
in help message.

Second, currntly implemented "options" in command handlers options are
implemented without SHELL_OPT macro.

And last but not least this change will allow to implement
help handler in a way that user will not need to think about calling
functions printing help in a command handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Tomasz Bursztyka 93fc23bc7e net/icmpv6: Verify header's checksum relevantly
Missing verification.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-05 11:43:54 +02:00
Tomasz Bursztyka 6c291524bc net/icmpv4: Verify header's checksum relevantly
Missing verification.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-05 11:43:54 +02:00
Tomasz Bursztyka 3db4378d9e net/ipv4: Verify header's checksum relevantly
Missing verification.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-05 11:43:54 +02:00
Tomasz Bursztyka 0dd5113ca4 net/connection: Verify UDP and TCP checksum the easy way
No need to store/reset/recompute the chksums, only compute it again and
if it's not 0: drop the packet.

RFC 1071:

"To check a checksum, the 1's complement sum is computed over the
 same set of octets, including the checksum field.  If the result
 is all 1 bits (-0 in 1's complement arithmetic), the check succeeds."

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-05 11:43:54 +02:00
Tomasz Bursztyka b4f79ae418 net: Return fully calculated chksum
IPv4, ICMPv4/6, UDP, TCP: all checksums are meant to be one's complement
on a calculated sum. Thus return one's complement already from the right
place instead of applying it in each and every place where
net_calc_chksum is called.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-05 11:43:54 +02:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Paul Sokolovsky 6a2853f9f4 net: ipv4: Clarify basic IPv4 packet drop logging
1. Clarify message telling that the actual packet length fed by the
driver differs from what specified in IPv4 header, and that leads to
drop.
2. Debug log any dropped packets in general.

These changes come from the experience of developing a networking
driver, where figuring out why packets get dropped may require
quite a head-scratching.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-04 12:29:03 +02:00
Jukka Rissanen e9364d52fe net: Discard received extra data at the end of the IP message
If we receive extra data at the end of the IP message, then
discard that data and accept the packet.

Fixes #11649

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-02 14:23:13 -05:00
Tomasz Bursztyka 10c4841835 net/net_if: Do not set TCP related flags on non-INET/6 family
Such sent flag is in a union in net_pkt, shared with a gptp flag.
Tweaking it when the family is not AF_INET or AF_INET6 will generate
corrupted gptp packets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka ee9dedd5a7 net/iface: Finally remove the send function from net_if_api
And apply that to modem driver setting that pointer to NULL.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 9464ec3343 net/iface: Switch fully to a one-pass sending logic in net_if
Now instead of such path:

net_if_send_data -> L2's send -> net_if tx_queue -> net_if_tx -> driver
net_if's send

It will be:

net_if_send_data -> net_if tx_queue -> net_if_tx -> L2's send -> driver
net_if's send

Only Ethernet is adapted, but 15.4 and bt will follow up.
All Ethernet drivers are made compatible with that new scheme also.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Ravi kumar Veeramally 7a5640f126 net: ipv4: Drop incoming packets with src addr is multicast
As per RFC1112 sec 6.2 "A host group address must never be
placed in the source address field or anywhere in a source
route or record route option of an outgoing IP datagram."

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-28 10:13:41 +01:00
Ravi kumar Veeramally f2e0754718 net: ipv4: Drop the replies if src address in unspecified
Networking stack sometimes try to find source address based
on destination address. If interface could not find best match
then it returns unspecified address (0.0.0.0). Host should not
send these packets.

IPv4 reply related issues fixed.

Fixes #11329

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-28 10:13:41 +01:00
Ravi kumar Veeramally b848f8f9c5 net: rpl: Remove __deprecated tag to one function
net_rpl_get_interface() function which returns always NULL is
defined if NET_RPL is not enabled. so remove deprecated tag to
this particular function. Otherwise it will cause unnecessary
compilation warnings.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-23 09:10:23 -05:00
Ravi kumar Veeramally 7d0aecfc2a net: rpl: Deprecate RPL
RPL support has been deprecated from Zephyr.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-22 09:01:04 -05:00
Jukka Rissanen 279da528bc net: pkt: Print debug prints in one line
In earlier commit 15e7e3ea4 ("net: ip: Split debug prints into
smaller pieces"), the net_pkt debug prints were split to two
lines because of the argument count limitation in logging system.
As the logging subsystem increased the limit count in
commit 62d011549a ("logging: Support for up to 15 arguments in log
message") we can restore the original version as it is easier
to read.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-13 12:54:27 -05:00
Jukka Rissanen 89355e14ac net: if: Properly turn off promiscuous mode
Pass the promiscuous mode OFF event properly to device driver
instead of just toggling the network interface flag.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-13 12:53:44 +02:00
Jukka Rissanen 64eb47e032 net: promisc: Flush the promisc queue properly
Flush the promiscuous queue after all the clients have turned
off promiscuous mode. This makes sure that we do not leave any
RX packets hanging on the queue and waste memory.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-13 10:00:07 +02:00
Krzysztof Chruscinski 97345dbb1b logging: Fix errors in log usage
Couple of findings which were revealed after changing
LOG_MODULE_REGISTER macro:
- missing semicolons after LOG_MODULE_REGISTER()
- missing LOG_LEVEL defines
- other

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-10 12:38:29 -05:00
Jukka Rissanen 421505c7e3 net: qemu: Allow SLIP or normal ethernet connectivity
Introduce new Kconfig option for selecting either slip or ethernet
connectivity to host.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-10 09:13:45 -05:00
Jukka Rissanen aa5f219bd1 net: if: Allow calling IPv4 specific functions
Make sure that IPv4 specific functions are callable even if
IPv4 is not enabled. This allows use of IS_ENABLED() macro
in other parts of the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-08 15:23:05 +02:00
Jukka Rissanen 2808b23f44 net: if: Allow calling IPv6 specific functions
Make sure that IPv6 specific functions are callable even if
IPv6 is not enabled. This allows use of IS_ENABLED() macro
in other parts of the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-08 15:23:05 +02:00
Tomasz Bursztyka 7280757d7d net/ipv4: Use iface's ll reserve relevantly
No need to evaluate what's the ll reserve size here as net if has a
function to do so.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-06 12:42:06 +02:00
Jukka Rissanen 9fc9d1496e net: ipv6: Loopback interface local scope packets back to us
If the destination IPv6 address is interface local scope multicast
address FF01::, then loopback those packets back to us as that is
the purpose of those addresses. They are to work same way as
localhost unicast address. See RFC 3513 ch 2.7 for details.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-06 11:11:08 +02:00
Jukka Rissanen a13cee27c3 net: shell: Add IPv6 and IPv4 checks for ping command
If IPv6 is disabled, then we can skip IPv6 checks and avoid
Coverity warnings. Same thing for IPv4.

Coverity-CID: 189506
Fixes #11100

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-06 11:09:12 +02:00
Jukka Rissanen ad27d0e39e net: ipv6: Check the size of the ICMPv6 echo-req packet
The minimum size is 8 bytes, drop packet if shorter.

Fixes #10970

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-06 11:08:15 +02:00
Jukka Rissanen cf063fe85b net: Rename net_is_xxx...() functions to net_xxx_is...()
Unify the function naming for various network checking functions.

For example:
     net_is_ipv6_addr_loopback() -> net_ipv6_is_addr_loopback()
     net_is_my_ipv6_maddr() -> net_ipv6_is_my_maddr()
etc.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 14:52:33 -04:00
Jukka Rissanen 6c628737e0 net: ipv6: Verify ICMPv6 checksum before accepting packet
Make sure that ICMPv6 checksum is correct before continuing
processing the packet.

Fixes #10971

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 16:03:18 +02:00
Jukka Rissanen 4b7d8fb76d net: ipv6: Drop organisation scope multicast dst address pkt
If we receive an IPv6 packet with organisation scope multicast
address FF08:: then we must drop it as those addresses are
reserved for organisation network traffic only.

Fixes #10961

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 15:10:48 +02:00
Jukka Rissanen 84e85db994 net: ipv6: Drop site scope multicast dst address pkt
If we receive an IPv6 packet with site scope multicast
address FF05:: then we must drop it as those addresses are
reserved for site network traffic only.

Fixes #10960

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 15:10:48 +02:00
Jukka Rissanen fbaf9d615c net: ipv6: Drop zero scope multicast packet
The zero scope is a reserved value so it should not be used
so drop it.

Fixes #10958

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 15:10:48 +02:00
Jukka Rissanen 1e293b4089 net: ipv6: Drop interface scope multicast dst address pkt
If we receive an IPv6 packet with interface scope multicast
address FF01:: then we must drop it as those addresses are
reserved for local network traffic only.

Fixes #10959

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 15:10:48 +02:00
Jukka Rissanen 1e4f268ea9 net: if: Move link address assert check to net_if_up()
For Bluetooth, the link address is set only after the Bluetooth
connection is established. Because of this, place the link address
check to net_if_up() because at that point the link address should
be set properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 15:08:39 +02:00
Paul Sokolovsky 51c7b5f73a net: if: Assert that link layer addr was set by driver
There's a lot of code which assumes net_if_get_link_addr(iface)->addr
Forgetting to set it leads to deferred, spectacular crashes. It's
impractical to assert it on every usage. So, instead let's assert
it after call to driver->init(), as that is supposed to set it.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-02 10:18:17 +02:00
Jukka Rissanen 87dd0e7e6b net: ipv6: Drop outside pkt with ::1 dst or src address
We must drop packet that is received from outside and which has
IPv6 loopback address (::1) either as a destination address or
source address.

Fixes #10933

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-01 14:32:21 +02:00
Ruslan Mstoi de78a7af28 net: icmpv4: Drop ICMPv4 packet with zero checksum
ICMPv4 checksum is not optional and thus cannot be zero. Hence, drop
packet with invalid zero ICMPv4 checksum.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-10-30 16:13:57 +02:00
Björn Stenberg 01ff384f10 net: ipv6: Remove incorrect length assignment in MLDv2
This assignment causes the later code to overwrite part of the
packet, making it malformed.

Signed-off-by: Björn Stenberg <bjorn@haxx.se>
2018-10-26 22:28:43 +03:00
Jukka Rissanen b34da1ad62 net: Drop IPv4 packet if source address is broadcast one
Source address cannot be broadcast one so check it properly.

Fixes #10782

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 15:37:21 +03:00
Jukka Rissanen 7d83543379 net: Properly handle pkt IPv4 broadcast destination address
If we receive an IPv4 that has broadcast destination address, then
properly handle it.
This means that for
  * ICMPv4, if CONFIG_NET_ICMPV4_ACCEPT_BROADCAST is set (this is the
    default value) and we receive echo-request then accept the packet.
    Drop other ICMPv4 packets.
  * TCP, drop the packet
  * UDP, accept the packet if the destination address is the broadcast
    address 255.255.255.255 or the subnet broadcast address.
    Drop the packet if the packets broadcast address is not in our
    configured subnet.

In sending side, make sure that we do not route broadcast address
IPv4 packets back to us. Also set Ethernet MAC destination address
properly if destination IPv4 address is broadcast one.

Fixes #10780

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 15:37:21 +03:00
Jukka Rissanen aa2240a444 net: ip: Add function to check if IPv4 address is broadcast one
Add utility function that returns true if given IPv4 address is
a broadcast address. This will be used in later commits to check
received packet IPv4 source and destination addresses.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 15:37:21 +03:00
Jukka Rissanen 5f66852f62 net: ipv4: Fix network byte ordering for netmask related computing
Remove extra ntohl() calls when checking IPv4 address against
a subnet address.

Convert also the IPv4 address to be const as the netmask related
functions do not change its value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 15:37:21 +03:00
Jukka Rissanen 601426866a net: Set used transport protocol to net_pkt
Cache the used transport protocol in net_pkt. This way we can
avoid traversing IP header to get the last protocol in network
packet. This is mostly an issue in IPv6 which can have a long
list of extension headers after IPv6 header and before the
transport protocol header.

Fixes #10853

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 14:08:43 +03:00
Ruslan Mstoi f1c67615cf net: ipv6: Add Destination Options Header support
This patch adds support for IPv6 Destination Options Header

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-10-25 16:50:15 +03:00
Jukka Rissanen 72a37e59e5 net: log: Max debug level was forced too high
Wrong Kconfig template was used for max debug level which caused
the max level to be the default level (ERROR). This prevented
all debug prints from showing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-25 15:05:19 +03:00
Jukka Rissanen 7797c01eb5 net: Honor max log level in net
The maximum log level was using wrong template which caused
the max value to be ignored.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-24 15:10:33 +03:00
Jukka Rissanen eb6f37d753 net: log: Add missing spaces around = in Kconfig.debug
The CONFIG_NET_DEFAULT_LOG_LEVEL template entry was only partially
fixed earlier and some spaces were not there around "=".

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-22 11:11:35 +03:00
Paul Sokolovsky cdeddee7c6 net: Set names for threads used by the network subsys/libs
Previously, these either used generic names like "workqueue" (so,
it wasn't possible to distiguish tx and rx workqueues) or didn't
set for net management thread. Here's an example of thread dump
in a typical system (using stack_analyze() call):

rx_workq (real size 4092):	unused 3696	usage 396 / 4092 (9 %)
tx_workq (real size 4092):	unused 3692	usage 400 / 4092 (9 %)
net_mgmt (real size 4092):	unused 3772	usage 320 / 4092 (7 %)
sysworkq (real size 4092):	unused 3512	usage 580 / 4092 (14 %)
idle (real size 252):	unused 64	usage 188 / 252 (74 %)
main (real size 4732):	unused 3672	usage 1060 / 4732 (22 %)

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-19 07:58:45 -04:00
Jukka Rissanen 89783f5282 net: connection: Fix debug print for connection index
The connection index was printed incorrectly in debug print.

Coverity-CID: 188742
Coverity-CID: 188753

Fixes #10583 #10574

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-18 20:35:02 +03:00
Tedd Ho-Jeong An 548361c4e2 net: ip: Fix compile error due to config dependency
This patch fixes the compile error when CONFIG_NET_PKT_LOG_LEVEL
is LOG_LEVEL_DBG.

> subsys/net/ip/net_shell.c: In function ‘context_info’:
> subsys/net/ip/net_shell.c:2893:106: error: ‘struct net_buf_pool’
> has no member named ‘avail_count’
> subsys/net/ip/net_shell.c:2893:125: error: ‘struct net_buf_pool’
> has no member named ‘name’

In struct net_buf_pool, 'avail_count' and 'name' are depends on
CONFIG_NET_BUF_POOL_USAGE.

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2018-10-17 21:35:24 +03:00
qianfan Zhao a52186ded2 net: shell: Return -ETIMEDOUT if ping target timeout
The previous code returned 0 even if ping failed(timeout).

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-10-17 18:04:18 +03:00
Satya Bhattacharya 4f4c7e2b1a net: rpl: Null pointer dereferences
Check for NULL IPv6 addr values from net_if_ipv6_get_ll() in rpl.c
If NULL, print out an error statement stating that no proper IPv6
address was found
Coverity-CID: 188169

Fixes #10094.

Signed-off-by: Satya Bhattacharya <satyacube@gmail.com>
2018-10-17 14:33:36 +03:00
Jukka Rissanen 436e295dd9 net: shell: Migrate to new shell API
Convert net-shell to use the new shell API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-15 11:14:02 +03:00
Gil Pitney 00895795fa net: Fix assert on net_if_api send for NET_OFFLOAD drivers.
Recently, the wifi net offload driver has been asserting
as init_iface() was checking for api->send != NULL, even in
the case of NET_OFFLOAD

This patch suggests a fix to handle the NET_OFFLOAD case.

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-10-12 09:58:16 +03:00
Jukka Rissanen 57a8db7789 net: Use log_strdup() when printing debug strings
As the debugging print calls are async, all the strings that might
be overwritten must use log_strdup() which will create a copy
of the printable string.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 9b460b1105 net: Use logger hexdump print macro
As the logger provides hexdump macro, use that instead of our own.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 15e7e3ea4b net: ip: Split debug prints into smaller pieces
Currently logging subsystem supports quite small number of function
parameters. So split some long functions into smaller pieces.
Hopefully this is just a temporary patch and we can support more
parameters to logging macros.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 2bc38a8f88 net: mgmt: Use correct printf modifier in debug print
Net event information debug print was using wrong printf modifiers.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 3ab1f90822 net: lib: Convert net_app to use log level
Use network log level in net_app library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen a76814bfb6 net: Convert core IP stack to use log levels
Instead of one global log level option and one on/off boolean
config option / module, this commit creates one log level option
for each module. This simplifies the logging as it is now possible
to enable different level of debugging output for each network
module individually.

The commit also converts the code to use the new logger
instead of the old sys_log.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Tomasz Gorochowik a979841ec4 net: gptp: Fix sync receipt timeout timer starting
Completely remove the last_sync_receipt_timeout time. It is not part of
the standard (see 802.1AS-2011, 10.2.11 for the complete list of
variables for this state machine). Additionally this extra variable was
never really initialized so the calculated duration made no sense.

Just start the timer based on the regular sync receipt timeout time
interval from the port data set.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Mark Ruvald Pedersen d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Johann Fischer 7ba6736ac0 net: ipv6: set pkt properties prior to routing
pkt properties should be set prior to routing.
If packet routing is turned on and the packet is
forwarded to an interface, the pkt properties like
ipv6_ext_len or ip_hdr_len will not be initialized.
If a UDP packet is forwarded to an 6lo interface,
it leads to incorrect calculation of UDP header
during UDP header compression (net_udp_get_hdr).

Fixes #10204

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-09-26 10:09:05 +03:00
Jukka Rissanen 02e9f9c8e6 net: route: Check that neighbor exists before deleting it
If the neighbour does not exists, then the route to it cannot
be deleted so we can return error to caller in that case.

Coverity-CID: 188173
Fixes #10090

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-21 17:32:18 +03:00
Jukka Rissanen 3b8c37de45 net: route: Check NULL value in debug print
In net_route_add(), do not try to print route information if
route to neighbor is not found.

Coverity-CID: 188172
Fixes #10091

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-21 17:32:18 +03:00
Jukka Rissanen fc27a81ed2 net: context: Select proper network interface when binding
Use the destination address to select the proper network interface
when binding. The default network interface cannot be used here
as then the packet might be sent to wrong network interface.

Fixes #9935

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-20 11:21:22 +03:00
Krzysztof Chruscinski 527256501f shell: Rename shell to legacy_shell
New shell implementation is on the way. For now old one and all
references are kept to be gradually replaced by new shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Tomasz Bursztyka e8dee89079 net/udp: Separating net_context from udp and other cleanup
- Up to net_context to give the source port.
- net_udp_append is unused anywhere: let's remove it.
- left over macros on _raw versions removed as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-09-13 14:34:25 +03:00
Tomasz Bursztyka a7ddb1fb82 net/udp: Removing useless init function
There is nothing to initialize, so it can be removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-09-12 14:49:23 +03:00
Tomasz Bursztyka f1e5e17d3b net/udp: Removing useless insert/append _raw functions
These are not used anywhere.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-09-12 14:49:23 +03:00
Tomasz Bursztyka b6468999e4 net/pkt: Rename link layer address accessors relevantly
*_ll_src/*_ll_dst/*_ll_swap/*_ll_if were not self explanatory, ll
meaning "link layer" it's ambiguous what the names meant.
Changing to:
*_lladdr_src/*_lladdr_dst/*_lladdr_swap/*_lladdr_if to fix this.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-09-11 16:06:13 +03:00
Jukka Rissanen 1d33f2ba50 net: shell: Add information about IPv6 configuration
The new "net ipv6" command which will print general IPv6 configuration
and information about autoconfigured IPv6 addresses.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Jukka Rissanen 3f4d468059 net: if: Add utility function to return IPv6 prefix info
The net_if_ipv6_prefix_get() function will return the proper prefix
for a given IPv6 address and network interface. This is used when
checking which source address should be returned to the caller.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Jukka Rissanen 09390e5b3f net: if: Support long lifetime IPv6 prefixes
Enable IPv6 prefix to have long lifetime (> 25 days)

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Jukka Rissanen f8c6c7f0f0 tests: net: ipv6: Test long address lifetime timeouts
Check that long (> 24 days) IPv6 address lifetime timer is
properly handled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Jukka Rissanen c4cc8a5f3e net: if: Refactor IPv6 address lifetime timer
Refactor IPv6 address lifetime timer setting in net_if_addr to support
longer lifetime than 24 days.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Ravi kumar Veeramally 005f014ce4 net: ipv6: Initialize memory
Fix accessing uninitialized memory. Fixes coverity issue.

Coverity-CID: 187902
Fixes: #9768

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-09-04 08:10:18 -04:00
Jukka Rissanen feed6bfb3b net: dhcpv4: Do not debug print IP address using NULL pointer
The ciaddr can be null in requesting state so do not try to print
it in that case.

Fixes #9575

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-30 10:50:27 -04:00
Paul Sokolovsky b0c3b35735 net: tcp: Add comment of func prototype for NET_CONN_CB macro usages
NET_CONN_CB() functional macro hides the parameters a function takes
and its return type. In #8723, it's proposed to remove that macro
altogether. Until that proposal is reviewed, at least provide real
protype in code comments to help people who read/analyze the code.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-29 11:55:07 -04:00
Ruslan Mstoi 6dae106d79 net: ipv6: Drop packet with multiple HBHO
If a malformed packet with multiple HBHO is received by the Zephyr IP
stack it replies with ICMPv6 type 4 code 1: "Parameter problem
unrecognized Next Header type encountered". This ICMPv6 message has
wrong IPv6 payload length and ICMPv6 checksum.

RFC 8200 in chapter 4.1 states:

   Each extension header should occur at most once, except for the
   Destination Options header, which should occur at most twice (once
   before a Routing header and once before the upper-layer header).

There are two possible solutions to the problem at hand:

1) Respond with ICMPv6 Parameter problem, in this case IPv6 length and
   ICMPv6 checksum need to be fixed

2) Drop the malformed packet

This patch implements the easy solution - 2. Basically it changes the
code to drop the malformed packet instead of sending ICMPv6 type 4
code 1.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-08-29 09:26:19 -04:00
Paul Sokolovsky 45a394e805 net: tcp: Remove NET_TCP_FINAL_* flags
These were at most set, but never used. They appear to be artifacts
of importing code from the FNET stack.

Addresses: #9570

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-27 12:51:37 -04:00
Paul Sokolovsky 338dc8a952 net: tcp: Properly queue FIN packets for retransmission
In TCP protocol, any packet is subject to retransmission if not
ACKed in expected time. Thus, any packet, including FIN (and SYN
for that matter) should be added to the retransmission queue.

In our case, despite its name, queue_fin() function didn't add
FIN packet to rexmit queue, so do that. Then, in
net_tcp_ack_received() which handles ACKs, make sure that we can
handle FIN packets: calculate its sequence number properly, don't
make adhoc adjustments to retransmission logic (it's handled
centrally in restart_timer() already), etc.

Fixes: #8188

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-27 12:46:28 -04:00
Jukka Rissanen 4fedec2ee5 net: tcp: Handle out-of-buf properly when preparing segment
If we run out of buffers and cannot create the TCP segment,
then handle it properly and do not access NULL pointer.

Coverity-CID: 187822
Fixes #9639

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-27 12:26:26 -04:00
Jukka Rissanen ab9f39481f net: udp: Check return value when appending UDP data
If there is timeout when adding UDP data, then check this
condition and bail out by returning NULL as the packet is now
malformed.

Coverity-CID: 187825
Fixes #9636

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-27 12:26:26 -04:00
Paul Sokolovsky 8ccac9f74c net: context: Move/rename net_context_set_appdata_values() to net_pkt.c
This function has absolutely nothing to do with net_context.

Addresses: #8723

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-25 07:16:15 -07:00
Paul Sokolovsky 8d3510c554 net: pkt: Cleanup validation of min fragment size based on max headers
1. Where we calculate max size, name variable (preprocessor define)
correspondingly.
2. Calling TCP/UDP an "app protocol" is original, use "next protocol"
terminology of IPv6.
3. As headers go as IP, then "next", order calculations that way too.
4. Add more comments.

Addresses: #8723

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-25 07:15:58 -07:00
Paul Sokolovsky 49732b27d9 net: Move CONFIG_NET_OFFLOAD definition to net/ip/
CONFIG_NET_OFFLOAD was defined in Kconfig of net/ip/l2/, but actually
used by the code in net/ip/.

Fixes: #8646

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-22 12:56:34 +03:00
Florian Vaussard 5212659820 net: tcp: fix spurious TCP retries
Spurious TCP retries were observed using Wireshark while continuously
sending TCP packets at an interval faster than the initial RTO.

If the send list is empty and CONFIG_NET_TCP_TIME_WAIT_DELAY is used,
the retry timer will not be correctly stopped when receiving a valid
ACK. As a consequence, the timer might be running when a new packet is
queued, but the logics in net_tcp_queue_data() will not restart the
timer as it is already running. This will make the retry timer to expire
prematurely, potentially while sending packets.

The nested condition is merged into a single condition, allowing the
final else clause to be reached when a valid ACK is received.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2018-08-20 13:53:49 +03:00
Jukka Rissanen 57a41a2330 net: if: Remove IPv6 auto addresses if the prefix is removed
The autoconfigured IPv6 addresses that are related to removed
prefix, need also removed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-17 17:02:21 +03:00
Jukka Rissanen 3bfc1385f1 net: if: Mark IPv6 address as preferred if lifetime is renewed
If the IPv6 address expires, then it is marked as deprecated.
If a renewal is received in router advertisement, then the address
can be re-used again and is marked as preferred.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-17 17:02:21 +03:00
Ravi kumar Veeramally 7aff94dc5a net: ipv6: Separate IPv6 fragment functionality
No functionality changes. Just moved IPv6 fragment and related functions
to ipv6_fragment.c for better readability

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-17 17:01:54 +03:00
Ravi kumar Veeramally 8ddb3ba360 net: ipv6: Separate IPv6 MLD functionality
No functionality changes. Just moved IPv6 MLD and related functions
to ipv6_mld.c for better readability.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-17 17:01:54 +03:00
Ravi kumar Veeramally 58f3e18301 net: ipv6: Separate IPv6 Neighbor functionality
No functionality changes. Just moved IPv6 neighbor and related functions
to ipv6_nbr.c for better readability.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-17 17:01:54 +03:00
Ravi kumar Veeramally 51aa291f2c net: ipv6: Centralize ND reachable timeout through one k_delayed_work
Each IPv6 neighbor entry had a k_delayed_work to be used as a timer to
send ND reachable message and waiting for the reply in order to get to
the neighbor details.

But k_delayed_work is not a small object (40 bytes). Thus reworking the
IPv6 ND reachable request timer by having one central k_delayed_work
and a timestamp in every IPv6 neighbor data entry properly handled at
every timeout.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-17 17:01:54 +03:00
Ravi kumar Veeramally e300275185 net: ipv6: Centralize IPv6 send NS timeout through one k_delayed_work
Each IPv6 neighbor entry had a k_delayed_work to be used as a timer to
send NS message and waiting for the NS reply in order to get to the
neighbor details.

But k_delayed_work is not a small object (40 bytes). Thus reworking the
IPv6 send NS request timer by having one central k_delayed_work and
a timestamp in every IPv6 neighbor data entry properly handled at every
timeout.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-17 17:01:54 +03:00
Jukka Rissanen eeabc2ba3d net: if: Lower ram usage for IP address lifetime handling
Instead of having one delayed_work struct / IP address, use
only one delayed_work struct for lifetime timer. This saves
over 20 bytes / allocated address struct.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-17 13:36:59 +03:00
Oleg Zhurakivskyy 99dc5aef88 net: ip: Refactor usage of net_sprint_ip*()
Refactor usage of net_sprint_ip*() where multiple
invocations are needed per single log call.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-17 12:36:50 +03:00
Oleg Zhurakivskyy 9d7711f029 net: ip: Redirect net_sprint_ipv*_addr() invocations
Redirect net_sprint_ipv*_addr() invocations into net_sprint_addr().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-17 12:36:50 +03:00
Oleg Zhurakivskyy 37837f5be3 net: ip: Add net_sprint_addr()
The intention is to clean up the usage of net_sprint_ipv*_addr()
functions where 2 or 3 invocations are needed.

Thus, the default number of buffers is 3.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-17 12:36:50 +03:00
Oleg Zhurakivskyy 1a7e365f8b net: ip: Remove unused function
This is a preparation to refactor net_sprint_ip*().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-17 12:36:50 +03:00
Flavio Ceolin 0866d18d03 irq: Fix irq_lock api usage
irq_lock returns an unsigned int, though, several places was using
signed int. This commit fix this behaviour.

In order to avoid this error happens again, a coccinelle script was
added and can be used to check violations.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-08-16 19:47:41 -07:00
Daniel Egger d66e8077ce net/dhcpv4: Use new net_pkt_append_memset() function
Thise uses the new net_pkt_append_memset() function to generate the
required zero filling instead of calling net_pkt_append_u8() in loops.

Fixes #9287

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2018-08-16 10:35:01 +03:00
Daniel Egger 5d3bc8b3d8 net: pkt: Added new function net_pkt_append_memset() to prefill packet
Some locations like DHCPv4 client create a prefilled packet by appending
new fragments in a loop with one byte each via net_pkt_append_u8() which
is wasteful and noisy. This patch adds the new functions
net_pkt_append_memset() which creates fragments as needed in the desired
size and initialises it to the specified value.

This change also adds a unittest for the new function.

Prerequisite for #9287

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2018-08-16 10:35:01 +03:00
Ruslan Mstoi afa0e0026f net: ipv6: Fix crash from fragmented packets
Echo server crashes upon reception of fragmented packets. This
occurs when fragmentation is enabled with the default prj.conf
of echo server. The cause is that by default with logs disabled
net_sprint_ipv6_addr returns NULL.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-08-15 23:49:24 +03:00
Ulf Magnusson 14b4084d88 net: rpl: Kconfig: Fix 'Network type' choice default
The 'Network type' choice always defaulted to NET_RPL_L2_ANY, because
choices prefer the first default with a satisfied condition (this was
true even when Zephyr still had the prefer-later-defaults patch).

Swap the defaults so that NET_RPL_L2_IEEE802154 becomes the default if
NET_L2_IEEE802154 is enabled, as intended.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-14 13:43:11 -07:00
Jukka Rissanen 7c7cfdda50 net: core: Always have a timeout when allocating a net_buf
Instead of waiting forever for a network buffer, have a timeout
when allocating net_buf. This way we cannot left hanging for a
long time waiting for a buffer and possibly deadlock the system.
This commit only adds checks to core IP stack in subsys/net/ip

Fixes #7571

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-14 12:17:00 +03:00
Tedd Ho-Jeong An 8b1f966b12 net: tcp: Handle RST packet when multiple flags are set
After it sends SYN_ACK, there is a case that the client sends the packet
with both ACK and RST bits are set, and this packet needs to be handled
if the packet is valid.

   CLIENT                 SERVER
   ------                 ------
     |--------- SYN -------->|
     |<------ SYN_ACK -------|
     |------- ACK_RST ------>|
     |--------- SYN -------->|
     |<-------- ??? ---------|

This patch checks the RST bits even if other flags are set and process
the packet.

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2018-08-13 15:23:18 +03:00
Ravi kumar Veeramally 0aa437a16c net: ipv6: Fix regression in IPv6 cleanup
IPv6 cleanup patch introduced a regression. Misunderstood the logic.
Do not drop the packet if packet does not have ND options, just skip.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-13 14:41:34 +03:00
Oleg Zhurakivskyy ac92a01f5a net: ipv6: Refactor IPv6 header length handling
Change the length to uint16_t and work with it
through standard htons/ntohs() macros.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-13 13:53:14 +03:00
Ravi kumar Veeramally 7d55b7f11a net: icmpv4: Simplify the flow at net_icmpv4_get/set_xxx() calls
Instead of reading or writing different icmpv4 header's individual
variables, better to read or write whole struct at a time. This
minimizes the calls to net_frag_read() or net_frag_write().
changes also removed slow and fast paths. Changes should optimize
the total flow.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-13 13:52:57 +03:00
Ulf Magnusson ec3eff57e0 Kconfig: Use the first default with a satisfied condition
Up until now, Zephyr has patched Kconfig to use the last 'default' with
a satisfied condition, instead of the first one. I'm not sure why the
patch was added (it predates Kconfiglib), but I suspect it's related to
Kconfig.defconfig files.

There are at least three problems with the patch:

  1. It's inconsistent with how Kconfig works in other projects, which
     might confuse newcomers.

  2. Due to oversights, earlier 'range' properties are still preferred,
     as well as earlier 'default' properties on choices.

     In addition to being inconsistent, this makes it impossible to
     override 'range' properties and choice 'default' properties if the
     base definition of the symbol/choice already has 'range'/'default'
     properties.

     I've seen errors caused by the inconsistency, and I suspect there
     are more.

  3. A fork of Kconfiglib that adds the patch needs to be maintained.

Get rid of the patch and go back to standard Kconfig behavior, as
follows:

  1. Include the Kconfig.defconfig files first instead of last in
     Kconfig.zephyr.

  2. Include boards/Kconfig and arch/<arch>/Kconfig first instead of
     last in arch/Kconfig.

  3. Include arch/<arch>/soc/*/Kconfig first instead of last in
     arch/<arch>/Kconfig.

  4. Swap a few other 'source's to preserve behavior for some scattered
     symbols with multiple definitions.

     Swap 'source's in some no-op cases too, where it might match the
     intent.

  5. Reverse the defaults on symbol definitions that have more than one
     default.

     Skip defaults that are mutually exclusive, e.g. where each default
     has an 'if <some board>' condition. They are already safe.

  6. Remove the prefer-later-defaults patch from Kconfiglib.

Testing was done with a Python script that lists all Kconfig
symbols/choices with multiple defaults, along with a whitelist of fixed
symbols. The script also verifies that there are no "unreachable"
defaults hidden by defaults without conditions

As an additional test, zephyr/.config was generated before and after the
change for several samples and checked to be identical (after sorting).

This commit includes some default-related cleanups as well:

  - Simplify some symbol definitions, e.g. where a default has 'if FOO'
    when the symbol already has 'depends on FOO'.

  - Remove some redundant 'default ""' for string symbols. This is the
    implicit default.

Piggyback fixes for swapped ranges on BT_L2CAP_RX_MTU and
BT_L2CAP_TX_MTU (caused by confusing inconsistency).

Piggyback some fixes for style nits too, e.g. unindented help texts.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-10 12:38:28 -07:00
Marcin Niestroj 6521b9e4fa net: tcp: Fix net_buf leak in case of low available net_buf count
This net_buf leak happends when we are low on available net_buf
count. During TCP segment preparation we do allocate IP header
successfully, but we fail to allocate TCP header. In such case
pkt->frags is not NULL anymore (it contains IP header), but we
override it during TCP header allocation error path. This results
in net_buf containing IP header to never be deallocated, because
it does not belong to any net_pkt anymore.

Use net_pkt_frag_add() function to add tail for future net_pkt
deallocation, instead of assigning tail to pkt->frags pointer.

Fixes: c6407659f3 ("net: tcp: Add the frag back to caller allocated
  net_pkt")
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2018-08-10 13:38:08 +03:00
Ravi kumar Veeramally 06c4a9504f net: icmpv6: Simplify the flow at net_icmpv6_get/set_xxx() calls
Instead of reading or writing different icmpv6 header's individual
variables, better to read or write whole struct at a time. This
minimizes the calls to net_frag_read() or net_frag_write().
changes also removed slow and fast paths. Changes should optimize
the total flow.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-10 12:53:59 +03:00
Ravi kumar Veeramally c8b589045d net: ipv6: Fix memory leak
IPv6 fragmentation splits the packet into two parts, one is header
and another is payload. Every time header is cloned and part of
payload is appended. At the end original header packet is not freed.
Causes memory leak.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-09 16:25:52 +03:00
Ravi kumar Veeramally bfa7516851 net: Do not set appdata on a cloned packet
Current implementation only considers IP header length while setting
appdata value on a cloned packet. It will give bogus value if original
packet contains extension headers and if extension headers are large
(i.e. more than one fragment). Only consider appdata length from the
original packet.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-09 16:25:52 +03:00
Oleg Zhurakivskyy fbac80bb94 net: ipv4: Refactor IPv4 header length handling
Change the length to uint16_t and work with it
through standard htons/ntohs() macros.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-09 16:25:17 +03:00
Oleg Zhurakivskyy 33e06441ba net: ipv4: Minor refactoring
Trivial refactoring, no functionality changes.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-09 16:25:17 +03:00
Jukka Rissanen d003d0e6a6 net: ipv4: Corrupted ARP pkt was sent instead of real IPv4 pkt
The ethernet sending routine sent a corrupted ARP packet instead
of the actual IPv4 packet.

Fixes #9348

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-09 11:56:44 +03:00
Jukka Rissanen f39ff76ced net: if: Do not inline net_if_ipv6_addr_lookup_by_iface()
No need to inline the net_if_ipv6_addr_lookup_by_iface() function
as it is used multiple times in ipv6.c

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 14:54:27 +03:00
Jukka Rissanen d0205693ae net: if: Add net_if_select_src_iface() function
Add a function which returns proper network interface to send either
IPv4 or IPv6 network packet to corresponding destination address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 14:54:27 +03:00
Jukka Rissanen b8fdf3c67a net: if: Add net_if_ipv6_select_src_iface() function
Add a function that will return the network interface that would
be used when sending a IPv6 network packet to specific IPv6 destination
address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 14:54:27 +03:00
Tomasz Gorochowik e75b607131 net: Fix credit-based shaper typos
The same typo copied to two places, do a: s/sharper/shaper/

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-08 13:01:37 +03:00
Jukka Rissanen 1f855095b4 net: l2: Add promiscuous mode to L2 flags when applicable
This allows more bearers than just ethernet to have promiscuous
mode support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jukka Rissanen 66244a0e67 net: if: No need to always join solicit node mcast group
For example for Bluetooth IPSP, it is not needed to join solicited
node multicast group address.

From https://tools.ietf.org/html/rfc7668#section-3.2.2 :

"""
There is no need for 6LN to join the solicited-node multicast address,
since 6LBR will know device addresses and hence link-local addresses
of all connected 6LNs.
"""

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jukka Rissanen ccfcdabaf6 net: l2: Add flags to tell if L2 supports multicast
If multicast is not supported, then we do not need to join
multicast group.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jesus Sanchez-Palencia 598276262c net: l2: Add support for Link Layer Discovery Protocol (LLDP)
The LLDP protocol defines 2 separate agents, the Transmitters and
the Receivers. For the context of Zephyr, we are only interested in
the Tx agent, thus we drop any LLDP frames received by Zephyr.

LLDP frames are basically composed by an ethernet header followed by
the LLDP Protocol Data Unit (LLDPDU). The LLDPDU is composed by several
TLVs, some of them being mandatory and some optional.

Our approach here is having TLVs fully configured from Kconfig, thus
having the entire LLDPDU constructed on build time.

The commit adds NET_ETH_PTYPE_LLDP definition and related handling.

If CONFIG_NET_LLDP is enabled then ethernet_context has a pointer to
the struct net_lldpdu that belongs to that ethernet interface. Also
when CONFIG_NET_LLDP is enabled, the LLDP state machine will start to
send packets when network interface is coming up.

Currently the LLDP state machine is just a k_delayed_work() sending the
LLDPDU at a given period (defined by CONFIG_NET_LLDP_TX_INTERVAL).

Fixes #3233

Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 09:53:24 +03:00
Jukka Rissanen 2ff503b7c8 net: shell: Check strtol() conversion errors
Make sure that string to integer conversions are checked properly
so that we are not trying to use the return value from strtol()
if the string is not a number.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-06 14:21:26 +03:00
Michael Scott db577f00b1 net: buf: add linearize, append_bytes and skip APIs to net_buf
This change moves the logic for linearize and append_bytes from
the net_pkt sources into the net_buf sources where it can be
made available to layers which to not depend on net_pkt.  It also,
adds a new net_buf_skip() function which can be used to iterated
through a list of net_buf (freeing the buffers as it goes).

For the append_bytes function to be generic in nature, a net_buf
allocator callback was created.  Callers of append_bytes pass in
the callback which determines where the resulting net_buf is
allocated from.

Also, the dst buffer in linearize is now cleared prior to copy
(this was an addition from the code moved from net_pkt).

In order to preserve existing callers, the original functions are
left in the net_pkt layer, but now merely act as wrappers.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-06 10:43:46 +03:00
Tomasz Gorochowik 126602ac43 net: tc: Add other priority to traffic class mappings
This commits adds new priority to traffic class mappings and allows
users to choose which mapping to use through menuconfig.

The new mappings are recommended in 802.1 (chapter 34.5) for
time-sensitive applications supporting the credit-based sharper
algorithm.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-06 10:23:57 +03:00
Tomasz Gorochowik c0487a0608 net: tc: Fix priority to traffic class mappings
Priority 0 is the default, but 1 is the lowest. See 802.1Q tables I-1
and I-2.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-06 10:23:57 +03:00
Florian Vaussard 1f23d2681f ip: route: disable LL address check when using dummy L2
The dummy L2 does not setup the link layer address. Do not check the
source and destination link layer addresses when routing packets
otherwise packet routing will not work when using a dummy L2.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-02 16:42:47 +03:00
Jonathan Yong dd88711a69 net: eth: Vendor specific statistics
Allows ethernet drivers to provide vendor specific statistics
and details in the form of key-value pairs with the name of
the staticstic and its value.

The new string tables will be behind a new config:
	NET_STATISTICS_ETHERNET_VENDOR

Suggested-by: Jukka Rissanen <jukka.rissanen@intel.com>
Signed-off-by: Jonathan Yong <jonathan.yong@intel.com>
2018-08-02 12:42:27 +03:00
Ulf Magnusson d1684a83a4 Kconfig: Clean up some symbol definitions
- Remove redundant 'n' defaults. 'n' is the default value for bool
  symbols.

  This makes the auto-generated documentation clearer as well: You get
  "implicitly defaults to n" instead of
  "- n if <propagated dependencies>".

- Shorten

      <type>
      prompt "foo"

  to

      <type> "foo"

  This works for all types, not just bool.

- Various formatting nits.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-01 12:47:17 -04:00
Tomasz Gorochowik 805e2f2c79 net: eth: mgmt: Merge 802.1Qav related mgmt requests
There are too many individual requests for Qav related parameters. There
are more Qav parameters that need to be supported (and will be supported
soon - both on the GET and SET side). Handling it the way it was handled
so far would render the eth mgmt API dominated by Qav parameters. That
would make the file hard to read and understand.

Instead of that - use a single GET and SET requests for all Qav
parameters. This works by adding a separate enum with Qav request type
to the ethernet_qav_param struct.

Additionally this approach makes it much easier to document it all since
we now have just a single request and documentation comments in the
ethernet_qav_param struct.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-01 15:58:05 +03:00
Jukka Rissanen 528f7f8f2b net: shell: Print supported features for ethernet interfaces
Print information about supported hardware capabilities for
ethernet interfaces when executing "net iface" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-01 11:26:35 +03:00
Tomasz Gorochowik cb3f30a0c9 net: shell: print info about priority queues
If ethernet mgmt is enabled and the driver supports priority queues,
show info about them including the Qav status
(enabled/disabled/unsupported).

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-31 17:54:24 +03:00
Jukka Rissanen 00e37cbb5b net: IPv4 link local support
Add basic IPv4 Link Local support as described in RFC 3927.

Signed-off-by: Matthias Boesl <matthias.boesl@gmail.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-31 16:34:28 +03:00
Tomasz Bursztyka 2ba28dd78c net/dhcpv4: Unify timeout management in a unique k_delayed_work
This reduces memory overhead on net_if_dhcpv4: 16 bytes vs 120 bytes
before. This might proove to be beneficial when there are many network
interface.

dhcpv4 ROM consumption is now 2132 bytes vs 4224 (many switches removed)

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 11ccf36aa1 net/dhcpv4: Cleanup debug messages
No need to use PRIxxx primitives.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka bb6b2769ab net/dhcpv4: Tiny style fixes
Empty line before if (unless test uses previous line assignment) and
after } (unless it's another } ...)

Indentation fixed as well.

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 502912acf5 net/dhcpv4: Reuse generic IPv4 function relevantly
No need to recreate the IPv4 header code here, nor the checksum etc...

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 6d74e26245 net/dhcpv4: Reorder variable declaration
- Pre-assigned are always coming first.
- Always declare at the beginning of a code block

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 3d5876d4a8 net/dhcpv4: Rename functions to follow domain related naming rules
dhcpv4_ for static ones, net_dhcpv4_ for exported ones.

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 09233e6929 net/dhcpv4: Move definitions to header
As done everywhere else.

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Léonard Bise a691cc8159 net: ipv6: Fix memory leak caused by NS request failure
When an echo request is sent to an unknown neighbor, a Neighbor
Solicitation request is sent, however if the source address
cannot be determined the NS request is dropped but the pending
packet is not freed.

Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
2018-07-26 13:56:32 +03:00
Jukka Rissanen 9b8c83f44a net: Avoid holes in structs
Move struct members around in networking code so that we avoid
unnecessary holes inside structs. No functionality changes by
this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-25 15:20:34 +03:00
Tomasz Bursztyka 9bb56cc6b9 net/icmpv4: Rename static function with icmpv4_ prefix
Static ones with that prefix, exported ones with net_icmpv4_ prefix.

Fixes #8720

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka ea5610af0a net/icmpv4: src ll address does not need to be set
net if core code will do it.

Fixes #8720

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka be6f59d322 net/icmpv4: Checksum is always set to 0 prior to being calculated
Through net_icmpv4_set_chksum()

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka b89f127f01 net/icmpv4: Use generic IPv4 relevantly
Avoiding to re-create the IPv4 header into ICMPv4 code directly.

Fixes #8720

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka abf68bc5ea net/ipv4: Remove useless return value
net_ipv4_finalize is always successful.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka a38dc0914f net/ipv4: Remove ifdefs and use IS_ENABLED instead
Reduces the logic as well as the ipv4 header checksum needs to be
computed either way.

Fixes #8720

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka df4325a9b8 net/ipv4: Remove useless proto field setting in ipv4 header
No need to initialize it to 0 as it will be set through given parameter.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Jukka Rissanen fbbef6f436 net: stats: Simplify periodic statistics printing
Use modular arithmetic in statistics prints so that wraparounds are
automatically handled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 09:20:46 -04:00
Jukka Rissanen 36ab41df79 net: shell: Print information about promiscuous mode
If the network interface is in promiscuous mode, print information
about it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 15:12:37 +03:00
Jukka Rissanen 3f9c7bd159 net: Add promiscuous mode support
Allow user to set the network interface into promiscuous mode
and then receive all the network packets that are received by
that interface.

Fixes #7595

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 15:12:37 +03:00
Jukka Rissanen b19cb207cb net: if: Add promiscuous mode set / unset functionality
User is able to set the network interface to promiscuous mode
and query the promisc mode status.

Note that currently this is only supported for ethernet bearer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 15:12:37 +03:00
Ravi kumar Veeramally 3fafe4f9ad net: ipv6: Handle large IPv6 packets properly
Current implementation does not handle large extension headers
(e.g HBHO). Which resulted network stack crashes or due to
misinterpretation of lengths network packets are dropped. Also
caused issues while preparing IPv6 packet (e.g. large HBHO header
with IPv6 fragmentation support).

Issues fixed and provided more unit tests.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-07-23 15:01:09 +03:00
Jukka Rissanen 7f0432a114 net: utils: Check null pointer when parsing IPv6 address
We might access NULL pointer if strchr() return value is not
checked properly.

Coverity-CID: 187073
Fixes #8993

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-20 00:02:01 -04:00
Jukka Rissanen 0251a9f140 net: ipv6: Fix NA debug print
If Neighbor Advertisement cannot be sent, then print info about it.
Earlier we printed info when NA succeeded.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-18 13:01:04 -04:00
Ulf Magnusson 53c5058d6e net: ip: kconfig: Simplify NET_RX_STACK_RPL definition
A condition can be but on a prompt to make a symbol conditionally
user-assignable (visible).

Kconfig note:

'default's don't care whether the symbol is visible (has a prompt with a
satisfied condition) or not. 'if'/'depends on' just puts the same
condition on all the properties, disabling both the defaults and the
prompt at the same time. That might make it look like they're connected.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-16 21:03:27 -04:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
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.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Jukka Rissanen cb00061cbe net: dhcpv4: Use less parameters in debug print
Having 24 parameters in a debug print is a bit extreme especially
as it is causing warning from new logger. Split the debug print
to three pieces each having 8 parameters which is more reasonable.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-10 12:37:31 +03:00
Jukka Rissanen 48802024f2 net: icmpv4: Set the ICMPv4 header correctly
The code did not check if the icmpv4 header struct is already
pointing to net_buf or not. This meant that the code did not
set the ICMPv4 options and types correctly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-05 15:44:49 +03:00
Walter Xie 354c50e8ed net: add bound checking in net_addr_pton()
The net_addr_pton() did not check the number of ":" characters properly.
For example with following net-shell input
net ping fe80::210:2030:9b:d48efe80::210:2030:9b:d48e
the kernel panics.

Signed-off-by: Walter Xie <41377148@qq.com>
2018-07-05 14:17:23 +03:00
Tomasz Gorochowik 2ca3b1e3c4 net: if: Fix TX timestamp callbacks invocation
The problem is that net_if_call_timestamp_cb only checked if the
callback was registered for the PORT which invoked the whole action.

There is a possibility, that the callback will be registered, and packet
A will be passed to eth driver. Before the driver is finished with
packet A, network layer will start handling another packet (B) - so it
will unregister the callback for packet A and register it for B. After
that the network driver will finish processing packet A and invoke the
timestamp callback. The mechanism would then only check if a callback is
registered for the port of the driver and invoke the callback for the
packet that was registered earlier (so A instead of B).

This commit fixes that by storing info not only about the port but about
the packet too.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik b51f1ccce8 net: gptp: Fix validation of non-numeric inputs from net shell
The shell did not check if the gptp port (command argument) is numeric.
Add that check before executing the port info functions.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00