diff --git a/docs/concepts/modes-reseau.rst b/docs/concepts/modes-reseau.rst index 74031e9..6204e2c 100644 --- a/docs/concepts/modes-reseau.rst +++ b/docs/concepts/modes-reseau.rst @@ -42,11 +42,16 @@ vxlan Le subnet vit dans le netns du VPC. La VM n'est donc **pas joignable depuis l'host** sans route explicite — point à connaître avant de câbler un outil externe dessus. -Le bridge du subnet, qui porte ``interface_ip``, a une **MAC de gateway anycast** calculée depuis -le ``vxlan_id`` : ``02:01:00`` suivi des 24 bits de la VNI (``vxlan_id`` 2811 → -``02:01:00:00:0a:fb``). Elle est identique sur tous les hôtes qui portent le subnet : une VM qui -change d'hôte garde une entrée ARP valide pour sa gateway. Elle n'est posée qu'à la création du -subnet — un subnet créé avant garde la MAC choisie par le noyau jusqu'à sa recréation. +Le bridge du subnet, qui porte ``interface_ip``, a une **MAC de gateway propre à l'hôte**, calculée +depuis son VTEP — l'IPv4 primaire du ``local_iface`` : ``02:03`` suivi des quatre octets de +l'adresse (VTEP ``192.168.14.12`` → ``02:03:c0:a8:0e:0c``). Unique dans le fabric, elle est la +même pour tous les subnets d'un hôte, chacun étant un domaine L2 distinct. Elle n'est posée qu'à la +création du subnet — un subnet créé avant garde la MAC choisie par le noyau jusqu'à sa recréation. + +Une MAC de gateway **identique sur tous les hôtes** (anycast) a été essayée puis retirée : apprise +sur le veth du subnet, elle était annoncée en EVPN par chaque hôte et détectée en double ; et une +gateway ne pouvait plus joindre en L2 une VM d'un autre hôte, la réponse revenant à la gateway +locale de la VM. Le cache ARP d'une VM migrée à chaud est un sujet de la migration, pas du subnet. bridge ------ diff --git a/docs/developpement/lab.rst b/docs/developpement/lab.rst index 2e7a026..638b361 100644 --- a/docs/developpement/lab.rst +++ b/docs/developpement/lab.rst @@ -754,8 +754,8 @@ sortie vaut 1 si une vérification échoue **ou si aucune n'a été faite**. - suite de ``s7``, topologie ``evpn-3hv.yml`` : migration d'une VM de hv1 vers hv2 par l'API, observée depuis hv3 qui n'a pas le subnet : migration simple (VM supprimée puis recréée, ``/24`` comme filet), séquence orchestrée (deux VM de même IP, deux ``/32`` en ECMP, 40 - sources sur 40) ; l'ancien « pire cas » devient un refus (409) ; MAC de gateway anycast non - annoncée en EVPN ; watchdog : ``/32`` orphelin signalé comme trou noir, ``/32`` manquant + sources sur 40) ; l'ancien « pire cas » devient un refus (409) ; MAC de gateway propre à + chaque hôte, sans doublon EVPN ; watchdog : ``/32`` orphelin signalé comme trou noir, ``/32`` manquant signalé - hv1, hv2, hv3, rr1 diff --git a/internal/subnet/create.go b/internal/subnet/create.go index ae31b49..e70fd47 100644 --- a/internal/subnet/create.go +++ b/internal/subnet/create.go @@ -2,6 +2,7 @@ package subnet import ( "fmt" + "net" configuration "git.g3e.fr/syonad/two/internal/config/agent" "git.g3e.fr/syonad/two/internal/dhcp" @@ -73,17 +74,24 @@ func createSubnet(db *badger.DB, subnetName string, d subnetData, backend dhcpba return fmt.Errorf("unknown subnet mode %q", d.mode) } + var gatewayMAC net.HardwareAddr + if d.mode == ModeVxlan { + vtep, err := netif.VTEPAddress(d.localIface) + if err != nil { + return fmt.Errorf("vtep of %s: %w", d.localIface, err) + } + if gatewayMAC, err = hostGatewayMAC(vtep); err != nil { + return err + } + } + if err := netns.Call(d.vpc, func() error { if err := netif.CreateBridge(d.bridge, 1500); err != nil { return fmt.Errorf("create bridge: %w", err) } - if d.mode == ModeVxlan { - mac, err := anycastGatewayMAC(d.vxlanID) - if err != nil { - return err - } - if err := netif.LinkSetHardwareAddr(d.bridge, mac); err != nil { - return fmt.Errorf("set anycast gateway mac %s: %w", mac, err) + if gatewayMAC != nil { + if err := netif.LinkSetHardwareAddr(d.bridge, gatewayMAC); err != nil { + return fmt.Errorf("set gateway mac %s: %w", gatewayMAC, err) } } return netif.BridgeSetMaster(vethI, d.bridge) diff --git a/internal/subnet/gateway.go b/internal/subnet/gateway.go index a61eb11..4d3c37a 100644 --- a/internal/subnet/gateway.go +++ b/internal/subnet/gateway.go @@ -6,14 +6,14 @@ import ( ) const ( - maxVNI = 1<<24 - 1 - roleAnycastGateway = 0x01 + roleHostGateway = 0x03 locallyAdministered = 0x02 ) -func anycastGatewayMAC(vni int) (net.HardwareAddr, error) { - if vni < 0 || vni > maxVNI { - return nil, fmt.Errorf("vxlan_id %d does not fit in 24 bits", vni) +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, roleAnycastGateway, 0x00, byte(vni >> 16), byte(vni >> 8), byte(vni)}, nil + 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 index 2352996..55f7c8b 100644 --- a/internal/subnet/gateway_test.go +++ b/internal/subnet/gateway_test.go @@ -1,31 +1,29 @@ package subnet -import "testing" +import ( + "net" + "testing" +) -func TestAnycastGatewayMAC(t *testing.T) { - cases := []struct { - vni int - want string - }{ - {2811, "02:01:00:00:0a:fb"}, - {0, "02:01:00:00:00:00"}, - {1, "02:01:00:00:00:01"}, - {0x123456, "02:01:00:12:34:56"}, - {maxVNI, "02:01:00:ff:ff:ff"}, +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 _, c := range cases { - got, err := anycastGatewayMAC(c.vni) + for vtep, want := range cases { + got, err := hostGatewayMAC(net.ParseIP(vtep)) if err != nil { - t.Fatalf("VNI %d : erreur inattendue %v", c.vni, err) + t.Fatalf("VTEP %s : erreur inattendue %v", vtep, err) } - if got.String() != c.want { - t.Errorf("VNI %d : %s, %s attendu", c.vni, got, c.want) + if got.String() != want { + t.Errorf("VTEP %s : %s, %s attendu", vtep, got, want) } } } -func TestAnycastGatewayMACIsLocalUnicast(t *testing.T) { - got, err := anycastGatewayMAC(2811) +func TestHostGatewayMACIsLocalUnicast(t *testing.T) { + got, err := hostGatewayMAC(net.ParseIP("192.168.14.11")) if err != nil { t.Fatal(err) } @@ -37,22 +35,17 @@ func TestAnycastGatewayMACIsLocalUnicast(t *testing.T) { } } -func TestAnycastGatewayMACIsIdenticalForTheSameVNIAndDistinctOtherwise(t *testing.T) { - a, _ := anycastGatewayMAC(2811) - b, _ := anycastGatewayMAC(2811) - c, _ := anycastGatewayMAC(2812) - if a.String() != b.String() { - t.Errorf("même VNI, MAC différentes : %s et %s", a, b) - } - if a.String() == c.String() { - t.Errorf("VNI différentes, même MAC : %s", a) +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 TestAnycastGatewayMACRejectsVNIOutside24Bits(t *testing.T) { - for _, vni := range []int{-1, maxVNI + 1} { - if mac, err := anycastGatewayMAC(vni); err == nil { - t.Errorf("VNI %d accepté : %s", vni, mac) +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/test/e2e/scenarios/s8-l3vni-migration.sh b/test/e2e/scenarios/s8-l3vni-migration.sh index 91f15de..f6fe22f 100644 --- a/test/e2e/scenarios/s8-l3vni-migration.sh +++ b/test/e2e/scenarios/s8-l3vni-migration.sh @@ -52,10 +52,10 @@ check "orchestrée, 2 — VM s8-m3 10.242.1.50 sur hv1 pendant que s8-m2 tourne check "hv1 : s8-m3 répond depuis son netns" netns_ping_wait vp-s8 10.242.1.50 NODE on rr1 <<'NODE' -check "rr1 : MAC de gateway anycast de sn-s8s (02:01:00:00:0a:fb), portée par hv1 et hv2, non annoncée en EVPN" sh -c "! vtysh -c 'show bgp l2vpn evpn route type macip' | grep -qi '02:01:00:00:0a:fb'" +check "rr1 : MAC de gateway de sn-s8s propre à chaque hôte, hv1 (02:03:c0:a8:0e:0b) et hv2 (02:03:c0:a8:0e:0c)" sh -c "r=\$(vtysh -c 'show bgp l2vpn evpn route type macip'); echo \"\$r\" | grep -qi '02:03:c0:a8:0e:0b' && echo \"\$r\" | grep -qi '02:03:c0:a8:0e:0c'" NODE on hv1 <<'NODE' -info "hv1 : MAC en double détectées sur la VNI 2811 : $(vtysh -c 'show evpn mac vni 2811 duplicate' 2>&1 | grep -ci '02:01:00' || true)" +check "hv1 : aucune MAC en double sur la VNI 2811" sh -c "! vtysh -c 'show evpn mac vni 2811 duplicate' | grep -qiE '([0-9a-f]{2}:){5}[0-9a-f]{2}'" NODE on hv3 <<'NODE' for i in $(seq 1 30); do [ "$(bgp_paths vp-s8 10.242.1.50/32)" = 2 ] && break; sleep 2; done