in network/endpoint.go [108:193]
func GetEndpointInfoFromHostComputeEndpoint(hcnEndpoint *hcn.HostComputeEndpoint, withIpv6 bool) *EndpointInfo {
// Ignore empty MAC, GW, and IP.
macAddr, _ := net.ParseMAC(hcnEndpoint.MacAddress)
var gwAddr net.IP
var gwAddr6 net.IP
var ipAddr4 net.IPNet
var ipAddr6 net.IPNet
if withIpv6 == false {
if len(hcnEndpoint.Routes) > 0 {
gwAddr = net.ParseIP(hcnEndpoint.Routes[0].NextHop)
}
if len(hcnEndpoint.IpConfigurations) > 0 {
ipAddr4.IP = net.ParseIP(hcnEndpoint.IpConfigurations[0].IpAddress)
}
} else {
var ip4found bool
var ip6found bool
for _, addr := range hcnEndpoint.IpConfigurations {
if net.ParseIP(addr.IpAddress).To4() == nil &&
ip6found == false {
ip, mask, _ := net.ParseCIDR(common.GetAddressAsCidr(addr.IpAddress, addr.PrefixLength))
ipAddr6.IP = ip
ipAddr6.Mask = mask.Mask
ip6found = true
} else {
if ip4found == false {
ip, mask, _ := net.ParseCIDR(common.GetAddressAsCidr(addr.IpAddress, addr.PrefixLength))
ipAddr4.IP = ip
ipAddr4.Mask = mask.Mask
ip4found = true
}
}
if ip4found && ip6found {
break
}
}
ip4found = false
ip6found = false
for _, r := range hcnEndpoint.Routes {
if net.ParseIP(r.NextHop).To4() == nil &&
ip6found == false {
gwAddr6 = net.ParseIP(r.NextHop)
ip6found = true
} else {
if ip4found == false {
gwAddr = net.ParseIP(r.NextHop)
ip4found = true
}
}
if ip4found && ip6found {
break
}
}
}
return &EndpointInfo{
Name: hcnEndpoint.Name,
ID: hcnEndpoint.Id,
NetworkID: hcnEndpoint.HostComputeNetwork,
NamespaceID: hcnEndpoint.HostComputeNamespace,
DNS: DNSInfo{
Domain: hcnEndpoint.Dns.Domain,
Search: hcnEndpoint.Dns.Search,
Nameservers: hcnEndpoint.Dns.ServerList,
Options: hcnEndpoint.Dns.Options,
},
MacAddress: macAddr,
Gateway: gwAddr,
IPAddress: ipAddr4.IP,
IP4Mask: ipAddr4.Mask,
Gateway6: gwAddr6,
IPAddress6: ipAddr6,
Policies: GetEndpointPoliciesFromHostComputePolicies(hcnEndpoint.Policies),
}
}