WireGuard Archive on lore.kernel.org
 help / color / Atom feed
From: Kent Friis <leeloored@gmx.com>
To: wireguard@lists.zx2c4.com
Subject: wireguard-go bug with IPv6-less kernels
Date: Fri, 7 Sep 2018 18:12:54 +0200
Message-ID: <20180907181254.54accc2784d47d048aa3320f@gmx.com> (raw)

I've been setting up wireguard-go on an old Linux kernel (no module),
and hit a bug with ipv6-less kernels. The create6() function returns 0
as the port number when an error occurs, so even though CreateBind
checks for EAFNOSUPPORT, it still ends up with port getting set to zero,
resulting in a random port.

I solved it by returning port instead of zero - as far as I can see
this shouldn't break anything, as CreateBind will return 0 anyway on
errors other than EAFNOSUPPORT.

I did not check whether the same bug exists in conn_default.go

- Kent

--- conn_linux.go.old	2018-09-05 23:11:19.407372785 +0200
+++ conn_linux.go	2018-09-07 16:58:28.971914271 +0200
@@ -335,7 +335,7 @@
 	)
 
 	if err != nil {
-		return -1, 0, err
+		return -1, port, err
 	}
 
 	addr := unix.SockaddrInet4{
@@ -366,7 +366,7 @@
 		return unix.Bind(fd, &addr)
 	}(); err != nil {
 		unix.Close(fd)
-		return -1, 0, err
+		return -1, port, err
 	}
 
 	return fd, uint16(addr.Port), err
@@ -383,7 +383,7 @@
 	)
 
 	if err != nil {
-		return -1, 0, err
+		return -1, port, err
 	}
 
 	// set sockopts and bind
@@ -425,7 +425,7 @@
 
 	}(); err != nil {
 		unix.Close(fd)
-		return -1, 0, err
+		return -1, port, err
 	}
 
 	return fd, uint16(addr.Port), err

                 reply index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180907181254.54accc2784d47d048aa3320f@gmx.com \
    --to=leeloored@gmx.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

WireGuard Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/wireguard/0 wireguard/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 wireguard wireguard/ https://lore.kernel.org/wireguard \
		wireguard@lists.zx2c4.com zx2c4-wireguard@archiver.kernel.org
	public-inbox-index wireguard


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/com.zx2c4.lists.wireguard


AGPL code for this site: git clone https://public-inbox.org/ public-inbox