FreeBSD/sys/net/rtsock.c
/*
 * This is used in dumping the kernel table via sysctl().
 */
This is used in dumping the kernel table via sysctl().
This is used in dumping the kernel table via sysctl () .
static int
sysctl_dumpentry(struct radix_node *rn, void *vw)
{
	struct walkarg *w = vw;
	struct rtentry *rt = (struct rtentry *)rn;
	int error = 0, size;
	struct rt_addrinfo info;
	struct sockaddr_storage ss;
	if (w->w_op == NET_RT_FLAGS && !(rt->rt_flags & w->w_arg))
		return 0;
	if ((rt->rt_flags & RTF_HOST) == 0
	    ? jailed_without_vnet(w->w_req->td->td_ucred)
	    : prison_if(w->w_req->td->td_ucred, rt_key(rt)) != 0)
		return (0);
	bzero((caddr_t)&info, sizeof(info));
	info.rti_info[RTAX_DST] = rt_key(rt);
	info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
	info.rti_info[RTAX_NETMASK] = rtsock_fix_netmask(rt_key(rt),
	    rt_mask(rt), &ss);
	info.rti_info[RTAX_GENMASK] = 0;
	if (rt->rt_ifp) {
		info.rti_info[RTAX_IFP] = rt->rt_ifp->if_addr->ifa_addr;
		info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
		if (rt->rt_ifp->if_flags & IFF_POINTOPOINT)
			info.rti_info[RTAX_BRD] = rt->rt_ifa->ifa_dstaddr;
	}
	if ((error = rtsock_msg_buffer(RTM_GET, &info, w, &size)) != 0)
		return (error);
	if (w->w_req && w->w_tmem) {
		struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem;
		if (rt->rt_flags & RTF_GWFLAG_COMPAT)
			rtm->rtm_flags = RTF_GATEWAY | 
				(rt->rt_flags & ~RTF_GWFLAG_COMPAT);
		else
			rtm->rtm_flags = rt->rt_flags;
		rt_getmetrics(rt, &rtm->rtm_rmx);
		rtm->rtm_index = rt->rt_ifp->if_index;
		rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0;
		rtm->rtm_addrs = info.rti_addrs;
		error = SYSCTL_OUT(w->w_req, (caddr_t)rtm, size);
		return (error);
	}
	return (error);
}
static int sysctl_dumpentry ( struct radix_node * rn , void * vw ) { struct walkarg * w = vw ; struct rtentry * rt = ( struct rtentry * ) rn ; int error = 0 , size ; struct rt_addrinfo info ; struct sockaddr_storage ss ; if ( w -> w_op == NET_RT_FLAGS && ! ( rt -> rt_flags & w -> w_arg ) ) return 0 ; if ( ( rt -> rt_flags & RTF_HOST ) == 0 ? jailed_without_vnet ( w -> w_req -> td -> td_ucred ) : prison_if ( w -> w_req -> td -> td_ucred , rt_key ( rt ) ) != 0 ) return ( 0 ) ; bzero ( ( caddr_t ) & info , sizeof ( info ) ) ; info . rti_info [ RTAX_DST ] = rt_key ( rt ) ; info . rti_info [ RTAX_GATEWAY ] = rt -> rt_gateway ; info . rti_info [ RTAX_NETMASK ] = rtsock_fix_netmask ( rt_key ( rt ) , rt_mask ( rt ) , & ss ) ; info . rti_info [ RTAX_GENMASK ] = 0 ; if ( rt -> rt_ifp ) { info . rti_info [ RTAX_IFP ] = rt -> rt_ifp -> if_addr -> ifa_addr ; info . rti_info [ RTAX_IFA ] = rt -> rt_ifa -> ifa_addr ; if ( rt -> rt_ifp -> if_flags & IFF_POINTOPOINT ) info . rti_info [ RTAX_BRD ] = rt -> rt_ifa -> ifa_dstaddr ; } if ( ( error = rtsock_msg_buffer ( RTM_GET , & info , w , & size ) ) != 0 ) return ( error ) ; if ( w -> w_req && w -> w_tmem ) { struct rt_msghdr * rtm = ( struct rt_msghdr * ) w -> w_tmem ; if ( rt -> rt_flags & RTF_GWFLAG_COMPAT ) rtm -> rtm_flags = RTF_GATEWAY | ( rt -> rt_flags & ~ RTF_GWFLAG_COMPAT ) ; else rtm -> rtm_flags = rt -> rt_flags ; rt_getmetrics ( rt , & rtm -> rtm_rmx ) ; rtm -> rtm_index = rt -> rt_ifp -> if_index ; rtm -> rtm_errno = rtm -> rtm_pid = rtm -> rtm_seq = 0 ; rtm -> rtm_addrs = info . rti_addrs ; error = SYSCTL_OUT ( w -> w_req , ( caddr_t ) rtm , size ) ; return ( error ) ; } return ( error ) ; }
This is used in dumping the kernel table via sysctl().
This is used in dumping the kernel table via sysctl () .