[PATCH] Make glibc sunrpc work with 2.4 unconnected UDP port error handling
Andreas Jaeger
aj@suse.de
Wed Jan 10 06:31:00 GMT 2001
>>>>> Jakub Jelinek writes:
> Hi!
> This seems to work for me on 2.2 (and I tried a short test which did all the
> syscalls gethostbyname is doing when trying to talk to portmap which is not
> running on 2.4).
> Maybe I've put too many tests in there, the msg.msg_namelen == 0 test is
> there because of bug in 2.2 as pointed out by Andi Kleen, ret can be 0 e.g
> if some router on the way sends host unreacheable. If I get payload back, I
> compare it to what we just sent to make sure it was ICMP for the same
> message.
> I'll try that glibc on 2.4 tomorrow.
> The problem this patch solves can be reproduced e.g. by making sure nis is
> before dns in nsswitch.conf and doing
> domainname xyz.foo.com
> killall portmap
> then on 2.4 any hostname lookup will take eons.
> 2001-01-09 Jakub Jelinek <jakub@redhat.com>
> * sunrpc/clnt_udp.c (clntudp_bufcreate): Set IP_RECVERR on the
> UDP socket.
> (clntudp_call): Handle MSG_ERRQUEUE.
> * sysdeps/generic/bits/errqueue.h: New.
> * sysdeps/unix/sysv/linux/bits/errqueue.h: New.
> --- libc/sunrpc/clnt_udp.c.jj Tue Aug 3 19:20:26 1999
> +++ libc/sunrpc/clnt_udp.c Tue Jan 9 18:51:32 2001
> @@ -51,6 +51,11 @@ static char sccsid[] = "@(#)clnt_udp.c 1
> #include <rpc/pmap_clnt.h>
> #include <net/if.h>
> +#ifdef IP_RECVERR
> +#include <bits/errqueue.h>
> +#include <sys/uio.h>
> +#endif
> +
> extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *);
> extern u_long _create_xid (void);
> @@ -186,6 +191,12 @@ clntudp_bufcreate (struct sockaddr_in *r
> (void) bindresvport (*sockp, (struct sockaddr_in *) 0);
> /* the sockets rpc controls are non-blocking */
> (void) __ioctl (*sockp, FIONBIO, (char *) &dontblock);
> +#ifdef IP_RECVERR
> + {
> + int on = 1;
> + setsockopt(*sockp, SOL_IP, IP_RECVERR, &on, sizeof(on));
> + }
> +#endif
cu-> cu_closeit = TRUE;
> }
> else
> @@ -361,6 +372,47 @@ send_again:
cu-> cu_error.re_errno = errno;
> return (cu->cu_error.re_status = RPC_CANTRECV);
> }
> +#ifdef IP_RECVERR
> + if (fd.revents & POLLERR)
> + {
> + struct msghdr msg;
> + struct cmsghdr *cmsg;
> + struct sock_extended_err *e;
> + struct sockaddr_in err_addr;
> + struct iovec iov;
> + char *cbuf = (char *) alloca (outlen + 256);
> + int ret;
> +
> + iov.iov_base = cbuf + 256;
> + iov.iov_len = outlen;
> + msg.msg_name = (void *) &err_addr;
> + msg.msg_namelen = sizeof (err_addr);
> + msg.msg_iov = &iov;
> + msg.msg_iovlen = 1;
> + msg.msg_flags = 0;
> + msg.msg_control = cbuf;
> + msg.msg_controllen = 256;
> + ret = recvmsg (cu->cu_sock, &msg, MSG_ERRQUEUE);
> + if ((ret == 0
> + || (ret == outlen
> + && memcmp (cbuf + 256, cu->cu_outbuf, outlen) == 0))
Andi Kleen told me that ret == 0 doesn't make sense since that would
mean that the error queue is empty. The outlen check is also wrong
since ICMP can shorten packages.
He advices to use:
if ((ret >= SUNRPC_MIN_HDR && memcpy(cbuf+256,cu->cu_outbuf,outlen) == 0)
where SUNRPC_MIN_HDR is a minimal value we will use for comparison.
Andreas
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
http://www.suse.de/~aj
More information about the Libc-hacker
mailing list