5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-25 07:11:36 +00:00

(broken state) WIP, compiles and passes the netns ping test

This commit is contained in:
Arceliar 2021-05-08 11:52:22 -05:00
parent b345806e3f
commit 8bed79370b
5 changed files with 32 additions and 28 deletions

View File

@ -281,7 +281,7 @@ func main() {
panic(err) panic(err)
} }
// Register the session firewall gatekeeper function // Register the session firewall gatekeeper function
n.core.SetSessionGatekeeper(n.sessionFirewall) // TODO n.core.SetSessionGatekeeper(n.sessionFirewall)
// Allocate our modules // Allocate our modules
n.admin = &admin.AdminSocket{} n.admin = &admin.AdminSocket{}
n.multicast = &multicast.Multicast{} n.multicast = &multicast.Multicast{}
@ -299,19 +299,26 @@ func main() {
} }
n.multicast.SetupAdminHandlers(n.admin.(*admin.AdminSocket)) n.multicast.SetupAdminHandlers(n.admin.(*admin.AdminSocket))
// Start the TUN/TAP interface // Start the TUN/TAP interface
if listener, err := n.core.ConnListen(); err == nil { n.tuntap.Init(&n.core, n.state, logger, tuntap.TunOptions{})
if dialer, err := n.core.ConnDialer(); err == nil { if err := n.tuntap.Start(); err != nil {
n.tuntap.Init(&n.core, n.state, logger, tuntap.TunOptions{Listener: listener, Dialer: dialer}) logger.Errorln("An error occurred starting TUN/TAP:", err)
if err := n.tuntap.Start(); err != nil {
logger.Errorln("An error occurred starting TUN/TAP:", err)
}
n.tuntap.SetupAdminHandlers(n.admin.(*admin.AdminSocket))
} else {
logger.Errorln("Unable to get Dialer:", err)
}
} else {
logger.Errorln("Unable to get Listener:", err)
} }
n.tuntap.SetupAdminHandlers(n.admin.(*admin.AdminSocket))
/*
if listener, err := n.core.ConnListen(); err == nil {
if dialer, err := n.core.ConnDialer(); err == nil {
n.tuntap.Init(&n.core, n.state, logger, tuntap.TunOptions{Listener: listener, Dialer: dialer})
if err := n.tuntap.Start(); err != nil {
logger.Errorln("An error occurred starting TUN/TAP:", err)
}
n.tuntap.SetupAdminHandlers(n.admin.(*admin.AdminSocket))
} else {
logger.Errorln("Unable to get Dialer:", err)
}
} else {
logger.Errorln("Unable to get Listener:", err)
}
*/
// Make some nice output that tells us what our IPv6 address and subnet are. // Make some nice output that tells us what our IPv6 address and subnet are.
// This is just logged to stdout for the user. // This is just logged to stdout for the user.
address := n.core.Address() address := n.core.Address()
@ -396,12 +403,14 @@ func (n *node) sessionFirewall(pubkey *crypto.BoxPubKey, initiator bool) bool {
// Look and see if the pubkey is that of a direct peer // Look and see if the pubkey is that of a direct peer
var isDirectPeer bool var isDirectPeer bool
/* TODO
for _, peer := range n.core.GetPeers() { for _, peer := range n.core.GetPeers() {
if peer.PublicKey == *pubkey { if peer.PublicKey == *pubkey {
isDirectPeer = true isDirectPeer = true
break break
} }
} }
*/
// Allow direct peers if appropriate // Allow direct peers if appropriate
if n.state.Current.SessionFirewall.AllowFromDirect && isDirectPeer { if n.state.Current.SessionFirewall.AllowFromDirect && isDirectPeer {

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/yggdrasil-network/yggdrasil-go
go 1.16 go 1.16
require ( require (
github.com/Arceliar/ironwood v0.0.0-20210508094446-74a68e4f5970 // indirect github.com/Arceliar/ironwood v0.0.0-00010101000000-000000000000
github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979 github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979
github.com/cheggaaa/pb/v3 v3.0.6 github.com/cheggaaa/pb/v3 v3.0.6
github.com/fatih/color v1.10.0 // indirect github.com/fatih/color v1.10.0 // indirect

3
go.sum
View File

@ -1,5 +1,3 @@
github.com/Arceliar/ironwood v0.0.0-20210508094446-74a68e4f5970 h1:sKiz18LynwInybi9BIhM8tdvZlSurnT6rM/ZUEqMgzU=
github.com/Arceliar/ironwood v0.0.0-20210508094446-74a68e4f5970/go.mod h1:RP72rucOFm5udrnEzTmIWLRVGQiV/fSUAQXJ0RST/nk=
github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979 h1:WndgpSW13S32VLQ3ugUxx2EnnWmgba1kCqPkd4Gk1yQ= github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979 h1:WndgpSW13S32VLQ3ugUxx2EnnWmgba1kCqPkd4Gk1yQ=
github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979/go.mod h1:6Lkn+/zJilRMsKmbmG1RPoamiArC6HS73xbwRyp3UyI= github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979/go.mod h1:6Lkn+/zJilRMsKmbmG1RPoamiArC6HS73xbwRyp3UyI=
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM= github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
@ -39,7 +37,6 @@ github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA= github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA=
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=

View File

@ -70,7 +70,7 @@ func (k *keyStore) sendToAddress(addr address.Address, bs []byte) {
delete(k.addrBuffer, addr) delete(k.addrBuffer, addr)
} }
}) })
panic("TODO") // TODO send lookup k.tun.sendKeyLookup(addr.GetKey())
} }
} }
@ -98,7 +98,7 @@ func (k *keyStore) sendToSubnet(subnet address.Subnet, bs []byte) {
delete(k.subnetBuffer, subnet) delete(k.subnetBuffer, subnet)
} }
}) })
panic("TODO") // TODO send lookup k.tun.sendKeyLookup(subnet.GetKey())
} }
} }

View File

@ -39,7 +39,6 @@ const tun_IPv6_HEADER_LENGTH = 40
// calling yggdrasil.Start(). // calling yggdrasil.Start().
type TunAdapter struct { type TunAdapter struct {
core *yggdrasil.Core core *yggdrasil.Core
secret ed25519.PrivateKey
store keyStore store keyStore
config *config.NodeState config *config.NodeState
log *log.Logger log *log.Logger
@ -108,14 +107,13 @@ func MaximumMTU() MTU {
// Init initialises the TUN module. You must have acquired a Listener from // Init initialises the TUN module. You must have acquired a Listener from
// the Yggdrasil core before this point and it must not be in use elsewhere. // the Yggdrasil core before this point and it must not be in use elsewhere.
func (tun *TunAdapter) Init(secret ed25519.PrivateKey, core *yggdrasil.Core, config *config.NodeState, log *log.Logger, options interface{}) error { func (tun *TunAdapter) Init(core *yggdrasil.Core, config *config.NodeState, log *log.Logger, options interface{}) error {
/* TODO /* TODO
tunoptions, ok := options.(TunOptions) tunoptions, ok := options.(TunOptions)
if !ok { if !ok {
return fmt.Errorf("invalid options supplied to TunAdapter module") return fmt.Errorf("invalid options supplied to TunAdapter module")
} }
*/ */
tun.secret = secret
tun.core = core tun.core = core
tun.store.init(tun) tun.store.init(tun)
tun.config = config tun.config = config
@ -149,10 +147,10 @@ func (tun *TunAdapter) _start() error {
return err return err
} }
copy(boxPub[:], boxPubHex) copy(boxPub[:], boxPubHex)
panic("TODO") sk := tun.core.PrivateKey()
//nodeID := crypto.GetNodeID(&boxPub) pk := sk.Public().(ed25519.PublicKey)
//tun.addr = *address.AddrForNodeID(nodeID) tun.addr = *address.AddrForKey(pk)
//tun.subnet = *address.SubnetForNodeID(nodeID) tun.subnet = *address.SubnetForKey(pk)
addr := fmt.Sprintf("%s/%d", net.IP(tun.addr[:]).String(), 8*len(address.GetPrefix())-1) addr := fmt.Sprintf("%s/%d", net.IP(tun.addr[:]).String(), 8*len(address.GetPrefix())-1)
if current.IfName == "none" || current.IfName == "dummy" { if current.IfName == "none" || current.IfName == "dummy" {
tun.log.Debugln("Not starting TUN as ifname is none or dummy") tun.log.Debugln("Not starting TUN as ifname is none or dummy")
@ -248,13 +246,13 @@ const (
) )
func (tun *TunAdapter) sendKeyLookup(partial ed25519.PublicKey) { func (tun *TunAdapter) sendKeyLookup(partial ed25519.PublicKey) {
sig := ed25519.Sign(tun.secret, partial[:]) sig := ed25519.Sign(tun.core.PrivateKey(), partial[:])
bs := append([]byte{typeKeyLookup}, sig...) bs := append([]byte{typeKeyLookup}, sig...)
tun.core.SendOutOfBand(partial, bs) tun.core.SendOutOfBand(partial, bs)
} }
func (tun *TunAdapter) sendKeyResponse(dest ed25519.PublicKey) { func (tun *TunAdapter) sendKeyResponse(dest ed25519.PublicKey) {
sig := ed25519.Sign(tun.secret, dest[:]) sig := ed25519.Sign(tun.core.PrivateKey(), dest[:])
bs := append([]byte{typeKeyResponse}, sig...) bs := append([]byte{typeKeyResponse}, sig...)
tun.core.SendOutOfBand(dest, bs) tun.core.SendOutOfBand(dest, bs)
} }