f-41: l3vni: borne à 65535 (RD <VTEP>:<l3vni> sur 16 bits) #41

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-12 13:05:14 +02:00
commit 3aa8119335
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
8 changed files with 25 additions and 23 deletions

View file

@ -4,10 +4,10 @@ import (
"fmt"
"net"
"strings"
"git.g3e.fr/syonad/two/internal/netif"
)
const MaxL3VNI = 1<<16 - 1
type Base struct {
ASN uint32
RouterID net.IP
@ -116,8 +116,8 @@ func (v VRF) validate() error {
if err := v.validateName(); err != nil {
return err
}
if v.L3VNI == 0 || v.L3VNI > netif.MaxVNI {
return fmt.Errorf("frr: l3vni %d does not fit in 24 bits", v.L3VNI)
if v.L3VNI == 0 || v.L3VNI > MaxL3VNI {
return fmt.Errorf("frr: l3vni %d out of range 1-%d: the route distinguisher <vtep>:<l3vni> holds 16 bits", v.L3VNI, MaxL3VNI)
}
if v.VTEP.To4() == nil {
return fmt.Errorf("frr: vtep %v is not an IPv4 address", v.VTEP)

View file

@ -117,8 +117,9 @@ func TestVRFValidateRejects(t *testing.T) {
}{
"asn nul": {func(v *VRF) { v.ASN = 0 }, "asn must not be 0"},
"id vide": {func(v *VRF) { v.ID = "" }, "vrf id must not be empty"},
"l3vni nul": {func(v *VRF) { v.L3VNI = 0 }, "l3vni 0 does not fit in 24 bits"},
"l3vni sur 25 bits": {func(v *VRF) { v.L3VNI = 16777216 }, "l3vni 16777216 does not fit in 24 bits"},
"l3vni nul": {func(v *VRF) { v.L3VNI = 0 }, "l3vni 0 out of range 1-65535"},
"l3vni sur 17 bits": {func(v *VRF) { v.L3VNI = 65536 }, "l3vni 65536 out of range 1-65535"},
"l3vni sur 24 bits": {func(v *VRF) { v.L3VNI = 16777215 }, "l3vni 16777215 out of range 1-65535"},
"vtep absent": {func(v *VRF) { v.VTEP = nil }, "vtep <nil> is not an IPv4 address"},
"vtep IPv6": {func(v *VRF) { v.VTEP = net.ParseIP("fd00::1") }, "vtep fd00::1 is not an IPv4 address"},
"supernet absent": {func(v *VRF) { v.Supernet = nil }, "supernet <nil> is not an IPv4 prefix"},
@ -133,10 +134,10 @@ func TestVRFValidateRejects(t *testing.T) {
}
}
func TestVRFAcceptsTheLargest24BitVNI(t *testing.T) {
func TestVRFAcceptsTheLargest16BitVNI(t *testing.T) {
v := labVRF(t)
v.L3VNI = 16777215
v.L3VNI = 65535
if err := v.validate(); err != nil {
t.Errorf("l3vni 16777215 refusée : %v", err)
t.Errorf("l3vni 65535 refusée : %v", err)
}
}