浏览代码

Immediately forward packets received on the nebula TUN device from self to self (#501)

* Immediately forward packets received on the nebula TUN device with a destination of our Nebula VPN IP right back out that same TUN device on MacOS.
brad-defined 3 年之前
父节点
当前提交
169cdbbd35
共有 3 个文件被更改,包括 20 次插入1 次删除
  1. 11 1
      inside.go
  2. 3 0
      inside_darwin.go
  3. 6 0
      inside_generic.go

+ 11 - 1
inside.go

@@ -23,8 +23,18 @@ func (f *Interface) consumeInsidePacket(packet []byte, fwPacket *firewall.Packet
 		return
 		return
 	}
 	}
 
 
-	// Ignore packets from self to self
 	if fwPacket.RemoteIP == f.myVpnIp {
 	if fwPacket.RemoteIP == f.myVpnIp {
+		// Immediately forward packets from self to self.
+		// This should only happen on Darwin-based hosts, which routes packets from
+		// the Nebula IP to the Nebula IP through the Nebula TUN device.
+		if immediatelyForwardToSelf {
+			_, err := f.readers[q].Write(packet)
+			if err != nil {
+				f.l.WithError(err).Error("Failed to forward to tun")
+			}
+		}
+		// Otherwise, drop. On linux, we should never see these packets - Linux
+		// routes packets from the nebula IP to the nebula IP through the loopback device.
 		return
 		return
 	}
 	}
 
 

+ 3 - 0
inside_darwin.go

@@ -0,0 +1,3 @@
+package nebula
+
+const immediatelyForwardToSelf bool = true

+ 6 - 0
inside_generic.go

@@ -0,0 +1,6 @@
+//go:build !darwin
+// +build !darwin
+
+package nebula
+
+const immediatelyForwardToSelf bool = false