wireguard.lists.zx2c4.com archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Daniel Lenski <dlenski@gmail.com>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: Re: Duplicate IP address, and permissions problems on Windows
Date: Thu, 08 Apr 2021 17:59:23 +0100	[thread overview]
Message-ID: <432300ddb79fffb1586ccac6852fade4c2d47db0.camel@infradead.org> (raw)
In-Reply-To: <CAOw_LSEasJuHDPXGkVQnYh_aHd+nOY53D0LRUXuH+pN45ynz2w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2420 bytes --]

On Wed, 2021-04-07 at 16:00 -0700, Daniel Lenski wrote:
> Following David's initial implementation, I wrote something for
> OpenConnect that's pretty much the same as yours:
> https://gitlab.com/openconnect/openconnect/-/compare/5e6e9b850756157164f83cd4fedafb747fbbd50f...0bca5b32ac478b5d03b6e88f96bf29c6556610a5
> 
> 1. Uses GetAdaptersAddresses to list all the addresses
> 2. If/when it finds a clashing address, it uses
> GetUnicastIpAddressTable to determine the up/down state of the other
> interface
> 3. Only delete the address from the other interface if it's non-UP.
> 
> I was also annoyed that the GetAdaptersAddresses return structure
> doesn't provide the adapter state, and that I had to go for this
> convoluted O(n^2) design.
> 
> I guess this reassures me that there isn't an obviously-better way to
> do it.

Hm, your description doesn't match the code I see at that link.

You're using GetAdaptersAddresses() which gives you the UP/DOWN status
as well as the addresses, and you iterate over those. The loop is

 ∀ adapter, ∀ Unicast address on that adapter:
     Check if it's our Legacy IP or IPv6 address.

That isn't O(n²), is it? It's still O(n) of the total number of unicast
addresses in the system?

Once you've found an address which needs to be removed, you're *then*
using GetUnicastIpAddressTable() and searching through the results to
find the appropriate MIB_UNICASTIPADDRESS_ROW that you need to pass to
DeleteUnicastIpAddressEntry().

Does *every* field in the MIB_UNICASTIPADDRESS_ROW have to be filled
in, or is it just the Address, InterfaceLuid and InterfaceIndex? Can't
we get those from the table we get back from GetAdaptersAddresses()?


Alternatively, can't we start with GetUnicastIpAddressTable() as my
original code did, and if we want to check whether an interface is down
before we steal the address from it, use GetIfEntry2() to find out?

Using GetIfEntry2() is probably a saner way to find the InterfaceIndex
for the Wintun itself, which I was dredging the registry for manually.


I'd like to be consistent about clearing the 'conflicting' addresses
and setting the address on the Wintun interface. Whatever we do in
OpenConnect for Legacy IP we should also do for IPv6. It looks like
you're clearing the conflicting addresses for both families, but we
still aren't *setting* the IPv6 address from the C code? 

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5174 bytes --]

  parent reply	other threads:[~2021-04-08 16:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 11:29 Duplicate IP address, and permissions problems on Windows David Woodhouse
2021-04-07  0:17 ` Jason A. Donenfeld
2021-04-07  8:18   ` David Woodhouse
2021-04-07 23:05     ` Daniel Lenski
2021-04-12 17:50       ` Jason A. Donenfeld
2021-04-07 23:00   ` Daniel Lenski
2021-04-08  8:46     ` David Woodhouse
2021-04-08 16:09       ` Daniel Lenski
2021-04-08 16:59     ` David Woodhouse [this message]
2021-04-08 17:53       ` Daniel Lenski
2021-04-10  9:25         ` David Woodhouse

Reply instructions:

You may reply publicly 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=432300ddb79fffb1586ccac6852fade4c2d47db0.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=Jason@zx2c4.com \
    --cc=dlenski@gmail.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).