Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tap_manager: work around flexible array members in uapi #426

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

KanjiMonster
Copy link
Contributor

@KanjiMonster KanjiMonster commented Feb 19, 2024

Recently the kernel replaced deprecated zero-length arrays with proper flexible arrays [1]. Unfortunately this causes the compilation to fail, since now G++ rejects anything in structs behind the flexible array member:

Feb 16 11:42:33 | In file included from ../git/src/netlink/tap_manager.cc:11: Feb 16 11:42:33 | /tmp/generic-x86-64/work/corei7-64-poky-linux/baseboxd/2.1.0-r0/recipe-sysroot/usr/include/linux/ethtool.h: In member function 'virtual int basebox::tap_manager::set_port_speed(std::string, uint32_t, uint8_t)': Feb 16 11:42:33 | /tmp/generic-x86-64/work/corei7-64-poky-linux/baseboxd/2.1.0-r0/recipe-sysroot/usr/include/linux/ethtool.h:2199:17: error: flexible array member 'ethtool_link_settings::link_mode_masks' not at end of 'struct basebox::tap_manager::set_port_speed(std::string, uint32_t, uint8_t)::<unnamed>'
Feb 16 11:42:33 |  2199 |         __u32   link_mode_masks[];
Feb 16 11:42:33 |       |                 ^~~~~~~~~~~~~~~
Feb 16 11:42:33 | ../git/src/netlink/tap_manager.cc:394:11: note: next member '__u32 basebox::tap_manager::set_port_speed(std::string, uint32_t, uint8_t)::<unnamed struct>::link_mode_data [381]' declared here
Feb 16 11:42:33 |   394 |     __u32 link_mode_data[3 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
Feb 16 11:42:33 |       |           ^~~~~~~~~~~~~~
Feb 16 11:42:33 | ../git/src/netlink/tap_manager.cc:392:10: note: in the definition of 'struct basebox::tap_manager::set_port_speed(std::string, uint32_t, uint8_t)::<unnamed>'
Feb 16 11:42:33 |   392 |   struct {
Feb 16 11:42:33 |       |          ^

Work around this by switching the order of the elements in our own struct so that the flexible array member is last, but the struct still is sized correctly. Then use a ethtool_link_settings pointer pointing to the beginning of this struct for any further accesses.

[1] torvalds/linux@94dfc73

Description

Motivation and Context

How Has This Been Tested?

@KanjiMonster KanjiMonster marked this pull request as ready for review February 19, 2024 09:08
Recently the kernel replaced deprecated zero-length arrays with proper
flexible arrays [1]. Unfortunately this causes the compilation to fail,
since now G++ rejects anything in structs behind the flexible array
member:

Feb 16 11:42:33 | In file included from ../git/src/netlink/tap_manager.cc:11:
Feb 16 11:42:33 | /tmp/generic-x86-64/work/corei7-64-poky-linux/baseboxd/2.1.0-r0/recipe-sysroot/usr/include/linux/ethtool.h: In member function 'virtual int basebox::tap_manager::set_port_speed(std::string, uint32_t, uint8_t)':
Feb 16 11:42:33 | /tmp/generic-x86-64/work/corei7-64-poky-linux/baseboxd/2.1.0-r0/recipe-sysroot/usr/include/linux/ethtool.h:2199:17: error: flexible array member 'ethtool_link_settings::link_mode_masks' not at end of 'struct basebox::tap_manager::set_port_speed(std::string, uint32_t, uint8_t)::<unnamed>'
Feb 16 11:42:33 |  2199 |         __u32   link_mode_masks[];
Feb 16 11:42:33 |       |                 ^~~~~~~~~~~~~~~
Feb 16 11:42:33 | ../git/src/netlink/tap_manager.cc:394:11: note: next member '__u32 basebox::tap_manager::set_port_speed(std::string, uint32_t, uint8_t)::<unnamed struct>::link_mode_data [381]' declared here
Feb 16 11:42:33 |   394 |     __u32 link_mode_data[3 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
Feb 16 11:42:33 |       |           ^~~~~~~~~~~~~~
Feb 16 11:42:33 | ../git/src/netlink/tap_manager.cc:392:10: note: in the definition of 'struct basebox::tap_manager::set_port_speed(std::string, uint32_t, uint8_t)::<unnamed>'
Feb 16 11:42:33 |   392 |   struct {
Feb 16 11:42:33 |       |          ^

Work around this by switching the order of the elements in our own
struct so that the flexible array member is last, but the struct still
is sized correctly. Then use a ethtool_link_settings pointer pointing to
the beginning of this struct for any further accesses.

[1] torvalds/linux@94dfc73

Signed-off-by: Jonas Gorski <[email protected]>
@KanjiMonster KanjiMonster force-pushed the jogo_fix_linux_uapi_6.0 branch from b33d5c3 to c4e1da7 Compare February 22, 2024 08:04
Copy link
Contributor

@rubensfig rubensfig left a comment

Choose a reason for hiding this comment

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

LGTM.

Compile tested in the x86 architectures. Thank you for the reference notes in the commit.

@rubensfig rubensfig merged commit a01b399 into main Feb 22, 2024
5 checks passed
@rubensfig rubensfig deleted the jogo_fix_linux_uapi_6.0 branch February 22, 2024 09:20
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.

2 participants