Compare commits

..

1 Commits

Author SHA1 Message Date
Nick Garlis ca25212b5a
Merge 7d83c94f64 into 8a8ad2be81 2025-06-28 16:00:51 +00:00
1 changed files with 2 additions and 26 deletions

28
conn.go
View File

@ -250,10 +250,10 @@ func (cc *Conn) Flush() error {
} }
defer func() { _ = closer() }() defer func() { _ = closer() }()
if err := cc.enlargeWriteBuffer(conn); err != nil { if err = cc.enlargeWriteBuffer(conn); err != nil {
return err return err
} }
if err := cc.enlargeReadBuffer(conn); err != nil { if err = cc.enlargeReadBuffer(conn); err != nil {
return err return err
} }
@ -440,22 +440,6 @@ func (cc *Conn) getMessageSize() int {
return total return total
} }
// canEnlargeBuffers returns true if the connection can automatically enlarge
// the write and read buffers of the netlink connection.
func (cc *Conn) canEnlargeBuffers() bool {
// If there are sock options, we assume that the user has already set the
// buffers to a fixed size.
if len(cc.sockOptions) > 0 {
return false
}
if cc.TestDial != nil {
return false
}
return true
}
// enlargeWriteBuffer automatically sets the write buffer of the given // enlargeWriteBuffer automatically sets the write buffer of the given
// connection to the accumulated message size. This is only done if the current // connection to the accumulated message size. This is only done if the current
// write buffer is smaller than the message size. // write buffer is smaller than the message size.
@ -469,10 +453,6 @@ func (cc *Conn) canEnlargeBuffers() bool {
// TODO: Update this function to mimic the behavior of nftables once our // TODO: Update this function to mimic the behavior of nftables once our
// socket library supports multiple iovec entries. // socket library supports multiple iovec entries.
func (cc *Conn) enlargeWriteBuffer(conn *netlink.Conn) error { func (cc *Conn) enlargeWriteBuffer(conn *netlink.Conn) error {
if !cc.canEnlargeBuffers() {
return nil
}
messageSize := cc.getMessageSize() messageSize := cc.getMessageSize()
writeBuffer, err := conn.WriteBuffer() writeBuffer, err := conn.WriteBuffer()
if err != nil { if err != nil {
@ -501,10 +481,6 @@ func (cc *Conn) getDefaultEchoReadBuffer() int {
// //
// See https://git.netfilter.org/nftables/tree/src/mnl.c?id=713592c6008a8c589a00d3d3d2e49709ff2de62c#n426 // See https://git.netfilter.org/nftables/tree/src/mnl.c?id=713592c6008a8c589a00d3d3d2e49709ff2de62c#n426
func (cc *Conn) enlargeReadBuffer(conn *netlink.Conn) error { func (cc *Conn) enlargeReadBuffer(conn *netlink.Conn) error {
if !cc.canEnlargeBuffers() {
return nil
}
var bufferSize int var bufferSize int
// If there are any messages with the Echo flag, we initialize the buffer size // If there are any messages with the Echo flag, we initialize the buffer size