* Update sockaddrs, flags, etc in @prtm based on @rc data. * rtm can be reallocated. * * Returns 0 on success, along with pointer to (potentially reallocated) * rtm. * */
| 887 | * |
| 888 | */ |
| 889 | static int |
| 890 | update_rtm_from_rc(struct rt_addrinfo *info, struct rt_msghdr **prtm, |
| 891 | int alloc_len, struct rib_cmd_info *rc, struct nhop_object *nh) |
| 892 | { |
| 893 | struct walkarg w; |
| 894 | union sockaddr_union saun; |
| 895 | struct rt_msghdr *rtm, *orig_rtm = NULL; |
| 896 | struct ifnet *ifp; |
| 897 | int error, len; |
| 898 | |
| 899 | rtm = *prtm; |
| 900 | union sockaddr_union sa_dst, sa_mask; |
| 901 | int family = info->rti_info[RTAX_DST]->sa_family; |
| 902 | init_sockaddrs_family(family, &sa_dst.sa, &sa_mask.sa); |
| 903 | export_rtaddrs(rc->rc_rt, &sa_dst.sa, &sa_mask.sa); |
| 904 | |
| 905 | info->rti_info[RTAX_DST] = &sa_dst.sa; |
| 906 | info->rti_info[RTAX_NETMASK] = rt_is_host(rc->rc_rt) ? NULL : &sa_mask.sa; |
| 907 | info->rti_info[RTAX_GATEWAY] = &nh->gw_sa; |
| 908 | info->rti_info[RTAX_GENMASK] = 0; |
| 909 | ifp = nh->nh_ifp; |
| 910 | if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) { |
| 911 | if (ifp) { |
| 912 | info->rti_info[RTAX_IFP] = |
| 913 | ifp->if_addr->ifa_addr; |
| 914 | error = rtm_get_jailed(info, ifp, nh, |
| 915 | &saun, curthread->td_ucred); |
| 916 | if (error != 0) |
| 917 | return (error); |
| 918 | if (ifp->if_flags & IFF_POINTOPOINT) |
| 919 | info->rti_info[RTAX_BRD] = |
| 920 | nh->nh_ifa->ifa_dstaddr; |
| 921 | rtm->rtm_index = ifp->if_index; |
| 922 | } else { |
| 923 | info->rti_info[RTAX_IFP] = NULL; |
| 924 | info->rti_info[RTAX_IFA] = NULL; |
| 925 | } |
| 926 | } else if (ifp != NULL) |
| 927 | rtm->rtm_index = ifp->if_index; |
| 928 | |
| 929 | /* Check if we need to realloc storage */ |
| 930 | rtsock_msg_buffer(rtm->rtm_type, info, NULL, &len); |
| 931 | if (len > alloc_len) { |
| 932 | struct rt_msghdr *tmp_rtm; |
| 933 | |
| 934 | tmp_rtm = malloc(len, M_TEMP, M_NOWAIT); |
| 935 | if (tmp_rtm == NULL) |
| 936 | return (ENOBUFS); |
| 937 | bcopy(rtm, tmp_rtm, rtm->rtm_msglen); |
| 938 | orig_rtm = rtm; |
| 939 | rtm = tmp_rtm; |
| 940 | alloc_len = len; |
| 941 | |
| 942 | /* |
| 943 | * Delay freeing original rtm as info contains |
| 944 | * data referencing it. |
| 945 | */ |
| 946 | } |
no test coverage detected