From 2181de9f75edb9e5e7b46d36a42ff5c5f903a29e Mon Sep 17 00:00:00 2001 From: Daniel Grau Date: Thu, 28 Mar 2024 22:21:04 +0000 Subject: [PATCH 1/4] hostif --- dataplane/forwarding/fwdconfig/table.go | 35 ++++++++++ dataplane/saiserver/hostif.go | 92 ++++++++++++++++++++++--- dataplane/saiserver/switch.go | 1 + 3 files changed, 119 insertions(+), 9 deletions(-) diff --git a/dataplane/forwarding/fwdconfig/table.go b/dataplane/forwarding/fwdconfig/table.go index 2a450bf5..07ca15bd 100644 --- a/dataplane/forwarding/fwdconfig/table.go +++ b/dataplane/forwarding/fwdconfig/table.go @@ -69,6 +69,41 @@ func (b TableEntryAddRequestBuilder) Build() *fwdpb.TableEntryAddRequest { return req } +// TableEntryAddRequest builds TableEntryAddRequests. +type TableEntryRemoveRequestBuilder struct { + contextID string + tableID string + entries []*EntryDescBuilder + actions [][]*ActionBuilder +} + +// TableEntryRemoveRequest creates a new TableEntryRemoveRequestBuilder. +func TableEntryRemoveRequest(ctxID, tableID string) *TableEntryRemoveRequestBuilder { + return &TableEntryRemoveRequestBuilder{ + contextID: ctxID, + tableID: tableID, + } +} + +// AppendEntry adds an entry to the requests. +func (b *TableEntryRemoveRequestBuilder) AppendEntry(entry *EntryDescBuilder) *TableEntryRemoveRequestBuilder { + b.entries = append(b.entries, entry) + return b +} + +// Build returns a new TableEntryAddRequest. +func (b TableEntryRemoveRequestBuilder) Build() *fwdpb.TableEntryRemoveRequest { + req := &fwdpb.TableEntryRemoveRequest{ + ContextId: &fwdpb.ContextId{Id: b.contextID}, + TableId: &fwdpb.TableId{ObjectId: &fwdpb.ObjectId{Id: b.tableID}}, + Entries: []*fwdpb.EntryDesc{}, + } + for _, entry := range b.entries { + req.Entries = append(req.Entries, entry.Build()) + } + return req +} + type entryDescBuilder interface { set(*fwdpb.EntryDesc) } diff --git a/dataplane/saiserver/hostif.go b/dataplane/saiserver/hostif.go index fe74136d..aeaf21fd 100644 --- a/dataplane/saiserver/hostif.go +++ b/dataplane/saiserver/hostif.go @@ -17,6 +17,7 @@ package saiserver import ( "context" "fmt" + "sync" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -42,6 +43,7 @@ func newHostif(mgr *attrmgr.AttrMgr, dataplane switchDataplaneAPI, s *grpc.Serve dataplane: dataplane, trapIDToHostifID: map[uint64]uint64{}, groupIDToQueue: map[uint64]uint32{}, + remoteHostifs: map[uint64]*pktiopb.HostPortControlMessage{}, opts: opts, } @@ -57,7 +59,19 @@ type hostif struct { trapIDToHostifID map[uint64]uint64 groupIDToQueue map[uint64]uint32 opts *dplaneopts.Options - sendPortReq func(msg *pktiopb.HostPortControlMessage) error + remoteMu sync.Mutex + remoteHostifs map[uint64]*pktiopb.HostPortControlMessage + remoteClosers []func() + remotePortReq func(msg *pktiopb.HostPortControlMessage) error +} + +func (hostif *hostif) Reset() { + hostif.trapIDToHostifID = map[uint64]uint64{} + hostif.groupIDToQueue = map[uint64]uint32{} + hostif.remoteHostifs = map[uint64]*pktiopb.HostPortControlMessage{} + for _, closeFn := range hostif.remoteClosers { + closeFn() + } } const switchID = 1 @@ -235,6 +249,8 @@ func (hostif *hostif) CreateHostif(ctx context.Context, req *saipb.CreateHostifR func (hostif *hostif) createRemoteHostif(ctx context.Context, req *saipb.CreateHostifRequest) (*saipb.CreateHostifResponse, error) { id := hostif.mgr.NextID() + hostif.remoteMu.Lock() + defer hostif.remoteMu.Unlock() ctlReq := &pktiopb.HostPortControlMessage{ Create: true, @@ -294,18 +310,65 @@ func (hostif *hostif) createRemoteHostif(ctx context.Context, req *saipb.CreateH return nil, status.Errorf(codes.InvalidArgument, "unknown type %v", req.GetType()) } + if hostif.remotePortReq == nil { + return nil, status.Error(codes.FailedPrecondition, "remote port control not configured") + } + if err := hostif.remotePortReq(ctlReq); err != nil { + return nil, err + } + attr := &saipb.HostifAttribute{ OperStatus: proto.Bool(true), } hostif.mgr.StoreAttributes(id, attr) + hostif.remoteHostifs[id] = ctlReq - if hostif.sendPortReq != nil { - if err := hostif.sendPortReq(ctlReq); err != nil { - return nil, err - } + return &saipb.CreateHostifResponse{Oid: id}, nil +} + +func (hostif *hostif) RemoveHostif(ctx context.Context, req *saipb.RemoveHostifRequest) (*saipb.RemoveHostifResponse, error) { + if !hostif.opts.RemoteCPUPort { + return nil, status.Error(codes.Unimplemented, "only remote cpu port is supported") } + hostif.remoteMu.Lock() + defer hostif.remoteMu.Unlock() - return &saipb.CreateHostifResponse{Oid: id}, nil + nid, err := hostif.dataplane.ObjectNID(ctx, &fwdpb.ObjectNIDRequest{ + ContextId: &fwdpb.ContextId{Id: hostif.dataplane.ID()}, + ObjectId: &fwdpb.ObjectId{Id: fmt.Sprint(hostif.remoteHostifs[req.GetOid()])}, + }) + if err != nil { + return nil, err + } + + delReq := fwdconfig.TableEntryRemoveRequest(hostif.dataplane.ID(), hostifToPortTable).AppendEntry( + fwdconfig.EntryDesc(fwdconfig.ExactEntry(fwdconfig.PacketFieldBytes(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_HOST_PORT_ID).WithUint64(req.GetOid()))), + ).Build() + if _, err := hostif.dataplane.TableEntryRemove(ctx, delReq); err != nil { + return nil, err + } + + delReq = fwdconfig.TableEntryRemoveRequest(hostif.dataplane.ID(), portToHostifTable).AppendEntry( + fwdconfig.EntryDesc(fwdconfig.ExactEntry(fwdconfig.PacketFieldBytes(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_PACKET_PORT_INPUT).WithUint64(nid.GetNid()))), + ).Build() + if _, err := hostif.dataplane.TableEntryRemove(ctx, delReq); err != nil { + return nil, err + } + + ctlReq := &pktiopb.HostPortControlMessage{ + Create: false, + PortId: req.Oid, + } + + if hostif.remotePortReq == nil { + return nil, status.Error(codes.FailedPrecondition, "remote port control not configured") + } + if err := hostif.remotePortReq(ctlReq); err != nil { + return nil, err + } + delete(hostif.remoteHostifs, req.Oid) + + return &saipb.RemoveHostifResponse{}, nil } // SetHostifAttribute sets the attributes in the request. @@ -529,20 +592,31 @@ func (hostif *hostif) HostPortControl(srv pktiopb.PacketIO_HostPortControlServer if err != nil { return err } - // TODO: Whenever this RPC is connected, should resend all existing hostifs to tolerate the client restarting. + hostif.remoteMu.Lock() + ctx, cancelFn := context.WithCancel(srv.Context()) + hostif.remoteClosers = append(hostif.remoteClosers, cancelFn) reqCh := make(chan *pktiopb.HostPortControlMessage) respCh := make(chan *pktiopb.HostPortControlRequest) - hostif.sendPortReq = func(msg *pktiopb.HostPortControlMessage) error { + hostif.remotePortReq = func(msg *pktiopb.HostPortControlMessage) error { reqCh <- msg resp := <-respCh return status.FromProto(resp.GetStatus()).Err() } + // Send all existing hostif. + for _, msg := range hostif.remoteHostifs { + if err := hostif.remotePortReq(msg); err != nil { + hostif.remoteMu.Unlock() + return err + } + } + hostif.remoteMu.Unlock() + log.Info("initialized host port control channel") for { select { - case <-srv.Context().Done(): + case <-ctx.Done(): return nil case req := <-reqCh: if err := srv.Send(req); err != nil { diff --git a/dataplane/saiserver/switch.go b/dataplane/saiserver/switch.go index 7f6aabcd..b86dffdb 100644 --- a/dataplane/saiserver/switch.go +++ b/dataplane/saiserver/switch.go @@ -786,6 +786,7 @@ func (sw *saiSwitch) PortStateChangeNotification(_ *saipb.PortStateChangeNotific func (sw saiSwitch) Reset() { sw.port.Reset() + sw.hostif.Reset() } // createFIBSelector creates a table that controls which forwarding table is used. From 30c71607df00e4d8ca5306aaa2826a098563352d Mon Sep 17 00:00:00 2001 From: Daniel Grau Date: Thu, 28 Mar 2024 23:10:17 +0000 Subject: [PATCH 2/4] debug file --- Makefile | 2 +- dataplane/forwarding/fwdconfig/table.go | 1 - dataplane/server.go | 2 +- dataplane/standalone/pkthandler/main.go | 7 ++++- .../pkthandler/pktiohandler/pktiohandler.go | 29 ++++++++++++++++++- .../pktiohandler/pktiohandler_test.go | 4 +-- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index aa2701cd..05bf6d71 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ load-debug: ## Run integration tests .PHONY: itest itest: - bazel test --test_output=errors --cache_test_results=no $(shell bazel query 'tests("//...") except (attr(size, small, tests("//...")) + attr(size, medium, tests("//..."))) ') + bazel test --flaky_test_attempts=3 --test_output=errors --cache_test_results=no $(shell bazel query 'tests("//...") except (attr(size, small, tests("//...")) + attr(size, medium, tests("//..."))) ') .PHONY: test test: diff --git a/dataplane/forwarding/fwdconfig/table.go b/dataplane/forwarding/fwdconfig/table.go index 07ca15bd..320390d8 100644 --- a/dataplane/forwarding/fwdconfig/table.go +++ b/dataplane/forwarding/fwdconfig/table.go @@ -74,7 +74,6 @@ type TableEntryRemoveRequestBuilder struct { contextID string tableID string entries []*EntryDescBuilder - actions [][]*ActionBuilder } // TableEntryRemoveRequest creates a new TableEntryRemoveRequestBuilder. diff --git a/dataplane/server.go b/dataplane/server.go index 841c4adb..bdc6f6e2 100644 --- a/dataplane/server.go +++ b/dataplane/server.go @@ -134,7 +134,7 @@ func (d *Dataplane) Start(ctx context.Context, c gpb.GNMIClient, target string) return err } - h, err := pktiohandler.New() + h, err := pktiohandler.New("") if err != nil { return err } diff --git a/dataplane/standalone/pkthandler/main.go b/dataplane/standalone/pkthandler/main.go index fa216d1b..2c8f4cc2 100644 --- a/dataplane/standalone/pkthandler/main.go +++ b/dataplane/standalone/pkthandler/main.go @@ -16,6 +16,7 @@ package main import ( "context" + "flag" "os" "os/signal" "sync" @@ -35,7 +36,11 @@ const ( addr = "10.0.2.2:50000" ) +var portFile = flag.String("port_file", "/etc/sonic/pktio_ports.json", "File at which to include hostif info, for debugging only") + func main() { + flag.Parse() + ctx, cancelFn := context.WithTimeout(context.Background(), time.Minute) defer cancelFn() @@ -46,7 +51,7 @@ func main() { pktio := pktiopb.NewPacketIOClient(conn) - h, err := pktiohandler.New() + h, err := pktiohandler.New(*portFile) if err != nil { log.Exit(err) } diff --git a/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go b/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go index 8ee61a43..5d372320 100644 --- a/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go +++ b/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go @@ -15,13 +15,16 @@ package pktiohandler import ( + "encoding/json" "errors" "fmt" "io" + "os" "time" "google.golang.org/genproto/googleapis/rpc/status" "google.golang.org/grpc/codes" + "google.golang.org/protobuf/encoding/protojson" "github.com/openconfig/lemming/dataplane/forwarding/util/queue" "github.com/openconfig/lemming/dataplane/internal/kernel" @@ -32,7 +35,7 @@ import ( ) // New returns a new PacketIOMgr -func New() (*PacketIOMgr, error) { +func New(portFile string) (*PacketIOMgr, error) { q, err := queue.NewUnbounded("send") if err != nil { return nil, err @@ -42,6 +45,7 @@ func New() (*PacketIOMgr, error) { hostifs: map[uint64]*port{}, dplanePortIfIndex: map[uint64]int{}, sendQueue: q, + portFile: portFile, }, nil } @@ -50,11 +54,13 @@ type PacketIOMgr struct { hostifs map[uint64]*port dplanePortIfIndex map[uint64]int // For tap devices, maps the dataport port id to hostif if index. sendQueue *queue.Queue + portFile string } type port struct { portIO cancelFn func() + msg *pktiopb.HostPortControlMessage } type portIO interface { @@ -117,6 +123,21 @@ func (m *PacketIOMgr) metadataFromPacket(p *pktiopb.Packet) *kernel.PacketMetada return md } +func (m *PacketIOMgr) writePorts() error { + if m.portFile == "" { + return nil + } + data := map[uint64]string{} + for id, h := range m.hostifs { + data[id] = protojson.Format(h.msg) + } + contents, err := json.Marshal(data) + if err != nil { + return err + } + return os.WriteFile(m.portFile, contents, 0666) +} + // ManagePorts handles HostPortControl message from a forwarding server. func (m *PacketIOMgr) ManagePorts(c pktiopb.PacketIO_HostPortControlClient) error { if err := c.Send(&pktiopb.HostPortControlRequest{Msg: &pktiopb.HostPortControlRequest_Init{}}); err != nil { @@ -144,6 +165,9 @@ func (m *PacketIOMgr) ManagePorts(c pktiopb.PacketIO_HostPortControlClient) erro if sendErr != nil { return sendErr } + if err := m.writePorts(); err != nil { + log.Warningf("failed to write file: %v", err) + } } else { p, ok := m.hostifs[resp.GetPortId()] if !ok { @@ -182,6 +206,9 @@ func (m *PacketIOMgr) ManagePorts(c pktiopb.PacketIO_HostPortControlClient) erro if sendErr != nil { return sendErr } + if err := m.writePorts(); err != nil { + log.Warningf("failed to write file: %v", err) + } } } } diff --git a/dataplane/standalone/pkthandler/pktiohandler/pktiohandler_test.go b/dataplane/standalone/pkthandler/pktiohandler/pktiohandler_test.go index db997a29..beee44e6 100644 --- a/dataplane/standalone/pkthandler/pktiohandler/pktiohandler_test.go +++ b/dataplane/standalone/pkthandler/pktiohandler/pktiohandler_test.go @@ -69,7 +69,7 @@ func TestStreamPackets(t *testing.T) { }} for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { - mgr, err := New() + mgr, err := New("") if err != nil { t.Fatalf("unexpected error on New(): %v", err) } @@ -123,7 +123,7 @@ func TestManagePorts(t *testing.T) { }} for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { - mgr, err := New() + mgr, err := New("") if err != nil { t.Fatalf("unexpected error on New(): %v", err) } From 1a836b7b51f960cc1246a2407bac24a9c4fe8985 Mon Sep 17 00:00:00 2001 From: Daniel Grau Date: Fri, 29 Mar 2024 19:23:52 +0000 Subject: [PATCH 3/4] fixes --- dataplane/saiserver/BUILD | 3 + dataplane/saiserver/hostif.go | 2 +- dataplane/saiserver/hostif_test.go | 91 ++++++++++++++++++- .../standalone/pkthandler/pktiohandler/BUILD | 1 + .../pkthandler/pktiohandler/pktiohandler.go | 2 +- 5 files changed, 92 insertions(+), 7 deletions(-) diff --git a/dataplane/saiserver/BUILD b/dataplane/saiserver/BUILD index 88041fd8..95a6cad0 100644 --- a/dataplane/saiserver/BUILD +++ b/dataplane/saiserver/BUILD @@ -49,12 +49,15 @@ go_test( "//dataplane/dplaneopts", "//dataplane/forwarding/infra/fwdcontext", "//dataplane/forwarding/infra/fwdobject", + "//dataplane/proto/packetio", "//dataplane/proto/sai", "//dataplane/saiserver/attrmgr", "//proto/forwarding", "@com_github_google_go_cmp//cmp", "@com_github_openconfig_gnmi//errdiff", + "@org_golang_google_genproto_googleapis_rpc//status", "@org_golang_google_grpc//:go_default_library", + "@org_golang_google_grpc//codes", "@org_golang_google_grpc//credentials/insecure", "@org_golang_google_protobuf//proto", "@org_golang_google_protobuf//testing/protocmp", diff --git a/dataplane/saiserver/hostif.go b/dataplane/saiserver/hostif.go index aeaf21fd..6133bc9e 100644 --- a/dataplane/saiserver/hostif.go +++ b/dataplane/saiserver/hostif.go @@ -328,7 +328,7 @@ func (hostif *hostif) createRemoteHostif(ctx context.Context, req *saipb.CreateH func (hostif *hostif) RemoveHostif(ctx context.Context, req *saipb.RemoveHostifRequest) (*saipb.RemoveHostifResponse, error) { if !hostif.opts.RemoteCPUPort { - return nil, status.Error(codes.Unimplemented, "only remote cpu port is supported") + return nil, status.Error(codes.FailedPrecondition, "only remote cpu port is supported") } hostif.remoteMu.Lock() defer hostif.remoteMu.Unlock() diff --git a/dataplane/saiserver/hostif_test.go b/dataplane/saiserver/hostif_test.go index 0aea67d2..f83b8fa7 100644 --- a/dataplane/saiserver/hostif_test.go +++ b/dataplane/saiserver/hostif_test.go @@ -18,15 +18,19 @@ import ( "context" "net" "testing" + "time" "github.com/google/go-cmp/cmp" "github.com/openconfig/gnmi/errdiff" + "google.golang.org/genproto/googleapis/rpc/status" "google.golang.org/grpc" + "google.golang.org/grpc/codes" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/testing/protocmp" "github.com/openconfig/lemming/dataplane/dplaneopts" "github.com/openconfig/lemming/dataplane/forwarding/infra/fwdcontext" + pktiopb "github.com/openconfig/lemming/dataplane/proto/packetio" saipb "github.com/openconfig/lemming/dataplane/proto/sai" "github.com/openconfig/lemming/dataplane/saiserver/attrmgr" fwdpb "github.com/openconfig/lemming/proto/forwarding" @@ -81,7 +85,7 @@ func TestCreateHostif(t *testing.T) { ctx: fwdcontext.New("foo", "foo"), } dplane.ctx.SetPacketSink(func(*fwdpb.PacketSinkResponse) error { return nil }) - c, mgr, stopFn := newTestHostif(t, dplane) + c, mgr, stopFn := newTestHostif(t, dplane, false) // Create switch and ports mgr.StoreAttributes(mgr.NextID(), &saipb.SwitchAttribute{ CpuPort: proto.Uint64(10), @@ -115,6 +119,72 @@ func TestCreateHostif(t *testing.T) { } } +func TestRemoveHostif(t *testing.T) { + tests := []struct { + desc string + req *saipb.RemoveHostifRequest + want *pktiopb.HostPortControlMessage + wantErr string + }{{ + desc: "sucess", + req: &saipb.RemoveHostifRequest{ + Oid: 1, + }, + want: &pktiopb.HostPortControlMessage{ + PortId: 1, + }, + }} + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + dplane := &fakeSwitchDataplane{ + portIDToNID: map[string]uint64{ + "1": 10, + }, + } + c, mgr, stopFn := newTestHostif(t, dplane, true) + defer stopFn() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + mgr.StoreAttributes(1, &saipb.CreateHostifRequest{Name: []byte("eth1")}) + + msgCh := make(chan *pktiopb.HostPortControlMessage, 1) + pc, err := c.HostPortControl(ctx) + if err != nil { + t.Fatal(err) + } + if err := pc.Send(&pktiopb.HostPortControlRequest{Msg: &pktiopb.HostPortControlRequest_Init{}}); err != nil { + t.Fatal(err) + } + time.Sleep(time.Millisecond) + go func() { + msg, _ := pc.Recv() + msgCh <- msg + pc.Send(&pktiopb.HostPortControlRequest{ + Msg: &pktiopb.HostPortControlRequest_Status{ + Status: &status.Status{ + Code: int32(codes.OK), + Message: "", + }, + }, + }) + }() + + _, gotErr := c.RemoveHostif(context.TODO(), tt.req) + if diff := errdiff.Check(gotErr, tt.wantErr); diff != "" { + t.Fatalf("RemoveHostif() unexpected err: %s", diff) + } + if gotErr != nil { + return + } + got := <-msgCh + if d := cmp.Diff(got, tt.want, protocmp.Transform()); d != "" { + t.Errorf("RemoveHostif() failed: diff(-got,+want)\n:%s", d) + } + }) + } +} + func TestSetHostifAttribute(t *testing.T) { tests := []struct { desc string @@ -144,7 +214,7 @@ func TestSetHostifAttribute(t *testing.T) { return nil, tt.getInterfaceErr } dplane := &fakeSwitchDataplane{} - c, mgr, stopFn := newTestHostif(t, dplane) + c, mgr, stopFn := newTestHostif(t, dplane, false) defer stopFn() _, gotErr := c.SetHostifAttribute(context.TODO(), tt.req) if diff := errdiff.Check(gotErr, tt.wantErr); diff != "" { @@ -167,9 +237,20 @@ func TestSetHostifAttribute(t *testing.T) { } } -func newTestHostif(t testing.TB, api switchDataplaneAPI) (saipb.HostifClient, *attrmgr.AttrMgr, func()) { +type hostifClient struct { + saipb.HostifClient + pktiopb.PacketIOClient +} + +func newTestHostif(t testing.TB, api switchDataplaneAPI, remotePort bool) (*hostifClient, *attrmgr.AttrMgr, func()) { conn, mgr, stopFn := newTestServer(t, func(mgr *attrmgr.AttrMgr, srv *grpc.Server) { - newHostif(mgr, api, srv, &dplaneopts.Options{HostifNetDevType: fwdpb.PortType_PORT_TYPE_KERNEL}) + newHostif(mgr, api, srv, &dplaneopts.Options{ + HostifNetDevType: fwdpb.PortType_PORT_TYPE_KERNEL, + RemoteCPUPort: remotePort, + }) }) - return saipb.NewHostifClient(conn), mgr, stopFn + return &hostifClient{ + HostifClient: saipb.NewHostifClient(conn), + PacketIOClient: pktiopb.NewPacketIOClient(conn), + }, mgr, stopFn } diff --git a/dataplane/standalone/pkthandler/pktiohandler/BUILD b/dataplane/standalone/pkthandler/pktiohandler/BUILD index 53f79435..15dd8d6e 100644 --- a/dataplane/standalone/pkthandler/pktiohandler/BUILD +++ b/dataplane/standalone/pkthandler/pktiohandler/BUILD @@ -12,6 +12,7 @@ go_library( "@com_github_golang_glog//:glog", "@org_golang_google_genproto_googleapis_rpc//status", "@org_golang_google_grpc//codes", + "@org_golang_google_protobuf//encoding/protojson", ], ) diff --git a/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go b/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go index 5d372320..66919f6c 100644 --- a/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go +++ b/dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go @@ -135,7 +135,7 @@ func (m *PacketIOMgr) writePorts() error { if err != nil { return err } - return os.WriteFile(m.portFile, contents, 0666) + return os.WriteFile(m.portFile, contents, 0666) //nolint:gosec } // ManagePorts handles HostPortControl message from a forwarding server. From f4fd0ab65ea3b21202f3a06c5a99ecbe7917e7e3 Mon Sep 17 00:00:00 2001 From: Daniel Grau Date: Fri, 29 Mar 2024 21:52:55 +0000 Subject: [PATCH 4/4] feedback --- dataplane/saiserver/hostif.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dataplane/saiserver/hostif.go b/dataplane/saiserver/hostif.go index 6133bc9e..d84daae8 100644 --- a/dataplane/saiserver/hostif.go +++ b/dataplane/saiserver/hostif.go @@ -72,6 +72,7 @@ func (hostif *hostif) Reset() { for _, closeFn := range hostif.remoteClosers { closeFn() } + hostif.remoteClosers = nil } const switchID = 1 @@ -249,8 +250,6 @@ func (hostif *hostif) CreateHostif(ctx context.Context, req *saipb.CreateHostifR func (hostif *hostif) createRemoteHostif(ctx context.Context, req *saipb.CreateHostifRequest) (*saipb.CreateHostifResponse, error) { id := hostif.mgr.NextID() - hostif.remoteMu.Lock() - defer hostif.remoteMu.Unlock() ctlReq := &pktiopb.HostPortControlMessage{ Create: true, @@ -310,6 +309,9 @@ func (hostif *hostif) createRemoteHostif(ctx context.Context, req *saipb.CreateH return nil, status.Errorf(codes.InvalidArgument, "unknown type %v", req.GetType()) } + hostif.remoteMu.Lock() + defer hostif.remoteMu.Unlock() + if hostif.remotePortReq == nil { return nil, status.Error(codes.FailedPrecondition, "remote port control not configured") }