svn commit: r346710 - in stable/12: lib/libc/net sys/fs/nfsclient sys/netinet sys/netinet/netdump sys/netpfil/ipfw/nat64 sys/netpfil/pf
Rodney W. Grimes
rgrimes at FreeBSD.org
Thu Apr 25 21:28:31 UTC 2019
Author: rgrimes
Date: Thu Apr 25 21:28:28 2019
New Revision: 346710
URL: https://svnweb.freebsd.org/changeset/base/346710
Log:
MFC: r345888: 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, implicit)
Sponsored by: John Gilmore
Differential Revision: https://reviews.freebsd.org/D19317
Modified:
stable/12/lib/libc/net/getnameinfo.c
stable/12/sys/fs/nfsclient/nfs_clport.c
stable/12/sys/netinet/in.c
stable/12/sys/netinet/ip_input.c
stable/12/sys/netinet/ip_output.c
stable/12/sys/netinet/netdump/netdump_client.c
stable/12/sys/netpfil/ipfw/nat64/nat64_translate.h
stable/12/sys/netpfil/pf/pf.c
Directory Properties:
stable/12/ (props changed)
Modified: stable/12/lib/libc/net/getnameinfo.c
==============================================================================
--- stable/12/lib/libc/net/getnameinfo.c Thu Apr 25 21:25:32 2019 (r346709)
+++ stable/12/lib/libc/net/getnameinfo.c Thu Apr 25 21:28:28 2019 (r346710)
@@ -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: stable/12/sys/fs/nfsclient/nfs_clport.c
==============================================================================
--- stable/12/sys/fs/nfsclient/nfs_clport.c Thu Apr 25 21:25:32 2019 (r346709)
+++ stable/12/sys/fs/nfsclient/nfs_clport.c Thu Apr 25 21:28:28 2019 (r346710)
@@ -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: stable/12/sys/netinet/in.c
==============================================================================
--- stable/12/sys/netinet/in.c Thu Apr 25 21:25:32 2019 (r346709)
+++ stable/12/sys/netinet/in.c Thu Apr 25 21:28:28 2019 (r346710)
@@ -190,15 +190,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: stable/12/sys/netinet/ip_input.c
==============================================================================
--- stable/12/sys/netinet/ip_input.c Thu Apr 25 21:25:32 2019 (r346709)
+++ stable/12/sys/netinet/ip_input.c Thu Apr 25 21:28:28 2019 (r346710)
@@ -501,10 +501,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: stable/12/sys/netinet/ip_output.c
==============================================================================
--- stable/12/sys/netinet/ip_output.c Thu Apr 25 21:25:32 2019 (r346709)
+++ stable/12/sys/netinet/ip_output.c Thu Apr 25 21:28:28 2019 (r346710)
@@ -588,9 +588,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: stable/12/sys/netinet/netdump/netdump_client.c
==============================================================================
--- stable/12/sys/netinet/netdump/netdump_client.c Thu Apr 25 21:25:32 2019 (r346709)
+++ stable/12/sys/netinet/netdump/netdump_client.c Thu Apr 25 21:28:28 2019 (r346710)
@@ -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: stable/12/sys/netpfil/ipfw/nat64/nat64_translate.h
==============================================================================
--- stable/12/sys/netpfil/ipfw/nat64/nat64_translate.h Thu Apr 25 21:25:32 2019 (r346709)
+++ stable/12/sys/netpfil/ipfw/nat64/nat64_translate.h Thu Apr 25 21:28:28 2019 (r346710)
@@ -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: stable/12/sys/netpfil/pf/pf.c
==============================================================================
--- stable/12/sys/netpfil/pf/pf.c Thu Apr 25 21:25:32 2019 (r346709)
+++ stable/12/sys/netpfil/pf/pf.c Thu Apr 25 21:28:28 2019 (r346710)
@@ -6172,7 +6172,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 &&
More information about the svn-src-all
mailing list