-
Notifications
You must be signed in to change notification settings - Fork 8
Add --network-id and related host address options
#258
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: main
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 |
|---|---|---|
|
|
@@ -300,6 +300,7 @@ static const char *mode_name(operating_modes_t mode) | |
| // Start interface with the specified operation mode and options. | ||
| static void start_interface_with_options(void) | ||
| { | ||
| char network_id[37] = "(unset)"; | ||
| char interface_id[37] = "(unset)"; | ||
| if (!uuid_is_null(options.interface_id)) { | ||
| uuid_unparse(options.interface_id, interface_id); | ||
|
|
@@ -308,15 +309,22 @@ static void start_interface_with_options(void) | |
| switch (options.operation_mode) { | ||
| case VMNET_SHARED_MODE: | ||
| case VMNET_HOST_MODE: | ||
| if (!uuid_is_null(options.network_id)) { | ||
| uuid_unparse(options.network_id, network_id); | ||
| } | ||
| DEBUGF("[main] starting interface mode '%s' interface-id '%s' " | ||
| "start-address '%s' end-address '%s' subnet-mask '%s' " | ||
| "network-id '%s' host-ip-address '%s' host-subnet-mask '%s' " | ||
| "enable-tso %s enable-checksum-offload %s " | ||
| "enable-isolation %s", | ||
| mode_name(options.operation_mode), | ||
| interface_id, | ||
| options.start_address, | ||
| options.end_address, | ||
| options.subnet_mask, | ||
| network_id, | ||
| options.host_ip_address, | ||
| options.host_subnet_mask, | ||
| bool_str(options.enable_tso), | ||
| bool_str(options.enable_checksum_offload), | ||
| bool_str(options.enable_isolation)); | ||
|
|
@@ -342,13 +350,26 @@ static void start_interface_with_options(void) | |
|
|
||
| switch (options.operation_mode) { | ||
| case VMNET_SHARED_MODE: | ||
| if (options.start_address != NULL) { | ||
| xpc_dictionary_set_string(desc, vmnet_start_address_key, options.start_address); | ||
| xpc_dictionary_set_string(desc, vmnet_end_address_key, options.end_address); | ||
| xpc_dictionary_set_string(desc, vmnet_subnet_mask_key, options.subnet_mask); | ||
| } | ||
| xpc_dictionary_set_bool(desc, vmnet_enable_isolation_key, options.enable_isolation); | ||
| case VMNET_HOST_MODE: | ||
| if (options.start_address != NULL) { | ||
| xpc_dictionary_set_string(desc, vmnet_start_address_key, options.start_address); | ||
| xpc_dictionary_set_string(desc, vmnet_end_address_key, options.end_address); | ||
| xpc_dictionary_set_string(desc, vmnet_subnet_mask_key, options.subnet_mask); | ||
| } | ||
| xpc_dictionary_set_bool(desc, vmnet_enable_isolation_key, options.enable_isolation); | ||
| if (!uuid_is_null(options.network_id)) { | ||
|
Owner
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. We cannot have start_address and network_id, host_ip_* at the same time, right? The code try to handle both at the same time. We can use this to make the intent more clear: |
||
| xpc_dictionary_set_uuid(desc, vmnet_network_identifier_key, options.network_id); | ||
| if (options.host_ip_address != NULL && options.host_subnet_mask != NULL) { | ||
| xpc_dictionary_set_string(desc, vmnet_host_ip_address_key, options.host_ip_address); | ||
| xpc_dictionary_set_string(desc, vmnet_host_subnet_mask_key, options.host_subnet_mask); | ||
| } | ||
| } | ||
| break; | ||
| case VMNET_BRIDGED_MODE: | ||
| xpc_dictionary_set_string(desc, vmnet_shared_interface_name_key, options.shared_interface); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,8 @@ static void usage(int code) | |
| " vmnet-helper (--fd FD|--socket SOCKET) [--interface-id UUID]\n" | ||
| " [--operation-mode shared|bridged|host] [--shared-interface NAME]\n" | ||
| " [--start-address ADDR] [--end-address ADDR] [--subnet-mask MASK]\n" | ||
| " [--network-id UUID] [--host-ip-address ADDR]\n" | ||
| " [--host-subnet-mask MASK]\n" | ||
|
Owner
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. Less keep these in the same line - they are releated. |
||
| " [--enable-tso] [--enable-checksum-offload] [--enable-isolation]\n" | ||
| " [--network NAME] [--list-shared-interfaces]\n" | ||
| " [--stats-interval SECONDS]\n" | ||
|
|
@@ -40,7 +42,8 @@ static void usage(int code) | |
| " With --network, vmnet-helper joins a network managed by vmnet-broker.\n" | ||
| "\n" | ||
| " --network is mutually exclusive with: --operation-mode, --shared-interface,\n" | ||
| " --start-address, --end-address, --subnet-mask.\n" | ||
| " --start-address, --end-address, --subnet-mask, --network-id, --host-ip-address,\n" | ||
| " --host-subnet-mask.\n" | ||
| "\n" | ||
| " --network requires macOS 26 or later.\n" | ||
| "\n"; | ||
|
|
@@ -54,6 +57,9 @@ enum { | |
| OPT_START_ADDRESS, | ||
| OPT_END_ADDRESS, | ||
| OPT_SUBNET_MASK, | ||
| OPT_NETWORK_ID, | ||
| OPT_HOST_IP_ADDRESS, | ||
| OPT_HOST_SUBNET_MASK, | ||
| OPT_ENABLE_TSO, | ||
| OPT_ENABLE_CHECKSUM_OFFLOAD, | ||
| OPT_ENABLE_ISOLATION, | ||
|
|
@@ -74,6 +80,9 @@ static struct option long_options[] = { | |
| {"start-address", required_argument, 0, OPT_START_ADDRESS}, | ||
| {"end-address", required_argument, 0, OPT_END_ADDRESS}, | ||
| {"subnet-mask", required_argument, 0, OPT_SUBNET_MASK}, | ||
| {"network-id", required_argument, 0, OPT_NETWORK_ID}, | ||
| {"host-ip-address", required_argument, 0, OPT_HOST_IP_ADDRESS}, | ||
| {"host-subnet-mask", required_argument, 0, OPT_HOST_SUBNET_MASK}, | ||
| {"enable-tso", no_argument, 0, OPT_ENABLE_TSO}, | ||
| {"enable-checksum-offload", no_argument, 0, OPT_ENABLE_CHECKSUM_OFFLOAD}, | ||
| {"enable-isolation", no_argument, 0, OPT_ENABLE_ISOLATION}, | ||
|
|
@@ -154,6 +163,14 @@ static void parse_interface_id(const char *arg, uuid_t uuid) | |
| } | ||
| } | ||
|
|
||
| static void parse_network_id(const char *arg, uuid_t uuid) | ||
| { | ||
| if (uuid_parse(arg, uuid) < 0) { | ||
| ERRORF("Invalid network-id: \"%s\"", arg); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| } | ||
|
|
||
| static void parse_operation_mode(const char *arg, const char *name, uint32_t *mode) | ||
| { | ||
| if (strcmp(arg, "shared") == 0) { | ||
|
|
@@ -205,6 +222,25 @@ static void validate_network_options(struct options *opts) | |
| } | ||
| } | ||
|
|
||
| static void validate_network_id_options(struct options *opts) | ||
| { | ||
| int host_address_options_set = (opts->host_ip_address != NULL) + (opts->host_subnet_mask != NULL); | ||
| int dhcp_options_set = (opts->start_address != NULL) + (opts->end_address != NULL) + | ||
| (opts->subnet_mask != NULL); | ||
| if (host_address_options_set != 0 && uuid_is_null(opts->network_id)) { | ||
| ERROR("--host-ip-address and --host-subnet-mask require --network-id"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| if (host_address_options_set != 0 && host_address_options_set != 2) { | ||
| ERROR("--host-ip-address and --host-subnet-mask must be given together, or all omitted"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| if (!uuid_is_null(opts->network_id) && dhcp_options_set != 0) { | ||
| ERROR("--network-id cannot be used with --start-address, --end-address, --subnet-mask"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| } | ||
|
|
||
| void parse_options(struct options *opts, int argc, char **argv) | ||
| { | ||
| const char *optname; | ||
|
|
@@ -248,6 +284,15 @@ void parse_options(struct options *opts, int argc, char **argv) | |
| case OPT_SUBNET_MASK: | ||
| parse_address(optarg, optname, &opts->subnet_mask); | ||
| break; | ||
| case OPT_NETWORK_ID: | ||
| parse_network_id(optarg, opts->network_id); | ||
| break; | ||
| case OPT_HOST_IP_ADDRESS: | ||
| parse_address(optarg, optname, &opts->host_ip_address); | ||
| break; | ||
| case OPT_HOST_SUBNET_MASK: | ||
| parse_address(optarg, optname, &opts->host_subnet_mask); | ||
| break; | ||
| case OPT_ENABLE_TSO: | ||
| opts->enable_tso = true; | ||
| break; | ||
|
|
@@ -304,6 +349,18 @@ void parse_options(struct options *opts, int argc, char **argv) | |
| ERROR("Conflicting arguments: --network cannot be used with --subnet-mask"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| if (!uuid_is_null(opts->network_id)) { | ||
| ERROR("Conflicting arguments: --network cannot be used with --network-id"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| if (opts->host_ip_address != NULL) { | ||
| ERROR("Conflicting arguments: --network cannot be used with --host-ip-address"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| if (opts->host_subnet_mask != NULL) { | ||
| ERROR("Conflicting arguments: --network cannot be used with --host-subnet-mask"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| } else { | ||
| // Apply defaults and validate when not using vmnet-broker network. | ||
| if (opts->operation_mode == 0) { | ||
|
|
@@ -312,10 +369,37 @@ void parse_options(struct options *opts, int argc, char **argv) | |
|
|
||
| switch (opts->operation_mode) { | ||
| case VMNET_SHARED_MODE: | ||
| validate_network_options(opts); | ||
| if (!uuid_is_null(opts->network_id)) { | ||
| ERROR("--network-id cannot be used with operation-mode=shared"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| if (opts->host_ip_address != NULL) { | ||
| ERROR("--host-ip-address cannot be used with operation-mode=shared"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| if (opts->host_subnet_mask != NULL) { | ||
| ERROR("--host-subnet-mask cannot be used with operation-mode=shared"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| break; | ||
| case VMNET_HOST_MODE: | ||
| validate_network_options(opts); | ||
| validate_network_id_options(opts); | ||
| break; | ||
| case VMNET_BRIDGED_MODE: | ||
| if (!uuid_is_null(opts->network_id)) { | ||
| ERROR("--network-id cannot be used with operation-mode=bridged"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| if (opts->host_ip_address != NULL) { | ||
| ERROR("--host-ip-address cannot be used with operation-mode=bridged"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| if (opts->host_subnet_mask != NULL) { | ||
| ERROR("--host-subnet-mask cannot be used with operation-mode=bridged"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| if (opts->shared_interface == NULL) { | ||
| ERROR("Missing argument: shared-interface is required for operation-mode=bridged"); | ||
| exit(EXIT_FAILURE); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.