From: Guus Sliepen Date: Mon, 30 Mar 2026 21:20:53 +0000 (+0200) Subject: Fix more clang-tidy warnings X-Git-Url: https://www.tinc-vpn.org/git/?a=commitdiff_plain;h=e415bb5cf0ea787148f6e7dc76d3bd0b6fd4b7ec;p=tinc Fix more clang-tidy warnings --- diff --git a/src/bsd/darwin/vmnet.c b/src/bsd/darwin/vmnet.c index d46e9c29..1a35fade 100644 --- a/src/bsd/darwin/vmnet.c +++ b/src/bsd/darwin/vmnet.c @@ -34,8 +34,75 @@ static size_t max_packet_size; static struct iovec read_iov_in; static int read_socket[2]; -static void macos_vmnet_read(void); -static const char *str_vmnet_status(vmnet_return_t status); +static const char *str_vmnet_status(vmnet_return_t status) { + switch(status) { + case VMNET_SUCCESS: + return "success"; + + case VMNET_FAILURE: + return "general failure (possibly not enough privileges)"; + + case VMNET_MEM_FAILURE: + return "memory allocation failure"; + + case VMNET_INVALID_ARGUMENT: + return "invalid argument specified"; + + case VMNET_SETUP_INCOMPLETE: + return "interface setup is not complete"; + + case VMNET_INVALID_ACCESS: + return "invalid access, permission denied"; + + case VMNET_PACKET_TOO_BIG: + return "packet size is larger than MTU"; + + case VMNET_BUFFER_EXHAUSTED: + return "buffers exhausted in kernel"; + + case VMNET_TOO_MANY_PACKETS: + return "packet count exceeds limit"; + + case VMNET_SHARING_SERVICE_BUSY: + return "conflict, sharing service is in use"; + + default: + return "unknown vmnet error"; + } +} + +static void macos_vmnet_read(void) { + if(if_status != VMNET_SUCCESS) { + return; + } + + int pkt_count = 1; + struct vmpktdesc packet = { + .vm_flags = 0, + .vm_pkt_size = max_packet_size, + .vm_pkt_iov = &read_iov_in, + .vm_pkt_iovcnt = 1, + }; + + if_status = vmnet_read(vmnet_if, &packet, &pkt_count); + + if(if_status != VMNET_SUCCESS) { + logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read packet: %s", str_vmnet_status(if_status)); + return; + } + + if(pkt_count && packet.vm_pkt_iovcnt) { + struct iovec read_iov_out = { + .iov_base = packet.vm_pkt_iov->iov_base, + .iov_len = packet.vm_pkt_size, + }; + + if(writev(read_socket[1], &read_iov_out, 1) < 0) { + logger(DEBUG_ALWAYS, LOG_ERR, "Unable to write to read socket: %s", strerror(errno)); + return; + } + } +} int macos_vmnet_open(const char device[]) { if(socketpair(AF_UNIX, SOCK_DGRAM, 0, read_socket)) { @@ -156,39 +223,6 @@ int macos_vmnet_close(int fd) { return 0; } -void macos_vmnet_read(void) { - if(if_status != VMNET_SUCCESS) { - return; - } - - int pkt_count = 1; - struct vmpktdesc packet = { - .vm_flags = 0, - .vm_pkt_size = max_packet_size, - .vm_pkt_iov = &read_iov_in, - .vm_pkt_iovcnt = 1, - }; - - if_status = vmnet_read(vmnet_if, &packet, &pkt_count); - - if(if_status != VMNET_SUCCESS) { - logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read packet: %s", str_vmnet_status(if_status)); - return; - } - - if(pkt_count && packet.vm_pkt_iovcnt) { - struct iovec read_iov_out = { - .iov_base = packet.vm_pkt_iov->iov_base, - .iov_len = packet.vm_pkt_size, - }; - - if(writev(read_socket[1], &read_iov_out, 1) < 0) { - logger(DEBUG_ALWAYS, LOG_ERR, "Unable to write to read socket: %s", strerror(errno)); - return; - } - } -} - ssize_t macos_vmnet_write(uint8_t *buffer, size_t buflen) { if(buflen > max_packet_size) { logger(DEBUG_ALWAYS, LOG_ERR, "Max packet size (%zd) exceeded: %zd", max_packet_size, buflen); @@ -218,40 +252,3 @@ ssize_t macos_vmnet_write(uint8_t *buffer, size_t buflen) { return pkt_count ? buflen : 0; } - -const char *str_vmnet_status(vmnet_return_t status) { - switch(status) { - case VMNET_SUCCESS: - return "success"; - - case VMNET_FAILURE: - return "general failure (possibly not enough privileges)"; - - case VMNET_MEM_FAILURE: - return "memory allocation failure"; - - case VMNET_INVALID_ARGUMENT: - return "invalid argument specified"; - - case VMNET_SETUP_INCOMPLETE: - return "interface setup is not complete"; - - case VMNET_INVALID_ACCESS: - return "invalid access, permission denied"; - - case VMNET_PACKET_TOO_BIG: - return "packet size is larger than MTU"; - - case VMNET_BUFFER_EXHAUSTED: - return "buffers exhausted in kernel"; - - case VMNET_TOO_MANY_PACKETS: - return "packet count exceeds limit"; - - case VMNET_SHARING_SERVICE_BUSY: - return "conflict, sharing service is in use"; - - default: - return "unknown vmnet error"; - } -} diff --git a/test/unit/test_net.c b/test/unit/test_net.c index 36cfc1ee..9e56ee30 100644 --- a/test/unit/test_net.c +++ b/test/unit/test_net.c @@ -4,6 +4,7 @@ static environment_t *device_env = NULL; +// NOLINTBEGIN(misc-use-internal-linkage) void __wrap_environment_init(environment_t *env) { assert_non_null(env); assert_null(device_env); @@ -23,6 +24,7 @@ bool __wrap_execute_script(const char *name, environment_t *env) { // Used instead of mock_type(bool) to silence clang warning return mock() ? true : false; } +// NOLINTEND(misc-use-internal-linkage) static void run_device_enable_disable(void (*device_func)(void), const char *script) {