diff --git a/docs/architecture/vue-densemble.rst b/docs/architecture/vue-densemble.rst index a0f5c3f..e589562 100644 --- a/docs/architecture/vue-densemble.rst +++ b/docs/architecture/vue-densemble.rst @@ -39,6 +39,13 @@ Paquets - migrations idempotentes jouées au démarrage de l'agent * - ``internal/vpc``, ``internal/subnet`` - création et suppression bas niveau (netns + netif) + * - ``internal/l3vni`` + - routage d'une VPC par L3VNI : VRF, L3VNI, transit, configuration FRR, export des routes + ``/24`` et ``/32`` + * - ``internal/frr`` + - génération des commandes FRR, seul point d'appel à ``vtysh`` + * - ``internal/sysctl`` + - écriture sous ``/proc/sys``, dans un netns si besoin * - ``internal/netns`` - network namespaces : create/enter/delete/call * - ``internal/netif`` diff --git a/internal/api/agent/vpcs.go b/internal/api/agent/vpcs.go index 1e0ed68..17110d2 100644 --- a/internal/api/agent/vpcs.go +++ b/internal/api/agent/vpcs.go @@ -8,7 +8,7 @@ import ( "strings" dispatcher "git.g3e.fr/syonad/two/internal/dispatcher/agent" - "git.g3e.fr/syonad/two/internal/vpc" + "git.g3e.fr/syonad/two/internal/l3vni" "git.g3e.fr/syonad/two/pkg/db/kv" ) @@ -82,7 +82,7 @@ func (s *Server) postVpc(w http.ResponseWriter, r *http.Request) { } cmd := dispatcher.CreateVPCCommand{Name: req.Name, CIDR: req.CIDR} if req.L3VNI != nil { - if err := vpc.ValidL3VNI(*req.L3VNI); err != nil { + if err := l3vni.Valid(*req.L3VNI); err != nil { w.WriteHeader(http.StatusBadRequest) json.NewEncoder(w).Encode(ErrorResponse{Error: err.Error()}) return diff --git a/internal/dispatcher/agent/vpc_commands.go b/internal/dispatcher/agent/vpc_commands.go index d37c31b..5af1e5e 100644 --- a/internal/dispatcher/agent/vpc_commands.go +++ b/internal/dispatcher/agent/vpc_commands.go @@ -8,6 +8,7 @@ import ( "time" configuration "git.g3e.fr/syonad/two/internal/config/agent" + "git.g3e.fr/syonad/two/internal/l3vni" "git.g3e.fr/syonad/two/internal/state" "git.g3e.fr/syonad/two/internal/vpc" "git.g3e.fr/syonad/two/pkg/db/kv" @@ -46,7 +47,7 @@ func (c CreateVPCCommand) Prepare(db *badger.DB, cfg *configuration.Config) erro } func (c CreateVPCCommand) checkL3VNI(db *badger.DB, cfg *configuration.Config) error { - if err := vpc.ValidL3VNI(c.L3VNI); err != nil { + if err := l3vni.Valid(c.L3VNI); err != nil { return err } if cfg == nil || !cfg.BGP.Enabled() { diff --git a/internal/frr/config.go b/internal/frr/config.go index 2ebad5e..e63df1e 100644 --- a/internal/frr/config.go +++ b/internal/frr/config.go @@ -4,9 +4,9 @@ import ( "fmt" "net" "strings" -) -const maxVNI = 1<<24 - 1 + "git.g3e.fr/syonad/two/internal/netif" +) type Base struct { ASN uint32 @@ -116,7 +116,7 @@ func (v VRF) validate() error { if err := v.validateName(); err != nil { return err } - if v.L3VNI == 0 || v.L3VNI > maxVNI { + if v.L3VNI == 0 || v.L3VNI > netif.MaxVNI { return fmt.Errorf("frr: l3vni %d does not fit in 24 bits", v.L3VNI) } if v.VTEP.To4() == nil { diff --git a/internal/vpc/host.go b/internal/l3vni/host.go similarity index 99% rename from internal/vpc/host.go rename to internal/l3vni/host.go index 37a1720..35e8818 100644 --- a/internal/vpc/host.go +++ b/internal/l3vni/host.go @@ -1,4 +1,4 @@ -package vpc +package l3vni import ( "net" diff --git a/internal/vpc/l3.go b/internal/l3vni/l3.go similarity index 90% rename from internal/vpc/l3.go rename to internal/l3vni/l3.go index 79b2088..a36f423 100644 --- a/internal/vpc/l3.go +++ b/internal/l3vni/l3.go @@ -1,4 +1,4 @@ -package vpc +package l3vni import ( "fmt" @@ -7,6 +7,7 @@ import ( configuration "git.g3e.fr/syonad/two/internal/config/agent" "git.g3e.fr/syonad/two/internal/frr" + "git.g3e.fr/syonad/two/internal/netif" "git.g3e.fr/syonad/two/pkg/db/kv" "github.com/dgraph-io/badger/v4" @@ -35,7 +36,7 @@ func loadL3(db *badger.DB, name, id string) (l3VPC, bool, error) { if err != nil { return l3VPC{}, false, fmt.Errorf("vpc %q: invalid l3vni %q", name, raw) } - if err := ValidL3VNI(uint32(vni)); err != nil { + if err := Valid(uint32(vni)); err != nil { return l3VPC{}, false, fmt.Errorf("vpc %q: %w", name, err) } cidr, err := kv.GetFromDB(db, "vpc/"+name+"/cidr") @@ -55,14 +56,6 @@ func (v l3VPC) vxlan() string { return "vxl3-" + v.id } func (v l3VPC) vethHost() string { return "l3-" + v.id + "-o" } func (v l3VPC) vethNetns() string { return "l3-" + v.id + "-i" } -func routerMAC(vtep net.IP) (net.HardwareAddr, error) { - ip := vtep.To4() - if ip == nil { - return nil, fmt.Errorf("vtep %v is not an IPv4 address", vtep) - } - return net.HardwareAddr{0x02, 0x02, ip[0], ip[1], ip[2], ip[3]}, nil -} - func bgpASN(cfg *configuration.Config) (uint32, error) { if cfg == nil || !cfg.BGP.Enabled() { return 0, fmt.Errorf("the vpc has an l3vni but the agent configuration has no bgp section") @@ -79,7 +72,7 @@ func createL3(h host, cfg *configuration.Config, v l3VPC) error { if err != nil { return fmt.Errorf("vtep: %w", err) } - rmac, err := routerMAC(vtep) + rmac, err := RouterMAC(vtep) if err != nil { return err } @@ -138,6 +131,22 @@ func deleteL3(h host, cfg *configuration.Config, v l3VPC) error { return nil } +func Create(db *badger.DB, vpcName string, cfg *configuration.Config) error { + v, ok, err := loadRouted(db, vpcName) + if err != nil || !ok { + return err + } + return createL3(newSystem(), cfg, v) +} + +func Delete(db *badger.DB, vpcName string, cfg *configuration.Config) error { + v, ok, err := loadRouted(db, vpcName) + if err != nil || !ok { + return err + } + return deleteL3(newSystem(), cfg, v) +} + type Routing struct { VNI uint32 Supernet *net.IPNet @@ -165,5 +174,5 @@ func LoadRouting(db *badger.DB, vpcName string) (Routing, bool, error) { } func RouterMAC(vtep net.IP) (net.HardwareAddr, error) { - return routerMAC(vtep) + return netif.HostMAC(netif.RoleRouter, vtep) } diff --git a/internal/vpc/l3_test.go b/internal/l3vni/l3_test.go similarity index 97% rename from internal/vpc/l3_test.go rename to internal/l3vni/l3_test.go index a56fad9..9838a09 100644 --- a/internal/vpc/l3_test.go +++ b/internal/l3vni/l3_test.go @@ -1,4 +1,4 @@ -package vpc +package l3vni import ( "errors" @@ -220,11 +220,11 @@ func TestDeleteL3RequiresTheBGPSection(t *testing.T) { } func TestRouterMAC(t *testing.T) { - mac, err := routerMAC(net.ParseIP("192.168.14.11")) + mac, err := RouterMAC(net.ParseIP("192.168.14.11")) if err != nil || mac.String() != "02:02:c0:a8:0e:0b" { - t.Errorf("routerMAC = %v, %v", mac, err) + t.Errorf("RouterMAC = %v, %v", mac, err) } - if _, err := routerMAC(net.ParseIP("fd00::1")); err == nil { + if _, err := RouterMAC(net.ParseIP("fd00::1")); err == nil { t.Error("VTEP IPv6 accepté") } } diff --git a/internal/vpc/l3vni.go b/internal/l3vni/l3vni.go similarity index 60% rename from internal/vpc/l3vni.go rename to internal/l3vni/l3vni.go index eddf26d..60b3164 100644 --- a/internal/vpc/l3vni.go +++ b/internal/l3vni/l3vni.go @@ -1,12 +1,14 @@ -package vpc +package l3vni -import "fmt" +import ( + "fmt" -const maxL3VNI = 1<<24 - 1 + "git.g3e.fr/syonad/two/internal/netif" +) -func ValidL3VNI(id uint32) error { - if id == 0 || id > maxL3VNI { - return fmt.Errorf("l3vni %d does not fit in 24 bits (1-%d)", id, maxL3VNI) +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 >= 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 new file mode 100644 index 0000000..0e35e11 --- /dev/null +++ b/internal/l3vni/l3vni_test.go @@ -0,0 +1,29 @@ +package l3vni + +import ( + "strings" + "testing" +) + +func TestValid_AcceptsEvery24BitValueOutsideTheKernelTables(t *testing.T) { + for _, id := range []uint32{1, 252, 256, 4001, 16777215} { + if err := Valid(id); err != nil { + t.Errorf("Valid(%d) = %v", id, err) + } + } +} + +func TestValid_RejectsOutOfRangeAndReservedTables(t *testing.T) { + cases := map[uint32]string{ + 0: "does not fit in 24 bits", + 16777216: "does not fit in 24 bits", + 253: "is reserved", + 254: "is reserved", + 255: "is reserved", + } + for id, want := range cases { + if err := Valid(id); err == nil || !strings.Contains(err.Error(), want) { + t.Errorf("Valid(%d) = %v, attendu %q", id, err, want) + } + } +} diff --git a/internal/vpc/route.go b/internal/l3vni/route.go similarity index 98% rename from internal/vpc/route.go rename to internal/l3vni/route.go index 3b5da19..333abf6 100644 --- a/internal/vpc/route.go +++ b/internal/l3vni/route.go @@ -1,4 +1,4 @@ -package vpc +package l3vni import ( "fmt" diff --git a/internal/vpc/route_test.go b/internal/l3vni/route_test.go similarity index 99% rename from internal/vpc/route_test.go rename to internal/l3vni/route_test.go index ded011a..0377f68 100644 --- a/internal/vpc/route_test.go +++ b/internal/l3vni/route_test.go @@ -1,4 +1,4 @@ -package vpc +package l3vni import ( "errors" diff --git a/internal/netif/mac.go b/internal/netif/mac.go new file mode 100644 index 0000000..ba8300c --- /dev/null +++ b/internal/netif/mac.go @@ -0,0 +1,21 @@ +package netif + +import ( + "fmt" + "net" +) + +const ( + locallyAdministered byte = 0x02 + + RoleRouter byte = 0x02 + RoleHostGateway byte = 0x03 +) + +func HostMAC(role byte, vtep net.IP) (net.HardwareAddr, error) { + ip := vtep.To4() + if ip == nil { + return nil, fmt.Errorf("vtep %v is not an IPv4 address", vtep) + } + return net.HardwareAddr{locallyAdministered, role, ip[0], ip[1], ip[2], ip[3]}, nil +} diff --git a/internal/netif/mac_test.go b/internal/netif/mac_test.go new file mode 100644 index 0000000..5230513 --- /dev/null +++ b/internal/netif/mac_test.go @@ -0,0 +1,60 @@ +package netif + +import ( + "net" + "testing" +) + +func TestHostMAC(t *testing.T) { + cases := []struct { + role byte + vtep string + want string + }{ + {RoleHostGateway, "192.168.14.11", "02:03:c0:a8:0e:0b"}, + {RoleHostGateway, "192.168.14.12", "02:03:c0:a8:0e:0c"}, + {RoleHostGateway, "10.0.0.1", "02:03:0a:00:00:01"}, + {RoleRouter, "192.168.14.11", "02:02:c0:a8:0e:0b"}, + } + for _, c := range cases { + got, err := HostMAC(c.role, net.ParseIP(c.vtep)) + if err != nil { + t.Fatalf("rôle %#x, VTEP %s : erreur inattendue %v", c.role, c.vtep, err) + } + if got.String() != c.want { + t.Errorf("rôle %#x, VTEP %s : %s, %s attendu", c.role, c.vtep, got, c.want) + } + } +} + +func TestHostMACIsLocalUnicast(t *testing.T) { + for _, role := range []byte{RoleRouter, RoleHostGateway} { + got, err := HostMAC(role, net.ParseIP("192.168.14.11")) + if err != nil { + t.Fatal(err) + } + if got[0]&0x02 == 0 { + t.Errorf("%s : bit « administrée localement » absent", got) + } + if got[0]&0x01 != 0 { + t.Errorf("%s : MAC de groupe (multicast)", got) + } + } +} + +func TestHostMACRolesDifferOnTheSameHost(t *testing.T) { + if RoleRouter == RoleHostGateway { + t.Fatalf("rôles identiques : %#x", RoleRouter) + } + if RoleRouter != 0x02 || RoleHostGateway != 0x03 { + t.Errorf("rôles %#x / %#x, 0x02 / 0x03 attendus (valeurs publiées dans la doc)", RoleRouter, RoleHostGateway) + } +} + +func TestHostMACRejectsANonIPv4VTEP(t *testing.T) { + for _, vtep := range []net.IP{nil, net.ParseIP("fd00::1")} { + if mac, err := HostMAC(RoleHostGateway, vtep); err == nil { + t.Errorf("VTEP %v accepté : %s", vtep, mac) + } + } +} diff --git a/internal/netif/route_other.go b/internal/netif/route_other.go index 71daec7..dcfd025 100644 --- a/internal/netif/route_other.go +++ b/internal/netif/route_other.go @@ -8,7 +8,7 @@ import ( ) func RouteAdd(_ string, _ *net.IPNet) error { - return nil + return errors.New("not supported on this platform") } func TableRoutesVia(_ int, _ string) ([]*net.IPNet, error) { diff --git a/internal/netif/vxlan.go b/internal/netif/vxlan.go index 81ec3a2..3455aae 100644 --- a/internal/netif/vxlan.go +++ b/internal/netif/vxlan.go @@ -8,6 +8,8 @@ import ( "github.com/vishvananda/netlink" ) +const MaxVNI = 1<<24 - 1 + const ( scopeUniverse = 0 addressSecondary = 0x01 diff --git a/internal/subnet/create.go b/internal/subnet/create.go index e70fd47..4c7d79b 100644 --- a/internal/subnet/create.go +++ b/internal/subnet/create.go @@ -8,10 +8,10 @@ import ( "git.g3e.fr/syonad/two/internal/dhcp" "git.g3e.fr/syonad/two/internal/dhcpbackend" "git.g3e.fr/syonad/two/internal/ebtables" + "git.g3e.fr/syonad/two/internal/l3vni" "git.g3e.fr/syonad/two/internal/netif" "git.g3e.fr/syonad/two/internal/netns" "git.g3e.fr/syonad/two/internal/state" - "git.g3e.fr/syonad/two/internal/vpc" "github.com/dgraph-io/badger/v4" ) @@ -40,7 +40,7 @@ func CreateSubnet(db *badger.DB, subnetName string, cfg *configuration.Config) e } if d.mode == ModeVxlan { - if err := vpc.ExportRoute(db, d.vpc, d.cidr); err != nil { + if err := l3vni.ExportRoute(db, d.vpc, d.cidr); err != nil { return err } } @@ -80,7 +80,7 @@ func createSubnet(db *badger.DB, subnetName string, d subnetData, backend dhcpba if err != nil { return fmt.Errorf("vtep of %s: %w", d.localIface, err) } - if gatewayMAC, err = hostGatewayMAC(vtep); err != nil { + if gatewayMAC, err = netif.HostMAC(netif.RoleHostGateway, vtep); err != nil { return err } } diff --git a/internal/subnet/delete.go b/internal/subnet/delete.go index 8ad0b3d..8ee4d78 100644 --- a/internal/subnet/delete.go +++ b/internal/subnet/delete.go @@ -6,10 +6,10 @@ import ( configuration "git.g3e.fr/syonad/two/internal/config/agent" "git.g3e.fr/syonad/two/internal/dhcpbackend" "git.g3e.fr/syonad/two/internal/ebtables" + "git.g3e.fr/syonad/two/internal/l3vni" "git.g3e.fr/syonad/two/internal/netif" "git.g3e.fr/syonad/two/internal/netns" "git.g3e.fr/syonad/two/internal/state" - "git.g3e.fr/syonad/two/internal/vpc" "git.g3e.fr/syonad/two/pkg/db/kv" "github.com/dgraph-io/badger/v4" @@ -35,7 +35,7 @@ func DeleteSubnet(db *badger.DB, subnetName string, cfg *configuration.Config) e } if d.mode == ModeVxlan { - if err := vpc.WithdrawRoute(db, d.vpc, d.cidr); err != nil { + if err := l3vni.WithdrawRoute(db, d.vpc, d.cidr); err != nil { return err } } diff --git a/internal/subnet/gateway.go b/internal/subnet/gateway.go deleted file mode 100644 index 4d3c37a..0000000 --- a/internal/subnet/gateway.go +++ /dev/null @@ -1,19 +0,0 @@ -package subnet - -import ( - "fmt" - "net" -) - -const ( - roleHostGateway = 0x03 - locallyAdministered = 0x02 -) - -func hostGatewayMAC(vtep net.IP) (net.HardwareAddr, error) { - ip := vtep.To4() - if ip == nil { - return nil, fmt.Errorf("vtep %v is not an IPv4 address", vtep) - } - return net.HardwareAddr{locallyAdministered, roleHostGateway, ip[0], ip[1], ip[2], ip[3]}, nil -} diff --git a/internal/subnet/gateway_test.go b/internal/subnet/gateway_test.go deleted file mode 100644 index 55f7c8b..0000000 --- a/internal/subnet/gateway_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package subnet - -import ( - "net" - "testing" -) - -func TestHostGatewayMAC(t *testing.T) { - cases := map[string]string{ - "192.168.14.11": "02:03:c0:a8:0e:0b", - "192.168.14.12": "02:03:c0:a8:0e:0c", - "10.0.0.1": "02:03:0a:00:00:01", - } - for vtep, want := range cases { - got, err := hostGatewayMAC(net.ParseIP(vtep)) - if err != nil { - t.Fatalf("VTEP %s : erreur inattendue %v", vtep, err) - } - if got.String() != want { - t.Errorf("VTEP %s : %s, %s attendu", vtep, got, want) - } - } -} - -func TestHostGatewayMACIsLocalUnicast(t *testing.T) { - got, err := hostGatewayMAC(net.ParseIP("192.168.14.11")) - if err != nil { - t.Fatal(err) - } - if got[0]&0x02 == 0 { - t.Errorf("%s : bit « administrée localement » absent", got) - } - if got[0]&0x01 != 0 { - t.Errorf("%s : MAC de groupe (multicast)", got) - } -} - -func TestHostGatewayMACDiffersFromTheRouterMACOfTheSameHost(t *testing.T) { - got, _ := hostGatewayMAC(net.ParseIP("192.168.14.11")) - if got.String() == "02:02:c0:a8:0e:0b" { - t.Errorf("%s : même MAC que la RMAC du L3VNI de cet hôte", got) - } -} - -func TestHostGatewayMACRejectsANonIPv4VTEP(t *testing.T) { - for _, vtep := range []net.IP{nil, net.ParseIP("fd00::1")} { - if mac, err := hostGatewayMAC(vtep); err == nil { - t.Errorf("VTEP %v accepté : %s", vtep, mac) - } - } -} diff --git a/internal/vm/create.go b/internal/vm/create.go index 1896b81..1318750 100644 --- a/internal/vm/create.go +++ b/internal/vm/create.go @@ -10,12 +10,12 @@ import ( configuration "git.g3e.fr/syonad/two/internal/config/agent" "git.g3e.fr/syonad/two/internal/dhcpbackend" "git.g3e.fr/syonad/two/internal/iptables" + "git.g3e.fr/syonad/two/internal/l3vni" "git.g3e.fr/syonad/two/internal/metadata" "git.g3e.fr/syonad/two/internal/netif" "git.g3e.fr/syonad/two/internal/netns" "git.g3e.fr/syonad/two/internal/qemu" "git.g3e.fr/syonad/two/internal/state" - "git.g3e.fr/syonad/two/internal/vpc" "github.com/dgraph-io/badger/v4" ) @@ -112,7 +112,7 @@ func StartVM(db *badger.DB, name string, cfg *configuration.Config) error { return fmt.Errorf("start qemu: %w", err) } - if err := applyHostRoutes(db, d, vpc.ExportRoute); err != nil { + if err := applyHostRoutes(db, d, l3vni.ExportRoute); err != nil { return err } diff --git a/internal/vm/delete.go b/internal/vm/delete.go index 12651fb..304a75d 100644 --- a/internal/vm/delete.go +++ b/internal/vm/delete.go @@ -9,12 +9,12 @@ import ( configuration "git.g3e.fr/syonad/two/internal/config/agent" "git.g3e.fr/syonad/two/internal/dhcpbackend" "git.g3e.fr/syonad/two/internal/iptables" + "git.g3e.fr/syonad/two/internal/l3vni" "git.g3e.fr/syonad/two/internal/metadata" "git.g3e.fr/syonad/two/internal/netif" "git.g3e.fr/syonad/two/internal/netns" "git.g3e.fr/syonad/two/internal/qmp" "git.g3e.fr/syonad/two/internal/state" - "git.g3e.fr/syonad/two/internal/vpc" "github.com/dgraph-io/badger/v4" ) @@ -39,7 +39,7 @@ func StopVM(db *badger.DB, name string, cfg *configuration.Config) error { return err } - if err := applyHostRoutes(db, d, vpc.WithdrawRoute); err != nil { + if err := applyHostRoutes(db, d, l3vni.WithdrawRoute); err != nil { return err } diff --git a/internal/vpc/create.go b/internal/vpc/create.go index a7f5b24..31856d6 100644 --- a/internal/vpc/create.go +++ b/internal/vpc/create.go @@ -4,6 +4,7 @@ import ( "strings" configuration "git.g3e.fr/syonad/two/internal/config/agent" + "git.g3e.fr/syonad/two/internal/l3vni" "git.g3e.fr/syonad/two/internal/netif" "git.g3e.fr/syonad/two/internal/netns" "git.g3e.fr/syonad/two/internal/state" @@ -49,15 +50,9 @@ func CreateVPC(db *badger.DB, name string, cfg *configuration.Config) error { }); err != nil { return err } - l3, ok, err := loadL3(db, name, vpcID) - if err != nil { + if err := l3vni.Create(db, name, cfg); err != nil { return err } - if ok { - if err := createL3(newSystem(), cfg, l3); err != nil { - return err - } - } return state.Set(db, "vpc/"+name, state.Running) } return nil diff --git a/internal/vpc/delete.go b/internal/vpc/delete.go index 66d6d7a..700429c 100644 --- a/internal/vpc/delete.go +++ b/internal/vpc/delete.go @@ -4,6 +4,7 @@ import ( "strings" configuration "git.g3e.fr/syonad/two/internal/config/agent" + "git.g3e.fr/syonad/two/internal/l3vni" "git.g3e.fr/syonad/two/internal/netif" "git.g3e.fr/syonad/two/internal/netns" "git.g3e.fr/syonad/two/internal/state" @@ -17,15 +18,9 @@ func DeleteVPC(db *badger.DB, name string, cfg *configuration.Config) error { } else if current == state.Deleting { vpcID := strings.SplitN(name, "-", 2)[1] - l3, ok, err := loadL3(db, name, vpcID) - if err != nil { + if err := l3vni.Delete(db, name, cfg); err != nil { return err } - if ok { - if err := deleteL3(newSystem(), cfg, l3); err != nil { - return err - } - } if err := netif.DeleteLink("vp-" + vpcID + "-e"); err != nil { return err diff --git a/internal/vpc/l3vni_test.go b/internal/vpc/l3vni_test.go deleted file mode 100644 index c93c86c..0000000 --- a/internal/vpc/l3vni_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package vpc - -import ( - "strings" - "testing" -) - -func TestValidL3VNI_AcceptsEvery24BitValueOutsideTheKernelTables(t *testing.T) { - for _, id := range []uint32{1, 252, 256, 4001, 16777215} { - if err := ValidL3VNI(id); err != nil { - t.Errorf("ValidL3VNI(%d) = %v", id, err) - } - } -} - -func TestValidL3VNI_RejectsOutOfRangeAndReservedTables(t *testing.T) { - cases := map[uint32]string{ - 0: "does not fit in 24 bits", - 16777216: "does not fit in 24 bits", - 253: "is reserved", - 254: "is reserved", - 255: "is reserved", - } - for id, want := range cases { - if err := ValidL3VNI(id); err == nil || !strings.Contains(err.Error(), want) { - t.Errorf("ValidL3VNI(%d) = %v, attendu %q", id, err, want) - } - } -} diff --git a/internal/watchdog/check_l3.go b/internal/watchdog/check_l3.go index 537cf29..0fee453 100644 --- a/internal/watchdog/check_l3.go +++ b/internal/watchdog/check_l3.go @@ -8,10 +8,10 @@ import ( configuration "git.g3e.fr/syonad/two/internal/config/agent" "git.g3e.fr/syonad/two/internal/frr" + "git.g3e.fr/syonad/two/internal/l3vni" "git.g3e.fr/syonad/two/internal/netif" "git.g3e.fr/syonad/two/internal/netns" "git.g3e.fr/syonad/two/internal/state" - "git.g3e.fr/syonad/two/internal/vpc" "git.g3e.fr/syonad/two/internal/watchdog/notify" "git.g3e.fr/syonad/two/pkg/db/kv" @@ -91,7 +91,7 @@ func CheckL3VPCs(db *badger.DB, cfg *configuration.Config, p l3Probe, n notify.N if st, err := state.Get(db, prefixVPC+name); err != nil || st != state.Running { continue } - r, ok, err := vpc.LoadRouting(db, name) + r, ok, err := l3vni.LoadRouting(db, name) if err != nil { n.Notify(kindVPC, name, err.Error()) continue @@ -117,7 +117,7 @@ func expectedRouterMAC(cfg *configuration.Config, p l3Probe, n notify.Notifier) n.Notify(kindBGP, "vtep", fmt.Sprintf("vtep address unreadable on %s: %v", cfg.DefaultInterface, err)) return "unknown" } - mac, err := vpc.RouterMAC(vtep) + mac, err := l3vni.RouterMAC(vtep) if err != nil { n.Notify(kindBGP, "vtep", err.Error()) return "unknown" @@ -125,7 +125,7 @@ func expectedRouterMAC(cfg *configuration.Config, p l3Probe, n notify.Notifier) return mac.String() } -func checkL3VPC(db *badger.DB, name string, r vpc.Routing, rmac string, p l3Probe, n notify.Notifier) { +func checkL3VPC(db *badger.DB, name string, r l3vni.Routing, rmac string, p l3Probe, n notify.Notifier) { for _, iface := range []string{r.VRF, r.Bridge, r.Vxlan, r.VethHost} { if problem := p.LinkProblem("", iface); problem != "" { n.Notify(kindVPC, name, problem)