* Conditionally unlinks rtentry matching data inside @info from @rnh. * Returns 0 on success with operation result stored in @rc. * On error, returns: * ESRCH - if prefix was not found, * EADDRINUSE - if trying to delete higher priority route. * ENOENT - if supplied filter function returned 0 (not matched). */
| 768 | * ENOENT - if supplied filter function returned 0 (not matched). |
| 769 | */ |
| 770 | static int |
| 771 | rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo *info, struct rib_cmd_info *rc) |
| 772 | { |
| 773 | struct rtentry *rt; |
| 774 | struct nhop_object *nh; |
| 775 | struct radix_node *rn; |
| 776 | struct route_nhop_data rnd; |
| 777 | int error; |
| 778 | |
| 779 | rt = lookup_prefix(rnh, info, &rnd); |
| 780 | if (rt == NULL) |
| 781 | return (ESRCH); |
| 782 | |
| 783 | nh = rt->rt_nhop; |
| 784 | #ifdef ROUTE_MPATH |
| 785 | if (NH_IS_NHGRP(nh)) { |
| 786 | error = del_route_mpath(rnh, info, rt, |
| 787 | (struct nhgrp_object *)nh, rc); |
| 788 | return (error); |
| 789 | } |
| 790 | #endif |
| 791 | error = check_info_match_nhop(info, rt, nh); |
| 792 | if (error != 0) |
| 793 | return (error); |
| 794 | |
| 795 | if (can_override_nhop(info, nh) < 0) |
| 796 | return (EADDRINUSE); |
| 797 | |
| 798 | /* |
| 799 | * Remove the item from the tree and return it. |
| 800 | * Complain if it is not there and do no more processing. |
| 801 | */ |
| 802 | rn = rnh->rnh_deladdr(info->rti_info[RTAX_DST], |
| 803 | info->rti_info[RTAX_NETMASK], &rnh->head); |
| 804 | if (rn == NULL) |
| 805 | return (ESRCH); |
| 806 | |
| 807 | if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT)) |
| 808 | panic ("rtrequest delete"); |
| 809 | |
| 810 | rt = RNTORT(rn); |
| 811 | rt->rte_flags &= ~RTF_UP; |
| 812 | |
| 813 | /* Finalize notification */ |
| 814 | rnh->rnh_gen++; |
| 815 | rnh->rnh_prefixes--; |
| 816 | |
| 817 | rc->rc_cmd = RTM_DELETE; |
| 818 | rc->rc_rt = rt; |
| 819 | rc->rc_nh_old = rt->rt_nhop; |
| 820 | rc->rc_nh_weight = rt->rt_weight; |
| 821 | rib_notify(rnh, RIB_NOTIFY_IMMEDIATE, rc); |
| 822 | |
| 823 | return (0); |
| 824 | } |
| 825 | |
| 826 | static int |
| 827 | del_route(struct rib_head *rnh, struct rt_addrinfo *info, |
no test coverage detected