mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 11:25:21 +01:00
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.
Fixes: 863c7e4562 (" - 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
This commit is contained in:
1 parent
495826f69d
commit
ddd850aa77
9 files changed
+16
-14
No files matched your search
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -146,7 +146,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;
|
||||
|
||||
@@ -1339,7 +1339,7 @@ nhops_ifnet_state_changed(struct ifnet *ifp, bool status)
|
||||
struct nhop_iter iter = { .fibnum = ifp->if_fib, .wlock = true };
|
||||
bool nhops_changed;
|
||||
|
||||
for (iter.family = 1; iter.family <= AF_MAX; iter.family++) {
|
||||
for (iter.family = 1; iter.family < AF_MAX; iter.family++) {
|
||||
/*
|
||||
* By tracking nhop changes, we avoid redundant nhgrp
|
||||
* recompilation triggered by multiple events.
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -183,7 +183,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);
|
||||
}
|
||||
}
|
||||
@@ -205,7 +205,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);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -2623,7 +2623,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];
|
||||
@@ -2647,7 +2647,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;
|
||||
|
||||
|
||||
@@ -1053,7 +1053,7 @@ rtnl_handle_newroute(struct nlmsghdr *hdr, struct nlpcb *nlp,
|
||||
}
|
||||
|
||||
old_linux_compat(&attrs);
|
||||
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);
|
||||
}
|
||||
@@ -1120,7 +1120,7 @@ rtnl_handle_delroute(struct nlmsghdr *hdr, struct nlpcb *nlp,
|
||||
}
|
||||
|
||||
old_linux_compat(&attrs);
|
||||
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);
|
||||
}
|
||||
@@ -1144,7 +1144,7 @@ rtnl_handle_getroute(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *
|
||||
return (error);
|
||||
|
||||
old_linux_compat(&attrs);
|
||||
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);
|
||||
}
|
||||
|
||||
+3
-1
@@ -272,7 +272,9 @@ struct accept_filter_arg {
|
||||
#define AF_HYPERV 43 /* HyperV sockets */
|
||||
#define AF_DIVERT 44 /* divert(4) */
|
||||
#define AF_IPFWLOG 46
|
||||
#define AF_MAX 46
|
||||
|
||||
#define AF_MAX 47
|
||||
|
||||
/*
|
||||
* When allocating a new AF_ constant, please only allocate
|
||||
* even numbered constants for FreeBSD until 134 as odd numbered AF_
|
||||
|
||||
Reference in new issue
Block a user