From 7566b3bb3433ba01e16e1838f7d7276228ae3606 Mon Sep 17 00:00:00 2001 From: Artem Glazychev Date: Tue, 26 Mar 2024 14:24:59 +0700 Subject: [PATCH] Fix vl3 ipam refresh Signed-off-by: Artem Glazychev --- pkg/networkservice/chains/nsmgr/vl3_test.go | 17 +++++++++++++++++ .../connectioncontext/ipcontext/vl3/ipam.go | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pkg/networkservice/chains/nsmgr/vl3_test.go b/pkg/networkservice/chains/nsmgr/vl3_test.go index 67fc1a0d4..4d365fac0 100644 --- a/pkg/networkservice/chains/nsmgr/vl3_test.go +++ b/pkg/networkservice/chains/nsmgr/vl3_test.go @@ -30,6 +30,7 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/require" "go.uber.org/goleak" + "google.golang.org/protobuf/proto" "github.com/networkservicemesh/api/pkg/api/networkservice" "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls" @@ -528,9 +529,17 @@ func Test_NSC_ConnectsTo_vl3NSE_With_Invalid_IpContext(t *testing.T) { req := defaultRequest(nsReg.Name) conn, err := nsc.Request(ctx, req) require.NoError(t, err) + require.True(t, checkIPContext(conn.Context.IpContext, prefix1)) + // Refresh + clonedConn := conn.Clone() + req.Connection = conn + conn, err = nsc.Request(ctx, req) + require.NoError(t, err) require.True(t, checkIPContext(conn.Context.IpContext, prefix1)) + require.True(t, proto.Equal(clonedConn.GetContext().IpContext, conn.GetContext().IpContext)) + // Reset ipam with a new prefix err = serverIpam.Reset(prefix2) require.NoError(t, err) @@ -540,6 +549,14 @@ func Test_NSC_ConnectsTo_vl3NSE_With_Invalid_IpContext(t *testing.T) { require.False(t, checkIPContext(conn.Context.IpContext, prefix1)) require.True(t, checkIPContext(conn.Context.IpContext, prefix2)) + + // Refresh + clonedConn = conn.Clone() + req.Connection = conn + conn, err = nsc.Request(ctx, req) + require.NoError(t, err) + require.True(t, checkIPContext(conn.Context.IpContext, prefix2)) + require.True(t, proto.Equal(clonedConn.GetContext().IpContext, conn.GetContext().IpContext)) } func checkIPContext(ipContext *networkservice.IPContext, prefix string) bool { diff --git a/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go b/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go index cf1e9b74e..8f3f2dac0 100644 --- a/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go +++ b/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go @@ -185,5 +185,12 @@ func (p *IPAM) Reset(prefix string, excludePrefies ...string) error { func (p *IPAM) ContainsNetString(ipNet string) bool { p.Lock() defer p.Unlock() - return p.ipPool.ContainsNetString(ipNet) + selfAddress := &net.IPNet{ + IP: p.self.IP, + Mask: net.CIDRMask( + int(p.clientMask), + int(p.clientMask), + ), + } + return p.ipPool.ContainsNetString(ipNet) || selfAddress.String() == ipNet }