Lines Matching defs:rt
315 * Returns 1 if the (cached) ``rt'' entry is still valid, 0 otherwise.
318 rtisvalid(struct rtentry *rt)
320 if (rt == NULL)
323 if (!ISSET(rt->rt_flags, RTF_UP))
326 if (ISSET(rt->rt_flags, RTF_GATEWAY)) {
327 KASSERT(rt->rt_gwroute != NULL);
328 KASSERT(!ISSET(rt->rt_gwroute->rt_flags, RTF_GATEWAY));
329 if (!ISSET(rt->rt_gwroute->rt_flags, RTF_UP))
349 struct rtentry *rt = NULL;
351 rt = rtable_match(tableid, dst, src);
352 if (rt == NULL) {
357 if (ISSET(rt->rt_flags, RTF_CLONING) && ISSET(flags, RT_RESOLVE))
358 rt_clone(&rt, dst, tableid);
360 rt->rt_use++;
361 return (rt);
369 struct rtentry *rt = *rtp;
383 error = rtrequest(RTM_RESOLVE, &info, rt->rt_priority - 1, &rt,
390 rtm_send(rt, RTM_ADD, 0, rtableid);
392 *rtp = rt;
413 rt_hash(struct rtentry *rt, const struct sockaddr *dst, uint32_t *src)
417 if (src == NULL || !rtisvalid(rt) || !ISSET(rt->rt_flags, RTF_MPATH))
494 * the gateway entry ``rt''.
497 rt_setgwroute(struct rtentry *rt, const struct sockaddr *gate, u_int rtableid)
511 if (nhrt->rt_ifidx != rt->rt_ifidx) {
530 while (prt != NULL && prt->rt_ifidx != rt->rt_ifidx)
549 * loops for example when rt->rt_gwroute points to rt.
560 if (!ISSET(rt->rt_locks, RTV_MTU)) {
563 mtu = atomic_load_int(&rt->rt_mtu);
566 atomic_cas_uint(&rt->rt_mtu, mtu, nhmtu);
579 rt_putgwroute(rt, nhrt);
585 * Invalidate the cached route entry of the gateway entry ``rt''.
588 rt_putgwroute(struct rtentry *rt, struct rtentry *nhrt)
594 if (!ISSET(rt->rt_flags, RTF_GATEWAY))
598 onhrt = rt->rt_gwroute;
599 rt->rt_gwroute = nhrt;
614 rtref(struct rtentry *rt)
616 refcnt_take(&rt->rt_refcnt);
620 rtfree(struct rtentry *rt)
622 if (rt == NULL)
625 if (refcnt_rele(&rt->rt_refcnt) == 0)
628 KASSERT(!ISSET(rt->rt_flags, RTF_UP));
629 KASSERT(!RT_ROOT(rt));
632 rt_timer_remove_all(rt);
633 ifafree(rt->rt_ifa);
634 rtlabel_unref(rt->rt_labelid);
636 rt_mpls_clear(rt);
638 if (rt->rt_gateway != NULL) {
639 free(rt->rt_gateway, M_RTABLE,
640 ROUNDUP(rt->rt_gateway->sa_len));
642 free(rt_key(rt), M_RTABLE, rt_key(rt)->sa_len);
644 pool_put(&rtentry_pool, rt);
672 struct rtentry *rt;
684 rt = rtalloc(gateway, 0, rdomain);
685 if (!rtisvalid(rt) || ISSET(rt->rt_flags, RTF_GATEWAY)) {
686 rtfree(rt);
690 ifidx = rt->rt_ifidx;
691 ifa = rt->rt_ifa;
692 rtfree(rt);
693 rt = NULL;
695 rt = rtable_lookup(rdomain, dst, NULL, NULL, RTP_ANY);
705 if (rt != NULL && (!equal(src, rt->rt_gateway) || rt->rt_ifa != ifa))
719 if (rt == NULL)
725 if (ISSET(rt->rt_flags, RTF_GATEWAY)) {
726 if (!ISSET(rt->rt_flags, RTF_HOST)) {
732 rtfree(rt);
739 rt = NULL;
740 error = rtrequest(RTM_ADD, &info, RTP_DEFAULT, &rt,
743 flags = rt->rt_flags;
744 prio = rt->rt_priority;
752 rt->rt_flags |= RTF_MODIFIED;
754 prio = rt->rt_priority;
756 rt_setgate(rt, gateway, rdomain);
761 if (rt) {
763 *rtp = rt;
765 rtfree(rt);
783 rtdeletemsg(struct rtentry *rt, struct ifnet *ifp, u_int tableid)
790 KASSERT(rt->rt_ifidx == ifp->if_index);
798 info.rti_info[RTAX_DST] = rt_key(rt);
799 info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
800 if (!ISSET(rt->rt_flags, RTF_HOST))
801 info.rti_info[RTAX_NETMASK] = rt_plen2mask(rt, &sa_mask);
802 info.rti_info[RTAX_LABEL] = rtlabel_id2sa(rt->rt_labelid, &sa_rl);
803 info.rti_flags = rt->rt_flags;
805 info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
806 error = rtrequest_delete(&info, rt->rt_priority, ifp, &rt, tableid);
807 rtm_miss(RTM_DELETE, &info, info.rti_flags, rt->rt_priority,
808 rt->rt_ifidx, error, tableid);
810 rtfree(rt);
828 rtflushclone1(struct rtentry *rt, void *arg, u_int id)
833 if (!ISSET(rt->rt_flags, RTF_CLONED))
837 if (ISSET(rt->rt_flags, RTF_CACHED) && (rt->rt_parent != cloningrt))
840 if (!rtequal(rt->rt_parent, cloningrt))
847 ifp = if_get(rt->rt_ifidx);
858 struct rtentry *rt = NULL;
868 error = rtable_walk(rtableid, rt_key(parent)->sa_family, &rt,
870 if (rt != NULL && error == EEXIST) {
871 ifp = if_get(rt->rt_ifidx);
875 error = rtdeletemsg(rt, ifp, rtableid);
881 rtfree(rt);
882 rt = NULL;
893 struct rtentry *rt;
900 rt = rtable_lookup(tableid, info->rti_info[RTAX_DST],
902 if (rt == NULL)
906 if (ifp != NULL && ifp->if_index != rt->rt_ifidx) {
907 rtfree(rt);
912 if (ISSET(rt->rt_flags, RTF_BFD))
913 bfdclear(rt);
917 info->rti_info[RTAX_NETMASK], rt);
919 rtfree(rt);
924 rt_putgwroute(rt, NULL);
927 if (ISSET(rt->rt_flags, RTF_CLONING))
928 rtflushclone(rt, tableid);
930 rtfree(rt->rt_parent);
931 rt->rt_parent = NULL;
933 rt->rt_flags &= ~RTF_UP;
935 KASSERT(ifp->if_index == rt->rt_ifidx);
936 ifp->if_rtrequest(ifp, RTM_DELETE, rt);
941 *ret_nrt = rt;
943 rtfree(rt);
956 struct rtentry *rt, *crt;
974 if (ret_nrt == NULL || (rt = *ret_nrt) == NULL)
976 if ((rt->rt_flags & RTF_CLONING) == 0)
978 KASSERT(rt->rt_ifa->ifa_ifp != NULL);
979 info->rti_ifa = rt->rt_ifa;
980 info->rti_flags = rt->rt_flags | (RTF_CLONED|RTF_HOST);
984 rtlabel_id2sa(rt->rt_labelid, &sa_rl2);
1000 rt = pool_get(&rtentry_pool, PR_NOWAIT | PR_ZERO);
1001 if (rt == NULL) {
1006 refcnt_init_trace(&rt->rt_refcnt, DT_REFCNT_IDX_RTENTRY);
1007 rt->rt_flags = info->rti_flags | RTF_UP;
1008 rt->rt_priority = prio; /* init routing priority */
1009 LIST_INIT(&rt->rt_timer);
1013 !ISSET(rt->rt_flags, RTF_LOCAL) &&
1016 rt->rt_flags &= ~RTF_UP;
1017 rt->rt_priority |= RTP_DOWN;
1023 rt->rt_labelid = rtlabel_name2id(sa_rl->sr_label);
1031 error = rt_mpls_set(rt, info->rti_info[RTAX_SRC],
1035 pool_put(&rtentry_pool, rt);
1039 rt_mpls_clear(rt);
1042 rt->rt_ifa = ifaref(ifa);
1043 rt->rt_ifidx = ifp->if_index;
1048 if (ISSET(rt->rt_flags, RTF_CLONED)) {
1050 rt->rt_parent = *ret_nrt;
1051 rt->rt_rmx = (*ret_nrt)->rt_rmx;
1055 * We must set rt->rt_gateway before adding ``rt'' to
1059 if ((error = rt_setgate(rt, info->rti_info[RTAX_GATEWAY],
1062 rtfree(rt->rt_parent);
1063 rt_putgwroute(rt, NULL);
1064 if (rt->rt_gateway != NULL) {
1065 free(rt->rt_gateway, M_RTABLE,
1066 ROUNDUP(rt->rt_gateway->sa_len));
1069 pool_put(&rtentry_pool, rt);
1075 rt->rt_priority, rt);
1091 rt->rt_priority, rt);
1097 rtfree(rt->rt_parent);
1098 rt_putgwroute(rt, NULL);
1099 if (rt->rt_gateway != NULL) {
1100 free(rt->rt_gateway, M_RTABLE,
1101 ROUNDUP(rt->rt_gateway->sa_len));
1104 pool_put(&rtentry_pool, rt);
1107 ifp->if_rtrequest(ifp, req, rt);
1113 *ret_nrt = rt;
1115 rtfree(rt);
1127 rt_setgate(struct rtentry *rt, const struct sockaddr *gate, u_int rtableid)
1134 if (rt->rt_gateway == gate) {
1145 osa = rt->rt_gateway;
1146 rt->rt_gateway = sa;
1148 if (ISSET(rt->rt_flags, RTF_GATEWAY))
1149 error = rt_setgwroute(rt, gate, rtableid);
1160 * address corresponding to ``rt''.
1163 rt_getll(struct rtentry *rt)
1165 if (ISSET(rt->rt_flags, RTF_GATEWAY)) {
1166 KASSERT(rt->rt_gwroute != NULL);
1167 return (rt->rt_gwroute);
1170 return (rt);
1247 struct rtentry *rt;
1279 error = rtrequest(RTM_ADD, &info, prio, &rt, rdomain);
1288 rtm_send(rt, RTM_ADD, 0, rdomain);
1289 rtfree(rt);
1299 struct rtentry *rt;
1336 error = rtrequest_delete(&info, prio, ifp, &rt, rdomain);
1338 rtm_send(rt, RTM_DELETE, 0, rdomain);
1341 rtfree(rt);
1355 struct rtentry *rt;
1385 rt = rtalloc(ifa->ifa_addr, 0, ifp->if_rdomain);
1386 if (rt == NULL || ISSET(rt->rt_flags, flags) != flags) {
1390 rtfree(rt);
1402 struct rtentry *rt;
1437 rt = rtalloc(ifa->ifa_addr, 0, ifp->if_rdomain);
1438 if (rt != NULL && ISSET(rt->rt_flags, flags) == flags) {
1442 rtfree(rt);
1454 struct rtentry *rt = NULL;
1466 error = rtable_walk(rtableid, af, &rt,
1468 if (rt != NULL && error == EEXIST) {
1469 error = rtdeletemsg(rt, ifp, rtableid);
1473 rtfree(rt);
1474 rt = NULL;
1486 rt_ifa_purge_walker(struct rtentry *rt, void *vifa, unsigned int rtableid)
1490 if (rt->rt_ifa == ifa)
1513 time_t rtt_expire; /* [I] rt expire time */
1610 rt_timer_remove_all(struct rtentry *rt)
1617 while ((r = LIST_FIRST(&rt->rt_timer)) != NULL) {
1631 rt_timer_get_expire(const struct rtentry *rt)
1637 LIST_FOREACH(r, &rt->rt_timer, rtt_link) {
1647 rt_timer_add(struct rtentry *rt, struct rttimer_queue *queue, u_int rtableid)
1655 rnew->rtt_rt = rt;
1666 LIST_FOREACH(r, &rt->rt_timer, rtt_link) {
1673 LIST_INSERT_HEAD(&rt->rt_timer, rnew, rtt_link);
1711 rt_mpls_set(struct rtentry *rt, const struct sockaddr *src, uint8_t op)
1723 rt->rt_llinfo = malloc(sizeof(struct rt_mpls), M_TEMP, M_NOWAIT|M_ZERO);
1724 if (rt->rt_llinfo == NULL)
1727 rt_mpls = (struct rt_mpls *)rt->rt_llinfo;
1732 rt->rt_flags |= RTF_MPLS;
1738 rt_mpls_clear(struct rtentry *rt)
1740 if (rt->rt_llinfo != NULL && rt->rt_flags & RTF_MPLS) {
1741 free(rt->rt_llinfo, M_TEMP, sizeof(struct rt_mpls));
1742 rt->rt_llinfo = NULL;
1744 rt->rt_flags &= ~RTF_MPLS;
1878 struct rtentry *rt = NULL;
1890 error = rtable_walk(rtableid, i, &rt,
1892 if (rt != NULL && error == EEXIST) {
1893 error = rtdeletemsg(rt, ifp, rtableid);
1897 rtfree(rt);
1898 rt = NULL;
1913 rt_if_linkstate_change(struct rtentry *rt, void *arg, u_int id)
1919 if (rt->rt_ifidx != ifp->if_index)
1923 if (rt->rt_flags & RTF_LOCAL) {
1924 rt->rt_flags |= RTF_UP;
1929 if (ISSET(rt->rt_flags, RTF_UP))
1933 rt->rt_flags |= RTF_UP;
1934 error = rtable_mpath_reprio(id, rt_key(rt), rt_plen(rt),
1935 rt->rt_priority & RTP_MASK, rt);
1942 if (ISSET(rt->rt_flags, RTF_CLONED|RTF_DYNAMIC) &&
1943 !ISSET(rt->rt_flags, RTF_CACHED|RTF_BFD)) {
1947 if (!ISSET(rt->rt_flags, RTF_UP))
1951 rt->rt_flags &= ~RTF_UP;
1952 error = rtable_mpath_reprio(id, rt_key(rt), rt_plen(rt),
1953 rt->rt_priority | RTP_DOWN, rt);
1955 if_group_routechange(rt_key(rt), rt_plen2mask(rt, &sa_mask));
1999 rt_plen2mask(struct rtentry *rt, struct sockaddr_in6 *sa_mask)
2001 return (rt_plentosa(rt_key(rt)->sa_family, rt_plen(rt), sa_mask));
2055 db_show_rtentry(struct rtentry *rt, void *w, unsigned int id)
2057 db_printf("rtentry=%p", rt);
2060 rt->rt_flags, rt->rt_refcnt.r_refs, rt->rt_use, rt->rt_expire);
2062 db_printf(" key="); db_print_sa(rt_key(rt));
2063 db_printf(" plen=%d", rt_plen(rt));
2064 db_printf(" gw="); db_print_sa(rt->rt_gateway);
2065 db_printf(" ifidx=%u ", rt->rt_ifidx);
2066 db_printf(" ifa=%p\n", rt->rt_ifa);
2067 db_print_ifa(rt->rt_ifa);
2070 rt->rt_gwroute, rt->rt_llinfo, rt->rt_priority);