Some stuff I found while looking at kroute code is that the kernel is not always filling the info in the same way. This tries to fix this. First of all make sure the RTM_GET lookups fill out rtm_index no matter what. We do the same thing in the sysctl code and also in most other RTM_* messages. Second fill out rtm_pid in the sysctl dumper. This will reduce the check that I commited to ospfd for RTM_GET messages to just check for the own pid.
-- :wq Claudio Index: net/rtsock.c =================================================================== RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.176 diff -u -p -r1.176 rtsock.c --- net/rtsock.c 24 Oct 2015 11:58:47 -0000 1.176 +++ net/rtsock.c 25 Oct 2015 09:27:30 -0000 @@ -714,7 +714,6 @@ report: rt->rt_ifa->ifa_dstaddr; else info.rti_info[RTAX_BRD] = NULL; - rtm->rtm_index = ifp->if_index; } if_put(ifp); len = rt_msg2(rtm->rtm_type, RTM_VERSION, &info, NULL, @@ -735,6 +734,7 @@ report: rtm->rtm_flags = rt->rt_flags; rtm->rtm_use = 0; rtm->rtm_priority = rt->rt_priority & RTP_MASK; + rtm->rtm_index = rt->rt_ifidx; rt_getmetrics(&rt->rt_rmx, &rtm->rtm_rmx); rtm->rtm_addrs = info.rti_addrs; break; @@ -1251,6 +1251,7 @@ sysctl_dumpentry(struct rtentry *rt, voi if (w->w_where && w->w_tmem && w->w_needed <= 0) { struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem; + rtm->rtm_pid = curproc->p_p->ps_pid; rtm->rtm_flags = rt->rt_flags; rtm->rtm_priority = rt->rt_priority & RTP_MASK; rt_getmetrics(&rt->rt_rmx, &rtm->rtm_rmx);