netlink icon indicating copy to clipboard operation
netlink copied to clipboard

Mac OSX attempting to connect to TUN "not implemented" error

Open amlwwalker opened this issue 3 years ago • 3 comments

I am atteempting to create a TUN and then configure it with netlink. My code is

	config := water.Config{
		DeviceType: water.TUN,
	}

	// Create a tunnel
	inf, err := water.New(config)
	if err != nil {
		log.Fatalf("error while creating a tun interface: %v", err)
	}
	defer inf.Close()
	log.Printf("Interface Name: %s\n", inf.Name())
	link, err := netlink.LinkByName(inf.Name())
	if err != nil {
		log.Fatalf("error while getting link: %v", err)
	}
	addr, err := netlink.ParseAddr(IPAddr)
	if err != nil {
		log.Fatalf("error parsing ip address: %v", err)
	}

	err = netlink.LinkSetMTU(link, 1300)
	if err != nil {
		log.Fatalf("error setting MTU: %v", err)
	}

	err = netlink.AddrAdd(link, addr)
	if err != nil {
		log.Fatalf("error assigning ip address: %v", err)
	}

	err = netlink.LinkSetUp(link)
	if err != nil {
		log.Fatalf("error bringing up the link: %v", err)
	}

	log.Printf("tunnel created with name: %s", inf.Name())

However when I run this, I get error while getting link: not implemented.

I can however configure using ifconfig (the tunnel always seems to come up as utun2 and the code prints as such).

Any tips as to why I am getting this error? Thanks

amlwwalker avatar Oct 25 '22 14:10 amlwwalker

This library only works on linux. There are some stubs in place for osx/windows, but nothing has been implemented.

On Tue, Oct 25, 2022 at 7:42 AM Alex Walker @.***> wrote:

I am atteempting to create a TUN and then configure it with netlink. My code is

config := water.Config{ DeviceType: water.TUN, }

// Create a tunnel inf, err := water.New(config) if err != nil { log.Fatalf("error while creating a tun interface: %v", err) } defer inf.Close() log.Printf("Interface Name: %s\n", inf.Name()) link, err := netlink.LinkByName(inf.Name()) if err != nil { log.Fatalf("error while getting link: %v", err) } addr, err := netlink.ParseAddr(IPAddr) if err != nil { log.Fatalf("error parsing ip address: %v", err) }

err = netlink.LinkSetMTU(link, 1300) if err != nil { log.Fatalf("error setting MTU: %v", err) }

err = netlink.AddrAdd(link, addr) if err != nil { log.Fatalf("error assigning ip address: %v", err) }

err = netlink.LinkSetUp(link) if err != nil { log.Fatalf("error bringing up the link: %v", err) }

log.Printf("tunnel created with name: %s", inf.Name())

However when I run this, I get error while getting link: not implemented.

I can however configure using ifconfig (the tunnel always seems to come up as utun2 and the code prints as such).

Any tips as to why I am getting this error? Thanks

— Reply to this email directly, view it on GitHub https://github.com/vishvananda/netlink/issues/823, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABCXDQP2SVPSLZUHGBZZN3WE7WVHANCNFSM6AAAAAAROBP7XU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

vishvananda avatar Oct 25 '22 16:10 vishvananda

Thanks for response - are you aware of any other libraries out there that do what this one does and i can look into this on Mac? I'm trying to learn through Go about TUN/TAP and a Go library working on OSX would be great

amlwwalker avatar Oct 27 '22 10:10 amlwwalker

I haven't looked for the functionality on osx, but I imagine someone must have written one.

On Thu, Oct 27, 2022 at 3:18 AM Alex Walker @.***> wrote:

Thanks for response - are you aware of any other libraries out there that do what this one does and i can look into this on Mac? I'm trying to learn through Go about TUN/TAP and a Go library working on OSX would be great

— Reply to this email directly, view it on GitHub https://github.com/vishvananda/netlink/issues/823#issuecomment-1293308371, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABCXDUXWEHOYHZNVEC6BUDWFJJH3ANCNFSM6AAAAAAROBP7XU . You are receiving this because you commented.Message ID: @.***>

vishvananda avatar Oct 27 '22 15:10 vishvananda