+/*
+ * Decrements the refcount but does not free the route when
+ * the refcount reaches zero. Unless you have really good reason,
+ * use rtfree not rtunref.
+ */
+void
+rtunref(struct rtentry* rt)
+{
+ if (rt == NULL)
+ panic("rtunref");
+ rt->rt_refcnt--;
+#if DEBUG
+ if (rt->rt_refcnt <= 0 && (rt->rt_flags & RTF_UP) == 0)
+ printf("rtunref - if rtfree were called, we would have freed route\n");
+#endif
+}
+
+/*
+ * Add a reference count from an rtentry.
+ */
+void
+rtref(struct rtentry* rt)
+{
+ if (rt == NULL)
+ panic("rtref");
+
+ rt->rt_refcnt++;
+}
+
+void
+rtsetifa(struct rtentry *rt, struct ifaddr* ifa)
+{
+ if (rt == NULL)
+ panic("rtsetifa");
+
+ if (rt->rt_ifa == ifa)
+ return;
+
+ /* Release the old ifa if it isn't our parent route's ifa */
+ if (rt->rt_ifa && !(rt->rt_parent && rt->rt_parent->rt_ifa == rt->rt_ifa))
+ ifafree(rt->rt_ifa);
+
+ /* Set rt_ifa */
+ rt->rt_ifa = ifa;
+
+ /* Take a reference to the ifa if it isn't our parent route's ifa */
+ if (rt->rt_ifa && !(rt->rt_parent && rt->rt_parent->rt_ifa == ifa))
+ ifaref(rt->rt_ifa);
+}
+