Get out faster on nil udpAddr (#449)

This commit is contained in:
Nathan Brown 2021-04-26 20:21:47 -05:00 committed by GitHub
parent 6f37280e8e
commit df7c7eec4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -340,7 +340,7 @@ func (f *Interface) handleRecvError(addr *udpAddr, h *Header) {
if !hostinfo.RecvErrorExceeded() {
return
}
if hostinfo.remote != nil && hostinfo.remote.String() != addr.String() {
if hostinfo.remote != nil && hostinfo.remote.Equals(addr) {
f.l.Infoln("Someone spoofing recv_errors? ", addr, hostinfo.remote)
return
}

View File

@ -99,6 +99,10 @@ func (r *RemoteList) ForEach(preferredRanges []*net.IPNet, forEach forEachFunc)
// CopyAddrs locks and makes a deep copy of the deduplicated address list
// The deduplication work may need to occur here, so you must pass preferredRanges
func (r *RemoteList) CopyAddrs(preferredRanges []*net.IPNet) []*udpAddr {
if r == nil {
return nil
}
r.Rebuild(preferredRanges)
r.RLock()

View File

@ -33,14 +33,26 @@ func (ua *udpAddr) Equals(t *udpAddr) bool {
}
func (ua *udpAddr) String() string {
if ua == nil {
return "<nil>"
}
return net.JoinHostPort(ua.IP.String(), fmt.Sprintf("%v", ua.Port))
}
func (ua *udpAddr) MarshalJSON() ([]byte, error) {
if ua == nil {
return nil, nil
}
return json.Marshal(m{"ip": ua.IP, "port": ua.Port})
}
func (ua *udpAddr) Copy() *udpAddr {
if ua == nil {
return nil
}
nu := udpAddr{
Port: ua.Port,
IP: make(net.IP, len(ua.IP)),