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

@ -321,11 +321,11 @@ components:
type: integer type: integer
format: int32 format: int32
minimum: 1 minimum: 1
maximum: 16777215 maximum: 65535
description: >- description: >-
Optional. L3VNI of the VPC, used for inter-subnet routing between hypervisors Optional. L3VNI of the VPC, used for inter-subnet routing between hypervisors
(symmetric IRB). Also the id of the routing table of the VPC VRF, so 253-255 are (symmetric IRB). Also the id of the routing table of the VPC VRF, so 253-255 are
rejected. Requires the bgp section in the agent configuration, and must not be used rejected, and the number of the route distinguisher <vtep>:<l3vni>, which holds 16 bits. Requires the bgp section in the agent configuration, and must not be used
by another VPC of the agent. Absent: the VPC has no L3VNI. by another VPC of the agent. Absent: the VPC has no L3VNI.
example: 4001 example: 4001

View file

@ -280,6 +280,7 @@ func TestPostVpc_RejectsAnInvalidL3VNIAsABadRequest(t *testing.T) {
for _, body := range []string{ for _, body := range []string{
`{"name":"vp-1","cidr":"10.0.0.0/16","l3vni":0}`, `{"name":"vp-1","cidr":"10.0.0.0/16","l3vni":0}`,
`{"name":"vp-1","cidr":"10.0.0.0/16","l3vni":255}`, `{"name":"vp-1","cidr":"10.0.0.0/16","l3vni":255}`,
`{"name":"vp-1","cidr":"10.0.0.0/16","l3vni":65536}`,
`{"name":"vp-1","cidr":"10.0.0.0/16","l3vni":16777216}`, `{"name":"vp-1","cidr":"10.0.0.0/16","l3vni":16777216}`,
`{"name":"vp-1","cidr":"10.0.0.0/16","l3vni":-1}`, `{"name":"vp-1","cidr":"10.0.0.0/16","l3vni":-1}`,
} { } {

View file

@ -4,10 +4,10 @@ import (
"fmt" "fmt"
"net" "net"
"strings" "strings"
"git.g3e.fr/syonad/two/internal/netif"
) )
const MaxL3VNI = 1<<16 - 1
type Base struct { type Base struct {
ASN uint32 ASN uint32
RouterID net.IP RouterID net.IP
@ -116,8 +116,8 @@ func (v VRF) validate() error {
if err := v.validateName(); err != nil { if err := v.validateName(); err != nil {
return err return err
} }
if v.L3VNI == 0 || v.L3VNI > netif.MaxVNI { if v.L3VNI == 0 || v.L3VNI > MaxL3VNI {
return fmt.Errorf("frr: l3vni %d does not fit in 24 bits", v.L3VNI) 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 { if v.VTEP.To4() == nil {
return fmt.Errorf("frr: vtep %v is not an IPv4 address", v.VTEP) 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"}, "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"}, "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 nul": {func(v *VRF) { v.L3VNI = 0 }, "l3vni 0 out of range 1-65535"},
"l3vni sur 25 bits": {func(v *VRF) { v.L3VNI = 16777216 }, "l3vni 16777216 does not fit in 24 bits"}, "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 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"}, "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"}, "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 := labVRF(t)
v.L3VNI = 16777215 v.L3VNI = 65535
if err := v.validate(); err != nil { if err := v.validate(); err != nil {
t.Errorf("l3vni 16777215 refusée : %v", err) t.Errorf("l3vni 65535 refusée : %v", err)
} }
} }

View file

@ -3,12 +3,12 @@ package l3vni
import ( import (
"fmt" "fmt"
"git.g3e.fr/syonad/two/internal/netif" "git.g3e.fr/syonad/two/internal/frr"
) )
func Valid(id uint32) error { func Valid(id uint32) error {
if id == 0 || id > netif.MaxVNI { if id == 0 || id > frr.MaxL3VNI {
return fmt.Errorf("l3vni %d does not fit in 24 bits (1-%d)", id, netif.MaxVNI) return fmt.Errorf("l3vni %d out of range 1-%d: the route distinguisher <vtep>:<l3vni> holds 16 bits", id, frr.MaxL3VNI)
} }
if id >= 253 && id <= 255 { if id >= 253 && id <= 255 {
return fmt.Errorf("l3vni %d is reserved: it is also the routing table id, and tables 253-255 belong to the kernel", id) return fmt.Errorf("l3vni %d is reserved: it is also the routing table id, and tables 253-255 belong to the kernel", id)

View file

@ -5,8 +5,8 @@ import (
"testing" "testing"
) )
func TestValid_AcceptsEvery24BitValueOutsideTheKernelTables(t *testing.T) { func TestValid_AcceptsEvery16BitValueOutsideTheKernelTables(t *testing.T) {
for _, id := range []uint32{1, 252, 256, 4001, 16777215} { for _, id := range []uint32{1, 252, 256, 4001, 65535} {
if err := Valid(id); err != nil { if err := Valid(id); err != nil {
t.Errorf("Valid(%d) = %v", id, err) t.Errorf("Valid(%d) = %v", id, err)
} }
@ -15,8 +15,9 @@ func TestValid_AcceptsEvery24BitValueOutsideTheKernelTables(t *testing.T) {
func TestValid_RejectsOutOfRangeAndReservedTables(t *testing.T) { func TestValid_RejectsOutOfRangeAndReservedTables(t *testing.T) {
cases := map[uint32]string{ cases := map[uint32]string{
0: "does not fit in 24 bits", 0: "out of range 1-65535",
16777216: "does not fit in 24 bits", 65536: "out of range 1-65535",
16777215: "out of range 1-65535",
253: "is reserved", 253: "is reserved",
254: "is reserved", 254: "is reserved",
255: "is reserved", 255: "is reserved",

View file

@ -8,8 +8,6 @@ import (
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
) )
const MaxVNI = 1<<24 - 1
const ( const (
scopeUniverse = 0 scopeUniverse = 0
addressSecondary = 0x01 addressSecondary = 0x01

View file

@ -34,9 +34,10 @@ L3VNI, avec une configuration BGP pilotée par l'agent ; documentation du projet
**Routage inter-subnet entre hyperviseurs : L3VNI (#41)** **Routage inter-subnet entre hyperviseurs : L3VNI (#41)**
- Nouveau champ facultatif `l3vni` sur `POST /vpcs` (1 à 16777215, sauf 253-255 : c'est aussi - Nouveau champ facultatif `l3vni` sur `POST /vpcs` (1 à 65535, sauf 253-255 : c'est aussi
l'identifiant de la table de routage). Absent, le VPC se comporte comme avant. Une L3VNI déjà l'identifiant de la table de routage, et le numéro du RD `<VTEP>:<l3vni>`, sur 16 bits).
portée par un VPC de l'agent est refusée (409), comme un `l3vni` demandé sans section `bgp` Absent, le VPC se comporte comme avant. Une L3VNI déjà portée par un VPC de l'agent est refusée
(409), comme un `l3vni` demandé sans section `bgp`
- Pour un VPC routé, l'agent pose sur l'hyperviseur une VRF (table = L3VNI), un bridge à la MAC de - Pour un VPC routé, l'agent pose sur l'hyperviseur une VRF (table = L3VNI), un bridge à la MAC de
routeur `02:02:<IPv4 du VTEP>`, le VXLAN de la L3VNI, un lien de transit `169.254.0.1/30` ↔ routeur `02:02:<IPv4 du VTEP>`, le VXLAN de la L3VNI, un lien de transit `169.254.0.1/30` ↔
`169.254.0.2/30` vers le netns et la route du `cidr` du VPC dans le netns ; FRR reçoit la VRF, `169.254.0.2/30` vers le netns et la route du `cidr` du VPC dans le netns ; FRR reçoit la VRF,