mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-10-29 13:38:50 +08:00
The iptables path wrote each whitelisted CIDR with its own iptables process. With the mainland China group (about 15,000 CIDRs) a core start spent minutes on this, and every packet of a direct connection walked the list linearly. Load each family into one hash:net set with a single `ipset restore` and match it with one rule at the old position. Without ipset, write the rules with one `iptables-restore --noflush` per family; without that, keep the per-rule commands. Cleanup destroys the sets.
23 lines
471 B
Go
23 lines
471 B
Go
package cmds
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestExecCommandWithInput(t *testing.T) {
|
|
output := filepath.Join(t.TempDir(), "stdin")
|
|
err := ExecCommandWithInput("sh", []string{"-c", `IFS= read -r value; printf %s "$value" > "$1"`, "sh", output}, "payload\n")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := os.ReadFile(output)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(got) != "payload" {
|
|
t.Fatalf("stdin payload = %q, want payload", got)
|
|
}
|
|
}
|