From 1b6002ec304141bc5a16035998bab0f87275b9a0 Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Tue, 5 Aug 2003 17:01:33 +0000 Subject: [PATCH] * makes mfc[MFCTBLSIZ] and vif[MAXVIFS] tables accessible via sysctl: - sysctlbyname("net.inet.ip.mfctable", ...) - sysctlbyname("net.inet.ip.viftable", ...) This change is needed so netstat can use sysctlbyname() to read the data from those tables. Otherwise, in some cases "netstat -g" may fail to report the multicast forwarding information (e.g., if we run a multicast router on PicoBSD). * Bug fix: when sending IGMPMSG_WRONGVIF upcall to the multicast routing daemon, set properly "im->im_vif" to the receiving incoming interface of the packet that triggered that upcall rather than to the expected incoming interface of that packet. * Bug fix: add missing increment of counter "mrtstat.mrts_upcalls" * Few formatting nits (e.g., replace extra spaces with TABs) Submitted by: Pavlin Radoslavov --- sys/netinet/ip_mroute.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index 5abf2ee7c119..f0f2471370c7 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -68,8 +68,16 @@ SYSCTL_STRUCT(_net_inet_ip, OID_AUTO, mrtstat, CTLFLAG_RW, "Multicast Routing Statistics (struct mrtstat, netinet/ip_mroute.h)"); static struct mfc *mfctable[MFCTBLSIZ]; -static u_char nexpire[MFCTBLSIZ]; +SYSCTL_OPAQUE(_net_inet_ip, OID_AUTO, mfctable, CTLFLAG_RD, + &mfctable, sizeof(mfctable), "S,*mfc[MFCTBLSIZ]", + "Multicast Forwarding Table (struct *mfc[MFCTBLSIZ], netinet/ip_mroute.h)"); + static struct vif viftable[MAXVIFS]; +SYSCTL_OPAQUE(_net_inet_ip, OID_AUTO, viftable, CTLFLAG_RD, + &viftable, sizeof(viftable), "S,vif[MAXVIFS]", + "Multicast Virtual Interfaces (struct vif[MAXVIFS], netinet/ip_mroute.h)"); + +static u_char nexpire[MFCTBLSIZ]; static struct callout_handle expire_upcalls_ch; @@ -1084,9 +1092,9 @@ X_ip_mforward(struct ip *ip, struct ifnet *ifp, * Locate the vifi for the incoming interface for this packet. * If none found, drop packet. */ - for (vifi=0; vifi= numvifs) /* vif not found, drop packet */ + if (vifi >= numvifs) /* vif not found, drop packet */ goto non_fatal; /* no upcall, so make a new entry */ @@ -1241,11 +1249,11 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt, vifi_t xmt_vif) * input, they shouldn't get counted on output, so statistics keeping is * separate. */ -#define MC_SEND(ip,vifp,m) { \ - if ((vifp)->v_flags & VIFF_TUNNEL) \ - encap_send((ip), (vifp), (m)); \ - else \ - phyint_send((ip), (vifp), (m)); \ +#define MC_SEND(ip,vifp,m) { \ + if ((vifp)->v_flags & VIFF_TUNNEL) \ + encap_send((ip), (vifp), (m)); \ + else \ + phyint_send((ip), (vifp), (m)); \ } /* @@ -1280,6 +1288,12 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt, vifi_t xmt_vif) struct timeval now; u_long delta; + /* Get vifi for the incoming packet */ + for (vifi=0; vifi < numvifs && viftable[vifi].v_ifp != ifp; vifi++) + ; + if (vifi >= numvifs) + return 0; /* if not found: ignore the packet */ + GET_TIME(now); TV_DELTA(rt->mfc_last_assert, now, delta); @@ -1302,8 +1316,9 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt, vifi_t xmt_vif) im->im_mbz = 0; im->im_vif = vifi; - k_igmpsrc.sin_addr = im->im_src; + mrtstat.mrts_upcalls++; + k_igmpsrc.sin_addr = im->im_src; if (socket_send(ip_mrouter, mm, &k_igmpsrc) < 0) { log(LOG_WARNING, "ip_mforward: ip_mrouter socket queue full\n");