Skip to content

Commit df1f00b

Browse files
committed
Better logic + esplicitely printing when DHCP is going to be disabled
1 parent 20d8ee1 commit df1f00b

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,20 +393,13 @@ On the other hand, `socket_vmnet` does not require the entire QEMU process to ru
393393

394394
### How to use static IP addresses?
395395

396-
Two options:
397-
398-
#### By using a shorter DHCP range
399396
When `--vmnet-gateway=IP` is set to "192.168.105.1", the whole subnet (192.168.105.2-192.168.105.254) is used as the DHCP range.
400397

401398
To use static IP addresses, limit the DHCP range with `--vmnet-dhcp-end=IP`.
402399

403400
For example, `--vmnet-gateway=192.168.105.1 --vmnet-dhcp-end=192.168.105.100` allows using `192.168.105.101-192.168.105.254`
404401
as non-DHCP static addresses.
405402

406-
#### By setting up network UUID (only in vmnet.host mode)
407-
408-
When `--vmnet-mode=host` and `--vmnet-network-uuid` are set, the internal DHCP is disabled and you are free to use static IP addresses. You still need to set `--vmnet-gateway=IP` to avoid collision with other vmnet networks.
409-
410403
### How to reserve DHCP addresses?
411404

412405
- Decide a unique MAC address for the VM, e.g. `de:ad:be:ef:00:01`.
@@ -443,6 +436,15 @@ sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /usr/libexec/bootpd
443436
/usr/libexec/ApplicationFirewall/socketfilterfw --unblock /usr/libexec/bootpd
444437
```
445438

439+
### How to setup a vmnet host network without DHCP
440+
441+
You may need to disable the vmnet framework's DHCP to:
442+
- Create a host network where all VMs have static IPs.
443+
- Run a custom DHCP server on one VM to assign IPs to others on the same network.
444+
445+
To disable the internal DHCP, use `--vmnet-mode=host` without `--vmnet-gateway`. This allows you to use static IP addresses for your VMs.
446+
You can optionally provide a `--vmnet-network-uuid`.
447+
446448
## Links
447449

448450
- https://developer.apple.com/documentation/vmnet

cli.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ static void print_usage(const char *argv0) {
4848
"specified\n");
4949
printf("--vmnet-interface-id=UUID vmnet interface ID (default: "
5050
"random)\n");
51-
printf("--vmnet-network-uuid=UUID vmnet network UUID (default: "
52-
"random)\n");
53-
printf("--vmnet-network-uuid=UUID vmnet network UUID, if provided in \"host\" vmnet mode the\n"
51+
printf("--vmnet-network-uuid=UUID vmnet network UUID, if provided in \"host\" vmnet mode withouht --vmnet-gateway, the\n"
5452
" internal DHCP will be disabled (default: " "random)\n");
5553
printf("--vmnet-nat66-prefix=PREFIX:: The IPv6 prefix to use with "
5654
"shared mode.\n");
@@ -207,7 +205,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
207205
goto error;
208206
}
209207
if (res->vmnet_gateway == NULL) {
210-
if (res->vmnet_mode != VMNET_BRIDGED_MODE) {
208+
if (res->vmnet_mode != VMNET_BRIDGED_MODE && res->vmnet_mode != VMNET_HOST_MODE) {
211209
WARN("--vmnet-gateway=IP should be explicitly specified to "
212210
"avoid conflicting with other applications");
213211
}

main.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,23 @@ static interface_ref start(struct state *state, struct cli_options *cliopt) {
230230
INFOF("Using network interface \"%s\"", cliopt->vmnet_interface);
231231
xpc_dictionary_set_string(dict, vmnet_shared_interface_name_key, cliopt->vmnet_interface);
232232
}
233-
if (cliopt->vmnet_gateway != NULL) {
234-
xpc_dictionary_set_string(dict, vmnet_start_address_key, cliopt->vmnet_gateway);
235-
xpc_dictionary_set_string(dict, vmnet_end_address_key, cliopt->vmnet_dhcp_end);
236-
xpc_dictionary_set_string(dict, vmnet_subnet_mask_key, cliopt->vmnet_mask);
237-
}
238233

239-
xpc_dictionary_set_uuid(dict, vmnet_interface_id_key, cliopt->vmnet_interface_id);
240-
if (cliopt->vmnet_mode == VMNET_HOST_MODE) {
234+
// no dhcp
235+
if (cliopt->vmnet_mode == VMNET_HOST_MODE && cliopt->vmnet_gateway == NULL) {
241236
xpc_dictionary_set_uuid(dict, vmnet_network_identifier_key, cliopt->vmnet_network_uuid);
237+
uuid_string_t uuid_str;
238+
uuid_unparse(cliopt->vmnet_network_uuid, uuid_str);
239+
INFOF("Using network identifier \"%s\" and no vmnet gateway -> NO DHCP will be enabled on this vmnet", uuid_str);
240+
} else {
241+
if (cliopt->vmnet_gateway != NULL) {
242+
xpc_dictionary_set_string(dict, vmnet_start_address_key, cliopt->vmnet_gateway);
243+
xpc_dictionary_set_string(dict, vmnet_end_address_key, cliopt->vmnet_dhcp_end);
244+
xpc_dictionary_set_string(dict, vmnet_subnet_mask_key, cliopt->vmnet_mask);
245+
}
242246
}
243247

248+
xpc_dictionary_set_uuid(dict, vmnet_interface_id_key, cliopt->vmnet_interface_id);
249+
244250
if (cliopt->vmnet_nat66_prefix != NULL) {
245251
xpc_dictionary_set_string(dict, vmnet_nat66_prefix_key, cliopt->vmnet_nat66_prefix);
246252
}

0 commit comments

Comments
 (0)