| 697 | } |
| 698 | |
| 699 | __noinline static int |
| 700 | dump_nhgrp_entry(struct rib_head *rh, const struct nhgrp_priv *nhg_priv, |
| 701 | char *buffer, size_t buffer_size, struct sysctl_req *w) |
| 702 | { |
| 703 | struct rt_msghdr *rtm; |
| 704 | struct nhgrp_external *nhge; |
| 705 | struct nhgrp_container *nhgc; |
| 706 | const struct nhgrp_object *nhg; |
| 707 | struct nhgrp_nhop_external *ext; |
| 708 | int error; |
| 709 | size_t sz; |
| 710 | |
| 711 | nhg = nhg_priv->nhg; |
| 712 | |
| 713 | sz = sizeof(struct rt_msghdr) + sizeof(struct nhgrp_external); |
| 714 | /* controlplane nexthops */ |
| 715 | sz += sizeof(struct nhgrp_container); |
| 716 | sz += sizeof(struct nhgrp_nhop_external) * nhg_priv->nhg_nh_count; |
| 717 | /* dataplane nexthops */ |
| 718 | sz += sizeof(struct nhgrp_container); |
| 719 | sz += sizeof(struct nhgrp_nhop_external) * nhg->nhg_size; |
| 720 | |
| 721 | KASSERT(sz <= buffer_size, ("increase nhgrp buffer size")); |
| 722 | |
| 723 | bzero(buffer, sz); |
| 724 | |
| 725 | rtm = (struct rt_msghdr *)buffer; |
| 726 | rtm->rtm_msglen = sz; |
| 727 | rtm->rtm_version = RTM_VERSION; |
| 728 | rtm->rtm_type = RTM_GET; |
| 729 | |
| 730 | nhge = (struct nhgrp_external *)(rtm + 1); |
| 731 | |
| 732 | nhge->nhg_idx = nhg_priv->nhg_idx; |
| 733 | nhge->nhg_refcount = nhg_priv->nhg_refcount; |
| 734 | |
| 735 | /* fill in control plane nexthops firs */ |
| 736 | nhgc = (struct nhgrp_container *)(nhge + 1); |
| 737 | nhgc->nhgc_type = NHG_C_TYPE_CNHOPS; |
| 738 | nhgc->nhgc_subtype = 0; |
| 739 | nhgc->nhgc_len = sizeof(struct nhgrp_container); |
| 740 | nhgc->nhgc_len += sizeof(struct nhgrp_nhop_external) * nhg_priv->nhg_nh_count; |
| 741 | nhgc->nhgc_count = nhg_priv->nhg_nh_count; |
| 742 | |
| 743 | ext = (struct nhgrp_nhop_external *)(nhgc + 1); |
| 744 | for (int i = 0; i < nhg_priv->nhg_nh_count; i++) { |
| 745 | ext[i].nh_idx = nhg_priv->nhg_nh_weights[i].nh->nh_priv->nh_idx; |
| 746 | ext[i].nh_weight = nhg_priv->nhg_nh_weights[i].weight; |
| 747 | } |
| 748 | |
| 749 | /* fill in dataplane nexthops */ |
| 750 | nhgc = (struct nhgrp_container *)(&ext[nhg_priv->nhg_nh_count]); |
| 751 | nhgc->nhgc_type = NHG_C_TYPE_DNHOPS; |
| 752 | nhgc->nhgc_subtype = 0; |
| 753 | nhgc->nhgc_len = sizeof(struct nhgrp_container); |
| 754 | nhgc->nhgc_len += sizeof(struct nhgrp_nhop_external) * nhg->nhg_size; |
| 755 | nhgc->nhgc_count = nhg->nhg_size; |
| 756 |
no test coverage detected