Skip to content

Commit

Permalink
Fix panic when allowing conflicting subnets on macOS.
Browse files Browse the repository at this point in the history
This commit fixes a regression introduced in 2.21.0, causing the macOS
client to panic when the `--allow-conflicting-subnets` connect flag was
used, or when `routing.allowConflictingSubnets` was added to the client
configuration.

Closes #3784

Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed Feb 2, 2025
1 parent 9bc0279 commit a835b0d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg/vif/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (d *device) AddSubnet(ctx context.Context, subnet netip.Prefix) (err error)

// Index returns the index of this device.
func (d *device) Index() uint32 {
return d.index()
return d.interfaceIndex
}

// Name returns the name of this device, e.g. "tun0".
Expand Down
26 changes: 12 additions & 14 deletions pkg/vif/device_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ const (

type device struct {
*channel.Endpoint
file *os.File
ctx context.Context
name string
wb bytes.Buffer
wg sync.WaitGroup
file *os.File
ctx context.Context
name string
interfaceIndex uint32
wb bytes.Buffer
wg sync.WaitGroup
}

func openTun(ctx context.Context) (*device, error) {
Expand Down Expand Up @@ -66,15 +67,16 @@ func openTun(ctx context.Context) (*device, error) {
if err != nil {
return nil, err
}
mtu, err := getMTU(name)
iface, err := net.InterfaceByName(name)
if err != nil {
return nil, err
}
return &device{
file: os.NewFile(uintptr(fd), ""),
ctx: ctx,
name: name,
Endpoint: channel.New(defaultDevOutQueueLen, mtu, ""),
file: os.NewFile(uintptr(fd), ""),
ctx: ctx,
name: name,
interfaceIndex: uint32(iface.Index),
Endpoint: channel.New(defaultDevOutQueueLen, uint32(iface.MTU), ""),
}, nil
}

Expand Down Expand Up @@ -106,10 +108,6 @@ func (d *device) addSubnet(_ context.Context, subnet netip.Prefix) error {
return routing.Add(1, subnet, dest)
}

func (d *device) index() uint32 {
panic("not implemented")
}

func (d *device) removeSubnet(_ context.Context, subnet netip.Prefix) error {
to := subnet.Addr().AsSlice()
to[len(to)-1] = 1
Expand Down
4 changes: 0 additions & 4 deletions pkg/vif/device_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ func (d *device) removeSubnet(ctx context.Context, pfx netip.Prefix) error {
return netlink.AddrDel(link, addr)
}

func (d *device) index() uint32 {
return d.interfaceIndex
}

func (d *device) getMTU() (mtu uint32, err error) {
err = withSocket(unix.AF_INET, func(fd int) error {
ifr, err := unix.NewIfreq(d.name)
Expand Down
4 changes: 0 additions & 4 deletions pkg/vif/device_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ func (d *device) getLUID() winipcfg.LUID {
return winipcfg.LUID(d.dev.(*tun.NativeTun).LUID())
}

func (d *device) index() uint32 {
return d.interfaceIndex
}

func (d *device) addSubnet(_ context.Context, subnet netip.Prefix) error {
return d.getLUID().AddIPAddress(subnet)
}
Expand Down

0 comments on commit a835b0d

Please sign in to comment.