Skip to content

Commit a359ea6

Browse files
fpolica91claude
andcommitted
fix: handle nat66 prefix and unsupported opts in --vmnet-disable-dhcp
Follow-up to Copilot review on the macOS 26 --vmnet-disable-dhcp path: - Apply --vmnet-nat66-prefix via vmnet_network_configuration_set_ipv6_prefix (parsed with inet_pton, /64), mirroring the legacy vmnet_nat66_prefix_key. - Warn that --vmnet-interface-id, --vmnet-network-identifier and --vmnet-dhcp-end are ignored on this path: the macOS 26 vmnet network configuration API has no setter for the network identifier, vmnet_interface_start_with_network assigns its own interface id (verified empirically on macOS 26.4), and no DHCP server is started. - Validate --vmnet-gateway / --vmnet-mask separately and print the offending value instead of relying on errno (inet_aton does not set errno on failure). - Tighten the disable-dhcp test assertion and PID handling. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: fpolica91 <fabriciopolicarpo0@gmail.com>
1 parent 5887eb9 commit a359ea6

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

cli.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
139139
break;
140140
case CLI_OPT_VMNET_DHCP_END:
141141
res->vmnet_dhcp_end = strdup(optarg);
142+
res->vmnet_dhcp_end_specified = true;
142143
break;
143144
case CLI_OPT_VMNET_MASK:
144145
res->vmnet_mask = strdup(optarg);

cli.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct cli_options {
1616
char *vmnet_gateway;
1717
// --vmnet-dhcp-end, corresponds to vmnet_end_address_key
1818
char *vmnet_dhcp_end;
19+
bool vmnet_dhcp_end_specified;
1920
// --vmnet-mask, corresponds to vmnet_subnet_mask_key
2021
char *vmnet_mask;
2122
// --vmnet-interface-id, corresponds to vmnet_interface_id_key

main.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ static interface_ref start(struct state *state, struct cli_options *cliopt) {
253253
WARN("--vmnet-network-identifier is ignored with --vmnet-disable-dhcp: "
254254
"the macOS 26 vmnet network configuration API has no equivalent");
255255
}
256+
if (cliopt->vmnet_dhcp_end_specified) {
257+
WARN("--vmnet-dhcp-end is ignored with --vmnet-disable-dhcp: "
258+
"no DHCP server is started");
259+
}
256260
vmnet_return_t st = VMNET_FAILURE;
257261
vmnet_network_configuration_ref cfg =
258262
vmnet_network_configuration_create(cliopt->vmnet_mode, &st);
@@ -271,8 +275,12 @@ static interface_ref start(struct state *state, struct cli_options *cliopt) {
271275
}
272276
if (cliopt->vmnet_gateway != NULL) {
273277
struct in_addr gateway, subnet, mask;
274-
if (!inet_aton(cliopt->vmnet_gateway, &gateway) || !inet_aton(cliopt->vmnet_mask, &mask)) {
275-
ERRORN("inet_aton");
278+
if (!inet_aton(cliopt->vmnet_gateway, &gateway)) {
279+
ERRORF("invalid address \"%s\" was specified for --vmnet-gateway", cliopt->vmnet_gateway);
280+
return NULL;
281+
}
282+
if (!inet_aton(cliopt->vmnet_mask, &mask)) {
283+
ERRORF("invalid address \"%s\" was specified for --vmnet-mask", cliopt->vmnet_mask);
276284
return NULL;
277285
}
278286
subnet = gateway;

test/test-disable-dhcp.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ if [ ! -f ipxe.lkrn ]; then
1515
curl -fSL -O https://boot.ipxe.org/ipxe.lkrn
1616
fi
1717

18-
sudo /opt/socket_vmnet/bin/socket_vmnet --vmnet-disable-dhcp \
18+
PIDFILE="$(mktemp -t socket_vmnet.pid.XXXXXX)"
19+
20+
sudo /opt/socket_vmnet/bin/socket_vmnet --pidfile "${PIDFILE}" --vmnet-disable-dhcp \
1921
--vmnet-gateway="${GATEWAY}" --socket-group=staff "${SOCKET}" &
20-
socket_vmnet_pid=$!
2122
cleanup() {
22-
sudo kill "${socket_vmnet_pid}" 2>/dev/null || true
23+
if [ -f "${PIDFILE}" ]; then
24+
sudo kill "$(cat "${PIDFILE}")" 2>/dev/null || true
25+
rm -f "${PIDFILE}"
26+
fi
2327
sudo rm -f "${SOCKET}"
2428
}
2529
trap cleanup EXIT

0 commit comments

Comments
 (0)