From 913af5185990b66c7dd1609fafbe77f0b4adb5c0 Mon Sep 17 00:00:00 2001 From: Luigi Rizzo Date: Sat, 17 Apr 2004 15:09:36 +0000 Subject: [PATCH] misc cleanup in sysctl_ifmalist(): + remove a partly incorrect comment that i introduced in the last commit; + deal with the correct part of the above comment by cleaning up the updates of 'info' -- rti_addrs needd not to be updated, rti_info[RTAX_IFP] can be set once outside the loop. While at it, correct a few misspelling of NULL as 0, but there are way too many in this file, and i did not want to clutter the important part of this commit. --- sys/net/rtsock.c | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 6ba86d0cd45..3c72138fc16 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -408,8 +408,7 @@ route_output(m, so) info.rti_info[RTAX_IFA] = 0; } } - len = rt_msg2(rtm->rtm_type, &info, (caddr_t)0, - (struct walkarg *)0); + len = rt_msg2(rtm->rtm_type, &info, NULL, NULL); if (len > rtm->rtm_msglen) { struct rt_msghdr *new_rtm; R_Malloc(new_rtm, struct rt_msghdr *, len); @@ -420,8 +419,7 @@ route_output(m, so) Bcopy(rtm, new_rtm, rtm->rtm_msglen); Free(rtm); rtm = new_rtm; } - (void)rt_msg2(rtm->rtm_type, &info, (caddr_t)rtm, - (struct walkarg *)0); + (void)rt_msg2(rtm->rtm_type, &info, (caddr_t)rtm, NULL); rtm->rtm_flags = rt->rt_flags; rt_getmetrics(&rt->rt_rmx, &rtm->rtm_rmx); rtm->rtm_addrs = info.rti_addrs; @@ -937,7 +935,7 @@ sysctl_dumpentry(struct radix_node *rn, void *vw) if (rt->rt_ifp->if_flags & IFF_POINTOPOINT) info.rti_info[RTAX_BRD] = rt->rt_ifa->ifa_dstaddr; } - size = rt_msg2(RTM_GET, &info, 0, w); + size = rt_msg2(RTM_GET, &info, NULL, w); if (w->w_req && w->w_tmem) { struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem; @@ -968,7 +966,7 @@ sysctl_iflist(int af, struct walkarg *w) continue; ifa = ifaddr_byindex(ifp->if_index); info.rti_info[RTAX_IFP] = ifa->ifa_addr; - len = rt_msg2(RTM_IFINFO, &info, (caddr_t)0, w); + len = rt_msg2(RTM_IFINFO, &info, NULL, w); info.rti_info[RTAX_IFP] = 0; if (w->w_req && w->w_tmem) { struct if_msghdr *ifm; @@ -991,7 +989,7 @@ sysctl_iflist(int af, struct walkarg *w) info.rti_info[RTAX_IFA] = ifa->ifa_addr; info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask; info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr; - len = rt_msg2(RTM_NEWADDR, &info, 0, w); + len = rt_msg2(RTM_NEWADDR, &info, NULL, w); if (w->w_req && w->w_tmem) { struct ifa_msghdr *ifam; @@ -1024,37 +1022,22 @@ sysctl_ifmalist(int af, struct walkarg *w) bzero((caddr_t)&info, sizeof(info)); /* IFNET_RLOCK(); */ /* could sleep XXX */ - /* - * XXX i think this code is buggy. It does not properly reset - * 'info' at each inner loop, resulting in possibly incorrect - * values in rti_addrs. Also, some ops are repeated for each ifma - * where they could be done just once per ifp. - */ TAILQ_FOREACH(ifp, &ifnet, if_link) { if (w->w_arg && w->w_arg != ifp->if_index) continue; ifa = ifaddr_byindex(ifp->if_index); + info.rti_info[RTAX_IFP] = ifa ? ifa->ifa_addr : NULL; TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { if (af && af != ifma->ifma_addr->sa_family) continue; if (jailed(curproc->p_ucred) && prison_if(curproc->p_ucred, ifma->ifma_addr)) continue; - info.rti_addrs = RTA_IFA; info.rti_info[RTAX_IFA] = ifma->ifma_addr; - if (ifa) { - info.rti_addrs |= RTA_IFP; - info.rti_info[RTAX_IFP] = ifa->ifa_addr; - } else - info.rti_info[RTAX_IFP] = NULL; - - if (ifma->ifma_addr->sa_family != AF_LINK) { - info.rti_addrs |= RTA_GATEWAY; - info.rti_info[RTAX_GATEWAY] = ifma->ifma_lladdr; - } else - info.rti_info[RTAX_GATEWAY] = NULL; - - len = rt_msg2(RTM_NEWMADDR, &info, 0, w); + info.rti_info[RTAX_GATEWAY] = + (ifma->ifma_addr->sa_family != AF_LINK) ? + ifma->ifma_lladdr : NULL; + len = rt_msg2(RTM_NEWMADDR, &info, NULL, w); if (w->w_req && w->w_tmem) { struct ifma_msghdr *ifmam; -- 2.45.0