Skip to content

Commit

Permalink
hotfix: envoy control-plane detect enable ipv6 or not to add route (#389
Browse files Browse the repository at this point in the history
)
  • Loading branch information
wencaiwulue authored Dec 9, 2024
1 parent d9d4091 commit 9ebc953
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pkg/controlplane/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Rule struct {
PortMap map[int32]int32
}

func (a *Virtual) To() (
func (a *Virtual) To(enableIPv6 bool) (
listeners []types.Resource,
clusters []types.Resource,
routes []types.Resource,
Expand All @@ -56,7 +56,13 @@ func (a *Virtual) To() (

var rr []*route.Route
for _, rule := range a.Rules {
for _, ip := range []string{rule.LocalTunIPv4, rule.LocalTunIPv6} {
var ips []string
if enableIPv6 {
ips = []string{rule.LocalTunIPv4, rule.LocalTunIPv6}
} else {
ips = []string{rule.LocalTunIPv4}
}
for _, ip := range ips {
clusterName := fmt.Sprintf("%s_%v", ip, rule.PortMap[port.ContainerPort])
clusters = append(clusters, ToCluster(clusterName))
endpoints = append(endpoints, ToEndPoint(clusterName, ip, rule.PortMap[port.ContainerPort]))
Expand Down
5 changes: 4 additions & 1 deletion pkg/controlplane/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
log "github.com/sirupsen/logrus"
utilcache "k8s.io/apimachinery/pkg/util/cache"
"sigs.k8s.io/yaml"

"github.com/wencaiwulue/kubevpn/v2/pkg/util"
)

type Processor struct {
Expand Down Expand Up @@ -50,6 +52,7 @@ func (p *Processor) ProcessFile(file NotifyMessage) error {
p.logger.Errorf("error parsing yaml file: %+v", err)
return err
}
enableIPv6, _ := util.DetectSupportIPv6()
for _, config := range configList {
if len(config.Uid) == 0 {
continue
Expand All @@ -62,7 +65,7 @@ func (p *Processor) ProcessFile(file NotifyMessage) error {
}
p.logger.Debugf("update config, version %d, config %v", p.version, config)

listeners, clusters, routes, endpoints := config.To()
listeners, clusters, routes, endpoints := config.To(enableIPv6)
resources := map[resource.Type][]types.Resource{
resource.ListenerType: listeners, // listeners
resource.RouteType: routes, // routes
Expand Down
15 changes: 15 additions & 0 deletions pkg/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"math"
"math/rand"
"net"
"os"
"strconv"
"strings"
"time"

"github.com/cilium/ipam/service/allocator"
Expand Down Expand Up @@ -240,3 +243,15 @@ func GenICMPPacketIPv6(src net.IP, dst net.IP) ([]byte, error) {
}
return buf.Bytes(), nil
}

func DetectSupportIPv6() (bool, error) {
content, err := os.ReadFile("/proc/sys/net/ipv6/conf/all/disable_ipv6")
if err != nil {
return false, err
}
disableIPv6, err := strconv.Atoi(strings.TrimSpace(string(content)))
if err != nil {
return false, err
}
return disableIPv6 == 0, nil
}

0 comments on commit 9ebc953

Please sign in to comment.