Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common/control/bind_finder_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package control
import (
"net"
"net/netip"
"sync"

E "github.com/sagernet/sing/common/exceptions"
)
Expand All @@ -11,6 +12,7 @@ var _ InterfaceFinder = (*DefaultInterfaceFinder)(nil)

type DefaultInterfaceFinder struct {
interfaces []Interface
access sync.RWMutex
}

func NewDefaultInterfaceFinder() *DefaultInterfaceFinder {
Expand All @@ -31,7 +33,9 @@ func (f *DefaultInterfaceFinder) Update() error {
}
interfaces = append(interfaces, iif)
}
f.access.Lock()
f.interfaces = interfaces
f.access.Unlock()
return nil
}

Expand Down Expand Up @@ -61,11 +65,14 @@ func (f *DefaultInterfaceFinder) ByName(name string) (*Interface, error) {
}

func (f *DefaultInterfaceFinder) ByIndex(index int) (*Interface, error) {
f.access.RLock()
for _, netInterface := range f.interfaces {
if netInterface.Index == index {
return &netInterface, nil
}
}
f.access.RUnlock()

_, err := net.InterfaceByIndex(index)
if err == nil {
err = f.Update()
Expand Down
3 changes: 3 additions & 0 deletions common/udpnat2/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func (c *natConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error
}

func (c *natConn) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool) {
c.handlerAccess.Lock()
defer c.handlerAccess.Unlock()

c.readWaitOptions = options
return false
}
Expand Down
2 changes: 1 addition & 1 deletion common/udpnat2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func (s *Service) NewPacket(bufferSlices [][]byte, source M.Socksaddr, destinati
if !ok {
return
}
conn.handlerAccess.RLock()
buffer := conn.readWaitOptions.NewPacketBuffer()
for _, bufferSlice := range bufferSlices {
buffer.Write(bufferSlice)
}
conn.handlerAccess.RLock()
handler := conn.handler
conn.handlerAccess.RUnlock()
if handler != nil {
Expand Down