sockaddr used in the kernel?
sockaddr used in the kernel?
Posted Nov 8, 2024 2:59 UTC (Fri) by clugstj (subscriber, #4020)Parent article: The trouble with struct sockaddr's fake flexible array
How can this be anything but a bug? It's not big enough for many address formats.
Posted Nov 8, 2024 3:41 UTC (Fri)
by iabervon (subscriber, #722)
[Link] (12 responses)
Posted Nov 8, 2024 7:02 UTC (Fri)
by smurf (subscriber, #17840)
[Link] (11 responses)
So why do the short variants need padding up to an arbitrary 14, which happens to not match *any* actual address type's length?
Posted Nov 8, 2024 7:58 UTC (Fri)
by johill (subscriber, #25196)
[Link] (10 responses)
Sure, wireless extensions wouldn't need 14 bytes for a MAC address there, only ever 6. But now it's stuck with 14 and can't use 6, and shouldn't use "14 or variable" either because it's embedded in other types.
Posted Nov 8, 2024 21:31 UTC (Fri)
by magfr (subscriber, #16052)
[Link]
Would it be confirming if the kernel returned a size of 8 and only filled in the sin_family, sin_port, and sin_addr fields?
I suppose the kernel does nothing with the padding as it is today so beeing explicit about it should be ok.
It should be noted that posix says sa_data must exist but it says nothing about it's size.
Then there is the issue that all the sockaddr_xx types must have the same alignment.
What I am going for is if the following is standards conforming:
typedef alignas(16) int16_t sa_family_t;
with an obvious caveat for what the alignment of sa_family_t should be.
In particular this makes sizeof(struct sockaddr) == 2 and sizeof(struct sockaddr_in) == 8 but note that
Posted Nov 9, 2024 8:33 UTC (Sat)
by smurf (subscriber, #17840)
[Link] (8 responses)
So why does the kernel really need padded addresses anywhere? Just use / copy however many bytes the address's type requires and be done with it.
Posted Nov 9, 2024 23:15 UTC (Sat)
by johill (subscriber, #25196)
[Link] (7 responses)
But for some APIs the address is _embedded_ into other structures (which is what most of the article is about), and changing the size now would change the position of everything that comes after it, breaking the ABI.
Posted Nov 10, 2024 9:17 UTC (Sun)
by smurf (subscriber, #17840)
[Link] (6 responses)
I'm not aware of any system call that embeds a sockaddr in some other data structure, but maybe that's just me.
Posted Nov 10, 2024 19:20 UTC (Sun)
by johill (subscriber, #25196)
[Link] (5 responses)
You can take a look at https://lore.kernel.org/netdev/cover.1729802213.git.gusta... for probably most/all of the APIs affected.
Posted Nov 10, 2024 21:18 UTC (Sun)
by smurf (subscriber, #17840)
[Link] (4 responses)
Oh well.
Posted Nov 10, 2024 21:32 UTC (Sun)
by johill (subscriber, #25196)
[Link] (3 responses)
Posted Nov 11, 2024 9:21 UTC (Mon)
by Sesse (subscriber, #53779)
[Link] (2 responses)
Posted Nov 11, 2024 10:36 UTC (Mon)
by mb (subscriber, #50428)
[Link] (1 responses)
Posted Nov 11, 2024 12:34 UTC (Mon)
by johill (subscriber, #25196)
[Link]
As for the question about why it "must" be coupled with changes in the CLI, well ... it doesn't really need to be, but when writing a completely new tool that for the most part has completely new semantics, keeping the CLI intact really isn't the first priority.
If you want to submit patches to make 'iw' have a mode where it behaves like iwconfig/iwlist for a subset of functionality, I guess I'd even apply them if they're reasonably well implemented.
But you can keep using it for eternity, for all I care, just don't expect new hardware support etc., and then you can just keep using an old kernel version too.
sockaddr used in the kernel?
sockaddr used in the kernel?
sockaddr used in the kernel?
sockaddr used in the kernel?
struct sockaddr { sa_family_t sa_family; char sa_data[]; };
struct sockaddr_in { sa_family_t sin_family; uint16_t sin_port; struct inaddr sin_addr; };
sizeof(struct sockaddr[2]) == 32 due to the alignment.
sockaddr used in the kernel?
sockaddr used in the kernel?
sockaddr used in the kernel?
sockaddr used in the kernel?
sockaddr used in the kernel?
sockaddr used in the kernel?
sockaddr used in the kernel?
sockaddr used in the kernel?
So it's exactly the opposite of what you say: The fundamental API has changed, but the obsolete CLI and its obsolete API have not.
So, if almost two decades is not enough for you to adapt to the "new" iw CLI, then you can keep using iwconfig/iwlist.
sockaddr used in the kernel?