Commit graph

199 commits

Author SHA1 Message Date
Jukka Rissanen
0a259d6bd0 net: ipv6: Prefix length was incorrectly set
The IPv6 prefix address length was incorrectly set in net_if
after RA was received from the network. The incorrect "len"
variable was used instead of correct "prefix_len" in the prefix
info struct.

Change-Id: Ifeaf150b9960414d2ad200053a3bd5290dc8d365
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:44 +02:00
Jukka Rissanen
157c383260 net: ipv6: Make config options more fine grained
Add CONFIG_NET_IPV6_NBR_CACHE option that is the base for both
neighbor discovery (ND) and duplicate address detection (DAD).

Both ND and DAD can be disabled if needed. If NBR cache is
disabled, then ND and DAD are disabled too.

Note that it makes not much sense to disable DAD or NBR cache
as IPv6 will not work properly without them. It is possible
to disable ND but then the neighbor information needs to come
via other sources like RPL.

Change-Id: I57c8668ad828b3a153dfc58eea78bf5f7ac3938a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen
312a9cbb32 net: ipv6: Enhance debug print when handling pending packet
The fragment pointer is good to print here.

Change-Id: If09e684bbe0f9f5d3f961c4af8f86fb3ff364671
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen
b18dd41b2d net: ipv6: Clear pending buf if NS cannot be sent
If for some reason the neighbor solicitation cannot be sent,
then we need to unref the pending packet as that would never
be freed otherwise.

Change-Id: Ied12a9b3a027a2aad3fafd0b5b36c56b5f042c28
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen
ff6365c928 net: ipv6: Make sure there is data to be sent
If we are trying to send a IPv6 network packet and there
is no data, then print error.

Change-Id: Ia0e7bebae513f1bcf984e189566ae7e10a90bbfc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen
13c1037885 net: ipv6: Use net_nbuf_unref() to get better debug prints
When going through fragments in update_ll_reserve(), use
net_nbuf_unref() in order to get better memory allocation
debug prints.

Change-Id: Ia7ee15b32800acdebeb28125465515132c55e179
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Ravi kumar Veeramally
8cb97ae47d net: Modify IPv4/6 packet finalize API's
Current finalize api's takes buf as input parameter and returns
the finalized buf. But if there are any issue while finalizing,
it failed to throw an error.

Change-Id: I6db54b7453eec41a8051fab50d5c0dc937debd54
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:42 +02:00
Ravi kumar Veeramally
ad855fc31d net: ipv6: Fix handling of RA 6CO options
As per RFC 6775 4.2, context length holds number of leading bits
in the Context Prefix field that are valid. Rest are not valid
for compression.

Change-Id: Id21cc2d7a5d42980cf9295f85e75c4869ff6cb99
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:41 +02:00
Jukka Rissanen
d9528ac7fa net: ipv6: Properly enter DELAY state in NUD
We did not handle NUD (Neighbor Unreachability Detection)
properly and did not go to DELAY state when neighbor
reachability was checked.

Change-Id: I127d25124aa806c44ff37c1355cc3db7fb25b2d2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen
cd85a5e924 net: ipv6: Add more debugging to reachability timer
Print timer information when creating and expiring the
reachability timer.

Change-Id: I5c8fee91de85fe7c9ea7c467f45dbb105250d5b1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen
7848d6e0ff net: ipv6: Wrong timer was used when reachability timer expired
The send_ns timer was used instead of reachable timer when
the reachability timer was expired. This meant that the
reachability timer was never restarted after it expired once.

Change-Id: Iccbd6d019d1106adca60f7319bc4c547cdb1d924
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen
ac74637e54 net: ipv6: Return the prefix lifetime in seconds
Use the proper API to get the remaining time in prefix timer
and return the value in seconds as expected.

Change-Id: I055ce0ba6092c23ad60d6775ce75a0a67ad91d26
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen
465ce5bac5 net: ipv6: Send NS when neighbor is added
In order to verify that the neighbor is reachable, send
neighbor solicitation message to neighbor which should then
send neighbor advertisement to us so that we can then mark
it reachable.

Change-Id: I2c45ee4a6982c698ef6c8fa1acccb995aadf8ee6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen
2f5ee81c28 net: ipv6: Print IPv6 neighbor state changes
In order to be able to debug IPv6 neighbor state changes,
pretty print the state names when setting the new state.

Change-Id: I64e0b4173eaa63c9715c17420a008602759aa4fa
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen
91e99ea7da net: ipv6: Add debug function to convert nbr state to string
To be used by net-shell and other files for debugging neighbor
state.

Change-Id: Ie9b09a54a05dcb066906a3697dfe38aeffc886e6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen
75b550e81d net: ipv6: Collect MLD statistics
Collect number of received, sent or dropped multicast listener
reports and queries.

Change-Id: Ia5c08203155475763f96df23f44eceffa7569873
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen
8d8e3772e6 net: ipv6: Respond to MLD query
If we receive MLDv2 (Multicast Listener Discover) query,
we send out information about the multicast groups that
we have joined.

Change-Id: If4ea9fa685319b2ad900e1949a5cbe12e7696b43
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen
ef2ee88af1 net: ipv6: Add router alert option to MLD msg
As dictated by RFC 3810 ch 5, we need to add Hop-by-Hop option
with Router Alert sub-option to the sent multicast listener
message.

Change-Id: I8e3ed58fff4736e9708276a3185f94e7f2b453a3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen
82267e7bd4 net: ipv6: Allow joining to existing multicast address
If the multicast address already exists, then do not give
error but try to join it.

Change-Id: I32ffa6b3bf0798011d684a1a21e87e389f1f0380
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen
f8467437e6 net: if: Leave all joined IPv6 multicast groups at net_if_down
When network interface is taken down, leave only those
IPv6 multicast groups that were joined.

Change-Id: I414556c093ba67be7c13e6c86e0451465c2203f3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen
c3c76f35cc net: ipv6: Notify others if we join/leave IPv6 mcast group
Send management event if we joined or leaved IPv6 multicast
group.

Change-Id: Ieeb407ef88fb3bf4cd92d4fb4b69f03b260474e7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen
74e747a27f net: ipv6: Add support to join/leave multicast group
This and subsequent commits adds API to join or leave
an IPv6 multicast group.

Jira: ZEP-1673

Change-Id: I26dcfe16a4527dbf7886a30827a5d4ebfdeaac01
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:47 +02:00
Jukka Rissanen
f8c60de061 net: nbuf: Create net_nbuf_frag_del() for tracking allocations
Create net_nbuf_frag_del() so that we can track net_buf frees.
If CONFIG_NET_DEBUG_NET_BUF is not defined, then this new function
will call net_buf_frag_del() directly, and if not, then it will
track memory usage.

Change-Id: I5f382436cebc71fdaf12baf7bf964fb63bee7aca
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02: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
189ec2b6ad net: Remove link layer reserve param from IP packet creator
The ll_reserve parameter is useless in net_ipv{4|6}_create_raw()
function as the reserve information is already stored in buf.

Change-Id: I7815a78c001e3da532478c04b3dac9b37bbc723c
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
Jukka Rissanen
7719cee113 net: Add net_buf pool support to each context
User can configure its own pools for data that needs to
be transmitted out (TX). This helps to avoid deadlocking
the system if user space application uses all the buffers
in the system, and the core IP stack tries to get buffer
that needs to be sent out.

By default the net_buf pool support in net_context is turned
off as application developer needs to create the pools and
tie them to desired contexts.

Change-Id: Ida4a1771d34d6c250974e56fba4f0e0b2592cb29
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen
4852d6859b net: ipv6: Do not try to unref null pointer
If the DAD timeouts, then the pending pointer will be null
when we remove the neighbor. Fortunately this only prints
this error message and does not cause any issues in the code.

[net/nbuf] [DBG] net_nbuf_unref_debug: (0x00118350): *** ERROR *** \
  buf 0x00000000 (nbr_clear_ns_pending():175)

Change-Id: I3e11d4aa1d90f205df591b5d5cdcf2ee7bde6c01
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:55 +02:00
Jukka Rissanen
f5477582bd net: ipv6: Add util to remove neighbor from cache
Add net_ipv6_nbr_rm() utility function that can be used to
remove an IPv6 neighbor from the cache.

Change-Id: I9794856a4f65c5e943656970648e5c5762b0338c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:54 +02:00
Jukka Rissanen
d29e073c62 net: ipv6: Add util to traverse neighbor cache entries
Add utility function to go through all the stored neighbors
in the IPv6 neighbor cache.

Change-Id: I42fe0ec48c000215403aef63629d0763189ebdbb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:54 +02: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
Jukka Rissanen
8db13f905b net: ipv6: Free received NA net_buf
If we receive a neighbor advertisement, we need to free its
net_buf because we are returning NET_OK to the caller. This
return code means that we consumed the net_buf but we did
not call net_nbuf_unref() in this case.

Change-Id: Ia6d8f1b440be87eff5d2b14a23336a37be6d6a04
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen
f25d4768b2 net: ipv6: Fix pending buf leak when NA is received
The pending buf needs to be freed after it has been sent
to the network. We took the ref when pending buf was saved,
now we need to unref it when it is about to be sent.

Change-Id: I1e429969895700000a8aa124bd645db2d52d036c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:34 +02:00
Tomasz Bursztyka
93ed88a670 net/ipv6: Updating ll reserve should be done for all IPv6 packet.
Doing it only in net_context, prevented to do it once NS succesfully
finished. This generated an error in 15.4, where pending data had wrong
ll reserve size.

Change-Id: I0f917fb76171457e5dff2c29e44edb8f00662150
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:20 +02:00
Jukka Rissanen
1301d3f6d3 net: ipv6: Use the nexthop when sending the packet
We must use the nexthop instead of destination address
when sending the packet. The current code mixed destination
and nexthop addresses and ignored the nexthop when sending
neighbor solicitation message.

Change-Id: I53887c16ef6fcf8365f1f47ab5792cb208dd273e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-03 15:59:20 +02:00
Luiz Augusto von Dentz
2c1bef4d09 net: Introduce NET_IF_POINTOPOINT flag
This flag can be used by driver to indicate pointopoint links which should
not require destination link address to be resolved.

Jira: ZEP-1656

Change-Id: I58dd3bf48485d6203e75373497e00668317b9825
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-03 15:59:19 +02:00
Luiz Augusto von Dentz
a94f179252 net: Add ll addresses on net_if_send_data
This makes sure ll addresses are properly set before sending reducing the
duplicated code on L2 drivers.

Change-Id: I5330c1d00a344e77555c6f31033ae42af20214bf
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-03 15:59:17 +02:00
Ravi kumar Veeramally
4540a73b59 net: Use lighter printk() instead of printf()
Use printk(), snprintk() instead of printf() and snprintf().
CONFIG_STDOUT_CONSOLE is anyway disabled by default so printf()
will not output anything without it.

Change-Id: I9ad778e318fe999e79ec34182f2de8574e45b7d4
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:51 +02:00
Jukka Rissanen
d3301aae88 net: ipv6: Check neighbor pointer in NS reply timeout
If neighbor is not found, then ignore the timeout.

Coverity-CID: 157583

Change-Id: Ia2199970bd862e43901f5717025271c11c74af5e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:18 +02:00
Michael Scott
f3c66e5205 net: ipv6: fix NULL reference in handle_ra_neighbor
lladdr.addr doesn't point to any storage value when it's
handed off to the net_nbuf_read function.  This results
in a write to an undefined area of memory.

Fix this by pointing lladdr.addr to a net_linkaddr_storage
structure's byte storage array which can handle the maximum
specified length.

Change-Id: I05e0a0420b262ba1e5ac95cebe1f0d91f54878ce
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:16 +02:00
Michael Scott
7b674cb287 net: linkaddr: introduce net_linkaddr_set function
The net_linkaddr_storage structure contains an array of bytes used
to store the link address.  This array can be different sizes
depending on the CONFIG options used when building.  To facilitate
consistency and error checking let's introduce a new helper function
to copy the addr and len values to this structure.

Also move all uses of memcpy related to net_link_storage structures to
the new helper function.

Change-Id: Ic547d86b07e62e5ac3bc330d4eaeb4508a143200
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:16 +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
Andy Ross
a5b694fbbc net: tcp: Select correct source address for SYNACK packets
The source address for a TCP SYNACK must (obviously) be the same as
the destination address of the SYN that produced it.  But the existing
IP packet creation routines would simply fill in a default address
from the net_context struct, which is correct for *established*
connections, but for the listening socket is generally INADDR_ANY
(i.e. all zeroes) and will result in an arbitrary choice for source
address (e.g. a link-local address on the same interface) which can
easily be wrong.

So we need to pass the correct address all the way down from the SYN
packet handler code through the net_ipv*_create() packet creation
functions.  This requires lots of API plumbing, but relatively little
logic change.

Change-Id: Ic368f8cef6689f8a27cbafd5933a4964d5cc457e
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-06 08:21:15 -05: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
Tomasz Bursztyka
06e2b421af net: statistics: Make statistics calculation fully private
Let's change from macros to inlined function to make things nicer.

Change-Id: Ie98e0667613961b03c84ca60bc551d0f473765f6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Flavio Santes
9216e6c47d net: Add ARG_UNUSED
This patch adds the ARG_UNUSED macros to some function arguments
to avoid compiler warnings.

Change-Id: Iae2cd3018c9442ffa9268fdfd33eb9a21f55087c
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-21 12:54:49 +00:00
Johan Hedberg
fc21a76db6 net: Fix incorrect logging format specifiers
Fix compilation issues that show up if SYS_LOG is mapped to printk
instead of printf. Unlike printf, printk is annotated so that the
compiler catches incorrect format specifiers passed to it.

Change-Id: Iab7cc6da110e9c98720211a6f773dcf055a3a411
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-07 13:15:58 +00: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/ipv6.c (Browse further)