mirror of
https://github.com/MengMengCode/CLICD.git
synced 2026-08-06 05:52:19 +08:00
修复了一些已知问题
This commit is contained in:
@@ -2385,7 +2385,8 @@ func runKVMSSHScript(client *ssh.Client, script string, description string, time
|
|||||||
var output []byte
|
var output []byte
|
||||||
go func() {
|
go func() {
|
||||||
var err error
|
var err error
|
||||||
output, err = session.CombinedOutput(script)
|
session.Stdin = strings.NewReader(script)
|
||||||
|
output, err = session.CombinedOutput("sh -s")
|
||||||
done <- err
|
done <- err
|
||||||
}()
|
}()
|
||||||
select {
|
select {
|
||||||
@@ -3437,11 +3438,10 @@ func (m *Manager) allocateIPv6ForContainer(id int) (string, int, string, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) allocateIPv6AssignmentsForContainer(id int, requested []string, count int, auto bool) ([]config.IPv6Assignment, error) {
|
func (m *Manager) allocateIPv6AssignmentsForContainer(id int, requested []string, count int, auto bool) ([]config.IPv6Assignment, error) {
|
||||||
if count <= 0 {
|
var err error
|
||||||
count = 1
|
count, err = lxc.NormalizePublicIPAllocationCount(requested, count)
|
||||||
}
|
if err != nil {
|
||||||
if len(requested) > count {
|
return nil, err
|
||||||
count = len(requested)
|
|
||||||
}
|
}
|
||||||
prefixes := lxc.DetectPublicIPv6Prefixes()
|
prefixes := lxc.DetectPublicIPv6Prefixes()
|
||||||
if len(prefixes) == 0 {
|
if len(prefixes) == 0 {
|
||||||
@@ -3483,7 +3483,7 @@ func (m *Manager) allocateIPv6AssignmentsForContainer(id int, requested []string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result := make([]config.IPv6Assignment, 0, count)
|
result := []config.IPv6Assignment{}
|
||||||
selected := map[string]bool{}
|
selected := map[string]bool{}
|
||||||
for _, raw := range requested {
|
for _, raw := range requested {
|
||||||
raw = strings.TrimSpace(raw)
|
raw = strings.TrimSpace(raw)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const ipv6GatewayLinkLocal = "fe80::1"
|
const ipv6GatewayLinkLocal = "fe80::1"
|
||||||
|
const MaxPublicIPAssignments = 64
|
||||||
|
|
||||||
type IPv6PrefixInfo struct {
|
type IPv6PrefixInfo struct {
|
||||||
Interface string `json:"interface"`
|
Interface string `json:"interface"`
|
||||||
@@ -836,11 +837,10 @@ func detectPublicIPv4LocalAddresses() []PublicIPInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AllocatePublicIPv4Assignments(id int, requested []string, count int, auto bool) ([]config.PublicIPv4Assignment, error) {
|
func AllocatePublicIPv4Assignments(id int, requested []string, count int, auto bool) ([]config.PublicIPv4Assignment, error) {
|
||||||
if count <= 0 {
|
var err error
|
||||||
count = 1
|
count, err = NormalizePublicIPAllocationCount(requested, count)
|
||||||
}
|
if err != nil {
|
||||||
if len(requested) > count {
|
return nil, err
|
||||||
count = len(requested)
|
|
||||||
}
|
}
|
||||||
candidates := DetectPublicIPv4Candidates()
|
candidates := DetectPublicIPv4Candidates()
|
||||||
if len(candidates) == 0 {
|
if len(candidates) == 0 {
|
||||||
@@ -866,7 +866,7 @@ func AllocatePublicIPv4Assignments(id int, requested []string, count int, auto b
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make([]config.PublicIPv4Assignment, 0, count)
|
result := []config.PublicIPv4Assignment{}
|
||||||
selected := map[string]bool{}
|
selected := map[string]bool{}
|
||||||
for _, raw := range requested {
|
for _, raw := range requested {
|
||||||
raw = strings.TrimSpace(raw)
|
raw = strings.TrimSpace(raw)
|
||||||
@@ -916,6 +916,22 @@ func AllocatePublicIPv4Assignments(id int, requested []string, count int, auto b
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NormalizePublicIPAllocationCount(requested []string, count int) (int, error) {
|
||||||
|
if len(requested) > MaxPublicIPAssignments {
|
||||||
|
return 0, fmt.Errorf("IP address count cannot exceed %d", MaxPublicIPAssignments)
|
||||||
|
}
|
||||||
|
if count <= 0 {
|
||||||
|
count = 1
|
||||||
|
}
|
||||||
|
if len(requested) > count {
|
||||||
|
count = len(requested)
|
||||||
|
}
|
||||||
|
if count > MaxPublicIPAssignments {
|
||||||
|
return 0, fmt.Errorf("IP address count cannot exceed %d", MaxPublicIPAssignments)
|
||||||
|
}
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
func EnsureAssignedPublicIPv4s(assignments []config.PublicIPv4Assignment) {
|
func EnsureAssignedPublicIPv4s(assignments []config.PublicIPv4Assignment) {
|
||||||
for _, assignment := range assignments {
|
for _, assignment := range assignments {
|
||||||
addr := strings.TrimSpace(assignment.Address)
|
addr := strings.TrimSpace(assignment.Address)
|
||||||
@@ -1210,13 +1226,37 @@ func isTunnelLikeInterface(iface string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func operState(iface string) string {
|
func operState(iface string) string {
|
||||||
data, err := os.ReadFile("/sys/class/net/" + iface + "/operstate")
|
path, err := safeSysClassNetFile(iface, "operstate")
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return strings.TrimSpace(string(data))
|
return strings.TrimSpace(string(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func safeSysClassNetFile(iface string, filename string) (string, error) {
|
||||||
|
iface = strings.TrimSpace(iface)
|
||||||
|
filename = strings.TrimSpace(filename)
|
||||||
|
if iface == "" || filename == "" || len(iface) > 64 || len(filename) > 64 {
|
||||||
|
return "", fmt.Errorf("invalid sysfs network path")
|
||||||
|
}
|
||||||
|
if iface == "." || iface == ".." || filename == "." || filename == ".." {
|
||||||
|
return "", fmt.Errorf("invalid sysfs network path")
|
||||||
|
}
|
||||||
|
if strings.ContainsAny(iface, "/\\\x00") || strings.ContainsAny(filename, "/\\\x00") {
|
||||||
|
return "", fmt.Errorf("invalid sysfs network path")
|
||||||
|
}
|
||||||
|
base := filepath.Clean("/sys/class/net")
|
||||||
|
path := filepath.Clean(filepath.Join(base, iface, filename))
|
||||||
|
if !strings.HasPrefix(path, base+string(os.PathSeparator)) {
|
||||||
|
return "", fmt.Errorf("invalid sysfs network path")
|
||||||
|
}
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
|
||||||
func isPublicIPv4(addr netip.Addr) bool {
|
func isPublicIPv4(addr netip.Addr) bool {
|
||||||
if !addr.IsGlobalUnicast() || addr.IsPrivate() || addr.IsLoopback() || addr.IsLinkLocalUnicast() {
|
if !addr.IsGlobalUnicast() || addr.IsPrivate() || addr.IsLoopback() || addr.IsLinkLocalUnicast() {
|
||||||
return false
|
return false
|
||||||
@@ -1289,11 +1329,10 @@ func (m *Manager) allocateIPv6ForContainer(id int) (string, int, string, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) allocateIPv6AssignmentsForContainer(id int, requested []string, count int, auto bool) ([]config.IPv6Assignment, error) {
|
func (m *Manager) allocateIPv6AssignmentsForContainer(id int, requested []string, count int, auto bool) ([]config.IPv6Assignment, error) {
|
||||||
if count <= 0 {
|
var err error
|
||||||
count = 1
|
count, err = NormalizePublicIPAllocationCount(requested, count)
|
||||||
}
|
if err != nil {
|
||||||
if len(requested) > count {
|
return nil, err
|
||||||
count = len(requested)
|
|
||||||
}
|
}
|
||||||
status := m.DetectIPv6Status()
|
status := m.DetectIPv6Status()
|
||||||
if !status.Available {
|
if !status.Available {
|
||||||
@@ -1336,7 +1375,7 @@ func (m *Manager) allocateIPv6AssignmentsForContainer(id int, requested []string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make([]config.IPv6Assignment, 0, count)
|
result := []config.IPv6Assignment{}
|
||||||
selected := map[string]bool{}
|
selected := map[string]bool{}
|
||||||
for _, raw := range requested {
|
for _, raw := range requested {
|
||||||
raw = strings.TrimSpace(raw)
|
raw = strings.TrimSpace(raw)
|
||||||
|
|||||||
Reference in New Issue
Block a user