From nobody Tue Nov 09 15:36:01 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 9D3CC18486B9; Tue, 9 Nov 2021 15:36:01 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HpXBT3v5Pz4tYd; Tue, 9 Nov 2021 15:36:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 669582752A; Tue, 9 Nov 2021 15:36:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1A9Fa1Ud099850; Tue, 9 Nov 2021 15:36:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A9Fa1NS099849; Tue, 9 Nov 2021 15:36:01 GMT (envelope-from git) Date: Tue, 9 Nov 2021 15:36:01 GMT Message-Id: <202111091536.1A9Fa1NS099849@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mike Karels Subject: git: 20d59403961d - main - kernel: deprecate Internet Class A/B/C List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: karels X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 20d59403961d531467cfab22163f49c131cc8b55 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by karels: URL: https://cgit.FreeBSD.org/src/commit/?id=20d59403961d531467cfab22163f49c131cc8b55 commit 20d59403961d531467cfab22163f49c131cc8b55 Author: Mike Karels AuthorDate: 2021-10-27 03:01:09 +0000 Commit: Mike Karels CommitDate: 2021-11-09 15:32:38 +0000 kernel: deprecate Internet Class A/B/C Hide historical Class A/B/C macros unless IN_HISTORICAL_NETS is defined; define it for user level. Define IN_MULTICAST separately from IN_CLASSD, and use it in pf instead of IN_CLASSD. Stop using class for setting default masks when not specified; instead, define new default mask (24 bits). Warn when an Internet address is set without a mask. MFC after: 1 month Reviewed by: cy Differential Revision: https://reviews.freebsd.org/D32708 --- sys/contrib/ipfilter/netinet/fil.c | 2 +- sys/netinet/in.c | 19 +++++++++---------- sys/netinet/in.h | 22 +++++++++++++++++----- sys/nfs/bootp_subr.c | 16 ++++++++-------- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/sys/contrib/ipfilter/netinet/fil.c b/sys/contrib/ipfilter/netinet/fil.c index c04015c2b41e..89f50c261474 100644 --- a/sys/contrib/ipfilter/netinet/fil.c +++ b/sys/contrib/ipfilter/netinet/fil.c @@ -1715,7 +1715,7 @@ ipf_pr_ipv4hdr(fin) fin->fin_crc += fi->fi_saddr; fi->fi_daddr = ip->ip_dst.s_addr; fin->fin_crc += fi->fi_daddr; - if (IN_CLASSD(ntohl(fi->fi_daddr))) + if (IN_MULTICAST(ntohl(fi->fi_daddr))) fin->fin_flx |= FI_MULTICAST|FI_MBCAST; /* diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 8eb20f0f2d27..6bc4f638a98a 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -449,18 +449,17 @@ in_aifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, struct thread *td) ia->ia_sockmask = *mask; ia->ia_subnetmask = ntohl(ia->ia_sockmask.sin_addr.s_addr); } else { - in_addr_t i = ntohl(addr->sin_addr.s_addr); - /* - * Be compatible with network classes, if netmask isn't - * supplied, guess it based on classes. + * If netmask isn't supplied, use default for now. + * This is deprecated for interfaces other than loopback + * or point-to-point; warn in other cases. In the future + * we should return an error rather than warning. */ - if (IN_CLASSA(i)) - ia->ia_subnetmask = IN_CLASSA_NET; - else if (IN_CLASSB(i)) - ia->ia_subnetmask = IN_CLASSB_NET; - else - ia->ia_subnetmask = IN_CLASSC_NET; + if ((ifp->if_flags & (IFF_POINTOPOINT | IFF_LOOPBACK)) == 0) + printf("%s: set address: WARNING: network mask" + " should be specified; using default mask\n", + ifp->if_xname); + ia->ia_subnetmask = IN_NETMASK_DEFAULT; ia->ia_sockmask.sin_addr.s_addr = htonl(ia->ia_subnetmask); } ia->ia_subnet = ntohl(addr->sin_addr.s_addr) & ia->ia_subnetmask; diff --git a/sys/netinet/in.h b/sys/netinet/in.h index 0506f1739e9b..92d150701422 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -342,10 +342,15 @@ __END_DECLS #define IPPORT_MAX 65535 /* - * Definitions of bits in internet address integers. - * On subnets, the decomposition of addresses to host and net parts - * is done according to subnet mask, not the masks here. + * Historical definitions of bits in internet address integers + * (pre-CIDR). Class A/B/C are long obsolete, and now deprecated. + * Hide these definitions from the kernel unless IN_HISTORICAL_NETS + * is defined. Provide the historical definitions to user level for now. */ +#ifndef _KERNEL +#define IN_HISTORICAL_NETS +#endif +#ifdef IN_HISTORICAL_NETS #define IN_CLASSA(i) (((in_addr_t)(i) & 0x80000000) == 0) #define IN_CLASSA_NET 0xff000000 #define IN_CLASSA_NSHIFT 24 @@ -362,12 +367,17 @@ __END_DECLS #define IN_CLASSC_NET 0xffffff00 #define IN_CLASSC_NSHIFT 8 #define IN_CLASSC_HOST 0x000000ff +#endif /* IN_HISTORICAL_NETS */ + +#define IN_NETMASK_DEFAULT 0xffffff00 /* mask when forced to guess */ -#define IN_CLASSD(i) (((in_addr_t)(i) & 0xf0000000) == 0xe0000000) +#define IN_MULTICAST(i) (((in_addr_t)(i) & 0xf0000000) == 0xe0000000) +#ifdef IN_HISTORICAL_NETS +#define IN_CLASSD(i) IN_MULTICAST(i) #define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */ #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ #define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */ -#define IN_MULTICAST(i) IN_CLASSD(i) +#endif /* IN_HISTORICAL_NETS */ #define IN_EXPERIMENTAL(i) (((in_addr_t)(i) & 0xf0000000) == 0xf0000000) #define IN_BADCLASS(i) (((in_addr_t)(i) & 0xf0000000) == 0xf0000000) @@ -398,7 +408,9 @@ __END_DECLS #define INADDR_ALLMDNS_GROUP ((in_addr_t)0xe00000fb) /* 224.0.0.251 */ #define INADDR_MAX_LOCAL_GROUP ((in_addr_t)0xe00000ff) /* 224.0.0.255 */ +#ifdef IN_HISTORICAL_NETS #define IN_LOOPBACKNET 127 /* official! */ +#endif /* IN_HISTORICAL_NETS */ #define IN_RFC3021_MASK ((in_addr_t)0xfffffffe) diff --git a/sys/nfs/bootp_subr.c b/sys/nfs/bootp_subr.c index 2386a23084da..a6dfbe0334f8 100644 --- a/sys/nfs/bootp_subr.c +++ b/sys/nfs/bootp_subr.c @@ -654,7 +654,7 @@ bootpc_call(struct bootpc_globalcontext *gctx, struct thread *td) error, (int )bootp_so->so_state); /* Set netmask to 255.0.0.0 */ - sin->sin_addr.s_addr = htonl(IN_CLASSA_NET); + sin->sin_addr.s_addr = htonl(0xff000000); error = ifioctl(bootp_so, SIOCAIFADDR, (caddr_t)ifra, td); if (error != 0) @@ -882,7 +882,7 @@ bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx, struct thread *td) clear_sinaddr(sin); sin = (struct sockaddr_in *)&ifra->ifra_mask; clear_sinaddr(sin); - sin->sin_addr.s_addr = htonl(IN_CLASSA_NET); + sin->sin_addr.s_addr = htonl(0xff000000); sin = (struct sockaddr_in *)&ifra->ifra_broadaddr; clear_sinaddr(sin); sin->sin_addr.s_addr = htonl(INADDR_BROADCAST); @@ -1485,12 +1485,12 @@ bootpc_decode_reply(struct nfsv3_diskless *nd, struct bootpc_ifcontext *ifctx, printf("\n"); if (ifctx->gotnetmask == 0) { - if (IN_CLASSA(ntohl(ifctx->myaddr.sin_addr.s_addr))) - ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSA_NET); - else if (IN_CLASSB(ntohl(ifctx->myaddr.sin_addr.s_addr))) - ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSB_NET); - else - ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSC_NET); + /* + * If there is no netmask, use a default, but we really + * need the right mask from the server. + */ + printf("%s: no netmask received!\n", ifctx->ireq.ifr_name); + ifctx->netmask.sin_addr.s_addr = htonl(IN_NETMASK_DEFAULT); } }