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

Function rt_exportinfo

freebsd/net/route.c:333–406  ·  view source on GitHub ↗

* Copy most of @rt data into @info. * * If @flags contains NHR_COPY, copies dst,netmask and gw to the * pointers specified by @info structure. Assume such pointers * are zeroed sockaddr-like structures with sa_len field initialized * to reflect size of the provided buffer. if no NHR_COPY is specified, * point dst,netmask and gw @info fields to appropriate @rt values. * * if @flags contains

Source from the content-addressed store, hash-verified

331 * Returns 0 on success.
332 */
333static int
334rt_exportinfo(struct rtentry *rt, struct nhop_object *nh,
335 struct rt_addrinfo *info, int flags)
336{
337 struct rt_metrics *rmx;
338 struct sockaddr *src, *dst;
339 int sa_len;
340
341 if (flags & NHR_COPY) {
342 /* Copy destination if dst is non-zero */
343 src = rt_key(rt);
344 dst = info->rti_info[RTAX_DST];
345 sa_len = src->sa_len;
346 if (dst != NULL) {
347 if (src->sa_len > dst->sa_len)
348 return (ENOMEM);
349 memcpy(dst, src, src->sa_len);
350 info->rti_addrs |= RTA_DST;
351 }
352
353 /* Copy mask if set && dst is non-zero */
354 src = rt_mask(rt);
355 dst = info->rti_info[RTAX_NETMASK];
356 if (src != NULL && dst != NULL) {
357 /*
358 * Radix stores different value in sa_len,
359 * assume rt_mask() to have the same length
360 * as rt_key()
361 */
362 if (sa_len > dst->sa_len)
363 return (ENOMEM);
364 memcpy(dst, src, src->sa_len);
365 info->rti_addrs |= RTA_NETMASK;
366 }
367
368 /* Copy gateway is set && dst is non-zero */
369 src = &nh->gw_sa;
370 dst = info->rti_info[RTAX_GATEWAY];
371 if ((nhop_get_rtflags(nh) & RTF_GATEWAY) &&
372 src != NULL && dst != NULL) {
373 if (src->sa_len > dst->sa_len)
374 return (ENOMEM);
375 memcpy(dst, src, src->sa_len);
376 info->rti_addrs |= RTA_GATEWAY;
377 }
378 } else {
379 info->rti_info[RTAX_DST] = rt_key(rt);
380 info->rti_addrs |= RTA_DST;
381 if (rt_mask(rt) != NULL) {
382 info->rti_info[RTAX_NETMASK] = rt_mask(rt);
383 info->rti_addrs |= RTA_NETMASK;
384 }
385 if (nhop_get_rtflags(nh) & RTF_GATEWAY) {
386 info->rti_info[RTAX_GATEWAY] = &nh->gw_sa;
387 info->rti_addrs |= RTA_GATEWAY;
388 }
389 }
390

Callers 1

rib_lookup_infoFunction · 0.85

Calls 4

nhop_get_rtflagsFunction · 0.85
if_refFunction · 0.85
ifa_refFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected