Commit Graph

6851 Commits

Author SHA1 Message Date
Jacob Berg Potter
f7ff2d416c ports/freertos: add missing include of tcpip.h
To fix build (lock_tcpip_core is not defined otherwise)
2021-01-23 13:41:34 +01:00
Erik Ekman
651d0af0b6 netdb: Accept '0' as service in lwip_getaddrinfo
Fixes bug #59925
2021-01-22 20:20:51 +01:00
Erik Ekman
c825eb3604 tcp: Check tcp_output return values in tests
Found with clang-analyzer
2021-01-19 20:19:02 +01:00
Erik Ekman
21fba21054 test/unit: Update convenience makefile
Allow cleaning - useful when switching compiler between GCC/clang.
2021-01-19 20:19:02 +01:00
Erik Ekman
b5618c51ca altcp: Fix memory leak in altcp_tls_free_config
Reported in bug #59032 by Ondrej Lufinka,
fix suggested by David GIRAULT.
2021-01-13 22:19:47 +01:00
Erik Ekman
ecab77654a ports/unix/check: Ignore error from fail_* macros
Usage of fail_if/fail_unless macros with a message results in a
warning with the latest version of check (0.15.2+) and GCC.

Ignore this specific error (since warnings are treated as errors) for now.

Example failure:

In file included from ../../../../src/../test/unit/lwip_check.h:7,
                 from ../../../../src/../test/unit/lwip_unittests.c:1:
../../../../src/../test/unit/lwip_unittests.c: In function ‘lwip_check_ensure_no_alloc’:
../../../../src/../test/unit/lwip_unittests.c:55:7: error: too many arguments for format [-Werror=format-extra-args]
   55 |       "mem heap still has %d bytes allocated", lwip_stats.mem.used);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-01-13 21:48:03 +01:00
Erik Ekman
7b77378ed8 test/unit: Fix compilation of ip4 test
../../../../src/../test/unit/ip4/test_ip4.c: In function ‘test_ip4_icmp_replylen_short’:
../../../../src/../test/unit/ip4/test_ip4.c:291:35: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
   fail_unless(linkoutput_byte_ctr == icmp_len + sizeof(unknown_proto));

Plus minor cleanup in second icmp reply test
2021-01-13 21:31:19 +01:00
Erik Ekman
d0c214feff test/unit: Add convenience Makefile
To allow running them easily on *nix without changing directory.
2021-01-13 20:57:23 +01:00
Erik Ekman
35550eeab3 icmp: Fix copied length in response packets
Fixes bug #59364, reported by Yi Guai
2021-01-13 20:31:55 +01:00
Mike Kleshov
c6777547f6 Make sure tag insertion is complete when tag is followed by EOF.
See bug #59728.

Signed-off-by: Mike Kleshov <m.kleshov@gmail.com>
2021-01-01 11:26:30 +03:00
Erik Ekman
2d0c49adca Clean up COPYING
No need to have comment block.
2020-12-05 09:48:51 +01:00
Erik Ekman
d6a37b1ad6 fuzz: Improve Makefile
Similar to recent change to ports/unix/check:
- Split depfile into three different files
- Fix make dep
- Skip depfile generation for 'make clean'
2020-12-04 10:51:11 +01:00
Erik Ekman
45332ab38c ports/unix/check: Fix 'make dep'
It used to fail with this error after building the depfiles:

clang -DLWIP_NOASSERT_ON_ERROR -I/usr/include/check -I../../../../src/../test/unit -Wno-gnu-zero-variadic-macro-arguments -g -DLWIP_DEBUG -Wall -pedantic -Werror -Wparentheses -Wsequence-point -Wswitch-default -Wextra -Wundef -Wshadow -Wpointer-arith -Wcast-qual -Wc++-compat -Wwrite-strings -Wold-style-definition -Wcast-align -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Wunreachable-code -Wuninitialized -Wmissing-prototypes -Wredundant-decls -Waggregate-return -Wlogical-not-parentheses -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -Wdocumentation -Wno-documentation-deprecated-sync -I. -I../../.. -I../../../../src/include -I../../../ports/unix/port/include -c
clang-11: error: no input files

Also don't include depfiles while cleaning, to avoid generating them
just to remove them.
2020-12-03 21:55:45 +01:00
Erik Ekman
63fb3721ef ports/unix/check: Split depfiles for faster build
Having just one depfile (.depend) means it has to be fully regenerated
on every change, and it can't be done in parallel.

After this change the rebuild time after touching a single test file has
gone from 5.0 to 0.9 seconds. (make -j12)

Build of tests from clean has gone from 8.1 to 5.5s.

We could go even further and have one depfile per c-file, but this felt
like a simple first step giving a nice improvement.
2020-12-03 21:41:31 +01:00
Erik Ekman
c748395bda PPP: Change data argument in sio_write to const
To fix the build after ppp_output_cb started taking it as const in
commit b2d1fc119d.

Fixes this failure:
../contrib/examples/ppp/pppos_example.c: In function ‘ppp_output_cb’:
../contrib/examples/ppp/pppos_example.c:163:29: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual]
   return sio_write(ppp_sio, (u8_t*)data, len);
                             ^
2020-12-03 09:47:00 +01:00
Sylvain Rochet
d1fc5c2ec4 PPP: add one more timer to PPP_NUM_TIMEOUTS_PER_PCB for late authentication
Authentication timer might still be running when entering network phase
for any necessary rechallenge, mostly for PPP server support.

Update the detailed analysis of simultaneously running PPP timers
taking into account the authentication timer that might still be
running and chose to increase the base number to 2 instead of
adding more unnecessary complexity.
2020-11-17 01:19:21 +01:00
Sylvain Rochet
9a9d92a59e PPP, PAP: cancel PAP timeout when authentication succeed or fail
upap_timeout is not currently stopped on authentication success or
fail events. This may have strange results if session is restarted
in a high pace because even if the timeout callback have a sanity
check against the PAP state the session can be restarted and be
back in the valid state before the timeout callback is actually
called.
2020-11-17 00:50:50 +01:00
Sylvain Rochet
3013e1fc19 PPP: remove unused ppp_pcb CHAP fields if server mode is disabled
pcb->settings.chap_timeout_time and pcb->settings.chap_max_transmits
are only used if server mode is enabled.
2020-11-17 00:26:32 +01:00
Sylvain Rochet
a4514cf416 PPP: fix unused parameter warning on prot_flavor if CHAP support is disabled
prot_flavor parameter is only used if CHAP support is enabled.
2020-11-16 22:26:00 +01:00
Sylvain Rochet
332119d7e0 PPP, magic: dot not assume LWIP_RAND will return 32 bits of randomness
Do not assume LWIP_RAND will return 32 bits of randomness because it is
probably going to be defined to directly return the rand() value. For
example, LCP magic numbers are 32-bit random values.
2020-10-27 21:52:18 +01:00
Sylvain Rochet
e239222775 PPP, magic: cleanup code and documentation
Documentation and simple code cleanup, no behavior change.
2020-10-27 21:47:26 +01:00
Sylvain Rochet
72d9132ecf PPP, PPPoL2TP: skip address & flags for PPP control packets
This is already what we inherently have always done for IPv4/IPv6
packets, so it works. Receivers must handle both cases anyway because
both behaviors are seen in the wild.
2020-10-23 17:34:25 +02:00
Sylvain Rochet
a494b990da PPP, PPPoS: drop in flight packets from the tcpip mailbox if PPP session is down
A previous call to ppp_input might have disconnected the session while
there were still packets in flight in the tcpip mailbox. Drop incoming
packets because ppp_input must never be called if the upper layer is
down.
2020-10-22 23:03:56 +02:00
Sylvain Rochet
a9f19cd7f1 PPP, PPPoS: only check open flag after events that may have changed it
Speed-up a little bit the PPPoS input parser by only checking the open
flag after calling the ppp_input function, the only one that can induce
a state change here.
2020-10-22 20:56:23 +02:00
Sylvain Rochet
22f13c24aa PPP: assert if ppp_set_* functions are called when session is not dead
ppp_set_* functions that set the PPP session parameters must only be
called when the session is in a dead state (i.e. disconnected),
otherwise not fatal but surprising results may happen.
2020-10-21 02:11:59 +02:00
Sylvain Rochet
dbb7c00aa5 PPP: add LWIP_ASSERT_CORE_LOCKED to ppp_set_notify_phase_callback
This function call the notify phase callback that should be called from
the lwIP core thread. This is especially true if the user callback
is not designed to be reentrant.
2020-10-21 01:43:57 +02:00
Freddie Chopin
c18a8dc9cc PPP, PPPoS: Remove useless cast from pppos_output_append() and pppos_output_last()
pppos_output_cb_fn() now takes `const void*`, so there is no need to
cast the payload (`void*`) to anything else.
2020-10-20 05:38:05 +02:00
Freddie Chopin
b2d1fc119d PPP, PPPoS: Use const void* instead of u8_t* in pppos_output_cb_fn()
There is no good reason why this function should take a non-const
pointer, as the output callback should never modify what lwIP gives it.
While changing that also switch to a more generic `void*` instead of
"byte".
2020-10-20 05:38:03 +02:00
Freddie Chopin
7f91a71eca Contrib, PPP: Remove trailing whitespaces in pppos_example.c 2020-10-20 05:30:59 +02:00
Freddie Chopin
34156e0594 PPP, PPPoS: Remove useless cast from pppos_input_sys()
pppos_input() now takes `const void*`, so there is no need to cast the
payload (`void*`) to anything else.
2020-10-20 05:30:21 +02:00
Freddie Chopin
5ad2f06333 PPP, PPPoS: Use const void* instead of u8_t* in pppos_input()
There is no good reason why this function should take a non-const
pointer. While changing that also switch to a more generic `void*`
instead of "byte".
2020-10-20 05:30:17 +02:00
Freddie Chopin
c5021bdc4d PPP, PPPoS: Use const void* instead of u8_t* in pppos_input_tcpip()
There is no good reason why this function should take a non-const
pointer. While changing that also switch to a more generic `void*`
instead of "byte".
2020-10-20 05:30:12 +02:00
Sylvain Rochet
3b57750715 PPP: remove LWIP_ASSERT_CORE_LOCKED on ppp_set_auth function
We do not have equivalents in PPPAPI for ppp_set_* functions because
calling them only makes sense while session is disconnected, furthermore
they are only setting structure members of the session configuration.
2020-10-20 04:15:25 +02:00
Sylvain Rochet
9b7cba9643 PPP: don't define PPP_IP if PPP_IPV4_SUPPORT is disabled
Doing so helps a lot at finding places where we have leftovers of IPv4
support when the support is disabled.
2020-10-20 03:59:34 +02:00
Sylvain Rochet
6584002826 PPP, PPPoS: only reserve header space for IPv4 and IPv6 packets if IP forwarding is enabled
We only have to reserve header space for forwarding for IPv4 and IPv6
packets, all other packets are PPP control packets. Doing so reduce
the need of having to coalesce the PBUF chain before PPP processes
control packets.
2020-10-20 03:53:07 +02:00
Sylvain Rochet
e801307738 PPP: set mtu6 too when setting PPP netif MTU
PPP peer can negotiate its MRU, therefore we don't know the MTU we are
going to use before starting PPP. This is an issue because netif_add
function assume that the netif init callback function will set the MTU,
netif_add will then copy mtu to mtu6. We have then to update mtu6 each
time we update mtu to keep them in sync. Doing so is fine because PPP
netif MTU is only updated when the netif is in link down state.
2020-10-20 02:53:46 +02:00
Sylvain Rochet
a39ce0f53b PPP, PPPoS: drop input packets much bigger than our MRU
Our current HDLC decoder does not protect against starving the Rx
PBUF POOL for one packet, most likely due to received garbage on
the serial port.

Prevent starving the Rx pool by checking incoming packets length
against PPP_MRU with a 10% margin because we only want to avoid
filling all PBUFs with garbage, we don't have to be pedantic.

Fixes bug #58441: Invalid PPP data accumulates forever.
2020-10-20 02:18:48 +02:00
Sylvain Rochet
51c6548631 PPP: allow negotiating MRU with PPP_MRU config option
PPP_MRU is now free to be used for what it should have been. Now using
it at PPP init stage to set the wanted MRU value, triggering a MRU
negotiation at the LCP phase.

I doubt anyone needs it anyway, but, well, at least it is fixed and the
MRU/MTU config mess is cleaned.

And while we are at it, better document PPP MRU config values.
2020-10-19 00:53:11 +02:00
Sylvain Rochet
90874392e3 PPP: force default MRU to 1500
RFC1661 mandates that default MRU value, that must be used prior
negotiation of MRU value and if MRU value is not negotiated later, must
be 1500.

That is, any PPP host must accept control frames of at least 1500 when
the PPP session start (there are no way to split them in multiples
frames anyway) and must use a value of 1500 if MRU is no negotiated
during LCP exchanges.

Therefore, having it configurable in ppp_opts is a mistake. It was wrong
and never worked because changing the value never triggered a MRU value
negotiation because it changed both the wanted MRU value and the RFC
default value to which the wanted value is compared to trigger a MRU
negotiation if values are not equal.
2020-10-18 23:54:48 +02:00
Sylvain Rochet
b8640678d6 PPP, LCP: merge PPP_MRU into PPP_DEFMRU
This is actually the same thing, both values are used interchangeably in
various places but their value must be the same.
2020-10-18 22:36:53 +02:00
Sylvain Rochet
331fe2dea2 PPP: rename netif_set/get_mtu to ppp_netif_set/get_mtu
Those are private functions, using the netif_ prefix here is not really
nice, especially with functions named netif_set_mtu and netif_get_mtu
for obvious reasons.
2020-10-18 22:11:18 +02:00
Sylvain Rochet
7633c24213 PPP, PPPoE, PPPoL2TP: remove persistent retries if sending packets fails
We currently retry indefinitely if sending packets fails, for example
if the output interface is down. We are even doing it if we are in
a middle of a connection process. This is not a very nice behavior
because PPP low level will retry indefinitely to connect and the user
application will never be warned that something is wrong.

We have the persist boolean in PPP settings to achieve more or less
the same thing anyway. Except it does it better at only retrying
indefinitely the initiation packet.
2020-10-18 17:10:13 +02:00
Sylvain Rochet
39cb84466d PPP: remove PPP_USE_PBUF_RAM configuration option
Having it configurable does not really make sense anymore, we already
need PBUF_RAM in all transmit paths. There are no real reason to keep
allocating PPP response buffers from the PBUF_POOL which should be now
reserved for receive paths only.
2020-10-18 16:44:23 +02:00
Sylvain Rochet
012fadd77f PPP: enable PPP_USE_PBUF_RAM by default
We need PBUF_RAM for quite a while for PPP, e.g. through pbuf_coalesce
and for all PPP transmit paths. There are no real reason to keep
allocating packets from PBUF_POOL for PPP control packets transmit path
by default today.
2020-10-18 02:34:43 +02:00
Sylvain Rochet
6b30cf62cc PPP, PPPoL2TP: fix displayed length in debug message
Packet length is p->tot_len here, not len.
2020-10-18 02:29:42 +02:00
Sylvain Rochet
5bf9cebb54 PPP: check that pbuf_coalesce succeed
When pbuf_coalesce fails it does nothing and returns the previous buffer
chain. Adds checks that pbuf_coalesce succeeded, otherwise drop incoming
packet.
2020-10-18 02:18:50 +02:00
Sylvain Rochet
7c0c3879b2 PPP, PPPoS: use PBUF_RAM in transmit pathway
Allocate Tx chunk in PBUF_RAM, using PBUF_POOL_BUFSIZE as a great
chosen value for chunk size.
2020-10-18 01:44:09 +02:00
Sylvain Rochet
3779cf7856 PPP, PPPoS: wait for next packet when we drop a packet before it is complete
If we fail to receive a full packet, for exemple if a memory allocation
fail for some reason, we currently do not wait for next packet flag
character and we start filling a new packet at next received byte. Then
we expect the checksum check to discard the packet.

The behavior seem to have been broken one or two decades ago when adding
support for PFC (Protocol-Field-Compression) and ACFC
(Address-and-Control-Field-Compression).

Rework to drop any character until we receive a flag character at init
and when we drop a packet before it is complete.
2020-10-17 20:09:35 +02:00
Sylvain Rochet
88ac7460f0 PPP: cleanup
Code cleaning only (misleading indents or comments, etc.), no behavior
change.
2020-10-17 17:53:04 +02:00
Sylvain Rochet
bedb4e4745 PPP: disable VJ support by default
VJ support is known to be broken when built with some compiler
optimizations enabled, disabling it by default until someone needs it
and fixes it.

It was mostly used with dial-up modems, it is useless with PPPoE and
PPPoL2TP and is probably useless as well with cellular modems, so
disabling it by default makes sense anyway.
2020-10-17 01:19:35 +02:00