mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-14 10:50:45 +01:00
bind
This commit is contained in:
parent
2ae4c204af
commit
9350c5f8d8
@ -216,16 +216,18 @@ func (s *sharedUDPConn) ReadFrom(buff []byte) (n int, addr net.Addr, err error)
|
|||||||
if n, addr, err = s.PacketConn.ReadFrom(buff); err == nil {
|
if n, addr, err = s.PacketConn.ReadFrom(buff); err == nil {
|
||||||
bytes := make([]byte, n)
|
bytes := make([]byte, n)
|
||||||
copy(bytes, buff)
|
copy(bytes, buff)
|
||||||
if !stun.IsMessage(bytes[:n]) {
|
if !stun.IsMessage(bytes) {
|
||||||
e, err := netip.ParseAddrPort(addr.String())
|
e, err := netip.ParseAddrPort(addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
s.bind.OnData(bytes, &net.UDPAddr{
|
a := &net.UDPAddr{
|
||||||
IP: e.Addr().AsSlice(),
|
IP: e.Addr().AsSlice(),
|
||||||
Port: int(e.Port()),
|
Port: int(e.Port()),
|
||||||
Zone: e.Addr().Zone(),
|
Zone: e.Addr().Zone(),
|
||||||
})
|
}
|
||||||
|
s.bind.OnData(bytes, a)
|
||||||
|
return 0, a, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,17 +257,17 @@ func (e *Engine) Start() error {
|
|||||||
log.Errorf("failed listening on UDP port %d: [%s]", e.config.UDPMuxPort, err.Error())
|
log.Errorf("failed listening on UDP port %d: [%s]", e.config.UDPMuxPort, err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
s := &sharedUDPConn{PacketConn: e.udpMuxConn}
|
||||||
|
bind := iface.NewUserBind(s)
|
||||||
|
s.bind = bind
|
||||||
e.udpMuxConnSrflx, err = net.ListenUDP("udp4", &net.UDPAddr{Port: e.config.UDPMuxSrflxPort})
|
e.udpMuxConnSrflx, err = net.ListenUDP("udp4", &net.UDPAddr{Port: e.config.UDPMuxSrflxPort})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed listening on UDP port %d: [%s]", e.config.UDPMuxSrflxPort, err.Error())
|
log.Errorf("failed listening on UDP port %d: [%s]", e.config.UDPMuxSrflxPort, err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
e.udpMux = ice.NewUDPMuxDefault(ice.UDPMuxParams{UDPConn: e.udpMuxConn})
|
e.udpMux = ice.NewUDPMuxDefault(ice.UDPMuxParams{UDPConn: s})
|
||||||
s := &sharedUDPConn{PacketConn: e.udpMuxConnSrflx}
|
|
||||||
bind := iface.NewUserBind(s)
|
e.udpMuxSrflx = ice.NewUniversalUDPMuxDefault(ice.UniversalUDPMuxParams{UDPConn: e.udpMuxConnSrflx})
|
||||||
s.bind = bind
|
|
||||||
e.udpMuxSrflx = ice.NewUniversalUDPMuxDefault(ice.UniversalUDPMuxParams{UDPConn: s})
|
|
||||||
err = e.wgInterface.CreateNew(bind)
|
err = e.wgInterface.CreateNew(bind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed creating tunnel interface %s: [%s]", wgIfaceName, err.Error())
|
log.Errorf("failed creating tunnel interface %s: [%s]", wgIfaceName, err.Error())
|
||||||
|
@ -146,8 +146,8 @@ func (conn *Conn) reCreateAgent() error {
|
|||||||
conn.agent, err = ice.NewAgent(&ice.AgentConfig{
|
conn.agent, err = ice.NewAgent(&ice.AgentConfig{
|
||||||
MulticastDNSMode: ice.MulticastDNSModeDisabled,
|
MulticastDNSMode: ice.MulticastDNSModeDisabled,
|
||||||
NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4},
|
NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4},
|
||||||
Urls: conn.config.StunTurn,
|
//Urls: conn.config.StunTurn,
|
||||||
CandidateTypes: []ice.CandidateType{ice.CandidateTypeServerReflexive},
|
CandidateTypes: []ice.CandidateType{ice.CandidateTypeHost},
|
||||||
FailedTimeout: &failedTimeout,
|
FailedTimeout: &failedTimeout,
|
||||||
InterfaceFilter: interfaceFilter(conn.config.InterfaceBlackList),
|
InterfaceFilter: interfaceFilter(conn.config.InterfaceBlackList),
|
||||||
UDPMux: conn.config.UDPMux,
|
UDPMux: conn.config.UDPMux,
|
||||||
|
Loading…
Reference in New Issue
Block a user