Add socket receive buffer size configuration#53
Add socket receive buffer size configuration#53DineshI-MS wants to merge 3 commits intoflorianl:mainfrom
Conversation
There was a problem hiding this comment.
@DineshI-MS Looking more at this approach. It might be easier to just provide an API to set the receiver buffer:
// SetReadBuffer SetReadBuffer sets the size of the receive buffer associated with this socket.
func (nflog *Nflog) SetReadBuffer(bytes int) error {
return nflog.Con.SetReadBuffer(bytes)
}
This would redude the complexity of configuration and would also users allow to change it any time. Would you be open to update your PR with such an approach?
There was a problem hiding this comment.
Thanks for providing this suggestion. I was able to set the buffer size this way without making any additional changes. I wasn’t aware of the API functions that are already part of netlink.Conn
nf, err := nflog.Open(&config)
if err != nil {
return fmt.Errorf("failed to open nflog: %w", err)
}
defer nf.Close()
reqSocketBufferSize := (512 * 1024) // set default as 512 KB
if err := nf.Con.SetReadBuffer(reqSocketBufferSize); err != nil {
return fmt.Errorf("failed to set read buffer: %w", err)
}
There was a problem hiding this comment.
@DineshI-MS Would you be open to update your PR with this new approach?
There was a problem hiding this comment.
As Nflog already exposes *netlink.Conn, it might be best to just improve documentation. I might open a new PR in a few days improving documentation, if this PR becomes stale.
|
Closing as resolved with #54. |
Problem
The library currently doesn't provide a way to set the netlink socket receive buffer size. This causes ENOBUFS errors under moderate to high packet rates (>5k pps) with the default 208KB buffer.
Solution
This PR adds a new
SockBufSizefield to the Config struct that allows users to set the socket receive buffer size usingSO_RCVBUFFORCE(with fallback toSO_RCVBUF).Changes
SockBufSize uint32field to Config structOpen()to apply the socket buffer size if specifiedTesting
Backwards Compatibility
This change is fully backwards compatible: