From nobody Thu Aug 13 00:08:57 2026 X-Original-To: dev-commits-src-branches@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 4hL5Ld4xh8zGktB for ; Thu, 13 Aug 2026 00:08:57 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hL5Ld48Jfz3PRb for ; Thu, 13 Aug 2026 00:08:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786579737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jYtX2WPic/KYcHckafVhLe19xrPEXVP4uIKgFOVJwew=; b=hqUZNaq2c65yhRG/AlIcDVE3Gvis0/9vqR4l6y9frMS/20LGRP/D4Eh36gDOU/MO4KYEc+ +5sXswz9LGBwr7cycOsxItYWdjjKMfVHqdoGBqu9ff48yPCD/6P0bZL1pojr1FIsoGtNFi U5GkDF6bW0BzaXU0kD2BHPY36jW7wh0AAM/bp84cLOeguVKtE1QNqQpFJyxXwNKZ8rtTjP zmJt6eK0HGKCZUwye1beOKFHQBlF+DiSXCn2JiC8pkQ+ATI21icFgZeVsuotqH6kf3JKn2 qiIZe2hQVi+v+8FD5WfABnFjMFzhAsEZEjDARtNiVwdODQK9lAbwVsplXFovcA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786579737; a=rsa-sha256; cv=none; b=sodxq+k6tk0Oa4TX3IDfoHA7k1c4B5U8DI7ZGEJ+ICZ5Q+eOiV1FLWl++H3whj94y+twaj WKDhugFyaQXc+cf7JzFhE5PKbDxnbcx6iZ9aetctSGayZyoRrkzyZ7tyl8s6aiHbyekBpp 43zHK6wLi7J60nIquUdtWn9UEUQ9fONI1AxnoY16N+GchuZFbhDMMmw+jnT4vXBfxGCMqU BYlJgK2jTtA1MjFVEv7DuaonPjPP7KUCkwJz548JlanWtSwEaX4Xg3dqgltcdfekGgSQHU N1mvqNtZ0AGl1+Bg+EejPl6GsNuIksWYDbQD4GsYPQZv+FMTsJc5xGvR2RMAhw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786579737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jYtX2WPic/KYcHckafVhLe19xrPEXVP4uIKgFOVJwew=; b=FF1+DtpVUHdU4/wnVfFTE38BUwnVQ7dZA2m0MJ+8vbulwxG5qdF3kz4gVxzjArcdGxxiFB trKX4l3ZUl3Mf2IEtnSb2s8n0Mevfzj77NerOCCglk6HLi/f5tPArIU2KWmuoWl0dJssOH Sf4YgNcCuwz0FsR4QQMQmLQVz9csBL6a+anuwxP1rH2UZqfoxMij61izdLLn1lSbCf12qw 1GMf3igOzTfEM/0rhEg0MEPNIsR+E9Ygd1chuwNWMecra0uYn3aENbK2h4QKP/c8T+JI7V O5S8VhXDbaT4p0wjiY0/HbGcLK1wl3Ol51Y66fIWRetIdxoAqh8SeSGmP04bdg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hL5Ld2dLjznmT for ; Thu, 13 Aug 2026 00:08:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1dc93 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 13 Aug 2026 00:08:57 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav From: Colin Percival Subject: git: f77a60a27ad6 - releng/14.5 - sys/socket.h: Fix AF_MAX List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.5 X-Git-Reftype: branch X-Git-Commit: f77a60a27ad64e3acf26f3dc088c6e80fdd15754 Auto-Submitted: auto-generated Date: Thu, 13 Aug 2026 00:08:57 +0000 Message-Id: <6a7d0b19.1dc93.819bcfc@gitrepo.freebsd.org> The branch releng/14.5 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=f77a60a27ad64e3acf26f3dc088c6e80fdd15754 commit f77a60a27ad64e3acf26f3dc088c6e80fdd15754 Author: Dag-Erling Smørgrav AuthorDate: 2026-08-04 09:55:22 +0000 Commit: Colin Percival CommitDate: 2026-08-13 00:08:29 +0000 sys/socket.h: Fix AF_MAX AF_MAX was always intended to be one more than the greatest allocated value. Jeff broke this in 2013. Unfortunately, a bunch of people then decided to adapt to the mistake instead of correcting it. Approved by: re (cperciva) Fixes: 863c7e45628d (" - Reserve a special AF for SDP. The one we were incorrectly using before was taken by another AF.") MFC after: 3 days Sponsored by: Klara, Inc. Sponsored by: NetApp, Inc. Reviewed by: kevans, glebius Differential Revision: https://reviews.freebsd.org/D58597 (cherry picked from commit ddd850aa7720f77b6605599655df898b16ed74cc) (cherry picked from commit 2d252764711bebe09970507a30dff0f7641c6e0c) --- lib/libifconfig/libifconfig.c | 4 ++-- lib/libifconfig/libifconfig_internal.c | 2 +- sys/kern/vfs_export.c | 2 +- sys/net/route.c | 2 +- sys/net/route/route_ddb.c | 2 +- sys/net/route/route_helpers.c | 4 ++-- sys/net/rtsock.c | 4 ++-- sys/netlink/route/rt.c | 6 +++--- sys/sys/socket.h | 4 +++- 9 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/libifconfig/libifconfig.c b/lib/libifconfig/libifconfig.c index f844ae235a71..9b2f1fd753c8 100644 --- a/lib/libifconfig/libifconfig.c +++ b/lib/libifconfig/libifconfig.c @@ -81,7 +81,7 @@ ifconfig_open(void) if (h == NULL) { return (NULL); } - for (int i = 0; i <= AF_MAX; i++) { + for (int i = 0; i < AF_MAX; i++) { h->sockets[i] = -1; } @@ -92,7 +92,7 @@ void ifconfig_close(ifconfig_handle_t *h) { - for (int i = 0; i <= AF_MAX; i++) { + for (int i = 0; i < AF_MAX; i++) { if (h->sockets[i] != -1) { (void)close(h->sockets[i]); } diff --git a/lib/libifconfig/libifconfig_internal.c b/lib/libifconfig/libifconfig_internal.c index c6c955debb3d..91de1ece59fb 100644 --- a/lib/libifconfig/libifconfig_internal.c +++ b/lib/libifconfig/libifconfig_internal.c @@ -78,7 +78,7 @@ int ifconfig_socket(ifconfig_handle_t *h, const int addressfamily, int *s) { - if (addressfamily > AF_MAX) { + if (addressfamily >= AF_MAX) { h->error.errtype = SOCKET; h->error.errcode = EINVAL; return (-1); diff --git a/sys/kern/vfs_export.c b/sys/kern/vfs_export.c index 96b4464436e3..5e8253c4f149 100644 --- a/sys/kern/vfs_export.c +++ b/sys/kern/vfs_export.c @@ -162,7 +162,7 @@ vfs_hang_addrlist(struct mount *mp, struct netexport *nep, saddr = (struct sockaddr *) (np + 1); if ((error = copyin(argp->ex_addr, saddr, argp->ex_addrlen))) goto out; - if (saddr->sa_family == AF_UNSPEC || saddr->sa_family > AF_MAX) { + if (saddr->sa_family == AF_UNSPEC || saddr->sa_family >= AF_MAX) { error = EINVAL; vfs_mount_error(mp, "Invalid saddr->sa_family: %d"); goto out; diff --git a/sys/net/route.c b/sys/net/route.c index d86f40dedec9..9543b3359a18 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -518,7 +518,7 @@ rt_updatemtu(struct ifnet *ifp) * Unfortunately the only way to do this is to traverse all * routing tables in all fibs/domains. */ - for (i = 1; i <= AF_MAX; i++) { + for (i = 1; i < AF_MAX; i++) { mtu = if_getmtu_family(ifp, i); for (j = 0; j < rt_numfibs; j++) { rnh = rt_tables_get_rnh(j, i); diff --git a/sys/net/route/route_ddb.c b/sys/net/route/route_ddb.c index 71bffd98663b..c93370d0a570 100644 --- a/sys/net/route/route_ddb.c +++ b/sys/net/route/route_ddb.c @@ -174,7 +174,7 @@ DB_SHOW_COMMAND(routetable, db_show_routetable) i = lim = addr; else { i = 1; - lim = AF_MAX; + lim = AF_MAX - 1; } for (; i <= lim; i++) { diff --git a/sys/net/route/route_helpers.c b/sys/net/route/route_helpers.c index 2c0df15b04b7..bee01f28a81d 100644 --- a/sys/net/route/route_helpers.c +++ b/sys/net/route/route_helpers.c @@ -184,7 +184,7 @@ rib_foreach_table_walk(int family, bool wlock, rib_walktree_f_t *wa_f, continue; } - for (int i = 1; i <= AF_MAX; i++) + for (int i = 1; i < AF_MAX; i++) rib_walk_ext(fibnum, i, wlock, wa_f, hook_f, arg); } } @@ -206,7 +206,7 @@ rib_foreach_table_walk_del(int family, rib_filter_f_t *filter_f, void *arg) continue; } - for (int i = 1; i <= AF_MAX; i++) + for (int i = 1; i < AF_MAX; i++) rib_walk_del(fibnum, i, filter_f, arg, 0); } } diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index e3116b8ee4b5..a8e62f5046ce 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -2605,7 +2605,7 @@ sysctl_rtsock(SYSCTL_HANDLER_ARGS) } else if (namelen != 3) return ((namelen < 3) ? EISDIR : ENOTDIR); af = name[0]; - if (af > AF_MAX) + if (af >= AF_MAX) return (EINVAL); bzero(&w, sizeof(w)); w.w_op = name[1]; @@ -2629,7 +2629,7 @@ sysctl_rtsock(SYSCTL_HANDLER_ARGS) case NET_RT_FLAGS: if (af == 0) { /* dump all tables */ i = 1; - lim = AF_MAX; + lim = AF_MAX - 1; } else /* dump only one table */ i = lim = af; diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c index fac174e01efd..810ed219df27 100644 --- a/sys/netlink/route/rt.c +++ b/sys/netlink/route/rt.c @@ -960,7 +960,7 @@ rtnl_handle_newroute(struct nlmsghdr *hdr, struct nlpcb *nlp, /* pre-2.6.19 Linux API compatibility */ if (attrs.rtm_table > 0 && attrs.rta_table == 0) attrs.rta_table = attrs.rtm_table; - if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family > AF_MAX) { + if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family >= AF_MAX) { NLMSG_REPORT_ERR_MSG(npt, "invalid fib"); return (EINVAL); } @@ -1023,7 +1023,7 @@ rtnl_handle_delroute(struct nlmsghdr *hdr, struct nlpcb *nlp, return (ESRCH); } - if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family > AF_MAX) { + if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family >= AF_MAX) { NLMSG_REPORT_ERR_MSG(npt, "invalid fib"); return (EINVAL); } @@ -1046,7 +1046,7 @@ rtnl_handle_getroute(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate * if (error != 0) return (error); - if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family > AF_MAX) { + if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family >= AF_MAX) { NLMSG_REPORT_ERR_MSG(npt, "invalid fib"); return (EINVAL); } diff --git a/sys/sys/socket.h b/sys/sys/socket.h index b2afc735a383..ce6fe421d44b 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -271,7 +271,9 @@ struct accept_filter_arg { #define AF_INET6_SDP 42 /* OFED Socket Direct Protocol ipv6 */ #define AF_HYPERV 43 /* HyperV sockets */ #define AF_DIVERT 44 /* divert(4) */ -#define AF_MAX 44 + +#define AF_MAX 45 + /* * When allocating a new AF_ constant, please only allocate * even numbered constants for FreeBSD until 134 as odd numbered AF_