443 Commits

Author SHA1 Message Date
Paul Donald
9a4d6fe802 dhcpv6: use stable IAID for IA_NA
https://www.rfc-editor.org/rfc/rfc8415.html#section-12

   ........  The IAID is chosen by the client.  For any given use of an
   IA by the client, the IAID for that IA MUST be consistent across
   restarts of the DHCP client.  The client may maintain consistency by
   either storing the IAID in non-volatile storage or using an algorithm
   that will consistently produce the same IAID as long as the
   configuration of the client has not changed.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/140
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-18 18:44:07 +01:00
Álvaro Fernández Rojas
d99528f7a9 odhcp6c: avoid clearing CLIENT_ID
When CLIENT_ID is set as an argument instead of relying on the HW address
it gets lost after getting to a DHCPV6_RESET state.

Closes: https://github.com/openwrt/openwrt/issues/21053
Link: https://github.com/openwrt/odhcp6c/pull/139
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-18 17:43:58 +01:00
Álvaro Fernández Rojas
02e783c2f6 dhcpv6: fix NA/PD=try when NA/PD aren't provided
Fixes infinite SOLICIT loop when NA=try and/or PD=try but the ISP provides
no NA and/or no PD (only SLAAC).

Closes: https://github.com/openwrt/odhcp6c/issues/134
Link: https://github.com/openwrt/odhcp6c/pull/137
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-17 14:56:15 +01:00
Álvaro Fernández Rojas
0f64e66b92 odhcp6c: fix "-S" usage
Commit 1d6c4e794c converted "-S" option from integer to boolean, but
usage wasn't properly updated.

Fixes: 1d6c4e794c ("src: convert allow_slaac_only to boolean")
Link: https://github.com/openwrt/odhcp6c/pull/136
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-17 08:59:45 +01:00
Alvaro Fernandez Rojas
13805fce5a odhcp6c: reset res variable on INIT state
res variable is used on multiple states and it can be modified from the
default value during the argument parsing, so it should be properly reset
at INIT state.

Signed-off-by: Alvaro Fernandez Rojas <alvaro-fernandez@airbus.com>
2025-12-17 08:52:47 +01:00
Lincoln Ramsay
5212a1019d odhcp6c: clear the socket buffer after initialising it
There is a chance that the socket receives packets it should not
process between its initial creation and when ra_init is finished.

Flush these from the buffer by calling recvmsg and throwing away
everything that is received.

This solves a race condition on a multi-interface device, where
several odhcp6c instances are started, and an RA for one interface
ends up in the queue for another interface's odhcp6c socket.

Signed-off-by: Lincoln Ramsay <a1291762@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/133
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-09 16:12:21 +01:00
Álvaro Fernández Rojas
1d6c4e794c src: convert allow_slaac_only to boolean
It's declared as a boolean in the OpenWrt wiki, and the package script
doesn't pass any value.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-06 15:12:04 +01:00
Álvaro Fernández Rojas
8cfe71daaa src: stop overriding allow_slaac_only values
script_sync_delay is no longer updated with allow_slaac_only, so this
isn't needed.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-06 13:51:06 +01:00
Álvaro Fernández Rojas
aac3415716 odhcp6c: drop script_sync_delay override
allow_slaac_only is declared as a boolean in the OpenWrt wiki and the
script doesn't pass any value at all:
00c8b5c612/package/network/ipv6/odhcp6c/files/dhcpv6.sh (L94)

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-06 13:50:47 +01:00
Álvaro Fernández Rojas
05aa750fbe config: fix default value for allow_slaac_only
As reported by @nxhack at https://github.com/openwrt/odhcp6c/issues/131,
allow_slaac_only was assigned an incorrect default value when it was moved
from odhcp6c.c to config.c.

Fixes: 1048fc4fb6 ("reconfigure: move all configuration functions to a new file")
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-06 13:34:24 +01:00
Álvaro Fernández Rojas
f19dd37fb4 odhcp6c: accept EUI64 and random for interface ID
ip6ifaceid is now properly passed to odhcp6c in OpenWrt scripts, which is
broken if we don't support 'eui64' and 'random' options.
Instead of printing help and exiting when an invalid fixed address is
configured, let's just log an error and pretend that no interface ID was
passed to odhcp6c.

Closes https://github.com/openwrt/openwrt/issues/20976

Link: https://github.com/openwrt/odhcp6c/pull/130
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-04 08:53:51 +01:00
George Sapkin
e955729c78 formal: fix workflow permissions
Fix formality check permissions that are needed to post optional
summaries back to the PR.

Link: openwrt/actions-shared-workflows#64
Signed-off-by: George Sapkin <george@sapk.in>
Link: https://github.com/openwrt/odhcp6c/pull/128
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-02 14:49:01 +01:00
Álvaro Fernández Rojas
9557d3e245 vscode: set tabs to 8 whitespaces by default
VSCode uses 4 whitespaces by default instead of the usual 8 used in linux
projects.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-12-01 15:19:08 +01:00
Álvaro Fernández Rojas
98dfd156f3 src: fix shadowed local variables
Fix shadowed local variables and enable warning to prevent more shadowed
variables in the future.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-28 08:42:29 +01:00
Paul Donald
f98b6ec823 all: implement RFC8910 §3 URI equality check
§3 Precedence of API URIs
"
A device may learn about Captive Portal API URIs through more than one of (or
indeed all of) the above options. Implementations can select their own
precedence order (e.g., prefer one of the IPv6 options before the DHCPv4 option,
or vice versa, et cetera).

If the URIs learned via more than one option described in Section 2 are not all
identical, this condition should be logged for the device owner or
administrator; it is a network configuration error if the learned URIs are not
all identical.
"

We log the 'network configuration error' but proceed in an attempt to be useful
(since the RFC makes no mention of disregarding the URI) and prefer DHCPv6,
since this is the DHCPv6 client.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/127
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-24 10:29:58 +01:00
Paul Donald
3484787e9a all: implement RFC8910 captive portal (CP) option
https://www.rfc-editor.org/rfc/rfc8910.html

RFC8908 defines a captive portal client (CPC) that handles the API URI returned.

The captive portal (CP) option presence signals a portal that requires
authentication beyond what odhcp6c currently handles.

It's possible that a user connecting through an openwrt gateway encounters the
portal anyway (though this behaviour depends on the portal), but if this is not
the case, with this addition we can:
 - surface a message in a UI as to presence of the CP
 - signal that users install a CPC (a chicken/egg problem behind a CP)
 - provide the API URI for downstream consumers.

This should ease the use of travel router scenarios.

Downstream consumers of the API URI can find it via the CAPTIVE_PORTAL_URI
environment/ubus property.

The strengths of having this option handled means downstream consumers get one
unified environment variable since ra.c does not yet handle CUSTOM_* the way
DHCPv6 does.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/127
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-24 10:29:49 +01:00
Paul Donald
25a0c40580 dhcpv6: refactor variable names
improve readability

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/123
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-23 20:09:35 +01:00
Paul Donald
165bcc68ef dhcpv6: refactor variable names
improve readability

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/123
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-23 20:09:32 +01:00
Paul Donald
8f60e7b183 dhcpv6: refactor variable names
improve readability

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/123
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-23 20:09:29 +01:00
Paul Donald
319305fcee dhcpv6: refactor variable names
improve readability

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/123
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-23 20:09:26 +01:00
Paul Donald
dcb53c4965 dhcpv6: assign a new field for prefix exclusion length
re-using the priority field is very confusing, for the sake of saving a byte.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/123
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-23 20:09:22 +01:00
Paul Donald
080b64d70e dhcpv6: refactor variable names
for ia and pd entries

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/123
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-23 20:09:16 +01:00
Paul Donald
66dd9b26b7 dhcpv6: refactor variable names
improve readability

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/123
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-23 20:08:31 +01:00
Paul Donald
f038a50604 odhcp6c: set environment script to its current location
The calling script which sets odhcp6c up is currently passed -s as routine,
but synchronize its current location with its calling script, which should make
cross-referencing easier.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/126
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-23 17:42:27 +01:00
Álvaro Fernández Rojas
5f63e7e47d github: ci: add MIPS64, PowerPC64 and RISCV64
MIPS64, PowerPC64 and RISCV64 are popular OpenWrt archs.
Refactor the sizes build step to generate the table programatically.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-18 08:41:30 +01:00
Paul Donald
038407eca8 dhcpv6: restart DHCPv6 on receipt of RA containing a new prefix
When the upstream DHCPv6 server does not provide IA_NA or IA_PD options, odhcp6c
enters into stateless mode, which will not be exited from until SIGUSR2 signal
is received.

This change enforces DHCPv6 restart on receipt of a RA that:
  a) advertises the presence of DHCPv6 server on the network, containing
  either M or O flags
  b) has a PI (prefix information) option that contains a new prefix

thus allowing the switch to DHCPv6 stateful mode when RA PI options suggest that
the upstream DHCPv6 server now manages a new prefix.

Restart is useful even when DHCPv6 client is already in stateful mode, so the
DHCPv6 server will be able to refresh the client's IA_NA and IA_PD options
before renewal timeout is triggered, hence avoiding the usage of potentially
deprecated addresses.

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/119
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-18 08:23:20 +01:00
Paul Donald
af9968c029 dhcpv6: fix processing PIO exclusion loop variable collision
An inner loop variable i potentially collides with the outer loop i, possibly
giving unexpected results.
Commit b146f9adc8 introduced both the inner and outer loop.

Fixes: b146f9adc8 ("add support for multiple prefixes with distinct IAIDs")
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/124
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-18 08:18:57 +01:00
Jonas Lochmann
5492f09ec0 odhcp6c: apply draft-ietf-6man-slaac-renum-11 lifetime rules
Instead of applying the complicated ruleset from RFC 4862,
just use the new address information as described in the draft
draft-ietf-6man-slaac-renum-11.

Signed-off-by: Jonas Lochmann <git@inkompetenz.org>
Link: https://github.com/openwrt/odhcp6c/pull/114
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-17 08:57:45 +01:00
Álvaro Fernández Rojas
38a31eb29a src: add fallthrough attribute
- Enable fallthrough warnings.
- Use fallthrough attribute instead of comments.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/120
2025-11-17 08:28:54 +01:00
Álvaro Fernández Rojas
b46d79c879 odhcp6c: properly guard attributes
Properly guard odhcp6c.h attributes with `#ifndef` to avoid redefining them
when including external headers.
Also convert the remaining __attribute__ usages to the custom declarations.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/120
2025-11-17 08:28:40 +01:00
Álvaro Fernández Rojas
cbc8ff0e62 github: ci: add powerpc arch
PowerPC is another popular OpenWrt arch.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-14 14:19:31 +01:00
Álvaro Fernández Rojas
8eba022331 github: ci: add cmake build and source directories
Add cmake build and source directories to suppress the following warning:
CMake Warning:
  No source or binary directory provided. Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-14 14:17:49 +01:00
Álvaro Fernández Rojas
5f3104ea17 github: ci: disable json-c tests
Disable BUILD_TESTING to save time when building json-c.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-14 08:36:51 +01:00
Álvaro Fernández Rojas
27ff42cd40 scripts: devel-build: disable json-c tests
Disable BUILD_TESTING to save time when building json-c.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-14 08:35:18 +01:00
Paul Donald
e0a9d02b52 dhcpv6: DHCPV6_OPT_INFO_REFRESH contains a 4 byte option
we shall not expect data beyond 4 bytes. So the logic should be ==

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-13 13:37:19 +01:00
Paul Donald
5a02da9c12 dhcpv6: use compile time resolved sizeof(struct in6_addr) for IPv6 values
make it evident where 16 byte sizes come from, for the options that take IPv6

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-13 13:37:13 +01:00
Paul Donald
cf203ceb3f dhcpv6: set a static define for DUID max length
so the number 130 isn't so mysterious at first glance.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-13 13:37:08 +01:00
Paul Donald
3627e85d15 dhcpv6: set static defines for DHCPv6 option header size
so the number 4 isn't so mysterious at first glance.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-13 13:37:02 +01:00
Paul Donald
ecb9a0243e odhcp6c: RFC comments
make spec easier to identify

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-13 13:36:56 +01:00
Paul Donald
c284c587d3 all: spell fixes
spelling fixes

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-13 13:36:51 +01:00
Paul Donald
1259a32d7e dhcpv6: dhcpv6_handle_reply switch case handling
shortens jumps and reduces branching.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-13 13:36:46 +01:00
Paul Donald
227280a378 dhcpv6: dhcpv6_handle_advert; migrate if blocks to switch case
reduces branching

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-13 13:36:39 +01:00
Paul Donald
b253f8907e dhcpv6: migrate to switch case for dhcpv6_handle_reply
Indent the if blocks (squash with previous commit)

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-13 13:36:34 +01:00
Paul Donald
61a54db802 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 <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-13 13:36:27 +01:00
Paul Donald
49c64bbe00 all: drop CER_ID
We have removed it from odhcpd since this never saw adoption. Remove here also.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-13 13:36:00 +01:00
Paul Donald
16ce83075b 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 <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/117
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-11 08:22:58 +01:00
Hauke Mehrtens
e5690c1f13 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 <hauke@hauke-m.de>
2025-11-09 13:33:51 +01:00
Jerome Küttner
775e6c759c 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 <jkuettner-dev@proton.me>
Link: https://github.com/openwrt/odhcp6c/pull/90
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-05 08:18:58 +01:00
Paul Donald
9e414d41e1 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 <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/115
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-05 08:15:03 +01:00
Paul Donald
a92f199d6b dhcpv6: potential bug fix for checking DHCPV6_OPT_STATUS
follow-up to b65ff293a9

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 <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/113
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-11-05 08:12:13 +01:00