MCPcopy Create free account
hub / github.com/F-Stack/f-stack / update_rtm_from_rc

Function update_rtm_from_rc

lib/ff_route.c:934–1014  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

932}
933
934static int
935update_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 /*

Callers 1

ff_rtioctlFunction · 0.70

Calls 9

rt_is_hostFunction · 0.85
mallocFunction · 0.85
nhop_get_rtflagsFunction · 0.85
init_sockaddrs_familyFunction · 0.70
export_rtaddrsFunction · 0.70
rtm_get_jailedFunction · 0.70
rtsock_msg_bufferFunction · 0.70
rt_getmetricsFunction · 0.70
freeFunction · 0.70

Tested by

no test coverage detected