mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-03 02:35:08 +03:00 
			
		
		
		
	check that the source IP inside a packet matches the address or prefix for the session that transmitted it
This commit is contained in:
		
							parent
							
								
									f929df1ea9
								
							
						
					
					
						commit
						502ab3cfaa
					
				
					 2 changed files with 9 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -149,21 +149,22 @@ func (r *router) sendPacket(bs []byte) {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *router) recvPacket(bs []byte, theirAddr *address) {
 | 
			
		||||
	// TODO pass their NodeID, check *that* instead
 | 
			
		||||
	//  Or store their address in the session?...
 | 
			
		||||
func (r *router) recvPacket(bs []byte, theirAddr *address, theirSubnet *subnet) {
 | 
			
		||||
  // TODO? move this into the session?
 | 
			
		||||
	//fmt.Println("Recv packet")
 | 
			
		||||
	if theirAddr == nil {
 | 
			
		||||
		panic("Should not happen ever")
 | 
			
		||||
	}
 | 
			
		||||
	if len(bs) < 24 {
 | 
			
		||||
		util_putBytes(bs)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	var source address
 | 
			
		||||
	copy(source[:], bs[8:])
 | 
			
		||||
	var snet subnet
 | 
			
		||||
	copy(snet[:], bs[8:])
 | 
			
		||||
	if !source.isValid() && !snet.isValid() {
 | 
			
		||||
	switch {
 | 
			
		||||
	case source.isValid() && source == *theirAddr:
 | 
			
		||||
	case snet.isValid() && snet == *theirSubnet:
 | 
			
		||||
	default:
 | 
			
		||||
		util_putBytes(bs)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	//go func() { r.recv<-bs }()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -373,5 +373,5 @@ func (sinfo *sessionInfo) doRecv(p *wire_trafficPacket) {
 | 
			
		|||
	}
 | 
			
		||||
	sinfo.updateNonce(&p.nonce)
 | 
			
		||||
	sinfo.time = time.Now()
 | 
			
		||||
	sinfo.core.router.recvPacket(bs, &sinfo.theirAddr)
 | 
			
		||||
	sinfo.core.router.recvPacket(bs, &sinfo.theirAddr, &sinfo.theirSubnet)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue