| 646 | } |
| 647 | |
| 648 | void |
| 649 | nhop_free(struct nhop_object *nh) |
| 650 | { |
| 651 | struct nh_control *ctl; |
| 652 | struct nhop_priv *nh_priv = nh->nh_priv; |
| 653 | struct epoch_tracker et; |
| 654 | |
| 655 | if (!refcount_release(&nh_priv->nh_refcnt)) |
| 656 | return; |
| 657 | |
| 658 | /* |
| 659 | * There are only 2 places, where nh_linked can be decreased: |
| 660 | * rib destroy (nhops_destroy_rib) and this function. |
| 661 | * nh_link can never be increased. |
| 662 | * |
| 663 | * Hence, use initial value of 2 to make use of |
| 664 | * refcount_release_if_not_last(). |
| 665 | * |
| 666 | * There can be two scenarious when calling this function: |
| 667 | * |
| 668 | * 1) nh_linked value is 2. This means that either |
| 669 | * nhops_destroy_rib() has not been called OR it is running, |
| 670 | * but we are guaranteed that nh_control won't be freed in |
| 671 | * this epoch. Hence, nexthop can be safely unlinked. |
| 672 | * |
| 673 | * 2) nh_linked value is 1. In that case, nhops_destroy_rib() |
| 674 | * has been called and nhop unlink can be skipped. |
| 675 | */ |
| 676 | |
| 677 | NET_EPOCH_ENTER(et); |
| 678 | if (refcount_release_if_not_last(&nh_priv->nh_linked)) { |
| 679 | ctl = nh_priv->nh_control; |
| 680 | if (unlink_nhop(ctl, nh_priv) == NULL) { |
| 681 | /* Do not try to reclaim */ |
| 682 | DPRINTF("Failed to unlink nexhop %p", nh_priv); |
| 683 | NET_EPOCH_EXIT(et); |
| 684 | return; |
| 685 | } |
| 686 | } |
| 687 | NET_EPOCH_EXIT(et); |
| 688 | |
| 689 | epoch_call(net_epoch_preempt, destroy_nhop_epoch, |
| 690 | &nh_priv->nh_epoch_ctx); |
| 691 | } |
| 692 | |
| 693 | void |
| 694 | nhop_ref_any(struct nhop_object *nh) |
no test coverage detected