Commit graph

1749 commits

Author SHA1 Message Date
Jukka Rissanen 06b500b6bd net: sockets: can: Close the socket cleanly
If the socket is closed, then do CAN detach if that is needed.
This way the CAN interrupts are not received if there are no
CAN sockets listening the data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-18 17:58:00 +03:00
Jukka Rissanen 7e37fd7203 net: connection: The connection logic was not init properly
We need to initialize the connection.c for UDP, TCP, PACKET socket
and CANBUS sockets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-18 17:58:00 +03:00
Jukka Rissanen 1e98928424 net: shell: Print connection information properly for AF_CAN
CANBUS socket information was just printing unknown information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-18 17:58:00 +03:00
Jukka Rissanen 0032f68669 net: context: Set local address properly for AF_CAN connections
At the moment there is no real address for local CANBUS socket,
but we can still set protocol family of local socket to AF_CAN
so that for example net-shell "net conn" command can show
information about it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-18 17:58:00 +03:00
Jukka Rissanen 6621491014 net: sockets: can: Add dispatcher
We need to dispatch the received CAN frame if there are multiple
sockets interested in the same CAN-IDs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-18 17:58:00 +03:00
Jukka Rissanen bf0f52dc4c net: nbr: Set the link address type when saving neighbor data
The neighbor cache did not contain link address type. This is not
causing problems atm but good to fix anyway.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-13 19:47:31 +03:00
Jukka Rissanen d20c6f96e6 net: utils: Print pkt address in net_pkt_hexdump()
It is useful in debugging if net_pkt pointer value is printed
in net_pkt_hexdump().

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-13 19:46:54 +03:00
Jukka Rissanen 343bdd3e3a net: if: Fix null pointer deref when selecting IPv4 address
It is possible that iface is NULL when selecting IPv4 destination
address for a sent packet.

Coverity-CID: 198877
Fixes #16570

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-12 14:50:38 -04:00
Anas Nashif 4c32258606 style: add braces around if/while statements
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-06 15:20:21 +02:00
Tomasz Bursztyka e9a4ef2b0a net/udp: Always drop IPv6 UDP packet if checksum field is 0
Missing checksum is only valid in IPv4 and only on certain context.

Fixes #16483

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-30 13:02:25 +08:00
Tomasz Bursztyka a5b90a4aad net/udp: Check UDP header's length attribute
Length should be at least of UDP header size but not bigger than actual
payload size.

Reported-by: Ruslan Mstoi <ruslan.mstoi@intel.com>

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-30 13:01:30 +08:00
Tomasz Bursztyka 274db4f33d net/udp: Accept UDP packet with missing checksum
Having a checksum of zeros in UDP means "missing checksum" and is a
valid case as per RFC 768:

"An all zero transmitted checksum value means that the transmitter
generated no checksum (for debugging or for higher level protocols
that don't care)."

Such support is made possible by adding a new Kconfig option named
CONFIG_NET_UDP_MISSING_CHECKSUM.

However, that is valid only for IPv4. For IPv6, see the RFC 2460
section 8.1:

"Unlike IPv4, when UDP packets are originated by an IPv6 node, the UDP
checksum is not optional."

So the UDP checksum will always be verified in IPv6.

Fixes #16375

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-27 20:58:53 +08:00
Tomasz Bursztyka 770625826c net/udp: Computed checksum field should not be 0
From RFC 768, in "Fields":
"If the computed  checksum  is zero,  it is transmitted  as all ones"

Fixes #16379

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-27 20:58:53 +08:00
Jukka Rissanen ecac10cb47 net: shell: Refactor help information for ping command
Do not always print general help for ping cmd. Only if user supplies
'-h' or '--help' command, print information about the parameters.
After this the generated HTML documentation looks better for the
ping command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-23 22:12:23 +03:00
Jukka Rissanen d13039f80f net: shell: Remove leading underscore from parse_args()
The leading underscore in function names should not be used
because of Misra rules.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-23 22:12:23 +03:00
Jukka Rissanen 29b55f860e net: shell: Indentation fixes for ping command
Fix the indentation of code for the ping command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-23 22:12:23 +03:00
Jukka Rissanen 6f79b019c4 net: if: Select global IPv4 address if needed
The net_if_ipv4_select_src_addr() should return global address
in the interface if nothing else is being found.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-21 15:37:53 +03:00
Tomasz Bursztyka 426764ebcf net/iface: Add a function to get IPv4 global address
As for IPv6, let's create the same function on IPv4 side.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-21 15:37:53 +03:00
Tomasz Bursztyka 979aedfab4 net/iface: Modify function to get IPv6 global address
Let's filter out on a state parameter.

There is no impact as this function is not used anywhere yet.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-21 15:37:53 +03:00
Jukka Rissanen 60cb25d198 net: ipv4: Send multicast ICMPv4 reply with correct src address
If we receive a multicast ICMPv4 packet, then send the reply back
with correct source address and not with multicast address.

Fixes #16257

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-21 15:37:53 +03:00
Jukka Rissanen b800737f72 net: ipv4: Allow UDP packets with broadcast dst address
Make sure we are able to receive UDP packets with broadcast
destination address. If CONFIG_NET_IPV4_ACCEPT_ZERO_BROADCAST
is set, then check here also non-standard broadcast address
that is described in RFC 1122 chapter 3.3.6.

Fixes #11617

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-20 14:11:11 +03:00
Sebastian Bøe c2c8c849b6 cmake: Don't have users call zephyr_link_interface on mbedTLS
Libraries that use mbedTLS have been invoking
zephyr_link_interface(mbedTLS). It is not clear what the intent of
this code has been, but it is redundant with the mbedTLS build
scripts, so it can be safely removed.

In addition to being redundant, it causes problems as it introduces an
ordering dependency, with this code mbedTLS must be declared before
users of mbedTLS are declared. Since this code is redundant, this
ordering dependency is also unnecessary.

This code is believed to have been added early on by accident and
copied through cargo-cult programming since.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-05-11 08:35:26 -04:00
Robert Lubos 2de06b4b3c net: Avoid calling L2 functions on offloaded interface
Calling functions like `net_if_start_dad`, `join_mcast_nodes` or
`net_if_start_rs` lead to L2 API function calls, which is not correct
for offloaded interfaces and leads to a crash. This is especially
problematic, as they are called in the default configuration.

Avoid calling these functions while an offloaded interface is brought up
by adding extra jump label.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-05-10 10:07:26 +03:00
Robert Lubos cd07a30c51 net: Allow to disable native IP stack with socket offloading
In case socket offloading is used, one might want to disable native IP
stack, both IPv4 and IPv6, to save memory. Currently it is not possible
due to preprocessor check. Prevent that by adding additional exception
for socket offloading.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-05-10 10:07:05 +03:00
Jukka Rissanen 9a6bbbfb69 net: Check device driver API pointer
It is possible that the device driver API pointer is null.
For example if the device driver returns an error, the device
code will make the API pointer NULL so that the API would not
be used. This can cause errors in networking code where we
typically do not check the NULL value.

Fixes #15003

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-07 15:41:15 +03:00
Tomasz Bursztyka 9a6e3012da net/connection: Final cleanup
- renaming functions to better names
- reordering functions place (register, then unregister for instance)
- centralizing logs to relevant place

Fixes #8722

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-07 15:40:53 +03:00
Tomasz Bursztyka d652a1e809 net/connection: Merge rank bits into flags attribute
Also, there is no need for unspecified address bit. If specified address
bit is not set, then it will be obvious address is unspecified. Reducing
the amount of bits from 6 to 4.

This permits to reduce net_conn structure of 4 bytes. Its size is as
before indroducing node attribute.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-07 15:40:53 +03:00
Tomasz Bursztyka d85aabe2a6 net/connection: Use slist to manage used/unused connections
This will optimize path when unused an connection is required or when
looking up a used one.

That said, at this stage, it bloats up the net_conn structure with 4
added bytes. More optimization will overcome this drawback.

Fixes #8722

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-07 15:40:53 +03:00
Tomasz Bursztyka de6fd24e96 net/connection: Reduce usage of #ifdef
Most of present #ifdef can be removed via using IS_ENABLED() macro.

Only small part of cache related logic still require #ifdef.

Fixes #8722

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-07 15:40:53 +03:00
Tomasz Bursztyka b2b21412ae net/connection: Removing cache feature
There were various flaws in it that motivated its removal:

- No hash collision handling mechanism. In case that would happen, the
behavior of the network connection would be unknown. This is the main
drawback
- The lookup is not that much more efficient than the default one. The
only difference of gain is in connection comparison (a u32t comparison
vs a full connection compare). But the list handling is the same. It's
made worse by the presence of a negatives match array which can be
easily filled in and becomes then fully usless, appart from consuming
CPU. As well as adding a new connection: it requires the whole cache
to be cleared which is unefficient.
- Not memory efficient, even compared to a proper hash table.
Two arrays instead of one etc...

All of this could be fixed by using a proper hash table, though it
remains to be seen if such object could fit in Zephyr core.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-07 15:40:53 +03:00
Tomasz Bursztyka dea1cdfdea net/context: Reordering some ipv4/6 logic to follow all other places
During net_pkt/net_context API changes, some ip handling blocks were
ordered ipv4 first, ipv6 second. While it is the contrary everywhere
else. So reordering to get things consistent.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-07 15:40:33 +03:00
Tomasz Bursztyka 6fee12619f net/context: Reduce the usage of #ifdef/#endif
- Not all #ifdef can be removed: those which have a dedicated attribute
in struct net_context.
- For CONFIG_NET_CONTEXT_CHECK: switching the NET_ASSERT_INFO to
NET_DBG (simpler to read and anyway an error code is returned)

Fixes #8725

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-07 15:40:33 +03:00
Luiz Augusto von Dentz 95cadb7bfe net: bt: Add multi-link support
This adds support for having multiple connections based on BT_MAX_CONN.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-07 11:16:29 +03:00
Jukka Rissanen 3d8fe9a8fa net: core: In RX check if the pkt is for loopback interface
If the loopback driver is enabled, then the packet might come
from localhost in which case mark it properly. Without this marking
the packet from/to 127.0.0.1 or ::1 would be dropped in later checks.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-04-30 09:56:01 -07:00
Ravi kumar Veeramally 543eecb9a5 net: shell: Add VLAN tag stripping to capabilites
VLAN tag stripping flag added to ethernet_capabilities
print in net shell.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-04-26 10:46:27 +03:00
Ravi kumar Veeramally 25309eb356 net: ipv6: Trivial changes in fragmentation debug
Values are misleading when debugging IPv6 fragmentation.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-04-26 10:45:45 +03:00
Benjamin Valentin 812b999731 net: shell: Improve the output of the ping function
Report rtt, ttl and rssi if available.

Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
2019-04-26 09:05:14 +03:00
Benjamin Valentin 7c09695344 net/icmpv6: Allow for arbitrary payload data in ICMP echo
Allow for including arbitrary data in net_icmpv6_send_echo_request()
that will be echoed verbatim by the receiver.

This allows to use ICMP echo for diagnostic use cases, e.g. by testing
packet framentation (large payload) or measuring round-trip-time.

Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
2019-04-26 09:05:14 +03:00
Benjamin Valentin dd65cfb533 net/icmpv4: Allow for arbitrary payload data in ICMP echo
Allow for including arbitrary data in net_icmpv4_send_echo_request()
that will be echoed verbatim by the receiver.

This allows to use ICMP echo for diagnostic use cases, e.g. by testing
packet framentation (large payload) or measuring round-trip-time.

Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
2019-04-26 09:05:14 +03:00
Benjamin Valentin b938324345 net/icmpv4: Include icmp_hdr in callback
Allow accessing already parsed information from the ICMP header
that callbacks might be interested in.

This makes the callback signature and behaviour match that of
the ICMPv6 implementation.

Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
2019-04-26 09:05:14 +03:00
ling wei cdebd81994 net: trickle: Re-init trickle timer for multiple triggerings
We need to re-initialize the trickle->timer delayed work to use
trickle_timeout() if there are multiple triggerings.

Fixes #15606

Signed-off-by: ling wei <lingwei@cisco.com>
2019-04-24 12:54:48 +03:00
Jukka Rissanen 3633951652 net: if: Only start the network interface during init if needed
If the NET_IF_NO_AUTO_START network interface flag is set, then
do not take network interface up during the initialization of the
network interface. The network device driver can set the flag in its
network interface initialization function if needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-04-23 13:11:03 +03:00
Jukka Rissanen 712103d594 net: if: Add access functions for network interface flags
Provide access functions for manipulating network interface flags.
There is no need for the caller of this API to know about the inner
details of the flags.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-04-23 13:11:03 +03:00
Patrik Flykt 91ca8aabc8 net/ip/dhcpv4: Set source IP address in DHCP Request
The source address in unicast DHCPv4 Request packets was found out
to be all zeros address 0.0.0.0. This address is only acceptable if
the destination is a multicast one, where the host in question is
acquiring a DHCP address lease. This is true for the DHCP Discover
and the initial DHCP Request message from the client towards the
server. As subsequent DHCP Request renewal messages are sent as
unicast to the server, the server will drop such packets.

Fix this issue by explicitely specifying what source IP address is
to be used, if none is specified, the all zeros address 0.0.0.0 is
used in multicast addresses. The source address in the other
unicast cases is identical to the 'ciaddr' in the DHCP message.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-17 10:35:38 -05:00
Alexander Wachter c204f70540 net: increase mgmt event stack size
Increase the default mgmt event stack size from 512 to 768 because of
stack overflows.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-04-09 15:35:41 -04:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Andrew Boie 4e5c093e66 kernel: demote K_THREAD_STACK_BUFFER() to private
This macro is slated for complete removal, as it's not possible
on arches with an MPU stack guard to know the true buffer bounds
without also knowing the runtime state of its associated thread.

As removing this completely would be invasive to where we are
in the 1.14 release, demote to a private kernel Z_ API instead.
The current way that the macro is being used internally will
not cause any undue harm, we just don't want any external code
depending on it.

The final work to remove this (and overhaul stack specification in
general) will take place in 1.15 in the context of #14269

Fixes: #14766

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-05 16:10:02 -04:00
Patrik Flykt 4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Patrik Flykt 97b3bd11a7 drivers: Rename reserved function names
Rename reserved function names in drivers/ subdirectory. Update
function macros concatenatenating function names with '##'. As
there is a conflict between the existing gpio_sch_manage_callback()
and _gpio_sch_manage_callback() names, leave the latter unmodified.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Tomasz Bursztyka 16dd53b5a5 net/core: Initialize network services only after the stack
DNS is not part of L3, but as dhcpv4 or the net shell, it is a services
on top of the network stack. So let's gather all in a dedicated
function.

This also rework the order when starting the DNS service. There was an
issue for offload device: these would be fully initialized in
init_rx_queues() which was called after l3_init. l3_init had already
started dns: which would not be able to bind correctly, proving to be
fully dead afterwards. Instead, starting the dns at the very end
ensures that all is initialized properly from devices to stack.

Fixes #15124

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-04-03 09:32:39 -04:00
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