Instead of having a single config specifying the memory pool size for
variable-sized net buffers, have a separate one for TX and RX for better
configuration granularity when optimizing memory usage of the
application.
Deprecate the old configuration but use its value as a default (for now)
for the new configs. This will need to change when the config is
deleted.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The original packet's link-layer destination and source address can be
stored in separately allocated memory. This allocated memory can be
placed just after pkt data buffers.
In case when `net_pkt_find_offset()` uses condition:
`if (buf->data <= ptr && ptr <= (buf->data + buf->len)) {`
the offset is set outside the packet's buffer and the function returns
incorrect offset instead of error code.
Finally the offset is used to set ll address in cloned packet, and
this can have unexpected behavior (e.g. crash when cursor will be set
to empty memory).
Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
Add new function to allocate additional buffers for net_pkt, w/o any
additional preconditions/checks. Just allocate what was requested.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The current logic to determine whether a packet is IP reassembled is
flawed, as it only worked in certain conditions (which was ok, as the
conditions were satisfied for the current use case, but now it's a
public function). Therefore, add an explicit flag that indicates whether
a packet is IP reassembled or not.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add new net_pkt checksum, which indicate checksum status on the packet
(i. e. whether it has already been calculated or not).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
A few attributes isn't cloned togerder with pkt.
This commit add missing part.
Additionally, because the `eof` flag in net_pkt structure is
avilable unconditionally hence `#if defined(CONFIG_NET_SOCKETS)`
guard has been removed form setter and getter functions for
this flag.
Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
Modify the signature of the k_mem_slab_free() function with a new one,
replacing the old void **mem with void *mem as a parameter.
The following function:
void k_mem_slab_free(struct k_mem_slab *slab, void **mem);
has the wrong signature. mem is only used as a regular pointer, so there
is no need to use a double-pointer. The correct signature should be:
void k_mem_slab_free(struct k_mem_slab *slab, void *mem);
The issue with the current signature, although functional, is that it is
extremely confusing. I myself, a veteran Zephyr developer, was confused
by this parameter when looking at it recently.
All in-tree uses of the function have been adapted.
Fixes#61888.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Fix possible NULL dereference at net_pkt_cursor_operate() and
resolve 'Dereference after null check' warnings from the Coverity
static code analysis.
Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@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>
Clean up occurrences of "#if IS_ENABLED(CONFIG_FOO)" an replace
with classical "#if defined(CONFIG_FOO)".
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Introduce the Kconfig symbol `NET_PKT_BUF_USER_DATA_SIZE`. It is used to
set the user data size in the buffers used in the rx and tx network buffer
pools.
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
This aligns the conditional compilation logic with the one used for the
prototype in net_pkt.h, avoids build errors due to a undefined reference
to net_pkt_print_frags.
Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
net_pkt_get_frag() and a few other functions did not specify the
allocated fragment length, incorrectly assuming that fixed-sized
buffers are always used.
In order to make the function work properly also with variable-sized
buffers, extend the function argument list with minimum expected
fragment length parameter. This allows to use net_buf_alloc_len()
allocator in variable buffer length configuration, as well as verify if
the fixed-sized buffer is large enough to satisfy the requirements
otherwise.
Update the existing codebase to provide the expected fragment length,
based on the context.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case variable buffer length feature was enabled, net_pkt code did
not build due to unconditional references to CONFIG_NET_BUF_DATA_SIZE,
which is not avaialable in this configuration.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Adds support for incoming and outgoing IPv4 fragmented packet support,
allowing a single packet that is too large to be sent to be split up
and sent successfully.
Signed-off-by: Jamie McCrae <spam@helper3000.net>
Add new fields to the net_pkt structure, representing IP-specific
Differentiated services code point (DSCP) and Explicit Congestion
Notification (ECN) values. Those values are encoded in legacy
Type of Service (IPv4) and Trafic Class (IPv6) header fields.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This change implements part two of the program laid out in the TSCH RFC,
see #50336#issuecomment-1250250154 :
> Consolidate IEEE 802.15.4 options in net_pkt
This change improves decoupling of generic net core code from
IEEE 802.15.4 internals. It also simplifies IEEE 802.15.4
attribute cloning and thereby makes it easier to maintain and less
error prone (and probably even faster as individual bits are no longer
copied over separately).
This enables us to extend and design IEEE 802.15.4 L2 attributes inside
the package in isolation from the net core code which will no longer
have to be changed when introducing changes or additions to the flags.
This flexibility will be built upon in later change sets to model the
IEEE 802.15.4 attributes closer to the spec.
The solution is inspired by Linux's sk_buff->cb attribute which addresses
the same concern as the attribute introduced in this change set:
https://elixir.bootlin.com/linux/v6.0.1/source/include/linux/skbuff.h#L871
As the inline comment says: The cb attribute can be made a union or even a
uint8[something] in the future, if further L2s need a control block, too.
Right now such full indirection would make the code overly abstract, so
I chose to compromise with maintainability in mind.
Care has been taken to ensure that this changes does not introduce
additional padding into the net package. To maintain zero-padding, future
changes to the net packet struct will have to ensure that the
IEEE 802.15.4 struct is 4-byte aligned (iff the IEEE 802.15.4 struct
continues with max uint32_t scalar members) which is no deviation from
the previous implementation.
Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
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>
This is a follow up to commit bb86f8b967.
Also custom IEEE 802.15.4 based L2 implementations may need to use
packet handling without the IP layer. Add support for such cases.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
Since db11fcd174 [net/net_pkt: Fully
separate struct net_pkt from struct net_buf], net_pkt_compact() can not
fail anymore.
This commit acknowledges this and simplifies the API accordingly.
Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
While a previous change had already decoupled the IEEE 802.15.4 L2 from
IP upper layers, this only worked when at least one other interface of
the device supported IP.
This change removes this requirement and thereby fixes a build error
that occurred when disabling IP support while maintaining IEEE 802.15.4
L2 support.
Fixes: #48718
Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
The L2 protocol type information is not carried to the upper layers.
This is problematic for packet sockets, as the address structure in
recvfrom() is supposed to provide this information.
Fix this by adding ll_proto_type field in the net_pkt structure.
Set the protocol type in the Ethernet L2 when packet is processed.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit extends the `struct net_pkt` structure with
`ieee802154_txpwr` field that contains signed value of the desired
transmission power of a IEEE 802.15.4 frame in dBm.
Signed-off-by: Jedrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
Currently a shallow clone of a packet will bump the reference count on
all the fragments. The net_pkt_unref() function, however, only drops the
reference count on the head fragment. Fix this by only bumping the ref
count on the head buf during shallow clone.
Only bumping the ref count of head is more in line with the idea that
head buf is not responsible for the fragments of its child.
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#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>
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>
The print specifier for `atomic_t` should be updated
to `%ld`, `%lu`, or `%lx` to account for the type
change of `atomic_t` to `long`.
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This adds the ability to create Ethernet bridges for connecting
separate Ethernet segments together to appear as a single
Ethernet network.
This mimics the Linux functionality of the same name.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
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 value is used to measure the RX/TX statistics. The previous
use of the timestamp field did not work in RX path as the timestamp
value could be overwritten by the driver if gPTP timestamping
is enabled. So to fix the RX statistics, use a separate field
for the create time.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Set the net_pkt creation time just before the actual net_pkt
is allocated in order to get more accurate information for
statistics.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add get/set helpers to store information whether the net_pkt
is captured already or not. This bit is used to detect capture
loop and avoid recursion.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Instead of forcing net_pkt_clone() use the tx_pkts slab, use
the same slab that was used when allocating the original net_pkt.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
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>
net_buf_max_len() provides the maximum number of bytes which can be put
behind the data pointer. This provides a save alternative to using the
size field of the net_buf structure directly, which does not take the
reserved bytes (headroom) into account.
This commit also replaces the usage of the size field in places where
size got used directly. Code has not been adjusted when it is easy to
recognise that the buffer does not have any reserved bytes, which is the
case after allocation or reset. Same goes for the faulty usage by
net_pkt as exposed by the last commit and begin fixed by a separate
commit.
Even though it would be cleaner, I decided to not rename the size field
to e.g. __buf_size in order to keep the amount of code changes low.
Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
using CONFIG_NET_BUF_POOL_USAGE monitor avail_count,
this variable should be protect.
Protecting it by using atomic variable
Signed-off-by: Ehud Naim <ehudn@marvell.com>