summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivano@gnu.org>2018-09-04 20:18:23 +0200
committerGitHub <noreply@github.com>2018-09-04 20:18:23 +0200
commitfd588d110c4f0ead47d6000e0bf9de9babfd6c05 (patch)
treeb1fd989ad52dd42721af19e1c1d72471a764a10a
parent8a95c92fb14274abceed8d8bbe512c871932406e (diff)
parent332aa51fb19b18747d2cf0b618ed34ef3e749440 (diff)
Merge pull request #25 from AkihiroSuda/ipv6
experimental support for ipv6
-rw-r--r--main.c21
-rw-r--r--slirp4netns.112
-rw-r--r--slirp4netns.1.md11
-rw-r--r--slirp4netns.c14
-rw-r--r--slirp4netns.h2
5 files changed, 39 insertions, 21 deletions
diff --git a/main.c b/main.c
index 58fe026..5ec4693 100644
--- a/main.c
+++ b/main.c
@@ -10,9 +10,9 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <linux/if.h>
#include <linux/if_tun.h>
#include <arpa/inet.h>
+#include <net/if.h>
#include <net/route.h>
#include <stdbool.h>
#include <getopt.h>
@@ -154,7 +154,7 @@ static int configure_network(const char *tapname, unsigned int mtu)
}
static int child(int sock, pid_t target_pid, bool do_config_network, const char *tapname, int ready_fd,
- unsigned int mtu)
+ unsigned int mtu, bool enable_ipv6)
{
int rc, tapfd;
if ((rc = nsenter(target_pid)) < 0) {
@@ -215,7 +215,7 @@ static int recvfd(int sock)
return fd;
}
-static int parent(int sock, int exit_fd, unsigned int mtu)
+static int parent(int sock, int exit_fd, unsigned int mtu, bool enable_ipv6)
{
int rc, tapfd;
if ((tapfd = recvfd(sock)) < 0) {
@@ -224,7 +224,7 @@ static int parent(int sock, int exit_fd, unsigned int mtu)
fprintf(stderr, "received tapfd=%d\n", tapfd);
close(sock);
printf("starting slirp, MTU=%d\n", mtu);
- if ((rc = do_slirp(tapfd, exit_fd, mtu)) < 0) {
+ if ((rc = do_slirp(tapfd, exit_fd, mtu, enable_ipv6)) < 0) {
fprintf(stderr, "do_slirp failed\n");
close(tapfd);
return rc;
@@ -241,6 +241,7 @@ static void usage(const char *argv0)
printf("-e, --exit-fd=FD specify the FD for terminating slirp4netns\n");
printf("-r, --ready-fd=FD specify the FD to write to when the network is configured\n");
printf("-m, --mtu=MTU specify MTU (default=1500, max=65521)\n");
+ printf("-6, --enable-ipv6 enable IPv6 (experimental)\n");
}
struct options {
@@ -250,6 +251,7 @@ struct options {
int exit_fd; // -e
int ready_fd; // -r
unsigned int mtu; // -m
+ bool enable_ipv6; // -6
};
static void options_init(struct options *options)
@@ -279,10 +281,11 @@ static void parse_args(int argc, char *const argv[], struct options *options)
{"exit-fd", required_argument, NULL, 'e'},
{"ready-fd", required_argument, NULL, 'r'},
{"mtu", required_argument, NULL, 'm'},
+ {"enable-ipv6", no_argument, NULL, '6'},
{0, 0, 0, 0},
};
options_init(options);
- while ((opt = getopt_long(argc, argv, "ce:r:m:", longopts, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "ce:r:m:6", longopts, NULL)) != -1) {
switch (opt) {
case 'c':
options->do_config_network = true;
@@ -314,6 +317,10 @@ static void parse_args(int argc, char *const argv[], struct options *options)
exit(EXIT_FAILURE);
}
break;
+ case '6':
+ options->enable_ipv6 = true;
+ printf("WARNING: Support for IPv6 is experimental\n");
+ break;
default:
usage(argv[0]);
exit(EXIT_FAILURE);
@@ -360,7 +367,7 @@ int main(int argc, char *const argv[])
if (child_pid == 0) {
if (child
(sv[1], options.target_pid, options.do_config_network, options.tapname, options.ready_fd,
- options.mtu) < 0) {
+ options.mtu, options.enable_ipv6) < 0) {
options_destroy(&options);
exit(EXIT_FAILURE);
}
@@ -378,7 +385,7 @@ int main(int argc, char *const argv[])
fprintf(stderr, "child failed(%d)\n", child_status);
exit(child_status);
}
- if (parent(sv[0], options.exit_fd, options.mtu) < 0) {
+ if (parent(sv[0], options.exit_fd, options.mtu, options.enable_ipv6) < 0) {
fprintf(stderr, "parent failed\n");
exit(EXIT_FAILURE);
}
diff --git a/slirp4netns.1 b/slirp4netns.1
index 262ffc8..29ae2cf 100644
--- a/slirp4netns.1
+++ b/slirp4netns.1
@@ -20,11 +20,11 @@ Default configuration:
.RS
.IP \(bu 2
-Gateway: 10.0.2.2
+Gateway: 10.0.2.2, fd00::2
.IP \(bu 2
-DNS: 10.0.2.3
+DNS: 10.0.2.3, fd00::3
.IP \(bu 2
-Host: 10.0.2.2, 10.0.2.3
+Host: 10.0.2.2, 10.0.2.3, fd00::2, fd00::3
.RE
@@ -32,7 +32,7 @@ Host: 10.0.2.2, 10.0.2.3
.SH OPTIONS
.PP
\fB\-c\fP, \fB\-\-configure\fP
-bring up the interface. IP will be set to 10.0.2.100.
+bring up the interface. IP will be set to 10.0.2.100. IPv6 will be set to a random address.
.PP
\fB\-e\fP, \fB\-\-exit\-fd=FD\fP
@@ -46,6 +46,10 @@ specify the FD to write to when the network is configured.
\fB\-m\fP, \fB\-\-mtu=MTU\fP
specify MTU (default=1500, max=65521).
+.PP
+\fB\-6\fP, \fB\-\-enable\-ipv6\fP
+enable IPv6 (experimental).
+
.SH EXAMPLE
.PP
diff --git a/slirp4netns.1.md b/slirp4netns.1.md
index b3f1718..83aec55 100644
--- a/slirp4netns.1.md
+++ b/slirp4netns.1.md
@@ -15,14 +15,14 @@ slirp4netns provides a user-mode networking ("slirp") for unprivileged network n
Default configuration:
-* Gateway: 10.0.2.2
-* DNS: 10.0.2.3
-* Host: 10.0.2.2, 10.0.2.3
+* Gateway: 10.0.2.2, fd00::2
+* DNS: 10.0.2.3, fd00::3
+* Host: 10.0.2.2, 10.0.2.3, fd00::2, fd00::3
# OPTIONS
**-c**, **--configure**
-bring up the interface. IP will be set to 10.0.2.100.
+bring up the interface. IP will be set to 10.0.2.100. IPv6 will be set to a random address.
**-e**, **--exit-fd=FD**
specify the FD for terminating slirp4netns.
@@ -33,6 +33,9 @@ specify the FD to write to when the network is configured.
**-m**, **--mtu=MTU**
specify MTU (default=1500, max=65521).
+**-6**, **--enable-ipv6**
+enable IPv6 (experimental).
+
# EXAMPLE
Terminal 1:
diff --git a/slirp4netns.c b/slirp4netns.c
index b77457a..d111a73 100644
--- a/slirp4netns.c
+++ b/slirp4netns.c
@@ -21,18 +21,22 @@ void slirp_output(void *opaque, const uint8_t * pkt, int pkt_len)
assert(rc == pkt_len);
}
-Slirp *create_slirp(void *opaque, unsigned int mtu)
+Slirp *create_slirp(void *opaque, unsigned int mtu, bool ip6_enabled)
{
Slirp *slirp = NULL;
struct in_addr vnetwork, vnetmask, vhost, vdhcp_start, vnameserver;
- struct in6_addr vhost6, vprefix_addr6, vnameserver6; /* ignored */
+ struct in6_addr vhost6, vprefix_addr6, vnameserver6;
+ int vprefix_len = 64;
inet_pton(AF_INET, "10.0.2.0", &vnetwork);
inet_pton(AF_INET, "255.255.255.0", &vnetmask);
inet_pton(AF_INET, "10.0.2.2", &vhost);
inet_pton(AF_INET, "10.0.2.3", &vnameserver);
inet_pton(AF_INET, "10.0.2.15", &vdhcp_start);
+ inet_pton(AF_INET6, "fd00::2", &vhost6);
+ inet_pton(AF_INET6, "fd00::", &vprefix_addr6);
+ inet_pton(AF_INET6, "fd00::3", &vnameserver6);
slirp = slirp_init(0 /* restricted */ , 1 /* is_enabled */ ,
- vnetwork, vnetmask, vhost, 0 /* ip6_enabled */ , vprefix_addr6, 0 /* vprefix_len */ , vhost6,
+ vnetwork, vnetmask, vhost, (int)ip6_enabled, vprefix_addr6, vprefix_len, vhost6,
NULL /* vhostname */ , NULL /* bootfile */ , vdhcp_start,
vnameserver, vnameserver6, NULL /* vdnssearch */ , NULL /* vdomainname */ ,
mtu /* if_mtu */ , mtu /* if_mru */ ,
@@ -45,7 +49,7 @@ Slirp *create_slirp(void *opaque, unsigned int mtu)
#define ETH_BUF_SIZE (65536)
-int do_slirp(int tapfd, int exitfd, unsigned int mtu)
+int do_slirp(int tapfd, int exitfd, unsigned int mtu, bool ip6_enabled)
{
int ret = -1;
Slirp *slirp = NULL;
@@ -56,7 +60,7 @@ int do_slirp(int tapfd, int exitfd, unsigned int mtu)
struct pollfd tap_pollfd = { tapfd, POLLIN | POLLHUP, 0 };
struct pollfd exit_pollfd = { exitfd, POLLHUP, 0 };
- slirp = create_slirp((void *)&opaque, mtu);
+ slirp = create_slirp((void *)&opaque, mtu, ip6_enabled);
if (slirp == NULL) {
fprintf(stderr, "create_slirp failed\n");
goto err;
diff --git a/slirp4netns.h b/slirp4netns.h
index 8115be0..83c4633 100644
--- a/slirp4netns.h
+++ b/slirp4netns.h
@@ -1,6 +1,6 @@
#ifndef SLIRP_H
# define SLIRP_H
-int do_slirp(int tapfd, int exitfd, unsigned int mtu);
+int do_slirp(int tapfd, int exitfd, unsigned int mtu, bool enable_ipv6);
#endif