Discussion:
multicast, ETOOMANYREFS and intro(2)
Jérémie Courrèges-Anglas
2016-02-01 18:56:01 UTC
Permalink
Hi,

while glancing at the multicast code I noticed the use of ETOOMANYREFS:

if (imo->imo_num_memberships == imo->imo_max_memberships) {
struct in_multi **nmships, **omships;
size_t newmax;
/*
* Resize the vector to next power-of-two minus 1. If the
* size would exceed the maximum then we know we've really
* run out of entries. Otherwise, we reallocate the vector.
*/
nmships = NULL;
omships = imo->imo_membership;
newmax = ((imo->imo_max_memberships + 1) * 2) - 1;
if (newmax <= IP_MAX_MEMBERSHIPS) {
nmships = (struct in_multi **)malloc(
sizeof(*nmships) * newmax, M_IPMOPTS,
M_NOWAIT|M_ZERO);
if (nmships != NULL) {
memcpy(nmships, omships,
sizeof(*omships) *
imo->imo_max_memberships);
free(omships, M_IPMOPTS,
sizeof(*omships) *
imo->imo_max_memberships);
imo->imo_membership = nmships;
imo->imo_max_memberships = newmax;
}
}
if (nmships == NULL) {
error = ETOOMANYREFS;
if_put(ifp);
break;
}
}

intro(2) describes it as such:

59 ETOOMANYREFS Too many references: can't splice. Not used in OpenBSD.

Obviously it *is* used, since rev. 1.1. FreeBSD and NetBSD also make
use of it, but FreeBSD doesn't document it.

I don't know whether the kernel code should keep on using it, here's
a patch to fix the documentation:

Thoughts?

Index: lib/libc/sys/intro.2
===================================================================
RCS file: /cvs/src/lib/libc/sys/intro.2,v
retrieving revision 1.62
diff -u -p -r1.62 intro.2
--- lib/libc/sys/intro.2 1 Dec 2015 01:34:16 -0000 1.62
+++ lib/libc/sys/intro.2 31 Jan 2016 00:11:06 -0000
@@ -311,8 +311,6 @@ had already been shut down with a previo
.Xr shutdown 2
call.
.It Er 59 ETOOMANYREFS Em "Too many references: can't splice" .
-Not used in
-.Ox .
.It Er 60 ETIMEDOUT Em "Operation timed out" .
A
.Xr connect 2
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
Todd C. Miller
2016-02-01 20:15:26 UTC
Permalink
On Mon, 01 Feb 2016 19:56:01 +0100, =?utf-8?Q?J=C3=A9r=C3=A9mie_Courr=C3=A8ges-
Post by Jérémie Courrèges-Anglas
59 ETOOMANYREFS Too many references: can't splice. Not used in OpenBSD.
Obviously it *is* used, since rev. 1.1. FreeBSD and NetBSD also make
use of it, but FreeBSD doesn't document it.
I don't know whether the kernel code should keep on using it, here's
I think the correct thing to do here is fix the documentation.

- todd
Martin Pieuchot
2016-02-02 14:27:00 UTC
Permalink
Post by Todd C. Miller
On Mon, 01 Feb 2016 19:56:01 +0100, =?utf-8?Q?J=C3=A9r=C3=A9mie_Courr=C3=A8ges-
Post by Jérémie Courrèges-Anglas
59 ETOOMANYREFS Too many references: can't splice. Not used in OpenBSD.
Obviously it *is* used, since rev. 1.1. FreeBSD and NetBSD also make
use of it, but FreeBSD doesn't document it.
I don't know whether the kernel code should keep on using it, here's
I think the correct thing to do here is fix the documentation.
We could also return ENOBUFS in this case instead. That would
correspond to the errors described in ip(4) (sadly setsockopt(2) is not
really reflecting the code).

Jérémie what other OSes report as errors for IP_ADD_MEMBERSHIP?
Jérémie Courrèges-Anglas
2016-02-05 13:06:25 UTC
Permalink
Post by Martin Pieuchot
Post by Todd C. Miller
On Mon, 01 Feb 2016 19:56:01 +0100, =?utf-8?Q?J=C3=A9r=C3=A9mie_Courr=C3=A8ges-
Post by Jérémie Courrèges-Anglas
59 ETOOMANYREFS Too many references: can't splice. Not used in OpenBSD.
Obviously it *is* used, since rev. 1.1. FreeBSD and NetBSD also make
use of it, but FreeBSD doesn't document it.
I don't know whether the kernel code should keep on using it, here's
I think the correct thing to do here is fix the documentation.
We could also return ENOBUFS in this case instead. That would
correspond to the errors described in ip(4) (sadly setsockopt(2) is not
really reflecting the code).
Jérémie what other OSes report as errors for IP_ADD_MEMBERSHIP?
I only looked at loonix-4.5-rc2 so far: ENOBUFS in this error case.
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
Martin Pieuchot
2016-02-05 16:17:30 UTC
Permalink
Post by Jérémie Courrèges-Anglas
Post by Martin Pieuchot
Post by Todd C. Miller
On Mon, 01 Feb 2016 19:56:01 +0100, =?utf-8?Q?J=C3=A9r=C3=A9mie_Courr=C3=A8ges-
Post by Jérémie Courrèges-Anglas
59 ETOOMANYREFS Too many references: can't splice. Not used in OpenBSD.
Obviously it *is* used, since rev. 1.1. FreeBSD and NetBSD also make
use of it, but FreeBSD doesn't document it.
I don't know whether the kernel code should keep on using it, here's
I think the correct thing to do here is fix the documentation.
We could also return ENOBUFS in this case instead. That would
correspond to the errors described in ip(4) (sadly setsockopt(2) is not
really reflecting the code).
Jérémie what other OSes report as errors for IP_ADD_MEMBERSHIP?
I only looked at loonix-4.5-rc2 so far: ENOBUFS in this error case.
Then I think it's the way to go.
Todd C. Miller
2016-02-07 15:50:18 UTC
Permalink
Post by Martin Pieuchot
Post by Jérémie Courrèges-Anglas
Post by Martin Pieuchot
We could also return ENOBUFS in this case instead. That would
correspond to the errors described in ip(4) (sadly setsockopt(2) is not
really reflecting the code).
Jérémie what other OSes report as errors for IP_ADD_MEMBERSHIP?
I only looked at loonix-4.5-rc2 so far: ENOBUFS in this error case.
Then I think it's the way to go.
Works for me.

- todd
Jérémie Courrèges-Anglas
2016-02-09 00:35:36 UTC
Permalink
Post by Todd C. Miller
Post by Martin Pieuchot
Post by Jérémie Courrèges-Anglas
Post by Martin Pieuchot
We could also return ENOBUFS in this case instead. That would
correspond to the errors described in ip(4) (sadly setsockopt(2) is not
really reflecting the code).
Jérémie what other OSes report as errors for IP_ADD_MEMBERSHIP?
I only looked at loonix-4.5-rc2 so far: ENOBUFS in this error case.
Then I think it's the way to go.
Works for me.
Hmm, FreeBSD and NetBSD still return ETOOMANYREFS in such a situation.
But the only piece of software out there that seems to actively check
for ETOOMANYREFS is D-Bus. Not relevant here since multicast isn't
involved. (https://bugs.freedesktop.org/show_bug.cgi?id=80163)

ok?

Index: sys/netinet/ip_output.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_output.c,v
retrieving revision 1.317
diff -u -p -r1.317 ip_output.c
--- sys/netinet/ip_output.c 21 Jan 2016 11:23:48 -0000 1.317
+++ sys/netinet/ip_output.c 5 Feb 2016 17:46:08 -0000
@@ -1496,7 +1496,7 @@ ip_setmoptions(int optname, struct ip_mo
}
}
if (nmships == NULL) {
- error = ETOOMANYREFS;
+ error = ENOBUFS;
if_put(ifp);
break;
}
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
Loading...