-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Allow specifying vmnet network UUID to disable DHCP (when in Host mode) #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,27 +12,28 @@ Unlike `vde_vmnet`, `socket_vmnet` does not depend on VDE. | |
| <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
| <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
|
|
||
| - [Install](#install) | ||
| - [From binary](#from-binary) | ||
| - [From source](#from-source) | ||
| - [From Homebrew](#from-homebrew) | ||
| - [From MacPorts](#from-macports) | ||
| - [Usage](#usage) | ||
| - [QEMU](#qemu) | ||
| - [Lima](#lima) | ||
| - [Advanced usage](#advanced-usage) | ||
| - [Multi VM](#multi-vm) | ||
| - [Bridged mode](#bridged-mode) | ||
| - [FAQs](#faqs) | ||
| - [Why does `socket_vmnet` require root?](#why-does-socket_vmnet-require-root) | ||
| - [Is it possible to run `socket_vmnet` with SETUID?](#is-it-possible-to-run-socket_vmnet-with-setuid) | ||
| - [Install](#install) | ||
| - [From binary](#from-binary) | ||
| - [From source](#from-source) | ||
| - [From Homebrew](#from-homebrew) | ||
| - [From MacPorts](#from-macports) | ||
| - [Usage](#usage) | ||
| - [QEMU](#qemu) | ||
| - [Lima](#lima) | ||
| - [Advanced usage](#advanced-usage) | ||
| - [Multi VM](#multi-vm) | ||
| - [Bridged mode](#bridged-mode) | ||
| - [FAQs](#faqs) | ||
| - [Why does `socket_vmnet` require root?](#why-does-socket_vmnet-require-root) | ||
| - [Is it possible to run `socket_vmnet` with SETUID?](#is-it-possible-to-run-socket_vmnet-with-setuid) | ||
| - [How is socket_vmnet related to vde_vmnet?](#how-is-socket_vmnet-related-to-vde_vmnet) | ||
| - [How is socket_vmnet related to QEMU-builtin vmnet support?](#how-is-socket_vmnet-related-to-qemu-builtin-vmnet-support) | ||
| - [How to use static IP addresses?](#how-to-use-static-ip-addresses) | ||
| - [How to reserve DHCP addresses?](#how-to-reserve-dhcp-addresses) | ||
| - [IP address is not assigned](#ip-address-is-not-assigned) | ||
| - [Links](#links) | ||
| - [Troubleshooting](#troubleshooting) | ||
| - [How is socket_vmnet related to QEMU-builtin vmnet support?](#how-is-socket_vmnet-related-to-qemu-builtin-vmnet-support) | ||
| - [How to use static IP addresses?](#how-to-use-static-ip-addresses) | ||
| - [How to reserve DHCP addresses?](#how-to-reserve-dhcp-addresses) | ||
| - [IP address is not assigned](#ip-address-is-not-assigned) | ||
| - [How to setup a vmnet host network without DHCP?](#how-to-setup-a-vmnet-host-network-without-dhcp) | ||
| - [Links](#links) | ||
| - [Troubleshooting](#troubleshooting) | ||
pallotron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new toc looks wrong. This was not part of the top before: And the rest of the options are over indented now. You should should be only: Maybe the instructions for running doctor are not correct, or you are running a different version? Lets separate the README.md change to another PR. We ned to find how to update the README.md without adding unwanted changes. |
||
| <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
|
||
|
|
@@ -122,7 +123,7 @@ Run the following command to start the daemon: | |
| sudo /opt/socket_vmnet/bin/socket_vmnet --vmnet-gateway=192.168.105.1 /var/run/socket_vmnet | ||
| ``` | ||
|
|
||
| > [!TIP] | ||
| > [!TIP] | ||
| > `sudo make install` is also available in addition to `sudo make install.bin`. | ||
| > The former one installs the launchd service (see below) too. | ||
|
|
||
|
|
@@ -430,6 +431,20 @@ sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /usr/libexec/bootpd | |
| /usr/libexec/ApplicationFirewall/socketfilterfw --unblock /usr/libexec/bootpd | ||
| ``` | ||
|
|
||
| ### How to setup a vmnet host network without DHCP? | ||
|
|
||
| Some users may need to disable the vmnet framework's DHCP for various scenarios, such as: | ||
|
|
||
| - Create a host network where all VMs have static IPs. | ||
| - Run a custom DHCP server on one VM to assign IPs to others on the same network. | ||
|
|
||
| Disabling macOS DHCP only works in `--vmnet-mode=host` if you provide a `--vmnet-network-idenfitier`. | ||
| For example, to create a host network without DHCP on `socket_vmnet`: | ||
|
|
||
| ```bash | ||
| sudo /opt/socket_vmnet/bin/socket_vmnet --vmnet-mode=host --vmnet-network-identifier=$(uuidgen) | ||
| ``` | ||
|
|
||
| ## Links | ||
|
|
||
| - https://developer.apple.com/documentation/vmnet | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,12 @@ static void print_usage(const char *argv0) { | |
| "specified\n"); | ||
| printf("--vmnet-interface-id=UUID vmnet interface ID (default: " | ||
| "random)\n"); | ||
| printf("--vmnet-network-identifier=UUID The identifier(uuid) to uniquely identify the network. \n" | ||
| " This property is only applicable to a vmnet_interface\n" | ||
| " in VMNET_HOST_MODE.\n" | ||
| " If this property is set, the vmnet_interface is added to \n" | ||
| " an isolated network with the specified\n" | ||
| " identifier. No DHCP service is provided on this network.\n"); | ||
| printf("--vmnet-nat66-prefix=PREFIX:: The IPv6 prefix to use with " | ||
| "shared mode.\n"); | ||
| printf(" The prefix must be a ULA i.e. " | ||
|
|
@@ -72,6 +78,7 @@ enum { | |
| CLI_OPT_VMNET_MASK, | ||
| CLI_OPT_VMNET_INTERFACE_ID, | ||
| CLI_OPT_VMNET_NAT66_PREFIX, | ||
| CLI_OPT_VMNET_NETWORK_IDENTIFIER, | ||
| }; | ||
|
|
||
| struct cli_options *cli_options_parse(int argc, char *argv[]) { | ||
|
|
@@ -82,18 +89,19 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) { | |
| } | ||
|
|
||
| const struct option longopts[] = { | ||
| {"socket-group", required_argument, NULL, CLI_OPT_SOCKET_GROUP }, | ||
| {"vmnet-mode", required_argument, NULL, CLI_OPT_VMNET_MODE }, | ||
| {"vmnet-interface", required_argument, NULL, CLI_OPT_VMNET_INTERFACE }, | ||
| {"vmnet-gateway", required_argument, NULL, CLI_OPT_VMNET_GATEWAY }, | ||
| {"vmnet-dhcp-end", required_argument, NULL, CLI_OPT_VMNET_DHCP_END }, | ||
| {"vmnet-mask", required_argument, NULL, CLI_OPT_VMNET_MASK }, | ||
| {"vmnet-interface-id", required_argument, NULL, CLI_OPT_VMNET_INTERFACE_ID}, | ||
| {"vmnet-nat66-prefix", required_argument, NULL, CLI_OPT_VMNET_NAT66_PREFIX}, | ||
| {"pidfile", required_argument, NULL, 'p' }, | ||
| {"help", no_argument, NULL, 'h' }, | ||
| {"version", no_argument, NULL, 'v' }, | ||
| {0, 0, 0, 0 }, | ||
| {"socket-group", required_argument, NULL, CLI_OPT_SOCKET_GROUP }, | ||
| {"vmnet-mode", required_argument, NULL, CLI_OPT_VMNET_MODE }, | ||
| {"vmnet-interface", required_argument, NULL, CLI_OPT_VMNET_INTERFACE }, | ||
| {"vmnet-gateway", required_argument, NULL, CLI_OPT_VMNET_GATEWAY }, | ||
| {"vmnet-dhcp-end", required_argument, NULL, CLI_OPT_VMNET_DHCP_END }, | ||
| {"vmnet-mask", required_argument, NULL, CLI_OPT_VMNET_MASK }, | ||
| {"vmnet-interface-id", required_argument, NULL, CLI_OPT_VMNET_INTERFACE_ID }, | ||
| {"vmnet-nat66-prefix", required_argument, NULL, CLI_OPT_VMNET_NAT66_PREFIX }, | ||
| {"vmnet-network-identifier", required_argument, NULL, CLI_OPT_VMNET_NETWORK_IDENTIFIER}, | ||
| {"pidfile", required_argument, NULL, 'p' }, | ||
| {"help", no_argument, NULL, 'h' }, | ||
| {"version", no_argument, NULL, 'v' }, | ||
| {0, 0, 0, 0 }, | ||
| }; | ||
| int opt = 0; | ||
| while ((opt = getopt_long(argc, argv, "hvp:", longopts, NULL)) != -1) { | ||
|
|
@@ -134,6 +142,12 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) { | |
| case CLI_OPT_VMNET_NAT66_PREFIX: | ||
| res->vmnet_nat66_prefix = strdup(optarg); | ||
| break; | ||
| case CLI_OPT_VMNET_NETWORK_IDENTIFIER: | ||
| if (uuid_parse(optarg, res->vmnet_network_identifier) < 0) { | ||
| ERRORF("Failed to parse network identifier UUID \"%s\"", optarg); | ||
| goto error; | ||
| } | ||
| break; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets replace the section with: case CLI_OPT_VMNET_NETWORK_IDENTIFIER:
if (uuid_parse(optarg, res->vmnet_network_identifier) < 0) {
ERRORF("Failed to parse UUID \"%s\"", optarg);
goto error;
}
break; |
||
| case 'p': | ||
| res->pidfile = strdup(optarg); | ||
| break; | ||
|
|
@@ -191,7 +205,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) { | |
| goto error; | ||
| } | ||
| if (res->vmnet_gateway == NULL) { | ||
| if (res->vmnet_mode != VMNET_BRIDGED_MODE) { | ||
| if (res->vmnet_mode != VMNET_BRIDGED_MODE && res->vmnet_mode != VMNET_HOST_MODE) { | ||
| WARN("--vmnet-gateway=IP should be explicitly specified to " | ||
| "avoid conflicting with other applications"); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,6 +230,11 @@ static interface_ref start(struct state *state, struct cli_options *cliopt) { | |
| INFOF("Using network interface \"%s\"", cliopt->vmnet_interface); | ||
| xpc_dictionary_set_string(dict, vmnet_shared_interface_name_key, cliopt->vmnet_interface); | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be better to keep the block setting the gateway address as is. vmnet docs do not mention that you must not use gateway address and network identifier together, and the purpose of the new flag is not to disable DHCP, but to expose additional vment option, that can be used to disable DHCP. |
||
| if (!uuid_is_null(cliopt->vmnet_network_identifier)) { | ||
| xpc_dictionary_set_uuid(dict, vmnet_network_identifier_key, cliopt->vmnet_network_identifier); | ||
| } | ||
|
|
||
| if (cliopt->vmnet_gateway != NULL) { | ||
| xpc_dictionary_set_string(dict, vmnet_start_address_key, cliopt->vmnet_gateway); | ||
| xpc_dictionary_set_string(dict, vmnet_end_address_key, cliopt->vmnet_dhcp_end); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.