Compare commits

..

2 Commits

Author SHA1 Message Date
John Maguire 43fad65cf7
Use correct relay key in Nebula config (#184) 2024-10-16 17:13:44 -04:00
John Maguire 470578865b
Update to support netip use in Nebula 1.9.4 (#182) 2024-10-16 17:02:28 -04:00
5 changed files with 46 additions and 19 deletions

View File

@ -21,7 +21,7 @@ class HostInfo {
factory HostInfo.fromJson(Map<String, dynamic> json) {
UDPAddress? currentRemote;
if (json['currentRemote'] != null) {
if (json['currentRemote'] != "") {
currentRemote = UDPAddress.fromJson(json['currentRemote']);
}
@ -52,6 +52,11 @@ class UDPAddress {
String ip;
int port;
UDPAddress({
required this.ip,
required this.port,
});
@override
String toString() {
// Simple check on if nebula told us about a v4 or v6 ip address
@ -62,7 +67,17 @@ class UDPAddress {
return '$ip:$port';
}
UDPAddress.fromJson(Map<String, dynamic> json)
: ip = json['ip'],
port = json['port'];
factory UDPAddress.fromJson(String json) {
// IPv4 Address
if (json.contains('.')) {
var ip = json.split(':')[0];
var port = int.parse(json.split(':')[1]);
return UDPAddress(ip: ip, port: port);
}
// IPv6 Address
var ip = json.split(']')[0].substring(1);
var port = int.parse(json.split(']')[1].split(':')[1]);
return UDPAddress(ip: ip, port: port);
}
}

View File

@ -14,7 +14,7 @@ type config struct {
Stats configStats `yaml:"stats"`
Handshakes configHandshakes `yaml:"handshakes"`
Firewall configFirewall `yaml:"firewall"`
Relays configRelays `yaml:"relays"`
Relay configRelay `yaml:"relay"`
}
func newConfig() *config {
@ -38,7 +38,7 @@ func newConfig() *config {
Punch: true,
Delay: "1s",
},
Relays: configRelays{
Relay: configRelay{
UseRelays: true,
},
Cipher: "aes",
@ -205,7 +205,7 @@ type configFirewallRule struct {
CAName string `yaml:"ca_name,omitempty"`
}
type configRelays struct {
type configRelay struct {
AmRelay bool `yaml:"am_relay,omitempty"`
UseRelays bool `yaml:"use_relays"`
relays []string `yaml:"relays,omitempty"`

View File

@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"net/netip"
"os"
"runtime"
"runtime/debug"
@ -12,9 +12,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/slackhq/nebula"
nc "github.com/slackhq/nebula/config"
"github.com/slackhq/nebula/iputil"
"github.com/slackhq/nebula/overlay"
"github.com/slackhq/nebula/udp"
"github.com/slackhq/nebula/util"
)
@ -109,7 +107,12 @@ func (n *Nebula) ListHostmap(pending bool) (string, error) {
}
func (n *Nebula) GetHostInfoByVpnIp(vpnIp string, pending bool) (string, error) {
b, err := json.Marshal(n.c.GetHostInfoByVpnIp(stringIpToInt(vpnIp), pending))
netVpnIp, err := netip.ParseAddr(vpnIp)
if err != nil {
return "", err
}
b, err := json.Marshal(n.c.GetHostInfoByVpnIp(netVpnIp, pending))
if err != nil {
return "", err
}
@ -118,16 +121,26 @@ func (n *Nebula) GetHostInfoByVpnIp(vpnIp string, pending bool) (string, error)
}
func (n *Nebula) CloseTunnel(vpnIp string) bool {
return n.c.CloseTunnel(stringIpToInt(vpnIp), false)
netVpnIp, err := netip.ParseAddr(vpnIp)
if err != nil {
return false
}
return n.c.CloseTunnel(netVpnIp, false)
}
func (n *Nebula) SetRemoteForTunnel(vpnIp string, addr string) (string, error) {
udpAddr := udp.NewAddrFromString(addr)
if udpAddr == nil {
udpAddr, err := netip.ParseAddrPort(addr)
if err != nil {
return "", errors.New("could not parse udp address")
}
b, err := json.Marshal(n.c.SetRemoteForTunnel(stringIpToInt(vpnIp), *udpAddr))
netVpnIp, err := netip.ParseAddr(vpnIp)
if err != nil {
return "", errors.New("could not parse vpnIp")
}
b, err := json.Marshal(n.c.SetRemoteForTunnel(netVpnIp, udpAddr))
if err != nil {
return "", err
}
@ -140,7 +153,3 @@ func (n *Nebula) Sleep() {
n.l.WithField("tunnels", closed).Info("Sleep called, closed non lighthouse tunnels")
}
}
func stringIpToInt(ip string) iputil.VpnIp {
return iputil.Ip2VpnIp(net.ParseIP(ip))
}

View File

@ -39,6 +39,7 @@ require (
github.com/vishvananda/netlink v1.3.0 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/mobile v0.0.0-20241016134751-7ff83004ec2c // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect

View File

@ -159,6 +159,8 @@ golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20241016134751-7ff83004ec2c h1:zuNS/LWsEpPTLfrmBkis6Xofw3nieAqB4hYLn8+uswk=
golang.org/x/mobile v0.0.0-20241016134751-7ff83004ec2c/go.mod h1:snk1Mn2ZpdKCt90JPEsDh4sL3ReK520U2t0d7RHBnSU=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=