diff --git a/api/agent.yaml b/api/agent.yaml index d4a737c..bb3bb10 100644 --- a/api/agent.yaml +++ b/api/agent.yaml @@ -441,7 +441,7 @@ paths: schema: $ref: "#/components/schemas/Error" "409": - description: Floating IP already exists, VM unknown on this agent or not running, no interface of that name on the VM, interface that already has a floating IP, or public IP already used by another floating IP of this agent + description: Floating IP already exists, VM unknown on this agent or not running, no interface of that name on the VM, interface on a public_ip subnet (it carries its public IP itself), interface that already has a floating IP, or public IP already used by another floating IP of this agent content: application/json: schema: @@ -566,8 +566,10 @@ components: description: > Subnet mode. "vxlan" (default): creates a VXLAN tunnel and a host bridge. "bridge": attaches directly to an existing bridge resolved from iface_type in the agent config. - "public_ip": accepted and routed like vxlan for DHCP purposes, but its host network - setup is not implemented yet — creating such a subnet currently fails in Execute. + "public_ip": attached like bridge, but always to the public bridge (interfaces.internet, + br-public when absent); iface_type is ignored. The VMs carry public IPs; the VPC route + keeps interface_ip as next-hop. Several VPCs may use the same range with the same + interface_ip: each has its own subnet, whose name the caller keeps unique on the agent. "vlan" is reserved for future use. enum: [vxlan, bridge, public_ip] default: vxlan diff --git a/docs/concepts/ip-flottante.rst b/docs/concepts/ip-flottante.rst index 869e7b0..72c5fcc 100644 --- a/docs/concepts/ip-flottante.rst +++ b/docs/concepts/ip-flottante.rst @@ -79,4 +79,5 @@ Limites ------- * IPv4 seulement. +* Refusée (409) sur une interface d'un subnet ``public_ip`` : la VM y porte déjà son IP publique. * Une VM qui joint l'IP flottante d'une autre VM passe par les bordures. diff --git a/docs/concepts/modes-reseau.rst b/docs/concepts/modes-reseau.rst index 16ea561..fa42968 100644 --- a/docs/concepts/modes-reseau.rst +++ b/docs/concepts/modes-reseau.rst @@ -18,18 +18,13 @@ annoncées aux VM. - rattachement direct à un bridge existant de l'host, résolu depuis ``iface_type`` - disponible * - ``public_ip`` - - routé comme ``vxlan`` côté DHCP - - **mise en place host non implémentée** — la création échoue à l'exécution + - comme ``bridge``, toujours au bridge public de l'host (``interfaces.internet``) ; la VM + porte son IP publique + - disponible * - ``vlan`` - — - réservé, non implémenté -.. warning:: - - ``public_ip`` est accepté par l'API et traité comme ``vxlan`` pour le DHCP, mais sa - configuration réseau côté host n'existe pas encore : la création part en ``error`` dans - ``Execute``. Ne pas s'appuyer dessus en production. - vxlan ----- @@ -138,6 +133,33 @@ Par conception, une VM ne joint pas le netns d'un autre hôte. Les règles sont suppression du subnet ; une règle déjà absente ne fait pas échouer la suppression. Le watchdog signale les règles manquantes et celles qui ne sont pas de l'agent. +public_ip +--------- + +La VM **porte elle-même une IP publique**, sans NAT. Le subnet est raccordé comme un subnet +``bridge``, mais toujours au **bridge public** de l'host (``interfaces.internet``, ``br-public`` +par défaut) ; ``iface_type`` est ignoré. Le bridge du subnet dans le netns porte +``interface_ip`` ; un veth ``v--e`` le relie au bridge public. Le ``br-public`` propre au +netns n'est pas utilisé. + +Une plage publique (plusieurs /24 cohabitent sur le segment) est partagée par tous les VPC qui en +demandent : **chaque VPC a son propre subnet**, avec la **même** ``interface_ip``, sur un même +hôte comme sur des hôtes différents. Les règles de confinement du mode ``bridge`` sont posées sur +chaque ``v--i`` : une VM ne résout ``interface_ip`` que vers le netns de son VPC (sa +gateway, son DHCP, son DNS et son NTP), et ``interface_ip`` n'est jamais visible sur le segment. + +Le **nom** de chaque subnet est choisi par l'appelant et doit être **unique sur l'hyperviseur** : +l'orchestrateur tient un seul subnet public (``pub-203`` par exemple) et en crée une instance par +VPC (``pub-203a42`` pour ``vp-42``). La partie qui suit le premier tiret sert aux noms d'interface +(``br-``, ``v--e``) : 10 caractères au plus. + +Routes annoncées : la route par défaut vers la ``gateway`` fournie (``default_route: true`` et +``gateway`` obligatoires ensemble), la route du ``cidr`` du VPC vers ``interface_ip``. Le contrôle +de MTU est celui du mode ``bridge``, appliqué au bridge public. Les VM de plages publiques se +joignent directement sur le segment ; le filtrage au port les empêche d'usurper l'IP ou la MAC +d'une autre. Une interface d'un subnet ``public_ip`` ne reçoit pas d':doc:`IP flottante +` (409). + Règles de pont -------------- diff --git a/docs/developpement/lab.rst b/docs/developpement/lab.rst index afc0c8a..f748423 100644 --- a/docs/developpement/lab.rst +++ b/docs/developpement/lab.rst @@ -404,6 +404,10 @@ Générée par ``test/e2e/run.sh --matrice`` à partir des en-têtes ; à régé - IP flottante d'une interface de VM — macvlan fip- sur le br-public du netns, MAC 02:05 + IP publique, NAT 1:1 sans état, routage par source (sortie par l'IP flottante, pas par la passerelle NAT du VPC), entrée neuve depuis le segment public, métadonnées servies, affichage sur la VM, refus 409, détachement, déplacement vers un autre hôte par mobilité MAC - hv1 hv2 hv3 - #88 + * - ``48-subnet-public`` + - subnet public_ip — VM qui porte son IP publique, subnet raccordé au bridge public de l'hôte (iface_type ignoré), même plage et même interface_ip pour plusieurs VPC sur un même hôte et sur deux hôtes, interface_ip invisible sur le segment, gateway et DNS propres à chaque VPC, sortie et entrée sans NAT, usurpation refusée, IP flottante refusée + - hv1 hv2 hv3 + - #89 * - ``51-l3vni`` - routage inter-subnet entre hôtes par L3VNI (IRB symétrique) — VRF, RMAC, exports /24 et /32, RT-5 réfléchies, TTL, isolation par RT, unreachable default dans la VRF, démontage d'un VPC routé - hv1 hv2 diff --git a/docs/exploitation/diagnostic.rst b/docs/exploitation/diagnostic.rst index f06d16e..1cb045f 100644 --- a/docs/exploitation/diagnostic.rst +++ b/docs/exploitation/diagnostic.rst @@ -14,7 +14,8 @@ La ressource part en ``error`` juste après le 202 Cas fréquents : -* subnet en mode ``public_ip`` — la mise en place host n'est pas implémentée, l'échec est attendu ; +* subnet en mode ``public_ip`` dont le nom n'est pas unique sur l'hyperviseur, ou dont la partie + après le premier tiret dépasse 10 caractères (noms d'interface) ; * ``vxlan_id`` déjà utilisé sur l'host ; * bridge cible absent : ``iface_type`` inconnu retombé sur ``default_interface``, lui-même inexistant. diff --git a/internal/api/agent/fip_test.go b/internal/api/agent/fip_test.go index baeb624..ddf9e70 100644 --- a/internal/api/agent/fip_test.go +++ b/internal/api/agent/fip_test.go @@ -17,6 +17,7 @@ func seedRunningVM(t *testing.T, db *badger.DB) { for key, value := range map[string]string{ "vpc/vp-t47/cidr": "10.47.0.0/16", "subnet/sn-a/vpc": "vp-t47", + "subnet/sn-a/mode": "vxlan", "vm/vm-1/state": "running", "vm/vm-1/nic/0/name": "nic-a", "vm/vm-1/nic/0/subnet": "sn-a", diff --git a/internal/dispatcher/agent/fip_commands.go b/internal/dispatcher/agent/fip_commands.go index cd48943..fb59c1c 100644 --- a/internal/dispatcher/agent/fip_commands.go +++ b/internal/dispatcher/agent/fip_commands.go @@ -8,6 +8,7 @@ import ( configuration "git.g3e.fr/syonad/two/internal/config/agent" "git.g3e.fr/syonad/two/internal/fip" "git.g3e.fr/syonad/two/internal/state" + "git.g3e.fr/syonad/two/internal/subnet" "git.g3e.fr/syonad/two/pkg/db/kv" "github.com/dgraph-io/badger/v4" ) @@ -39,9 +40,13 @@ func (c CreateFloatingIPCommand) Prepare(db *badger.DB, _ *configuration.Config) if vmState != state.Running { return fmt.Errorf("vm %q is %s", c.VM, vmState) } - if _, err := fip.Resolve(db, c.VM, c.Interface); err != nil { + target, err := fip.Resolve(db, c.VM, c.Interface) + if err != nil { return err } + if target.Mode == subnet.ModePublicIP { + return fmt.Errorf("interface %q of vm %q is on public_ip subnet %q: it carries its public ip itself", c.Interface, c.VM, target.Subnet) + } others, err := floatingIPs(db) if err != nil { return err diff --git a/internal/dispatcher/agent/fip_commands_test.go b/internal/dispatcher/agent/fip_commands_test.go index de681eb..c5815a3 100644 --- a/internal/dispatcher/agent/fip_commands_test.go +++ b/internal/dispatcher/agent/fip_commands_test.go @@ -12,6 +12,12 @@ func seedVMWithInterfaces(t *testing.T, db *badger.DB, name, st string) { t.Helper() for key, value := range map[string]string{ "vpc/vp-t47/cidr": "10.47.0.0/16", + "subnet/sn-a/mode": "vxlan", + "subnet/sn-p/vpc": "vp-t47", + "subnet/sn-p/mode": "public_ip", + "vm/" + name + "/nic/2/name": "nic-pub", + "vm/" + name + "/nic/2/subnet": "sn-p", + "vm/" + name + "/nic/2/ip": "203.0.113.20", "subnet/sn-a/vpc": "vp-t47", "vm/" + name + "/state": st, "vm/" + name + "/nic/0/name": "nic-a", @@ -71,6 +77,7 @@ func TestCreateFloatingIPCommand_Prepare_Refuses(t *testing.T) { kv.AddInDB(db, "floating-ip/fip-0/interface", "nic-ab") kv.AddInDB(db, "floating-ip/fip-0/ip", "240.0.0.47/24") }, nil, `public ip 240.0.0.47 is already used by floating ip "fip-0"`}, + {"interface sur un subnet public_ip", nil, func(c *CreateFloatingIPCommand) { c.Interface = "nic-pub" }, `interface "nic-pub" of vm "vm-1" is on public_ip subnet "sn-p"`}, {"ip sans préfixe", nil, func(c *CreateFloatingIPCommand) { c.IP = "240.0.0.47" }, `invalid ip "240.0.0.47"`}, {"gateway invalide", nil, func(c *CreateFloatingIPCommand) { c.Gateway = "bordure" }, `invalid gateway "bordure"`}, } diff --git a/internal/dispatcher/agent/mtu_test.go b/internal/dispatcher/agent/mtu_test.go index 2313284..042b2be 100644 --- a/internal/dispatcher/agent/mtu_test.go +++ b/internal/dispatcher/agent/mtu_test.go @@ -86,3 +86,21 @@ func TestCreateVPCCommand_Prepare_L3VNIChecksTheUnderlay(t *testing.T) { t.Errorf("un VPC sans l3vni ne contrôle pas l'underlay : %v", err) } } + +func TestCreateSubnetCommand_Prepare_PublicIPChecksThePublicBridge(t *testing.T) { + withLinkMTU(t, map[string]int{"br-vms": 9000, "br-public": 1499}) + _, db := newTestDispatcher(t) + kv.AddInDB(db, "vpc/vpc-1/state", "running") + cmd := CreateSubnetCommand{Name: "sn-pub", VPC: "vpc-1", Mode: "public_ip", IfaceType: "vms", InterfaceIP: "203.0.113.254", CIDR: "203.0.113.0/24"} + err := cmd.Prepare(db, testCfg()) + if err == nil || !strings.Contains(err.Error(), "br-public") { + t.Fatalf("bridge public à 1499 : %v", err) + } + if _, err := kv.GetFromDB(db, "subnet/sn-pub/state"); err == nil { + t.Error("aucune clé ne doit être écrite après un refus") + } + withLinkMTU(t, map[string]int{"br-public": 1500}) + if err := cmd.Prepare(db, testCfg()); err != nil { + t.Errorf("bridge public à 1500 : %v", err) + } +} diff --git a/internal/dispatcher/agent/subnet_commands.go b/internal/dispatcher/agent/subnet_commands.go index 91f08bc..d6ea147 100644 --- a/internal/dispatcher/agent/subnet_commands.go +++ b/internal/dispatcher/agent/subnet_commands.go @@ -64,12 +64,15 @@ func (c CreateSubnetCommand) Prepare(db *badger.DB, cfg *configuration.Config) e if !ok { localIface = cfg.DefaultInterface } + if c.Mode == subnet.ModePublicIP { + localIface = cfg.PublicBridge() + } switch c.Mode { case subnet.ModeVxlan: if err := checkUnderlay(cfg, localIface); err != nil { return err } - case subnet.ModeBridge: + case subnet.ModeBridge, subnet.ModePublicIP: if err := checkBridge(cfg, localIface); err != nil { return err } diff --git a/internal/dispatcher/agent/subnet_commands_test.go b/internal/dispatcher/agent/subnet_commands_test.go index a2d6cd5..0373d29 100644 --- a/internal/dispatcher/agent/subnet_commands_test.go +++ b/internal/dispatcher/agent/subnet_commands_test.go @@ -391,6 +391,23 @@ func TestCreateSubnetCommand_Prepare_AcceptsPublicIPMode(t *testing.T) { if _, err := kv.GetFromDB(db, "subnet/sn-pub/vxlan_id"); err == nil { t.Error("vxlan_id ne doit être écrit que pour le mode vxlan") } + if got, _ := kv.GetFromDB(db, "subnet/sn-pub/local_iface"); got != "br-public" { + t.Errorf("local_iface %q, br-public attendu malgré iface_type vms", got) + } +} + +func TestCreateSubnetCommand_Prepare_PublicIPFollowsInterfacesInternet(t *testing.T) { + cfg := testCfg() + cfg.Interfaces["internet"] = "br-pub2" + _, db := newTestDispatcher(t) + kv.AddInDB(db, "vpc/vpc-1/state", "running") + cmd := CreateSubnetCommand{Name: "sn-pub", VPC: "vpc-1", Mode: "public_ip", IfaceType: "vms", InterfaceIP: "203.0.113.254", CIDR: "203.0.113.0/24"} + if err := cmd.Prepare(db, cfg); err != nil { + t.Fatal(err) + } + if got, _ := kv.GetFromDB(db, "subnet/sn-pub/local_iface"); got != "br-pub2" { + t.Errorf("local_iface %q, br-pub2 attendu", got) + } } func TestCreateSubnetCommand_Prepare_RejectsUnknownMode(t *testing.T) { diff --git a/internal/fip/fip.go b/internal/fip/fip.go index 69883df..ea6150b 100644 --- a/internal/fip/fip.go +++ b/internal/fip/fip.go @@ -24,6 +24,8 @@ type Target struct { VPC string CIDR *net.IPNet Private net.IP + Subnet string + Mode string } type floatingIP struct { @@ -85,7 +87,11 @@ func Resolve(db *badger.DB, vmName, ifaceName string) (Target, error) { if err != nil { return Target{}, fmt.Errorf("vm %q: interface %q: invalid cidr %q of vpc %q", vmName, ifaceName, raw, vpc) } - return Target{VPC: vpc, CIDR: cidr, Private: ip}, nil + mode, err := kv.GetFromDB(db, "subnet/"+subnet+"/mode") + if err != nil { + return Target{}, fmt.Errorf("vm %q: interface %q: mode of subnet %q: %w", vmName, ifaceName, subnet, err) + } + return Target{VPC: vpc, CIDR: cidr, Private: ip, Subnet: subnet, Mode: mode}, nil } return Target{}, fmt.Errorf("vm %q has no interface %q", vmName, ifaceName) } diff --git a/internal/fip/fip_test.go b/internal/fip/fip_test.go index e889d13..4c4900e 100644 --- a/internal/fip/fip_test.go +++ b/internal/fip/fip_test.go @@ -184,6 +184,8 @@ func seedVM(t *testing.T) *badger.DB { t.Cleanup(func() { db.Close() }) for key, value := range map[string]string{ "vpc/vp-t47/cidr": "10.47.0.0/16", + "subnet/sn-a/mode": "vxlan", + "subnet/sn-b/mode": "public_ip", "subnet/sn-a/vpc": "vp-t47", "subnet/sn-b/vpc": "vp-t47", "vm/vm-1/nic/0/name": "nic-a1b2", @@ -206,7 +208,7 @@ func TestResolveFindsTheInterfaceByName(t *testing.T) { if err != nil { t.Fatal(err) } - if got.VPC != "vp-t47" || got.CIDR.String() != "10.47.0.0/16" || got.Private.String() != "10.47.2.10" { + if got.VPC != "vp-t47" || got.CIDR.String() != "10.47.0.0/16" || got.Private.String() != "10.47.2.10" || got.Subnet != "sn-b" || got.Mode != "public_ip" { t.Errorf("cible %+v", got) } } diff --git a/internal/subnet/create.go b/internal/subnet/create.go index f0ae80a..9d19709 100644 --- a/internal/subnet/create.go +++ b/internal/subnet/create.go @@ -61,9 +61,7 @@ func createSubnet(db *badger.DB, subnetName string, d subnetData, backend dhcpba if err := setupVxlanHost(d, vethE); err != nil { return err } - case ModePublicIP: - return fmt.Errorf("subnet mode %q: host network setup is not implemented yet", d.mode) - case ModeBridge: + case ModeBridge, ModePublicIP: if err := netif.BridgeSetMaster(vethE, d.localIface); err != nil { return fmt.Errorf("add veth-e to bridge: %w", err) } @@ -122,7 +120,7 @@ func createSubnet(db *badger.DB, subnetName string, d subnetData, backend dhcpba }); err != nil { return fmt.Errorf("configure netns: %w", err) } - case d.mode == ModeBridge: + case Bridged(d.mode): if err := netns.Call(d.vpc, func() error { if err := netif.AddrAdd(d.bridge, d.interfaceIP); err != nil { return fmt.Errorf("add addr: %w", err) diff --git a/internal/subnet/delete.go b/internal/subnet/delete.go index e38c224..4ddd357 100644 --- a/internal/subnet/delete.go +++ b/internal/subnet/delete.go @@ -48,7 +48,7 @@ func DeleteSubnet(db *badger.DB, subnetName string, cfg *configuration.Config) e if err := deleteSubnetVxlan(d); err != nil { return err } - case "bridge": + case ModeBridge, ModePublicIP: if err := deleteSubnetBridge(d); err != nil { return err } diff --git a/internal/subnet/mode.go b/internal/subnet/mode.go index cfc61dd..c963251 100644 --- a/internal/subnet/mode.go +++ b/internal/subnet/mode.go @@ -13,3 +13,7 @@ func ValidMode(mode string) bool { } return false } + +func Bridged(mode string) bool { + return mode == ModeBridge || mode == ModePublicIP +} diff --git a/internal/subnet/mode_test.go b/internal/subnet/mode_test.go new file mode 100644 index 0000000..0c7b606 --- /dev/null +++ b/internal/subnet/mode_test.go @@ -0,0 +1,11 @@ +package subnet + +import "testing" + +func TestBridged(t *testing.T) { + for mode, want := range map[string]bool{"bridge": true, "public_ip": true, "vxlan": false, "": false} { + if got := Bridged(mode); got != want { + t.Errorf("%q : %v, %v attendu", mode, got, want) + } + } +} diff --git a/internal/watchdog/check_subnet.go b/internal/watchdog/check_subnet.go index fa20c87..b3d4803 100644 --- a/internal/watchdog/check_subnet.go +++ b/internal/watchdog/check_subnet.go @@ -16,8 +16,9 @@ import ( ) const ( - modeVxlan = "vxlan" - modeBridge = "bridge" + modeVxlan = "vxlan" + modeBridge = "bridge" + modePublicIP = "public_ip" ) func subnetIfaceNames(subnetName string) (hostVeth, nsVeth, bridge string, err error) { @@ -83,7 +84,7 @@ func checkSubnet(db *badger.DB, name string, backend dhcpbackend.Backend, u unit n.Notify(kindSubnet, name, p+" (host)") } checkVxlanIface(db, name, n) - case modeBridge: + case modeBridge, modePublicIP: default: n.Notify(kindSubnet, name, fmt.Sprintf("unknown mode %q", mode)) } @@ -92,7 +93,7 @@ func checkSubnet(db *badger.DB, name string, backend dhcpbackend.Backend, u unit switch mode { case modeVxlan: checkAnycastGateway(db, name, vpc, bridge, n) - case modeBridge: + case modeBridge, modePublicIP: checkBridgeGateway(db, name, vpc, nsVeth, n) } diff --git a/internal/watchdog/check_subnet_test.go b/internal/watchdog/check_subnet_test.go index a94589c..70bc25a 100644 --- a/internal/watchdog/check_subnet_test.go +++ b/internal/watchdog/check_subnet_test.go @@ -132,6 +132,25 @@ func TestCheckSubnets_ModeBridgeNeVerifiePasDeVxlan(t *testing.T) { } } +func TestCheckSubnets_ModePublicIPEstConnuEtSansVxlan(t *testing.T) { + db := newTestDB(t) + seedSubnet(t, db, "pub-203a42", "vp-admin", modePublicIP) + r := &recorder{} + + if err := CheckSubnets(db, dnsmasqConfig(), newFakeUnits(), r); err != nil { + t.Fatalf("erreur inattendue: %v", err) + } + + for _, c := range r.calls { + if strings.Contains(c.problem, "unknown mode") || strings.Contains(c.problem, "vxlan") || strings.Contains(c.problem, "(host)") { + t.Errorf("un subnet public_ip est contrôlé comme bridge : %q", c.problem) + } + } + if !r.hasProblemContaining("vp-admin_br-203a42.conf") { + t.Errorf("témoin : le contrôle DHCP du subnet public_ip doit avoir lieu, obtenu %v", r.calls) + } +} + func TestCheckSubnets_ModeVxlanSansVxlanID(t *testing.T) { db := newTestDB(t) seedSubnet(t, db, "br-000042", "vp-admin", modeVxlan) diff --git a/release_notes/0.3.0.md b/release_notes/0.3.0.md index 5066598..59a3223 100644 --- a/release_notes/0.3.0.md +++ b/release_notes/0.3.0.md @@ -102,6 +102,17 @@ - Déplacer l'IP flottante avec la VM : la supprimer sur l'ancien hôte, la créer sur le nouveau. Les connexions en cours sont perdues +**Subnet public_ip (#89)** + +- Le mode `public_ip` est mis en place : la VM porte son IP publique, sans NAT. Le subnet est + raccordé comme `bridge`, toujours au bridge public de l'hôte (`interfaces.internet`) ; + `iface_type` est ignoré, le contrôle de MTU porte sur le bridge public +- Une plage publique est partagée par plusieurs VPC : chacun a son subnet, avec la **même** + `interface_ip`, confinée à son netns par les règles du mode `bridge` (sur un même hôte comme + entre hôtes). Le nom de chaque subnet est choisi par l'appelant et unique sur l'hyperviseur +- Une IP flottante est refusée (409) sur une interface d'un subnet `public_ip`. Le watchdog + contrôle les subnets `public_ip` comme les subnets `bridge` + ## Correctifs - **Chaque VRF de VPC porte une route `unreachable default` (#81).** Une recherche qui échouait diff --git a/test/e2e/suite/48-subnet-public.sh b/test/e2e/suite/48-subnet-public.sh new file mode 100644 index 0000000..b1f34ce --- /dev/null +++ b/test/e2e/suite/48-subnet-public.sh @@ -0,0 +1,77 @@ +# fonctionnalité: subnet public_ip — VM qui porte son IP publique, subnet raccordé au bridge public de l'hôte (iface_type ignoré), même plage et même interface_ip pour plusieurs VPC sur un même hôte et sur deux hôtes, interface_ip invisible sur le segment, gateway et DNS propres à chaque VPC, sortie et entrée sans NAT, usurpation refusée, IP flottante refusée +# hôtes: hv1 hv2 hv3 +# tickets: #89 + +on hv1 <<'NODE' +KEY=$(vm_key) +pub () { api_post subnets "{\"name\":\"${1}\",\"vpc\":\"${2}\",\"mode\":\"public_ip\",\"iface_type\":\"vms\",\"cidr\":\"240.0.0.0/24\",\"interface_ip\":\"240.0.0.250\",\"default_route\":true,\"gateway\":\"240.0.0.1\"}" && wait_state "subnets/${1}" running; } +check "hv1 : VPC vp-t48a" vpc_create vp-t48a 10.48.0.0/16 +check "hv1 : VPC vp-t48b" vpc_create vp-t48b 10.49.0.0/16 +check "hv1 : subnet public sn-t48a de vp-t48a, 240.0.0.0/24, interface_ip 240.0.0.250" pub sn-t48a vp-t48a +check "hv1 : subnet public sn-t48b de vp-t48b, même plage, même interface_ip" pub sn-t48b vp-t48b +check "hv1 : sn-t48a raccordé au bridge public malgré iface_type vms" test "$(api_field subnets/sn-t48a local_iface)" = br-public +check "hv1 : v-t48a-e et v-t48b-e esclaves de br-public" sh -c "ip -o link show v-t48a-e | grep -q 'master br-public' && ip -o link show v-t48b-e | grep -q 'master br-public'" +for v in a b; do + check "hv1 : 240.0.0.250 sur br-t48${v} dans vp-t48${v}" sh -c "ip -n vp-t48${v} -4 -o addr show dev br-t48${v} | grep -q ' 240.0.0.250/32 '" +done +check "hv1 : VM t48-a 240.0.0.80 dans vp-t48a" vm_create t48-a sn-t48a 240.0.0.80 "${KEY}" +check "hv1 : VM t48-b 240.0.0.81 dans vp-t48b" vm_create t48-b sn-t48b 240.0.0.81 "${KEY}" +check "t48-a joignable" vm_wait vp-t48a 240.0.0.80 +check "t48-b joignable" vm_wait vp-t48b 240.0.0.81 +check "t48-a : route par défaut vers la bordure 240.0.0.1" route_via vp-t48a 240.0.0.80 default 240.0.0.1 +check "t48-a : route du VPC 10.48.0.0/16 via interface_ip" route_via vp-t48a 240.0.0.80 10.48.0.0/16 240.0.0.250 +check "t48-a : DNS et NTP annoncés = 240.0.0.250" sh -c "[ \"\$1\" = 240.0.0.250 ] && [ \"\$2\" = 240.0.0.250 ]" _ "$(vm_lease vp-t48a 240.0.0.80 DNS)" "$(vm_lease vp-t48a 240.0.0.80 NTP)" +vm_ssh vp-t48a 240.0.0.80 'ping -n -c 1 -W 1 240.0.0.250' >/dev/null 2>&1 +vm_ssh vp-t48b 240.0.0.81 'ping -n -c 1 -W 1 240.0.0.250' >/dev/null 2>&1 +MA=$(ip -n vp-t48a -o link show br-t48a | grep -o 'link/ether [0-9a-f:]*' | cut -d' ' -f2) +MB=$(ip -n vp-t48b -o link show br-t48b | grep -o 'link/ether [0-9a-f:]*' | cut -d' ' -f2) +info "MAC de la gateway : vp-t48a ${MA}, vp-t48b ${MB}" +check "témoin : les deux gateways 240.0.0.250 ont des MAC distinctes" sh -c "[ -n \"\$1\" ] && [ \"\$1\" != \"\$2\" ]" _ "${MA}" "${MB}" +check "t48-a résout 240.0.0.250 vers la gateway de son VPC" test "$(vm_neigh_mac vp-t48a 240.0.0.80 240.0.0.250)" = "${MA}" +check "t48-b résout 240.0.0.250 vers la gateway de son VPC" test "$(vm_neigh_mac vp-t48b 240.0.0.81 240.0.0.250)" = "${MB}" +S=$(mktemp -d) +sniff_start "${S}/a" v-t48a-e 10 icmp-from 240.0.0.80 +for i in $(seq 1 10); do vm_ssh vp-t48a 240.0.0.80 'ping -n -c 1 -W 2 240.255.0.1' >/dev/null 2>&1 && break; sleep 2; done +check "t48-a joint 240.255.0.1 derrière les bordures" vm_ssh vp-t48a 240.0.0.80 'ping -n -c 3 -W 2 240.255.0.1' +wait +check "t48-a sort avec son IP publique 240.0.0.80, sans NAT" test "$(cat "${S}/a")" -gt 0 +sniff_start "${S}/spoof" v-t48b-e 10 arp-from 240.0.0.80 +sniff_start "${S}/own" v-t48b-e 10 arp-from 240.0.0.81 +vm_frames vp-t48b 240.0.0.81 garp ens3 240.0.0.80 3 >/dev/null 2>&1 +vm_frames vp-t48b 240.0.0.81 garp ens3 240.0.0.81 3 >/dev/null 2>&1 +wait +info "ARP émis par t48-b vus sur v-t48b-e : au nom de 240.0.0.80 $(cat "${S}/spoof"), au sien $(cat "${S}/own")" +check "témoin : l'ARP de t48-b pour sa propre adresse atteint le segment" test "$(cat "${S}/own")" -gt 0 +check "t48-b ne peut pas annoncer l'adresse de t48-a sur le segment" test "$(cat "${S}/spoof")" -eq 0 +rm -r "${S}" +check "IP flottante refusée sur une interface public_ip (409)" expect_code 409 api_post_code floating-ips '{"name":"fip-t48","vm":"t48-a","interface":"nic-0","ip":"240.0.0.90/24","gateway":"240.0.0.1"}' +NODE + +on hv2 <<'NODE' +KEY=$(vm_key) +check "hv2 : VPC vp-t48c" vpc_create vp-t48c 10.50.0.0/16 +pub () { api_post subnets "{\"name\":\"${1}\",\"vpc\":\"${2}\",\"mode\":\"public_ip\",\"cidr\":\"240.0.0.0/24\",\"interface_ip\":\"240.0.0.250\",\"default_route\":true,\"gateway\":\"240.0.0.1\"}" && wait_state "subnets/${1}" running; } +check "hv2 : subnet public sn-t48c, même plage, même interface_ip, sans iface_type" pub sn-t48c vp-t48c +check "hv2 : VM t48-c 240.0.0.82" vm_create t48-c sn-t48c 240.0.0.82 "${KEY}" +check "t48-c joignable" vm_wait vp-t48c 240.0.0.82 +for i in $(seq 1 10); do vm_ssh vp-t48c 240.0.0.82 'ping -n -c 1 -W 2 240.255.0.1' >/dev/null 2>&1 && break; sleep 2; done +check "t48-c joint 240.255.0.1 derrière les bordures" vm_ssh vp-t48c 240.0.0.82 'ping -n -c 3 -W 2 240.255.0.1' +check "t48-c (hv2) joint t48-a (hv1) sur le segment public, sans NAT" vm_ssh vp-t48c 240.0.0.82 'ping -n -c 3 -W 2 240.0.0.80' +check "t48-c résout 240.0.0.250 vers la gateway de son VPC" test "$(vm_neigh_mac vp-t48c 240.0.0.82 240.0.0.250)" = "$(ip -n vp-t48c -o link show br-t48c | grep -o 'link/ether [0-9a-f:]*' | cut -d' ' -f2)" +NODE + +on hv3 <<'NODE' +NS=t48-pub +ip netns add "${NS}" +ip link add t48-pub-h type veth peer name t48-pub-n netns "${NS}" +ip link set t48-pub-h master br-public up +ip -n "${NS}" link set t48-pub-n up +ip -n "${NS}" addr add 240.0.0.148/24 dev t48-pub-n +check "hv3 : témoin, ${NS} joint la gateway des bordures" ip netns exec "${NS}" ping -n -c 3 -W 1 240.0.0.1 +check "hv3 : ${NS} joint t48-a (hv1) par son IP publique" ip netns exec "${NS}" ping -n -c 3 -W 2 240.0.0.80 +check "hv3 : ${NS} joint t48-c (hv2) par son IP publique" ip netns exec "${NS}" ping -n -c 3 -W 2 240.0.0.82 +R=$(ns_frames "${NS}" arp-who t48-pub-n 240.0.0.148 240.0.0.80 2) +check "hv3 : témoin, 240.0.0.80 répond à l'ARP depuis le segment (${R:-personne})" test -n "${R}" +R=$(ns_frames "${NS}" arp-who t48-pub-n 240.0.0.148 240.0.0.250 2) +check "hv3 : personne ne répond à l'ARP pour interface_ip 240.0.0.250 sur le segment (${R:-personne})" test -z "${R}" +NODE