mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
fix: windows ipv6 support (#19279)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -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
@@ -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
@@ -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
|
||||
|
||||
@@ -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, ` )`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user