From change 47eb592c28b9e7dfbdd25fedbf07a528ad240084 net_buf structures
allocated from pools defined with NET_BUF_POOL_FIXED_DEFINE() will keep
their `size` member set to the actual fixed size and not requested
size like before.
For this set of tests NET_BUF_POOL_FIXED_DEFINE() for several test
cases. These tests check the several values based on a fact that the
network buffer's size was set to the requested size.
This commit changes definition of the buffer pool to
NET_BUF_POOL_FIXED_DEFINE() in order to satisfy these expectations.
This change does not impact the tests themselves.
Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
rand32.h does not make much sense, since the random subsystem
provides more APIs than just getting a random 32 bits value.
Rename it to random.h and get consistently with other
subsystems.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
For socket families that are niether INET/INET6 e.g., PACKET, we cannot
estimate header length, so, if the payload is zero as well, networking
stack drop the packet.
Instead, allow for zero header + payload packets and let L2 take care of
handling them, for some L2's this is still a valid frame.
E..g, In case of Wi-Fi this is sent as 802.11 Header + LLC Header
(no payload).
Add unittests for both AF_INET + Zero payload and AF_PACKET + Zero
payload.
Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
The net packet structure contains pointers to link-layer source and
destination addresses. Usually, these structures do not point to
separately allocated memory but directly into the packet's data buffer.
In case of a deep package clone (which includes copying the buffer) the
copy of the ll addresses continued to point into the old package
(contrary to a rather misleading inline comment). This was proven by an
additional failing unit test assertion.
As the original package may be unreferenced while the cloned package is
still being accessed, the ll address pointers of the cloned package may
become invalid.
The fix consists of two parts:
* First it is determined whether a given ll address actually points into
the buffer and if so at which logical cursor offset it is located.
* If the address points into the package buffer then the cursor API is
used to determine the corresponding physical memory location in the
cloned package. The ll address of the cloned package is then patched
to point to the cloned buffer.
Additional assertions were introduced to the existing unit test to ensure
that the newly generated address points to the correct content of the
cloned package.
The solution is implemented in a generic way so that the previously
redundant implementations were consolidated into a single one. The code
includes a check that ensures that the ll address check and manipulation
will be skipped in case of shallow package copies.
The change also addresses problems related to the "overwrite" flag of the
package:
* Package cloning assumes the overwrite flag to be set. Otherwise it
will not work correctly. This was not ensured inside the clone method.
* Package cloning manipulates the overwrite flag of the cloned package
but does not reset it to represent the same state as the original
package.
The change introduces a fix and unit test assertions for both problems.
Fixes: #51265
Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
Add a bunch of missing "zephyr/" prefixes to #include statements in
various test and test framework files.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Checks that taking a shallow of a packet does not leak buffers after the
packet and its clone are unreffed.
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
In order to bring consistency in-tree, migrate all tests to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Update the macro prototype to explicitly require the length of the
desired user data. Update all in-tree usage of this macro.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Some net_pkt functions in `test_net_pkt_headroom_copy()` did not have
their return values verified, causing coverity complains.
CID: 240661
Fixes#39841
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Move to CMake 3.20.0.
At the Toolchain WG it was decided to move to CMake 3.20.0.
The main reason for increasing CMake version is better toolchain
support.
Better toolchain support is added in the following CMake versions:
- armclang, CMake 3.15
- Intel oneAPI, CMake 3.20
- IAR, CMake 3.15 and 3.20
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Introduce a helper function for being able to remove any arbitrary
length from tail of packet. This is handy in cases when removing
unneeded data, like CRC once it was verified.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This returns the available contingous space in the packet starting from
the current cursor position.
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
This commit fixes some edge cases when using net_bufs with reserved
bytes (headroom) as fragments of a net_pkt.
Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
When operating on a net_pkt using the cursor functionality, reserved
bytes (headroom) are currently not respected.
This commit adds test cases exposing this problem. Fix will be
introduced in a later commit.
Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
Adjust the test thread priority so that the test / IP stack
has a chance to run and the test passes.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.
A coccinelle rule is used for this:
@r_const_dev_1
disable optional_qualifier
@
@@
-struct device *
+const struct device *
@r_const_dev_2
disable optional_qualifier
@
@@
-struct device * const
+const struct device *
Fixes#27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Unit tests were failing to build because random header was included by
kernel_includes.h. The problem is that rand32.h includes a generated
file that is either not generated or not included when building unit
tests. Also, it is better to limit the scope of this file to where it is
used.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
... because it is (required).
This makes a difference when building with CMake and forgetting
ZEPHYR_BASE or not registering Zephyr in the CMake package registry.
In this particular case, REQUIRED turns this harmless looking log
statement:
-- Could NOT find Zephyr (missing: Zephyr_DIR)
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- ...
-- ...
-- ...
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:8 (target_sources):
Cannot specify sources for target "app" which is not built by
this project.
... into this louder, clearer, faster and (last but not least) final
error:
CMake Error at CMakeLists.txt:5 (find_package):
Could not find a package configuration file provided by "Zephyr" with
any of the following names:
ZephyrConfig.cmake
zephyr-config.cmake
Add the installation prefix of "Zephyr" to CMAKE_PREFIX_PATH or set
"Zephyr_DIR" to a directory containing one of the above files. If
"Zephyr" provides a separate development package or SDK, be sure it
has been installed.
-- Configuring incomplete, errors occurred!
Signed-off-by: Marc Herbert <marc.herbert@intel.com>
If we have removed first net_buf, then we must not restore the
original cursor as that will point to wrong head net_buf.
Add also unit test to check that the packets are removed
properly.
Clarify the documentation that we are removing data from
beginning of the function, also document that the cursor
is reset after this call.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Using find_package to locate Zephyr.
Old behavior was to use $ENV{ZEPHYR_BASE} for inclusion of boiler plate
code.
Whenever an automatic run of CMake happend by the build system / IDE
then it was required that ZEPHYR_BASE was defined.
Using ZEPHYR_BASE only to locate the Zephyr package allows CMake to
cache the base variable and thus allowing subsequent invocation even
if ZEPHYR_BASE is not set in the environment.
It also removes the risk of strange build results if a user switchs
between different Zephyr based project folders and forgetting to reset
ZEPHYR_BASE before running ninja / make.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
By changing the various *NET_DEVICE* macros. It is up to the device
drivers to either set a proper PM function or, if not supported or PM
disabled, to use device_pm_control_nop relevantly.
All existing macro calls are updated. Since no PM support was added so
far, device_pm_control_nop is used as the default everywhere.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Added simple test case for net_pkt_clone() to verify
cursor position after cloning.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
This is bad practice and may conceal issues on platforms
not in the whitelist.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
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>
Inside function test_net_pkt_basics_of_rw result of function call
net_pkt_read_be16 is not checked which might result performance
of the program and cause errors.
Coverity-CID 198003
Fixes#15776
Signed-off-by: Maksim Masalski <maxxliferobot@gmail.com>
Write the net_pkt using net_pkt_write() and then verify that the
data is actually written into net_buf.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
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>
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>
Remove magic numbers from Ethernet drivers and tests by defining
NET_ETH_MAX_DATAGRAM_SIZE and NET_ETH_MAX_FRAME_SIZE.
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Just a quick rm/mv. The new API is going to be the only one, so legacy
test can disappear.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
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>
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>
Fixed typo: CONFIG_NET_NET_PKT_LOG_LEVEL_DBG, removed extra _NET.
Removed debug macro CONFIG_NET_DEBUG_NET_PKT that is not used.
Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>