On 14/12/16(Wed) 16:54, Rafael Zalamena wrote:
> After running the igmpproxy in multiple domains I noticed that the kernel
> started complaining about sending packets on wrong domains. Here is the
> exact message:
> "
> vio1: trying to send packet on wrong domain. if 1 vs. mbuf 0
> "
>
> After some debugging I traced the problem to the igmp_sendpkt() function
> and it seems that it is missing to set the mbuf rdomain, so this is
> exactly what this diff does.
It doesn't make sense to call if_get(9) when all the callers of
igmp_sendpkt() already have a reference to the sending ifp. if_get(9)
has a cost and adds complexity. I'd rather pass ifp or the rdomain to
igmp_sendpkt().
> Index: sys/netinet/igmp.c
> ===================================================================
> RCS file: /home/obsdcvs/src/sys/netinet/igmp.c,v
> retrieving revision 1.56
> diff -u -p -r1.56 igmp.c
> --- sys/netinet/igmp.c 5 Dec 2016 15:31:43 -0000 1.56
> +++ sys/netinet/igmp.c 14 Dec 2016 15:40:08 -0000
> @@ -613,14 +613,21 @@ igmp_slowtimo(void)
> void
> igmp_sendpkt(struct in_multi *inm, int type, in_addr_t addr)
> {
> + struct ifnet *ifp;
> struct mbuf *m;
> struct igmp *igmp;
> struct ip *ip;
> struct ip_moptions imo;
>
> + if ((ifp = if_get(inm->inm_ifidx)) == NULL)
> + return;
> +
> MGETHDR(m, M_DONTWAIT, MT_HEADER);
> - if (m == NULL)
> + if (m == NULL) {
> + if_put(ifp);
> return;
> + }
> +
> /*
> * Assume max_linkhdr + sizeof(struct ip) + IGMP_MINLEN
> * is smaller than mbuf size returned by MGETHDR.
> @@ -652,6 +659,7 @@ igmp_sendpkt(struct in_multi *inm, int t
> m->m_data -= sizeof(struct ip);
> m->m_len += sizeof(struct ip);
>
> + m->m_pkthdr.ph_rtableid = ifp->if_rdomain;
> imo.imo_ifidx = inm->inm_ifidx;
> imo.imo_ttl = 1;
>
> @@ -666,6 +674,7 @@ igmp_sendpkt(struct in_multi *inm, int t
> #endif /* MROUTING */
>
> ip_output(m, router_alert, NULL, IP_MULTICASTOPTS, &imo, NULL, 0);
> + if_put(ifp);
>
> ++igmpstat.igps_snd_reports;
> }
>