From owner-svn-src-head@freebsd.org Thu Apr 4 19:01:16 2019 Return-Path: Delivered-To: svn-src-head@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 EB1D41553D0B; Thu, 4 Apr 2019 19:01:15 +0000 (UTC) (envelope-from rgrimes@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 89ADF87E42; Thu, 4 Apr 2019 19:01:15 +0000 (UTC) (envelope-from rgrimes@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 60B991A53; Thu, 4 Apr 2019 19:01:15 +0000 (UTC) (envelope-from rgrimes@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x34J1FXC085304; Thu, 4 Apr 2019 19:01:15 GMT (envelope-from rgrimes@FreeBSD.org) Received: (from rgrimes@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x34J1DN5085296; Thu, 4 Apr 2019 19:01:13 GMT (envelope-from rgrimes@FreeBSD.org) Message-Id: <201904041901.x34J1DN5085296@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rgrimes set sender to rgrimes@FreeBSD.org using -f From: "Rodney W. Grimes" Date: Thu, 4 Apr 2019 19:01:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r345888 - in head: lib/libc/net sys/fs/nfsclient sys/netinet sys/netinet/netdump sys/netpfil/ipfw/nat64 sys/netpfil/pf X-SVN-Group: head X-SVN-Commit-Author: rgrimes X-SVN-Commit-Paths: in head: lib/libc/net sys/fs/nfsclient sys/netinet sys/netinet/netdump sys/netpfil/ipfw/nat64 sys/netpfil/pf X-SVN-Commit-Revision: 345888 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 89ADF87E42 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.960,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Apr 2019 19:01:16 -0000 Author: rgrimes Date: Thu Apr 4 19:01:13 2019 New Revision: 345888 URL: https://svnweb.freebsd.org/changeset/base/345888 Log: Use IN_foo() macros from sys/netinet/in.h inplace of handcrafted code There are a few places that use hand crafted versions of the macros from sys/netinet/in.h making it difficult to actually alter the values in use by these macros. Correct that by replacing handcrafted code with proper macro usage. Reviewed by: karels, kristof Approved by: bde (mentor) MFC after: 3 weeks Sponsored by: John Gilmore Differential Revision: https://reviews.freebsd.org/D19317 Modified: head/lib/libc/net/getnameinfo.c head/sys/fs/nfsclient/nfs_clport.c head/sys/netinet/in.c head/sys/netinet/ip_input.c head/sys/netinet/ip_output.c head/sys/netinet/netdump/netdump_client.c head/sys/netpfil/ipfw/nat64/nat64_translate.h head/sys/netpfil/pf/pf.c Modified: head/lib/libc/net/getnameinfo.c ============================================================================== --- head/lib/libc/net/getnameinfo.c Thu Apr 4 18:52:03 2019 (r345887) +++ head/lib/libc/net/getnameinfo.c Thu Apr 4 19:01:13 2019 (r345888) @@ -224,10 +224,8 @@ getnameinfo_inet(const struct afd *afd, case AF_INET: v4a = (u_int32_t) ntohl(((const struct sockaddr_in *)sa)->sin_addr.s_addr); - if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a)) - flags |= NI_NUMERICHOST; - v4a >>= IN_CLASSA_NSHIFT; - if (v4a == 0) + if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a) || + IN_ZERONET(v4a)) flags |= NI_NUMERICHOST; break; #ifdef INET6 Modified: head/sys/fs/nfsclient/nfs_clport.c ============================================================================== --- head/sys/fs/nfsclient/nfs_clport.c Thu Apr 4 18:52:03 2019 (r345887) +++ head/sys/fs/nfsclient/nfs_clport.c Thu Apr 4 19:01:13 2019 (r345888) @@ -957,8 +957,7 @@ nfscl_getmyip(struct nfsmount *nmp, struct in6_addr *p if (error != 0) return (NULL); - if ((ntohl(nh_ext.nh_src.s_addr) >> IN_CLASSA_NSHIFT) == - IN_LOOPBACKNET) { + if (IN_LOOPBACK(ntohl(nh_ext.nh_src.s_addr))) { /* Ignore loopback addresses */ return (NULL); } Modified: head/sys/netinet/in.c ============================================================================== --- head/sys/netinet/in.c Thu Apr 4 18:52:03 2019 (r345887) +++ head/sys/netinet/in.c Thu Apr 4 19:01:13 2019 (r345888) @@ -191,15 +191,10 @@ int in_canforward(struct in_addr in) { u_long i = ntohl(in.s_addr); - u_long net; - if (IN_EXPERIMENTAL(i) || IN_MULTICAST(i) || IN_LINKLOCAL(i)) + if (IN_EXPERIMENTAL(i) || IN_MULTICAST(i) || IN_LINKLOCAL(i) || + IN_ZERONET(i) || IN_LOOPBACK(i)) return (0); - if (IN_CLASSA(i)) { - net = i & IN_CLASSA_NET; - if (net == 0 || net == (IN_LOOPBACKNET << IN_CLASSA_NSHIFT)) - return (0); - } return (1); } Modified: head/sys/netinet/ip_input.c ============================================================================== --- head/sys/netinet/ip_input.c Thu Apr 4 18:52:03 2019 (r345887) +++ head/sys/netinet/ip_input.c Thu Apr 4 19:01:13 2019 (r345888) @@ -499,10 +499,10 @@ ip_input(struct mbuf *m) IP_PROBE(receive, NULL, NULL, ip, m->m_pkthdr.rcvif, ip, NULL); - /* 127/8 must not appear on wire - RFC1122 */ + /* IN_LOOPBACK must not appear on the wire - RFC1122 */ ifp = m->m_pkthdr.rcvif; - if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || - (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) { + if (IN_LOOPBACK(ntohl(ip->ip_dst.s_addr)) || + IN_LOOPBACK(ntohl(ip->ip_src.s_addr))) { if ((ifp->if_flags & IFF_LOOPBACK) == 0) { IPSTAT_INC(ips_badaddr); goto bad; Modified: head/sys/netinet/ip_output.c ============================================================================== --- head/sys/netinet/ip_output.c Thu Apr 4 18:52:03 2019 (r345887) +++ head/sys/netinet/ip_output.c Thu Apr 4 19:01:13 2019 (r345888) @@ -594,9 +594,9 @@ sendit: } } - /* 127/8 must not appear on wire - RFC1122. */ - if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || - (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) { + /* IN_LOOPBACK must not appear on the wire - RFC1122. */ + if (IN_LOOPBACK(ntohl(ip->ip_dst.s_addr)) || + IN_LOOPBACK(ntohl(ip->ip_src.s_addr))) { if ((ifp->if_flags & IFF_LOOPBACK) == 0) { IPSTAT_INC(ips_badaddr); error = EADDRNOTAVAIL; Modified: head/sys/netinet/netdump/netdump_client.c ============================================================================== --- head/sys/netinet/netdump/netdump_client.c Thu Apr 4 18:52:03 2019 (r345887) +++ head/sys/netinet/netdump/netdump_client.c Thu Apr 4 19:01:13 2019 (r345888) @@ -557,8 +557,8 @@ netdump_handle_ip(struct mbuf **mb) } #ifdef INVARIANTS - if (((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || - (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) && + if ((IN_LOOPBACK(ntohl(ip->ip_dst.s_addr)) || + IN_LOOPBACK(ntohl(ip->ip_src.s_addr))) && (m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) == 0) { NETDDEBUG("Bad IP header (RFC1122)\n"); return; Modified: head/sys/netpfil/ipfw/nat64/nat64_translate.h ============================================================================== --- head/sys/netpfil/ipfw/nat64/nat64_translate.h Thu Apr 4 18:52:03 2019 (r345887) +++ head/sys/netpfil/ipfw/nat64/nat64_translate.h Thu Apr 4 19:01:13 2019 (r345888) @@ -123,14 +123,9 @@ static inline int nat64_check_ip4(in_addr_t ia) { - /* IN_LOOPBACK */ - if ((ia & htonl(0xff000000)) == htonl(0x7f000000)) - return (1); - /* IN_LINKLOCAL */ - if ((ia & htonl(0xffff0000)) == htonl(0xa9fe0000)) - return (1); - /* IN_MULTICAST & IN_EXPERIMENTAL */ - if ((ia & htonl(0xe0000000)) == htonl(0xe0000000)) + /* These checks are ordered from most likely to least */ + if (IN_MULTICAST(ntohl(ia)) || IN_LOOPBACK(ntohl(ia)) || + IN_LINKLOCAL(ntohl(ia)) || IN_EXPERIMENTAL(ntohl(ia))) return (1); return (0); } Modified: head/sys/netpfil/pf/pf.c ============================================================================== --- head/sys/netpfil/pf/pf.c Thu Apr 4 18:52:03 2019 (r345887) +++ head/sys/netpfil/pf/pf.c Thu Apr 4 19:01:13 2019 (r345888) @@ -6170,7 +6170,7 @@ done: pd.proto == IPPROTO_UDP) && s != NULL && s->nat_rule.ptr != NULL && (s->nat_rule.ptr->action == PF_RDR || s->nat_rule.ptr->action == PF_BINAT) && - (ntohl(pd.dst->v4.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) + IN_LOOPBACK(ntohl(pd.dst->v4.s_addr))) m->m_flags |= M_SKIP_FIREWALL; if (action == PF_PASS && r->divert.port && ip_divert_ptr != NULL &&