2017-01-16 15:19:47 +00:00
|
|
|
package netlink
|
|
|
|
|
|
|
|
import (
|
2022-01-12 22:51:04 +00:00
|
|
|
"os"
|
2017-01-16 15:19:47 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/vishvananda/netlink/nl"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestXfrmMonitorExpire(t *testing.T) {
|
2022-01-12 22:51:04 +00:00
|
|
|
if os.Getenv("CI") == "true" {
|
|
|
|
t.Skipf("Flaky in CI: Intermittently causes 10 minute timeout")
|
|
|
|
}
|
2017-11-28 06:59:57 +00:00
|
|
|
defer setUpNetlinkTest(t)()
|
2017-01-16 15:19:47 +00:00
|
|
|
|
|
|
|
ch := make(chan XfrmMsg)
|
|
|
|
done := make(chan struct{})
|
|
|
|
defer close(done)
|
|
|
|
errChan := make(chan error)
|
|
|
|
if err := XfrmMonitor(ch, nil, errChan, nl.XFRM_MSG_EXPIRE); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Program state with limits
|
|
|
|
state := getBaseState()
|
|
|
|
state.Limits.TimeHard = 2
|
|
|
|
state.Limits.TimeSoft = 1
|
|
|
|
if err := XfrmStateAdd(state); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-01-03 22:31:03 +00:00
|
|
|
hardFound := false
|
|
|
|
softFound := false
|
|
|
|
|
2017-01-16 15:19:47 +00:00
|
|
|
msg := (<-ch).(*XfrmMsgExpire)
|
2019-01-03 22:31:03 +00:00
|
|
|
if msg.XfrmState.Spi != state.Spi {
|
|
|
|
t.Fatal("Received unexpected msg, spi does not match")
|
2017-01-16 15:19:47 +00:00
|
|
|
}
|
2019-01-03 22:31:03 +00:00
|
|
|
hardFound = msg.Hard || hardFound
|
|
|
|
softFound = !msg.Hard || softFound
|
2017-01-16 15:19:47 +00:00
|
|
|
|
|
|
|
msg = (<-ch).(*XfrmMsgExpire)
|
2019-01-03 22:31:03 +00:00
|
|
|
if msg.XfrmState.Spi != state.Spi {
|
|
|
|
t.Fatal("Received unexpected msg, spi does not match")
|
|
|
|
}
|
|
|
|
hardFound = msg.Hard || hardFound
|
|
|
|
softFound = !msg.Hard || softFound
|
|
|
|
|
|
|
|
if !hardFound || !softFound {
|
|
|
|
t.Fatal("Missing expire msg: hard found:", hardFound, "soft found:", softFound)
|
2017-01-16 15:19:47 +00:00
|
|
|
}
|
|
|
|
}
|