Commit graph

98 commits

Author SHA1 Message Date
Jukka Rissanen 6ed7fb05d0 net: dhcpv4: Properly register UDP handler
The address family of the UDP port listener was not set. This
caused weird debug prints in net-shell. Now the listener will
be registering IPv4 any address as it should.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-19 14:56:22 +03:00
Paul Sokolovsky 25307d5331 net: net_pkt_append: Refactor to return length of data actually added
For stream-based protocols (TCP), adding less data than requested
("short write") is generally not a problem - the rest of data can
be sent in the next packet. So, make net_pkt_append() return length
of written data instead of just bool flag, which makes it closer
to the behavior of POSIX send()/write() calls.

There're many users of older net_pkt_append() in the codebase
however, so net_pkt_append_all() convenience function is added which
keeps returning a boolean flag. All current users were converted to
this function, except for two:

samples/net/http_server/src/ssl_utils.c
samples/net/mbedtls_sslclient/src/tcp.c

Both are related to TLS and implement mbedTLS "tx callback", which
follows POSIX short-write semantics. Both cases also had a code to
workaround previous boolean-only behavior of net_pkt_append() - after
calling it, they measured length of the actual data added (but only
in case of successful return of net_pkt_append(), so that didn't
really help). So, these 2 cases are already improved.

Jira: ZEP-1984

Change-Id: Ibaf7c029b15e91b516d73dab3612eed190ee982b
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-28 15:01:09 +03:00
Kumar Gala a509441210 net: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: I4ec03eb2183d59ef86ea2c20d956e5d272656837
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 09:30:38 -05:00
Tomasz Bursztyka e5896906f6 net: Rename all *_BUF() macros to *_HDR()
Most of these macros are not exactly exposing a buffer, but a specific
header pointer (ipv6, ivp4, ethernet and so on), so it relevant to
rename them accordingly.

Change-Id: I66e32f7c3f2bc75994befb28d823e24299a53f5c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:51 +03:00
Tomasz Bursztyka db11fcd174 net/net_pkt: Fully separate struct net_pkt from struct net_buf
- net_pkt becomes a stand-alone structure with network packet meta
  information.
- network packet data is still managed through net_buf, mostly named
  'frag'.
- net_pkt memory management is done through k_mem_slab
- function got introduced or relevantly renamed to target eithe net_pkt
  or net_buf fragments.
- net_buf's sent_list ends up in net_pkt now, and thus helps to save
  memory when TCP is enabled.

Change-Id: Ibd5c17df4f75891dec79db723a4c9fc704eb843d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Tomasz Bursztyka bf964cdd4c net: Renaming net nbuf API to net pkt API
There have been long lasting confusion between net_buf and net_nbuf.
While the first is actually a buffer, the second one is not. It's a
network buffer descriptor. More precisely it provides meta data about a
network packet, and holds the chain of buffer fragments made of net_buf.

Thus renaming net_nbuf to net_pkt and all names around it as well
(function, Kconfig option, ..).

Though net_pkt if the new name, it still inherit its logic from net_buf.
'
This patch is the first of a serie that will separate completely net_pkt
from net_buf.

Change-Id: Iecb32d2a0d8f4647692e5328e54b5c35454194cd
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Jukka Rissanen 5032bdc46d net: nbuf: Pass ll_reserve when creating TX buffer
Instead of always calling net_nbuf_get_reserve_tx() with zero
ll_reserve (first parameter) and then setting the link layer
reserve separately, pass the reserve to that function which can
then set the ll_reserve in buf itself.

Change-Id: I21c14cb7e2e6c36d170c09998bca0207ecf65c75
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen 5197266768 net: nbuf: Use net_nbuf_get_frag() to allocate a fragment
The code used net_nbuf_get_reserve_{rx|tx}_data() function to
allocate a fragment. Instead of that low level function, use
net_nbuf_get_frag() instead. There are few places this is not
possible or is too big change like in few test programs.

Change-Id: Ied7e2b7db352de998b200ffa6ff82471bfa5ebe3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen d32503f57e net: nbuf: Split one global DATA pool to RX and TX DATA pools
If we receive lot of packets, it might happen that we exhaust
all the DATA buffers in the system. This would prevent from
us sending anything to the network.
Change this by splitting the DATA buffer pool into RX and TX
parts. This way RX flooding cannot consume all DATA buffers
that needs to be sent.

Change-Id: I8e8934c6d5fdd47b579ffa6268721b5eb3d64b6d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Marcus Shawcroft 7c193b7f9f net/dhcpv4: Support REBINDING
Change-Id: I1e3809b3cde1dec29a001e750cb191cfac046dab
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft f8cc065d13 net/dhcpv4: Refactor t1 handler.
Rewrite the dhcpv4_t1_timeout() handler to explicitly handle all
states.

Change-Id: I6f9d6c8cfacd945e24eb66c6440bf305d528c521
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft b42a6b3192 net/dhcpv4: Remove !iface checks from timeout handlers.
The iface handle checks in the both timeout handlers are unnecessary.
Drop them.

Change-Id: Ie7c884b2ea648f700fbefa8382341036a4db063f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft b0df4bf260 net/dhcpv4: Fix the behaviour of ciaddr.
Correct the logic that determines when CIADDR is set and when it is
left as all zeros. RFC2131 requires that CIADDR is only set when the
client is in specific states.

Change-Id: I93a45e355fbef8d11dba5ac194570b87c594656e
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 045d317b9b net/dhcpv4: Use BROADCAST and UNICAST appropriately.
RFC2131 places explict requirements on a client w.r.t which messages
are broadcast and which are unicast directly to a server.  Notable
rules as they apply to the current dhcpv4 implementation are that
DISCOVER and a REQUEST in response to an OFFER are broadcast.  A
REQUEST in state RENEWAL is unicast.  There are further rules relevant
to the REBINDING state which is not yet implementated.

Adjust the current implementation that always uses broadcast to use
unicast as required by RFC2131

Change-Id: I6edef4241bcd74623a804a73415888cd679888d0
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 4b24c18f5f net/dhcpv4: Use server identifier appropriately.
RFC2131 requries that a client MUST NOT include server identifier in
DHCPREQUEST from state RENEWING.

Change-Id: I0fba703f3a3b218af1ac03f4f1f0daa290bd428f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 53f0823113 net/dhcpv4: Call net_if_ipv4_addr_rm
The DHCPv4 client obtains resources from the server on a lease.  Once
a lease expires those resources must be relinquished.

Update the DHCPv4 client to explicitly remove leased resources from
the network stack once a lease has expired.

Change-Id: I5d3b7a02e463041cfdee1d104f5962498bdd6a30
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 3726bb98bd net/dhcpv4: Introduce start/stop API and disabled state.
Change-Id: Iae3b96dd91325ecf51b33b8c58f65aa5ec2b40c9
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft c4f4cb17db net/dhcpv4: Rework initialization.
The existing dhcpv4 initialization code places all initialization in
the per iface dhcpv4_start() code.  The net_udp_register() setup needs
to happen once for the dhcpv4 instance rather than once per iface.
Subsequent patches in this series also need a place to perform one
time initialization, independent of iface.

Factor the one time setup code out of the existing net_dhcpv4_start()
into a dhcpv4_init() function.  Rather than use SYS_INIT() to run
dhcpv_init() we hook directly into net_init().

The prototype of dhcpv4_init() is shared within the net subsystem with
a new private header file deliberately to avoid exposing the function
via the public API in include/net/dhcpv4.h

Change-Id: I3502a53cc3bfe4db4e4cd22c02ae133c266fdf10
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 010102ae02 net/dhcpv4: Refactor REQUESTING state entry.
Factor out common code associated with entering the REQUESTING state.

Change-Id: I0fc038a49309625c24b874dfda0355794cd41da9
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 653d614e1e net/dhcpv4: Refactor SELECTING state entry.
Factor out common code associated with entering the SELECTING state.

Change-Id: If34929e5f13dff7650388a2b491a01cbbf5dc100
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 5cfc917617 net/dhcpv4: Refactor send_discover
Refactor send_discover() to provide a clean separation between state
machine and action.

Change-Id: I96510cc6a7ab16216821fe65ea4289a78f6443aa
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 33bb4c0f21 net/dhcpv4: Refactor send_request state handling.
Refactor send_request() to provide a clean separation between state
machine and action.

Change-Id: If4c61c5789c919ab3ce6c1f914afc243176760d8
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 9dd39e1553 net/dhcpv4: Implement NAK support.
Handle the NAK message.

Change-Id: Ia3686564b083b16bd409bbe39acc500404f90fe0
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 57b24721b2 net/dhcpv4: Refactor handle_reply()
Split handle_reply into distinct state machine and actions.

Change-Id: Ib177c7a4007662f941f156acfa5791e1d27e3d73
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft b840664c11 net/dhcpv4: Adjust state names to reflect rfc2131
The dhcpv4 state machine implementation names differ from the names
used by the relevant rfc.  There is no good reason for them to be
different, so rename them.

Change-Id: I837f1bc4788c0ed4d2949b12eb6f5bfeef9a0be8
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 1f279e13b3 net/dhcpv4: Unify dhcpv4 state name printers
There are two implementations of dhcpv4 state name numbers to human
readable strings, unify the two.

Change-Id: I1d654918bb919108a0d8c5514b309b193c9c3f96
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 8df38dc55f net/dhcpv4: Move timers inside the net_if dhcpv4 context
The dhcpv4 state machine has a dedicated context within each net_if
structure.  For reasons unknown the timers used by the dhcpv4 state
machine have been placed in net_if outside of the dhcpv4 context area.
Relocate them into the dhcpv4 context.

Change-Id: I0531f493610dffda9ca9208993597a5665bde997
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 5dcc56ebed net/dhcpv4: Refactor dhcpv4 message type representation.
Change the message type representation from integer to enum, this will
help prevent re-occurrence of recent issues where states and events
are interchanged by making it more likely the compiler will see a type
mismatch.

Change-Id: Ia235afda428a9e5dfbd933e02beeae468b4c84a2
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 0d0cdc23a6 net/dhcpv4: Refactor packet construction
Refactor and simplify packet construction.  This resulting code is
simplier, easier to read and compiles a lot smaller.

Change-Id: I43c67d79fbb77f85af54355eca41f516054cbba3
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 1559a3b3e8 net/dhcpv4: Add missing const
Change-Id: I213b35936eb862d5abc4356a1a920cc2fef02f3f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 0296cdd728 net/dhcpv4: Ensure udp header checksum is computed correctly
The dhcpv4 client code builds ip and udp packets from scratch rather
than using the network stack to do the heavy lifting (why ?).

When it computes the udp checksum of each packet it builds it neglects
to clear any preexisting detritus from the checksum field.  The result
of this is that some packets will be built with correct checksums and
some will be built with incorrect checksums.

This is the underlying reason that the dhcp client often taken many
retransmissions and elapsed time before in order to acquire an IP
address.

Change-Id: Iebd1ed34e06f7f2e53d45f6d1555e22f48490287
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-14 08:30:34 +02:00
Marcus Shawcroft ccd6d8c79f net/dhcpv4: Remove unused dhcpv4 offer state
The offer state is unused, remove it.

Change-Id: I9d6217dae291bb90c57c77ce439809bf7e9a9177
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-14 08:30:34 +02:00
Marcus Shawcroft 45e199c812 net/dhcpv4: Fix event/state mismatch
Fix long standing issue where a dhcpv4 message type is compared
against a dhcpv4 state machine state name rather than a message type.
The issue probably arizes due to the similarity in names between
messages and states.  By accident, the relevant message types and
states happen to share the same numbers, hence the implementation
works, but is ill defined.

Change-Id: I5c028de4336ff42f6696e28b3492c932c58b5a05
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-14 08:30:34 +02:00
Marcus Shawcroft 4c08b15c63 net/dhcpv4: Ensure the retransmission attempts counter gets reset.
Change-Id: I4c7c478425ca6f602a397295c36573a4453346d3
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-10 11:25:26 +02:00
Marcus Shawcroft 878aa5f15c net/dhcpv4: Correct backoff and retransmit behaviour
Implement RFC2131 4.1.1 requirement that at dhcp implementation wait
for a random delay of 1 to 10s before sending the initial DISCOVER.

Implement RF2131 4.1 requirement that at dhcp implementation set the
initial retransmit timeout at 4 seconds and exponentially backoff on
each retransmit.

Change-Id: Id7029f3ed16a5f886dbd555fed87320aeffe31aa
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-09 14:27:11 +00:00
Marcus Shawcroft d06ca47eb3 net/dhcpv4: Use unique XID on each request.
Rather than reuse XID's on retransmissions, always use a unique XID.

Either behaviour is permitted by rfc2131.  Debugging the dhcp client
in the presence of multiple dhcp servers with significant packet loss
in the network is much easier if we don't unnecessarily reuse request
identifiers.

Change-Id: I5c82cbdbf3dfc0ef88cae036aa863946844c144f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-09 14:27:11 +00:00
Marcus Shawcroft 8cd2e089d6 net/dhcpv4: Add further diagnostics.
Change-Id: I13fed6b6102d7711082f16de3f782c606808b142
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-09 14:27:10 +00:00
Jukka Rissanen bd3908b2a9 net: nbuf: Add timeout to net_buf getters
This commit changes the net_buf getter functions in nbuf.h
by adding a timeout parameter. These function prototypes
are changed to accept a timeout parameter.
	net_nbuf_get_rx()
	net_nbuf_get_tx()
	net_nbuf_get_data()
	net_nbuf_get_reserve_rx()
	net_nbuf_get_reserve_tx()
	net_nbuf_get_reserve_data()
	net_nbuf_copy()
	net_nbuf_copy_all()
	net_nbuf_push()
	net_nbuf_append()
	net_nbuf_write()
	net_nbuf_insert()

Following convinience functions have not been changed
	net_nbuf_append_u8
	net_nbuf_append_be16
	net_nbuf_append_be32
	net_nbuf_insert_u8
	net_nbuf_insert_be16
	net_nbuf_insert_be32
	net_nbuf_write_u8
	net_nbuf_write_be16
	net_nbuf_write_be32
so they call the base function using K_FOREVER. Use the
base function if you want to have a timeout when net_buf
is allocated.

Change-Id: I20bb602ffb73069e5a02668fce60575141586c0f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Ravi kumar Veeramally 313ee1d49b net: dhcpv4: Fix tiny style issues
Change-Id: I12e6763627d85912496e8c702cd97bf90ac4f741
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:54 +02:00
Ravi kumar Veeramally 4f3a0ef595 net: dhcpv4: Remove dead code
When parser encouter DHCPV4_OPTIONS_END, it immediately returns NET_OK.
No need to maintain end variable here.

Coverity-CID: 157584

Change-Id: I4c8b91f37ae882845c280dab1a8204966aaac00a
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-20 16:23:18 +02:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
li zj 0fc1d808a3 net: dhcpv4 : set ciaddr 0.0.0.0 when send DHCPV4_MSG_TYPE_REQUEST
When router receive dhcpv4 request with ciaddr not 0.0.0.0,
some router reply NAK, dhcpv4 never successful.

Change-Id: I4b66b18f7d30ad5a1b638fdca0bb204ed078d551
Signed-off-by: li zj <279939902@qq.com>
2017-01-13 10:29:03 +01:00
Tomasz Bursztyka a1aa08c288 net: ip: Improve logging by adding a dedicated sys_log level
Let's make net stack having its own level of debugging through sys_log.
It replaces NET_DEBUG by NET_LOG_ENABLED, which is then semantically
better: someone wanting to log the errors might want that not only for
debugging.

Along with it, CONFIG_NET_LOG_GLOBAL option is added, in order to enable
all available logging in network stack. It is disabled by default but
might be found useful when warning/errors need to be logged, so it is
then unnecessary to selectively enable by hand all CONFIG_NET_DEBUG_*
options.

It is possible, locally, to override CONFIG_SYS_LOG_NET_LEVEL by setting
the level one want to NET_SYS_LOG_LEVEL. This can be useful on samples
or tests.

Change-Id: I56a8f052340bc3a932229963cc69b39912093b88
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:20 +01:00
Marcus Shawcroft dc862ec104 net/dhcpv4: Use net_if_ipv4_set_netmask()
Use the interface function rather than writing directly to the iface
structure.  Check for errors in nbuf read.

Change-Id: I75311755c2060b640325962ada28adea597cb914
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:19 +01:00
Marcus Shawcroft defbc89358 net/dhcpv4: Use router option to set IPv4 GW.
Change-Id: I58f47c02665990dcb656f7e6f7802e1958b420a8
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:19 +01:00
Marcus Shawcroft 065c84d5a6 dhcpv4: Add option parsing diagnostics.
Change-Id: I81a4fa5df561217bfae0d48eb458bf45cfe55d16
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:19 +01:00
Marcus Shawcroft 39d5f26988 net/dhcpv4: Correct spellings in comments.
Change-Id: I2c08c35eb81233b14fdfc8ccdcbc84340bdfd6a2
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:16 +01:00
Jukka Rissanen 3eaec41ab8 net: Moved net/ to subsys/net
* Moved networking code into subsys/net.
* Renamed net/yaip to net/ip at the same time.
* Fixed the tests/net to compile
* Fixed the Makefiles and Kconfig files in subsys/net
  to use the new location of the IP stack

Change-Id: Ie45d9e8cb45a93fefdf969b20a81e3b1d3c16355
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:20 +02:00
Renamed from net/yaip/dhcpv4.c (Browse further)