MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / validateEditableNetworkConfig

Function validateEditableNetworkConfig

internal/ui/components/vm_config.go:833–880  ·  view source on GitHub ↗
(vmType, interfaceKey string, cfg editableNetworkConfig)

Source from the content-addressed store, hash-verified

831}
832
833func validateEditableNetworkConfig(vmType, interfaceKey string, cfg editableNetworkConfig) error {
834 if strings.TrimSpace(cfg.Bridge) == "" {
835 return fmt.Errorf("%s: bridge is required", interfaceKey)
836 }
837 if !isValidBridgeName(cfg.Bridge) {
838 return fmt.Errorf("%s: bridge contains invalid characters", interfaceKey)
839 }
840 if cfg.MACAddr != "" && !isValidMACAddress(cfg.MACAddr) {
841 return fmt.Errorf("%s: invalid MAC address format", interfaceKey)
842 }
843 if cfg.VLAN != "" {
844 if err := validateVLANTag(cfg.VLAN); err != nil {
845 return fmt.Errorf("%s: %v", interfaceKey, err)
846 }
847 }
848 if cfg.Rate != "" {
849 if err := validateRateLimit(cfg.Rate); err != nil {
850 return fmt.Errorf("%s: %v", interfaceKey, err)
851 }
852 }
853 if cfg.ExtraRawCSV != "" {
854 if err := validateExtraNetworkTokens(cfg.ExtraRawCSV); err != nil {
855 return fmt.Errorf("%s: invalid extra field: %v", interfaceKey, err)
856 }
857 }
858
859 if vmType != api.VMTypeLXC {
860 return nil
861 }
862 if strings.TrimSpace(cfg.Name) == "" {
863 return fmt.Errorf("%s: interface name is required", interfaceKey)
864 }
865 if strings.EqualFold(cfg.IPMode, ipModeStatic) {
866 ipValue := strings.TrimSpace(cfg.IP)
867 if ipValue == "" {
868 return fmt.Errorf("%s: IP/CIDR is required when IP Assignment is Static", interfaceKey)
869 }
870 if !isValidLXCIPv4Config(ipValue) {
871 return fmt.Errorf("%s: invalid IP format, use IPv4/CIDR (example: 192.168.99.24/24)", interfaceKey)
872 }
873 }
874 if cfg.Gateway != "" {
875 if err := validateGateway(cfg.Gateway, cfg.IP); err != nil {
876 return fmt.Errorf("%s: %v", interfaceKey, err)
877 }
878 }
879 return nil
880}
881
882func isValidMACAddress(value string) bool {
883 _, err := net.ParseMAC(strings.TrimSpace(value))

Calls 7

isValidBridgeNameFunction · 0.85
isValidMACAddressFunction · 0.85
validateVLANTagFunction · 0.85
validateRateLimitFunction · 0.85
isValidLXCIPv4ConfigFunction · 0.85
validateGatewayFunction · 0.85

Tested by 1