| 932 | } |
| 933 | |
| 934 | static int |
| 935 | update_rtm_from_rc(struct rt_addrinfo *info, struct rt_msghdr **prtm, |
| 936 | int alloc_len, struct rib_cmd_info *rc, struct nhop_object *nh, unsigned maxlen) |
| 937 | { |
| 938 | struct walkarg w; |
| 939 | union sockaddr_union saun; |
| 940 | struct rt_msghdr *rtm, *orig_rtm = NULL; |
| 941 | struct ifnet *ifp; |
| 942 | int error, len; |
| 943 | |
| 944 | rtm = *prtm; |
| 945 | union sockaddr_union sa_dst, sa_mask; |
| 946 | int family = info->rti_info[RTAX_DST]->sa_family; |
| 947 | init_sockaddrs_family(family, &sa_dst, &sa_mask); |
| 948 | export_rtaddrs(rc->rc_rt, &sa_dst.sa, &sa_mask.sa); |
| 949 | |
| 950 | info->rti_info[RTAX_DST] = &sa_dst.sa; |
| 951 | info->rti_info[RTAX_NETMASK] = rt_is_host(rc->rc_rt) ? NULL : &sa_mask.sa; |
| 952 | info->rti_info[RTAX_GATEWAY] = &nh->gw_sa; |
| 953 | info->rti_info[RTAX_GENMASK] = 0; |
| 954 | ifp = nh->nh_ifp; |
| 955 | if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) { |
| 956 | if (ifp) { |
| 957 | info->rti_info[RTAX_IFP] = |
| 958 | ifp->if_addr->ifa_addr; |
| 959 | error = rtm_get_jailed(info, ifp, nh, |
| 960 | &saun, curthread->td_ucred); |
| 961 | if (error != 0) |
| 962 | return (error); |
| 963 | if (ifp->if_flags & IFF_POINTOPOINT) |
| 964 | info->rti_info[RTAX_BRD] = |
| 965 | nh->nh_ifa->ifa_dstaddr; |
| 966 | rtm->rtm_index = ifp->if_index; |
| 967 | } else { |
| 968 | info->rti_info[RTAX_IFP] = NULL; |
| 969 | info->rti_info[RTAX_IFA] = NULL; |
| 970 | } |
| 971 | } else if (ifp != NULL) |
| 972 | rtm->rtm_index = ifp->if_index; |
| 973 | |
| 974 | /* Check if we need to realloc storage */ |
| 975 | rtsock_msg_buffer(rtm->rtm_type, info, NULL, &len); |
| 976 | if (len > maxlen) { |
| 977 | return (ENOBUFS); |
| 978 | } |
| 979 | |
| 980 | if (len > alloc_len) { |
| 981 | struct rt_msghdr *tmp_rtm; |
| 982 | |
| 983 | tmp_rtm = malloc(len, M_TEMP, M_NOWAIT); |
| 984 | if (tmp_rtm == NULL) |
| 985 | return (ENOBUFS); |
| 986 | bcopy(rtm, tmp_rtm, rtm->rtm_msglen); |
| 987 | orig_rtm = rtm; |
| 988 | rtm = tmp_rtm; |
| 989 | alloc_len = len; |
| 990 | |
| 991 | /* |
no test coverage detected