-#if PKT_PRIORITY
- if (soisbackground(in6p->in6p_socket))
- m_prio_background(m);
-#endif /* PKT_PRIORITY */
- error = ip6_output(m, in6p->in6p_outputopts, &in6p->in6p_route,
- flags, in6p->in6p_moptions, NULL, 0);
-
-#if IFNET_ROUTE_REFCNT
- /*
- * Always discard the cached route for unconnected socket
- * or if it is a multicast route.
- */
- if (in6p->in6p_route.ro_rt != NULL &&
- ((in6p->in6p_route.ro_rt->rt_flags & RTF_MULTICAST) ||
- in6p->in6p_socket == NULL ||
- in6p->in6p_socket->so_state != SS_ISCONNECTED)) {
- rtfree(in6p->in6p_route.ro_rt);
- in6p->in6p_route.ro_rt = NULL;
+
+ set_packet_tclass(m, in6p->in6p_socket, mtc, 1);
+
+ im6o = in6p->in6p_moptions;
+ if (im6o != NULL)
+ IM6O_ADDREF(im6o);
+
+ error = ip6_output(m, optp, &in6p->in6p_route,
+ flags, im6o, NULL, &ip6oa);
+
+ if (im6o != NULL)
+ IM6O_REMREF(im6o);
+
+ if (error == 0 && nstat_collect) {
+ locked_add_64(&in6p->inp_stat->txpackets, 1);
+ locked_add_64(&in6p->inp_stat->txbytes, ulen);
+ }
+
+ if (in6p->in6p_route.ro_rt != NULL) {
+ struct rtentry *rt = in6p->in6p_route.ro_rt;
+ unsigned int outif;
+
+ if ((rt->rt_flags & RTF_MULTICAST) ||
+ in6p->in6p_socket == NULL ||
+ !(in6p->in6p_socket->so_state & SS_ISCONNECTED)) {
+ rt = NULL; /* unusable */
+ }
+ /*
+ * Always discard the cached route for unconnected
+ * socket or if it is a multicast route.
+ */
+ if (rt == NULL) {
+ rtfree(in6p->in6p_route.ro_rt);
+ in6p->in6p_route.ro_rt = NULL;
+ }
+ /*
+ * If this is a connected socket and the destination
+ * route is not multicast, update outif with that of
+ * the route interface index used by IP.
+ */
+ if (rt != NULL && (outif = rt->rt_ifp->if_index) !=
+ in6p->in6p_last_outif)
+ in6p->in6p_last_outif = outif;