- Always make IPv6 sockets V6ONLY

- Fix incorrect sizeof() in __rpc_getbroadifs
This commit is contained in:
Steve Dickson 2008-09-04 18:18:22 +00:00
parent 175fea3b2c
commit 66af2ac9a7
3 changed files with 95 additions and 1 deletions

View File

@ -0,0 +1,57 @@
commit ea9f048761d0b9a2ab6310bffa07351f0b04d8c5
Author: Olaf Kirch <okir@suse.de>
Date: Tue Sep 2 12:11:15 2008 -0400
Always make IPv6 sockets V6ONLY
Assume you have a netconfig file looking like this:
udp tpi_clts v inet udp - -
udp6 tpi_clts v inet6 udp - -
...
a call to svc_tli_create(... &someaddr, "udp") will fail to create an
IPv6 server socket. The problem is that on Linux, passive IPv6 sockets
will also accept packets/connections from IPv4, and will simply map
the sender's address to an IPv6 mapped IPv4 address. So if you want to
bind both a UDPv4 and UDPv6 socket to the same port, this will fail with
EADDRINUSE.
The way to avoid this behavior is to change the socket to V6ONLY,
which tells the kernel to avoid the autmatic mapping.
The change proposed in the patch below does this. I *think* this is
a good place to do this, as it will also fix applications that do not
use svc_tli_create() - such as rpcbind, which creates the sockets on
its own using __rpc_nconf2fd.
I think this also improves portability, as BSD code assumes BSD
behavior, where this mapping does not occur either.
Signed-off-by: Olaf Kirch <okir@suse.de>
Signed-off-by: Steve Dickson <steved@redhat.com>
diff --git a/src/rpc_generic.c b/src/rpc_generic.c
index 583aff0..ff4ba16 100644
--- a/src/rpc_generic.c
+++ b/src/rpc_generic.c
@@ -525,11 +525,18 @@ int
__rpc_nconf2fd(const struct netconfig *nconf)
{
struct __rpc_sockinfo si;
+ int fd;
if (!__rpc_nconf2sockinfo(nconf, &si))
return 0;
- return socket(si.si_af, si.si_socktype, si.si_proto);
+ if ((fd = socket(si.si_af, si.si_socktype, si.si_proto)) >= 0 &&
+ si.si_af == AF_INET6) {
+ int val = 1;
+
+ setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, &val, sizeof(val));
+ }
+ return fd;
}
int

View File

@ -0,0 +1,27 @@
commit 95c8f7227e6b15f2e430d7b87dadc95b2acd4a61
Author: Olaf Kirch <okir@suse.de>
Date: Tue Sep 2 12:09:39 2008 -0400
Fix incorrect sizeof() in __rpc_getbroadifs
__rpc_getbroadifs returns bad broadcast addresses on 32bit
machines because when copying the broadcast addresses, ite
applies the sizeof() operator to a pointer to a sockaddr,
rather than the sockaddr itself.
Signed-off-by: Olaf Kirch <okir@suse.de>
Signed-off-by: Steve Dickson <steved@redhat.com>
diff --git a/src/clnt_bcast.c b/src/clnt_bcast.c
index a96db45..aa2b8f2 100644
--- a/src/clnt_bcast.c
+++ b/src/clnt_bcast.c
@@ -163,7 +163,7 @@ __rpc_getbroadifs(int af, int proto, int socktype, broadlist_t *list)
/* memcpy(&bip->broadaddr, ifap->ifa_broadaddr,
(size_t)ifap->ifa_broadaddr->sa_len);*/
memcpy(&bip->broadaddr, ifap->ifa_broadaddr,
- (size_t)sizeof(ifap->ifa_broadaddr));
+ sizeof(bip->broadaddr));
sin = (struct sockaddr_in *)(void *)&bip->broadaddr;
sin->sin_port =
((struct sockaddr_in *)

View File

@ -1,6 +1,6 @@
Name: libtirpc Name: libtirpc
Version: 0.1.9 Version: 0.1.9
Release: 3%{?dist} Release: 4%{?dist}
Summary: Transport Independent RPC Library Summary: Transport Independent RPC Library
Group: System Environment/Libraries Group: System Environment/Libraries
License: SISSL License: SISSL
@ -30,6 +30,9 @@ Group: Development/Libraries
Requires: %{name} = %{version}-%{release} Requires: %{name} = %{version}-%{release}
Requires(devel): pkgconfig man Requires(devel): pkgconfig man
Patch01: libtirpc-0.1.9-rpc_getbroadifs-sizeof.patch
Patch02: libtirpc-0.1.9-ipv6-socket.patch
Patch100: libtirpc-0.1.7-compile.patch Patch100: libtirpc-0.1.7-compile.patch
%description devel %description devel
@ -40,6 +43,9 @@ developing programs which use the tirpc library.
%prep %prep
%setup -q %setup -q
%patch01 -p1
%patch02 -p1
%patch100 -p1 %patch100 -p1
# Remove .orig files # Remove .orig files
@ -137,6 +143,10 @@ rm -rf %{buildroot}
%{_mandir}/*/* %{_mandir}/*/*
%changelog %changelog
* Thu Sep 4 2008 Steve Dickson <steved@redhat.com> 0.1.9-4
- Always make IPv6 sockets V6ONLY
- Fix incorrect sizeof() in __rpc_getbroadifs
* Thu Aug 7 2008 Tom "spot" Callaway <tcallawa@redhat.com> 0.1.9-3 * Thu Aug 7 2008 Tom "spot" Callaway <tcallawa@redhat.com> 0.1.9-3
- fix license tag - fix license tag