Skip to content

Commit dc0da40

Browse files
committed
support --vmnet-nat66-prefix
Signed-off-by: Ninh Pham <[email protected]>
1 parent 8b16e51 commit dc0da40

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

cli.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ static void print_usage(const char *argv0) {
4747
"specified\n");
4848
printf("--vmnet-interface-id=UUID vmnet interface ID (default: "
4949
"random)\n");
50+
printf("--vmnet-nat66-prefix=PREFIX:: The IPv6 prefix to use with "
51+
"shared mode.\n");
52+
printf(" The prefix must be a ULA i.e. "
53+
"start with fd00::/8.\n");
54+
printf(" (default: random)\n");
5055
printf("-p, --pidfile=PIDFILE save pid to PIDFILE\n");
5156
printf("-h, --help display this help and exit\n");
5257
printf("-v, --version display version information and "
@@ -64,6 +69,7 @@ static void print_version() { puts(VERSION); }
6469
#define CLI_OPTIONS_ID_VMNET_DHCP_END -46
6570
#define CLI_OPTIONS_ID_VMNET_MASK -47
6671
#define CLI_OPTIONS_ID_VMNET_INTERFACE_ID -48
72+
#define CLI_OPTIONS_ID_VMNET_NAT66_PREFIX -50
6773
struct cli_options *cli_options_parse(int argc, char *argv[]) {
6874
struct cli_options *res = malloc(sizeof(*res));
6975
if (res == NULL) {
@@ -82,6 +88,8 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
8288
{"vmnet-mask", required_argument, NULL, CLI_OPTIONS_ID_VMNET_MASK},
8389
{"vmnet-interface-id", required_argument, NULL,
8490
CLI_OPTIONS_ID_VMNET_INTERFACE_ID},
91+
{"vmnet-nat66-prefix", required_argument, NULL,
92+
CLI_OPTIONS_ID_VMNET_NAT66_PREFIX},
8593
{"pidfile", required_argument, NULL, 'p'},
8694
{"help", no_argument, NULL, 'h'},
8795
{"version", no_argument, NULL, 'v'},
@@ -123,6 +131,9 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
123131
goto error;
124132
}
125133
break;
134+
case CLI_OPTIONS_ID_VMNET_NAT66_PREFIX:
135+
res->vmnet_nat66_prefix = strdup(optarg);
136+
break;
126137
case 'p':
127138
res->pidfile = strdup(optarg);
128139
break;
@@ -238,6 +249,8 @@ void cli_options_destroy(struct cli_options *x) {
238249
free(x->vmnet_dhcp_end);
239250
if (x->vmnet_mask != NULL)
240251
free(x->vmnet_mask);
252+
if (x->vmnet_nat66_prefix != NULL)
253+
free(x->vmnet_nat66_prefix);
241254
if (x->pidfile != NULL)
242255
free(x->pidfile);
243256
free(x);

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+
// --vmnet-nat66-prefix, corresponds to vmnet_nat66_prefix_key
24+
char *vmnet_nat66_prefix;
2325
// -p, --pidfile; writes pidfile using permissions of socket_vmnet
2426
char *pidfile;
2527
// arg

main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ static interface_ref start(struct state *state, struct cli_options *cliopt) {
253253
xpc_dictionary_set_uuid(dict, vmnet_interface_id_key,
254254
cliopt->vmnet_interface_id);
255255

256+
if (cliopt->vmnet_nat66_prefix != NULL) {
257+
xpc_dictionary_set_string(dict, vmnet_nat66_prefix_key,
258+
cliopt->vmnet_nat66_prefix);
259+
}
260+
256261
dispatch_queue_t q = dispatch_queue_create(
257262
"io.github.lima-vm.socket_vmnet.start", DISPATCH_QUEUE_SERIAL);
258263
dispatch_semaphore_t sem = dispatch_semaphore_create(0);

0 commit comments

Comments
 (0)