add temporary debug printlns

ffi-segfault-fix
Jake McGinty 2021-11-26 00:41:39 +09:00
parent cf04cc0c23
commit 0d50532c9f
2 changed files with 16 additions and 7 deletions

View File

@ -1330,6 +1330,7 @@ static int parse_peers(const struct nlattr *attr, void *data)
if (!ret)
return ret;
if (!(new_peer->flags & WGPEER_HAS_PUBLIC_KEY)) {
printf("netlink validity error: peer doesn't have public key (required)");
errno = ENXIO;
return MNL_CB_ERROR;
}
@ -1415,11 +1416,14 @@ int wg_get_device(wg_device **device, const char *device_name)
try_again:
*device = calloc(1, sizeof(wg_device));
if (!*device)
if (!*device) {
printf("failed to calloc device struct");
return -errno;
}
nlg = mnlg_socket_open(WG_GENL_NAME, WG_GENL_VERSION);
if (!nlg) {
printf("failed to open netlink socket");
wg_free_device(*device);
*device = NULL;
return -errno;
@ -1428,11 +1432,13 @@ try_again:
nlh = mnlg_msg_prepare(nlg, WG_CMD_GET_DEVICE, NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
mnl_attr_put_strz(nlh, WGDEVICE_A_IFNAME, device_name);
if (mnlg_socket_send(nlg, nlh) < 0) {
printf("failed to send netlink request");
ret = -errno;
goto out;
}
errno = 0;
if (mnlg_socket_recv_run(nlg, read_device_cb, *device) < 0) {
printf("failed to receive netlink response");
ret = errno ? -errno : -EINVAL;
goto out;
}
@ -1442,9 +1448,12 @@ out:
if (nlg)
mnlg_socket_close(nlg);
if (ret) {
printf("out: ret was non-zero (%d)", ret);
wg_free_device(*device);
if (ret == -EINTR)
if (ret == -EINTR) {
printf("out: trying again");
goto try_again;
}
*device = NULL;
}
errno = -ret;

View File

@ -243,6 +243,7 @@ fn encode_peers(
*mut wireguard_control_sys::wg_peer,
*mut wireguard_control_sys::wg_peer,
) {
println!("encoding {} peers", peers.len());
let mut first_peer = ptr::null_mut();
let mut last_peer: *mut wireguard_control_sys::wg_peer = ptr::null_mut();
@ -253,10 +254,7 @@ fn encode_peers(
public_key: peer.public_key.0,
preshared_key: wireguard_control_sys::wg_key::default(),
endpoint: encode_endpoint(peer.endpoint),
last_handshake_time: timespec64 {
tv_sec: 0,
tv_nsec: 0,
},
last_handshake_time: timespec64::default(),
tx_bytes: 0,
rx_bytes: 0,
persistent_keepalive_interval: 0,
@ -396,7 +394,9 @@ pub fn get_by_name(name: &InterfaceName) -> Result<Device, io::Error> {
let result = if ret == 0 && !device.is_null() {
Ok(Device::from(unsafe { &*device }))
} else {
Err(io::Error::last_os_error())
let last_error = io::Error::last_os_error();
println!("FFI ret code was {}, &device is {:p}, last OS error: {:?}", ret, device, last_error.raw_os_error());
Err(last_error)
};
unsafe { wireguard_control_sys::wg_free_device(device) };