43
43
// + 100 .
44
44
#define NETWORK_PREFIX_MAX (25)
45
45
#define NETWORK_PREFIX_MIN6 (8)
46
- #define NETWORK_PREFIX_MAX6 (64 )
46
+ #define NETWORK_PREFIX_MAX6 (128 )
47
47
48
48
static int nsenter (pid_t target_pid , char * netns , char * userns ,
49
49
bool only_userns )
@@ -241,7 +241,6 @@ static const char *pseudo_random_global_id(const char *device)
241
241
ifr .ifr_flags = IFF_UP | IFF_RUNNING ;
242
242
243
243
if (device == NULL ) {
244
- /* TODO: which device should we get the mac address from? */
245
244
device = "lo" ;
246
245
}
247
246
strncpy (ifr .ifr_name , device , sizeof (ifr .ifr_name ) - 1 );
@@ -312,7 +311,7 @@ static const char *pseudo_random_global_id(const char *device)
312
311
* ID to create a Local IPv6 address prefix.
313
312
*/
314
313
315
- sprintf (id , "fd00:%s::" , tmp );
314
+ sprintf (id , "fd00:%s::/64 " , tmp );
316
315
317
316
return id ;
318
317
}
@@ -591,6 +590,7 @@ struct options {
591
590
bool do_config_network ; // -c
592
591
bool disable_host_loopback ; // --disable-host-loopback
593
592
bool enable_ipv6 ; // -6
593
+ bool ipv6_random ; // --ipv6-random
594
594
bool enable_sandbox ; // --enable-sandbox
595
595
bool enable_seccomp ; // --enable-seccomp
596
596
bool disable_dns ; // --disable-dns
@@ -663,8 +663,9 @@ static void parse_args(int argc, char *const argv[], struct options *options)
663
663
char * optarg_outbound_addr = NULL ;
664
664
char * optarg_outbound_addr6 = NULL ;
665
665
char * optarg_macaddress = NULL ;
666
- #define CIDR -41
667
- #define CIDR6 -42
666
+ #define CIDR -40
667
+ #define CIDR6 -41
668
+ #define IPV6_RANDOM -42
668
669
#define DISABLE_HOST_LOOPBACK -43
669
670
#define NETNS_TYPE -44
670
671
#define USERNS_PATH -45
@@ -691,6 +692,7 @@ static void parse_args(int argc, char *const argv[], struct options *options)
691
692
{ "userns-path" , required_argument , NULL , USERNS_PATH },
692
693
{ "api-socket" , required_argument , NULL , 'a' },
693
694
{ "enable-ipv6" , no_argument , NULL , '6' },
695
+ { "ipv6-random" , no_argument , NULL , IPV6_RANDOM },
694
696
{ "enable-sandbox" , no_argument , NULL , ENABLE_SANDBOX },
695
697
{ "create-sandbox" , no_argument , NULL , _DEPRECATED_CREATE_SANDBOX },
696
698
{ "enable-seccomp" , no_argument , NULL , ENABLE_SECCOMP },
@@ -783,6 +785,9 @@ static void parse_args(int argc, char *const argv[], struct options *options)
783
785
options -> enable_ipv6 = true;
784
786
printf ("WARNING: Support for IPv6 is experimental\n" );
785
787
break ;
788
+ case IPV6_RANDOM :
789
+ options -> ipv6_random = true;
790
+ break ;
786
791
case 'h' :
787
792
usage (argv [0 ]);
788
793
exit (EXIT_SUCCESS );
@@ -982,29 +987,12 @@ static int parse_cidr6(struct in6_addr *network, struct in6_addr *netmask,
982
987
fprintf (stderr , "invalid CIDR: %s\n" , cidr );
983
988
goto finish ;
984
989
}
985
- rc = from_regmatch (snetwork_end , sizeof (snetwork_end ), matches [2 ], cidr );
986
- if (rc < 0 ) {
987
- fprintf (stderr , "invalid CIDR: %s\n" , cidr );
988
- goto finish ;
989
- }
990
990
rc = from_regmatch (sprefix , sizeof (sprefix ), matches [4 ], cidr );
991
991
if (rc < 0 ) {
992
992
fprintf (stderr , "invalid CIDR: %s\n" , cidr );
993
993
goto finish ;
994
994
}
995
- if (strcmp (snetwork , snetwork_end ) == 0 ) {
996
- random = pseudo_random_global_id (NULL );
997
- if (random == NULL ) {
998
- fprintf (stderr , "cannot create pseudo random global id\n" );
999
- rc = -1 ;
1000
- goto finish ;
1001
- }
1002
- strcpy (snetwork , random );
1003
- strcat (snetwork , "0" );
1004
- } else {
1005
- strcat (snetwork , ":0" );
1006
- }
1007
-
995
+ strcat (snetwork , ":" );
1008
996
if (inet_pton (AF_INET6 , snetwork , network ) != 1 ) {
1009
997
fprintf (stderr , "invalid network address: %s\n" , snetwork );
1010
998
rc = -1 ;
@@ -1179,8 +1167,19 @@ static int slirp4netns_config_from_options(struct slirp4netns_config *cfg,
1179
1167
cfg -> enable_seccomp = opt -> enable_seccomp ;
1180
1168
1181
1169
if (cfg -> enable_ipv6 ) {
1182
- rc = slirp4netns_config_from_cidr6 (cfg , opt -> cidr6 == NULL ? DEFAULT_CIDR6 :
1183
- opt -> cidr6 );
1170
+ const char * cidr = opt -> cidr6 ;
1171
+ if (cidr == NULL ) {
1172
+ cidr = DEFAULT_CIDR6 ;
1173
+ if (opt -> ipv6_random ) {
1174
+ cidr = pseudo_random_global_id ("lo" );
1175
+ if (cidr == NULL ) {
1176
+ fprintf (stderr , "cannot create pseudo random global id\n" );
1177
+ rc = -1 ;
1178
+ goto finish ;
1179
+ }
1180
+ }
1181
+ }
1182
+ rc = slirp4netns_config_from_cidr6 (cfg , cidr );
1184
1183
if (rc < 0 ) {
1185
1184
goto finish ;
1186
1185
}
0 commit comments