From c01d14251ed9daebedd3841712db9d5b122842e4 Mon Sep 17 00:00:00 2001 From: cyclinder Date: Mon, 6 Nov 2023 14:05:15 +0800 Subject: [PATCH] Fix wrong policy table in multi-nic --- plugins/router/router.go | 5 +++++ plugins/veth/veth.go | 21 --------------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/plugins/router/router.go b/plugins/router/router.go index bdd0e83f..1188bd24 100644 --- a/plugins/router/router.go +++ b/plugins/router/router.go @@ -18,6 +18,7 @@ import ( spiderpool "github.com/spidernet-io/spiderpool/pkg/networking/networking" "github.com/vishvananda/netlink" "go.uber.org/zap" + "golang.org/x/sys/unix" "k8s.io/utils/pointer" "net" "os" @@ -334,12 +335,16 @@ func addHostIPRoute(logger *zap.Logger, netns ns.NetNS, ruleTable, ipfamily int, zap.Bool("enableIpv4", enableIpv4), zap.Bool("enableIpv6", enableIpv6)) err := netns.Do(func(_ ns.NetNS) error { + if ruleTable == 100 { + ruleTable = unix.RT_TABLE_MAIN + } for _, hostIP := range hostIPs { if err := spiderpool.AddRoute(logger, ruleTable, ipfamily, netlink.SCOPE_LINK, defaultInterface, spiderpool.ConvertMaxMaskIPNet(hostIP), nil, nil); err != nil { logger.Error(err.Error()) return err } } + logger.Debug("addHostIPRoute add hostIP route dev eth0 to table main") return nil }) diff --git a/plugins/veth/veth.go b/plugins/veth/veth.go index 837d3d79..9b1a0ff3 100644 --- a/plugins/veth/veth.go +++ b/plugins/veth/veth.go @@ -516,27 +516,6 @@ func setupRoutes(logger *zap.Logger, netns ns.NetNS, ruleTable, ipfamily int, ho } logger.Debug("AddRouteTable for localCIDRs successfully", zap.Strings("localCIDRs", allSubnets)) - - // As for more than two macvlan interface, we need to add something like below shown: - // eq: ip rule add to lookup table - var ipFamilies []int - if ipfamily == netlink.FAMILY_ALL { - ipFamilies = append(ipFamilies, netlink.FAMILY_V4, netlink.FAMILY_V6) - } else { - ipFamilies = append(ipFamilies, ipfamily) - } - - if ruleTable != unix.RT_TABLE_MAIN { - rule := netlink.NewRule() - rule.Table = ruleTable - for _, ipf := range ipFamilies { - rule.Family = ipf - if err = netlink.RuleAdd(rule); err != nil && !os.IsExist(err) { - logger.Error("failed to Add ToRuleTable for host", zap.String("rule", rule.String()), zap.Error(err)) - return fmt.Errorf("failed to Add ToRuleTable for host(%+v): %v", rule.String(), err) - } - } - } return nil })