wireguard.lists.zx2c4.com archive mirror
 help / color / mirror / Atom feed
* [PATCH] FreeBSD default tun name patch
@ 2021-03-06  9:47 kayrus
  2021-03-07 16:21 ` kayrus
  2021-03-08 15:02 ` Kyle Evans
  0 siblings, 2 replies; 4+ messages in thread
From: kayrus @ 2021-03-06  9:47 UTC (permalink / raw)
  To: wireguard

This change allows to omit the tun interface name setting in FreeBSD. When name
is not set, kernel automatically picks up the tun name and index.
---
 tun/tun_freebsd.go | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/tun/tun_freebsd.go b/tun/tun_freebsd.go
index 12b44da..1883aad 100644
--- a/tun/tun_freebsd.go
+++ b/tun/tun_freebsd.go
@@ -346,22 +346,24 @@ func CreateTUN(name string, mtu int) (Device, error) {
 		return nil, fmt.Errorf("Unable to set nd6 flags for %s: %w", assignedName, errno)
 	}
 
-	// Rename the interface
-	var newnp [unix.IFNAMSIZ]byte
-	copy(newnp[:], name)
-	var ifr ifreq_ptr
-	copy(ifr.Name[:], assignedName)
-	ifr.Data = uintptr(unsafe.Pointer(&newnp[0]))
-	_, _, errno = unix.Syscall(
-		unix.SYS_IOCTL,
-		uintptr(confd),
-		uintptr(unix.SIOCSIFNAME),
-		uintptr(unsafe.Pointer(&ifr)),
-	)
-	if errno != 0 {
-		tunFile.Close()
-		tunDestroy(assignedName)
-		return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno)
+	if name != "" {
+		// Rename the interface
+		var newnp [unix.IFNAMSIZ]byte
+		copy(newnp[:], name)
+		var ifr ifreq_ptr
+		copy(ifr.Name[:], assignedName)
+		ifr.Data = uintptr(unsafe.Pointer(&newnp[0]))
+		_, _, errno = unix.Syscall(
+			unix.SYS_IOCTL,
+			uintptr(confd),
+			uintptr(unix.SIOCSIFNAME),
+			uintptr(unsafe.Pointer(&ifr)),
+		)
+		if errno != 0 {
+			tunFile.Close()
+			tunDestroy(assignedName)
+			return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno)
+		}
 	}
 
 	return CreateTUNFromFile(tunFile, mtu)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] FreeBSD default tun name patch
  2021-03-06  9:47 [PATCH] FreeBSD default tun name patch kayrus
@ 2021-03-07 16:21 ` kayrus
  2021-03-07 16:30   ` Jason A. Donenfeld
  2021-03-08 15:02 ` Kyle Evans
  1 sibling, 1 reply; 4+ messages in thread
From: kayrus @ 2021-03-07 16:21 UTC (permalink / raw)
  To: wireguard

This change allows to omit the tun interface name setting in FreeBSD. When name
is not set, kernel automatically picks up the tun name and index.

Signed-off-by: kayrus <kay.diam@gmail.com>
---
 tun/tun_freebsd.go | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/tun/tun_freebsd.go b/tun/tun_freebsd.go
index 12b44da..1883aad 100644
--- a/tun/tun_freebsd.go
+++ b/tun/tun_freebsd.go
@@ -346,22 +346,24 @@ func CreateTUN(name string, mtu int) (Device, error) {
 		return nil, fmt.Errorf("Unable to set nd6 flags for %s: %w", assignedName, errno)
 	}
 
-	// Rename the interface
-	var newnp [unix.IFNAMSIZ]byte
-	copy(newnp[:], name)
-	var ifr ifreq_ptr
-	copy(ifr.Name[:], assignedName)
-	ifr.Data = uintptr(unsafe.Pointer(&newnp[0]))
-	_, _, errno = unix.Syscall(
-		unix.SYS_IOCTL,
-		uintptr(confd),
-		uintptr(unix.SIOCSIFNAME),
-		uintptr(unsafe.Pointer(&ifr)),
-	)
-	if errno != 0 {
-		tunFile.Close()
-		tunDestroy(assignedName)
-		return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno)
+	if name != "" {
+		// Rename the interface
+		var newnp [unix.IFNAMSIZ]byte
+		copy(newnp[:], name)
+		var ifr ifreq_ptr
+		copy(ifr.Name[:], assignedName)
+		ifr.Data = uintptr(unsafe.Pointer(&newnp[0]))
+		_, _, errno = unix.Syscall(
+			unix.SYS_IOCTL,
+			uintptr(confd),
+			uintptr(unix.SIOCSIFNAME),
+			uintptr(unsafe.Pointer(&ifr)),
+		)
+		if errno != 0 {
+			tunFile.Close()
+			tunDestroy(assignedName)
+			return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno)
+		}
 	}
 
 	return CreateTUNFromFile(tunFile, mtu)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] FreeBSD default tun name patch
  2021-03-07 16:21 ` kayrus
@ 2021-03-07 16:30   ` Jason A. Donenfeld
  0 siblings, 0 replies; 4+ messages in thread
From: Jason A. Donenfeld @ 2021-03-07 16:30 UTC (permalink / raw)
  To: kayrus; +Cc: WireGuard mailing list

Applied, thanks:
https://git.zx2c4.com/wireguard-go/commit/?id=f4695db51c393f60ed9b8398b95b1f2013ad9b22

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] FreeBSD default tun name patch
  2021-03-06  9:47 [PATCH] FreeBSD default tun name patch kayrus
  2021-03-07 16:21 ` kayrus
@ 2021-03-08 15:02 ` Kyle Evans
  1 sibling, 0 replies; 4+ messages in thread
From: Kyle Evans @ 2021-03-08 15:02 UTC (permalink / raw)
  To: kayrus; +Cc: wireguard

On Sun, Mar 7, 2021 at 9:45 AM kayrus <kay.diam@gmail.com> wrote:
>
> This change allows to omit the tun interface name setting in FreeBSD. When name
> is not set, kernel automatically picks up the tun name and index.
> ---
>  tun/tun_freebsd.go | 34 ++++++++++++++++++----------------
>  1 file changed, 18 insertions(+), 16 deletions(-)
>

Hi,

I'm a little confused by what's going on here -- folks are wanting to
use the assigned name from the tuntap cloner, or is it just a desire
to not require that a new name be specified? The latter seems
incompatible with how the Linux counterpart works, but perhaps Linux
doesn't assign a name/unit when opening /dev/net/tun like we do.

Thanks,

Kyle Evans


> diff --git a/tun/tun_freebsd.go b/tun/tun_freebsd.go
> index 12b44da..1883aad 100644
> --- a/tun/tun_freebsd.go
> +++ b/tun/tun_freebsd.go
> @@ -346,22 +346,24 @@ func CreateTUN(name string, mtu int) (Device, error) {
>                 return nil, fmt.Errorf("Unable to set nd6 flags for %s: %w", assignedName, errno)
>         }
>
> -       // Rename the interface
> -       var newnp [unix.IFNAMSIZ]byte
> -       copy(newnp[:], name)
> -       var ifr ifreq_ptr
> -       copy(ifr.Name[:], assignedName)
> -       ifr.Data = uintptr(unsafe.Pointer(&newnp[0]))
> -       _, _, errno = unix.Syscall(
> -               unix.SYS_IOCTL,
> -               uintptr(confd),
> -               uintptr(unix.SIOCSIFNAME),
> -               uintptr(unsafe.Pointer(&ifr)),
> -       )
> -       if errno != 0 {
> -               tunFile.Close()
> -               tunDestroy(assignedName)
> -               return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno)
> +       if name != "" {
> +               // Rename the interface
> +               var newnp [unix.IFNAMSIZ]byte
> +               copy(newnp[:], name)
> +               var ifr ifreq_ptr
> +               copy(ifr.Name[:], assignedName)
> +               ifr.Data = uintptr(unsafe.Pointer(&newnp[0]))
> +               _, _, errno = unix.Syscall(
> +                       unix.SYS_IOCTL,
> +                       uintptr(confd),
> +                       uintptr(unix.SIOCSIFNAME),
> +                       uintptr(unsafe.Pointer(&ifr)),
> +               )
> +               if errno != 0 {
> +                       tunFile.Close()
> +                       tunDestroy(assignedName)
> +                       return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno)
> +               }
>         }
>
>         return CreateTUNFromFile(tunFile, mtu)
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-09  0:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-06  9:47 [PATCH] FreeBSD default tun name patch kayrus
2021-03-07 16:21 ` kayrus
2021-03-07 16:30   ` Jason A. Donenfeld
2021-03-08 15:02 ` Kyle Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).