diff --git a/pfcpiface/bess.go b/pfcpiface/bess.go index c66206b58..d6ddeadb4 100644 --- a/pfcpiface/bess.go +++ b/pfcpiface/bess.go @@ -11,6 +11,8 @@ import ( "strconv" "time" + "google.golang.org/grpc/credentials/insecure" + pb "github.com/omec-project/upf-epc/pfcpiface/bess_pb" "github.com/prometheus/client_golang/prometheus" log "github.com/sirupsen/logrus" @@ -529,7 +531,7 @@ func (b *bess) setUpfInfo(u *upf, conf *Conf) { b.endMarkerChan = make(chan []byte, 1024) - b.conn, err = grpc.Dial(*bessIP, grpc.WithInsecure()) + b.conn, err = grpc.Dial(*bessIP, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { log.Fatalln("did not connect:", err) } diff --git a/pfcpiface/conn.go b/pfcpiface/conn.go index c6c152612..dc08f450d 100644 --- a/pfcpiface/conn.go +++ b/pfcpiface/conn.go @@ -113,14 +113,14 @@ func (node *PFCPNode) NewPFCPConn(lAddr, rAddr string, buf []byte) *PFCPConn { } // TODO: Get SEID range from PFCPNode for this PFCPConn - log.Infoln("Created PFCPConn from:", conn.LocalAddr(), "to:", conn.RemoteAddr()) + rng := rand.New(rand.NewSource(time.Now().UnixNano())) // #nosec G404 p := &PFCPConn{ ctx: node.ctx, Conn: conn, ts: ts, - rng: rand.New(rand.NewSource(time.Now().UnixNano())), + rng: rng, maxRetries: 100, sessions: make(map[uint64]*PFCPSession), upf: node.upf, diff --git a/pfcpiface/messages-conn.go b/pfcpiface/messages-conn.go index 0b7a20d86..b6a9ef102 100644 --- a/pfcpiface/messages-conn.go +++ b/pfcpiface/messages-conn.go @@ -86,23 +86,6 @@ func (pConn *PFCPConn) associationIEs() []*ie.IE { return ies } -func (pConn *PFCPConn) sendAssociationRequest() error { - upf := pConn.upf - - if !upf.isConnected() { - return errFastpathDown - } - - // Build request message - asreq := message.NewAssociationSetupRequest(pConn.getSeqNum(), - pConn.associationIEs()..., - ) - - pConn.SendPFCPMsg(asreq) - - return nil -} - func (pConn *PFCPConn) handleAssociationSetupRequest(msg message.Message) (message.Message, error) { addr := pConn.RemoteAddr().String() upf := pConn.upf @@ -151,33 +134,33 @@ func (pConn *PFCPConn) handleAssociationSetupRequest(msg message.Message) (messa return asres, nil } -func (pConn *PFCPConn) handleAssociationSetupResponse(msg message.Message) (message.Message, error) { +func (pConn *PFCPConn) handleAssociationSetupResponse(msg message.Message) error { addr := pConn.RemoteAddr().String() asres, ok := msg.(*message.AssociationSetupResponse) if !ok { - return nil, errUnmarshal(errMsgUnexpectedType) + return errUnmarshal(errMsgUnexpectedType) } cause, err := asres.Cause.Cause() if err != nil { - return nil, errUnmarshal(err) + return errUnmarshal(err) } if cause != ie.CauseRequestAccepted { log.Errorln("Association Setup Response from", addr, "with Cause:", cause) - return nil, errReqRejected + return errReqRejected } nodeID, err := asres.NodeID.NodeID() if err != nil { - return nil, errUnmarshal(err) + return errUnmarshal(err) } ts, err := asres.RecoveryTimeStamp.RecoveryTimeStamp() if err != nil { - return nil, errUnmarshal(err) + return errUnmarshal(err) } if pConn.ts.remote.IsZero() { @@ -195,7 +178,7 @@ func (pConn *PFCPConn) handleAssociationSetupResponse(msg message.Message) (mess log.Infoln("Association setup done between nodes", "local:", pConn.nodeID.local, "remote:", pConn.nodeID.remote) - return nil, nil + return nil } func (pConn *PFCPConn) handleAssociationReleaseRequest(msg message.Message) (message.Message, error) { diff --git a/pfcpiface/messages-session.go b/pfcpiface/messages-session.go index 9a88a1dad..720a2737b 100644 --- a/pfcpiface/messages-session.go +++ b/pfcpiface/messages-session.go @@ -497,17 +497,17 @@ func (pConn *PFCPConn) handleDigestReport(fseid uint64) { pConn.SendPFCPMsg(srreq) } -func (pConn *PFCPConn) handleSessionReportResponse(msg message.Message) (message.Message, error) { +func (pConn *PFCPConn) handleSessionReportResponse(msg message.Message) error { upf := pConn.upf srres, ok := msg.(*message.SessionReportResponse) if !ok { - return nil, errUnmarshal(errMsgUnexpectedType) + return errUnmarshal(errMsgUnexpectedType) } cause := srres.Cause.Payload[0] if cause == ie.CauseRequestAccepted { - return nil, nil + return nil } log.Warnln("session req not accepted seq : ", srres.SequenceNumber) @@ -517,7 +517,7 @@ func (pConn *PFCPConn) handleSessionReportResponse(msg message.Message) (message if cause == ie.CauseSessionContextNotFound { sessItem, ok := pConn.sessions[seid] if !ok { - return nil, errProcess(ErrNotFoundWithParam("PFCP session context", "SEID", seid)) + return errProcess(ErrNotFoundWithParam("PFCP session context", "SEID", seid)) } log.Warnln("context not found, deleting session locally") @@ -527,12 +527,12 @@ func (pConn *PFCPConn) handleSessionReportResponse(msg message.Message) (message cause := upf.sendMsgToUPF( upfMsgTypeDel, sessItem.pdrs, sessItem.fars, sessItem.qers) if cause == ie.CauseRequestRejected { - return nil, errProcess( + return errProcess( ErrOperationFailedWithParam("delete session from fastpath", "seid", seid)) } - return nil, nil + return nil } - return nil, nil + return nil } diff --git a/pfcpiface/messages.go b/pfcpiface/messages.go index cc27c7cbe..4f1309fe3 100644 --- a/pfcpiface/messages.go +++ b/pfcpiface/messages.go @@ -84,7 +84,7 @@ func (pConn *PFCPConn) HandlePFCPMsg(buf []byte) { } // TODO: Cleanup sessions case message.MsgTypeAssociationSetupResponse: - reply, err = pConn.handleAssociationSetupResponse(msg) + err = pConn.handleAssociationSetupResponse(msg) // TODO: Cleanup sessions // TODO: start heartbeats case message.MsgTypeAssociationReleaseRequest: @@ -99,7 +99,7 @@ func (pConn *PFCPConn) HandlePFCPMsg(buf []byte) { case message.MsgTypeSessionDeletionRequest: reply, err = pConn.handleSessionDeletionRequest(msg) case message.MsgTypeSessionReportResponse: - _, err = pConn.handleSessionReportResponse(msg) + err = pConn.handleSessionReportResponse(msg) // Incoming response messages // TODO: Association Setup Request, Session Report Request diff --git a/pfcpiface/p4rt.go b/pfcpiface/p4rt.go index bce6b739b..73e56453d 100644 --- a/pfcpiface/p4rt.go +++ b/pfcpiface/p4rt.go @@ -5,6 +5,7 @@ package main import ( "flag" + // #nosec G404 // Ignore G404. We don't need strong random number generator for allocating IDs for P4 objects. "math/rand" "net" "time" @@ -147,7 +148,7 @@ func getCounterVal(p *p4rtc, counterID uint8) (uint64, error) { for i := 0; i < int(ctr.maxSize); i++ { rand.Seed(time.Now().UnixNano()) - val = uint64(rand.Intn(int(ctr.maxSize)-1) + 1) + val = uint64(rand.Intn(int(ctr.maxSize)-1) + 1) // #nosec G404 if _, ok := ctr.allocated[val]; !ok { log.Println("key not in allocated map ", val) diff --git a/pfcpiface/p4rtc.go b/pfcpiface/p4rtc.go index f163c8d2e..4042ed27f 100644 --- a/pfcpiface/p4rtc.go +++ b/pfcpiface/p4rtc.go @@ -12,6 +12,11 @@ import ( "os" "time" + "google.golang.org/grpc/credentials/insecure" + + //nolint:staticcheck // Ignore SA1019. + // Upgrading to google.golang.org/protobuf/proto is not a drop-in replacement, + // as also P4Runtime stubs are based on the deprecated proto. "github.com/golang/protobuf/proto" grpcRetry "github.com/grpc-ecosystem/go-grpc-middleware/retry" p4ConfigV1 "github.com/p4lang/p4runtime/go/p4/config/v1" @@ -1125,7 +1130,7 @@ func GetConnection(host string) (conn *grpc.ClientConn, err error) { /* get connection */ log.Println("Get connection.") - conn, err = grpc.Dial(host, grpc.WithInsecure()) + conn, err = grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { log.Println("grpc dial err: ", err) return nil, err