Skip to content

Commit 66d719e

Browse files
Use constants from math package for 2 and 4 byte asn comparison
1 parent f1dca12 commit 66d719e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

internal/webhook/core/v1alpha1/vrf_webhook.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"errors"
99
"fmt"
10+
"math"
1011
"net/netip"
1112
"strconv"
1213
"strings"
@@ -104,7 +105,7 @@ func validateRouteDistinguisher(rd string) error {
104105
}
105106
// type 1 check
106107
if ip, err := netip.ParseAddr(admin); err == nil && ip.Is4() {
107-
if assigned > 65535 {
108+
if assigned > math.MaxUint16 {
108109
return errors.New("type-1 'Assigned Number' is out of range (0–65535)")
109110
}
110111
return nil
@@ -118,16 +119,16 @@ func validateRouteDistinguisher(rd string) error {
118119

119120
// Reserved ASNs
120121
switch asn {
121-
case 0, 65535, 4294967295:
122+
case 0, math.MaxUint16, math.MaxUint32:
122123
return fmt.Errorf("ASN %d is reserved and cannot be used", asn)
123124
}
124125

125126
// type 0: ASN 0–65535 + 32-bit number (0–4294967295) with reserved previously checked
126-
if asn <= 65535 && assigned <= 4294967295 {
127+
if asn <= math.MaxUint16 && assigned <= math.MaxUint32 {
127128
return nil
128129
}
129130
// type 2: ASN 65536–4294967295 + 16-bit number (0–65535) with reserved previously checked
130-
if asn <= 4294967295 && assigned <= 65535 {
131+
if asn <= math.MaxUint32 && assigned <= math.MaxUint16 {
131132
return nil
132133
}
133134

0 commit comments

Comments
 (0)