diff --git a/pkg/engine/tunnel.go b/pkg/engine/tunnel.go index 48fdb6f..fa14b37 100644 --- a/pkg/engine/tunnel.go +++ b/pkg/engine/tunnel.go @@ -53,8 +53,10 @@ func (t *TunnelEngine) processNextWorkItem() bool { func (t *TunnelEngine) handler(gw *v1beta1.Gateway) error { klog.Info(utils.FormatRavenEngine("update raven l3 tunnel config for gateway %s", gw.GetName())) - if err := t.checkNatCapability(); err != nil { - return err + if t.config.Tunnel.NATTraversal { + if err := t.checkNatCapability(); err != nil { + return err + } } err := t.initDriver() @@ -97,7 +99,7 @@ func (t *TunnelEngine) initDriver() error { } if t.tunnelHandler == nil { - t.tunnelHandler = tunnelengine.NewTunnelHandler(t.nodeName, t.config.Tunnel.ForwardNodeIP, t.client, t.routeDriver, t.vpnDriver) + t.tunnelHandler = tunnelengine.NewTunnelHandler(t.nodeName, t.config.Tunnel.ForwardNodeIP, t.config.Tunnel.NATTraversal, t.client, t.routeDriver, t.vpnDriver) } return nil } diff --git a/pkg/tunnelengine/tunnelagent.go b/pkg/tunnelengine/tunnelagent.go index c859193..c99f9af 100644 --- a/pkg/tunnelengine/tunnelagent.go +++ b/pkg/tunnelengine/tunnelagent.go @@ -41,6 +41,7 @@ import ( type TunnelHandler struct { nodeName string forwardNodeIP bool + natTraversal bool ownGateway *v1beta1.Gateway ravenClient client.Client @@ -52,10 +53,11 @@ type TunnelHandler struct { lastSeenNetwork *types.Network } -func NewTunnelHandler(nodeName string, forwardNodeIP bool, client client.Client, routeDriver routedriver.Driver, vpnDriver vpndriver.Driver) *TunnelHandler { +func NewTunnelHandler(nodeName string, forwardNodeIP bool, natTraversal bool, client client.Client, routeDriver routedriver.Driver, vpnDriver vpndriver.Driver) *TunnelHandler { return &TunnelHandler{ nodeName: nodeName, forwardNodeIP: forwardNodeIP, + natTraversal: natTraversal, ravenClient: client, routeDriver: routeDriver, vpnDriver: vpnDriver, @@ -87,13 +89,13 @@ func (c *TunnelHandler) Handler() error { // try to update public IP if empty. gw := &gws.Items[i] if ep := getTunnelActiveEndpoints(gw); ep != nil { - if ep.PublicIP == "" || ep.NATType == "" || ep.PublicPort == 0 && ep.NATType != utils.NATSymmetric { + if ep.PublicIP == "" || c.natTraversal && (ep.NATType == "" || ep.PublicPort == 0 && ep.NATType != utils.NATSymmetric) { if ep.PublicIP == "" { if err := c.configGatewayPublicIP(gw); err != nil { klog.ErrorS(err, "error config gateway public ip", "gateway", klog.KObj(gw)) } } - if ep.NATType == "" || ep.PublicPort == 0 && ep.NATType != utils.NATSymmetric { + if c.natTraversal && (ep.NATType == "" || ep.PublicPort == 0 && ep.NATType != utils.NATSymmetric) { if err := c.configGatewayStunInfo(gw); err != nil { klog.ErrorS(err, "error config gateway stun info", "gateway", klog.KObj(gw)) } @@ -214,13 +216,15 @@ func (c *TunnelHandler) shouldHandleGateway(gateway *v1beta1.Gateway) bool { klog.InfoS("no public IP for gateway, waiting for sync", "gateway", klog.KObj(gateway)) return false } - if ep.NATType == "" { - klog.InfoS("no nat type for gateway, waiting for sync", "gateway", klog.KObj(gateway)) - return false - } - if ep.NATType != utils.NATSymmetric && ep.PublicPort == 0 { - klog.InfoS("no public port for gateway, waiting for sync", "gateway", klog.KObj(gateway)) - return false + if c.natTraversal { + if ep.NATType == "" { + klog.InfoS("no nat type for gateway, waiting for sync", "gateway", klog.KObj(gateway)) + return false + } + if ep.NATType != utils.NATSymmetric && ep.PublicPort == 0 { + klog.InfoS("no public port for gateway, waiting for sync", "gateway", klog.KObj(gateway)) + return false + } } if c.ownGateway == nil { klog.InfoS(fmt.Sprintf("no own gateway for node %s, skip it", c.nodeName), "gateway", klog.KObj(gateway))