Skip to content

Commit 3893215

Browse files
swordqiuQiu Jian
andauthored
fix: ipv6-only mode compatibility fixes (#23027)
Co-authored-by: Qiu Jian <[email protected]>
1 parent 4e2c7bf commit 3893215

File tree

31 files changed

+231
-94
lines changed

31 files changed

+231
-94
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ require (
103103
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
104104
yunion.io/x/pkg v1.10.4-0.20250805171825-2431e10f90a9
105105
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1
106-
yunion.io/x/sqlchemy v1.1.3-0.20250531010554-ce98f840b833
106+
yunion.io/x/sqlchemy v1.1.3-0.20250806073422-e37f5197cec0
107107
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
108108
)
109109

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ yunion.io/x/pkg v1.10.4-0.20250805171825-2431e10f90a9 h1:8NuoKUPb3sHigChE6Mz6Nf9
14271427
yunion.io/x/pkg v1.10.4-0.20250805171825-2431e10f90a9/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
14281428
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1 h1:1KJ3YYinydPHpDEQRXdr/T8SYcKZ5Er+m489H+PnaQ4=
14291429
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
1430-
yunion.io/x/sqlchemy v1.1.3-0.20250531010554-ce98f840b833 h1:XTFC1naKYkciCQDLm9izpzHXfTenmmtYsTpVKrsN5hE=
1431-
yunion.io/x/sqlchemy v1.1.3-0.20250531010554-ce98f840b833/go.mod h1:vCIZpqhZ5Jzaq3tFyrti/vv8BijQKtkzSgNT/uH4H5A=
1430+
yunion.io/x/sqlchemy v1.1.3-0.20250806073422-e37f5197cec0 h1:Eha/ywh4foMJm7VJ8ibFOi+WPHacuTWtosAGpOld5vo=
1431+
yunion.io/x/sqlchemy v1.1.3-0.20250806073422-e37f5197cec0/go.mod h1:vCIZpqhZ5Jzaq3tFyrti/vv8BijQKtkzSgNT/uH4H5A=
14321432
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c h1:QuLab2kSRECZRxo4Lo2KcYn6XjQFDGaZ1+x0pYDVVwQ=
14331433
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=

pkg/apis/compute/guests.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,8 @@ type ServerDetachnetworkInput struct {
711711
NetId string `json:"net_id"`
712712
// 通过IP解绑网卡, 优先级高于mac
713713
IpAddr string `json:"ip_addr"`
714+
// 通过IP6 addr解绑网卡, 优先级高于mac
715+
Ip6Addr string `json:"ip6_addr"`
714716
// 通过Mac解绑网卡, 优先级低于ip_addr
715717
Mac string `json:"mac"`
716718
// 解绑后不立即同步配置

pkg/cloudcommon/options/options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ func parseOptions(optStruct interface{}, args []string, configFileName string, s
418418
consts.SetTaskWorkerCount(optionsRef.TaskWorkerCount)
419419
consts.SetLocalTaskWorkerCount(optionsRef.LocalTaskWorkerCount)
420420
consts.SetTaskArchiveThresholdHours(optionsRef.TaskArchiveThresholdHours)
421+
422+
if optionsRef.Address == "0.0.0.0" {
423+
optionsRef.Address = ""
424+
}
421425
}
422426

423427
func (self *BaseOptions) HttpTransportProxyFunc() httputils.TransportProxyFunc {

pkg/compute/models/guest_actions.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,8 +2847,14 @@ func (self *SGuest) PerformDetachnetwork(
28472847
if err != nil {
28482848
return nil, httperrors.NewGeneralError(err)
28492849
}
2850-
} else if len(input.IpAddr) > 0 {
2851-
gn, err := self.GetGuestnetworkByIp(input.IpAddr)
2850+
} else if len(input.IpAddr) > 0 || len(input.Ip6Addr) > 0 {
2851+
var gn *SGuestnetwork
2852+
var err error
2853+
if len(input.IpAddr) > 0 {
2854+
gn, err = self.GetGuestnetworkByIp(input.IpAddr)
2855+
} else if len(input.Ip6Addr) > 0 {
2856+
gn, err = self.GetGuestnetworkByIp6(input.Ip6Addr)
2857+
}
28522858
if err != nil {
28532859
if err == sql.ErrNoRows {
28542860
return nil, httperrors.NewNotFoundError("ip %s not found", input.IpAddr)
@@ -2944,7 +2950,7 @@ func (guest *SGuest) fixDefaultGatewayByNics(ctx context.Context, userCred mccli
29442950
}
29452951
net, _ := nics[i].GetNetwork()
29462952
if net != nil {
2947-
nicList = nicList.Add(nics[i].IpAddr, nics[i].MacAddr, net.GuestGateway)
2953+
nicList = nicList.Add(nics[i].MacAddr, nics[i].IpAddr, net.GuestGateway, nics[i].Ip6Addr, net.GuestGateway6, nics[i].IsDefault)
29482954
}
29492955
}
29502956

pkg/compute/models/guestnetworks.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func (manager *SGuestnetworkManager) newGuestNetwork(
426426
gn.Ifname = ifname
427427
gn.TeamWith = teamWithMac
428428

429-
if isDefault && len(gn.IpAddr) > 0 && len(network.GuestGateway) > 0 {
429+
if isDefault && ((len(gn.IpAddr) > 0 && len(network.GuestGateway) > 0) || (len(gn.Ip6Addr) > 0 && len(network.GuestGateway6) > 0)) {
430430
gn.IsDefault = isDefault
431431
}
432432

@@ -853,10 +853,10 @@ func (gn *SGuestnetwork) ValidateUpdateData(
853853
if err != nil {
854854
return input, errors.Wrapf(err, "GetNetwork")
855855
}
856-
if len(net.GuestGateway) == 0 {
856+
if len(net.GuestGateway) == 0 && len(net.GuestGateway6) == 0 {
857857
return input, errors.Wrap(httperrors.ErrInvalidStatus, "network of default gateway has no gateway")
858858
}
859-
if len(gn.IpAddr) == 0 {
859+
if (len(gn.IpAddr) == 0 || (len(gn.IpAddr) > 0 && len(net.GuestGateway) == 0)) && (len(gn.Ip6Addr) == 0 || (len(gn.Ip6Addr) > 0 && len(net.GuestGateway6) == 0)) {
860860
return input, errors.Wrap(httperrors.ErrInvalidStatus, "nic of default gateway has no ip")
861861
}
862862
}

pkg/compute/models/hosts.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5588,7 +5588,7 @@ func (h *SHost) PerformAddNetif(
55885588
mac := input.Mac
55895589
vlan := input.VlanId
55905590

5591-
wire := input.WireId
5591+
wireId := input.WireId
55925592
if len(input.WireId) > 0 {
55935593
wireObj, err := WireManager.FetchByIdOrName(ctx, userCred, input.WireId)
55945594
if err != nil {
@@ -5598,7 +5598,7 @@ func (h *SHost) PerformAddNetif(
55985598
return nil, errors.Wrap(err, "FetchByIdOrName")
55995599
}
56005600
}
5601-
wire = wireObj.GetId()
5601+
wireId = wireObj.GetId()
56025602
}
56035603
ipAddr := input.IpAddr
56045604
if len(ipAddr) > 0 && !regutils.MatchIP4Addr(ipAddr) {
@@ -5630,25 +5630,25 @@ func (h *SHost) PerformAddNetif(
56305630
}
56315631
}
56325632

5633-
err = h.addNetif(ctx, userCred, mac, vlan, wire, ipAddr, ip6Addr, int(rate), nicType, index, isLinkUp,
5633+
err = h.addNetif(ctx, userCred, mac, vlan, wireId, ipAddr, ip6Addr, int(rate), nicType, index, isLinkUp,
56345634
int16(mtu), reset, netIf, bridge, reserve, requireDesignatedIp, requireIpv6, strictIpv6)
56355635
return nil, errors.Wrap(err, "addNetif")
56365636
}
56375637

56385638
func (h *SHost) addNetif(ctx context.Context, userCred mcclient.TokenCredential,
5639-
mac string, vlanId int, wire string, ipAddr string, ip6Addr string,
5639+
mac string, vlanId int, wireId string, ipAddr string, ip6Addr string,
56405640
rate int, nicType compute.TNicType, index int, linkUp tristate.TriState, mtu int16,
56415641
reset bool, strInterface *string, strBridge *string,
56425642
reserve bool, requireDesignatedIp bool, requireIpv6 bool, strictIpv6 bool,
56435643
) error {
56445644
var sw *SWire
5645-
if len(wire) > 0 {
5646-
iWire, err := WireManager.FetchByIdOrName(ctx, userCred, wire)
5645+
if len(wireId) > 0 {
5646+
iWire, err := WireManager.FetchById(wireId)
56475647
if err != nil {
56485648
if err == sql.ErrNoRows {
5649-
return httperrors.NewResourceNotFoundError2(WireManager.Keyword(), wire)
5649+
return httperrors.NewResourceNotFoundError2(WireManager.Keyword(), wireId)
56505650
} else {
5651-
return httperrors.NewInternalServerError("find Wire %s error: %s", wire, err)
5651+
return httperrors.NewInternalServerError("find Wire %s error: %s", wireId, err)
56525652
}
56535653
}
56545654
sw = iWire.(*SWire)
@@ -5673,7 +5673,7 @@ func (h *SHost) addNetif(ctx context.Context, userCred mcclient.TokenCredential,
56735673
var v4net, v6net *SNetwork
56745674
swNets, err := sw.getNetworks(ctx, userCred, userCred, NetworkManager.AllowScope(userCred))
56755675
if err != nil {
5676-
return httperrors.NewInputParameterError("no networks on wire %s", wire)
5676+
return httperrors.NewInputParameterError("no networks on wire %s", wireId)
56775677
}
56785678
for i := range swNets {
56795679
if v4net == nil && v4addr != nil && swNets[i].IsAddressInRange(*v4addr) {
@@ -5694,7 +5694,7 @@ func (h *SHost) addNetif(ctx context.Context, userCred mcclient.TokenCredential,
56945694
if len(ip6Addr) > 0 {
56955695
addrs = append(addrs, ip6Addr)
56965696
}
5697-
return httperrors.NewBadRequestError("IP %s not attach to wire %s", strings.Join(addrs, ","), wire)
5697+
return httperrors.NewBadRequestError("IP %s not attach to wire %s", strings.Join(addrs, ","), wireId)
56985698
}
56995699
if v4net != nil && v6net != nil && v4net.Id != v6net.Id {
57005700
return httperrors.NewConflictError("IPv4 %s and IPv6 %s must be on the same network", ipAddr, ip6Addr)
@@ -6137,7 +6137,7 @@ func (hh *SHost) attach2Network(
61376137
defer lockman.ReleaseObject(ctx, net)
61386138

61396139
var freeIp4, freeIp6 string
6140-
if (!opt.strictIpv6 || len(ipAddr) > 0) && (bn == nil || bn.IpAddr != ipAddr) {
6140+
if (!opt.strictIpv6 || len(ipAddr) > 0) && (bn == nil || bn.IpAddr != ipAddr) && net.HasIPv4Addr() {
61416141
// allocate ipv4 address
61426142
usedAddrs := net.GetUsedAddresses(ctx)
61436143
if ipAddr != "" {
@@ -6158,7 +6158,7 @@ func (hh *SHost) attach2Network(
61586158
}
61596159
freeIp4 = freeIp
61606160
}
6161-
if (opt.requireIpv6 || len(ip6Addr) > 0) && (bn == nil || bn.Ip6Addr != ip6Addr) {
6161+
if (opt.requireIpv6 || len(ip6Addr) > 0) && (bn == nil || bn.Ip6Addr != ip6Addr) && net.HasIPv6Addr() {
61626162
usedAddrs6 := net.GetUsedAddresses6(ctx)
61636163
if ip6Addr != "" {
61646164
// converted baremetal can resuse related guest network ip

pkg/compute/models/networks.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3966,3 +3966,11 @@ func (net *SNetwork) StartRemoteUpdateTask(ctx context.Context, userCred mcclien
39663966
net.SetStatus(ctx, userCred, apis.STATUS_UPDATE_TAGS, "StartRemoteUpdateTask")
39673967
return task.ScheduleRun(nil)
39683968
}
3969+
3970+
func (net SNetwork) HasIPv4Addr() bool {
3971+
return len(net.GuestIpStart) > 0 && len(net.GuestIpEnd) > 0
3972+
}
3973+
3974+
func (net SNetwork) HasIPv6Addr() bool {
3975+
return len(net.GuestIp6Start) > 0 && len(net.GuestIp6End) > 0
3976+
}

pkg/compute/models/networks_used_addresses_query.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,18 @@ func (manager *SHostnetworkManager) usedAddressQuery(ctx context.Context, args *
103103
baseq = HostnetworkManager.Query().Equals("network_id", args.network.Id).SubQuery()
104104
retq *sqlchemy.SQuery
105105
)
106+
field := "ip_addr"
107+
if args.addrType == api.AddressTypeIPv6 {
108+
field = "ip6_addr"
109+
}
106110
if args.addrOnly {
107111
retq = baseq.Query(
108-
baseq.Field("ip_addr"),
112+
baseq.Field(field),
109113
)
110114
} else {
111115
ownerq := HostManager.FilterByOwner(ctx, HostManager.Query(), HostManager, args.userCred, args.owner, args.scope).SubQuery()
112116
retq = baseq.Query(
113-
baseq.Field("ip_addr"),
117+
baseq.Field(field),
114118
baseq.Field("mac_addr"),
115119
sqlchemy.NewStringField(HostManager.KeywordPlural()).Label("owner_type"),
116120
ownerq.Field("id").Label("owner_id"),

pkg/compute/models/storagecachedimages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ func (manager *SStoragecachedimageManager) Register(ctx context.Context, userCre
468468
}
469469
cachedimage.Status = status
470470

471-
err := manager.TableSpec().InsertOrUpdate(ctx, cachedimage)
471+
err := manager.TableSpec().Insert(ctx, cachedimage)
472472

473473
if err != nil {
474474
log.Errorf("insert error %s", err)

0 commit comments

Comments
 (0)