Skip to content

iwinfo: generic improvement of assoclist handling#19

Open
Ansuel wants to merge 4 commits intoopenwrt:masterfrom
Ansuel:dynamic-iwinfo
Open

iwinfo: generic improvement of assoclist handling#19
Ansuel wants to merge 4 commits intoopenwrt:masterfrom
Ansuel:dynamic-iwinfo

Conversation

@Ansuel
Copy link
Member

@Ansuel Ansuel commented Dec 6, 2024

This small PR makes generic improvement of assoclist handling.

Idea is to prevent any API change. User still needs to update their function to account for NULL buffer and len but updates likes that will only improve a fragile code.

This improves the assoc list and maybe also reduce the memory footprint. Allocating a big enough BUFFER is problematic for assoclist as it can grow a lot as it will contain info for every associated station.

To handle this, implement common practice way to get the number of element to alloc and dynamically alloc the space.
To apply this logic assoc list function needs to be called twice but this should not cause additional overhead.

Limit assoclist element to IWINFO_BUFSIZE. This is to fix a segfault if
the clients are more than 140. Once the local buffer is filled, the
function stop parsing additional clients and returns info for the parsed
ones.

Fixes: openwrt#15
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Make assoclist OP aware of the max allocated buffer. This is done by
setting the third arg to the max allocated buffer. Function needs to use
this info to stop parsing data if the max allocated buffer size is
reached.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Update any assoclist user to account for NULL buf. This is common
practice where a NULL buf is passed if only the len element needs to be
filled. This is useful to know how much space allocate for a function.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Change print_assoclist to dynamically allocate buffer for assoclist.
Assoclist is called 2 times, one to get the size of the buffer to
allocate by passint to assoclist a NULL buf. Then a second time to
actually fill the data.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
@Ansuel
Copy link
Member Author

Ansuel commented Dec 6, 2024

@mrisaev can you check and test?

benboguan added a commit to benboguan/immortalwrt-mt798x that referenced this pull request Dec 24, 2024
benboguan added a commit to benboguan/immortalwrt-mt798x that referenced this pull request Dec 25, 2024
benboguan added a commit to benboguan/immortalwrt-mt798x that referenced this pull request Dec 25, 2024
benboguan added a commit to benboguan/immortalwrt-mt798x that referenced this pull request Dec 25, 2024
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.

1 participant