Skip to content

Commit c49d5b0

Browse files
committed
feat: Allow specifying vmnet network UUID to disable DHCP (on vmnet.host network only)
This commit introduces a new `--vmnet-network-uuid` command-line option to allow setting the `vmnet_network_identifier_key` for vmnet. This property is only applicable to a vmnet_interface in VMNET_HOST_MODE. If this property is set, the vmnet_interface is added to an isolated network with the specified identifier. No DHCP service is provided on this network. This is useful for certain applications where the users need an isolated network and are running their own dhcp to assign IPs in such network. See issue [#139](#139) ``` ❯ sudo ./socket_vmnet "/opt/homebrew/var/run/socket_vmnet" --vmnet-mode=host --vmnet-gateway=192.168.100.1 --vmnet-network-uuid=99eddb74-3193-48e3-bafb-b3ca99e949c1 Password: INFO | Initializing vmnet.framework (mode 1000) INFO | * vmnet_write_max_packets: 256 INFO | * vmnet_read_max_packets: 256 INFO | * vmnet_subnet_mask: 0.0.0.0 INFO | * vmnet_mtu: 1500 INFO | * vmnet_end_address: 255.255.255.254 INFO | * vmnet_start_address: 0.0.0.0 INFO | * vmnet_interface_id: 0E21C1D4-43D9-4363-B767-A64FE591EA7D INFO | * vmnet_max_packet_size: 1514 INFO | * vmnet_mac_address: 66:77:98:e1:52:9c ``` I could run my LAB vms, I saw no DHCP been handed over by MacOS/bootp, my Lab runs a special VM with DHCPD and I saw that not colliding. ``` ❯ sudo ./socket_vmnet "/opt/homebrew/var/run/socket_vmnet" --vmnet-gateway=192.168.100.1 --vmnet-network-uuid=99eddb74-3193-48e3-bafb-b3ca99e949c1 INFO | Initializing vmnet.framework (mode 1001) INFO | * vmnet_write_max_packets: 256 INFO | * vmnet_read_max_packets: 256 INFO | * vmnet_subnet_mask: 255.255.255.0 INFO | * vmnet_mtu: 1500 INFO | * vmnet_end_address: 192.168.100.254 INFO | * vmnet_start_address: 192.168.100.1 INFO | * vmnet_interface_id: 99AC02F6-59D3-4192-820B-C8DAED0F2B81 INFO | * vmnet_max_packet_size: 1514 INFO | * vmnet_nat66_prefix: fd86:9a96:2682:1344:: INFO | * vmnet_mac_address: 3a:be:d4:0d:33:11 ``` Signed-off-by: Angelo Failla <[email protected]>
1 parent a7cc880 commit c49d5b0

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

cli.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ 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"
54+
" internal DHCP will be disabled (default: " "random)\n");
5155
printf("--vmnet-nat66-prefix=PREFIX:: The IPv6 prefix to use with "
5256
"shared mode.\n");
5357
printf(" The prefix must be a ULA i.e. "
@@ -72,6 +76,7 @@ enum {
7276
CLI_OPT_VMNET_MASK,
7377
CLI_OPT_VMNET_INTERFACE_ID,
7478
CLI_OPT_VMNET_NAT66_PREFIX,
79+
CLI_OPT_VMNET_NETWORK_UUID,
7580
};
7681

7782
struct cli_options *cli_options_parse(int argc, char *argv[]) {
@@ -80,6 +85,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
8085
ERRORN("calloc");
8186
exit(EXIT_FAILURE);
8287
}
88+
uuid_clear(res->vmnet_network_uuid);
8389

8490
const struct option longopts[] = {
8591
{"socket-group", required_argument, NULL, CLI_OPT_SOCKET_GROUP },
@@ -90,6 +96,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
9096
{"vmnet-mask", required_argument, NULL, CLI_OPT_VMNET_MASK },
9197
{"vmnet-interface-id", required_argument, NULL, CLI_OPT_VMNET_INTERFACE_ID},
9298
{"vmnet-nat66-prefix", required_argument, NULL, CLI_OPT_VMNET_NAT66_PREFIX},
99+
{"vmnet-network-uuid", required_argument, NULL, CLI_OPT_VMNET_NETWORK_UUID},
93100
{"pidfile", required_argument, NULL, 'p' },
94101
{"help", no_argument, NULL, 'h' },
95102
{"version", no_argument, NULL, 'v' },
@@ -134,6 +141,12 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
134141
case CLI_OPT_VMNET_NAT66_PREFIX:
135142
res->vmnet_nat66_prefix = strdup(optarg);
136143
break;
144+
case CLI_OPT_VMNET_NETWORK_UUID:
145+
if (uuid_parse(optarg, res->vmnet_network_uuid) < 0) {
146+
ERRORF("Failed to parse UUID \"%s\"", optarg);
147+
goto error;
148+
}
149+
break;
137150
case 'p':
138151
res->pidfile = strdup(optarg);
139152
break;
@@ -184,6 +197,9 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
184197
if (uuid_is_null(res->vmnet_interface_id)) {
185198
uuid_generate_random(res->vmnet_interface_id);
186199
}
200+
if (uuid_is_null(res->vmnet_network_uuid)) {
201+
uuid_generate_random(res->vmnet_network_uuid);
202+
}
187203

188204
/* validate */
189205
if (res->vmnet_mode == VMNET_BRIDGED_MODE && res->vmnet_interface == NULL) {

cli.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct cli_options {
2020
char *vmnet_mask;
2121
// --vmnet-interface-id, corresponds to vmnet_interface_id_key
2222
uuid_t vmnet_interface_id;
23+
// --network-uuid, corresponds to vmnet_network_identifier_key
24+
uuid_t vmnet_network_uuid;
2325
// --vmnet-nat66-prefix, corresponds to vmnet_nat66_prefix_key
2426
char *vmnet_nat66_prefix;
2527
// -p, --pidfile; writes pidfile using permissions of socket_vmnet

main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ static interface_ref start(struct state *state, struct cli_options *cliopt) {
237237
}
238238

239239
xpc_dictionary_set_uuid(dict, vmnet_interface_id_key, cliopt->vmnet_interface_id);
240+
if (cliopt->vmnet_mode == VMNET_HOST_MODE) {
241+
xpc_dictionary_set_uuid(dict, vmnet_network_identifier_key, cliopt->vmnet_network_uuid);
242+
}
240243

241244
if (cliopt->vmnet_nat66_prefix != NULL) {
242245
xpc_dictionary_set_string(dict, vmnet_nat66_prefix_key, cliopt->vmnet_nat66_prefix);

0 commit comments

Comments
 (0)