mirror of
https://github.com/gravitl/netmaker.git
synced 2025-11-11 09:10:53 +08:00
Net 1115 (#2890)
* add endpointipv6 for host * keep endpointipv6 unchanged when enable static endpoint * handle ipv6 endpoint updates --------- Co-authored-by: abhishek9686 <abhi281342@gmail.com>
This commit is contained in:
parent
879f37222e
commit
5740c3e009
6 changed files with 33 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ import (
|
||||||
var (
|
var (
|
||||||
apiHostFilePath string
|
apiHostFilePath string
|
||||||
endpoint string
|
endpoint string
|
||||||
|
endpoint6 string
|
||||||
name string
|
name string
|
||||||
listenPort int
|
listenPort int
|
||||||
mtu int
|
mtu int
|
||||||
|
|
@ -40,6 +41,7 @@ var hostUpdateCmd = &cobra.Command{
|
||||||
} else {
|
} else {
|
||||||
apiHost.ID = args[0]
|
apiHost.ID = args[0]
|
||||||
apiHost.EndpointIP = endpoint
|
apiHost.EndpointIP = endpoint
|
||||||
|
apiHost.EndpointIPv6 = endpoint6
|
||||||
apiHost.Name = name
|
apiHost.Name = name
|
||||||
apiHost.ListenPort = listenPort
|
apiHost.ListenPort = listenPort
|
||||||
apiHost.MTU = mtu
|
apiHost.MTU = mtu
|
||||||
|
|
@ -54,6 +56,7 @@ var hostUpdateCmd = &cobra.Command{
|
||||||
func init() {
|
func init() {
|
||||||
hostUpdateCmd.Flags().StringVar(&apiHostFilePath, "file", "", "Path to host_definition.json")
|
hostUpdateCmd.Flags().StringVar(&apiHostFilePath, "file", "", "Path to host_definition.json")
|
||||||
hostUpdateCmd.Flags().StringVar(&endpoint, "endpoint", "", "Endpoint of the Host")
|
hostUpdateCmd.Flags().StringVar(&endpoint, "endpoint", "", "Endpoint of the Host")
|
||||||
|
hostUpdateCmd.Flags().StringVar(&endpoint6, "endpoint6", "", "IPv6 Endpoint of the Host")
|
||||||
hostUpdateCmd.Flags().StringVar(&name, "name", "", "Host name")
|
hostUpdateCmd.Flags().StringVar(&name, "name", "", "Host name")
|
||||||
hostUpdateCmd.Flags().IntVar(&listenPort, "listen_port", 0, "Listen port of the host")
|
hostUpdateCmd.Flags().IntVar(&listenPort, "listen_port", 0, "Listen port of the host")
|
||||||
hostUpdateCmd.Flags().IntVar(&mtu, "mtu", 0, "Host MTU size")
|
hostUpdateCmd.Flags().IntVar(&mtu, "mtu", 0, "Host MTU size")
|
||||||
|
|
|
||||||
|
|
@ -217,6 +217,7 @@ func UpdateHost(newHost, currentHost *models.Host) {
|
||||||
newHost.Nodes = currentHost.Nodes
|
newHost.Nodes = currentHost.Nodes
|
||||||
newHost.PublicKey = currentHost.PublicKey
|
newHost.PublicKey = currentHost.PublicKey
|
||||||
newHost.TrafficKeyPublic = currentHost.TrafficKeyPublic
|
newHost.TrafficKeyPublic = currentHost.TrafficKeyPublic
|
||||||
|
newHost.EndpointIPv6 = currentHost.EndpointIPv6
|
||||||
// changeable fields
|
// changeable fields
|
||||||
if len(newHost.Version) == 0 {
|
if len(newHost.Version) == 0 {
|
||||||
newHost.Version = currentHost.Version
|
newHost.Version = currentHost.Version
|
||||||
|
|
@ -258,6 +259,10 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)
|
||||||
currHost.EndpointIP = newHost.EndpointIP
|
currHost.EndpointIP = newHost.EndpointIP
|
||||||
sendPeerUpdate = true
|
sendPeerUpdate = true
|
||||||
}
|
}
|
||||||
|
if currHost.EndpointIPv6.String() != newHost.EndpointIPv6.String() {
|
||||||
|
currHost.EndpointIPv6 = newHost.EndpointIPv6
|
||||||
|
sendPeerUpdate = true
|
||||||
|
}
|
||||||
currHost.DaemonInstalled = newHost.DaemonInstalled
|
currHost.DaemonInstalled = newHost.DaemonInstalled
|
||||||
currHost.Debug = newHost.Debug
|
currHost.Debug = newHost.Debug
|
||||||
currHost.Verbosity = newHost.Verbosity
|
currHost.Verbosity = newHost.Verbosity
|
||||||
|
|
|
||||||
|
|
@ -207,8 +207,21 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
||||||
uselocal = false
|
uselocal = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if host is ipv4 only or ipv4+ipv6, set the peer endpoint to ipv4 address, if host is ipv6 only, set the peer endpoint to ipv6 address
|
||||||
|
peerEndpoint := peerHost.EndpointIP
|
||||||
|
if ipv4 := host.EndpointIP.To4(); ipv4 != nil {
|
||||||
|
peerEndpoint = peerHost.EndpointIP
|
||||||
|
} else {
|
||||||
|
//if peer host's ipv6 address is empty, it means that peer is an IPv4 only host
|
||||||
|
//IPv4 only host could not communicate with IPv6 only host
|
||||||
|
if peerHost.EndpointIPv6 != nil && peerHost.EndpointIPv6.String() != "" {
|
||||||
|
peerEndpoint = peerHost.EndpointIPv6
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
peerConfig.Endpoint = &net.UDPAddr{
|
peerConfig.Endpoint = &net.UDPAddr{
|
||||||
IP: peerHost.EndpointIP,
|
IP: peerEndpoint,
|
||||||
Port: GetPeerListenPort(peerHost),
|
Port: GetPeerListenPort(peerHost),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ type ApiHost struct {
|
||||||
Interfaces []ApiIface `json:"interfaces" yaml:"interfaces"`
|
Interfaces []ApiIface `json:"interfaces" yaml:"interfaces"`
|
||||||
DefaultInterface string `json:"defaultinterface" yaml:"defautlinterface"`
|
DefaultInterface string `json:"defaultinterface" yaml:"defautlinterface"`
|
||||||
EndpointIP string `json:"endpointip" yaml:"endpointip"`
|
EndpointIP string `json:"endpointip" yaml:"endpointip"`
|
||||||
|
EndpointIPv6 string `json:"endpointipv6" yaml:"endpointipv6"`
|
||||||
PublicKey string `json:"publickey"`
|
PublicKey string `json:"publickey"`
|
||||||
MacAddress string `json:"macaddress"`
|
MacAddress string `json:"macaddress"`
|
||||||
Nodes []string `json:"nodes"`
|
Nodes []string `json:"nodes"`
|
||||||
|
|
@ -43,6 +44,7 @@ func (h *Host) ConvertNMHostToAPI() *ApiHost {
|
||||||
a := ApiHost{}
|
a := ApiHost{}
|
||||||
a.Debug = h.Debug
|
a.Debug = h.Debug
|
||||||
a.EndpointIP = h.EndpointIP.String()
|
a.EndpointIP = h.EndpointIP.String()
|
||||||
|
a.EndpointIPv6 = h.EndpointIPv6.String()
|
||||||
a.FirewallInUse = h.FirewallInUse
|
a.FirewallInUse = h.FirewallInUse
|
||||||
a.ID = h.ID.String()
|
a.ID = h.ID.String()
|
||||||
a.Interfaces = make([]ApiIface, len(h.Interfaces))
|
a.Interfaces = make([]ApiIface, len(h.Interfaces))
|
||||||
|
|
@ -83,6 +85,11 @@ func (a *ApiHost) ConvertAPIHostToNMHost(currentHost *Host) *Host {
|
||||||
} else {
|
} else {
|
||||||
h.EndpointIP = net.ParseIP(a.EndpointIP)
|
h.EndpointIP = net.ParseIP(a.EndpointIP)
|
||||||
}
|
}
|
||||||
|
if len(a.EndpointIPv6) == 0 || strings.Contains(a.EndpointIPv6, "nil") {
|
||||||
|
h.EndpointIPv6 = currentHost.EndpointIPv6
|
||||||
|
} else {
|
||||||
|
h.EndpointIPv6 = net.ParseIP(a.EndpointIPv6)
|
||||||
|
}
|
||||||
h.Debug = a.Debug
|
h.Debug = a.Debug
|
||||||
h.FirewallInUse = a.FirewallInUse
|
h.FirewallInUse = a.FirewallInUse
|
||||||
h.IPForwarding = currentHost.IPForwarding
|
h.IPForwarding = currentHost.IPForwarding
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ type Host struct {
|
||||||
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
|
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
|
||||||
DefaultInterface string `json:"defaultinterface" yaml:"defaultinterface"`
|
DefaultInterface string `json:"defaultinterface" yaml:"defaultinterface"`
|
||||||
EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
|
EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
|
||||||
|
EndpointIPv6 net.IP `json:"endpointipv6" yaml:"endpointipv6"`
|
||||||
IsDocker bool `json:"isdocker" yaml:"isdocker"`
|
IsDocker bool `json:"isdocker" yaml:"isdocker"`
|
||||||
IsK8S bool `json:"isk8s" yaml:"isk8s"`
|
IsK8S bool `json:"isk8s" yaml:"isk8s"`
|
||||||
IsStatic bool `json:"isstatic" yaml:"isstatic"`
|
IsStatic bool `json:"isstatic" yaml:"isstatic"`
|
||||||
|
|
|
||||||
|
|
@ -282,9 +282,11 @@ func HandleHostCheckin(h, currentHost *models.Host) bool {
|
||||||
!h.EndpointIP.Equal(currentHost.EndpointIP) ||
|
!h.EndpointIP.Equal(currentHost.EndpointIP) ||
|
||||||
(len(h.NatType) > 0 && h.NatType != currentHost.NatType) ||
|
(len(h.NatType) > 0 && h.NatType != currentHost.NatType) ||
|
||||||
h.DefaultInterface != currentHost.DefaultInterface ||
|
h.DefaultInterface != currentHost.DefaultInterface ||
|
||||||
(h.ListenPort != 0 && h.ListenPort != currentHost.ListenPort) || (h.WgPublicListenPort != 0 && h.WgPublicListenPort != currentHost.WgPublicListenPort)
|
(h.ListenPort != 0 && h.ListenPort != currentHost.ListenPort) ||
|
||||||
|
(h.WgPublicListenPort != 0 && h.WgPublicListenPort != currentHost.WgPublicListenPort) || (!h.EndpointIPv6.Equal(currentHost.EndpointIPv6))
|
||||||
if ifaceDelta { // only save if something changes
|
if ifaceDelta { // only save if something changes
|
||||||
currentHost.EndpointIP = h.EndpointIP
|
currentHost.EndpointIP = h.EndpointIP
|
||||||
|
currentHost.EndpointIPv6 = h.EndpointIPv6
|
||||||
currentHost.Interfaces = h.Interfaces
|
currentHost.Interfaces = h.Interfaces
|
||||||
currentHost.DefaultInterface = h.DefaultInterface
|
currentHost.DefaultInterface = h.DefaultInterface
|
||||||
currentHost.NatType = h.NatType
|
currentHost.NatType = h.NatType
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue