dhcpv6: refactor u8 and u16 to u32 to avoid boolean coercion
authorPaul Donald <[email protected]>
Mon, 10 Nov 2025 17:26:16 +0000 (18:26 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Tue, 11 Nov 2025 07:22:58 +0000 (08:22 +0100)
commit16ce83075b2e878051617f402a6b07a24af511fd
treecbec0f5d9c7d6728c32063353526aec4087684f8
parente5690c1f13ed3605ece68d870abb3c4a2f09d571
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]>
src/ubus.c