From owner-svn-src-stable@freebsd.org Thu Dec 6 08:27:31 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6059F13230BE; Thu, 6 Dec 2018 08:27:31 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F3C548588F; Thu, 6 Dec 2018 08:27:30 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B3CA320FE5; Thu, 6 Dec 2018 08:27:30 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wB68RUFM068508; Thu, 6 Dec 2018 08:27:30 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wB68RUwJ068507; Thu, 6 Dec 2018 08:27:30 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201812060827.wB68RUwJ068507@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Thu, 6 Dec 2018 08:27:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r341621 - stable/12/usr.sbin/nfsd X-SVN-Group: stable-12 X-SVN-Commit-Author: bapt X-SVN-Commit-Paths: stable/12/usr.sbin/nfsd X-SVN-Commit-Revision: 341621 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: F3C548588F X-Spamd-Result: default: False [-0.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.46)[-0.456,0]; NEURAL_HAM_SHORT(-0.41)[-0.414,0]; NEURAL_HAM_LONG(-0.07)[-0.070,0] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Dec 2018 08:27:31 -0000 Author: bapt Date: Thu Dec 6 08:27:30 2018 New Revision: 341621 URL: https://svnweb.freebsd.org/changeset/base/341621 Log: MFC r340111: nfsd: Factorize code Factorize code by using struct sockaddr_storage to handle both ipv6 and ipv4 Discussed with: rmacklem Reviewed by: manu Sponsored by: Gandi.net Differential Revision: https://reviews.freebsd.org/D13223 Modified: stable/12/usr.sbin/nfsd/nfsd.c Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.sbin/nfsd/nfsd.c ============================================================================== --- stable/12/usr.sbin/nfsd/nfsd.c Thu Dec 6 06:18:21 2018 (r341620) +++ stable/12/usr.sbin/nfsd/nfsd.c Thu Dec 6 08:27:30 2018 (r341621) @@ -160,10 +160,8 @@ main(int argc, char **argv) struct addrinfo *ai_udp, *ai_tcp, *ai_udp6, *ai_tcp6, hints; struct netconfig *nconf_udp, *nconf_tcp, *nconf_udp6, *nconf_tcp6; struct netbuf nb_udp, nb_tcp, nb_udp6, nb_tcp6; - struct sockaddr_in inetpeer; - struct sockaddr_in6 inet6peer; + struct sockaddr_storage peer; fd_set ready, sockbits; - fd_set v4bits, v6bits; int ch, connect_type_cnt, i, maxsock, msgsock; socklen_t len; int on = 1, unregister, reregister, sock; @@ -480,8 +478,6 @@ main(int argc, char **argv) } (void)signal(SIGUSR1, cleanup); - FD_ZERO(&v4bits); - FD_ZERO(&v6bits); FD_ZERO(&sockbits); rpcbregcnt = 0; @@ -663,7 +659,6 @@ main(int argc, char **argv) } freeaddrinfo(ai_tcp); FD_SET(tcpsock, &sockbits); - FD_SET(tcpsock, &v4bits); maxsock = tcpsock; connect_type_cnt++; } @@ -742,7 +737,6 @@ main(int argc, char **argv) } freeaddrinfo(ai_tcp6); FD_SET(tcp6sock, &sockbits); - FD_SET(tcp6sock, &v6bits); if (maxsock < tcp6sock) maxsock = tcp6sock; connect_type_cnt++; @@ -816,52 +810,25 @@ main(int argc, char **argv) } for (tcpsock = 0; tcpsock <= maxsock; tcpsock++) { if (FD_ISSET(tcpsock, &ready)) { - if (FD_ISSET(tcpsock, &v4bits)) { - len = sizeof(inetpeer); - if ((msgsock = accept(tcpsock, - (struct sockaddr *)&inetpeer, &len)) < 0) { - error = errno; - syslog(LOG_ERR, "accept failed: %m"); - if (error == ECONNABORTED || - error == EINTR) - continue; - nfsd_exit(1); - } - memset(inetpeer.sin_zero, 0, - sizeof(inetpeer.sin_zero)); - if (setsockopt(msgsock, SOL_SOCKET, - SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0) - syslog(LOG_ERR, - "setsockopt SO_KEEPALIVE: %m"); - addsockargs.sock = msgsock; - addsockargs.name = (caddr_t)&inetpeer; - addsockargs.namelen = len; - nfssvc(nfssvc_addsock, &addsockargs); - (void)close(msgsock); - } else if (FD_ISSET(tcpsock, &v6bits)) { - len = sizeof(inet6peer); - if ((msgsock = accept(tcpsock, - (struct sockaddr *)&inet6peer, - &len)) < 0) { - error = errno; - syslog(LOG_ERR, - "accept failed: %m"); - if (error == ECONNABORTED || - error == EINTR) - continue; - nfsd_exit(1); - } - if (setsockopt(msgsock, SOL_SOCKET, - SO_KEEPALIVE, (char *)&on, - sizeof(on)) < 0) - syslog(LOG_ERR, "setsockopt " - "SO_KEEPALIVE: %m"); - addsockargs.sock = msgsock; - addsockargs.name = (caddr_t)&inet6peer; - addsockargs.namelen = len; - nfssvc(nfssvc_addsock, &addsockargs); - (void)close(msgsock); + len = sizeof(peer); + if ((msgsock = accept(tcpsock, + (struct sockaddr *)&peer, &len)) < 0) { + error = errno; + syslog(LOG_ERR, "accept failed: %m"); + if (error == ECONNABORTED || + error == EINTR) + continue; + nfsd_exit(1); } + if (setsockopt(msgsock, SOL_SOCKET, + SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0) + syslog(LOG_ERR, + "setsockopt SO_KEEPALIVE: %m"); + addsockargs.sock = msgsock; + addsockargs.name = (caddr_t)&peer; + addsockargs.namelen = len; + nfssvc(nfssvc_addsock, &addsockargs); + (void)close(msgsock); } } }