/*
- * Copyright (c) 2000-2015 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2017 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <sys/syslog.h>
#include <sys/mcache.h>
#include <kern/locks.h>
+#include <sys/codesign.h>
#include <net/if.h>
#include <net/route.h>
SYSCTL_NODE(_net, OID_AUTO, route, CTLFLAG_RW|CTLFLAG_LOCKED, 0, "routing");
+/* Align x to 1024 (only power of 2) assuming x is positive */
+#define ALIGN_BYTES(x) do { \
+ x = P2ALIGN(x, 1024); \
+} while(0)
+
#define ROUNDUP32(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof (uint32_t) - 1))) : \
sizeof (uint32_t))
int sendonlytoself = 0;
unsigned int ifscope = IFSCOPE_NONE;
struct rawcb *rp = NULL;
-
+ boolean_t is_router = FALSE;
#define senderr(e) { error = (e); goto flush; }
if (m == NULL || ((m->m_len < sizeof (intptr_t)) &&
(m = m_pullup(m, sizeof (intptr_t))) == NULL))
senderr(EINVAL);
ifscope = rtm->rtm_index;
}
+ /*
+ * Block changes on INTCOPROC interfaces.
+ */
+ if (ifscope) {
+ unsigned int intcoproc_scope = 0;
+ ifnet_head_lock_shared();
+ TAILQ_FOREACH(ifp, &ifnet_head, if_link) {
+ if (IFNET_IS_INTCOPROC(ifp)) {
+ intcoproc_scope = ifp->if_index;
+ break;
+ }
+ }
+ ifnet_head_done();
+ if (intcoproc_scope == ifscope && current_proc()->p_pid != 0)
+ senderr(EINVAL);
+ }
/*
* RTF_PROXY can only be set internally from within the kernel.
*/
switch (rtm->rtm_type) {
case RTM_GET: {
+ kauth_cred_t cred;
struct ifaddr *ifa2;
report:
+ cred = kauth_cred_proc_ref(current_proc());
ifa2 = NULL;
RT_LOCK_ASSERT_HELD(rt);
info.rti_info[RTAX_DST] = rt_key(rt);
}
if (ifa2 != NULL)
IFA_LOCK(ifa2);
- len = rt_msg2(rtm->rtm_type, &info, NULL, NULL, NULL);
+ len = rt_msg2(rtm->rtm_type, &info, NULL, NULL, &cred);
if (ifa2 != NULL)
IFA_UNLOCK(ifa2);
if (len > rtm->rtm_msglen) {
if (ifa2 != NULL)
IFA_LOCK(ifa2);
(void) rt_msg2(rtm->rtm_type, &info, (caddr_t)rtm,
- NULL, NULL);
+ NULL, &cred);
if (ifa2 != NULL)
IFA_UNLOCK(ifa2);
rtm->rtm_flags = rt->rt_flags;
rtm->rtm_addrs = info.rti_addrs;
if (ifa2 != NULL)
IFA_REMREF(ifa2);
+
+ kauth_cred_unref(&cred);
break;
}
case RTM_CHANGE:
+ is_router = (rt->rt_flags & RTF_ROUTER) ? TRUE : FALSE;
+
if (info.rti_info[RTAX_GATEWAY] != NULL &&
(error = rt_setgate(rt, rt_key(rt),
info.rti_info[RTAX_GATEWAY]))) {
* the required gateway, then just use the old one.
* This can happen if the user tries to change the
* flags on the default route without changing the
- * default gateway. Changing flags still doesn't work.
+ * default gateway. Changing flags still doesn't work.
*/
if ((rt->rt_flags & RTF_GATEWAY) &&
info.rti_info[RTAX_GATEWAY] == NULL)
}
if (info.rti_info[RTAX_GENMASK])
rt->rt_genmask = info.rti_info[RTAX_GENMASK];
+
+ /*
+ * Enqueue work item to invoke callback for this route entry
+ * This may not be needed always, but for now issue it anytime
+ * RTM_CHANGE gets called.
+ */
+ route_event_enqueue_nwk_wq_entry(rt, NULL, ROUTE_ENTRY_REFRESH, NULL, TRUE);
+ /*
+ * If the route is for a router, walk the tree to send refresh
+ * event to protocol cloned entries
+ */
+ if (is_router) {
+ struct route_event rt_ev;
+ route_event_init(&rt_ev, rt, NULL, ROUTE_ENTRY_REFRESH);
+ RT_UNLOCK(rt);
+ (void) rnh->rnh_walktree(rnh, route_event_walktree, (void *)&rt_ev);
+ RT_LOCK(rt);
+ }
/* FALLTHRU */
case RTM_LOCK:
rt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
struct ifnet *ifp = NULL;
void (*ifa_rtrequest)(int, struct rtentry *, struct sockaddr *);
- lck_mtx_assert(rnh_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(rnh_lock, LCK_MTX_ASSERT_OWNED);
RT_LOCK_ASSERT_HELD(rt);
sa = rtm_scrub(type, i, hint, sa, &ssbuf,
sizeof (ssbuf), NULL);
break;
-
+ case RTAX_GATEWAY:
case RTAX_IFP:
sa = rtm_scrub(type, i, NULL, sa, &ssbuf,
sizeof (ssbuf), credp);
struct ifnet *ifp = ifa->ifa_ifp;
struct sockproto route_proto = { PF_ROUTE, 0 };
- lck_mtx_assert(rnh_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(rnh_lock, LCK_MTX_ASSERT_OWNED);
RT_LOCK_ASSERT_HELD(rt);
if (route_cb.any_count == 0)
struct ifnet *ifp;
struct ifaddr *ifa;
struct rt_addrinfo info;
- int len, error = 0;
+ int len = 0, error = 0;
int pass = 0;
int total_len = 0, current_len = 0;
char *total_buffer = NULL, *cp = NULL;
if_data_internal_to_if_data(ifp, &ifp->if_data,
&ifm->ifm_data);
ifm->ifm_addrs = info.rti_addrs;
+ /*
+ * <rdar://problem/32940901>
+ * Round bytes only for non-platform
+ */
+ if (!csproc_get_platform_binary(w->w_req->p)) {
+ ALIGN_BYTES(ifm->ifm_data.ifi_ibytes);
+ ALIGN_BYTES(ifm->ifm_data.ifi_obytes);
+ }
cp += len;
VERIFY(IS_P2ALIGNED(cp, sizeof (u_int32_t)));
struct ifnet *ifp;
struct ifaddr *ifa;
struct rt_addrinfo info;
- int len, error = 0;
+ int len = 0, error = 0;
int pass = 0;
int total_len = 0, current_len = 0;
char *total_buffer = NULL, *cp = NULL;
ifm->ifm_timer = ifp->if_timer;
if_data_internal_to_if_data64(ifp,
&ifp->if_data, &ifm->ifm_data);
+ /*
+ * <rdar://problem/32940901>
+ * Round bytes only for non-platform
+ */
+ if (!csproc_get_platform_binary(w->w_req->p)) {
+ ALIGN_BYTES(ifm->ifm_data.ifi_ibytes);
+ ALIGN_BYTES(ifm->ifm_data.ifi_obytes);
+ }
cp += len;
VERIFY(IS_P2ALIGNED(cp, sizeof (u_int32_t)));