From acf73093df68d4587fc363b930283edc6d919eb2 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Tue, 14 Aug 2012 12:46:43 +0400 Subject: [PATCH] sk-inet: save the socket option IPV6_V6ONLY (v2) Most part of services (ssh, httpd, ...) create two separate sockets one for ipv4 and one for ipv6. If IPV6_V6ONLY isn't dumped, bind() returns EADDRINUSE v2: use do_dump_opt and initialize yes = 1 Signed-off-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- protobuf/sk-inet.proto | 1 + sk-inet.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/protobuf/sk-inet.proto b/protobuf/sk-inet.proto index 340582f4f..36787b609 100644 --- a/protobuf/sk-inet.proto +++ b/protobuf/sk-inet.proto @@ -18,4 +18,5 @@ message inet_sk_entry { required fown_entry fown = 13; required sk_opts_entry opts = 14; + optional bool v6only = 15; } diff --git a/sk-inet.c b/sk-inet.c index 4e20a4706..edcafc7f4 100644 --- a/sk-inet.c +++ b/sk-inet.c @@ -204,8 +204,17 @@ static int dump_one_inet_fd(int lfd, u32 id, const struct fd_parms *p) ie.n_src_addr = PB_ALEN_INET; ie.n_dst_addr = PB_ALEN_INET; if (ie.family == AF_INET6) { + int val; + ie.n_src_addr = PB_ALEN_INET6; ie.n_dst_addr = PB_ALEN_INET6; + + ret = dump_opt(lfd, SOL_IPV6, IPV6_V6ONLY, &val); + if (ret < 0) + goto err; + + ie.v6only = val ? true : false; + ie.has_v6only = true; } ie.src_addr = xmalloc(pb_repeated_size(&ie, src_addr)); @@ -359,6 +368,13 @@ static int open_inet_sk(struct file_desc *d) return -1; } + if (ii->ie->v6only) { + int yes = 1; + + if (restore_opt(sk, SOL_IPV6, IPV6_V6ONLY, &yes) == -1) + return -1; + } + if (tcp_connection(ii->ie)) { if (!opts.tcp_established_ok) { pr_err("Connected TCP socket in image\n");