Skip to content

Commit

Permalink
Merge pull request #186 from cyclinder/fix_multi_nic
Browse files Browse the repository at this point in the history
Fix wrong policy table in multi-nic
  • Loading branch information
cyclinder authored Nov 6, 2023
2 parents 5d94e1b + c01d142 commit aa396cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
5 changes: 5 additions & 0 deletions plugins/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
})
Expand Down
21 changes: 0 additions & 21 deletions plugins/veth/veth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <chainedInterface subnet> lookup table <ruleTable>
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
})

Expand Down

0 comments on commit aa396cb

Please sign in to comment.