]> tinc-vpn.org Git - tinc/commitdiff
Fixes
authorEric Karge <eric.karge@innoq.com>
Fri, 11 Oct 2024 14:21:26 +0000 (16:21 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Mon, 30 Mar 2026 20:32:34 +0000 (22:32 +0200)
- Fix file description
- Fix some log messages
- Fix formatting and typos

src/bsd/darwin/vmnet.c
src/bsd/darwin/vmnet.h
src/bsd/device.c

index 5eceba201f257e50b3d29cf8b01c9872ed54dc34..74196e8b1780ca499ddc905b6c4b5e76dabf7ced 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  vmnet - Tun device emulation for Darwin
+ *  vmnet - macOS vmnet device support
  *  Copyright (C) 2024 Eric Karge
  *
  *  This program is free software: you can redistribute it and/or modify
@@ -38,7 +38,7 @@ static void macos_vmnet_read(void);
 static const char *str_vmnet_status(vmnet_return_t status);
 
 int macos_vmnet_open(void) {
-       if (socketpair(AF_UNIX, SOCK_DGRAM, 0, read_socket)) {
+       if(socketpair(AF_UNIX, SOCK_DGRAM, 0, read_socket)) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Unable to create socket: %s", strerror(errno));
                return -1;
        }
@@ -55,7 +55,7 @@ int macos_vmnet_open(void) {
                if_desc, if_queue,
                ^(vmnet_return_t status, xpc_object_t interface_param) {
                        if_status = status;
-                       if (status == VMNET_SUCCESS && interface_param) {
+                       if(status == VMNET_SUCCESS && interface_param) {
                                max_packet_size = xpc_dictionary_get_uint64(interface_param, vmnet_max_packet_size_key);
                        }
                        dispatch_semaphore_signal(if_started_sem);
@@ -83,7 +83,7 @@ int macos_vmnet_open(void) {
 }
 
 int macos_vmnet_close(int fd) {
-       if (vmnet_if == NULL || fd != read_socket[0]) {
+       if(vmnet_if == NULL || fd != read_socket[0]) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Unable to close vmnet device: device not setup properly");
                return -1;
        }
@@ -100,7 +100,7 @@ int macos_vmnet_close(int fd) {
        dispatch_semaphore_wait(if_stopped_sem, DISPATCH_TIME_FOREVER);
        dispatch_release(if_stopped_sem);
 
-       if (if_status != VMNET_SUCCESS) {
+       if(if_status != VMNET_SUCCESS) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Unable to close vmnet device: %s", str_vmnet_status(if_status));
                return -1;
        }
@@ -119,7 +119,7 @@ int macos_vmnet_close(int fd) {
 }
 
 void macos_vmnet_read(void) {
-    if (if_status != VMNET_SUCCESS) {
+    if(if_status != VMNET_SUCCESS) {
         return;
     }
 
@@ -132,17 +132,17 @@ void macos_vmnet_read(void) {
     };
 
     if_status = vmnet_read(vmnet_if, &packet, &pkt_count);
-    if (if_status != VMNET_SUCCESS) {
+    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 iov_out = {
+    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], &iov_out, 1) < 0) {
+        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;
         }
@@ -150,7 +150,7 @@ void macos_vmnet_read(void) {
 }
 
 ssize_t macos_vmnet_write(uint8_t *buffer, size_t buflen) {
-       if (buflen > max_packet_size) {
+       if(buflen > max_packet_size) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Max packet size (%zd) exceeded: %zd", max_packet_size, buflen);
                return -1;
        }
@@ -168,12 +168,12 @@ ssize_t macos_vmnet_write(uint8_t *buffer, size_t buflen) {
        int pkt_count = 1;
 
        vmnet_return_t result = vmnet_write(vmnet_if, &packet, &pkt_count);
-       if (result != VMNET_SUCCESS) {
+       if(result != VMNET_SUCCESS) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Write failed: %s", str_vmnet_status(result));
                return -1;
        }
 
-       return pkt_count ? buflen : 00;
+       return pkt_count ? buflen : 0;
 }
 
 const char *str_vmnet_status(vmnet_return_t status) {
index 39360e7f1d88f9b6f3d4e35be526c1e4a7ecde28..87b8382336e93ce73d51dbd8e61ca859a2ac7bf5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  vmnet - Tun device emulation for Darwin
+ *  vmnet - macOS vmnet device support
  *  Copyright (C) 2024 Eric Karge
  *
  *  This program is free software: you can redistribute it and/or modify
index af6274702b62f95c0c415f148f21ecdb52a616f5..84357fd23de0980b24da6cdfff5d4c050b4f058f 100644 (file)
@@ -187,15 +187,18 @@ static bool setup_device(void) {
                        }
        }
 
-       if(routing_mode == RMODE_SWITCH
-               && device_type != DEVICE_TYPE_TAP
 #ifdef ENABLE_VMNET
-               && device_type != DEVICE_TYPE_VMNET
-#endif
-       ) {
+       if(routing_mode == RMODE_SWITCH
+               && device_type != DEVICE_TYPE_TAP && device_type != DEVICE_TYPE_VMNET) {
+               logger(DEBUG_ALWAYS, LOG_ERR, "Only vmnet and tap devices support switch mode!");
+               return false;
+       }
+#else
+       if(routing_mode == RMODE_SWITCH && device_type != DEVICE_TYPE_TAP) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Only tap devices support switch mode!");
                return false;
        }
+#endif
 
        // Find out which device file to open
 
@@ -557,8 +560,6 @@ static bool write_packet(vpn_packet_t *packet) {
 
        case DEVICE_TYPE_VMNET:
                if(macos_vmnet_write(DATA(packet), packet->len) < 0) {
-                       logger(DEBUG_ALWAYS, LOG_ERR, "Error while writing to %s %s: %s", device_info,
-                              device, strerror(errno));
                        return false;
                }