Skip to content

Add SendMessagesScatter using conn.SendmsgBuffers#257

Open
Cellebyte wants to merge 1 commit intomdlayher:mainfrom
Cellebyte:fix/netlink-msg-too-long
Open

Add SendMessagesScatter using conn.SendmsgBuffers#257
Cellebyte wants to merge 1 commit intomdlayher:mainfrom
Cellebyte:fix/netlink-msg-too-long

Conversation

@Cellebyte
Copy link

@Cellebyte Cellebyte commented Feb 25, 2026

Add conn.SendmsgBuffers additionally of conn.Sendmsg

The library is used in a project which applies netfilter rules into network namespaces of containers.
Some customers use very huge netfilter configurations which cause a default socket configuration on linux to not accept the message. The project currently increases the socket buffer dynamically, based on the message size.

There was already #254 which got implemented here.
It is a separate function as suggested in #254, due to issues I had during a one to one replacement in gooogle/nftables.

This can only be merged after mdlayher/socket#18.

@nickgarlis
Copy link
Collaborator

Do you have an example or test case that demonstrates the issue this change is intended to fix?
From what I understand, scatter/gather may reduce user-space copying or memory usage, but it doesn’t prevent the socket send buffer from filling up. If the buffer runs out of space, we could still see an ENOBUFS error unless the socket memory limits are increased.

@Cellebyte
Copy link
Author

No the change does not help with the issue alone.
As I still get the message too long error, but I only use it in the nftables implementation.

@nickgarlis
Copy link
Collaborator

nickgarlis commented Feb 26, 2026

If you're using google/nftables and are trying to solve ENOBUFS or EMSGSIZE the solution might be to use the latest committed change (not the latest tagged one). There have been changes to address this issue.

This PR is still useful IMO (not a maintainer) but I just didn't think it was the solution to the issue described in the title.

@Cellebyte
Copy link
Author

Cellebyte commented Feb 26, 2026

Ok, I just saw your Issue and suggestion to add this method. I already use the latest commits in nftables:main on a cluster. Maybe we move the discussion to the right place and I add infos about the use-case and my Issue there as well as the reproducer and maybe some hint how I can debug it.

@Cellebyte Cellebyte force-pushed the fix/netlink-msg-too-long branch from 9f9bb1d to b2e09e5 Compare February 26, 2026 22:45
@Cellebyte Cellebyte changed the title Fix/netlink msg too long Add SendMessagesScatter using conn.SendmsgBuffers Feb 26, 2026
@Cellebyte
Copy link
Author

Cellebyte commented Feb 26, 2026

Changed the subject of this PR and implemented it as a separate function due to the mentioned issue above.

func (c *conn) SendMessagesScatter(messages []Message) error {
buffers := make([][]byte, len(messages))
for i, m := range messages {
b, err := m.MarshalBinary()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the issue discussed in google/nftables#350 now points to these buffers instead of the socket ones.

I think there is a limit on how many of these buffers you can use. Check getconf IOV_MAX

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