project/odhcp6c.git
3 weeks agoodhcp6c: RFC comments
Paul Donald [Thu, 13 Nov 2025 00:43:06 +0000 (01:43 +0100)]
odhcp6c: RFC comments

make spec easier to identify

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
3 weeks agoall: spell fixes
Paul Donald [Wed, 12 Nov 2025 23:44:40 +0000 (00:44 +0100)]
all: spell fixes

spelling fixes

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
3 weeks agodhcpv6: dhcpv6_handle_reply switch case handling
Paul Donald [Thu, 13 Nov 2025 10:37:25 +0000 (11:37 +0100)]
dhcpv6: dhcpv6_handle_reply switch case handling

shortens jumps and reduces branching.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
3 weeks agodhcpv6: dhcpv6_handle_advert; migrate if blocks to switch case
Paul Donald [Tue, 11 Nov 2025 14:27:43 +0000 (15:27 +0100)]
dhcpv6: dhcpv6_handle_advert; migrate if blocks to switch case

reduces branching

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
3 weeks agodhcpv6: migrate to switch case for dhcpv6_handle_reply
Paul Donald [Tue, 11 Nov 2025 16:40:02 +0000 (17:40 +0100)]
dhcpv6: migrate to switch case for dhcpv6_handle_reply

Indent the if blocks (squash with previous commit)

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
3 weeks agodhcpv6: migrate to switch case for dhcpv6_handle_reply
Paul Donald [Tue, 11 Nov 2025 16:57:36 +0000 (17:57 +0100)]
dhcpv6: migrate to switch case for dhcpv6_handle_reply

This cleans up the logic handling a bit, and accelerates the if compares to
jumps. Improves readability. Do not indent some if blocks to make diff easier
to compare.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
3 weeks agoall: drop CER_ID
Paul Donald [Tue, 11 Nov 2025 14:09:26 +0000 (15:09 +0100)]
all: drop CER_ID

We have removed it from odhcpd since this never saw adoption. Remove here also.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
3 weeks agodhcpv6: refactor u8 and u16 to u32 to avoid boolean coercion
Paul Donald [Mon, 10 Nov 2025 17:26:16 +0000 (18:26 +0100)]
dhcpv6: refactor u8 and u16 to u32 to avoid boolean coercion

ubus coerces u8 to boolean, and one workaround suitable is to amend u8
values (despite them being and containing only a u8 int) to u32 values. ubus
coerces u8 to booleans due to historical reasons. Any calls to e.g.

ubus call odhcp6c.eth1 get_state

(and subsequently downstream dependencies which use this invocation)

return booleans(!) where there shall be a number.

Amended calls to blobmsg_add_u8 into blobmsg_add_u32 to resolve this.
Amended calls to blobmsg_add_u16 into blobmsg_add_u32 also.

Apparently u8 and u16 get padded to u32 anyway.

See @nbd168 https://github.com/openwrt/libubox/pull/25#issuecomment-3512957433
"
I'd prefer to just deprecate treating u8 as integer and deprecate using u16 in
blobmsg entirely. That way we can avoid a lot of compatibility mess and JSON
conversion issues. Due to padding, u8, u16 and u32 attributes have the same
effective size anyway, so there isn't really a good reason to use them for
integer values.
"

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/117
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
3 weeks agotreewide: Replace _unused with _o_unused
Hauke Mehrtens [Sun, 9 Nov 2025 12:26:21 +0000 (13:26 +0100)]
treewide: Replace _unused with _o_unused

A header file in the Linux kernel on powerpc uses the variable name
_unused. This causes the following compile error:
```
In file included from /staging_dir/toolchain-powerpc_8548_gcc-14.3.0_musl/include/signal.h:48,
                 from /staging_dir/target-powerpc_8548_musl/usr/include/libubox/uloop.h:25,
                 from /staging_dir/target-powerpc_8548_musl/usr/include/libubus.h:24,
                 from /build_dir/target-powerpc_8548_musl/odhcp6c-2025.11.04~b3e1db42/src/ubus.h:67,
                 from /build_dir/target-powerpc_8548_musl/odhcp6c-2025.11.04~b3e1db42/src/ubus.c:73:
/staging_dir/toolchain-powerpc_8548_gcc-14.3.0_musl/include/bits/signal.h:27:30: error: expected identifier or '(' before '[' token
   27 |         unsigned long _unused[4];
      |                              ^
ninja: build stopped: subcommand failed.
make[3]: *** [Makefile:62: /build_dir/target-powerpc_8548_musl/odhcp6c-2025.11.04~b3e1db42/.built] Error 1
```

Use _o_unused instead to avoid such conflicts.

Signed-off-by: Hauke Mehrtens <[email protected]>
4 weeks agodhcpv6: return early upon success
Jerome Küttner [Mon, 20 Oct 2025 16:53:38 +0000 (18:53 +0200)]
dhcpv6: return early upon success

Once a "DHCPV6_Success" status is seen, don’t abort on subsequent
non-Success to prevent "No Address Available" errors.

Signed-off-by: Jerome Küttner <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/90
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoreadme: fix description string
Paul Donald [Tue, 4 Nov 2025 20:36:43 +0000 (21:36 +0100)]
readme: fix description string

The original amendments to README in the prpl patchset contained the same,
but it should read: 'maximum'.

( kind of obvious what it is from the variable name though )

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/115
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agodhcpv6: potential bug fix for checking DHCPV6_OPT_STATUS
Paul Donald [Tue, 4 Nov 2025 18:30:58 +0000 (19:30 +0100)]
dhcpv6: potential bug fix for checking DHCPV6_OPT_STATUS

follow-up to b65ff293a96924f9b19dff8855232bfb9054b976

The previous logic checked that the DHCPV6_OPT_STATUS was more than 2 bytes,
which meant that it would only be evaluated if the options *also* contained a
status message. We should handle this option being exactly 2 bytes, so that
DHCPV6_OPT_STATUS lacking a status message are correctly handled.

The relevant RFC section does not state that status message can be absent
https://www.rfc-editor.org/rfc/rfc8415#section-21.13
but the status message field is variable length and sets no mandates on its
size.

This ensures differing interpretations of this portion are handled adequately.
It's not uncommon that various options behave in this 'can be zero length' way,
so let's handle this option similarly.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/113
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agosrc: add missing if/else braces
Álvaro Fernández Rojas [Tue, 4 Nov 2025 13:52:00 +0000 (14:52 +0100)]
src: add missing if/else braces

The linux kernel coding style suggests using braces in all if/else blocks
if at least one of the blocks has multiple statements:
https://docs.kernel.org/process/coding-style.html
Let's follow that coding style since it makes the code easier to follow.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agotreewide: remove whitespaces at EOL
Álvaro Fernández Rojas [Tue, 4 Nov 2025 13:43:28 +0000 (14:43 +0100)]
treewide: remove whitespaces at EOL

Remove all whitespaces located at the end of the lines.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agosrc: remove pragma once in headers
Álvaro Fernández Rojas [Tue, 4 Nov 2025 13:40:22 +0000 (14:40 +0100)]
src: remove pragma once in headers

Switch existing headers to defines instead of pragma once.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agosrc: reorder includes alphabetically
Álvaro Fernández Rojas [Tue, 4 Nov 2025 13:38:41 +0000 (14:38 +0100)]
src: reorder includes alphabetically

Reorder includes alphabetically which makes them easier to follow and find
duplicates.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agosrc: align SoftAtHome license headers format
Álvaro Fernández Rojas [Tue, 4 Nov 2025 13:23:11 +0000 (14:23 +0100)]
src: align SoftAtHome license headers format

This commit aligns the new SoftAtHome license headers from prpl foundation
with the existing ones.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoreadme: update for prpl patch-set additions
Paul Donald [Tue, 4 Nov 2025 13:34:15 +0000 (14:34 +0100)]
readme: update for prpl patch-set additions

Convert the prpl patch-set additions in markdown.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/111
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoreadme: document all environment options
Paul Donald [Tue, 4 Nov 2025 00:16:27 +0000 (01:16 +0100)]
readme: document all environment options

These options were previously undocumented.
Document also an OPTION_x example.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/111
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoreadme: rewrite in markdown
Paul Donald [Tue, 4 Nov 2025 14:26:53 +0000 (15:26 +0100)]
readme: rewrite in markdown

Convert original README to markdown.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/111
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoodhcp6c: fix safe interval processing to follow RFC 4862
Jonas Lochmann [Mon, 27 Oct 2025 00:00:00 +0000 (01:00 +0100)]
odhcp6c: fix safe interval processing to follow RFC 4862

This resolves an issue occuring in combination with Fritz! upstream
routers that send old prefixes with a valid time of zero for a long
time. Before this change, they were with each received RA extended
to two hours if the prefix was already known before.

Signed-off-by: Jonas Lochmann <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/108
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agodhcpv6: always include IA_NA and IA_PD in Request message if requested
Nicolas BESNARD [Fri, 11 Apr 2025 09:40:27 +0000 (09:40 +0000)]
dhcpv6: always include IA_NA and IA_PD in Request message if requested

RFC7550 says that if you request both IA_NA and IA_PD and only one
option is offered in the Advertise, then the client must send a Request
message (and not a Solicit) and the message SHOULD still include both
IA_NA and IA_PD options.

Problem: A Request message is correctly sent instead of a Solicit but it
doesn't include both IA_NA and IA_PD options.

Solution: If IA_NA and IA_PD are requested, the Request message always
includes both options.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agodhcpv6: fix incorrect IA type being printed in syslog
Nicolas BESNARD [Fri, 11 Apr 2025 09:50:07 +0000 (09:50 +0000)]
dhcpv6: fix incorrect IA type being printed in syslog

Problem: If a status error code is received, "IA_NA" is always written
to syslog.

Cause: IA header type is not converted from network byte order to host
byte order.

Solution: Use ntohs() to convert to host byte order.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoodhcp6c: prevent RELEASE at shutdown when -k is set
Nicolas BESNARD [Thu, 10 Apr 2025 08:51:54 +0000 (08:51 +0000)]
odhcp6c: prevent RELEASE at shutdown when -k is set

Problem: Based on the README, if -k option is set, a RELEASE message
should not be sent when the process is stopped. RELEASE messages are
also not sent in case of a forced RELEASE or reconfiguration, however.

Solution: Stop the transmission of RELEASE messages when the process is
stopped but allow it for a forced RELEASE or reconfiguration.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoodhcp6c: fix client exiting if Renew and Rebind fails
Nicolas BESNARD [Thu, 20 Feb 2025 13:07:05 +0000 (13:07 +0000)]
odhcp6c: fix client exiting if Renew and Rebind fails

Problem: odhcp6c exits when no reply is received from the server after
retransmission of Renew/Rebind messages.

Solution: restart the state machine instead of exiting on retransmission
failure.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoodhcp6c: implement RKAP: Reconfiguration Key Authentication Protocol
Nicolas BESNARD [Fri, 31 Jan 2025 13:44:14 +0000 (13:44 +0000)]
odhcp6c: implement RKAP: Reconfiguration Key Authentication Protocol

Problem: odhcp6c doesn't support authentication protocol other than
the Configuration Token protocol (RFC 3118).

https://www.ietf.org/archive/id/draft-ietf-dhc-rfc8415bis-12.html#name-reconfiguration-key-authent

Solution: implement Reconfiguration Key Authentication Protocol (RKAP)
and add the option to disable all authentication protocols (will discard
all reconfigure messages received).

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agodhcpv6: fix solicit loop when server has no address available
Nicolas BESNARD [Thu, 23 Jan 2025 09:51:31 +0000 (09:51 +0000)]
dhcpv6: fix solicit loop when server has no address available

Problem: If Advertise with status 'noaddravail' is received while IA_NA
is requested, a new Solicit is sent creating an infinite loop.

Solution: Set IA_NA mode to none and send INFO-REQ message if no IA_NA
or IA_PD are available.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoubus: implement ubus methods to force a Renew and Release
Nicolas BESNARD [Wed, 22 Jan 2025 10:21:48 +0000 (10:21 +0000)]
ubus: implement ubus methods to force a Renew and Release

Problem: Renew/Information-Request or Release messages are sent when
odhcp6c receives signal SIGUSR1 or SIGUSR2.
It should also be possible to trigger these messages via a ubus methods.

Solution: Implement two new ubus methods : release() and renew().

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoubus: implement retransmission configuration via ubus
Nicolas BESNARD [Mon, 20 Jan 2025 16:05:29 +0000 (16:05 +0000)]
ubus: implement retransmission configuration via ubus

Problem: odhcp6c uses static retransmission parameters defined in
RFC3315.

Solution: Make retransmission parameters configurable via ubus and
update the default values based on RFC8815.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoodhcp6c: add failure when -E option is used without ubus support enabled
Nicolas BESNARD [Fri, 21 Feb 2025 08:58:17 +0000 (08:58 +0000)]
odhcp6c: add failure when -E option is used without ubus support enabled

Problem: The -E option disables the state script and relies only on ubus
to emit events on state changes. But if odhcp6c is compiled without ubus
support (ENABLE_UBUS flag omitted), odhcp6c has no way to signal state
changes.

Solution: Return an error when -E flag is used and ubus support is
absent.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoodhcp6c: add new argument option to disable script call
Nicolas BESNARD [Tue, 17 Dec 2024 15:28:15 +0000 (15:28 +0000)]
odhcp6c: add new argument option to disable script call

Problem: odhcp6c call user defined script (or /usr/sbin/odhcp6c-update
by default) on every state update. When using ubus event, this feature
is not needed.

Solution: add a new argument option to disable script call on state
update.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoreconfigure: move all configuration functions to a new file
Nicolas BESNARD [Fri, 6 Dec 2024 10:26:07 +0000 (10:26 +0000)]
reconfigure: move all configuration functions to a new file

Tidy up.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoreconfigure: implement DHCP reconfiguration
Nicolas BESNARD [Tue, 26 Nov 2024 16:29:27 +0000 (16:29 +0000)]
reconfigure: implement DHCP reconfiguration

Problem: To update DHCP parameters/options, the process needed to be
restarted with the new arguments. It makes odhcp6c not very flexible,
making it impossible to keep track of the total packet statistics.

Solution: Add a new ubus method to reconfigure DHCP without restarting
the process.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agodhcpv6: implement statistics for DHCPv6
Nicolas BESNARD [Wed, 20 Nov 2024 16:34:30 +0000 (16:34 +0000)]
dhcpv6: implement statistics for DHCPv6

Problem:
    odhcp6c does not provide any statistics.

Solution:
    Count the number of packets transmitted or received by message type.
    Add a UBus RPC method to get this information.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoubus: implement UBus method to get state data immediately
Nicolas BESNARD [Tue, 19 Nov 2024 12:46:22 +0000 (12:46 +0000)]
ubus: implement UBus method to get state data immediately

Problem:
    odhcp6c state data are transmitted when the DHCPv6 state changes.
    If a process subscribes after the start of odhcp6c, then it has to
    wait for the next update event.

Solution:
    Add a new UBus method "get_state" to get the latest state data
    immediately.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoubus: emit UBus event on DHCP state changes
Nicolas BESNARD [Tue, 19 Nov 2024 10:08:36 +0000 (10:08 +0000)]
ubus: emit UBus event on DHCP state changes

Problem:
    Whenever the DHCPv6 state changes a custom shell script provided in
    an argument on process start is called.

Solution:
    In addition to the current script mechanism, emit a UBus event
    whenever the DHCPv6 state changes.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoubus: connect to UBus backend
Nicolas BESNARD [Wed, 20 Nov 2024 13:20:49 +0000 (13:20 +0000)]
ubus: connect to UBus backend

Problem:
    odhcp6c is not connected to UBus making communication with other
    processes more difficult.

Solution:
    Connect odhcp6c to UBus back-end when the WITH_UBUS build time
    configuration option is set.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoodhcp6c: implement asynchronous handling for DHCPv6 State
Nicolas BESNARD [Tue, 29 Oct 2024 10:27:13 +0000 (10:27 +0000)]
odhcp6c: implement asynchronous handling for DHCPv6 State

Problem:
    The DHCPv6 states were previously handled synchronously, meaning
    that while waiting for a response from the server, no other actions
    could be performed in odhcp6c.

    The process would block inside a loop until a valid response was
    received, limiting responsiveness and overall system performance.

Solution:
    The new approach involves sending the requests and then
    asynchronously monitoring the DHCPv6 socket using poll(). By reading
    a response only when there is data available on the socket, the
    system remains non-blocking.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoodhcp6c: enable Non-Blocking DHCPv6 Socket
Nicolas BESNARD [Tue, 29 Oct 2024 10:06:15 +0000 (10:06 +0000)]
odhcp6c: enable Non-Blocking DHCPv6 Socket

Problem:
    The DHCPv6 socket is currently set to blocking mode, which causes
    the program to pause execution whenever it attempts to read from the
    socket. This can lead to delays and hinder the overall
    responsiveness of the application.

Solution:
    Add the set_nonblocking() function, using fcntl() to set the
    O_NONBLOCK flag, allowing the socket to operate in non-blocking
    mode.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agodhcpv6: refactor dhcp_request Function
Nicolas BESNARD [Mon, 28 Oct 2024 14:41:51 +0000 (14:41 +0000)]
dhcpv6: refactor dhcp_request Function

Problem:
    The current implementation of the dhcp_request function handles both
    sending and receiving messages within the same function. This makes
    the function a blocking one, as it waits for a valid response before
    proceeding, causing potential delays.

Solution:
    The dhcp_request function is refactored into two functions:
    one for sending DHCP messages and another for receiving them.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agodhcpv6: add t1 and t2 transmission
Nicolas BESNARD [Fri, 25 Oct 2024 15:24:34 +0000 (17:24 +0200)]
dhcpv6: add t1 and t2 transmission

Problem: there was no way to get access to the t1 and t2 that the
dhcpv6 server sends to the client

Solution: add the timing in the Prefix and Address sent to the
environment.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agodscp: add option to set dscp value
Nicolas BESNARD [Mon, 30 Sep 2024 09:58:35 +0000 (11:58 +0200)]
dscp: add option to set dscp value

Problem: odhcp6c doesn't support change of DSCP value.

Solution: Adapt odhcp6c to set socket option to change the DSCP value
for dhcpv6 packets.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agodhcpv6: fix wrong retransmission of DHCPv6 Solicit
Nicolas BESNARD [Tue, 14 May 2024 14:19:15 +0000 (16:19 +0200)]
dhcpv6: fix wrong retransmission of DHCPv6 Solicit

When the DHCPv6 client sends a DHCPv6 Solicit with both IA_NA and IA_PD
options, and if the server replies with a status code = NoAddrsAvailable
in the IA_NA option, then currently the DHCPv6 client sends a new
Solicit with only the IA_PD option despite the fact that a prefix was
sent by the server in the previous Advertise.

This behavior is described in
https://datatracker.ietf.org/doc/html/rfc7550#section-4.2

The client must handle the case of a server that does not offer both
valid IA_NA and IA_PD options when both are requested, according to
RFC 7550. It should not send a new Solicit, but a Request. The client
should, however, ignore the Advertise message if none of the IA_NA and
IA_PD options are offered by the server.

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agoodhcp6c: add a simple build script
Álvaro Fernández Rojas [Mon, 3 Nov 2025 11:29:46 +0000 (12:29 +0100)]
odhcp6c: add a simple build script

Should make it a little bit easier for people who want to contribute.

Link: https://github.com/openwrt/odhcp6c/pull/110
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agocmake: make libubox mandatory
Álvaro Fernández Rojas [Mon, 3 Nov 2025 08:58:29 +0000 (09:58 +0100)]
cmake: make libubox mandatory

- Drop USE_LIBUBOX from cmake.
- Drop downstream MD5 implementation.
- Drop libubox variants from Github CI.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/109
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agocmake: drop EXT_PREFIX_CLASS
Álvaro Fernández Rojas [Mon, 3 Nov 2025 08:51:19 +0000 (09:51 +0100)]
cmake: drop EXT_PREFIX_CLASS

This compile definition isn't used.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/109
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agocmake: disable pedantic
Paul Donald [Sat, 25 Oct 2025 16:24:35 +0000 (18:24 +0200)]
cmake: disable pedantic

This flag breaks compilation with ubus on aarch64/arm/x86.
The only platform which compiles successfully is mips.

/home/runner/work/odhcp6c/odhcp6c/build/include/libubox/utils.h:126:31: error: invalid application of ‘sizeof’ to a void type [-Werror=pointer-arith]
  126 |         (sizeof(int) == sizeof(*(1 ? ((void*)((long)(x) * 0l)) : (int*)1)))
      |                               ^
/home/runner/work/odhcp6c/odhcp6c/build/include/libubox/utils.h:140:31: note: in expansion of macro ‘__is_constant’
  140 |         __builtin_choose_expr(__is_constant(x),                         \
      |                               ^~~~~~~~~~~~~
/home/runner/work/odhcp6c/odhcp6c/build/include/libubox/utils.h:167:24: note: in expansion of macro ‘__eval_safe’
  167 | #define be32_to_cpu(x) __eval_safe(__constant_swap32, x)
      |                        ^~~~~~~~~~~

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/109
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
4 weeks agogithub: fix CI apt dependencies
Álvaro Fernández Rojas [Mon, 3 Nov 2025 06:38:52 +0000 (07:38 +0100)]
github: fix CI apt dependencies

We need to run 'apt update' before installing the APT packages.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
6 weeks agoodhcp6c: set server address from Information-request reply
Bert Goemans [Thu, 11 Jan 2024 16:17:42 +0000 (17:17 +0100)]
odhcp6c: set server address from Information-request reply

Update the environment variable STATE_SERVER_ADDR with the address
of the DHCPv6 server when a reply to an Information-request message
is received. Without this, there is no way of knowing which server
replied to the Information-request.
This is also consistent with the way that replies to Request and
Rebind messages are handled.

Signed-off-by: Bert Goemans <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/83
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
6 weeks agodhcpv6: use a per-interface IAID for IA_NA requests
David Härdeman [Mon, 20 Oct 2025 16:29:36 +0000 (18:29 +0200)]
dhcpv6: use a per-interface IAID for IA_NA requests

This ensures that the same IAID isn't used when odhcpd is e.g. running
on different interfaces (RFC8415, §12). This is more important now that
global DUID support has landed [1], meaning that odhcp6c won't typically
use per-interface DUIDs.

[1] https://github.com/openwrt/openwrt/pull/20359

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/105
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
6 weeks agogithub: improve CI
Álvaro Fernández Rojas [Sun, 19 Oct 2025 11:02:15 +0000 (13:02 +0200)]
github: improve CI

- Remove unneeded CMAKE_SYSTEM_PROCESSOR.
- Add summary table with sizes (in bytes) for each arch/variant.
- Upload generated binaries as artifacts.
- Add OpenWrt formalities.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
6 weeks agodhcpv6: Check status code for IA_ADDR operations
Paul Donald [Sat, 18 Oct 2025 20:22:41 +0000 (22:22 +0200)]
dhcpv6: Check status code for IA_ADDR operations

Check for error status code in the IA Address option in replies to RENEW
messages.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/103
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
6 weeks agodhcpv6: Add error checking to handle renew failure for IA_PD operations
Luke Deller [Sun, 1 Dec 2024 02:46:28 +0000 (13:46 +1100)]
dhcpv6: Add error checking to handle renew failure for IA_PD operations

Check for error status code in the IA Prefix option in replies to RENEW
messages.

This fixes a problem where odhcp6c thinks that renewal succeeded, when
actually the upstream router is no longer routing this prefix for us.

See https://github.com/openwrt/odhcp6c/issues/61#issuecomment-2509536512

Signed-off-by: Luke Deller <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/103
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
6 weeks agodhcpv6: dhcpv6_parse_ia refactor to switch case
Paul Donald [Sat, 18 Oct 2025 20:48:07 +0000 (22:48 +0200)]
dhcpv6: dhcpv6_parse_ia refactor to switch case

Add RFC comments for certain operations.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/103
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
6 weeks agoodhcp6c: fix deamon raw buffer inc
xuxb [Sun, 3 Dec 2023 07:11:21 +0000 (02:11 -0500)]
odhcp6c: fix deamon raw buffer inc

When starting odhcp6c as a daemon using the following command:
  odhcp6c -s /etc/odhcp6c.script -p /var/run/eth0_odhcp6c.pid -P 0 \
    -t 120 eth0"
The DHCPv6 server sends RA packets every 10 seconds.
However, it was observed that the raw socket's receive buffer keeps
increasing continuously. After investigating the code, an error was found:
the I/O signal was bound before starting the daemon, causing the daemon to
not receive the I/O signal. Consequently, the raw socket's recv queue kept
growing indefinitely.

The author of this patch is inactive and didn't include a proper SoB:
https://github.com/Horbivores

Link: https://github.com/openwrt/odhcp6c/pull/80
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
7 weeks agodhcpv6c: fix illegal DHCPV6_OPT_FQDN
Paul Donald [Wed, 1 Oct 2025 21:38:13 +0000 (23:38 +0200)]
dhcpv6c: fix illegal DHCPV6_OPT_FQDN

Some message types e.g. DHCPV6_MSG_INFO_REQ contained
DHCPV6_CLIENT_FQDN (39) which is illegal. See Client FQDN RFC4704:

https://www.rfc-editor.org/rfc/rfc4704#section-5

   A client MUST only include the Client FQDN option in SOLICIT,
   REQUEST, RENEW, or REBIND messages.

https://www.rfc-editor.org/rfc/rfc4704#section-6

   Servers MUST only include a Client FQDN option in ADVERTISE and REPLY
   messages...

Do not send it unless the message type is appropriate.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/100
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
7 weeks agoscript: don't ignore RA with zero router lifetime
Gasper Stukelj [Mon, 8 Apr 2024 09:48:09 +0000 (11:48 +0200)]
script: don't ignore RA with zero router lifetime

As per RFC 4861 (section 4.2), 0 is a valid value for
Router Lifetime field in Router Advertisement messages.
To quote from the RFC:

> A Lifetime of 0 indicates that the router is not a
> default router and SHOULD NOT appear on the default
> router list.

In fact, this is the mechanism by which a router,
previously advertising itself as a default router must
invalidate itself. From the RFC 7084 (4.1, G-5):

> By default, if the IPv6 CE router is an advertising
> router and loses its IPv6 default router(s) and/or
> detects loss of connectivity on the WAN interface,
> it MUST explicitly invalidate itself as an IPv6
> default router on each of its advertising interfaces
> by immediately transmitting one or more Router
> Advertisement messages with the "Router Lifetime"
> field set to zero [RFC4861].

Given that Router Lifetime is stored in the `valid`
field of the `struct odhcp6c_entry`, entries with
the field set to 0 shouldn't be ignored when entry
type is `ENTRY_ROUTE`.

Signed-off-by: Gasper Stukelj <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/84
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
7 weeks agoodhcp6c: sync and accumulate RA & DHCPv6 events as fast as possible
Alin Nastac [Wed, 3 Jan 2024 14:59:55 +0000 (15:59 +0100)]
odhcp6c: sync and accumulate RA & DHCPv6 events as fast as possible

This fixes commit dc186d6d2b0d which introduced accumulation delay
differences between the 2 possible scenarios:
  1. When DHCPv6 bound event precede RA receival, sync script is called
     after 1 second since accumulation has been completed (i.e. RA has
     been received).
  2. When RA receival precedes DHCPv6 bound event, sync script is called
     after a delay of 10 seconds since accumulation is done.

Fixes: dc186d6d2b0d ("odhcp6c: sync and accumulate RA & DHCPv6 events correctly")
Signed-off-by: Alin Nastac <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/82
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
7 weeks agoodhcp6c: update cmake file
Álvaro Fernández Rojas [Sun, 12 Oct 2025 20:00:18 +0000 (22:00 +0200)]
odhcp6c: update cmake file

Now that the minimum cmake version has been bumped, the cmake file can be
modernized a bit. Although it might look like a lot of changes, most of them
are quite straightforward.

Every library is located in a consistent manner (allowing command-line
overrides of library locations, useful for local development, and also makes it
trivial to do static linking, if desired).

The compiler flags have been broken up to have one per line (making it easy in
the future to add/remove flags, which would create a simple one-line diff).

Although it might look like this bumps the C standard level, cmake is actually
smart enough to pick an earlier version if C11 isn't supported by the compiler
(quite unlikely on any versions of gcc currently in use in OpenWrt and even on
old distros).

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
7 weeks agogithub: add CI build
Álvaro Fernández Rojas [Sun, 12 Oct 2025 20:00:18 +0000 (22:00 +0200)]
github: add CI build

Add Github CI supporting different architectures and odhcp6c build options.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
2 months agoCMakeLists: update cmake minimum required version to 3.10
Christian Marangi [Fri, 3 Oct 2025 21:40:21 +0000 (23:40 +0200)]
CMakeLists: update cmake minimum required version to 3.10

New cmake version 4.0 requires at least 3.5 version as the minimum
required version with it increased to 3.10 in to-be-released cmake
versions.

Set the minimum required version to 3.10 to future-proof for future
cmake version.

Suggested-by: Hannu Nyman <[email protected]>
Signed-off-by: Christian Marangi <[email protected]>
9 months agoUse GNUInstallDirs macros
Juan Orti Alcaine [Wed, 5 Feb 2025 09:29:40 +0000 (10:29 +0100)]
Use GNUInstallDirs macros

Instead of installing to a hardcoded path, use the macros from GNUInstallDirs.
This allows proper override of the directories at build time.

This was discovered because the package failed to build in Fedora with the
bin-sbin merge change:

https://fedoraproject.org/wiki/Changes/Unify_bin_and_sbin
https://bugzilla.redhat.com/show_bug.cgi?id=2340955

Signed-off-by: Juan Orti Alcaine <[email protected]>
11 months agoodhcp6c: Do not request S46 OROs by default
Richard Patterson [Mon, 19 Aug 2024 16:26:52 +0000 (17:26 +0100)]
odhcp6c: Do not request S46 OROs by default

This prevents odhcp6c from requesting MAP-T/E, LW4o6, and DS-Lite options by default, as the required packages aren't installed by default.

This commit should be merged along with commits to the map and ds-lite packages, that add configuration to requests the OROs when the packages are install

Signed-off-by: Richard Patterson <[email protected]>
14 months agoodhcp6c: allow to request specific ipv6 prefix
Vladislav Grishenko [Thu, 25 Jul 2024 19:51:09 +0000 (00:51 +0500)]
odhcp6c: allow to request specific ipv6 prefix

Expand -P option with optional exact ipv6 prefix format.
This allows to keep the IPv6 prefix in some cases, for example
if the prefix is issued dynamically on upstream.

Examples:
    -P <length>
    -P <prefix/length>

Based on https://github.com/openwrt/odhcp6c/pull/86

2 years agoodhcp6c: add -K option to set packet kernel priority
pacien [Sun, 9 Apr 2023 20:18:50 +0000 (22:18 +0200)]
odhcp6c: add -K option to set packet kernel priority

This adds a command line option (-K) to set the packet kernel
priority.

This makes it straightforward to set some VLAN priority for DHCP
requests through an egress qos map. (Avoiding the need for firewall
matching and marking through iptables, which prevents using flow
offloading).

(Such priority tag is a hard requirement for some ISPs, such as Orange
in France).

Signed-off-by: Pacien TRAN-GIRARD <[email protected]>
3 years agodhcpv6: add option to ignore stateless advertise
viktor.iarmola [Fri, 21 Jan 2022 12:33:02 +0000 (14:33 +0200)]
dhcpv6: add option to ignore stateless advertise

This change adds a new option to `odhcp6c` that makes it ignore any
advertisement without *both* IA_NA and IA_PD option.
Note that there is already an way to ignore advertisements without IA_NA
specifically (`-N force`) or without IA_PD specifically (`-F`), but there
is no way to express "advertisement MUST have either IA_NA or IA_PD
to be considered" - which is addressed by this change.

There are two primary use-cases for that.
First is to fix an issue with `odhcp6c` behavior when it encounters
a setup with both "stateful" (with IA_NA or IA_PD) and "stateless"
advertisements - and both coming with the same server DUID.
In that case, when the "stateless" advertisement comes last
during the RT window - it will overwrite the advertise entry for that
server DUID and effectively make it seem like we only received
one "stateless" advertisement on the link.
This, in turn, makes `odhcp6c` go into stateless mode
unless there was `-N force` or `-F` involved.

Second use case is as described in the initial part:
when we want to run in "stateful" mode, but would like to accept either
of IA_NA or IA_PD or both of them - and discard other advertisements.

Signed-off-by: Viktor Iarmola <[email protected]>
3 years agoodhcp6c: fix IA discard when T1 > 0 and T2 = 0
Dávid Benko [Wed, 13 Jul 2022 07:33:54 +0000 (09:33 +0200)]
odhcp6c: fix IA discard when T1 > 0 and T2 = 0

My ISP uses DHCPv6 advertisements where IA_PD T1 is non-zero (43200) and
T2 is zero. Current implementation of odhcp6c doesn't handle that and
just switches to stateless mode.

According to RFC 8415, section [21.21](https://datatracker.ietf.org/doc/html/rfc8415#section-21.21):
> If a client receives an IA_PD with T1 greater than T2 and both T1 and
  T2 are greater than 0, the client discards the IA_PD option and
  processes the remainder of the message as though the server had not
  included the IA_PD option.

Currently odhcp6c discards IA_PD option if `t1 > t2`:
https://github.com/openwrt/odhcp6c/blob/39b584bcac8770619b545d6ae344758f87028612/src/dhcpv6.c#L1346-L1347

The same applies for IA_NA.

Fix it by editing IA discard condition according to RFC.

Signed-off-by: Dávid Benko <[email protected]>
4 years agoRevert "dhcpv6: add a minimum valid lifetime for IA_PD updates"
Hans Dedecker [Sun, 5 Dec 2021 17:27:07 +0000 (18:27 +0100)]
Revert "dhcpv6: add a minimum valid lifetime for IA_PD updates"

Reverts commit ca43ea3f436c76fab0b8e3f170725c1d91ebdc36 as
gracefull handling of IA_PD options with valid_liftime 0
is supported in commit c9578e10428d12c683ceb05e17970a616817f577

4 years agodhcpv6: add support for null IA_PD valid lifetime
Alin Nastac [Wed, 10 Nov 2021 15:02:05 +0000 (16:02 +0100)]
dhcpv6: add support for null IA_PD valid lifetime

This allows immediate removal of the old PD assignments, triggered
by DHCPv6 server messages that contain both old and new IA_PD options:
  - new IA_PD, with normal valid & preferred lifetimes
  - old IA_PD, with valid & preffered lifetimes set to 0

Signed-off-by: Alin Nastac <[email protected]>
4 years agodhcpv6: add a minimum valid lifetime for IA_PD updates
Alin Nastac [Fri, 29 Oct 2021 08:44:10 +0000 (10:44 +0200)]
dhcpv6: add a minimum valid lifetime for IA_PD updates

Prefix delegation is removed when valid lifetime is set to 0,
which will result in current prefix assignments to be preserved
in odhcpd as long as their previously configured valid lifetime
allows it. When IA_PD valid lifetime is set to a small value iso 0,
netifd will update old IA_PD assignments, thus allowing removal
of the old prefixes from downstream interfaces.

Signed-off-by: Alin Nastac <[email protected]>
4 years agoodhcp6c: use strpbrk to provide get_sep_pos
Guilherme Janczak [Wed, 14 Jul 2021 09:32:45 +0000 (09:32 +0000)]
odhcp6c: use strpbrk to provide get_sep_pos

get_sep_pos is a reimplementation of strpbrk from the stdlib; this
patch removes it and replaces it with strpbrk in its callers.

Signed-off-by: Guilherme Janczak <[email protected]>
4 years agocmake: enable extra compiler checks
Hans Dedecker [Sat, 3 Apr 2021 18:28:11 +0000 (20:28 +0200)]
cmake: enable extra compiler checks

Let's catch enforced compiler errors during compilation

Signed-off-by: Hans Dedecker <[email protected]>
4 years agora: fix routing loop on point to point links
Hans Dedecker [Sat, 9 Jan 2021 20:17:48 +0000 (21:17 +0100)]
ra: fix routing loop on point to point links

For point-to-point links (e.g. PPP) don't create a link prefix route
when receiving a prefix information option with the on-link flag set.
Point-to-point links are non shared media and as such a destination
IPv6 address cannot be on-link.
If a link prefix route points to a point-to-point link it can trigger
a routing loop if the destination IPv6 address belongs to the prefix.
If such a packet is received and not directed to a local IPv6 address
it will be routed to the point-to-point link due to the link prefix route;
the upstream ISP router will route the IPv6 packet back due to the assigned
prefix route creating a "ping pong" effect

Signed-off-by: Hans Dedecker <[email protected]>
4 years agora: align ifindex resolving
Hans Dedecker [Wed, 6 Jan 2021 20:15:49 +0000 (21:15 +0100)]
ra: align ifindex resolving

Use ioctl SIOCGIFINDEX to resolve ifindex similar as in init_dhcpv6

Signed-off-by: Hans Dedecker <[email protected]>
4 years agodhcpv6: fix displaying IA info
Hans Dedecker [Sat, 26 Dec 2020 20:41:38 +0000 (21:41 +0100)]
dhcpv6: fix displaying IA info

Fix using ntohl and make clear if the recieved IA is either an IA_PD or
IA_NA option

Signed-off-by: Hans Dedecker <[email protected]>
4 years agodhcpv6: display status code as a string
Hans Dedecker [Sat, 26 Dec 2020 20:38:49 +0000 (21:38 +0100)]
dhcpv6: display status code as a string

For better readibility display the returned status code from the DHCPv6
server as a string

Signed-off-by: Hans Dedecker <[email protected]>
4 years agodhcpv6: harden reconfigure logic
Hans Dedecker [Tue, 8 Dec 2020 17:43:38 +0000 (18:43 +0100)]
dhcpv6: harden reconfigure logic

Check if a valid DHCPv6 message is returned by dhcpv6_request in
dhcpv6_poll_reconfigure as only RENEW/REBIND/INFORMATION REQUEST
messages can trigger the transmission of these messages in reply
to a RECONFIGURE

Signed-off-by: Hans Dedecker <[email protected]>
4 years agodhcpv6: rework DHCPv6 message to string implementation
Hans Dedecker [Tue, 8 Dec 2020 17:31:25 +0000 (18:31 +0100)]
dhcpv6: rework DHCPv6 message to string implementation

As the DHCPv6 messages handled by odhcp6c are not numerical consecutive
drop the DHCPv6 message string array

Signed-off-by: Hans Dedecker <[email protected]>
5 years agodhcpv6: fix regression
Hans Dedecker [Mon, 7 Dec 2020 20:26:47 +0000 (21:26 +0100)]
dhcpv6: fix regression

Fixes regression introduced in commit faed29a.
The DHCPv6 message type need to be returned by dhcpv6_handle_reconfigure
via dhcpv6_request when different from -1 so the correct message type
is passed to dhcpv6_request

Signed-off-by: Hans Dedecker <[email protected]>
5 years agodhcpv6: improve syslog tracing
Hans Dedecker [Mon, 7 Dec 2020 20:17:16 +0000 (21:17 +0100)]
dhcpv6: improve syslog tracing

Improve syslog tracing by displaying the DHCPv6 message type
in the received DHCPv6 message and requested DHCPv6 message type in
reply to a RECONFIGURE

Signed-off-by: Hans Dedecker <[email protected]>
5 years agodhcpv6: only refresh timers when reconfigure is valid
Hans Dedecker [Thu, 3 Dec 2020 20:28:41 +0000 (21:28 +0100)]
dhcpv6: only refresh timers when reconfigure is valid

Refresh timers only when a valid DHCPv6 msg-type has been received
in the received DHCPv6 reconfigure

Signed-off-by: Hans Dedecker <[email protected]>
5 years agodhcpv6: fix printing identity association id
Hans Dedecker [Thu, 3 Dec 2020 20:10:20 +0000 (21:10 +0100)]
dhcpv6: fix printing identity association id

Fix endian issue when printing the identity association id

Signed-off-by: Hans Dedecker <[email protected]>
5 years agodhcpv6: avoid sending continuous renew/rebind messages
Hans Dedecker [Mon, 30 Nov 2020 21:10:09 +0000 (22:10 +0100)]
dhcpv6: avoid sending continuous renew/rebind messages

If any of the IAs is not present in the Reply message in response
to a Renew/Rebind message don't set t1 to one second.
This will cause a continuous sending of Renew messages every second
if the DHCP server does not include all IAs in the Reply message.
Instead continue the normal retransmission time as if the Reply
message is not received as specified in RFC8415 §18.2.10.1

Signed-off-by: Hans Dedecker <[email protected]>
5 years agodhcpv6: add extra syslog info traces
Hans Dedecker [Sat, 28 Nov 2020 20:01:47 +0000 (21:01 +0100)]
dhcpv6: add extra syslog info traces

Add extra syslog info traces for debug purposes which are only enabled
when the verbose option is specified

Signed-off-by: Hans Dedecker <[email protected]>
5 years agoodhcp6c_find_entry: exclude priority from the list of fields that must match
Alin Nastac [Thu, 15 Oct 2020 15:12:15 +0000 (17:12 +0200)]
odhcp6c_find_entry: exclude priority from the list of fields that must match

Priority of an entry can vary from one RA to another, but the entry
identity should be the same regardless of the priority declared in the
RA message handled in ra_process() at a time.

CDRouter for instance tests compliance of the device  to requirement
G-5 of RFC 7084 by provisioning initially the CPE with a valid default
route that has a medium preference after which it sends a low preference
RA with lifetime 0 to check that CPE will start sending RAs with
lifetime 0 on the LAN side. Because odhcp6c didn't matched the low
precedence default router entry with the odhcp6c_entry that was
previously stored with medium precedence, it will fail to remove the
existing STATE_RA_ROUTE default route, hence preventing odhcpd from
advertising RAs with lifetime 0 to LAN.

Signed-off-by: Alin Nastac <[email protected]>
5 years agora: fix sending router solicitations
Hans Dedecker [Sat, 28 Mar 2020 19:47:18 +0000 (20:47 +0100)]
ra: fix sending router solicitations

Only stop sending router solicitations when a RA is received with a
valid router lifetime as specified in RFC4861 §6.3.7

Signed-off-by: Hans Dedecker <[email protected]>
5 years agoodhcp6c: fix compilation with musl 1.2.0
Rosen Penev [Wed, 25 Mar 2020 23:15:25 +0000 (16:15 -0700)]
odhcp6c: fix compilation with musl 1.2.0

SYS_clock_gettime is gone with musl 1.2.0. Switch to using the normal
function.

This was done back in the day when uClibc was used when librt was
separate.

Removed struct initialization since it gets written to right after.

Signed-off-by: Rosen Penev <[email protected]>
Signed-off-by: Hans Dedecker <[email protected]>
6 years agodhcpv6: sanitize oro options
Hans Dedecker [Fri, 6 Sep 2019 20:09:29 +0000 (22:09 +0200)]
dhcpv6: sanitize oro options

Remove SOL_MAX_RT and INF_MAX_RT from the non-strict oro option
array as both options will be added anyway by the required oro
option array

Signed-off-by: Hans Dedecker <[email protected]>
6 years agoodhcp6c: align further with RFC8415
Hans Dedecker [Fri, 11 Jan 2019 14:02:11 +0000 (15:02 +0100)]
odhcp6c: align further with RFC8415

Align acceptable options in the ORO list further with RFC8415; where
appropriate add send option support for the newly added options.

Signed-off-by: Hans Dedecker <[email protected]>
6 years agodhcpv6: avoid parsing unncessary IAs
Hans Dedecker [Fri, 11 Jan 2019 09:25:12 +0000 (10:25 +0100)]
dhcpv6: avoid parsing unncessary IAs

Don't parse IA_NA/IA_PD options if either na_mode or pd_mode is set
to IA_MODE_NONE

Signed-off-by: Hans Dedecker <[email protected]>
6 years agodhcpv6: set cnt to correct IOV enum
Hans Dedecker [Fri, 11 Jan 2019 09:16:54 +0000 (10:16 +0100)]
dhcpv6: set cnt to correct IOV enum

Make the code less error prone by setting cnt to IOV_HDR_IA_NA when
sending an INFORMATION REQUEST message

Signed-off-by: Hans Dedecker <[email protected]>
6 years agodhcpv6: get rid of request_prefix
Hans Dedecker [Fri, 11 Jan 2019 08:49:27 +0000 (09:49 +0100)]
dhcpv6: get rid of request_prefix

Get rid of the variable request_prefix as it serves no purpose anymore
and even triggers wrong code in dhcpv6_send by setting cnt to 12 which
is an invalid msg_iovlen index
Where appropriate request_prefix check can be replaced by checking the
pd_mode variable.

Signed-off-by: Hans Dedecker <[email protected]>
6 years agodhcpv6: sanitize option request list
Hans Dedecker [Wed, 9 Jan 2019 10:38:14 +0000 (11:38 +0100)]
dhcpv6: sanitize option request list

By config statefull options can be specified for the option request
list which will be included in DHCPv6 INFORMATION request messages.
Obviously this is wrong as both RFC3315 and RFC8415 specify no
statefull options must be included in stateless mode.
In RFC8415 Table 4 specifies the options which can be included in
the option request list and which options are required to be requested
in some messages.
This commit extends the option table with flags indicating which options
may be included in the option request list.
On top the client adds by default the options 32/82/83 as they're
required to be sent depending on the message.

Signed-off-by: Hans Dedecker <[email protected]>
7 years agoodhcp6c: add option to ignore Server Unicast option
Adrian Friedli [Wed, 11 Jul 2018 20:32:41 +0000 (22:32 +0200)]
odhcp6c: add option to ignore Server Unicast option

Add option -U to ignore Server Unicast option and force odhcp6c to use
the multicast address. This allows a workaround for broken setups.

Signed-off-by: Adrian Friedli <[email protected]>
Signed-off-by: Hans Dedecker <[email protected]>
7 years agoodhcp6c: remove len check in option parsing handle
Hans Dedecker [Wed, 20 Jun 2018 12:42:11 +0000 (14:42 +0200)]
odhcp6c: remove len check in option parsing handle

Replace len check by checking src to determine end of option data in the
different option data handlers.
This will make Coverity happy as reported in CID1437049, CID1430905,
CID1430898 and CID1430848

Signed-off-by: Hans Dedecker <[email protected]>
7 years agoodhcp6c: add support for user string options
Hans Dedecker [Fri, 8 Jun 2018 14:29:50 +0000 (16:29 +0200)]
odhcp6c: add support for user string options

Support user defined options having a string as option value.
The option value is detected as a string if it starts and ends with
either a double or single quote.

Signed-off-by: Hans Dedecker <[email protected]>
7 years agora: always trigger update in case of RA parameter change
Hans Dedecker [Sun, 29 Apr 2018 20:30:00 +0000 (22:30 +0200)]
ra: always trigger update in case of RA parameter change

Always launch a ra-updated event in case the RA hoplimit/mtu/reachable/
retransmit parameters change

Signed-off-by: Hans Dedecker <[email protected]>
7 years agodhcpv6: fix strncpy bounds
Hans Dedecker [Sat, 21 Apr 2018 11:40:29 +0000 (13:40 +0200)]
dhcpv6: fix strncpy bounds

Fixes dhcpv6.c:138:2: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation]                                                                                                        strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));

Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Hans Dedecker <[email protected]>
7 years agoscript: fix possible negative delay
Hans Dedecker [Thu, 5 Apr 2018 14:51:19 +0000 (16:51 +0200)]
script: fix possible negative delay

Fix delay becoming negative when killing a running script

Signed-off-by: Hans Dedecker <[email protected]>
7 years agodhcpv6: always trigger script update in case of IA updates
Hans Dedecker [Thu, 5 Apr 2018 09:55:50 +0000 (11:55 +0200)]
dhcpv6: always trigger script update in case of IA updates

Trigger a script update when IAs have been updated during a reply in reponse
to to either a renew/rebind.
This will make sure new IAs assigned by the DHCPv6 server are published via
a script update.

This covers the following scenario:
    -Prefix A is assigned by DHCPv6 server
    -Prefix A is renewed but the DHCPv6 server does not include prefix A in
    the reply but assigns a new prefix B.
    -Prefix B is published via the update script while renews for prefix A
    will still be sent

Signed-off-by: Hans Dedecker <[email protected]>