Skip to content

Commit

Permalink
Merge pull request #2149 from spidernet-io/robot/cherrypick/pr2148/re…
Browse files Browse the repository at this point in the history
…lease-v0.6

title:	coordinator: fix failed to setupHijackRoutes
  • Loading branch information
weizhoublue authored Aug 8, 2023
2 parents 6e16e5c + 02f75e4 commit 771f294
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/coordinator/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,22 @@ func (c *coordinator) setupHijackRoutes(logger *zap.Logger, ruleTable int) error
// make sure that veth0/eth0 forwards traffic within the cluster
// eq: ip route add <cluster/service cidr> dev veth0/eth0
for _, hijack := range c.HijackCIDR {
_, ipNet, err := net.ParseCIDR(hijack)
nip, ipNet, err := net.ParseCIDR(hijack)
if err != nil {
logger.Error("Invalid Hijack Cidr", zap.String("Cidr", hijack), zap.Error(err))
return err
}

if nip.To4() != nil && v4Gw == nil {
logger.Warn("ignore adding hijack routing table(ipv4), due to ipv4 gateway is nil", zap.String("IPv4 Hijack cidr", hijack))
continue
}

if nip.To4() == nil && v6Gw == nil {
logger.Warn("ignore adding hijack routing table(ipv6), due to ipv6 gateway is nil", zap.String("IPv6 Hijack cidr", hijack))
continue
}

if err := networking.AddRoute(logger, ruleTable, c.ipFamily, netlink.SCOPE_UNIVERSE, c.podVethName, ipNet, v4Gw, v6Gw); err != nil {
logger.Error("failed to AddRoute for hijackCIDR", zap.String("Dst", ipNet.String()), zap.Error(err))
return fmt.Errorf("failed to AddRoute for hijackCIDR: %v", err)
Expand Down

0 comments on commit 771f294

Please sign in to comment.