According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:
sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Takes the modem state machine by calling lcp_close instead of lcp_down
Using this method the LCP layer sends a TERMINATE_REQ to the modem and the
network interface is only taken down when the LCP layer has properly
finished.
Moved the ppp_mgmt_raise_carrier_off_event and net_if_carrier_down
to lcp.c to avoid breaking the interface.
Tested on a real modem.
Fixes: zephyrproject-rtos#41627
Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
A common pattern here was to take the work item as the subfield of a
containing object. But the contained field is not a k_work, it's a
k_work_delayable.
Things were working only because the work field was first, so the
pointers had the same value. Do things right and fix things to
produce correct code if/when that field ever moves within delayable.
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
When support for custom MRU/MTU was added with
CONFIG_NET_L2_PPP_OPTION_MRU=y, code flow with
CONFIG_NET_L2_PPP_OPTION_MRU=n has been broken due to lack of valid
'ctx->lcp.my_options.mru' initialization and its use (with value 0) in
the implementation.
Initialize 'ctx->lcp.my_options.mru' unconditionally in lcp_init(), so
that PPP works fine with CONFIG_NET_L2_PPP_OPTION_MRU=n.
Fixes: 8a51a79d89 ("net: l2: ppp: possibility to have a custom
MRU/MTU")
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Reading a set MTU from the used net_if when starting LCP.
This enables also other custom MTU/MRU to be set for the link than
the default CONFIG_NET_PPP_MTU_MRU (set by a ppp driver during
initialization).
Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
With the introduction of `EXPERIMENTAL` and `WARN_EXPERIMENTAL` in
Zephyr all subsys/net and drivers/ethernet/Kconfig.e1000 settings
having `[EXPERIMENTAL]` in their prompt has has been updated to include
`select EXPERIMENTAL` so that developers can enable warnings when
experimental features are enabled.
The following settings has EXPERIMENTAL removed as they are considered
mature:
- NET_OFFLOAD
- NET_PROMISCUOUS_MODE
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This migrates all the current iterable section usages to the external
API, dropping the "Z_" prefix:
Z_ITERABLE_SECTION_ROM
Z_ITERABLE_SECTION_ROM_GC_ALLOWED
Z_ITERABLE_SECTION_RAM
Z_ITERABLE_SECTION_RAM_GC_ALLOWED
Z_STRUCT_SECTION_ITERABLE
Z_STRUCT_SECTION_ITERABLE_ALTERNATE
Z_STRUCT_SECTION_FOREACH
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Following commits will remove k_work from net_pkt, so convert
PPP L2 to use k_fifo when sending PPP data.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use recently introduced API, which takes care of gracefully closing any
pending DNS requests and replacing existing DNS server list with new
one.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Replace all existing deprecated API with the recommended alternative.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Create net_l2_send() function which will be called by each L2
sending function so that we can catch all the network packets
that are being sent. Some L2 layers send things a bit differently,
so in those cases call the net_capture_send() directly by the L2
layer.
Add network packet capture call in receive side after the pkt has
been received by the RX queue handler. This avoids calling the
net_capture_send() from ISR context.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Introducing PPP dialup features to enable e.g. usage of nrf9160
based board as a dialup modem for transferring ip data over PPP
(e.g. windows dial up), i.e. usage of Zephyr PPP as a server for
providing MTU/MRU, IP address and DNS addresses for a PC:
- PPP LCP MRU option (configurable)
- PPP server: IPCP ip and dns address peer options to enable
providing IP and DNS addresses for PPP peer.
Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
net_ppp_carrier_on() and net_ppp_carrier_off() call k_work_init() on
work item that can be pending or still be processed in another thread.
This results in undefined behavior.
Initialize work item once and use an atomic flag to switch between
up/down carrier state. Submit work to workqueue whenever up/down carrier
state changes, so that last state is always properly propagated to
network interface layer.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Currently there is no way to distinguish between a caller
explicitly asking for a semaphore with a limit that
happens to be `UINT_MAX` and a semaphore that just
has a limit "as large as possible".
Add `K_SEM_MAX_LIMIT`, currently defined to `UINT_MAX`, and akin
to `K_FOREVER` versus just passing some very large wait time.
In addition, the `k_sem_*` APIs were type-confused, where
the internal data structure was `uint32_t`, but the APIs took
and returned `unsigned int`. This changes the underlying data
structure to also use `unsigned int`, as changing the APIs
would be a (potentially) breaking change.
These changes are backwards-compatible, but it is strongly suggested
to take a quick scan for `k_sem_init` and `K_SEM_DEFINE` calls with
`UINT_MAX` (or `UINT32_MAX`) and replace them with `K_SEM_MAX_LIMIT`
where appropriate.
Signed-off-by: James Harris <james.harris@intel.com>
This lets an application detect when a PPP connection fails to establish
or terminates, so that the connection can be reattempted (for example,
by setting carrier off and on).
Signed-off-by: Jim Paris <jim@jim.sh>
If an address was obtained by IPCP, it should always be removed in
ipcp_down(). This commit replaces the predicate with something slightly
more robust.
Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
Without removing the stale address obtained during IPCP, it will still
be present the next time we do IPCP, marked as "in use" by the network
stack even if it is stale. This turned out to be a showstopper for
restarting the PPP stack on devices without static IP.
Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
PPP Phase Diagram [1] allows only one way phase change. In current
implementation there is an additional RUNNING phase, which is entered
just after NETWORK phase.
Prevent going back from RUNNING to NETWORK phase when Term-Req was
received, as this is meaningless for overall PPP operation and violates
PPP Phase Diagram property of having one way direction change.
This change also improves Adminitrative Close handling (calling
lcp_close()). This request results in moving into TERMINATE phase. Then
LCP is put down (by calling lcp_down()) and then ppp_link_down() is
called, which so far (before this patch) resulted in moving back to
NETWORK and then to DEAD. Right now (after this patch) we move directly
from TERMINATE to DEAD phase, which is exactly how [1] specifies it.
[1] https://tools.ietf.org/html/rfc1661#section-3.2
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
State Transition Table [1] specifies that Administrative Close should
result in CLOSING state. This is not respected in case of LCP, as
STOPPED state was forced in lcp_close().
Don't force going into STOPPED state in lcp_close() and rely on
ppp_fsm_close() to move to CLOSING state instead.
This patch fixes overall Adminitrative Close procedure and allows to
move back into fully operating PPP connection once again after
Adminitrative Open.
[1] https://tools.ietf.org/html/rfc1661#section-4.1
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This patch implements optional authentication phase, which is done
between link establishment and network phases. It is part of LCP option
negotiation to decide whether authentication is needed and which
protocol will be used. For now we add only PAP support and try to
negotiate it when some other protocol (e.g. CHAP or EAP) is proposed
earlier. For simplicity reason we only add one way authentication
support, which means that we try to authenticate to the other peer, but
do not require authentication from it.
This is an important step to make PPP work with cellular network modems,
because most of them require to provide username and password within PPP
authentication phase. Those credentials are used by modem to login to
cellular network. In most cases however it is enough to provide dummy
values, because they are not verified. For this reason and simplicity of
this patch we hardcode PAP Peer-ID and Password now.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This module had only some header includes, without actual code. Remove
it, as it is better to create one module per authentication protocol
anyway.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Add enums of PAP, CHAP and EAP authentication protocols. Also add their
string representations, so they will nicely show up in logs during
debugging.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Interpret -EINVAL return value from options' parse() callback as "option
value is not supported". After receiving such value nack() callback will
be executed in order to put supported value in the response.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This macro has no use in code and was most probably replaced by
FSM_TIMEOUT (which resolves to CONFIG_NET_L2_PPP_TIMEOUT) with the same
default value.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Those macros are not used anymore after commit 35a2519091 ("net: l2:
ppp: add generic function for handling Conf-Req"), because we no longer
need preallocated table on stack for parsing option information.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This option is not used after commit 50b2cafc42 ("net: l2: ppp: use
net_pkt API for replying to Configure-Req") has been applied. We don't
need to preallocate table on stack for parsing option information, so
information about maximum number of supported options is useless.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Drop unused ppp_parse_options_array() function and 'struct
ppp_option_pkt' data type. Both were used in initial PPP implementation,
but are not longer needed after recent PPP refactoring.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Introduce new ppp_config_info_req() function that can be used in order
to handle options received within Conf-Req packet. As an input it takes
array of supported options. If received Conf-Req packet contains unknown
options, then a Conf-Rej packet is automatically generated with all of
those options. If all of received options are supported, then function
continues to parse each provided option individually by calling option
specific callbacks.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Use a generic handler for received options in Conf-Rej packet. This will
mark all those options as rejected, to they will no longer be included
in subsequence Conf-Req packets.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Use a generic handler for received options in Conf-Rej packet. This will
mark all those options as rejected, to they will no longer be included
in subsequence Conf-Req packets.
This allows to communicate with PPP peers, which do not support DNS1 and
DNS2 options.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
So far there was no generalized way how to handle negotiation of "my
options" (those sent with Conf-Req packet to peer). Peer response for
proposed options and their values were not tracked in any way, so
rejected (by peer) options were sent over and over again in subsequent
Conf-Req packets. In case of IPCP it means that all sent options such as
IP_ADDRESS, DNS1, DNS2 were mandatory for being supported by peer in
order to successfully finish negotiation. For example if 'pppd' was the
configured peer (e.g. when using with QEMU and net-tools scripts),
without ms-dns being configured (which is the default), then "my
options" negotiation failed.
Introduce generalized mechanism for negotiating "my options", so it is
easier to maintain current set of supported options and easily add new
options to the implementation in future. FSM instance inititialization
function can provide information about supported "my options".
Information is is passed as a table of 'struct ppp_my_option_info'
containing:
* option code (type),
* callback for adding option to Conf-Req packet,
* callback for received Conf-Ack with that option,
* callback for received Conf-Nak with that option.
Store also runtime information about each negotiated option. First of
all remember which options have been rejected, so they are not sent to
peer once again in the next Conf-Req packet. This will solve issue with
IPCP negotiation when peer doesn't support DNS1 or DNS2 options. Keep
also track about which options have been acked, so such information can
be verified before bringing FSM instance up.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Rework implementation of ppp_parse_options() to be more generic and
flexible to use. Pass callback and user data for parsing each option
separately.
Keep old functionality of ppp_parse_options() accessible via
ppp_parse_options_array() function. This will make sure that old code
using this function doesn't need to be changed now. There are plans
however to remove ppp_parse_options_array() once there are no more users
of it in future.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Use net_pkt API to assemble Configure-Req messages. Compared to net_buf
API it allows us to simplify code.
Remove append_to_buf() helper functions, as their functionality is now
totally replaced by net_pkt API. Additionally net_pkt API handles data
that wraps several net_buf packets, which was not the case with
append_to_buf().
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Use net_pkt instead of net_buf API for replying to Configure-Req. We use
the fact that for now we reply with either Configure-Ack or
Configure-Rej only. In both cases we can allocate net_pkt ahead, because
we know its maximum length (which is equal to length of received
Configure-Req packet).
Make also an improvement in generic FSM code and reply with
Configure-Rej to all Configure-Req for which there is no config_info_req
callback set. Use that to drop LCP specific Conf-Req handling code,
because there is no option properly supported there yet.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
So far ppp_parse_options() has returned enum net_verdict. This type was
never used directly by network stack. Instead, caller was always
checking for NET_OK and returning error code in case of failure.
Change implementation of ppp_parse_options(), so it returns error code
in case of error and 0 when succeeded. This better fits its generic
purpose.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
There is no allocation in ppp_l2.c file, which mean that
BUF_ALLOC_TIMEOUT macros is not used anywhere. Drop it.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
There was a race condition when ppp_fsm_open() was called in CLOSED
state. Conf-Req was sent first, then state was changed to
REQUEST_SENT. In the meantime however we have already received Conf-Req
to which we responded with Term-Ack.
Change state before sending Conf-Req, so we handle Conf-Req from peer
properly instead of dropping it.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
is_init field is useless, because there is only single code path that
always sets it to true before using it.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Make sure IPv6 address is removed from network interface in IPV6CP
protocol down handler. This makes sure that application can receive
high-level notification about missing network connection.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Make sure IPv4 address is removed from network interface in IPCP
protocol down handler. This makes sure that application can receive
high-level notification about missing network connection.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
The Z_STRUCT_SECTION_ITERABLE() provides an alignment so remove
the 32 byte alignment for net_if and ppp_protocol_handler structs.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use system provided Z_STRUCT_SECTION_FOREACH() and
Z_STRUCT_SECTION_ITERABLE() macros instead of manually coding
everything for network sections.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Single work object for whole fsm was not being able to handle more than
single packet at a time. Because of that we have overwritten already
scheduled packets, resulting in fsm timeout and net_pkt leak.
Use net_pkt work object instead, so we can safely schedule more than a
single packet.
This commit also drops workaround for qemu_x86 unit testing.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Currently there is a single function that handles both Configure-Ack and
Configure-Rej messages. This is obviously wrong for Configure-Rej,
because implementation applies options received in the message.
Remove Configure-Rej callback, so those frames are simply ignored for
the time no valid handling code exists.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Clear negotiated options in protocol down handler. That way all
addresses are properly requested (by sending 0.0.0.0 in Configure-Req)
in the subsequent option negotiation phases.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
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>
There is already a variable 'network_protos_up', which stores number of
network protocols being up. Additionally each network protocol has its
own state represented by is_ip{,v6}cp_up. Use the latter in FSM up() and
down() callbacks.
This fixes a case when both IPCP and IPv6CP protocols are going
down. When using ctx->is_network_up only one of them (the first) was
deinitialized correctly, second stayed always up (at least partially,
e.g. not calling ppp_network_down()).
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Each PPP packet sent on wire needs to have at least 4 bytes length. Set
that length for outgoing Term-Req and Term-Ack packets. Also update
length validation to check for at least 4 bytes instead of at least 1
byte.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>