]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commit
Kit: Adapter: use more reliable utun detection technique
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 16 Jun 2021 15:09:40 +0000 (17:09 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Wed, 16 Jun 2021 15:40:12 +0000 (17:40 +0200)
commit23bf3cfccb5a6fa9faf85c35ca24ec4c3e29c3fe
tree17fdcb0327ab8bcf03da407beabef80c8702f17b
parent7f5ad3e503f231893dc5d298f703c4b72b83bdb9
Kit: Adapter: use more reliable utun detection technique

Rather than hoping that the AF_SYSTEM fd is of type utun, and then
calling "2" on it to get the name -- which could be defined as something
else for a different AF_SYSTEM socket type -- instead simply query the
AF_SYSTEM control socket ID with getpeername. This has one catch, which
is that the ID is dynamically allocated, so we resolve it using the
qualified name. Normally we'd make a new AF_SYSTEM socket for this, but
since that's not allowed in the sandbox, we reuse the AF_SYSTEM socket
that we're checking. At this point in the flow, we know that it's a
proper AF_SYSTEM one, based on the first sockaddr member; we just don't
know that it's a utun variety.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Sources/WireGuardKit/WireGuardAdapter.swift
Sources/WireGuardKitC/WireGuardKitC.h