Browse Source

Get out faster on nil udpAddr (#449)

Nathan Brown 4 years ago
parent
commit
df7c7eec4a
3 changed files with 17 additions and 1 deletions
  1. 1 1
      outside.go
  2. 4 0
      remote_list.go
  3. 12 0
      udp_all.go

+ 1 - 1
outside.go

@@ -340,7 +340,7 @@ func (f *Interface) handleRecvError(addr *udpAddr, h *Header) {
 	if !hostinfo.RecvErrorExceeded() {
 	if !hostinfo.RecvErrorExceeded() {
 		return
 		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)
 		f.l.Infoln("Someone spoofing recv_errors? ", addr, hostinfo.remote)
 		return
 		return
 	}
 	}

+ 4 - 0
remote_list.go

@@ -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
 // 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
 // The deduplication work may need to occur here, so you must pass preferredRanges
 func (r *RemoteList) CopyAddrs(preferredRanges []*net.IPNet) []*udpAddr {
 func (r *RemoteList) CopyAddrs(preferredRanges []*net.IPNet) []*udpAddr {
+	if r == nil {
+		return nil
+	}
+
 	r.Rebuild(preferredRanges)
 	r.Rebuild(preferredRanges)
 
 
 	r.RLock()
 	r.RLock()

+ 12 - 0
udp_all.go

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