Commit graph

1749 commits

Author SHA1 Message Date
Alexander Wachter 35f01673ac net: l2: 6LoCAN implementation
This commit is an implementation of 6LoCAN, a 6Lo adaption layer for
Controller Area Networks. 6LoCAN is not yet standardised.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03:00
Jukka Rissanen 7c387a34ac net: context: Allow TCP to use sendmsg()
If sendmsg() is used for TCP sockets, the msghdr->msg_name is not
really used as the socket must already have been connected.
In that case just get the destination address directly from
net_context remote address field.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-08 09:44:50 +03:00
Ravi kumar Veeramally c8fa169294 net: Add support for SOCKS5 socket option
The SO_SOCKS5 socket option can be used by the application to
set the SOCKS5 proxy details. These details will be used when
connecting to peer.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-08-05 13:26:11 +03:00
Jukka Rissanen c4a692a85f net: ppp: Add proper support to receive Echo-Reply message
Currently only net-shell calls net_ppp_ping() command, so make
it return the amount of time that it took to receive Echo-Reply
so the net-shell can print the round trip time value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen 19a09bf553 net: pkt: Add net_pkt_read_le16() helper
We had a big endian helper but little endian one was missing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen 7ccc47de78 net: if: No need to set IP addresses etc for PPP
If the network interface is point-to-point one which does
not need IP address etc, then no need to start DAD etc for
those interfaces.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen 4a5543db25 net: shell: Add ppp network interface support
Print point-to-point network information properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen 4df61cd772 net: shell: Refactor network statistics printing
The traffic class printing section was too convoluted because of
many #ifdef's.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen f95938da0f net: ppp: Initial support for point-to-point protocol
This implements ppp L2 component, LCP and IPCP modules.

Fixes #14034

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Alexander Wachter 144dc592a6 net: ip: 6lo: Remove unnecessary net_buf allocation and memmove
This patch tries to avoid memmoves and buffer allocations when there
is enough space in the original buffer. Headers are still contiguous
but not in the same buffer.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-07-25 15:19:28 +03:00
Alexander Wachter f10da7b643 net: ip: 6lo (IPHC) uncompression rework
This is a rework of the 6lo IPHC uncompression.
The uncompression now tries to work in place on the original buffer
instead of allocation a new one. If there is not enough tail-room,
a new buffer is allocated and filled with the IP and maybe UDP header.
The compressed header is pulled from the original buffer and the
buffer is preserved.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-07-25 15:19:28 +03:00
Alexander Wachter 0261ecdee4 net: ip: net_pkt: Add pkt_cursor_advance before contiguous check
When net_pkt_skip skips the entire data in a net buffer, the cursor
still points to this buffer on data that is off by one.
Calling pkt_cursor_advance in net_pkt_is_contiguous fixes this and
moves the cursor to the next buffer.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-07-25 15:19:28 +03:00
Alexander Wachter 12e11b0451 net: ip: 6lo compression rework
This is a rework of the 6lo IPHC. The compression now works inline
on the original buffer instead of allocation a new one.
Additionally DAM_11 (Destination address fully elided) has precedence
over DAM_10 (16 bit compressible) now.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-07-25 15:19:28 +03:00
Jukka Rissanen 0435dce697 net: Add support for TXTIME socket option
The SO_TXTIME socket option can be used by the application to
tell the network device driver the exact moment when the
network packet should be sent.

This feature is also implemented in Linux.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-24 10:17:16 +03:00
Jukka Rissanen 390a6cf617 net: context: Add support for net_context_sendmsg()
After this we can implement BSD sendmsg() API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-24 10:17:16 +03:00
Jukka Rissanen a0865adf25 net: context: Use const for the IP address
We are not modifying the IP address and this is needed in next
commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-24 10:17:16 +03:00
Jukka Rissanen aaafb6abba net: pkt: Allow larger packets for IPv6 fragmentation
If the allocated net_pkt is larger than the network interface MTU,
then check if the IPv6 fragmentation is enabled and allow larger
net_pkt length as the IPv6 fragmentation will split the packet into
suitable parts.

Fixes #16354

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-23 15:40:27 +03:00
Jukka Rissanen ccba1036c5 net: ipv6: Fix fragmentation
The next header was not properly set in the de-fragmented
packet.

Fixes #16354

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-23 15:40:27 +03:00
Jukka Rissanen 0ec4341277 net: pkt: Move everything up when pulling data
The net_pkt_pull() needs to move all the remaining data in the
net_buf instead of just the pull amount.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-23 15:40:27 +03:00
Jukka Rissanen 3ebe60a3ba net: ip: Helper for getting used network address family as string
This helper can be used in debugging the used network address family.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-12 12:33:19 +03:00
Tomasz Bursztyka 845f070c1e net/ethernet: Cleanup a bit on the usage of ifdefs
ARP, LLDP and GPTP functions have dummies in case of being disabled so
let's use IS_ENABLED() accordingly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-10 15:24:32 +03:00
Tomasz Bursztyka 599450671d net/gptp: net_gptp_recv() dummy function needs to return a verdict
Since gptp is disabled in this case, let's return NET_DROP.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-10 15:24:32 +03:00
Jukka Rissanen 44d6838d2b net: ipv6: Drop pkt if src address is unspecified
If we receive IPv6 packet where source address is unspecified
(all zeros), then we need to drop it.

Fixes #17450

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-10 14:47:32 +03:00
Jukka Rissanen 868cd477d5 net: ipv4: Drop pkt if src address is unspecified
If we receive IPv4 packet where source address is unspecified
(all zeros), then we need to drop it.

Fixes #17427

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-09 21:02:27 +03:00
Tomasz Bursztyka d80d181d04 net/iface: Add IPv4 route find and add
Removing an IPv4 router was missing, as well as finding the default
router for an IPv4 address.

Note howevere that IPv4 router features are not used anywhere yet. But
at least the API is there and is a 1:1 to IPv6, if that matters.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka eccc268d0a net/iface: Rework how routers are handled
- router lifetime is always a u16_t so fixing
net_if_ipv6_router_update_lifetime() signature.
- Coalescing router timers into one: this reduces the net_if_router
structure by 22 bytes
- refactor IPv6 and IPv4 router code so it's handled in generic
functions, to avoid duplicating 90% of the code for each family. This
also fixes the lifetime support for IPv4 which was missing.

Note however that IPv4 routing support seems to be missing as none of
the relevant functions are used anywhere yet.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka b5bcd25398 net/iface: Coalesce all RS timers through one
This reduces the size of struct net_if_ipv6 by 24 bytes by moving
the k_delayed_work attribute into net_if core code.
Then each net_if_ipv6 can be added to the timer handler via a slist.

This does not make much gain if the system has only 1 network interface
It starts to be interesting if it has 2+ network interfaces then.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka 09e7262be8 net/iface: Coalesce all DAD timers through one
This reduces the size of struct net_if_addr by 24 bytes by moving
the k_delayed_work attribute into net_if core code.
Then each net_if_addr can be added to the timer handler via a slist.

This does not make much gain if the system has only 1 unicast IPv6
address. It's a nice memory improvment once it has 2+ unicast IPv6
address. Note that having IPv4 enabled along with IPv6 will also see
memory improvements since both IPv6 and IPv4 use the same struct
net_if_addr.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka 4e3a93d530 net/iface: Initialize IPv4/6 address so it removes more ifdef
Just create init functions for each IP version.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka 6a513e4394 net/iface: Reduce ifdef usage on various options
Offload, DAD, RS and IPv4 autoconf.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka cf6c5428e1 net/iface: Reduce usage of ifdef around CONFIG_NET_IPV4
Let's regroup all the IPv4 related function into one ifdef. There is no
need to implement a dummy function for each: if IPv4 is not enabled,
these functions are unused in the core.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka 315b47b56b net/iface: Reduce usage of ifdef around CONFIG_NET_IPV6
Let's regroup all the IPv6 related function into one ifdef. There is no
need to implement a dummy function for each: if IPv6 is not enabled,
these functions are unused in the core.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Jukka Rissanen b68d6a9a26 net: tcp: Adjust data length if TCP options are present
Skip the TCP options before giving the data to application.
Without this, the TCP options would be passed to the application.

Fixes #17055

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-08 10:27:33 +03:00
Jukka Rissanen 77c10fc7e3 net: shell: Show network packet TX transit times
Useful when checking TX packet timings in the network stack.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-03 09:42:45 +03:00
Jukka Rissanen e809b95c51 net: Collect network packet TX send time
Finalize the CONFIG_NET_CONTEXT_TIMESTAMP support that was started
earlier but never properly finished. We collect network statistics for
TX packet network stack throughput time from when the net_context_send
is called and when the net_pkt was sent out successfully by the network
device driver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-03 09:42:45 +03:00
Jukka Rissanen 5d13df9c3b net: utils: Add userspace support to net_addr_ntop/pton()
Allow userspace application call net_addr_ntop() and
net_addr_pton() functions.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen 2da132e5e3 net: mgmt: Send event with info when applicaple
If the net_mgmt event has some info, like IP address, that
could be sent, then send it the same time. This is very useful
for the receiver of the event in order to know that is happening
in the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen 02b3826fa0 net: mgmt: Add info length to event wait API
The info parameter is difficult to use if the caller does not
get information how long the info struct is. So add info_length
parameter to net_mgmt_event_wait_on_iface() and
net_mgmt_event_wait() APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen 766ad9f96c net: if: Make gateway address in net_if_ipv4_set_gw() const
As the function does not modify the parameter, we can make it const.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 15:34:11 +03:00
Jukka Rissanen 7063921e87 net: if: Add userspace support to IPv4 gateway set function
Allow application to call net_if_ipv4_set_gw_by_index()
and set the gateway if enabled by configuration.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 15:34:11 +03:00
Jukka Rissanen 813ae63f6b net: if: Add userspace support to IPv4 netmask set function
Allow application to call net_if_ipv4_set_netmask_by_index()
and set the netmask if enabled by configuration.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 15:34:11 +03:00
Jukka Rissanen 10189332cd net: if: Make IPv4 address const in removal function
As the function does not touch IPv4 address in removal, we
can mark it const.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 15:34:11 +03:00
Jukka Rissanen 041cd5f18f net: if: Add syscall interface to IP address add and rm
Make IPv4 and IPv6 address addition and removal possible from
userspace app. But allow this only if CONFIG_NET_IF_USERSPACE_ACCESS
By default these operations are not allowed from userspace app.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 15:34:11 +03:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 536dd5a71f cleanup: include/: move misc/slist.h to sys/slist.h
move misc/slist.h to sys/slist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Jukka Rissanen 034bccca20 net: Fix net_pkt_hexdump() to print pkt address properly
If immediate logging is disabled, then we must use log_strdup()
when printing log string allocated from stack.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-24 16:44:02 +03:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
David B. Kinder 2aebc980e2 doc: fix Kconfig misspellings
Fix misspellings in Kconfig files missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-06-18 15:07:52 -04:00
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