mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 20:15:23 +00:00
Strict checking of Yggdrasil source/destination addresses
This commit is contained in:
parent
2a629880fd
commit
2b6462c8a9
@ -1,6 +1,7 @@
|
|||||||
package tuntap
|
package tuntap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -70,6 +71,17 @@ func (s *tunConn) reader() (err error) {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
} else if len(bs) > 0 {
|
} else if len(bs) > 0 {
|
||||||
|
if bs[0]&0xf0 == 0x60 {
|
||||||
|
switch {
|
||||||
|
case bs[8] == 0x02 && !bytes.Equal(s.addr[:16], bs[8:24]): // source
|
||||||
|
case bs[8] == 0x03 && !bytes.Equal(s.snet[:8], bs[8:16]): // source
|
||||||
|
case bs[24] == 0x02 && !bytes.Equal(s.tun.addr[:16], bs[24:40]): // destination
|
||||||
|
case bs[24] == 0x03 && !bytes.Equal(s.tun.subnet[:8], bs[24:32]): // destination
|
||||||
|
util.PutBytes(bs)
|
||||||
|
continue
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
s.tun.send <- bs
|
s.tun.send <- bs
|
||||||
s.stillAlive()
|
s.stillAlive()
|
||||||
} else {
|
} else {
|
||||||
@ -96,6 +108,16 @@ func (s *tunConn) writer() error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("send closed")
|
return errors.New("send closed")
|
||||||
}
|
}
|
||||||
|
if bs[0]&0xf0 == 0x60 {
|
||||||
|
switch {
|
||||||
|
case bs[8] == 0x02 && !bytes.Equal(s.tun.addr[:16], bs[8:24]): // source
|
||||||
|
case bs[8] == 0x03 && !bytes.Equal(s.tun.subnet[:8], bs[8:16]): // source
|
||||||
|
case bs[24] == 0x02 && !bytes.Equal(s.addr[:16], bs[24:40]): // destination
|
||||||
|
case bs[24] == 0x03 && !bytes.Equal(s.snet[:8], bs[24:32]): // destination
|
||||||
|
continue
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
msg := yggdrasil.FlowKeyMessage{
|
msg := yggdrasil.FlowKeyMessage{
|
||||||
FlowKey: util.GetFlowKey(bs),
|
FlowKey: util.GetFlowKey(bs),
|
||||||
Message: bs,
|
Message: bs,
|
||||||
|
Loading…
Reference in New Issue
Block a user