5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-09-20 03:42:32 +00:00

Check CKR routes when receiving packets in router

This commit is contained in:
Neil Alexander 2018-11-05 22:58:58 +00:00
parent 87b0f5fe24
commit c7f2427de1
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
2 changed files with 9 additions and 6 deletions

View File

@ -253,7 +253,7 @@ func (r *router) sendPacket(bs []byte) {
// 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.
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
if len(bs) < 24 {
util_putBytes(bs)
@ -264,11 +264,14 @@ func (r *router) recvPacket(bs []byte, theirAddr *address, theirSubnet *subnet)
var snet subnet
copy(snet[:], bs[8:])
switch {
case source.isValid() && source == *theirAddr:
case snet.isValid() && snet == *theirSubnet:
case source.isValid() && source == sinfo.theirAddr:
case snet.isValid() && snet == sinfo.theirSubnet:
default:
util_putBytes(bs)
return
key, err := r.cryptokey.getPublicKeyForAddress(source)
if err != nil || key != sinfo.theirPermPub {
util_putBytes(bs)
return
}
}
//go func() { r.recv<-bs }()
r.recv <- bs

View File

@ -589,5 +589,5 @@ func (sinfo *sessionInfo) doRecv(p *wire_trafficPacket) {
sinfo.updateNonce(&p.Nonce)
sinfo.time = time.Now()
sinfo.bytesRecvd += uint64(len(bs))
sinfo.core.router.recvPacket(bs, &sinfo.theirAddr, &sinfo.theirSubnet)
sinfo.core.router.recvPacket(bs, sinfo)
}