Changeset View
Changeset View
Standalone View
Standalone View
sys/net/rtsock.c
Show First 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | |||||
static int handle_rtm_get(struct rt_addrinfo *info, u_int fibnum, | static int handle_rtm_get(struct rt_addrinfo *info, u_int fibnum, | ||||
struct rt_msghdr *rtm, struct rib_cmd_info *rc); | struct rt_msghdr *rtm, struct rib_cmd_info *rc); | ||||
static int update_rtm_from_rc(struct rt_addrinfo *info, | static int update_rtm_from_rc(struct rt_addrinfo *info, | ||||
struct rt_msghdr **prtm, int alloc_len, | struct rt_msghdr **prtm, int alloc_len, | ||||
struct rib_cmd_info *rc, struct nhop_object *nh); | struct rib_cmd_info *rc, struct nhop_object *nh); | ||||
static void send_rtm_reply(struct socket *so, struct rt_msghdr *rtm, | static void send_rtm_reply(struct socket *so, struct rt_msghdr *rtm, | ||||
struct mbuf *m, sa_family_t saf, u_int fibnum, | struct mbuf *m, sa_family_t saf, u_int fibnum, | ||||
int rtm_errno); | int rtm_errno); | ||||
static bool can_export_rte(struct ucred *td_ucred, bool rt_is_host, | |||||
const struct sockaddr *rt_dst); | |||||
static void rtsock_notify_event(uint32_t fibnum, const struct rib_cmd_info *rc); | static void rtsock_notify_event(uint32_t fibnum, const struct rib_cmd_info *rc); | ||||
static void rtsock_ifmsg(struct ifnet *ifp, int if_flags_mask); | static void rtsock_ifmsg(struct ifnet *ifp, int if_flags_mask); | ||||
static struct netisr_handler rtsock_nh = { | static struct netisr_handler rtsock_nh = { | ||||
.nh_name = "rtsock", | .nh_name = "rtsock", | ||||
.nh_handler = rts_input, | .nh_handler = rts_input, | ||||
.nh_proto = NETISR_ROUTE, | .nh_proto = NETISR_ROUTE, | ||||
.nh_policy = NETISR_POLICY_SOURCE, | .nh_policy = NETISR_POLICY_SOURCE, | ||||
▲ Show 20 Lines • Show All 932 Lines • ▼ Show 20 Lines | #endif | ||||
break; | break; | ||||
case RTM_GET: | case RTM_GET: | ||||
error = handle_rtm_get(&info, fibnum, rtm, &rc); | error = handle_rtm_get(&info, fibnum, rtm, &rc); | ||||
if (error != 0) | if (error != 0) | ||||
senderr(error); | senderr(error); | ||||
nh = rc.rc_nh_new; | nh = rc.rc_nh_new; | ||||
if (!can_export_rte(curthread->td_ucred, | if (!rt_is_exportable(rc.rc_rt, curthread->td_ucred)) | ||||
info.rti_info[RTAX_NETMASK] == NULL, | |||||
info.rti_info[RTAX_DST])) { | |||||
senderr(ESRCH); | senderr(ESRCH); | ||||
} | |||||
break; | break; | ||||
default: | default: | ||||
senderr(EOPNOTSUPP); | senderr(EOPNOTSUPP); | ||||
} | } | ||||
if (error == 0 && nh != NULL) { | if (error == 0 && nh != NULL) { | ||||
error = update_rtm_from_rc(&info, &rtm, alloc_len, &rc, nh); | error = update_rtm_from_rc(&info, &rtm, alloc_len, &rc, nh); | ||||
▲ Show 20 Lines • Show All 1,010 Lines • ▼ Show 20 Lines | rt_dispatch(struct mbuf *m, sa_family_t saf) | ||||
else { | else { | ||||
m_freem(m); | m_freem(m); | ||||
return; | return; | ||||
} | } | ||||
netisr_queue(NETISR_ROUTE, m); /* mbuf is free'd on failure. */ | netisr_queue(NETISR_ROUTE, m); /* mbuf is free'd on failure. */ | ||||
} | } | ||||
/* | /* | ||||
* Checks if rte can be exported w.r.t jails/vnets. | |||||
* | |||||
* Returns true if it can, false otherwise. | |||||
*/ | |||||
static bool | |||||
can_export_rte(struct ucred *td_ucred, bool rt_is_host, | |||||
const struct sockaddr *rt_dst) | |||||
{ | |||||
if ((!rt_is_host) ? jailed_without_vnet(td_ucred) | |||||
: prison_if(td_ucred, rt_dst) != 0) | |||||
return (false); | |||||
return (true); | |||||
} | |||||
/* | |||||
* This is used in dumping the kernel table via sysctl(). | * This is used in dumping the kernel table via sysctl(). | ||||
*/ | */ | ||||
static int | static int | ||||
sysctl_dumpentry(struct rtentry *rt, void *vw) | sysctl_dumpentry(struct rtentry *rt, void *vw) | ||||
{ | { | ||||
struct walkarg *w = vw; | struct walkarg *w = vw; | ||||
struct nhop_object *nh; | struct nhop_object *nh; | ||||
NET_EPOCH_ASSERT(); | NET_EPOCH_ASSERT(); | ||||
export_rtaddrs(rt, w->dst, w->mask); | if (!rt_is_exportable(rt, w->w_req->td->td_ucred)) | ||||
if (!can_export_rte(w->w_req->td->td_ucred, rt_is_host(rt), w->dst)) | |||||
return (0); | return (0); | ||||
export_rtaddrs(rt, w->dst, w->mask); | |||||
nh = rt_get_raw_nhop(rt); | nh = rt_get_raw_nhop(rt); | ||||
#ifdef ROUTE_MPATH | #ifdef ROUTE_MPATH | ||||
if (NH_IS_NHGRP(nh)) { | if (NH_IS_NHGRP(nh)) { | ||||
const struct weightened_nhop *wn; | const struct weightened_nhop *wn; | ||||
uint32_t num_nhops; | uint32_t num_nhops; | ||||
int error; | int error; | ||||
wn = nhgrp_get_nhops((struct nhgrp_object *)nh, &num_nhops); | wn = nhgrp_get_nhops((struct nhgrp_object *)nh, &num_nhops); | ||||
for (int i = 0; i < num_nhops; i++) { | for (int i = 0; i < num_nhops; i++) { | ||||
▲ Show 20 Lines • Show All 485 Lines • Show Last 20 Lines |