From 50cc94889fb837172a132e4b211af1cd3fcdc6e7 Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 28 Feb 2024 17:45:24 -0800 Subject: [PATCH] feat: netlink rcv/snd buffer config options --- README.ja.md | 2 ++ README.md | 2 ++ README.zh.md | 2 ++ cmd/root.go | 12 ++++++++---- io/nfqueue.go | 20 ++++++++++++++++++-- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.ja.md b/README.ja.md index 243195a..ed281c4 100644 --- a/README.ja.md +++ b/README.ja.md @@ -70,6 +70,8 @@ opkg install kmod-nft-queue kmod-nf-conntrack-netlink ```yaml io: queueSize: 1024 + rcvBuf: 4194304 + sndBuf: 4194304 local: true # FORWARD チェーンで OpenGFW を実行したい場合は false に設定する workers: diff --git a/README.md b/README.md index fa177e8..0094047 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,8 @@ opkg install kmod-nft-queue kmod-nf-conntrack-netlink ```yaml io: queueSize: 1024 + rcvBuf: 4194304 + sndBuf: 4194304 local: true # set to false if you want to run OpenGFW on FORWARD chain workers: diff --git a/README.zh.md b/README.zh.md index 42b43a2..0a5bb9c 100644 --- a/README.zh.md +++ b/README.zh.md @@ -70,6 +70,8 @@ opkg install kmod-nft-queue kmod-nf-conntrack-netlink ```yaml io: queueSize: 1024 + rcvBuf: 4194304 + sndBuf: 4194304 local: true # 如果需要在 FORWARD 链上运行 OpenGFW,请设置为 false workers: diff --git a/cmd/root.go b/cmd/root.go index a60338d..aec1650 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -168,8 +168,10 @@ type cliConfig struct { } type cliConfigIO struct { - QueueSize uint32 `mapstructure:"queueSize"` - Local bool `mapstructure:"local"` + QueueSize uint32 `mapstructure:"queueSize"` + ReadBuffer int `mapstructure:"rcvBuf"` + WriteBuffer int `mapstructure:"sndBuf"` + Local bool `mapstructure:"local"` } type cliConfigWorkers struct { @@ -192,8 +194,10 @@ func (c *cliConfig) fillLogger(config *engine.Config) error { func (c *cliConfig) fillIO(config *engine.Config) error { nfio, err := io.NewNFQueuePacketIO(io.NFQueuePacketIOConfig{ - QueueSize: c.IO.QueueSize, - Local: c.IO.Local, + QueueSize: c.IO.QueueSize, + ReadBuffer: c.IO.ReadBuffer, + WriteBuffer: c.IO.WriteBuffer, + Local: c.IO.Local, }) if err != nil { return configError{Field: "io", Err: err} diff --git a/io/nfqueue.go b/io/nfqueue.go index d299479..2c1cff2 100644 --- a/io/nfqueue.go +++ b/io/nfqueue.go @@ -97,8 +97,10 @@ type nfqueuePacketIO struct { } type NFQueuePacketIOConfig struct { - QueueSize uint32 - Local bool + QueueSize uint32 + ReadBuffer int + WriteBuffer int + Local bool } func NewNFQueuePacketIO(config NFQueuePacketIOConfig) (PacketIO, error) { @@ -128,6 +130,20 @@ func NewNFQueuePacketIO(config NFQueuePacketIOConfig) (PacketIO, error) { if err != nil { return nil, err } + if config.ReadBuffer > 0 { + err = n.Con.SetReadBuffer(config.ReadBuffer) + if err != nil { + _ = n.Close() + return nil, err + } + } + if config.WriteBuffer > 0 { + err = n.Con.SetWriteBuffer(config.WriteBuffer) + if err != nil { + _ = n.Close() + return nil, err + } + } return &nfqueuePacketIO{ n: n, local: config.Local,