Compare commits
2 Commits
7d83c94f64
...
f8c01f0bf3
Author | SHA1 | Date |
---|---|---|
|
f8c01f0bf3 | |
|
0a7196fb65 |
28
conn.go
28
conn.go
|
@ -250,10 +250,10 @@ func (cc *Conn) Flush() error {
|
|||
}
|
||||
defer func() { _ = closer() }()
|
||||
|
||||
if err = cc.enlargeWriteBuffer(conn); err != nil {
|
||||
if err := cc.enlargeWriteBuffer(conn); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = cc.enlargeReadBuffer(conn); err != nil {
|
||||
if err := cc.enlargeReadBuffer(conn); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -440,6 +440,22 @@ func (cc *Conn) getMessageSize() int {
|
|||
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
|
||||
// connection to the accumulated message size. This is only done if the current
|
||||
// write buffer is smaller than the message size.
|
||||
|
@ -453,6 +469,10 @@ func (cc *Conn) getMessageSize() int {
|
|||
// TODO: Update this function to mimic the behavior of nftables once our
|
||||
// socket library supports multiple iovec entries.
|
||||
func (cc *Conn) enlargeWriteBuffer(conn *netlink.Conn) error {
|
||||
if !cc.canEnlargeBuffers() {
|
||||
return nil
|
||||
}
|
||||
|
||||
messageSize := cc.getMessageSize()
|
||||
writeBuffer, err := conn.WriteBuffer()
|
||||
if err != nil {
|
||||
|
@ -481,6 +501,10 @@ func (cc *Conn) getDefaultEchoReadBuffer() int {
|
|||
//
|
||||
// See https://git.netfilter.org/nftables/tree/src/mnl.c?id=713592c6008a8c589a00d3d3d2e49709ff2de62c#n426
|
||||
func (cc *Conn) enlargeReadBuffer(conn *netlink.Conn) error {
|
||||
if !cc.canEnlargeBuffers() {
|
||||
return nil
|
||||
}
|
||||
|
||||
var bufferSize int
|
||||
|
||||
// If there are any messages with the Echo flag, we initialize the buffer size
|
||||
|
|
Loading…
Reference in New Issue