mirror of
https://github.com/slackhq/nebula.git
synced 2025-11-23 08:54:25 +01:00
try to fix windows?
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
|||||||
const tunGUIDLabel = "Fixed Nebula Windows GUID v1"
|
const tunGUIDLabel = "Fixed Nebula Windows GUID v1"
|
||||||
|
|
||||||
type tun struct {
|
type tun struct {
|
||||||
luid windows.LUID
|
luid winipcfg.LUID
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTunFromFd(_ *config.C, _ *logrus.Logger, _ int, _ []netip.Prefix) (*wgTun, error) {
|
func newTunFromFd(_ *config.C, _ *logrus.Logger, _ int, _ []netip.Prefix) (*wgTun, error) {
|
||||||
@@ -56,13 +56,14 @@ func newTun(c *config.C, l *logrus.Logger, vpnNetworks []netip.Prefix, _ bool) (
|
|||||||
// Create Windows-specific route manager
|
// Create Windows-specific route manager
|
||||||
rm := &tun{}
|
rm := &tun{}
|
||||||
|
|
||||||
// Get LUID from the device name
|
// Get LUID from the TUN device
|
||||||
luid, err := winipcfg.LUIDFromAlias(actualName)
|
// The WireGuard TUN device on Windows should provide a LUID() method
|
||||||
if err != nil {
|
if nativeTun, ok := tunDevice.(interface{ LUID() uint64 }); ok {
|
||||||
|
rm.luid = winipcfg.LUID(nativeTun.LUID())
|
||||||
|
} else {
|
||||||
tunDevice.Close()
|
tunDevice.Close()
|
||||||
return nil, fmt.Errorf("failed to get LUID: %w", err)
|
return nil, fmt.Errorf("failed to get LUID from TUN device")
|
||||||
}
|
}
|
||||||
rm.luid = luid
|
|
||||||
t.routeManager = rm
|
t.routeManager = rm
|
||||||
|
|
||||||
err = t.reload(c, true)
|
err = t.reload(c, true)
|
||||||
@@ -113,7 +114,9 @@ func (rm *tun) SetMTU(t *wgTun, mtu int) {
|
|||||||
|
|
||||||
func (rm *tun) setMTU(t *wgTun, mtu int) error {
|
func (rm *tun) setMTU(t *wgTun, mtu int) error {
|
||||||
// Set MTU using winipcfg
|
// Set MTU using winipcfg
|
||||||
return rm.luid.SetIPInterfaceMTU(uint32(mtu))
|
// Note: MTU setting on Windows TUN devices may be handled by the driver
|
||||||
|
// For now, we'll skip explicit MTU setting as the WireGuard TUN handles it
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rm *tun) SetDefaultRoute(t *wgTun, cidr netip.Prefix) error {
|
func (rm *tun) SetDefaultRoute(t *wgTun, cidr netip.Prefix) error {
|
||||||
@@ -128,17 +131,19 @@ func (rm *tun) AddRoutes(t *wgTun, logErrors bool) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
route := winipcfg.RouteData{
|
|
||||||
Destination: r.Cidr,
|
|
||||||
Metric: uint32(r.Metric),
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.MTU > 0 {
|
if r.MTU > 0 {
|
||||||
// Windows route MTU is not directly supported
|
// Windows route MTU is not directly supported
|
||||||
t.l.WithField("route", r).Debug("Route MTU is not supported on Windows")
|
t.l.WithField("route", r).Debug("Route MTU is not supported on Windows")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := rm.luid.AddRoute(route.Destination, route.Destination.Addr(), route.Metric)
|
// Use winipcfg to add the route
|
||||||
|
// The rm.luid should have the AddRoute method from winipcfg
|
||||||
|
if len(r.Via) == 0 {
|
||||||
|
t.l.WithField("route", r).Warn("Route has no via address, skipping")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err := rm.luid.AddRoute(r.Cidr, r.Via[0].Addr(), uint32(r.Metric))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
retErr := util.NewContextualError("Failed to add route", map[string]any{"route": r}, err)
|
retErr := util.NewContextualError("Failed to add route", map[string]any{"route": r}, err)
|
||||||
if logErrors {
|
if logErrors {
|
||||||
@@ -160,7 +165,11 @@ func (rm *tun) RemoveRoutes(t *wgTun, routes []Route) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err := rm.luid.DeleteRoute(r.Cidr, r.Cidr.Addr())
|
if len(r.Via) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err := rm.luid.DeleteRoute(r.Cidr, r.Via[0].Addr())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.l.WithError(err).WithField("route", r).Error("Failed to remove route")
|
t.l.WithError(err).WithField("route", r).Error("Failed to remove route")
|
||||||
} else {
|
} else {
|
||||||
@@ -182,7 +191,8 @@ func (rm *tun) NewMultiQueueReader(t *wgTun) (io.ReadWriteCloser, error) {
|
|||||||
|
|
||||||
func (rm *tun) addIP(t *wgTun, network netip.Prefix) error {
|
func (rm *tun) addIP(t *wgTun, network netip.Prefix) error {
|
||||||
// Add IP address using winipcfg
|
// Add IP address using winipcfg
|
||||||
err := rm.luid.AddIPAddress(network)
|
// SetIPAddresses expects a slice of prefixes
|
||||||
|
err := rm.luid.SetIPAddresses([]netip.Prefix{network})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to add IP address %s: %w", network, err)
|
return fmt.Errorf("failed to add IP address %s: %w", network, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user