Compare commits
1 Commits
5efaa3e177
...
755908a189
Author | SHA1 | Date |
---|---|---|
Ian VanSchooten | 755908a189 |
|
@ -21,7 +21,7 @@ class HostInfo {
|
|||
|
||||
factory HostInfo.fromJson(Map<String, dynamic> json) {
|
||||
UDPAddress? currentRemote;
|
||||
if (json['currentRemote'] != "") {
|
||||
if (json['currentRemote'] != null) {
|
||||
currentRemote = UDPAddress.fromJson(json['currentRemote']);
|
||||
}
|
||||
|
||||
|
@ -52,11 +52,6 @@ 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
|
||||
|
@ -67,17 +62,7 @@ class UDPAddress {
|
|||
return '$ip:$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);
|
||||
}
|
||||
UDPAddress.fromJson(Map<String, dynamic> json)
|
||||
: ip = json['ip'],
|
||||
port = json['port'];
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ type config struct {
|
|||
Stats configStats `yaml:"stats"`
|
||||
Handshakes configHandshakes `yaml:"handshakes"`
|
||||
Firewall configFirewall `yaml:"firewall"`
|
||||
Relay configRelay `yaml:"relay"`
|
||||
Relays configRelays `yaml:"relays"`
|
||||
}
|
||||
|
||||
func newConfig() *config {
|
||||
|
@ -38,7 +38,7 @@ func newConfig() *config {
|
|||
Punch: true,
|
||||
Delay: "1s",
|
||||
},
|
||||
Relay: configRelay{
|
||||
Relays: configRelays{
|
||||
UseRelays: true,
|
||||
},
|
||||
Cipher: "aes",
|
||||
|
@ -205,7 +205,7 @@ type configFirewallRule struct {
|
|||
CAName string `yaml:"ca_name,omitempty"`
|
||||
}
|
||||
|
||||
type configRelay struct {
|
||||
type configRelays struct {
|
||||
AmRelay bool `yaml:"am_relay,omitempty"`
|
||||
UseRelays bool `yaml:"use_relays"`
|
||||
relays []string `yaml:"relays,omitempty"`
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
|
@ -12,7 +12,9 @@ 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"
|
||||
)
|
||||
|
||||
|
@ -107,12 +109,7 @@ func (n *Nebula) ListHostmap(pending bool) (string, error) {
|
|||
}
|
||||
|
||||
func (n *Nebula) GetHostInfoByVpnIp(vpnIp string, pending bool) (string, error) {
|
||||
netVpnIp, err := netip.ParseAddr(vpnIp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
b, err := json.Marshal(n.c.GetHostInfoByVpnIp(netVpnIp, pending))
|
||||
b, err := json.Marshal(n.c.GetHostInfoByVpnIp(stringIpToInt(vpnIp), pending))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -121,26 +118,16 @@ func (n *Nebula) GetHostInfoByVpnIp(vpnIp string, pending bool) (string, error)
|
|||
}
|
||||
|
||||
func (n *Nebula) CloseTunnel(vpnIp string) bool {
|
||||
netVpnIp, err := netip.ParseAddr(vpnIp)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return n.c.CloseTunnel(netVpnIp, false)
|
||||
return n.c.CloseTunnel(stringIpToInt(vpnIp), false)
|
||||
}
|
||||
|
||||
func (n *Nebula) SetRemoteForTunnel(vpnIp string, addr string) (string, error) {
|
||||
udpAddr, err := netip.ParseAddrPort(addr)
|
||||
if err != nil {
|
||||
udpAddr := udp.NewAddrFromString(addr)
|
||||
if udpAddr == nil {
|
||||
return "", errors.New("could not parse udp address")
|
||||
}
|
||||
|
||||
netVpnIp, err := netip.ParseAddr(vpnIp)
|
||||
if err != nil {
|
||||
return "", errors.New("could not parse vpnIp")
|
||||
}
|
||||
|
||||
b, err := json.Marshal(n.c.SetRemoteForTunnel(netVpnIp, udpAddr))
|
||||
b, err := json.Marshal(n.c.SetRemoteForTunnel(stringIpToInt(vpnIp), *udpAddr))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -153,3 +140,7 @@ 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))
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ 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
|
||||
|
|
|
@ -159,8 +159,6 @@ 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=
|
||||
|
|
Loading…
Reference in New Issue