]> tinc-vpn.org Git - tinc/commitdiff
Fix more clang-tidy warnings
authorGuus Sliepen <guus@tinc-vpn.org>
Mon, 30 Mar 2026 21:20:53 +0000 (23:20 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Mon, 30 Mar 2026 21:20:53 +0000 (23:20 +0200)
src/bsd/darwin/vmnet.c
test/unit/test_net.c

index d46e9c29a2ab52146541273cb3c858d318e4127d..1a35fade89a5aac2a2124313a494ee332a060ddd 100644 (file)
@@ -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";
-       }
-}
index 36cfc1eef7d068658fb4dc4825b0527daa352288..9e56ee301a5f1b8e2662a3c09f699eaf457927be 100644 (file)
@@ -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) {