diff --git a/docs/architecture/vue-densemble.rst b/docs/architecture/vue-densemble.rst index e589562..a0f5c3f 100644 --- a/docs/architecture/vue-densemble.rst +++ b/docs/architecture/vue-densemble.rst @@ -39,13 +39,6 @@ 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 17110d2..1e0ed68 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/l3vni" + "git.g3e.fr/syonad/two/internal/vpc" "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 := l3vni.Valid(*req.L3VNI); err != nil { + if err := vpc.ValidL3VNI(*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 5af1e5e..d37c31b 100644 --- a/internal/dispatcher/agent/vpc_commands.go +++ b/internal/dispatcher/agent/vpc_commands.go @@ -8,7 +8,6 @@ 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" @@ -47,7 +46,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 := l3vni.Valid(c.L3VNI); err != nil { + if err := vpc.ValidL3VNI(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 e63df1e..2ebad5e 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 maxVNI = 1<<24 - 1 + type Base struct { ASN uint32 RouterID net.IP @@ -116,7 +116,7 @@ func (v VRF) validate() error { if err := v.validateName(); err != nil { return err } - if v.L3VNI == 0 || v.L3VNI > netif.MaxVNI { + if v.L3VNI == 0 || v.L3VNI > maxVNI { return fmt.Errorf("frr: l3vni %d does not fit in 24 bits", v.L3VNI) } if v.VTEP.To4() == nil { diff --git a/internal/l3vni/l3vni_test.go b/internal/l3vni/l3vni_test.go deleted file mode 100644 index 0e35e11..0000000 --- a/internal/l3vni/l3vni_test.go +++ /dev/null @@ -1,29 +0,0 @@ -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/netif/mac.go b/internal/netif/mac.go deleted file mode 100644 index ba8300c..0000000 --- a/internal/netif/mac.go +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index 5230513..0000000 --- a/internal/netif/mac_test.go +++ /dev/null @@ -1,60 +0,0 @@ -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 dcfd025..71daec7 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 errors.New("not supported on this platform") + return nil } func TableRoutesVia(_ int, _ string) ([]*net.IPNet, error) { 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/internal/subnet/create.go b/internal/subnet/create.go index 4c7d79b..e70fd47 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 := l3vni.ExportRoute(db, d.vpc, d.cidr); err != nil { + if err := vpc.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 = netif.HostMAC(netif.RoleHostGateway, vtep); err != nil { + if gatewayMAC, err = hostGatewayMAC(vtep); err != nil { return err } } diff --git a/internal/subnet/delete.go b/internal/subnet/delete.go index 8ee4d78..8ad0b3d 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 := l3vni.WithdrawRoute(db, d.vpc, d.cidr); err != nil { + if err := vpc.WithdrawRoute(db, d.vpc, d.cidr); err != nil { return err } } diff --git a/internal/subnet/gateway.go b/internal/subnet/gateway.go new file mode 100644 index 0000000..4d3c37a --- /dev/null +++ b/internal/subnet/gateway.go @@ -0,0 +1,19 @@ +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 new file mode 100644 index 0000000..55f7c8b --- /dev/null +++ b/internal/subnet/gateway_test.go @@ -0,0 +1,51 @@ +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 1318750..1896b81 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, l3vni.ExportRoute); err != nil { + if err := applyHostRoutes(db, d, vpc.ExportRoute); err != nil { return err } diff --git a/internal/vm/delete.go b/internal/vm/delete.go index 304a75d..12651fb 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, l3vni.WithdrawRoute); err != nil { + if err := applyHostRoutes(db, d, vpc.WithdrawRoute); err != nil { return err } diff --git a/internal/vpc/create.go b/internal/vpc/create.go index 31856d6..a7f5b24 100644 --- a/internal/vpc/create.go +++ b/internal/vpc/create.go @@ -4,7 +4,6 @@ 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" @@ -50,9 +49,15 @@ func CreateVPC(db *badger.DB, name string, cfg *configuration.Config) error { }); err != nil { return err } - if err := l3vni.Create(db, name, cfg); err != nil { + l3, ok, err := loadL3(db, name, vpcID) + if 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 700429c..66d6d7a 100644 --- a/internal/vpc/delete.go +++ b/internal/vpc/delete.go @@ -4,7 +4,6 @@ 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" @@ -18,9 +17,15 @@ func DeleteVPC(db *badger.DB, name string, cfg *configuration.Config) error { } else if current == state.Deleting { vpcID := strings.SplitN(name, "-", 2)[1] - if err := l3vni.Delete(db, name, cfg); err != nil { + l3, ok, err := loadL3(db, name, vpcID) + if 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/l3vni/host.go b/internal/vpc/host.go similarity index 99% rename from internal/l3vni/host.go rename to internal/vpc/host.go index 35e8818..37a1720 100644 --- a/internal/l3vni/host.go +++ b/internal/vpc/host.go @@ -1,4 +1,4 @@ -package l3vni +package vpc import ( "net" diff --git a/internal/l3vni/l3.go b/internal/vpc/l3.go similarity index 90% rename from internal/l3vni/l3.go rename to internal/vpc/l3.go index a36f423..79b2088 100644 --- a/internal/l3vni/l3.go +++ b/internal/vpc/l3.go @@ -1,4 +1,4 @@ -package l3vni +package vpc import ( "fmt" @@ -7,7 +7,6 @@ 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" @@ -36,7 +35,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 := Valid(uint32(vni)); err != nil { + if err := ValidL3VNI(uint32(vni)); err != nil { return l3VPC{}, false, fmt.Errorf("vpc %q: %w", name, err) } cidr, err := kv.GetFromDB(db, "vpc/"+name+"/cidr") @@ -56,6 +55,14 @@ 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") @@ -72,7 +79,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 } @@ -131,22 +138,6 @@ 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 @@ -174,5 +165,5 @@ func LoadRouting(db *badger.DB, vpcName string) (Routing, bool, error) { } func RouterMAC(vtep net.IP) (net.HardwareAddr, error) { - return netif.HostMAC(netif.RoleRouter, vtep) + return routerMAC(vtep) } diff --git a/internal/l3vni/l3_test.go b/internal/vpc/l3_test.go similarity index 97% rename from internal/l3vni/l3_test.go rename to internal/vpc/l3_test.go index 9838a09..a56fad9 100644 --- a/internal/l3vni/l3_test.go +++ b/internal/vpc/l3_test.go @@ -1,4 +1,4 @@ -package l3vni +package vpc 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/l3vni/l3vni.go b/internal/vpc/l3vni.go similarity index 60% rename from internal/l3vni/l3vni.go rename to internal/vpc/l3vni.go index 60b3164..eddf26d 100644 --- a/internal/l3vni/l3vni.go +++ b/internal/vpc/l3vni.go @@ -1,14 +1,12 @@ -package l3vni +package vpc -import ( - "fmt" +import "fmt" - "git.g3e.fr/syonad/two/internal/netif" -) +const maxL3VNI = 1<<24 - 1 -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) +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) } 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/vpc/l3vni_test.go b/internal/vpc/l3vni_test.go new file mode 100644 index 0000000..c93c86c --- /dev/null +++ b/internal/vpc/l3vni_test.go @@ -0,0 +1,29 @@ +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/l3vni/route.go b/internal/vpc/route.go similarity index 98% rename from internal/l3vni/route.go rename to internal/vpc/route.go index 333abf6..3b5da19 100644 --- a/internal/l3vni/route.go +++ b/internal/vpc/route.go @@ -1,4 +1,4 @@ -package l3vni +package vpc import ( "fmt" diff --git a/internal/l3vni/route_test.go b/internal/vpc/route_test.go similarity index 99% rename from internal/l3vni/route_test.go rename to internal/vpc/route_test.go index 0377f68..ded011a 100644 --- a/internal/l3vni/route_test.go +++ b/internal/vpc/route_test.go @@ -1,4 +1,4 @@ -package l3vni +package vpc import ( "errors" diff --git a/internal/watchdog/check_l3.go b/internal/watchdog/check_l3.go index 0fee453..537cf29 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 := l3vni.LoadRouting(db, name) + r, ok, err := vpc.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 := l3vni.RouterMAC(vtep) + mac, err := vpc.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 l3vni.Routing, rmac string, p l3Probe, n notify.Notifier) { +func checkL3VPC(db *badger.DB, name string, r vpc.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)