mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-21 23:03:08 +01:00
Add DisabledAf
This commit is contained in:
parent
eb6bb7d15d
commit
b4ce21f5c5
@ -69,16 +69,23 @@ func NewLinuxSocketBindAf(use4 bool, use6 bool) Bind {
|
|||||||
return &LinuxSocketBind{sock4: -1, sock6: -1, use4: use4, use6: use6}
|
return &LinuxSocketBind{sock4: -1, sock6: -1, use4: use4, use6: use6}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultBind(use4 bool, use6 bool, bindmode string) Bind {
|
func NewDefaultBind(Af EnabledAf, bindmode string) Bind {
|
||||||
if bindmode == "std" {
|
if bindmode == "std" {
|
||||||
return NewStdNetBindAf(use4, use6)
|
return NewStdNetBindAf(Af.IPv4, Af.IPv6)
|
||||||
}
|
}
|
||||||
return NewLinuxSocketBindAf(use4, use6)
|
return NewLinuxSocketBindAf(Af.IPv4, Af.IPv6)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Endpoint = (*LinuxSocketEndpoint)(nil)
|
var _ Endpoint = (*LinuxSocketEndpoint)(nil)
|
||||||
var _ Bind = (*LinuxSocketBind)(nil)
|
var _ Bind = (*LinuxSocketBind)(nil)
|
||||||
|
|
||||||
|
func (s *LinuxSocketBind) EnabledAf() EnabledAf {
|
||||||
|
return EnabledAf{
|
||||||
|
s.use4,
|
||||||
|
s.use6,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (*LinuxSocketBind) ParseEndpoint(s string) (Endpoint, error) {
|
func (*LinuxSocketBind) ParseEndpoint(s string) (Endpoint, error) {
|
||||||
var end LinuxSocketEndpoint
|
var end LinuxSocketEndpoint
|
||||||
addr, err := parseEndpoint(s)
|
addr, err := parseEndpoint(s)
|
||||||
|
@ -43,6 +43,13 @@ func (*StdNetBind) ParseEndpoint(s string) (Endpoint, error) {
|
|||||||
|
|
||||||
func (*StdNetEndpoint) ClearSrc() {}
|
func (*StdNetEndpoint) ClearSrc() {}
|
||||||
|
|
||||||
|
func (s *StdNetBind) EnabledAf() EnabledAf {
|
||||||
|
return EnabledAf{
|
||||||
|
s.use4,
|
||||||
|
s.use6,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (e *StdNetEndpoint) DstIP() net.IP {
|
func (e *StdNetEndpoint) DstIP() net.IP {
|
||||||
return (*net.UDPAddr)(e).IP
|
return (*net.UDPAddr)(e).IP
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,13 @@ func NewChannelBinds() [2]conn.Bind {
|
|||||||
return [2]conn.Bind{&binds[0], &binds[1]}
|
return [2]conn.Bind{&binds[0], &binds[1]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ChannelBind) EnabledAf() conn.EnabledAf {
|
||||||
|
return conn.EnabledAf{
|
||||||
|
IPv4: true,
|
||||||
|
IPv6: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c ChannelEndpoint) ClearSrc() {}
|
func (c ChannelEndpoint) ClearSrc() {}
|
||||||
|
|
||||||
func (c ChannelEndpoint) SrcToString() string { return "" }
|
func (c ChannelEndpoint) SrcToString() string { return "" }
|
||||||
|
37
conn/conn.go
37
conn/conn.go
@ -43,6 +43,26 @@ type Bind interface {
|
|||||||
|
|
||||||
// ParseEndpoint creates a new endpoint from a string.
|
// ParseEndpoint creates a new endpoint from a string.
|
||||||
ParseEndpoint(s string) (Endpoint, error)
|
ParseEndpoint(s string) (Endpoint, error)
|
||||||
|
|
||||||
|
EnabledAf() EnabledAf
|
||||||
|
}
|
||||||
|
|
||||||
|
type EnabledAf struct {
|
||||||
|
IPv4 bool `yaml:"IPv4"`
|
||||||
|
IPv6 bool `yaml:"IPv6"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var EnabledAf4 = EnabledAf{
|
||||||
|
IPv4: true,
|
||||||
|
IPv6: false,
|
||||||
|
}
|
||||||
|
var EnabledAf6 = EnabledAf{
|
||||||
|
IPv4: false,
|
||||||
|
IPv6: true,
|
||||||
|
}
|
||||||
|
var EnabledAf46 = EnabledAf{
|
||||||
|
IPv4: true,
|
||||||
|
IPv6: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// BindSocketToInterface is implemented by Bind objects that support being
|
// BindSocketToInterface is implemented by Bind objects that support being
|
||||||
@ -150,7 +170,7 @@ func parseEndpoint(s string) (*net.UDPAddr, error) {
|
|||||||
return addr, err
|
return addr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func LookupIP(host_port string, Af int, AfPrefer int) (string, string, error) {
|
func LookupIP(host_port string, Af EnabledAf, AfPrefer int) (string, string, error) {
|
||||||
if host_port == "" {
|
if host_port == "" {
|
||||||
return "", "", fmt.Errorf("error lookup ip from empty string")
|
return "", "", fmt.Errorf("error lookup ip from empty string")
|
||||||
}
|
}
|
||||||
@ -159,12 +179,7 @@ func LookupIP(host_port string, Af int, AfPrefer int) (string, string, error) {
|
|||||||
var af_try_order []string
|
var af_try_order []string
|
||||||
|
|
||||||
var NetStr string
|
var NetStr string
|
||||||
switch Af {
|
if Af.IPv4 && Af.IPv6 {
|
||||||
case 4:
|
|
||||||
af_try_order = []string{"udp4"}
|
|
||||||
case 6:
|
|
||||||
af_try_order = []string{"udp6"}
|
|
||||||
case 0:
|
|
||||||
switch AfPrefer {
|
switch AfPrefer {
|
||||||
case 0:
|
case 0:
|
||||||
af_try_order = []string{"udp"}
|
af_try_order = []string{"udp"}
|
||||||
@ -175,8 +190,12 @@ func LookupIP(host_port string, Af int, AfPrefer int) (string, string, error) {
|
|||||||
default:
|
default:
|
||||||
return "", "", fmt.Errorf("unknown address family:%v", AfPrefer)
|
return "", "", fmt.Errorf("unknown address family:%v", AfPrefer)
|
||||||
}
|
}
|
||||||
default:
|
} else if Af.IPv4 {
|
||||||
return "", "", fmt.Errorf("unknown address family:%v", Af)
|
af_try_order = []string{"udp4"}
|
||||||
|
} else if Af.IPv6 {
|
||||||
|
af_try_order = []string{"udp6"}
|
||||||
|
} else {
|
||||||
|
return "", "", fmt.Errorf("no EnabledAf:%v", Af)
|
||||||
}
|
}
|
||||||
for _, af := range af_try_order {
|
for _, af := range af_try_order {
|
||||||
conn, err = net.Dial(af, host_port)
|
conn, err = net.Dial(af, host_port)
|
||||||
|
@ -82,6 +82,7 @@ type Device struct {
|
|||||||
EdgeConfig *mtypes.EdgeConfig
|
EdgeConfig *mtypes.EdgeConfig
|
||||||
SuperConfigPath string
|
SuperConfigPath string
|
||||||
SuperConfig *mtypes.SuperConfig
|
SuperConfig *mtypes.SuperConfig
|
||||||
|
enabledAf conn.EnabledAf
|
||||||
|
|
||||||
Chan_server_register chan mtypes.RegisterMsg
|
Chan_server_register chan mtypes.RegisterMsg
|
||||||
Chan_server_pong chan mtypes.PongMsg
|
Chan_server_pong chan mtypes.PongMsg
|
||||||
@ -344,6 +345,7 @@ func NewDevice(tapDevice tap.Device, id mtypes.Vertex, bind conn.Bind, logger *L
|
|||||||
device.graph = graph
|
device.graph = graph
|
||||||
device.Version = version
|
device.Version = version
|
||||||
device.JWTSecret = mtypes.ByteSlice2Byte32(mtypes.RandomBytes(32, []byte(fmt.Sprintf("%v", time.Now()))))
|
device.JWTSecret = mtypes.ByteSlice2Byte32(mtypes.RandomBytes(32, []byte(fmt.Sprintf("%v", time.Now()))))
|
||||||
|
device.enabledAf = bind.EnabledAf()
|
||||||
|
|
||||||
device.state_hashes.NhTable.Store("")
|
device.state_hashes.NhTable.Store("")
|
||||||
device.state_hashes.Peer.Store("")
|
device.state_hashes.Peer.Store("")
|
||||||
|
@ -33,15 +33,17 @@ type endpoint_tryitem struct {
|
|||||||
type endpoint_trylist struct {
|
type endpoint_trylist struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
|
enabledAf conn.EnabledAf
|
||||||
peer *Peer
|
peer *Peer
|
||||||
trymap_super map[string]*endpoint_tryitem
|
trymap_super map[string]*endpoint_tryitem
|
||||||
trymap_p2p map[string]*endpoint_tryitem
|
trymap_p2p map[string]*endpoint_tryitem
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEndpoint_trylist(peer *Peer, timeout time.Duration) *endpoint_trylist {
|
func NewEndpoint_trylist(peer *Peer, timeout time.Duration, enabledAf conn.EnabledAf) *endpoint_trylist {
|
||||||
return &endpoint_trylist{
|
return &endpoint_trylist{
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
peer: peer,
|
peer: peer,
|
||||||
|
enabledAf: enabledAf,
|
||||||
trymap_super: make(map[string]*endpoint_tryitem),
|
trymap_super: make(map[string]*endpoint_tryitem),
|
||||||
trymap_p2p: make(map[string]*endpoint_tryitem),
|
trymap_p2p: make(map[string]*endpoint_tryitem),
|
||||||
}
|
}
|
||||||
@ -60,7 +62,7 @@ func (et *endpoint_trylist) UpdateSuper(urls mtypes.API_connurl, UseLocalIP bool
|
|||||||
if url == "" {
|
if url == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
addr, _, err := conn.LookupIP(url, 0, AfPerfer)
|
addr, _, err := conn.LookupIP(url, et.enabledAf, AfPerfer)
|
||||||
switch AfPerfer {
|
switch AfPerfer {
|
||||||
case 4:
|
case 4:
|
||||||
if addr == "udp4" {
|
if addr == "udp4" {
|
||||||
@ -97,7 +99,7 @@ func (et *endpoint_trylist) UpdateSuper(urls mtypes.API_connurl, UseLocalIP bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (et *endpoint_trylist) UpdateP2P(url string) {
|
func (et *endpoint_trylist) UpdateP2P(url string) {
|
||||||
_, _, err := conn.LookupIP(url, 0, 0)
|
_, _, err := conn.LookupIP(url, et.enabledAf, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -254,7 +256,7 @@ type Peer struct {
|
|||||||
AskedForNeighbor bool
|
AskedForNeighbor bool
|
||||||
StaticConn bool //if true, this peer will not write to config file when roaming, and the endpoint will be reset periodically
|
StaticConn bool //if true, this peer will not write to config file when roaming, and the endpoint will be reset periodically
|
||||||
ConnURL string
|
ConnURL string
|
||||||
ConnAF int //0: both, 4: ipv4 only, 6: ipv6 only
|
ConnAF conn.EnabledAf
|
||||||
|
|
||||||
// These fields are accessed with atomic operations, which must be
|
// These fields are accessed with atomic operations, which must be
|
||||||
// 64-bit aligned even on 32-bit platforms. Go guarantees that an
|
// 64-bit aligned even on 32-bit platforms. Go guarantees that an
|
||||||
@ -330,6 +332,7 @@ func (device *Device) NewPeer(pk NoisePublicKey, id mtypes.Vertex, isSuper bool,
|
|||||||
fmt.Println("Internal: Create peer with ID : " + id.ToString() + " and PubKey:" + pk.ToString())
|
fmt.Println("Internal: Create peer with ID : " + id.ToString() + " and PubKey:" + pk.ToString())
|
||||||
}
|
}
|
||||||
peer := new(Peer)
|
peer := new(Peer)
|
||||||
|
peer.ConnAF = conn.EnabledAf46
|
||||||
atomic.SwapUint32(&peer.persistentKeepaliveInterval, PersistentKeepalive)
|
atomic.SwapUint32(&peer.persistentKeepaliveInterval, PersistentKeepalive)
|
||||||
peer.LastPacketReceivedAdd1Sec.Store(&time.Time{})
|
peer.LastPacketReceivedAdd1Sec.Store(&time.Time{})
|
||||||
peer.Lock()
|
peer.Lock()
|
||||||
@ -337,7 +340,7 @@ func (device *Device) NewPeer(pk NoisePublicKey, id mtypes.Vertex, isSuper bool,
|
|||||||
|
|
||||||
peer.cookieGenerator.Init(pk)
|
peer.cookieGenerator.Init(pk)
|
||||||
peer.device = device
|
peer.device = device
|
||||||
peer.endpoint_trylist = NewEndpoint_trylist(peer, mtypes.S2TD(device.EdgeConfig.DynamicRoute.PeerAliveTimeout))
|
peer.endpoint_trylist = NewEndpoint_trylist(peer, mtypes.S2TD(device.EdgeConfig.DynamicRoute.PeerAliveTimeout), device.enabledAf)
|
||||||
peer.SingleWayLatency.device = device
|
peer.SingleWayLatency.device = device
|
||||||
peer.SingleWayLatency.Push(mtypes.Infinity)
|
peer.SingleWayLatency.Push(mtypes.Infinity)
|
||||||
peer.queue.outbound = newAutodrainingOutboundQueue(device)
|
peer.queue.outbound = newAutodrainingOutboundQueue(device)
|
||||||
@ -556,7 +559,7 @@ func (peer *Peer) SetPSK(psk NoisePresharedKey) {
|
|||||||
peer.handshake.mutex.Unlock()
|
peer.handshake.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (peer *Peer) SetEndpointFromConnURL(connurl string, af int, af_perfer int, static bool) error {
|
func (peer *Peer) SetEndpointFromConnURL(connurl string, af conn.EnabledAf, af_perfer int, static bool) error {
|
||||||
if peer.device.LogLevel.LogInternal {
|
if peer.device.LogLevel.LogInternal {
|
||||||
fmt.Printf("Internal: Set endpoint to %v for NodeID: %v static:%v\n", connurl, peer.ID.ToString(), static)
|
fmt.Printf("Internal: Set endpoint to %v for NodeID: %v static:%v\n", connurl, peer.ID.ToString(), static)
|
||||||
}
|
}
|
||||||
|
@ -757,7 +757,7 @@ func (device *Device) RoutineTryReceivedEndpoint() {
|
|||||||
if connurl == "" {
|
if connurl == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err := thepeer.SetEndpointFromConnURL(connurl, thepeer.ConnAF, device.EdgeConfig.AfPrefer, thepeer.StaticConn) //trying to bind first url in the list and wait ConnNextTry seconds
|
err := thepeer.SetEndpointFromConnURL(connurl, device.enabledAf, device.EdgeConfig.AfPrefer, thepeer.StaticConn) //trying to bind first url in the list and wait ConnNextTry seconds
|
||||||
if err != nil {
|
if err != nil {
|
||||||
device.log.Errorf("Bind " + connurl + " failed!")
|
device.log.Errorf("Bind " + connurl + " failed!")
|
||||||
thepeer.endpoint_trylist.Delete(connurl)
|
thepeer.endpoint_trylist.Delete(connurl)
|
||||||
@ -939,12 +939,12 @@ func (device *Device) RoutinePostPeerInfo(startchan <-chan struct{}) {
|
|||||||
}
|
}
|
||||||
for _, AIP := range device.EdgeConfig.DynamicRoute.SuperNode.AdditionalLocalIP {
|
for _, AIP := range device.EdgeConfig.DynamicRoute.SuperNode.AdditionalLocalIP {
|
||||||
success := false
|
success := false
|
||||||
_, ipstr, err := conn.LookupIP(AIP, 4, 0)
|
_, ipstr, err := conn.LookupIP(AIP, conn.EnabledAf4, 0)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
success = true
|
success = true
|
||||||
LocalV4s[ipstr] = 50
|
LocalV4s[ipstr] = 50
|
||||||
}
|
}
|
||||||
_, ipstr, err = conn.LookupIP(AIP, 6, 0)
|
_, ipstr, err = conn.LookupIP(AIP, conn.EnabledAf6, 0)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
success = true
|
success = true
|
||||||
LocalV6s[ipstr] = 50
|
LocalV6s[ipstr] = 50
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: kkKXE1uFha84Yd8YIDUI02OsjVi2v7CM60rIUgC7zP4=
|
PrivKey: kkKXE1uFha84Yd8YIDUI02OsjVi2v7CM60rIUgC7zP4=
|
||||||
ListenPort: 3001
|
ListenPort: 3001
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: cK6/KorPQRK2o8w+upCr77XHK9/Mwvab59evSz/Jg0I=
|
PrivKey: cK6/KorPQRK2o8w+upCr77XHK9/Mwvab59evSz/Jg0I=
|
||||||
ListenPort: 3002
|
ListenPort: 3002
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: qaSOwMzr7nC7Vcphd7w6q9k6bz1eCVhe9uEt+803lvk=
|
PrivKey: qaSOwMzr7nC7Vcphd7w6q9k6bz1eCVhe9uEt+803lvk=
|
||||||
ListenPort: 3003
|
ListenPort: 3003
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: GL9GrJCeptF8+iiT8Nrem9qMaiQScu6tGjQ4CvEskn0=
|
PrivKey: GL9GrJCeptF8+iiT8Nrem9qMaiQScu6tGjQ4CvEskn0=
|
||||||
ListenPort: 3004
|
ListenPort: 3004
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: 5zWmtAW/NipYIZU1wWM6gWiYGPpz/yPslF3TEdNvUzw=
|
PrivKey: 5zWmtAW/NipYIZU1wWM6gWiYGPpz/yPslF3TEdNvUzw=
|
||||||
ListenPort: 3005
|
ListenPort: 3005
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: FxdP9nKi0YLvhMvwYV3NcUixDjb3Q7gBGtmFLPjqLZs=
|
PrivKey: FxdP9nKi0YLvhMvwYV3NcUixDjb3Q7gBGtmFLPjqLZs=
|
||||||
ListenPort: 3006
|
ListenPort: 3006
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: u1U5zImQ0lByFcJXTysUq9ZSTg3ZLIKMDYn/RAXEtKI=
|
PrivKey: u1U5zImQ0lByFcJXTysUq9ZSTg3ZLIKMDYn/RAXEtKI=
|
||||||
ListenPort: 3001
|
ListenPort: 3001
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: Gn3hwOAtlKeBldzr6Jmu+aeoXR/TAcT7RzITZGMYfek=
|
PrivKey: Gn3hwOAtlKeBldzr6Jmu+aeoXR/TAcT7RzITZGMYfek=
|
||||||
ListenPort: 3002
|
ListenPort: 3002
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: odbxmbr0GhcsZSpyrVLooMixeSg0t1WpL1BYwb8EJWw=
|
PrivKey: odbxmbr0GhcsZSpyrVLooMixeSg0t1WpL1BYwb8EJWw=
|
||||||
ListenPort: 3003
|
ListenPort: 3003
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: t5DUQqA4/G7ONUVroXuYx94iC8ZEOGW/LH7GT3MfL/8=
|
PrivKey: t5DUQqA4/G7ONUVroXuYx94iC8ZEOGW/LH7GT3MfL/8=
|
||||||
ListenPort: 3004
|
ListenPort: 3004
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: MxAk/kCWlBRBpSJqdJImIlG7ic2drOPxEqUr/cyevx4=
|
PrivKey: MxAk/kCWlBRBpSJqdJImIlG7ic2drOPxEqUr/cyevx4=
|
||||||
ListenPort: 3005
|
ListenPort: 3005
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: zlcpGbnXXtTuaB+XDKtWQpXqxvwzhee2qdMcTI1k3cA=
|
PrivKey: zlcpGbnXXtTuaB+XDKtWQpXqxvwzhee2qdMcTI1k3cA=
|
||||||
ListenPort: 3006
|
ListenPort: 3006
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
LogTransit: true
|
LogTransit: true
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: +KAYwkRgacUbxc52t04z8fTJBgvrkPLsisr0qJOhIUE=
|
PrivKey: +KAYwkRgacUbxc52t04z8fTJBgvrkPLsisr0qJOhIUE=
|
||||||
ListenPort: 0
|
ListenPort: 0
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
AfPrefer: 4
|
AfPrefer: 4
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: jDAolOiiRj/ju1xpVagZTtsxJSJba2rjp7J2XMc3yoM=
|
PrivKey: jDAolOiiRj/ju1xpVagZTtsxJSJba2rjp7J2XMc3yoM=
|
||||||
ListenPort: 0
|
ListenPort: 0
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
AfPrefer: 4
|
AfPrefer: 4
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
|||||||
L2FIBTimeout: 3600
|
L2FIBTimeout: 3600
|
||||||
PrivKey: yNf1SkvwV8c59GmesfTNxSut6gFjYKEg9uIsE05XQUI=
|
PrivKey: yNf1SkvwV8c59GmesfTNxSut6gFjYKEg9uIsE05XQUI=
|
||||||
ListenPort: 0
|
ListenPort: 0
|
||||||
|
DisabledAf:
|
||||||
|
IPv4: false
|
||||||
|
IPv6: false
|
||||||
AfPrefer: 4
|
AfPrefer: 4
|
||||||
LogLevel:
|
LogLevel:
|
||||||
LogLevel: error
|
LogLevel: error
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
|
||||||
|
"github.com/KusakabeSi/EtherGuard-VPN/conn"
|
||||||
"github.com/KusakabeSi/EtherGuard-VPN/device"
|
"github.com/KusakabeSi/EtherGuard-VPN/device"
|
||||||
"github.com/KusakabeSi/EtherGuard-VPN/mtypes"
|
"github.com/KusakabeSi/EtherGuard-VPN/mtypes"
|
||||||
"github.com/KusakabeSi/EtherGuard-VPN/path"
|
"github.com/KusakabeSi/EtherGuard-VPN/path"
|
||||||
@ -44,7 +45,11 @@ func GetExampleEdgeConf(templatePath string, getDemo bool) (mtypes.EdgeConfig, e
|
|||||||
L2FIBTimeout: 3600,
|
L2FIBTimeout: 3600,
|
||||||
PrivKey: "6GyDagZKhbm5WNqMiRHhkf43RlbMJ34IieTlIuvfJ1M=",
|
PrivKey: "6GyDagZKhbm5WNqMiRHhkf43RlbMJ34IieTlIuvfJ1M=",
|
||||||
ListenPort: 0,
|
ListenPort: 0,
|
||||||
AfPrefer: 4,
|
DisableAf: conn.EnabledAf{
|
||||||
|
IPv4: false,
|
||||||
|
IPv6: false,
|
||||||
|
},
|
||||||
|
AfPrefer: 4,
|
||||||
LogLevel: mtypes.LoggerInfo{
|
LogLevel: mtypes.LoggerInfo{
|
||||||
LogLevel: "error",
|
LogLevel: "error",
|
||||||
LogTransit: false,
|
LogTransit: false,
|
||||||
|
@ -114,7 +114,7 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
|
|||||||
return fmt.Errorf("duplicate definition: NodeID %v ", NodeID)
|
return fmt.Errorf("duplicate definition: NodeID %v ", NodeID)
|
||||||
}
|
}
|
||||||
if endpoint != "" {
|
if endpoint != "" {
|
||||||
_, _, err = conn.LookupIP(endpoint, 0, 0)
|
_, _, err = conn.LookupIP(endpoint, conn.EnabledAf46, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) {
|
|||||||
API_Prefix := SMCfg.Supernode.EdgeAPI_Prefix
|
API_Prefix := SMCfg.Supernode.EdgeAPI_Prefix
|
||||||
EndpointV4 := SMCfg.Supernode.EndpointV4
|
EndpointV4 := SMCfg.Supernode.EndpointV4
|
||||||
if EndpointV4 != "" {
|
if EndpointV4 != "" {
|
||||||
_, _, err = conn.LookupIP(EndpointV4+":"+ListenPort, 4, 0)
|
_, _, err = conn.LookupIP(EndpointV4+":"+ListenPort, conn.EnabledAf4, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) {
|
|||||||
if strings.Contains(EndpointV6, ":") && (EndpointV6[0] != '[' || EndpointV6[len(EndpointV6)-1] != ']') {
|
if strings.Contains(EndpointV6, ":") && (EndpointV6[0] != '[' || EndpointV6[len(EndpointV6)-1] != ']') {
|
||||||
return fmt.Errorf("Invalid IPv6 format, please use [%v] instead", EndpointV6)
|
return fmt.Errorf("Invalid IPv6 format, please use [%v] instead", EndpointV6)
|
||||||
}
|
}
|
||||||
_, _, err = conn.LookupIP(EndpointV6+":"+ListenPort, 6, 0)
|
_, _, err = conn.LookupIP(EndpointV6+":"+ListenPort, conn.EnabledAf6, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
17
main_edge.go
17
main_edge.go
@ -120,7 +120,12 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
|||||||
}
|
}
|
||||||
graph.SetNHTable(econfig.NextHopTable)
|
graph.SetNHTable(econfig.NextHopTable)
|
||||||
|
|
||||||
the_device := device.NewDevice(thetap, econfig.NodeID, conn.NewDefaultBind(true, true, bindmode), logger, graph, false, configPath, &econfig, nil, nil, Version)
|
EnabledAf := conn.EnabledAf{
|
||||||
|
IPv4: !econfig.DisableAf.IPv4,
|
||||||
|
IPv6: !econfig.DisableAf.IPv6,
|
||||||
|
}
|
||||||
|
|
||||||
|
the_device := device.NewDevice(thetap, econfig.NodeID, conn.NewDefaultBind(EnabledAf, bindmode), logger, graph, false, configPath, &econfig, nil, nil, Version)
|
||||||
defer the_device.Close()
|
defer the_device.Close()
|
||||||
pk, err := device.Str2PriKey(econfig.PrivKey)
|
pk, err := device.Str2PriKey(econfig.PrivKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -140,7 +145,7 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
|||||||
the_device.NewPeer(pk, peerconf.NodeID, false, peerconf.PersistentKeepalive)
|
the_device.NewPeer(pk, peerconf.NodeID, false, peerconf.PersistentKeepalive)
|
||||||
if peerconf.EndPoint != "" {
|
if peerconf.EndPoint != "" {
|
||||||
peer := the_device.LookupPeer(pk)
|
peer := the_device.LookupPeer(pk)
|
||||||
err = peer.SetEndpointFromConnURL(peerconf.EndPoint, 0, econfig.AfPrefer, peerconf.Static)
|
err = peer.SetEndpointFromConnURL(peerconf.EndPoint, EnabledAf, econfig.AfPrefer, peerconf.Static)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Failed to set endpoint %v: %w", peerconf.EndPoint, err)
|
logger.Errorf("Failed to set endpoint %v: %w", peerconf.EndPoint, err)
|
||||||
return err
|
return err
|
||||||
@ -151,7 +156,7 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
|||||||
if econfig.DynamicRoute.SuperNode.UseSuperNode {
|
if econfig.DynamicRoute.SuperNode.UseSuperNode {
|
||||||
S4 := true
|
S4 := true
|
||||||
S6 := true
|
S6 := true
|
||||||
if econfig.DynamicRoute.SuperNode.EndpointV4 != "" {
|
if econfig.DynamicRoute.SuperNode.EndpointV4 != "" && EnabledAf.IPv4 {
|
||||||
pk, err := device.Str2PubKey(econfig.DynamicRoute.SuperNode.PubKeyV4)
|
pk, err := device.Str2PubKey(econfig.DynamicRoute.SuperNode.PubKeyV4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error decode base64 ", err)
|
fmt.Println("Error decode base64 ", err)
|
||||||
@ -176,13 +181,13 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
|||||||
StaticSuper = false
|
StaticSuper = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = peer.SetEndpointFromConnURL(econfig.DynamicRoute.SuperNode.EndpointV4, 4, 0, StaticSuper)
|
err = peer.SetEndpointFromConnURL(econfig.DynamicRoute.SuperNode.EndpointV4, conn.EnabledAf4, 0, StaticSuper)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Failed to set endpoint for supernode v4 %v: %v", econfig.DynamicRoute.SuperNode.EndpointV4, err)
|
logger.Errorf("Failed to set endpoint for supernode v4 %v: %v", econfig.DynamicRoute.SuperNode.EndpointV4, err)
|
||||||
S4 = false
|
S4 = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if econfig.DynamicRoute.SuperNode.EndpointV6 != "" {
|
if econfig.DynamicRoute.SuperNode.EndpointV6 != "" && EnabledAf.IPv6 {
|
||||||
pk, err := device.Str2PubKey(econfig.DynamicRoute.SuperNode.PubKeyV6)
|
pk, err := device.Str2PubKey(econfig.DynamicRoute.SuperNode.PubKeyV6)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error decode base64 ", err)
|
fmt.Println("Error decode base64 ", err)
|
||||||
@ -206,7 +211,7 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
|||||||
StaticSuper = false
|
StaticSuper = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = peer.SetEndpointFromConnURL(econfig.DynamicRoute.SuperNode.EndpointV6, 6, 0, StaticSuper)
|
err = peer.SetEndpointFromConnURL(econfig.DynamicRoute.SuperNode.EndpointV6, conn.EnabledAf6, 0, StaticSuper)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Failed to set endpoint for supernode v6 %v: %v", econfig.DynamicRoute.SuperNode.EndpointV6, err)
|
logger.Errorf("Failed to set endpoint for supernode v6 %v: %v", econfig.DynamicRoute.SuperNode.EndpointV6, err)
|
||||||
S6 = false
|
S6 = false
|
||||||
|
@ -162,7 +162,7 @@ func get_api_peers(old_State_hash string) (api_peerinfo mtypes.API_Peers, StateH
|
|||||||
if strings.Contains(connV4, ":") {
|
if strings.Contains(connV4, ":") {
|
||||||
hostport := strings.Split(connV4, ":")
|
hostport := strings.Split(connV4, ":")
|
||||||
ExternalIP = ExternalIP + ":" + hostport[len(hostport)-1]
|
ExternalIP = ExternalIP + ":" + hostport[len(hostport)-1]
|
||||||
_, ExternalEndPoint_v4, err := conn.LookupIP(ExternalIP, 4, 0)
|
_, ExternalEndPoint_v4, err := conn.LookupIP(ExternalIP, conn.EnabledAf4, 0)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
connV4 = ExternalEndPoint_v4
|
connV4 = ExternalEndPoint_v4
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ func get_api_peers(old_State_hash string) (api_peerinfo mtypes.API_Peers, StateH
|
|||||||
if strings.Contains(connV6, ":") {
|
if strings.Contains(connV6, ":") {
|
||||||
hostport := strings.Split(connV6, ":")
|
hostport := strings.Split(connV6, ":")
|
||||||
ExternalIP = ExternalIP + ":" + hostport[len(hostport)-1]
|
ExternalIP = ExternalIP + ":" + hostport[len(hostport)-1]
|
||||||
_, ExternalEndPoint_v6, err := conn.LookupIP(ExternalIP, 6, 0)
|
_, ExternalEndPoint_v6, err := conn.LookupIP(ExternalIP, conn.EnabledAf6, 0)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
connV6 = ExternalEndPoint_v6
|
connV6 = ExternalEndPoint_v6
|
||||||
}
|
}
|
||||||
|
@ -144,10 +144,10 @@ func Super(configPath string, useUAPI bool, printExample bool, bindmode string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
thetap4, _ := tap.CreateDummyTAP()
|
thetap4, _ := tap.CreateDummyTAP()
|
||||||
httpobj.http_device4 = device.NewDevice(thetap4, mtypes.NodeID_SuperNode, conn.NewDefaultBind(true, false, bindmode), logger4, httpobj.http_graph, true, configPath, nil, &sconfig, httpobj.http_super_chains, Version)
|
httpobj.http_device4 = device.NewDevice(thetap4, mtypes.NodeID_SuperNode, conn.NewDefaultBind(conn.EnabledAf4, bindmode), logger4, httpobj.http_graph, true, configPath, nil, &sconfig, httpobj.http_super_chains, Version)
|
||||||
defer httpobj.http_device4.Close()
|
defer httpobj.http_device4.Close()
|
||||||
thetap6, _ := tap.CreateDummyTAP()
|
thetap6, _ := tap.CreateDummyTAP()
|
||||||
httpobj.http_device6 = device.NewDevice(thetap6, mtypes.NodeID_SuperNode, conn.NewDefaultBind(false, true, bindmode), logger6, httpobj.http_graph, true, configPath, nil, &sconfig, httpobj.http_super_chains, Version)
|
httpobj.http_device6 = device.NewDevice(thetap6, mtypes.NodeID_SuperNode, conn.NewDefaultBind(conn.EnabledAf6, bindmode), logger6, httpobj.http_graph, true, configPath, nil, &sconfig, httpobj.http_super_chains, Version)
|
||||||
defer httpobj.http_device6.Close()
|
defer httpobj.http_device6.Close()
|
||||||
if sconfig.PrivKeyV4 != "" {
|
if sconfig.PrivKeyV4 != "" {
|
||||||
pk4, err := device.Str2PriKey(sconfig.PrivKeyV4)
|
pk4, err := device.Str2PriKey(sconfig.PrivKeyV4)
|
||||||
@ -263,7 +263,7 @@ func super_peeradd(peerconf mtypes.SuperPeerInfo) error {
|
|||||||
peer4.SetPSK(psk)
|
peer4.SetPSK(psk)
|
||||||
}
|
}
|
||||||
if peerconf.EndPoint != "" {
|
if peerconf.EndPoint != "" {
|
||||||
err = peer4.SetEndpointFromConnURL(peerconf.EndPoint, 4, 0, true)
|
err = peer4.SetEndpointFromConnURL(peerconf.EndPoint, conn.EnabledAf4, 0, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if httpobj.http_sconfig.LogLevel.LogInternal {
|
if httpobj.http_sconfig.LogLevel.LogInternal {
|
||||||
fmt.Printf("Internal: Set endpoint failed:%v\n", err)
|
fmt.Printf("Internal: Set endpoint failed:%v\n", err)
|
||||||
@ -288,7 +288,7 @@ func super_peeradd(peerconf mtypes.SuperPeerInfo) error {
|
|||||||
peer6.SetPSK(psk)
|
peer6.SetPSK(psk)
|
||||||
}
|
}
|
||||||
if peerconf.EndPoint != "" {
|
if peerconf.EndPoint != "" {
|
||||||
err = peer6.SetEndpointFromConnURL(peerconf.EndPoint, 6, 0, true)
|
err = peer6.SetEndpointFromConnURL(peerconf.EndPoint, conn.EnabledAf6, 0, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if httpobj.http_sconfig.LogLevel.LogInternal {
|
if httpobj.http_sconfig.LogLevel.LogInternal {
|
||||||
fmt.Printf("Internal: Set endpoint failed:%v\n", err)
|
fmt.Printf("Internal: Set endpoint failed:%v\n", err)
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/KusakabeSi/EtherGuard-VPN/conn"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Nonnegative integer ID of vertex
|
// Nonnegative integer ID of vertex
|
||||||
@ -26,6 +28,7 @@ type EdgeConfig struct {
|
|||||||
L2FIBTimeout float64 `yaml:"L2FIBTimeout"`
|
L2FIBTimeout float64 `yaml:"L2FIBTimeout"`
|
||||||
PrivKey string `yaml:"PrivKey"`
|
PrivKey string `yaml:"PrivKey"`
|
||||||
ListenPort int `yaml:"ListenPort"`
|
ListenPort int `yaml:"ListenPort"`
|
||||||
|
DisableAf conn.EnabledAf `yaml:"DisabledAf"`
|
||||||
AfPrefer int `yaml:"AfPrefer"`
|
AfPrefer int `yaml:"AfPrefer"`
|
||||||
LogLevel LoggerInfo `yaml:"LogLevel"`
|
LogLevel LoggerInfo `yaml:"LogLevel"`
|
||||||
DynamicRoute DynamicRouteInfo `yaml:"DynamicRoute"`
|
DynamicRoute DynamicRouteInfo `yaml:"DynamicRoute"`
|
||||||
|
Loading…
Reference in New Issue
Block a user