f-57: subnet: entrée FDB locale pour la MAC anycast, route du subnet émise depuis la gateway, contrôle watchdog #57
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
efad4efc13
commit
3ce390cb40
8 changed files with 133 additions and 3 deletions
51
internal/netif/fdb_linux.go
Normal file
51
internal/netif/fdb_linux.go
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package netif
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"net"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
)
|
||||||
|
|
||||||
|
func bridgeLocalEntry(bridgeIndex int, mac net.HardwareAddr) *netlink.Neigh {
|
||||||
|
return &netlink.Neigh{
|
||||||
|
LinkIndex: bridgeIndex,
|
||||||
|
Family: syscall.AF_BRIDGE,
|
||||||
|
State: netlink.NUD_PERMANENT,
|
||||||
|
Flags: netlink.NTF_SELF,
|
||||||
|
HardwareAddr: mac,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasBridgeLocalMAC(entries []netlink.Neigh, bridgeIndex int, mac net.HardwareAddr) bool {
|
||||||
|
for _, e := range entries {
|
||||||
|
if e.LinkIndex == bridgeIndex && e.MasterIndex == bridgeIndex &&
|
||||||
|
e.State&netlink.NUD_PERMANENT != 0 && bytes.Equal(e.HardwareAddr, mac) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func BridgeAddLocalMAC(bridge string, mac net.HardwareAddr) error {
|
||||||
|
link, err := netlink.LinkByName(bridge)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return netlink.NeighAdd(bridgeLocalEntry(link.Attrs().Index, mac))
|
||||||
|
}
|
||||||
|
|
||||||
|
func BridgeHasLocalMAC(bridge string, mac net.HardwareAddr) (bool, error) {
|
||||||
|
link, err := netlink.LinkByName(bridge)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
entries, err := netlink.NeighList(link.Attrs().Index, syscall.AF_BRIDGE)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return hasBridgeLocalMAC(entries, link.Attrs().Index, mac), nil
|
||||||
|
}
|
||||||
43
internal/netif/fdb_linux_test.go
Normal file
43
internal/netif/fdb_linux_test.go
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package netif
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBridgeLocalEntry(t *testing.T) {
|
||||||
|
mac, _ := AnycastMAC(2911)
|
||||||
|
e := bridgeLocalEntry(7, mac)
|
||||||
|
if e.LinkIndex != 7 || e.Family != syscall.AF_BRIDGE {
|
||||||
|
t.Errorf("index ou famille inattendus : %d, %d", e.LinkIndex, e.Family)
|
||||||
|
}
|
||||||
|
if e.State != netlink.NUD_PERMANENT || e.Flags != netlink.NTF_SELF {
|
||||||
|
t.Errorf("état %#x et drapeaux %#x, entrée permanente du bridge attendue", e.State, e.Flags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHasBridgeLocalMAC(t *testing.T) {
|
||||||
|
mac, _ := AnycastMAC(2911)
|
||||||
|
other, _ := AnycastMAC(2912)
|
||||||
|
local := netlink.Neigh{LinkIndex: 7, MasterIndex: 7, State: netlink.NUD_PERMANENT, HardwareAddr: mac}
|
||||||
|
cases := []struct {
|
||||||
|
label string
|
||||||
|
entries []netlink.Neigh
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{"entrée locale du bridge", []netlink.Neigh{local}, true},
|
||||||
|
{"seulement la liste unicast du bridge (macvlan)", []netlink.Neigh{{LinkIndex: 7, State: netlink.NUD_PERMANENT, Flags: netlink.NTF_SELF, HardwareAddr: mac}}, false},
|
||||||
|
{"apprise sur un port", []netlink.Neigh{{LinkIndex: 9, MasterIndex: 7, State: netlink.NUD_REACHABLE, HardwareAddr: mac}}, false},
|
||||||
|
{"autre MAC", []netlink.Neigh{{LinkIndex: 7, MasterIndex: 7, State: netlink.NUD_PERMANENT, HardwareAddr: other}}, false},
|
||||||
|
{"aucune entrée", nil, false},
|
||||||
|
}
|
||||||
|
for _, c := range cases {
|
||||||
|
if got := hasBridgeLocalMAC(c.entries, 7, mac); got != c.want {
|
||||||
|
t.Errorf("%s : %v, %v attendu", c.label, got, c.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
internal/netif/fdb_other.go
Normal file
16
internal/netif/fdb_other.go
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package netif
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BridgeAddLocalMAC(_ string, _ net.HardwareAddr) error {
|
||||||
|
return errors.New("not supported on this platform")
|
||||||
|
}
|
||||||
|
|
||||||
|
func BridgeHasLocalMAC(_ string, _ net.HardwareAddr) (bool, error) {
|
||||||
|
return false, errors.New("not supported on this platform")
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func RouteAdd(iface string, subnet *net.IPNet) error {
|
func RouteAdd(iface string, subnet *net.IPNet) error {
|
||||||
|
return RouteAddFrom(iface, subnet, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RouteAddFrom(iface string, subnet *net.IPNet, src net.IP) error {
|
||||||
link, err := netlink.LinkByName(iface)
|
link, err := netlink.LinkByName(iface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -16,6 +20,7 @@ func RouteAdd(iface string, subnet *net.IPNet) error {
|
||||||
return netlink.RouteAdd(&netlink.Route{
|
return netlink.RouteAdd(&netlink.Route{
|
||||||
LinkIndex: link.Attrs().Index,
|
LinkIndex: link.Attrs().Index,
|
||||||
Dst: subnet,
|
Dst: subnet,
|
||||||
|
Src: src,
|
||||||
Scope: netlink.SCOPE_LINK,
|
Scope: netlink.SCOPE_LINK,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ func RouteAdd(_ string, _ *net.IPNet) error {
|
||||||
return errors.New("not supported on this platform")
|
return errors.New("not supported on this platform")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RouteAddFrom(_ string, _ *net.IPNet, _ net.IP) error {
|
||||||
|
return errors.New("not supported on this platform")
|
||||||
|
}
|
||||||
|
|
||||||
func TableRoutesVia(_ int, _ string) ([]*net.IPNet, error) {
|
func TableRoutesVia(_ int, _ string) ([]*net.IPNet, error) {
|
||||||
return nil, errors.New("route listing is only implemented on linux")
|
return nil, errors.New("route listing is only implemented on linux")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,11 @@ func setupAnycastGateway(d subnetData, vethI string) error {
|
||||||
{"confine " + mac.String(), func() error { return ebtables.ConfineMAC(vethI, mac.String()) }},
|
{"confine " + mac.String(), func() error { return ebtables.ConfineMAC(vethI, mac.String()) }},
|
||||||
{"arp sysctls on " + d.bridge, func() error { return setSysctls(arpSysctls(d.bridge)) }},
|
{"arp sysctls on " + d.bridge, func() error { return setSysctls(arpSysctls(d.bridge)) }},
|
||||||
{"relay address on " + d.bridge, func() error { return netif.AddrAdd(d.bridge, d.relayIP) }},
|
{"relay address on " + d.bridge, func() error { return netif.AddrAdd(d.bridge, d.relayIP) }},
|
||||||
{"route " + d.cidr.String(), func() error { return netif.RouteAdd(d.bridge, d.cidr) }},
|
|
||||||
{"create " + gw, func() error { return netif.CreateMacvlan(gw, d.bridge, mac) }},
|
{"create " + gw, func() error { return netif.CreateMacvlan(gw, d.bridge, mac) }},
|
||||||
|
{"local fdb entry " + mac.String(), func() error { return netif.BridgeAddLocalMAC(d.bridge, mac) }},
|
||||||
{"arp sysctls on " + gw, func() error { return setSysctls(arpSysctls(gw)) }},
|
{"arp sysctls on " + gw, func() error { return setSysctls(arpSysctls(gw)) }},
|
||||||
{"gateway address on " + gw, func() error { return netif.AddrAdd(gw, d.interfaceIP) }},
|
{"gateway address on " + gw, func() error { return netif.AddrAdd(gw, d.interfaceIP) }},
|
||||||
|
{"route " + d.cidr.String(), func() error { return netif.RouteAddFrom(d.bridge, d.cidr, d.interfaceIP) }},
|
||||||
{"set up " + gw, func() error { return netif.LinkSetUp(gw) }},
|
{"set up " + gw, func() error { return netif.LinkSetUp(gw) }},
|
||||||
{"drop arp to gateway", func() error { return ebtables.DropARPToGateway(vethI, d.interfaceIP.String()) }},
|
{"drop arp to gateway", func() error { return ebtables.DropARPToGateway(vethI, d.interfaceIP.String()) }},
|
||||||
{"drop arp to relay", func() error { return ebtables.DropARPToGateway(vethI, d.relayIP.String()) }},
|
{"drop arp to relay", func() error { return ebtables.DropARPToGateway(vethI, d.relayIP.String()) }},
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import (
|
||||||
|
|
||||||
type gatewayState struct {
|
type gatewayState struct {
|
||||||
MAC string
|
MAC string
|
||||||
|
LocalFDB bool
|
||||||
GatewayAddrs []string
|
GatewayAddrs []string
|
||||||
BridgeAddrs []string
|
BridgeAddrs []string
|
||||||
}
|
}
|
||||||
|
|
@ -34,6 +35,9 @@ func gatewayProblems(gw, bridge string, got gatewayState, wantMAC, gatewayIP, re
|
||||||
if got.MAC != wantMAC {
|
if got.MAC != wantMAC {
|
||||||
problems = append(problems, fmt.Sprintf("interface %s has mac %q, expected anycast %s", gw, got.MAC, wantMAC))
|
problems = append(problems, fmt.Sprintf("interface %s has mac %q, expected anycast %s", gw, got.MAC, wantMAC))
|
||||||
}
|
}
|
||||||
|
if !got.LocalFDB {
|
||||||
|
problems = append(problems, fmt.Sprintf("bridge %s has no local fdb entry for %s, frames to the gateway are flooded", bridge, wantMAC))
|
||||||
|
}
|
||||||
if !hasAddr(got.GatewayAddrs, gatewayIP) {
|
if !hasAddr(got.GatewayAddrs, gatewayIP) {
|
||||||
problems = append(problems, fmt.Sprintf("interface %s lacks the gateway address %s", gw, gatewayIP))
|
problems = append(problems, fmt.Sprintf("interface %s lacks the gateway address %s", gw, gatewayIP))
|
||||||
}
|
}
|
||||||
|
|
@ -46,13 +50,16 @@ func gatewayProblems(gw, bridge string, got gatewayState, wantMAC, gatewayIP, re
|
||||||
return problems
|
return problems
|
||||||
}
|
}
|
||||||
|
|
||||||
func readGatewayState(gw, bridge string) (gatewayState, error) {
|
func readGatewayState(gw, bridge string, anycast net.HardwareAddr) (gatewayState, error) {
|
||||||
var st gatewayState
|
var st gatewayState
|
||||||
mac, err := netif.LinkMAC(gw)
|
mac, err := netif.LinkMAC(gw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return st, err
|
return st, err
|
||||||
}
|
}
|
||||||
st.MAC = mac.String()
|
st.MAC = mac.String()
|
||||||
|
if st.LocalFDB, err = netif.BridgeHasLocalMAC(bridge, anycast); err != nil {
|
||||||
|
return st, err
|
||||||
|
}
|
||||||
for _, side := range []struct {
|
for _, side := range []struct {
|
||||||
iface string
|
iface string
|
||||||
dst *[]string
|
dst *[]string
|
||||||
|
|
@ -106,7 +113,7 @@ func checkAnycastGateway(db *badger.DB, name, vpc, bridge string, n notify.Notif
|
||||||
n.Notify(kindSubnet, name, p+" (in netns "+vpc+")")
|
n.Notify(kindSubnet, name, p+" (in netns "+vpc+")")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
st, err := readGatewayState(gw, bridge)
|
st, err := readGatewayState(gw, bridge, wantMAC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
n.Notify(kindSubnet, name, fmt.Sprintf("anycast gateway unreadable in netns %s: %v", vpc, err))
|
n.Notify(kindSubnet, name, fmt.Sprintf("anycast gateway unreadable in netns %s: %v", vpc, err))
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
func TestGatewayProblems_Healthy(t *testing.T) {
|
func TestGatewayProblems_Healthy(t *testing.T) {
|
||||||
st := gatewayState{
|
st := gatewayState{
|
||||||
MAC: "02:01:00:00:0b:5f",
|
MAC: "02:01:00:00:0b:5f",
|
||||||
|
LocalFDB: true,
|
||||||
GatewayAddrs: []string{"10.0.0.254"},
|
GatewayAddrs: []string{"10.0.0.254"},
|
||||||
BridgeAddrs: []string{"10.0.0.253"},
|
BridgeAddrs: []string{"10.0.0.253"},
|
||||||
}
|
}
|
||||||
|
|
@ -20,6 +21,7 @@ func TestGatewayProblems_EachDefectIsReported(t *testing.T) {
|
||||||
healthy := func() gatewayState {
|
healthy := func() gatewayState {
|
||||||
return gatewayState{
|
return gatewayState{
|
||||||
MAC: "02:01:00:00:0b:5f",
|
MAC: "02:01:00:00:0b:5f",
|
||||||
|
LocalFDB: true,
|
||||||
GatewayAddrs: []string{"10.0.0.254"},
|
GatewayAddrs: []string{"10.0.0.254"},
|
||||||
BridgeAddrs: []string{"10.0.0.253"},
|
BridgeAddrs: []string{"10.0.0.253"},
|
||||||
}
|
}
|
||||||
|
|
@ -30,6 +32,7 @@ func TestGatewayProblems_EachDefectIsReported(t *testing.T) {
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{"MAC du macvlan changée", func(s *gatewayState) { s.MAC = "02:03:c0:a8:0e:0b" }, "expected anycast 02:01:00:00:0b:5f"},
|
{"MAC du macvlan changée", func(s *gatewayState) { s.MAC = "02:03:c0:a8:0e:0b" }, "expected anycast 02:01:00:00:0b:5f"},
|
||||||
|
{"entrée FDB locale absente du bridge", func(s *gatewayState) { s.LocalFDB = false }, "no local fdb entry for 02:01:00:00:0b:5f"},
|
||||||
{"gateway absente du macvlan", func(s *gatewayState) { s.GatewayAddrs = nil }, "lacks the gateway address 10.0.0.254"},
|
{"gateway absente du macvlan", func(s *gatewayState) { s.GatewayAddrs = nil }, "lacks the gateway address 10.0.0.254"},
|
||||||
{"adresse d'émission absente du bridge", func(s *gatewayState) { s.BridgeAddrs = nil }, "lacks the relay address 10.0.0.253"},
|
{"adresse d'émission absente du bridge", func(s *gatewayState) { s.BridgeAddrs = nil }, "lacks the relay address 10.0.0.253"},
|
||||||
{"gateway posée sur le bridge", func(s *gatewayState) { s.BridgeAddrs = append(s.BridgeAddrs, "10.0.0.254") }, "bypass the anycast mac"},
|
{"gateway posée sur le bridge", func(s *gatewayState) { s.BridgeAddrs = append(s.BridgeAddrs, "10.0.0.254") }, "bypass the anycast mac"},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue