Skip to content

dhcpv6: refactor u8 and u16 to u32 to avoid boolean coercion - #117

Merged
openwrt-bot merged 1 commit into
openwrt:masterfrom
systemcrash:ubus_fixes
Nov 11, 2025
Merged

openwrt-bot merged 1 commit into
openwrt:masterfrom
systemcrash:ubus_fixes

Conversation

@systemcrash

Copy link
Copy Markdown
Contributor

ubus has been weird for a while, and one workaround suitable is to amend u8 values (despite them being and containing only a u8 int) to u16 values. ubus coerces u8 to booleans for some reason. The actual values on the bus might be a u8, but 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_u16 to resolve this.

ping @Noltari

@Noltari

Noltari commented Nov 10, 2025

Copy link
Copy Markdown
Member

@systemcrash I think it's time to fix this at libubox...

@systemcrash

Copy link
Copy Markdown
Contributor Author

If you feel up to that (I wrote to Felix) then that's an option. But this works today. I've had to employ this workaround elsewhere...

@Noltari

Noltari commented Nov 10, 2025

Copy link
Copy Markdown
Member

If you feel up to that (I wrote to Felix) then that's an option. But this works today. I've had to employ this workaround elsewhere...

openwrt/libubox#25

@Noltari Noltari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@systemcrash systemcrash changed the title dhcpv6: refactor u8 to u16 to avoid boolean coercion dhcpv6: refactor u8 and u16 to u32 to avoid boolean coercion Nov 10, 2025
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 openwrt/libubox#25 (comment)
"
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: openwrt#117
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
@openwrt-bot
openwrt-bot merged commit 16ce830 into openwrt:master Nov 11, 2025
5 checks passed
@Noltari

Noltari commented Nov 11, 2025

Copy link
Copy Markdown
Member

Mrged, thanks @systemcrash!

@systemcrash
systemcrash deleted the ubus_fixes branch November 11, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants