From: Jeff Layton <jlayton@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: chuck.lever@oracle.com, steved@redhat.com
Subject: [PATCH 3/5] nfs-utils: set IPV6_V6ONLY on nfssvc IPv6 sockets
Date: Wed, 27 May 2009 07:54:33 -0400 [thread overview]
Message-ID: <1243425275-6284-4-git-send-email-jlayton@redhat.com> (raw)
In-Reply-To: <1243425275-6284-1-git-send-email-jlayton@redhat.com>
IPv6 sockets for knfsd can't be allowed to accept IPv4 packets. Set the
correct option to prevent it.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
support/nfs/nfssvc.c | 31 ++++++++++++++++++++++++++-----
1 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/support/nfs/nfssvc.c b/support/nfs/nfssvc.c
index 7634562..2aa5281 100644
--- a/support/nfs/nfssvc.c
+++ b/support/nfs/nfssvc.c
@@ -60,6 +60,7 @@ nfssvc_setfds(unsigned int ctlbits, struct sockaddr *sa, socklen_t addrlen)
int fd, on = 1;
char buf[BUFSIZ];
int udpfd = -1, tcpfd = -1, rc = 0;
+ unsigned short family = sa->sa_family;
/*
* if file can't be opened, then assume that it's not available and
@@ -70,9 +71,19 @@ nfssvc_setfds(unsigned int ctlbits, struct sockaddr *sa, socklen_t addrlen)
return 0;
if (NFSCTL_UDPISSET(ctlbits)) {
- udpfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ udpfd = socket(family, SOCK_DGRAM, IPPROTO_UDP);
if (udpfd < 0) {
- syslog(LOG_ERR, "nfssvc: unable to create UDP socket: "
+ syslog(LOG_ERR, "nfssvc: unable to create %s UDP "
+ "socket: errno %d (%s)\n",
+ family == AF_INET6 ? "ipv6" : "ipv4", errno,
+ strerror(errno));
+ rc = -errno;
+ goto error;
+ }
+ if (family == AF_INET6 && setsockopt(udpfd, IPPROTO_IPV6,
+ IPV6_V6ONLY, &on,
+ sizeof(on))) {
+ syslog(LOG_ERR, "nfssvc: unable to set IPV6_V6ONLY: "
"errno %d (%s)\n", errno, strerror(errno));
rc = -errno;
goto error;
@@ -86,10 +97,12 @@ nfssvc_setfds(unsigned int ctlbits, struct sockaddr *sa, socklen_t addrlen)
}
if (NFSCTL_TCPISSET(ctlbits)) {
- tcpfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ tcpfd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (tcpfd < 0) {
- syslog(LOG_ERR, "nfssvc: unable to create TCP socket: "
- "errno %d (%s)\n", errno, strerror(errno));
+ syslog(LOG_ERR, "nfssvc: unable to create %s TCP "
+ "socket: errno %d (%s)\n",
+ family == AF_INET6 ? "ipv6" : "ipv4", errno,
+ strerror(errno));
rc = -errno;
goto error;
}
@@ -99,6 +112,14 @@ nfssvc_setfds(unsigned int ctlbits, struct sockaddr *sa, socklen_t addrlen)
rc = -errno;
goto error;
}
+ if (family == AF_INET6 && setsockopt(tcpfd, IPPROTO_IPV6,
+ IPV6_V6ONLY, &on,
+ sizeof(on))) {
+ syslog(LOG_ERR, "nfssvc: unable to set IPV6_V6ONLY: "
+ "errno %d (%s)\n", errno, strerror(errno));
+ exit(1);
+ }
+
if (bind(tcpfd, sa, addrlen) < 0) {
syslog(LOG_ERR, "nfssvc: unable to bind TCP socket: "
"errno %d (%s)\n", errno, strerror(errno));
--
1.6.0.6
next prev parent reply other threads:[~2009-05-27 11:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-27 11:54 [PATCH 0/5] nfs-utils: add IPv6 support for rpc.nfsd (try #3) Jeff Layton
2009-05-27 11:54 ` [PATCH 1/5] nfs-utils: don't link libexport.a and libmisc.a to nfsd Jeff Layton
2009-05-27 11:54 ` [PATCH 2/5] nfs-utils: break up nfssvc.c into more individually callable functions Jeff Layton
2009-05-27 11:54 ` Jeff Layton [this message]
2009-05-27 11:54 ` [PATCH 4/5] nfs-utils: add IPv6 support to nfsd Jeff Layton
2009-05-27 16:22 ` Chuck Lever
2009-05-29 11:08 ` Jeff Layton
2009-05-27 11:54 ` [PATCH 5/5] nfs-utils: limit protocols and families used by nfsd to those listed in /etc/netconfig Jeff Layton
2009-05-27 16:30 ` Chuck Lever
2009-05-29 11:20 ` Jeff Layton
[not found] ` <20090529072050.0f24e385-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2009-05-29 15:30 ` Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1243425275-6284-4-git-send-email-jlayton@redhat.com \
--to=jlayton@redhat.com \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=steved@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox