mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	Check CKR routes when receiving packets in router
This commit is contained in:
		
							parent
							
								
									87b0f5fe24
								
							
						
					
					
						commit
						c7f2427de1
					
				
					 2 changed files with 9 additions and 6 deletions
				
			
		| 
						 | 
					@ -253,7 +253,7 @@ func (r *router) sendPacket(bs []byte) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Called for incoming traffic by the session worker for that connection.
 | 
					// Called for incoming traffic by the session worker for that connection.
 | 
				
			||||||
// Checks that the IP address is correct (matches the session) and passes the packet to the tun/tap.
 | 
					// Checks that the IP address is correct (matches the session) and passes the packet to the tun/tap.
 | 
				
			||||||
func (r *router) recvPacket(bs []byte, theirAddr *address, theirSubnet *subnet) {
 | 
					func (r *router) recvPacket(bs []byte, sinfo *sessionInfo) {
 | 
				
			||||||
	// Note: called directly by the session worker, not the router goroutine
 | 
						// Note: called directly by the session worker, not the router goroutine
 | 
				
			||||||
	if len(bs) < 24 {
 | 
						if len(bs) < 24 {
 | 
				
			||||||
		util_putBytes(bs)
 | 
							util_putBytes(bs)
 | 
				
			||||||
| 
						 | 
					@ -264,12 +264,15 @@ func (r *router) recvPacket(bs []byte, theirAddr *address, theirSubnet *subnet)
 | 
				
			||||||
	var snet subnet
 | 
						var snet subnet
 | 
				
			||||||
	copy(snet[:], bs[8:])
 | 
						copy(snet[:], bs[8:])
 | 
				
			||||||
	switch {
 | 
						switch {
 | 
				
			||||||
	case source.isValid() && source == *theirAddr:
 | 
						case source.isValid() && source == sinfo.theirAddr:
 | 
				
			||||||
	case snet.isValid() && snet == *theirSubnet:
 | 
						case snet.isValid() && snet == sinfo.theirSubnet:
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
 | 
							key, err := r.cryptokey.getPublicKeyForAddress(source)
 | 
				
			||||||
 | 
							if err != nil || key != sinfo.theirPermPub {
 | 
				
			||||||
			util_putBytes(bs)
 | 
								util_putBytes(bs)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	//go func() { r.recv<-bs }()
 | 
						//go func() { r.recv<-bs }()
 | 
				
			||||||
	r.recv <- bs
 | 
						r.recv <- bs
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -589,5 +589,5 @@ func (sinfo *sessionInfo) doRecv(p *wire_trafficPacket) {
 | 
				
			||||||
	sinfo.updateNonce(&p.Nonce)
 | 
						sinfo.updateNonce(&p.Nonce)
 | 
				
			||||||
	sinfo.time = time.Now()
 | 
						sinfo.time = time.Now()
 | 
				
			||||||
	sinfo.bytesRecvd += uint64(len(bs))
 | 
						sinfo.bytesRecvd += uint64(len(bs))
 | 
				
			||||||
	sinfo.core.router.recvPacket(bs, &sinfo.theirAddr, &sinfo.theirSubnet)
 | 
						sinfo.core.router.recvPacket(bs, sinfo)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue