diff --git a/api/agent.yaml b/api/agent.yaml index e8e5b7c..714b8f6 100644 --- a/api/agent.yaml +++ b/api/agent.yaml @@ -321,11 +321,11 @@ components: type: integer format: int32 minimum: 1 - maximum: 16777215 + maximum: 65535 description: >- 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 - rejected. Requires the bgp section in the agent configuration, and must not be used + rejected, and the number of the route distinguisher :, 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. example: 4001 diff --git a/internal/api/agent/vpc_test.go b/internal/api/agent/vpc_test.go index 626667a..8578b57 100644 --- a/internal/api/agent/vpc_test.go +++ b/internal/api/agent/vpc_test.go @@ -280,6 +280,7 @@ func TestPostVpc_RejectsAnInvalidL3VNIAsABadRequest(t *testing.T) { 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":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":-1}`, } { diff --git a/internal/frr/config.go b/internal/frr/config.go index e63df1e..34e3210 100644 --- a/internal/frr/config.go +++ b/internal/frr/config.go @@ -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 : holds 16 bits", v.L3VNI, MaxL3VNI) } if v.VTEP.To4() == nil { return fmt.Errorf("frr: vtep %v is not an IPv4 address", v.VTEP) diff --git a/internal/frr/config_test.go b/internal/frr/config_test.go index ac30a87..766554a 100644 --- a/internal/frr/config_test.go +++ b/internal/frr/config_test.go @@ -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 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 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) } } diff --git a/internal/l3vni/l3vni.go b/internal/l3vni/l3vni.go index 60b3164..bebfa7b 100644 --- a/internal/l3vni/l3vni.go +++ b/internal/l3vni/l3vni.go @@ -3,12 +3,12 @@ package l3vni import ( "fmt" - "git.g3e.fr/syonad/two/internal/netif" + "git.g3e.fr/syonad/two/internal/frr" ) func Valid(id uint32) error { - if id == 0 || id > netif.MaxVNI { - return fmt.Errorf("l3vni %d does not fit in 24 bits (1-%d)", id, netif.MaxVNI) + if id == 0 || id > frr.MaxL3VNI { + return fmt.Errorf("l3vni %d out of range 1-%d: the route distinguisher : holds 16 bits", id, frr.MaxL3VNI) } 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) diff --git a/internal/l3vni/l3vni_test.go b/internal/l3vni/l3vni_test.go index 0e35e11..ea18bc3 100644 --- a/internal/l3vni/l3vni_test.go +++ b/internal/l3vni/l3vni_test.go @@ -5,8 +5,8 @@ import ( "testing" ) -func TestValid_AcceptsEvery24BitValueOutsideTheKernelTables(t *testing.T) { - for _, id := range []uint32{1, 252, 256, 4001, 16777215} { +func TestValid_AcceptsEvery16BitValueOutsideTheKernelTables(t *testing.T) { + for _, id := range []uint32{1, 252, 256, 4001, 65535} { if err := Valid(id); err != nil { t.Errorf("Valid(%d) = %v", id, err) } @@ -15,8 +15,9 @@ func TestValid_AcceptsEvery24BitValueOutsideTheKernelTables(t *testing.T) { func TestValid_RejectsOutOfRangeAndReservedTables(t *testing.T) { cases := map[uint32]string{ - 0: "does not fit in 24 bits", - 16777216: "does not fit in 24 bits", + 0: "out of range 1-65535", + 65536: "out of range 1-65535", + 16777215: "out of range 1-65535", 253: "is reserved", 254: "is reserved", 255: "is reserved", diff --git a/internal/netif/vxlan.go b/internal/netif/vxlan.go index 3455aae..81ec3a2 100644 --- a/internal/netif/vxlan.go +++ b/internal/netif/vxlan.go @@ -8,8 +8,6 @@ import ( "github.com/vishvananda/netlink" ) -const MaxVNI = 1<<24 - 1 - const ( scopeUniverse = 0 addressSecondary = 0x01 diff --git a/release_notes/0.2.0.md b/release_notes/0.2.0.md index a552911..950937e 100644 --- a/release_notes/0.2.0.md +++ b/release_notes/0.2.0.md @@ -34,9 +34,10 @@ L3VNI, avec une configuration BGP pilotée par l'agent ; documentation du projet **Routage inter-subnet entre hyperviseurs : L3VNI (#41)** -- Nouveau champ facultatif `l3vni` sur `POST /vpcs` (1 à 16777215, sauf 253-255 : c'est aussi - l'identifiant de la table de routage). 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` +- Nouveau champ facultatif `l3vni` sur `POST /vpcs` (1 à 65535, sauf 253-255 : c'est aussi + l'identifiant de la table de routage, et le numéro du RD `:`, sur 16 bits). + 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 routeur `02:02:`, 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,