23bf3cfccb
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>
21 lines
457 B
C
21 lines
457 B
C
// SPDX-License-Identifier: MIT
|
|
// Copyright © 2018-2020 WireGuard LLC. All Rights Reserved.
|
|
|
|
#include "key.h"
|
|
#include "x25519.h"
|
|
|
|
/* From <sys/kern_control.h> */
|
|
#define CTLIOCGINFO 0xc0644e03UL
|
|
struct ctl_info {
|
|
u_int32_t ctl_id;
|
|
char ctl_name[96];
|
|
};
|
|
struct sockaddr_ctl {
|
|
u_char sc_len;
|
|
u_char sc_family;
|
|
u_int16_t ss_sysaddr;
|
|
u_int32_t sc_id;
|
|
u_int32_t sc_unit;
|
|
u_int32_t sc_reserved[5];
|
|
};
|