Skip to content

Commit

Permalink
Add --enable-isolation option
Browse files Browse the repository at this point in the history
Vmnet provides an option to isolate vment guests. Supporting it is
trivial so lets add it.

/*!
 * @constant vmnet_enable_isolation_key
 * Enable isolation for this interface. Interface isolation ensures that
 * network communication between multiple vmnet_interface instances is
 * not possible.
 */
extern const char *
vmnet_enable_isolation_key API_AVAILABLE(macos(11.0)) API_UNAVAILABLE(ios, watchos, tvos);

The isolation feature seems to be broken. vmnet_start_interface() fails
with both "shared" and "bridged" modes:

    ERROR [main] vmnet_start_interface: VMNET_FAILURE
  • Loading branch information
nirs committed Feb 12, 2025
1 parent 19790ce commit fc6fae2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions example
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def main():
"--shared-interface",
help="vmnet shared interface, required for --operation-mode=bridged",
)
p.add_argument(
"--enable-isolation",
action="store_true",
help="Isolate the guest from other guests on the vmnet interface",
)
p.add_argument(
"--vmnet-offload",
choices=["auto", "on", "off"],
Expand Down Expand Up @@ -310,6 +315,9 @@ def start_helper(args, fd=None, socket=None):
if args.shared_interface:
cmd.append(f"--shared-interface={args.shared_interface}")

if args.enable_isolation:
cmd.append("--enable-isolation")

if args.verbose:
cmd.append("--verbose")

Expand Down
1 change: 1 addition & 0 deletions helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ static void start_host_interface(void)

xpc_dictionary_set_bool(desc, vmnet_enable_tso_key, options.enable_tso);
xpc_dictionary_set_bool(desc, vmnet_enable_checksum_offload_key, options.enable_checksum_offload);
xpc_dictionary_set_bool(desc, vmnet_enable_isolation_key, options.enable_isolation);

dispatch_semaphore_t completed = dispatch_semaphore_create(0);

Expand Down
7 changes: 6 additions & 1 deletion options.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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"
" [--enable-tso] [--enable-checksum-offload]\n"
" [--enable-tso] [--enable-checksum-offload] [--enable-isolation]\n"
" [-v|--verbose] [--version] [-h|--help]\n"
"\n";
fputs(msg, stderr);
Expand All @@ -44,6 +44,7 @@ enum {
OPT_SUBNET_MASK,
OPT_ENABLE_TSO,
OPT_ENABLE_CHECKSUM_OFFLOAD,
OPT_ENABLE_ISOLATION,
OPT_VERSION,
};

Expand All @@ -60,6 +61,7 @@ static struct option long_options[] = {
{"subnet-mask", required_argument, 0, OPT_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},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, OPT_VERSION},
{"help", no_argument, 0, 'h'},
Expand Down Expand Up @@ -195,6 +197,9 @@ void parse_options(struct options *opts, int argc, char **argv)
case OPT_ENABLE_CHECKSUM_OFFLOAD:
opts->enable_checksum_offload = true;
break;
case OPT_ENABLE_ISOLATION:
opts->enable_isolation = true;
break;
case 'v':
verbose = true;
break;
Expand Down
1 change: 1 addition & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct options {
const char *end_address;
const char *subnet_mask;
const char *shared_interface;
bool enable_isolation;
bool enable_tso;
bool enable_checksum_offload;
uid_t uid;
Expand Down

0 comments on commit fc6fae2

Please sign in to comment.