Skip to content

Node Discovery IPv6 support #218

Description

@tkam8

Summary

The Node Discovery wizard in the frontend fails to accept valid IPv6 addresses, throwing an Invalid IP address: error.

The validation logic in frontend-v2/src/lib/ip-range.ts specifically expects a 4-octet IPv4 format and splits strings using the . character. When an IPv6 address (e.g., 2020:ab1:1010::81) is parsed, it evaluates to null because it uses colons (:) instead of dots,
triggering the validation error.

Severity

Low

Steps to Reproduce

1. Navigate to Build > Projects > Discovery > Node Discovery > Host IP Addresses.
2. Enter a valid IPv6 address (e.g., `2020:ab1:1010::81`).
3. Observe the validation error: `Invalid IP address: 2020:ab1:1010::81`.

Expected Behavior

The wizard should recognize valid IPv6 addresses as acceptable input and not throw an invalid IP error.

Suggested Fix

Update the validation logic in `frontend-v2/src/lib/ip-range.ts` to include regex validation for IPv6 addresses before falling back to the error state. 

Location: frontend-v2/src/lib/ip-range.ts

Code change:

```typescript
// 1. Add this helper function
function isIpv6(value: string): boolean {
  const regexString =
    '^(' +
    '([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|' +
    '([0-9a-fA-F]{1,4}:){1,7}:|' +
    '([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|' +
    '([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|' +
    '([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|' +
    '([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|' +
    '([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|' +
    '[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|' +
    ':((:[0-9a-fA-F]{1,4}){1,7}|:)' +
    ')$';
  return new RegExp(regexString).test(value);
}

// 2. Update expandIpToken to check for either IPv4 or IPv6
export function expandIpToken(token: string): ExpandResult {
  const trimmed = token.trim();
  if (!trimmed) return { ips: [], errors: [] };

  if (!trimmed.includes('-')) {
    if (parseIp(trimmed) !== null || isIpv6(trimmed)) {
      return { ips: [trimmed], errors: [] };
    }
    return { ips: [], errors: [`Invalid IP address: ${trimmed}`] };
  }
  // ... rest of the function for IPv4 ranges
}
```

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions