For instance, DHCP (UDP protocol) can send broadcasted packet and if we
no not serve the requested destination port, let's not send an error
back.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Invert src/dst strings, the icmpv4 error is sent from the dst (us) to
src (sender of the ipv4 packet that generated the error).
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Replace unpacked in_addr structures with raw buffers in net_ipv4_hdr
struct, to prevent compiler warnings about unaligned access.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If `CONFIG_NET_ICMPV4_ACCEPT_BROADCAST` is enabled ICMPv4 should reply
to request packets sent to the broadcast address of an interface with
the unicast address of that interface from the same subnet.
Previously the code blindly copied the ICMP source address which meant
it would reply to broadcast packets with a broadcast source address.
Signed-off-by: Arvin Farahmand <arvinf@ip-logix.com>
net_icmpv4_send_echo_request currently returns EINVAL (invalid
argument) when IPv4 is unavailable.
Since the availability of IPv4 has nothing to do with the arguments
provided to this function and the meaning of EINVAL in this case is
ambiguous, return the ENETUNREACH (network is unreachable) error
number instead.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
NET_OFFLOAD interfaces do not handle ICMP request. Request to send ICMP
packet resulted in NULL pointer dereference in net_if_tx() later
on. Prevent that by detecting NET_OFFLOAD interfaces early in icmpv4
module.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Timestamp and RecordRoute options are supported
in only ICMPv4 EchoRequest call as per
RFC 1122 3.2.2.6.
Fixes#14668
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Introduced by commit id de78a7af28.
If the sum is 0xffff, a ~sum will give 0.
Fixes#12164
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Remove network specific default and max log level setting
and start to use the zephyr logging values for those.
Remove LOG_MODULE_REGISTER() from net_core.h and place the
calls into .c files. This is done in order to avoid weird
compiler errors in some cases and to make the code look similar
as other subsystems.
Fixes#11343Fixes#11659
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
IPv4, ICMPv4/6, UDP, TCP: all checksums are meant to be one's complement
on a calculated sum. Thus return one's complement already from the right
place instead of applying it in each and every place where
net_calc_chksum is called.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Networking stack sometimes try to find source address based
on destination address. If interface could not find best match
then it returns unspecified address (0.0.0.0). Host should not
send these packets.
IPv4 reply related issues fixed.
Fixes#11329
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Unify the function naming for various network checking functions.
For example:
net_is_ipv6_addr_loopback() -> net_ipv6_is_addr_loopback()
net_is_my_ipv6_maddr() -> net_ipv6_is_my_maddr()
etc.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
ICMPv4 checksum is not optional and thus cannot be zero. Hence, drop
packet with invalid zero ICMPv4 checksum.
Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
If we receive an IPv4 that has broadcast destination address, then
properly handle it.
This means that for
* ICMPv4, if CONFIG_NET_ICMPV4_ACCEPT_BROADCAST is set (this is the
default value) and we receive echo-request then accept the packet.
Drop other ICMPv4 packets.
* TCP, drop the packet
* UDP, accept the packet if the destination address is the broadcast
address 255.255.255.255 or the subnet broadcast address.
Drop the packet if the packets broadcast address is not in our
configured subnet.
In sending side, make sure that we do not route broadcast address
IPv4 packets back to us. Also set Ethernet MAC destination address
properly if destination IPv4 address is broadcast one.
Fixes#10780
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
As the debugging print calls are async, all the strings that might
be overwritten must use log_strdup() which will create a copy
of the printable string.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Instead of one global log level option and one on/off boolean
config option / module, this commit creates one log level option
for each module. This simplifies the logging as it is now possible
to enable different level of debugging output for each network
module individually.
The commit also converts the code to use the new logger
instead of the old sys_log.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
*_ll_src/*_ll_dst/*_ll_swap/*_ll_if were not self explanatory, ll
meaning "link layer" it's ambiguous what the names meant.
Changing to:
*_lladdr_src/*_lladdr_dst/*_lladdr_swap/*_lladdr_if to fix this.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Refactor usage of net_sprint_ip*() where multiple
invocations are needed per single log call.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Instead of waiting forever for a network buffer, have a timeout
when allocating net_buf. This way we cannot left hanging for a
long time waiting for a buffer and possibly deadlock the system.
This commit only adds checks to core IP stack in subsys/net/ip
Fixes#7571
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Instead of reading or writing different icmpv4 header's individual
variables, better to read or write whole struct at a time. This
minimizes the calls to net_frag_read() or net_frag_write().
changes also removed slow and fast paths. Changes should optimize
the total flow.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>