Compare commits
2 Commits
90eef68fb3
...
24b208f66c
Author | SHA1 | Date |
---|---|---|
|
24b208f66c | |
|
7218f2ae46 |
|
@ -7669,13 +7669,42 @@ func TestNftablesCompat(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNftablesDeadlock(t *testing.T) {
|
func TestNftablesDeadlock(t *testing.T) {
|
||||||
helperConn := func(t *testing.T, readBufSize, writeBufSize, wantRules int) (error, int) {
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
readBufSize int
|
||||||
|
writeBufSize int
|
||||||
|
sendRules int
|
||||||
|
wantRules int
|
||||||
|
wantErr error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "recv",
|
||||||
|
readBufSize: 1024,
|
||||||
|
writeBufSize: 1 * 1024 * 1024,
|
||||||
|
sendRules: 2048,
|
||||||
|
wantRules: 2048,
|
||||||
|
wantErr: syscall.ENOBUFS,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "send",
|
||||||
|
readBufSize: 1 * 1024 * 1024,
|
||||||
|
writeBufSize: 1024,
|
||||||
|
sendRules: 2048,
|
||||||
|
wantRules: 0,
|
||||||
|
wantErr: syscall.EMSGSIZE,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
_, newNS := nftest.OpenSystemConn(t, *enableSysTests)
|
_, newNS := nftest.OpenSystemConn(t, *enableSysTests)
|
||||||
conn, err := nftables.New(nftables.WithNetNSFd(int(newNS)), nftables.WithSockOptions(func(conn *netlink.Conn) error {
|
conn, err := nftables.New(nftables.WithNetNSFd(int(newNS)), nftables.WithSockOptions(func(conn *netlink.Conn) error {
|
||||||
if err := conn.SetWriteBuffer(writeBufSize); err != nil {
|
if err := conn.SetWriteBuffer(tt.writeBufSize); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := conn.SetReadBuffer(readBufSize); err != nil {
|
if err := conn.SetReadBuffer(tt.readBufSize); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -7697,7 +7726,7 @@ func TestNftablesDeadlock(t *testing.T) {
|
||||||
Table: table,
|
Table: table,
|
||||||
})
|
})
|
||||||
|
|
||||||
for i := 0; i < wantRules; i++ {
|
for i := 0; i < tt.sendRules; i++ {
|
||||||
conn.AddRule(&nftables.Rule{
|
conn.AddRule(&nftables.Rule{
|
||||||
Table: table,
|
Table: table,
|
||||||
Chain: chain,
|
Chain: chain,
|
||||||
|
@ -7710,39 +7739,18 @@ func TestNftablesDeadlock(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
flushErr := conn.Flush()
|
flushErr := conn.Flush()
|
||||||
|
|
||||||
rules, err := conn.GetRules(table, chain)
|
rules, err := conn.GetRules(table, chain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("conn.GetRules() failed: %v", err)
|
t.Fatalf("conn.GetRules() failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return flushErr, len(rules)
|
if !errors.Is(flushErr, tt.wantErr) {
|
||||||
}
|
|
||||||
|
|
||||||
t.Run("recv", func(t *testing.T) {
|
|
||||||
sendRules := 2048
|
|
||||||
wantRules := 2048
|
|
||||||
|
|
||||||
flushErr, rulesLen := helperConn(t, 1024, 1*1024*1024, sendRules)
|
|
||||||
if !errors.Is(flushErr, syscall.ENOBUFS) {
|
|
||||||
t.Errorf("conn.Flush() failed: %v", flushErr)
|
t.Errorf("conn.Flush() failed: %v", flushErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if got, want := rulesLen, wantRules; got != want {
|
if got, want := len(rules), tt.wantRules; got != want {
|
||||||
t.Fatalf("got rules %d, want rules %d", got, want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
t.Run("send", func(t *testing.T) {
|
|
||||||
sendRules := 2048
|
|
||||||
wantRules := 0
|
|
||||||
|
|
||||||
flushErr, rulesLen := helperConn(t, 1*1024*1024, 1024, sendRules)
|
|
||||||
if !errors.Is(flushErr, syscall.EMSGSIZE) {
|
|
||||||
t.Errorf("conn.Flush() failed: %v", flushErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
if got, want := rulesLen, wantRules; got != want {
|
|
||||||
t.Fatalf("got rules %d, want rules %d", got, want)
|
t.Fatalf("got rules %d, want rules %d", got, want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue