Skip to content

Commit

Permalink
Fix error use of WriteTo with pre-connected connection
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Dec 10, 2024
1 parent bb992be commit 788cba7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pfcp/api/entity_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
package api

import (
"net/netip"

"github.com/wmnsk/go-pfcp/ie"
)

type PFCPEntityInterface interface {
ListenAddr() netip.Addr
IsUserPlane() bool
IsControlPlane() bool
NodeID() *ie.IE
Expand Down
4 changes: 4 additions & 0 deletions pfcp/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func (e *PFCPEntity) closePfcpConn() error {
return nil
}

func (e *PFCPEntity) ListenAddr() netip.Addr {
return e.listenAddr
}

func (e *PFCPEntity) Options() api.EntityOptionsInterface {
return e.options
}
Expand Down
8 changes: 6 additions & 2 deletions pfcp/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func newPFCPPeer(srv api.PFCPEntityInterface, nodeID *ie.IE, kind string) (peer

raddr := net.UDPAddrFromAddrPort(netip.AddrPortFrom(ips[0], pfcputil.PFCP_PORT))

conn, err := net.DialUDP("udp", nil, raddr)
conn, err := net.ListenUDP("udp", net.UDPAddrFromAddrPort(netip.AddrPortFrom(srv.ListenAddr(), 0)))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -112,11 +112,15 @@ func (peer *PFCPPeer) startLoop() {

func (peer *PFCPPeer) loopUnwrapped() {
b := make([]byte, pfcputil.DEFAULT_MTU) // TODO: detect MTU for interface instead of using DEFAULT_MTU
n, _, err := peer.conn.ReadFromUDP(b)
n, addr, err := peer.conn.ReadFromUDP(b)
if err != nil {
// socket has been closed
return
}
if addr.String() != peer.udpAddr.String() {
// peer usurpated
return
}
// Processing of message in a new thread to avoid blocking
go func(msgArray []byte, size int, e *PFCPPeer) {
msg, err := message.ParseHeader(msgArray[:size])
Expand Down

0 comments on commit 788cba7

Please sign in to comment.