On 02/09/13(Mon) 07:54, Kenneth R Westerback wrote:
> On Mon, Sep 02, 2013 at 12:43:51PM +0200, Martin Pieuchot wrote:
> > Diff below is just a small refactoring of two similar code chunks to
> > inform user processes that something changed regarding a route.
> > 
> > I'd like to get this in because it removes one use of rt_addrinfo in
> > netinet6.
> > 
> > There's no functional change, ok?
> > 
> 
> This seems sane. ok krw@ fwiw.
> 
> I would suggest copying the 'Inform listeners of the new route'
> comment to replace the 'tell the change to user processes watching
> the routing socket' comment. The latter reads very oddly to my
> native english speaking brain.

Here's an updated diff that takes into consideration all the previous
comments (changed the named and removed the comment), plus it fixes
the newly added `rtableid' argument in the IPv6 case to not
dereference `rt_ifp' if it is null.

Still ok?

Index: net/route.c
===================================================================
RCS file: /home/ncvs/src/sys/net/route.c,v
retrieving revision 1.149
diff -u -p -r1.149 route.c
--- net/route.c 10 Jan 2014 14:29:08 -0000      1.149
+++ net/route.c 14 Jan 2014 14:30:29 -0000
@@ -345,17 +345,7 @@ rtalloc1(struct sockaddr *dst, int flags
                                goto miss;
                        }
                        /* Inform listeners of the new route */
-                       bzero(&info, sizeof(info));
-                       info.rti_info[RTAX_DST] = rt_key(rt);
-                       info.rti_info[RTAX_NETMASK] = rt_mask(rt);
-                       info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
-                       if (rt->rt_ifp != NULL) {
-                               info.rti_info[RTAX_IFP] =
-                                   
TAILQ_FIRST(&rt->rt_ifp->if_addrlist)->ifa_addr;
-                               info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
-                       }
-                       rt_missmsg(RTM_ADD, &info, rt->rt_flags,
-                           rt->rt_ifp, 0, tableid);
+                       rt_sendmsg(rt, RTM_ADD, tableid);
                } else
                        rt->rt_refcnt++;
        } else {
@@ -409,6 +399,24 @@ rtfree(struct rtentry *rt)
                free(rt_key(rt), M_RTABLE);
                pool_put(&rtentry_pool, rt);
        }
+}
+
+void
+rt_sendmsg(struct rtentry *rt, int cmd, u_int rtableid)
+{
+       struct rt_addrinfo info;
+
+       bzero(&info, sizeof(info));
+       info.rti_info[RTAX_DST] = rt_key(rt);
+       info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
+       info.rti_info[RTAX_NETMASK] = rt_mask(rt);
+       if (rt->rt_ifp != NULL) {
+               info.rti_info[RTAX_IFP] =
+                   TAILQ_FIRST(&rt->rt_ifp->if_addrlist)->ifa_addr;
+               info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
+       }
+
+       rt_missmsg(cmd, &info, rt->rt_flags, rt->rt_ifp, 0, rtableid);
 }
 
 void
Index: net/route.h
===================================================================
RCS file: /home/ncvs/src/sys/net/route.h,v
retrieving revision 1.83
diff -u -p -r1.83 route.h
--- net/route.h 31 Oct 2013 18:10:21 -0000      1.83
+++ net/route.h 14 Jan 2014 14:30:29 -0000
@@ -413,6 +413,7 @@ void         rt_ifmsg(struct ifnet *);
 void    rt_ifannouncemsg(struct ifnet *, int);
 void    rt_maskedcopy(struct sockaddr *,
            struct sockaddr *, struct sockaddr *);
+void    rt_sendmsg(struct rtentry *, int, u_int);
 void    rt_missmsg(int, struct rt_addrinfo *, int, struct ifnet *, int,
            u_int);
 void    rt_newaddrmsg(int, struct ifaddr *, int, struct rtentry *);
Index: netinet6/nd6_rtr.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet6/nd6_rtr.c,v
retrieving revision 1.77
diff -u -p -r1.77 nd6_rtr.c
--- netinet6/nd6_rtr.c  13 Jan 2014 23:03:52 -0000      1.77
+++ netinet6/nd6_rtr.c  14 Jan 2014 14:30:29 -0000
@@ -70,7 +70,6 @@ void pfxrtr_add(struct nd_prefix *, stru
 void pfxrtr_del(struct nd_pfxrouter *);
 struct nd_pfxrouter *find_pfxlist_reachable_router(struct nd_prefix *);
 void defrouter_delreq(struct nd_defrouter *);
-void nd6_rtmsg(int, struct rtentry *);
 void purge_detached(struct ifnet *);
 
 void in6_init_address_ltimes(struct nd_prefix *, struct in6_addrlifetime *);
@@ -425,27 +424,6 @@ nd6_ra_input(struct mbuf *m, int off, in
 /*
  * default router list processing sub routines
  */
-
-/* tell the change to user processes watching the routing socket. */
-void
-nd6_rtmsg(int cmd, struct rtentry *rt)
-{
-       struct rt_addrinfo info;
-
-       bzero((caddr_t)&info, sizeof(info));
-       info.rti_info[RTAX_DST] = rt_key(rt);
-       info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
-       info.rti_info[RTAX_NETMASK] = rt_mask(rt);
-       if (rt->rt_ifp) {
-               info.rti_info[RTAX_IFP] =
-                   TAILQ_FIRST(&rt->rt_ifp->if_addrlist)->ifa_addr;
-               info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
-       }
-
-       rt_missmsg(cmd, &info, rt->rt_flags, rt->rt_ifp, 0,
-           rt->rt_ifp->if_rdomain);
-}
-
 void
 defrouter_addreq(struct nd_defrouter *new)
 {
@@ -475,7 +453,7 @@ defrouter_addreq(struct nd_defrouter *ne
        error = rtrequest1(RTM_ADD, &info, RTP_DEFAULT, &newrt,
            new->ifp->if_rdomain);
        if (newrt) {
-               nd6_rtmsg(RTM_ADD, newrt); /* tell user process */
+               rt_sendmsg(newrt, RTM_ADD, new->ifp->if_rdomain);
                newrt->rt_refcnt--;
        }
        if (error == 0)
@@ -579,7 +557,7 @@ defrouter_delreq(struct nd_defrouter *dr
        rtrequest1(RTM_DELETE, &info, RTP_DEFAULT, &oldrt,
            dr->ifp->if_rdomain);
        if (oldrt) {
-               nd6_rtmsg(RTM_DELETE, oldrt);
+               rt_sendmsg(oldrt, RTM_DELETE, dr->ifp->if_rdomain);
                if (oldrt->rt_refcnt <= 0) {
                        /*
                         * XXX: borrowed from the RTM_DELETE case of
@@ -1672,7 +1650,7 @@ nd6_prefix_onlink(struct nd_prefix *pr)
        error = rtrequest1(RTM_ADD, &info, RTP_CONNECTED, &rt, ifp->if_rdomain);
        if (error == 0) {
                if (rt != NULL) /* this should be non NULL, though */
-                       nd6_rtmsg(RTM_ADD, rt);
+                       rt_sendmsg(rt, RTM_ADD, ifp->if_rdomain);
                pr->ndpr_stateflags |= NDPRF_ONLINK;
        } else {
                char gw[INET6_ADDRSTRLEN], mask[INET6_ADDRSTRLEN];
@@ -1734,7 +1712,7 @@ nd6_prefix_offlink(struct nd_prefix *pr)
 
                /* report the route deletion to the routing socket. */
                if (rt != NULL)
-                       nd6_rtmsg(RTM_DELETE, rt);
+                       rt_sendmsg(rt, RTM_DELETE, ifp->if_rdomain);
 
                /*
                 * There might be the same prefix on another interface,

Reply via email to