diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2014-01-23 10:16:31 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2014-01-23 10:16:31 +0000 |
commit | b8efa3a2a76b8f8fcabffc935f6922eb52406198 (patch) | |
tree | ce17447770f322fe5f4cfe915ef9b1c0184ef8a3 /sys | |
parent | dd779435885537c478a27056ddb718a7eb901c6b (diff) |
Merge two chunks of code to inform listeners of a route change into a
new function, rt_sendmsg(). While here, in the v6 cases, pass the same
rtableid that was used for the request instead of dereferencing a pointer
after checking for it to be NULL.
ok krw@ on a previous version, ok bluhm@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/route.c | 32 | ||||
-rw-r--r-- | sys/net/route.h | 3 | ||||
-rw-r--r-- | sys/netinet6/nd6_rtr.c | 32 |
3 files changed, 27 insertions, 40 deletions
diff --git a/sys/net/route.c b/sys/net/route.c index 2cf4a792764..cf26b84698d 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.150 2014/01/22 06:28:09 claudio Exp $ */ +/* $OpenBSD: route.c,v 1.151 2014/01/23 10:16:30 mpi Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -345,17 +345,7 @@ rtalloc1(struct sockaddr *dst, int flags, u_int tableid) 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 { @@ -412,6 +402,24 @@ rtfree(struct rtentry *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 ifafree(struct ifaddr *ifa) { if (ifa == NULL) diff --git a/sys/net/route.h b/sys/net/route.h index 38ad42b0eb6..e07bd2030e3 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -1,4 +1,4 @@ -/* $OpenBSD: route.h,v 1.86 2014/01/22 06:28:09 claudio Exp $ */ +/* $OpenBSD: route.h,v 1.87 2014/01/23 10:16:30 mpi Exp $ */ /* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */ /* @@ -371,6 +371,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 *); diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 280def0d385..9d93d514460 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_rtr.c,v 1.77 2014/01/13 23:03:52 bluhm Exp $ */ +/* $OpenBSD: nd6_rtr.c,v 1.78 2014/01/23 10:16:30 mpi Exp $ */ /* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */ /* @@ -70,7 +70,6 @@ void pfxrtr_add(struct nd_prefix *, struct nd_defrouter *); 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, int icmp6len) /* * 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 *new) 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, |