Commit graph

98 commits

Author SHA1 Message Date
Flavio Ceolin c4f7faea10 random: Include header where it is used
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>
2020-07-08 21:05:36 -04:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Jukka Rissanen 76d07ccd00 net: dhcpv4: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Luuk Bosma 9587a271f6 net/ip/dhcpv4: Set Host Name in DHCP Request
This option specifies the name of the client.
See https://tools.ietf.org/html/rfc2132#section-3.14

This is useful for identification when looking in DHCP lease table.

Signed-off-by: Luuk Bosma <l.bosma@interay.com>
2020-03-10 14:10:01 +02:00
Oleg Zhurakivskyy 8a77b53053 net: core: Drop NET_ASSERT_INFO() macro
A single assert macro can serve a purpose here.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Markus Fuchs 4ff6c69233 net: dhcpv4: Cancel pending DNS queries on DNS server update
On processing a DNS server option, which re-initializes the DNS resolve
context, also cancel all pending DNS queries before closing the old DNS
resolve context. Otherwise, `z_clock_announce()` will later work on the
re-initialized context once the queries expire and crash because the
reference to the timeout function `query_timeout()` has been cleared.

Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
2019-10-22 15:06:51 +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
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
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 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 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
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
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
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
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
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 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 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 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 e97a543e9b net/pkt: Remove parameters to "reserve" some headroom
Such parameter is not used anymore, it was defaulted to 0 previously.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 156213078d net/ipv4: Remove any use of ll reserve
As this is now unnecessary, let's ignore that and use 0 instead.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Vincent van der Locht 58463b7ea7 net: dhcpv4: dhcp start/stop made compatible for multiple interfaces
The net_dhcpv4_stop() function stops the event listener for any IF_UP
events previously. In case multiple interfaces are used and optionally
being switched over, it could result in disabling dhcp unintentionally.

The callback is initialized at the init function and added/removed in
the start/stop function based on the interface list being empty
or not. (first added, last removed)

The event handler checks if the interface is in the list before acting
on it.

Signed-off-by: Vincent van der Locht <vincent@vlotech.nl>
2018-12-07 12:23:46 +02:00
Vincent van der Locht 994a4772ca net: dhcpv4: net_dhcpv4_stop() removing address during renew
In case "net_dhcpv4_stop(..) is called when the interface is
in NET_DHCPV4_RENEWING state, the address is not removed.
When deleting the address in the NET_DHCPV4_RENEWING state
means the status is always equal to the moment before _start
is called.

Signed-off-by: Vincent van der Locht <vincent@vlotech.nl>
2018-12-07 12:22:19 +02:00
Jukka Rissanen 86689030e8 net: Clarify logging in networking code
Remove network specific default and max log level setting
and start to use the zephyr logging values for those.

Remove LOG_MODULE_REGISTER() from net_core.h and place the
calls into .c files. This is done in order to avoid weird
compiler errors in some cases and to make the code look similar
as other subsystems.

Fixes #11343
Fixes #11659

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Jukka Rissanen 57a8db7789 net: Use log_strdup() when printing debug strings
As the debugging print calls are async, all the strings that might
be overwritten must use log_strdup() which will create a copy
of the printable string.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 15e7e3ea4b net: ip: Split debug prints into smaller pieces
Currently logging subsystem supports quite small number of function
parameters. So split some long functions into smaller pieces.
Hopefully this is just a temporary patch and we can support more
parameters to logging macros.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen a76814bfb6 net: Convert core IP stack to use log levels
Instead of one global log level option and one on/off boolean
config option / module, this commit creates one log level option
for each module. This simplifies the logging as it is now possible
to enable different level of debugging output for each network
module individually.

The commit also converts the code to use the new logger
instead of the old sys_log.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Jukka Rissanen feed6bfb3b net: dhcpv4: Do not debug print IP address using NULL pointer
The ciaddr can be null in requesting state so do not try to print
it in that case.

Fixes #9575

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-30 10:50:27 -04:00
Oleg Zhurakivskyy 99dc5aef88 net: ip: Refactor usage of net_sprint_ip*()
Refactor usage of net_sprint_ip*() where multiple
invocations are needed per single log call.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-17 12:36:50 +03:00
Daniel Egger d66e8077ce net/dhcpv4: Use new net_pkt_append_memset() function
Thise uses the new net_pkt_append_memset() function to generate the
required zero filling instead of calling net_pkt_append_u8() in loops.

Fixes #9287

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2018-08-16 10:35:01 +03:00
Tomasz Bursztyka 2ba28dd78c net/dhcpv4: Unify timeout management in a unique k_delayed_work
This reduces memory overhead on net_if_dhcpv4: 16 bytes vs 120 bytes
before. This might proove to be beneficial when there are many network
interface.

dhcpv4 ROM consumption is now 2132 bytes vs 4224 (many switches removed)

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 11ccf36aa1 net/dhcpv4: Cleanup debug messages
No need to use PRIxxx primitives.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka bb6b2769ab net/dhcpv4: Tiny style fixes
Empty line before if (unless test uses previous line assignment) and
after } (unless it's another } ...)

Indentation fixed as well.

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 502912acf5 net/dhcpv4: Reuse generic IPv4 function relevantly
No need to recreate the IPv4 header code here, nor the checksum etc...

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 6d74e26245 net/dhcpv4: Reorder variable declaration
- Pre-assigned are always coming first.
- Always declare at the beginning of a code block

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 3d5876d4a8 net/dhcpv4: Rename functions to follow domain related naming rules
dhcpv4_ for static ones, net_dhcpv4_ for exported ones.

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 09233e6929 net/dhcpv4: Move definitions to header
As done everywhere else.

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Jukka Rissanen cb00061cbe net: dhcpv4: Use less parameters in debug print
Having 24 parameters in a debug print is a bit extreme especially
as it is causing warning from new logger. Split the debug print
to three pieces each having 8 parameters which is more reasonable.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-10 12:37:31 +03:00
Jukka Rissanen 5cda31c8f1 net: dhcpv4: Detect network interface on/off events
Catch interface up/down events so that we can renew the
address if interface goes down and is then restored.

Fixes #7553

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-11 17:27:29 -04:00
Jukka Rissanen fa8824184d net: dhcpv4: Fix IPv4 and UDP checksum calculation
Make sure we calculate the IPv4 and UDP checksum only when
needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-11 17:27:29 -04:00
Jukka Rissanen 8670e8a1f7 net: Convert MSEC_PER_SEC to K_SECONDS()
Use of K_SECONDS() macro is more intuitive so use that instead of
plain MSEC_PER_SEC define.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-28 17:20:11 -04:00
Jukka Rissanen 47dafffb67 net: if: Separate IP address configuration from net_if
Move IP address settings from net_if to separate structs.
This is needed for VLAN support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Leandro Pereira 6504b2850e net: ip: dhcpv4: Do not try to write to NULL pointer on failure
Assertions should only be used to check invariants.  Things that may
change value in runtime are better left to proper checks.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
John Andersen b0d8075709 net: ip: dhcpv4: Handle DHCPV4_OPTIONS_DNS_SERVER
Actually set Zephyr's default DNS server based on the corresponding
DHCP option received. This makes DHCP-based setup Zephyr complete:
now it's possible to connect Zephyr DHCP-enabled system to a typical
router, and it will fully auto-configure to access Internet.

This initial implementation uses just first DNS server address as
returned in DHCP message, it may need to be extended in the future
based on the need.

Signed-off-by: John Andersen <john.s.andersen@intel.com>
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-18 17:30:40 +02:00
june li 486e156827 net: dhcpv4: Unref net_pkt if message sending fails
If we cannot send a DHCP message, then unref the net_pkt
in order to avoid a buffer leak. Earlier we tried to
unref NULL net_pkt which is not correct.

Signed-off-by: june li <junelizh@foxmail.com>
2017-11-17 11:16:04 +02:00
Paul Sokolovsky dcb80f7ab8 net: struct sockaddr should have field "sa_family"
POSIX requires struct sockaddr's field to be named "sa_family"
(not just "family"):
http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/socket.h.html

This change allows to port POSIX apps easier (including writing
portable apps using BSD Sockets compatible API).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-18 16:34:51 -04:00
Jukka Rissanen 3604c391e6 net: udp: Remove NET_UDP_HDR() macro and direct access to net_buf
Remove NET_UDP_HDR() macro as we cannot safely access UDP header
via it if the network packet header spans over multiple net_buf
fragments.

Fixed also the UDP unit tests so that they pass correctly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-07 15:24:00 +03:00
Paul Sokolovsky 515788648a net: ip: Make struct in_addr::s_addr compatible with POSIX definition
From
http://pubs.opengroup.org/onlinepubs/7908799/xns/netinetin.h.html:

in_addr_t
    An unsigned integral type of exactly 32 bits.

[] the in_addr structure [] includes at least the following member:

in_addr_t      s_addr

In other words, POSIX requires s_addr to be a single integer value,
whereas Zephyr defines it as an array, and then access as s_addr[0]
everywhere. Fix that by following POSIX definition, which helps to
port existing apps to Zephyr.

Jira: ZEP-2264

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-13 10:32:03 +03:00