func TestConnTrackerCrossNamespaceAllNsDisabled(t *testing.T) {
	defer testutil.TeardownCrossNsDNAT(t)
	testutil.SetupCrossNsDNAT(t)

	cfg := config.New()
	cfg.ConntrackMaxStateSize = 100
	cfg.ConntrackRateLimit = 500
	cfg.EnableConntrackAllNamespaces = false
	ct, err := NewConntracker(cfg)
	require.NoError(t, err)
	time.Sleep(time.Second)

	closer := nettestutil.StartServerTCPNs(t, net.ParseIP("2.2.2.4"), 8080, "test")
	laddr := nettestutil.PingTCP(t, net.ParseIP("2.2.2.4"), 80).LocalAddr().(*net.TCPAddr)
	defer closer.Close()

	testNs, err := netns.GetFromName("test")
	require.NoError(t, err)
	defer testNs.Close()

	testIno, err := util.GetInoForNs(testNs)
	require.NoError(t, err)

	time.Sleep(time.Second)
	trans := ct.GetTranslationForConn(
		network.ConnectionStats{
			Source: util.AddressFromNetIP(laddr.IP),
			SPort:  uint16(laddr.Port),
			Dest:   util.AddressFromString("2.2.2.4"),
			DPort:  uint16(80),
			Type:   network.TCP,
			NetNS:  testIno,
		},
	)

	assert.Nil(t, trans)
}
// keep this test for netlink only, because eBPF listens to all namespaces all the time.
keep this test for netlink only, because eBPF listens to all namespaces all the time.
// keep this test for netlink only because eBPF listens to all namespaces all the time .
func TestConnTrackerCrossNamespaceAllNsDisabled(t *testing.T) {
	defer testutil.TeardownCrossNsDNAT(t)
	testutil.SetupCrossNsDNAT(t)
	cfg := config.New()
	cfg.ConntrackMaxStateSize = 100
	cfg.ConntrackRateLimit = 500
	cfg.EnableConntrackAllNamespaces = false
	ct, err := NewConntracker(cfg)
	require.NoError(t, err)
	time.Sleep(time.Second)
	closer := nettestutil.StartServerTCPNs(t, net.ParseIP("2.2.2.4"), 8080, "test")
	laddr := nettestutil.PingTCP(t, net.ParseIP("2.2.2.4"), 80).LocalAddr().(*net.TCPAddr)
	defer closer.Close()
	testNs, err := netns.GetFromName("test")
	require.NoError(t, err)
	defer testNs.Close()
	testIno, err := util.GetInoForNs(testNs)
	require.NoError(t, err)
	time.Sleep(time.Second)
	trans := ct.GetTranslationForConn(
		network.ConnectionStats{
			Source: util.AddressFromNetIP(laddr.IP),
			SPort:  uint16(laddr.Port),
			Dest:   util.AddressFromString("2.2.2.4"),
			DPort:  uint16(80),
			Type:   network.TCP,
			NetNS:  testIno,
		},
	)
	assert.Nil(t, trans)
}
func TestConnTrackerCrossNamespaceAllNsDisabled ( t * testing . T ) { defer testutil . TeardownCrossNsDNAT ( t ) testutil . SetupCrossNsDNAT ( t ) cfg := config . New ( ) cfg . ConntrackMaxStateSize = 100 cfg . ConntrackRateLimit = 500 cfg . EnableConntrackAllNamespaces = false ct , err := NewConntracker ( cfg ) require . NoError ( t , err ) time . Sleep ( time . Second ) closer := nettestutil . StartServerTCPNs ( t , net . ParseIP ( " " ) , 8080 , " " ) laddr := nettestutil . PingTCP ( t , net . ParseIP ( " " ) , 80 ) . LocalAddr ( ) . ( * net . TCPAddr ) defer closer . Close ( ) testNs , err := netns . GetFromName ( " " ) require . NoError ( t , err ) defer testNs . Close ( ) testIno , err := util . GetInoForNs ( testNs ) require . NoError ( t , err ) time . Sleep ( time . Second ) trans := ct . GetTranslationForConn ( network . ConnectionStats { Source : util . AddressFromNetIP ( laddr . IP ) , SPort : uint16 ( laddr . Port ) , Dest : util . AddressFromString ( " " ) , DPort : uint16 ( 80 ) , Type : network . TCP , NetNS : testIno , } , ) assert . Nil ( t , trans ) }
keep this test for netlink only, because eBPF listens to all namespaces all the time.
keep this test for netlink only because eBPF listens to all namespaces all the time .