...and in the end, they believe the mbuf(9) flags!
There's no good reason to recheck if the IP destination address is a
multicast or broadcast in {tcp,udp}_input(). We've already done that
when the packet got delivered.
So the diff below makes sure the multicast flag is set (jut be as
paranoid as with broadcast) and check for these flags in the upper
layer.
I verified with crafted packets that this works, the goal of this diff
is obviously to reduce the usage of "rcvif" pointers (and simplify
in_broadcast() afterward).
Comments, ok?
Index: netinet/ip_input.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ip_input.c,v
retrieving revision 1.241
diff -u -p -r1.241 ip_input.c
--- netinet/ip_input.c 5 Nov 2014 14:03:02 -0000 1.241
+++ netinet/ip_input.c 19 Nov 2014 15:39:59 -0000
@@ -348,6 +348,10 @@ ipv4_input(struct mbuf *m)
if (IN_MULTICAST(ip->ip_dst.s_addr)) {
struct in_multi *inm;
+
+ /* Paranoia. */
+ m->m_flags |= M_MCAST;
+
#ifdef MROUTING
if (ipmforwarding && ip_mrouter) {
if (m->m_flags & M_EXT) {
Index: netinet/tcp_input.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/tcp_input.c,v
retrieving revision 1.283
diff -u -p -r1.283 tcp_input.c
--- netinet/tcp_input.c 18 Nov 2014 02:37:31 -0000 1.283
+++ netinet/tcp_input.c 19 Nov 2014 15:39:59 -0000
@@ -394,7 +394,6 @@ tcp_input(struct mbuf *m, ...)
/*
* RFC1122 4.2.3.10, p. 104: discard bcast/mcast SYN
- * See below for AF specific multicast.
*/
if (m->m_flags & (M_BCAST|M_MCAST))
goto drop;
@@ -459,10 +458,6 @@ tcp_input(struct mbuf *m, ...)
switch (af) {
case AF_INET:
ip = mtod(m, struct ip *);
- if (IN_MULTICAST(ip->ip_dst.s_addr) ||
- in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif,
- m->m_pkthdr.ph_rtableid))
- goto drop;
#ifdef TCP_ECN
/* save ip_tos before clearing it for checksum */
iptos = ip->ip_tos;
Index: netinet/udp_usrreq.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/udp_usrreq.c,v
retrieving revision 1.191
diff -u -p -r1.191 udp_usrreq.c
--- netinet/udp_usrreq.c 9 Nov 2014 22:05:08 -0000 1.191
+++ netinet/udp_usrreq.c 19 Nov 2014 15:39:59 -0000
@@ -400,16 +400,7 @@ udp_input(struct mbuf *m, ...)
}
#endif
-#ifdef INET6
- if ((ip6 && IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) ||
- (ip && IN_MULTICAST(ip->ip_dst.s_addr)) ||
- (ip && in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif,
- m->m_pkthdr.ph_rtableid))) {
-#else /* INET6 */
- if (IN_MULTICAST(ip->ip_dst.s_addr) ||
- in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif,
- m->m_pkthdr.ph_rtableid)) {
-#endif /* INET6 */
+ if (m->m_flags & (M_BCAST|M_MCAST)) {
struct inpcb *last;
/*
* Deliver a multicast or broadcast datagram to *all* sockets
Index: netinet6/ip6_input.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet6/ip6_input.c,v
retrieving revision 1.130
diff -u -p -r1.130 ip6_input.c
--- netinet6/ip6_input.c 14 Oct 2014 09:52:26 -0000 1.130
+++ netinet6/ip6_input.c 19 Nov 2014 15:39:59 -0000
@@ -398,6 +398,9 @@ ip6_input(struct mbuf *m)
if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
struct in6_multi *in6m = 0;
+ /* Paranoia. */
+ m->m_flags |= M_MCAST;
+
in6_ifstat_inc(ifp, ifs6_in_mcast);
/*
* See if we belong to the destination multicast group on the