fix: windows ipv6 support (#19279)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2024-01-17 19:47:25 +08:00
committed by GitHub
parent 847775cfb9
commit 9ca7fb3bf8
4 changed files with 36 additions and 9 deletions
+1 -1
View File
@@ -745,7 +745,7 @@ func (manager *SGuestnetworkManager) GetGuestByAddress(address string, projectId
gnQ = gnQ.Equals(ipField, address)
gnSubQ := gnQ.SubQuery()
q := GuestManager.Query("name", "tenant_id")
q := GuestManager.Query("hostname", "tenant_id")
if len(projectId) > 0 {
q = q.Equals("tenant_id", projectId)
}
+18 -7
View File
@@ -256,6 +256,10 @@ func (r *SRegionDNS) Services(state request.Request, exact bool, opt plugin.Opti
return services, nil
}
if _, ok := DNSTypeMap[state.QType()]; !ok {
return nil, errRefused
}
services, err = r.Records(state, false)
if err != nil {
// log.Errorf("Records %s fail: %s", state.Name(), err)
@@ -286,6 +290,9 @@ func (r *SRegionDNS) Records(state request.Request, exact bool) ([]msg.Service,
}
func (r *SRegionDNS) getHostIpWithName(req *recordRequest) string {
if req.Type() != "A" {
return ""
}
name := req.QueryName()
name = strings.TrimSuffix(name, ".")
host, _ := models.HostManager.FetchByName(nil, name)
@@ -301,13 +308,17 @@ func (r *SRegionDNS) getGuestIpsWithName(req *recordRequest) []string {
name := req.QueryName()
projectId := req.ProjectId()
wantOnlyExit := false
ip4s := models.GuestManager.GetIpsInProjectWithName(projectId, name, wantOnlyExit, api.AddressTypeIPv4)
if len(ip4s) > 0 {
ips = append(ips, ip4s...)
if req.Type() == "A" {
ip4s := models.GuestManager.GetIpsInProjectWithName(projectId, name, wantOnlyExit, api.AddressTypeIPv4)
if len(ip4s) > 0 {
ips = append(ips, ip4s...)
}
}
ip6s := models.GuestManager.GetIpsInProjectWithName(projectId, name, wantOnlyExit, api.AddressTypeIPv6)
if len(ip6s) > 0 {
ips = append(ips, ip6s...)
if req.Type() == "AAAA" {
ip6s := models.GuestManager.GetIpsInProjectWithName(projectId, name, wantOnlyExit, api.AddressTypeIPv6)
if len(ip6s) > 0 {
ips = append(ips, ip6s...)
}
}
return ips
}
@@ -366,7 +377,7 @@ func (r *SRegionDNS) queryLocalDnsRecords(req *recordRequest) []msg.Service {
}
)
recs := make([]msg.Service, 0)
records, err := models.DnsRecordManager.QueryDns(projId, req.Name(), "")
records, err := models.DnsRecordManager.QueryDns(projId, req.Name(), req.Type())
if err != nil {
log.Errorf("QueryDns %s %s error: %v", req.Type(), req.Name(), err)
return nil
+1 -1
View File
@@ -52,7 +52,7 @@ func (r *SRegionDNS) getNameForIp(ip string, state request.Request) ([]msg.Servi
// 2. try guests table
guest := models.GuestnetworkManager.GetGuestByAddress(ip, req.ProjectId())
if guest != nil {
return []msg.Service{{Host: r.joinDomain(guest.Name), TTL: defaultTTL}}, nil
return []msg.Service{{Host: r.joinDomain(guest.Hostname), TTL: defaultTTL}}, nil
}
// 3. try hosts table
+16
View File
@@ -321,6 +321,14 @@ func (w *SWindowsRootFs) DeployNetworkingScripts(rootfs IDiskPartition, nics []*
cfg += fmt.Sprintf(" %s", snic.Gateway)
}
lines = append(lines, cfg)
if len(snic.Ip6) > 0 {
cfg := fmt.Sprintf(` netsh interface ipv6 add address "%%%%b" %s/%d store=persistent`, snic.Ip6, snic.Masklen6)
lines = append(lines, cfg)
if len(snic.Gateway) > 0 && snic.Ip == mainIp {
cfg := fmt.Sprintf(` netsh interface ipv6 add route ::/0 "%%%%b" %s`, snic.Gateway6)
lines = append(lines, cfg)
}
}
routes := [][]string{}
routes = netutils2.AddNicRoutes(routes, snic, mainIp, len(nics))
for _, r := range routes {
@@ -343,6 +351,14 @@ func (w *SWindowsRootFs) DeployNetworkingScripts(rootfs IDiskPartition, nics []*
} else {
lines = append(lines, ` netsh interface ip set address "%%b" dhcp`)
lines = append(lines, ` netsh interface ip set dns "%%b" dhcp`)
if len(snic.Ip6) > 0 {
cfg := fmt.Sprintf(` netsh interface ipv6 add address "%%%%b" %s/%d store=persistent`, snic.Ip6, snic.Masklen6)
lines = append(lines, cfg)
if len(snic.Gateway) > 0 && snic.Ip == mainIp {
cfg := fmt.Sprintf(` netsh interface ipv6 add route ::/0 "%%%%b" %s`, snic.Gateway6)
lines = append(lines, cfg)
}
}
}
lines = append(lines, ` )`)
}