/*
- * Copyright (c) 2000-2015 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
- *
+ *
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
* SUCH DAMAGE.
*
* @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95
- * $FreeBSD: src/sys/netinet/udp_usrreq.c,v 1.64.2.13 2001/08/08 18:59:54 ghelmer Exp $
*/
#include <sys/param.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
+#include <netinet/in_tclass.h>
#include <netinet/ip.h>
#if INET6
#include <netinet/ip6.h>
int udp_log_in_vain = 0;
SYSCTL_INT(_net_inet_udp, OID_AUTO, log_in_vain, CTLFLAG_RW | CTLFLAG_LOCKED,
- &udp_log_in_vain, 0, "Log all incoming UDP packets");
+ &udp_log_in_vain, 0, "Log all incoming UDP packets");
static int blackhole = 0;
SYSCTL_INT(_net_inet_udp, OID_AUTO, blackhole, CTLFLAG_RW | CTLFLAG_LOCKED,
- &blackhole, 0, "Do not send port unreachables for refused connects");
+ &blackhole, 0, "Do not send port unreachables for refused connects");
struct inpcbhead udb; /* from udp_var.h */
#define udb6 udb /* for KAME src sync over BSD*'s */
struct inpcbinfo udbinfo;
#ifndef UDBHASHSIZE
-#define UDBHASHSIZE 16
+#define UDBHASHSIZE 16
#endif
/* Garbage collection performed during most recent udp_gc() run */
#if IPFIREWALL
extern int fw_verbose;
-extern void ipfwsyslog( int level, const char *format,...);
+extern void ipfwsyslog(int level, const char *format, ...);
extern void ipfw_stealth_stats_incr_udp(void);
/* Apple logging, log to ipfw.log */
-#define log_in_vain_log(a) { \
+#define log_in_vain_log(a) { \
if ((udp_log_in_vain == 3) && (fw_verbose == 2)) { \
ipfwsyslog a; \
} else if ((udp_log_in_vain == 4) && (fw_verbose == 2)) { \
- ipfw_stealth_stats_incr_udp(); \
+ ipfw_stealth_stats_incr_udp(); \
} else { \
log a; \
} \
}
#else /* !IPFIREWALL */
-#define log_in_vain_log( a ) { log a; }
+#define log_in_vain_log(a) { log a; }
#endif /* !IPFIREWALL */
static int udp_getstat SYSCTL_HANDLER_ARGS;
struct udpstat udpstat; /* from udp_var.h */
SYSCTL_PROC(_net_inet_udp, UDPCTL_STATS, stats,
- CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED,
- 0, 0, udp_getstat, "S,udpstat",
- "UDP statistics (struct udpstat, netinet/udp_var.h)");
+ CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED,
+ 0, 0, udp_getstat, "S,udpstat",
+ "UDP statistics (struct udpstat, netinet/udp_var.h)");
SYSCTL_INT(_net_inet_udp, OID_AUTO, pcbcount,
- CTLFLAG_RD | CTLFLAG_LOCKED, &udbinfo.ipi_count, 0,
- "Number of active PCBs");
+ CTLFLAG_RD | CTLFLAG_LOCKED, &udbinfo.ipi_count, 0,
+ "Number of active PCBs");
__private_extern__ int udp_use_randomport = 1;
SYSCTL_INT(_net_inet_udp, OID_AUTO, randomize_ports,
- CTLFLAG_RW | CTLFLAG_LOCKED, &udp_use_randomport, 0,
- "Randomize UDP port numbers");
+ CTLFLAG_RW | CTLFLAG_LOCKED, &udp_use_randomport, 0,
+ "Randomize UDP port numbers");
#if INET6
struct udp_in6 {
static int udp_attach(struct socket *, int, struct proc *);
static int udp_bind(struct socket *, struct sockaddr *, struct proc *);
static int udp_connect(struct socket *, struct sockaddr *, struct proc *);
-static int udp_connectx(struct socket *, struct sockaddr_list **,
- struct sockaddr_list **, struct proc *, uint32_t, sae_associd_t,
+static int udp_connectx(struct socket *, struct sockaddr *,
+ struct sockaddr *, struct proc *, uint32_t, sae_associd_t,
sae_connid_t *, uint32_t, void *, uint32_t, struct uio *, user_ssize_t *);
static int udp_detach(struct socket *);
static int udp_disconnect(struct socket *);
udpstat.udps_ipackets++;
- KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_START, 0,0,0,0,0);
+ KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_START, 0, 0, 0, 0, 0);
/* Expect 32-bit aligned data pointer on strict-align platforms */
MBUF_STRICT_DATA_ALIGNMENT_CHECK_32(m);
if (m == NULL) {
udpstat.udps_hdrops++;
KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END,
- 0,0,0,0,0);
+ 0, 0, 0, 0, 0);
return;
}
ip = mtod(m, struct ip *);
/* NOTREACHED */
}
#if INET6
- if ((inp->inp_vflag & INP_IPV4) == 0)
- continue;
+ if ((inp->inp_vflag & INP_IPV4) == 0)
+ continue;
#endif /* INET6 */
if (inp_restricted_recv(inp, ifp))
continue;
#if NECP
skipit = 0;
- if (!necp_socket_is_allowed_to_send_recv_v4(inp,
+ if (!necp_socket_is_allowed_to_send_recv_v4(inp,
uh->uh_dport, uh->uh_sport, &ip->ip_dst,
&ip->ip_src, ifp, NULL, NULL)) {
/* do not inject data to pcb */
/* free the extra copy of mbuf or skipped by IPSec */
if (m != NULL)
m_freem(m);
- KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END, 0,0,0,0,0);
+ KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END, 0, 0, 0, 0, 0);
return;
}
payload_len)) == NULL) {
udpstat.udps_hdrops++;
KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END,
- 0,0,0,0,0);
+ 0, 0, 0, 0, 0);
return;
}
/*
uh = (struct udphdr *)(void *)((caddr_t)ip + iphlen);
}
/* Check for NAT keepalive packet */
- if (payload_len == 1 && *(u_int8_t*)
+ if (payload_len == 1 && *(u_int8_t *)
((caddr_t)uh + sizeof (struct udphdr)) == 0xFF) {
m_freem(m);
KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END,
- 0,0,0,0,0);
+ 0, 0, 0, 0, 0);
return;
- } else if (payload_len == 4 && *(u_int32_t*)(void *)
+ } else if (payload_len == 4 && *(u_int32_t *)(void *)
((caddr_t)uh + sizeof (struct udphdr)) != 0) {
/* UDP encapsulated IPSec packet to pass through NAT */
KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END,
- 0,0,0,0,0);
+ 0, 0, 0, 0, 0);
/* preserve the udp header */
esp4_input(m, iphlen + sizeof (struct udphdr));
return;
if (udp_log_in_vain < 3) {
log(LOG_INFO, "Connection attempt to "
"UDP %s:%d from %s:%d\n", inet_ntop(AF_INET,
- &ip->ip_dst, buf, sizeof (buf)),
+ &ip->ip_dst, buf, sizeof (buf)),
ntohs(uh->uh_dport), inet_ntop(AF_INET,
&ip->ip_src, buf2, sizeof (buf2)),
ntohs(uh->uh_sport));
*ip = save_ip;
ip->ip_len += iphlen;
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0);
- KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END, 0,0,0,0,0);
+ KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END, 0, 0, 0, 0, 0);
return;
}
udp_lock(inp->inp_socket, 1, 0);
sorwakeup(inp->inp_socket);
}
udp_unlock(inp->inp_socket, 1, 0);
- KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END, 0,0,0,0,0);
+ KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END, 0, 0, 0, 0, 0);
return;
bad:
m_freem(m);
if (opts)
m_freem(opts);
- KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END, 0,0,0,0,0);
+ KERNEL_DEBUG(DBG_FNC_UDP_INPUT | DBG_FUNC_END, 0, 0, 0, 0, 0);
}
#if INET6
append_sa = (struct sockaddr *)pudp_in;
if (nstat_collect) {
INP_ADD_STAT(last, cell, wifi, wired, rxpackets, 1);
- INP_ADD_STAT(last, cell, wifi, wired, rxbytes,
+ INP_ADD_STAT(last, cell, wifi, wired, rxbytes,
n->m_pkthdr.len);
}
so_recv_data_stat(last->inp_socket, n, 0);
error:
m_freem(n);
m_freem(opts);
- return;
}
/*
{
struct ip *ip = vip;
void (*notify)(struct inpcb *, int) = udp_notify;
- struct in_addr faddr;
+ struct in_addr faddr;
struct inpcb *inp;
faddr = ((struct sockaddr_in *)(void *)sa)->sin_addr;
bcopy(((caddr_t)ip + (ip->ip_hl << 2)), &uh, sizeof (uh));
inp = in_pcblookup_hash(&udbinfo, faddr, uh.uh_dport,
- ip->ip_src, uh.uh_sport, 0, NULL);
+ ip->ip_src, uh.uh_sport, 0, NULL);
if (inp != NULL && inp->inp_socket != NULL) {
udp_lock(inp->inp_socket, 1, 0);
if (in_pcb_checkstate(inp, WNT_RELEASE, 1) ==
UDP_KEEPALIVE_OFFLOAD_DATA_SIZE);
if (inp->inp_keepalive_datalen > 0) {
MALLOC(inp->inp_keepalive_data,
- u_int8_t *,
+ u_int8_t *,
inp->inp_keepalive_datalen,
M_TEMP, M_WAITOK);
if (inp->inp_keepalive_data == NULL) {
}
for (inp = LIST_FIRST(udbinfo.ipi_listhead), i = 0; inp && i < n;
- inp = LIST_NEXT(inp, inp_list)) {
+ inp = LIST_NEXT(inp, inp_list)) {
if (inp->inp_gencnt <= gencnt &&
inp->inp_state != INPCB_STATE_DEAD)
inp_list[i++] = inp;
error = 0;
for (i = 0; i < n; i++) {
+ struct xinpcb xi;
+
inp = inp_list[i];
- if (inp->inp_gencnt <= gencnt &&
- inp->inp_state != INPCB_STATE_DEAD) {
- struct xinpcb xi;
-
- bzero(&xi, sizeof (xi));
- xi.xi_len = sizeof (xi);
- /* XXX should avoid extra copy */
- inpcb_to_compat(inp, &xi.xi_inp);
- if (inp->inp_socket)
- sotoxsocket(inp->inp_socket, &xi.xi_socket);
- error = SYSCTL_OUT(req, &xi, sizeof (xi));
+
+ if (in_pcb_checkstate(inp, WNT_ACQUIRE, 0) == WNT_STOPUSING)
+ continue;
+ udp_lock(inp->inp_socket, 1, 0);
+ if (in_pcb_checkstate(inp, WNT_RELEASE, 1) == WNT_STOPUSING) {
+ udp_unlock(inp->inp_socket, 1, 0);
+ continue;
+ }
+ if (inp->inp_gencnt > gencnt) {
+ udp_unlock(inp->inp_socket, 1, 0);
+ continue;
}
+
+ bzero(&xi, sizeof (xi));
+ xi.xi_len = sizeof (xi);
+ /* XXX should avoid extra copy */
+ inpcb_to_compat(inp, &xi.xi_inp);
+ if (inp->inp_socket)
+ sotoxsocket(inp->inp_socket, &xi.xi_socket);
+
+ udp_unlock(inp->inp_socket, 1, 0);
+
+ error = SYSCTL_OUT(req, &xi, sizeof (xi));
}
if (!error) {
/*
}
SYSCTL_PROC(_net_inet_udp, UDPCTL_PCBLIST, pcblist,
- CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0, udp_pcblist,
- "S,xinpcb", "List of active UDP sockets");
+ CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0, udp_pcblist,
+ "S,xinpcb", "List of active UDP sockets");
static int
udp_pcblist64 SYSCTL_HANDLER_ARGS
{
#pragma unused(oidp, arg1, arg2)
- int error, i, n;
- struct inpcb *inp, **inp_list;
- inp_gen_t gencnt;
- struct xinpgen xig;
-
- /*
- * The process of preparing the TCB list is too time-consuming and
- * resource-intensive to repeat twice on every request.
- */
- lck_rw_lock_shared(udbinfo.ipi_lock);
- if (req->oldptr == USER_ADDR_NULL) {
- n = udbinfo.ipi_count;
- req->oldidx =
+ int error, i, n;
+ struct inpcb *inp, **inp_list;
+ inp_gen_t gencnt;
+ struct xinpgen xig;
+
+ /*
+ * The process of preparing the TCB list is too time-consuming and
+ * resource-intensive to repeat twice on every request.
+ */
+ lck_rw_lock_shared(udbinfo.ipi_lock);
+ if (req->oldptr == USER_ADDR_NULL) {
+ n = udbinfo.ipi_count;
+ req->oldidx =
2 * (sizeof (xig)) + (n + n/8) * sizeof (struct xinpcb64);
- lck_rw_done(udbinfo.ipi_lock);
- return (0);
- }
-
- if (req->newptr != USER_ADDR_NULL) {
- lck_rw_done(udbinfo.ipi_lock);
- return (EPERM);
- }
-
- /*
- * OK, now we're committed to doing something.
- */
- gencnt = udbinfo.ipi_gencnt;
- n = udbinfo.ipi_count;
-
- bzero(&xig, sizeof (xig));
- xig.xig_len = sizeof (xig);
- xig.xig_count = n;
- xig.xig_gen = gencnt;
- xig.xig_sogen = so_gencnt;
- error = SYSCTL_OUT(req, &xig, sizeof (xig));
- if (error) {
- lck_rw_done(udbinfo.ipi_lock);
- return (error);
- }
+ lck_rw_done(udbinfo.ipi_lock);
+ return (0);
+ }
+
+ if (req->newptr != USER_ADDR_NULL) {
+ lck_rw_done(udbinfo.ipi_lock);
+ return (EPERM);
+ }
+
+ /*
+ * OK, now we're committed to doing something.
+ */
+ gencnt = udbinfo.ipi_gencnt;
+ n = udbinfo.ipi_count;
+
+ bzero(&xig, sizeof (xig));
+ xig.xig_len = sizeof (xig);
+ xig.xig_count = n;
+ xig.xig_gen = gencnt;
+ xig.xig_sogen = so_gencnt;
+ error = SYSCTL_OUT(req, &xig, sizeof (xig));
+ if (error) {
+ lck_rw_done(udbinfo.ipi_lock);
+ return (error);
+ }
/*
* We are done if there is no pcb
*/
return (0);
}
- inp_list = _MALLOC(n * sizeof (*inp_list), M_TEMP, M_WAITOK);
- if (inp_list == 0) {
- lck_rw_done(udbinfo.ipi_lock);
- return (ENOMEM);
- }
+ inp_list = _MALLOC(n * sizeof (*inp_list), M_TEMP, M_WAITOK);
+ if (inp_list == 0) {
+ lck_rw_done(udbinfo.ipi_lock);
+ return (ENOMEM);
+ }
- for (inp = LIST_FIRST(udbinfo.ipi_listhead), i = 0; inp && i < n;
- inp = LIST_NEXT(inp, inp_list)) {
- if (inp->inp_gencnt <= gencnt &&
+ for (inp = LIST_FIRST(udbinfo.ipi_listhead), i = 0; inp && i < n;
+ inp = LIST_NEXT(inp, inp_list)) {
+ if (inp->inp_gencnt <= gencnt &&
inp->inp_state != INPCB_STATE_DEAD)
- inp_list[i++] = inp;
- }
- n = i;
-
- error = 0;
- for (i = 0; i < n; i++) {
- inp = inp_list[i];
- if (inp->inp_gencnt <= gencnt &&
- inp->inp_state != INPCB_STATE_DEAD) {
- struct xinpcb64 xi;
-
- bzero(&xi, sizeof (xi));
- xi.xi_len = sizeof (xi);
- inpcb_to_xinpcb64(inp, &xi);
- if (inp->inp_socket)
- sotoxsocket64(inp->inp_socket, &xi.xi_socket);
- error = SYSCTL_OUT(req, &xi, sizeof (xi));
- }
- }
- if (!error) {
- /*
- * Give the user an updated idea of our state.
- * If the generation differs from what we told
- * her before, she knows that something happened
- * while we were processing this request, and it
- * might be necessary to retry.
- */
- bzero(&xig, sizeof (xig));
- xig.xig_len = sizeof (xig);
- xig.xig_gen = udbinfo.ipi_gencnt;
- xig.xig_sogen = so_gencnt;
- xig.xig_count = udbinfo.ipi_count;
- error = SYSCTL_OUT(req, &xig, sizeof (xig));
- }
- FREE(inp_list, M_TEMP);
- lck_rw_done(udbinfo.ipi_lock);
- return (error);
+ inp_list[i++] = inp;
+ }
+ n = i;
+
+ error = 0;
+ for (i = 0; i < n; i++) {
+ struct xinpcb64 xi;
+
+ inp = inp_list[i];
+
+ if (in_pcb_checkstate(inp, WNT_ACQUIRE, 0) == WNT_STOPUSING)
+ continue;
+ udp_lock(inp->inp_socket, 1, 0);
+ if (in_pcb_checkstate(inp, WNT_RELEASE, 1) == WNT_STOPUSING) {
+ udp_unlock(inp->inp_socket, 1, 0);
+ continue;
+ }
+ if (inp->inp_gencnt > gencnt) {
+ udp_unlock(inp->inp_socket, 1, 0);
+ continue;
+ }
+
+ bzero(&xi, sizeof (xi));
+ xi.xi_len = sizeof (xi);
+ inpcb_to_xinpcb64(inp, &xi);
+ if (inp->inp_socket)
+ sotoxsocket64(inp->inp_socket, &xi.xi_socket);
+
+ udp_unlock(inp->inp_socket, 1, 0);
+
+ error = SYSCTL_OUT(req, &xi, sizeof (xi));
+ }
+ if (!error) {
+ /*
+ * Give the user an updated idea of our state.
+ * If the generation differs from what we told
+ * her before, she knows that something happened
+ * while we were processing this request, and it
+ * might be necessary to retry.
+ */
+ bzero(&xig, sizeof (xig));
+ xig.xig_len = sizeof (xig);
+ xig.xig_gen = udbinfo.ipi_gencnt;
+ xig.xig_sogen = so_gencnt;
+ xig.xig_count = udbinfo.ipi_count;
+ error = SYSCTL_OUT(req, &xig, sizeof (xig));
+ }
+ FREE(inp_list, M_TEMP);
+ lck_rw_done(udbinfo.ipi_lock);
+ return (error);
}
SYSCTL_PROC(_net_inet_udp, OID_AUTO, pcblist64,
- CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0, udp_pcblist64,
- "S,xinpcb64", "List of active UDP sockets");
+ CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0, udp_pcblist64,
+ "S,xinpcb64", "List of active UDP sockets");
static int
}
SYSCTL_PROC(_net_inet_udp, OID_AUTO, pcblist_n,
- CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0, udp_pcblist_n,
- "S,xinpcb_n", "List of active UDP sockets");
+ CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0, udp_pcblist_n,
+ "S,xinpcb_n", "List of active UDP sockets");
__private_extern__ void
udp_get_ports_used(uint32_t ifindex, int protocol, uint32_t flags,
struct ip_moptions *mopts;
struct route ro;
struct ip_out_args ipoa =
- { IFSCOPE_NONE, { 0 }, IPOAF_SELECT_SRCIF, 0 };
+ { IFSCOPE_NONE, { 0 }, IPOAF_SELECT_SRCIF, 0, 0, 0 };
struct ifnet *outif = NULL;
struct flowadv *adv = &ipoa.ipoa_flowadv;
- mbuf_svc_class_t msc = MBUF_SC_UNSPEC;
+ int sotc = SO_TC_UNSPEC;
+ int netsvctype = _NET_SERVICE_TYPE_UNSPEC;
struct ifnet *origoutifp = NULL;
int flowadv = 0;
flowadv = (so->so_state & SS_ISCONNECTED) ? 1 : 0;
pi_laddr.s_addr = INADDR_ANY;
- KERNEL_DEBUG(DBG_FNC_UDP_OUTPUT | DBG_FUNC_START, 0,0,0,0,0);
+ KERNEL_DEBUG(DBG_FNC_UDP_OUTPUT | DBG_FUNC_START, 0, 0, 0, 0, 0);
lck_mtx_assert(&inp->inpcb_mtx, LCK_MTX_ASSERT_OWNED);
if (control != NULL) {
- msc = mbuf_service_class_from_control(control);
+ sotc = so_tc_from_control(control, &netsvctype);
VERIFY(outif == NULL);
error = udp_check_pktinfo(control, &outif, &pi_laddr);
m_freem(control);
if (outif != NULL)
ipoa.ipoa_boundif = outif->if_index;
}
+ if (sotc == SO_TC_UNSPEC) {
+ sotc = so->so_traffic_class;
+ netsvctype = so->so_netsvctype;
+ }
KERNEL_DEBUG(DBG_LAYER_OUT_BEG, inp->inp_fport, inp->inp_lport,
inp->inp_laddr.s_addr, inp->inp_faddr.s_addr,
ipoa.ipoa_flags |= IPOAF_NO_EXPENSIVE;
if (INP_AWDL_UNRESTRICTED(inp))
ipoa.ipoa_flags |= IPOAF_AWDL_UNRESTRICTED;
+ ipoa.ipoa_sotc = sotc;
+ ipoa.ipoa_netsvctype = netsvctype;
soopts |= IP_OUTARGS;
/*
origladdr.s_addr = INADDR_ANY;
/* we don't want to keep the laddr or route */
udp_dodisconnect = 1;
- /* remember we don't care about src addr.*/
+ /* remember we don't care about src addr */
inp->inp_flags |= INP_INADDR_ANY;
} else {
origladdr = laddr = inp->inp_laddr;
/* synch up in case in_pcbladdr() overrides */
if (outif != NULL && ipoa.ipoa_boundif != IFSCOPE_NONE)
ipoa.ipoa_boundif = outif->if_index;
- }
- else {
+ } else {
/*
* Fast path case
*
*/
if (laddr.s_addr == INADDR_ANY) {
if ((error = in_pcbladdr(inp, addr, &laddr,
- ipoa.ipoa_boundif, &outif)) != 0)
+ ipoa.ipoa_boundif, &outif, 0)) != 0)
goto release;
/*
* from pcbconnect: remember we don't
udpstat.udps_opackets++;
KERNEL_DEBUG(DBG_LAYER_OUT_END, ui->ui_dport, ui->ui_sport,
- ui->ui_src.s_addr, ui->ui_dst.s_addr, ui->ui_ulen);
+ ui->ui_src.s_addr, ui->ui_dst.s_addr, ui->ui_ulen);
#if NECP
{
necp_kernel_policy_id policy_id;
u_int32_t route_rule_id;
+
+ /*
+ * We need a route to perform NECP route rule checks
+ */
+ if (net_qos_policy_restricted != 0 &&
+ ROUTE_UNUSABLE(&inp->inp_route)) {
+ struct sockaddr_in to;
+ struct sockaddr_in from;
+
+ ROUTE_RELEASE(&inp->inp_route);
+
+ bzero(&from, sizeof(struct sockaddr_in));
+ from.sin_family = AF_INET;
+ from.sin_len = sizeof(struct sockaddr_in);
+ from.sin_addr = laddr;
+
+ bzero(&to, sizeof(struct sockaddr_in));
+ to.sin_family = AF_INET;
+ to.sin_len = sizeof(struct sockaddr_in);
+ to.sin_addr = faddr;
+
+ inp->inp_route.ro_dst.sa_family = AF_INET;
+ inp->inp_route.ro_dst.sa_len = sizeof(struct sockaddr_in);
+ ((struct sockaddr_in *)(void *)&inp->inp_route.ro_dst)->sin_addr =
+ faddr;
+
+ rtalloc_scoped(&inp->inp_route, ipoa.ipoa_boundif);
+
+ inp_update_necp_policy(inp, (struct sockaddr *)&from,
+ (struct sockaddr *)&to, ipoa.ipoa_boundif);
+ inp->inp_policyresult.results.qos_marking_gencount = 0;
+ }
+
if (!necp_socket_is_allowed_to_send_recv_v4(inp, lport, fport,
&laddr, &faddr, NULL, &policy_id, &route_rule_id)) {
error = EHOSTUNREACH;
}
necp_mark_packet_from_socket(m, inp, policy_id, route_rule_id);
+
+ if (net_qos_policy_restricted != 0) {
+ necp_socket_update_qos_marking(inp,
+ inp->inp_route.ro_rt, NULL, route_rule_id);
+ }
}
#endif /* NECP */
+ if ((so->so_flags1 & SOF1_QOSMARKING_ALLOWED))
+ ipoa.ipoa_flags |= IPOAF_QOSMARKING_ALLOWED;
#if IPSEC
if (inp->inp_sp != NULL && ipsec_setsocket(m, inp->inp_socket) != 0) {
/* Copy the cached route and take an extra reference */
inp_route_copyout(inp, &ro);
- set_packet_service_class(m, so, msc, 0);
+ set_packet_service_class(m, so, sotc, 0);
m->m_pkthdr.pkt_flowsrc = FLOWSRC_INPCB;
m->m_pkthdr.pkt_flowid = inp->inp_flowhash;
m->m_pkthdr.pkt_proto = IPPROTO_UDP;
if (flowadv && (adv->code == FADV_FLOW_CONTROLLED ||
adv->code == FADV_SUSPENDED)) {
- /* return a hint to the application that
+ /*
+ * return a hint to the application that
* the packet has been dropped
*/
error = ENOBUFS;
space_p = &udp_sendspace;
break;
default:
- return EINVAL;
+ return (EINVAL);
}
- error = sysctl_io_number(req, *space_p, sizeof (u_int32_t),
+ error = sysctl_io_number(req, *space_p, sizeof (u_int32_t),
&new_value, &changed);
- if (changed) {
- if (new_value > 0 && new_value <= sb_effective_max)
- *space_p = new_value;
- else
- error = ERANGE;
- }
- return (error);
+ if (changed) {
+ if (new_value > 0 && new_value <= sb_effective_max)
+ *space_p = new_value;
+ else
+ error = ERANGE;
+ }
+ return (error);
}
SYSCTL_PROC(_net_inet_udp, UDPCTL_RECVSPACE, recvspace,
- CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED, &udp_recvspace, 0,
- &sysctl_udp_sospace, "IU", "Maximum incoming UDP datagram size");
+ CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED, &udp_recvspace, 0,
+ &sysctl_udp_sospace, "IU", "Maximum incoming UDP datagram size");
SYSCTL_PROC(_net_inet_udp, UDPCTL_MAXDGRAM, maxdgram,
- CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED, &udp_sendspace, 0,
- &sysctl_udp_sospace, "IU", "Maximum outgoing UDP datagram size");
+ CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED, &udp_sendspace, 0,
+ &sysctl_udp_sospace, "IU", "Maximum outgoing UDP datagram size");
static int
udp_abort(struct socket *so)
inp = sotoinpcb(so);
if (inp != NULL) {
- panic ("%s so=%p inp=%p\n", __func__, so, inp);
+ panic("%s so=%p inp=%p\n", __func__, so, inp);
/* NOTREACHED */
}
error = in_pcballoc(so, &udbinfo, p);
}
int
-udp_connectx_common(struct socket *so, int af,
- struct sockaddr_list **src_sl, struct sockaddr_list **dst_sl,
+udp_connectx_common(struct socket *so, int af, struct sockaddr *src, struct sockaddr *dst,
struct proc *p, uint32_t ifscope, sae_associd_t aid, sae_connid_t *pcid,
uint32_t flags, void *arg, uint32_t arglen,
struct uio *uio, user_ssize_t *bytes_written)
{
#pragma unused(aid, flags, arg, arglen)
- struct sockaddr_entry *src_se = NULL, *dst_se = NULL;
struct inpcb *inp = sotoinpcb(so);
int error;
user_ssize_t datalen = 0;
if (inp == NULL)
return (EINVAL);
- VERIFY(dst_sl != NULL);
-
- /* select source (if specified) and destination addresses */
- error = in_selectaddrs(af, src_sl, &src_se, dst_sl, &dst_se);
- if (error != 0)
- return (error);
-
- VERIFY(*dst_sl != NULL && dst_se != NULL);
- VERIFY(src_se == NULL || *src_sl != NULL);
- VERIFY(dst_se->se_addr->sa_family == af);
- VERIFY(src_se == NULL || src_se->se_addr->sa_family == af);
+ VERIFY(dst != NULL);
#if NECP
- inp_update_necp_policy(inp, src_se ? src_se->se_addr : NULL,
- dst_se ? dst_se->se_addr : NULL, ifscope);
+ inp_update_necp_policy(inp, src, dst, ifscope);
#endif /* NECP */
-
+
/* bind socket to the specified interface, if requested */
if (ifscope != IFSCOPE_NONE &&
(error = inp_bindif(inp, ifscope, NULL)) != 0)
return (error);
/* if source address and/or port is specified, bind to it */
- if (src_se != NULL) {
- struct sockaddr *sa = src_se->se_addr;
- error = sobindlock(so, sa, 0); /* already locked */
+ if (src != NULL) {
+ error = sobindlock(so, src, 0); /* already locked */
if (error != 0)
return (error);
}
switch (af) {
case AF_INET:
- error = udp_connect(so, dst_se->se_addr, p);
+ error = udp_connect(so, dst, p);
break;
#if INET6
case AF_INET6:
- error = udp6_connect(so, dst_se->se_addr, p);
+ error = udp6_connect(so, dst, p);
break;
#endif /* INET6 */
default:
/*
* If there is data, copy it. DATA_IDEMPOTENT is ignored.
- * CONNECT_RESUME_ON_READ_WRITE is ignored.
+ * CONNECT_RESUME_ON_READ_WRITE is ignored.
*/
if (uio != NULL) {
socket_unlock(so, 0);
datalen = uio_resid(uio);
error = so->so_proto->pr_usrreqs->pru_sosend(so, NULL,
- (uio_t)uio, NULL, NULL, 0);
+ (uio_t)uio, NULL, NULL, 0);
socket_lock(so, 0);
/* If error returned is EMSGSIZE, for example, disconnect */
if (error == 0 || error == EWOULDBLOCK)
*bytes_written = datalen - uio_resid(uio);
else
- (void)so->so_proto->pr_usrreqs->pru_disconnectx(so,
+ (void) so->so_proto->pr_usrreqs->pru_disconnectx(so,
SAE_ASSOCID_ANY, SAE_CONNID_ANY);
/*
* mask the EWOULDBLOCK error so that the caller
}
static int
-udp_connectx(struct socket *so, struct sockaddr_list **src_sl,
- struct sockaddr_list **dst_sl, struct proc *p, uint32_t ifscope,
+udp_connectx(struct socket *so, struct sockaddr *src,
+ struct sockaddr *dst, struct proc *p, uint32_t ifscope,
sae_associd_t aid, sae_connid_t *pcid, uint32_t flags, void *arg,
uint32_t arglen, struct uio *uio, user_ssize_t *bytes_written)
{
- return (udp_connectx_common(so, AF_INET, src_sl, dst_sl,
+ return (udp_connectx_common(so, AF_INET, src, dst,
p, ifscope, aid, pcid, flags, arg, arglen, uio, bytes_written));
}
/*
* If this is a socket that does not want to wakeup the device
- * for it's traffic, the application might be waiting for
- * close to complete before going to sleep. Send a notification
+ * for it's traffic, the application might be waiting for
+ * close to complete before going to sleep. Send a notification
* for this kind of sockets
*/
if (so->so_options & SO_NOWAKEFROMSLEEP)
#if FLOW_DIVERT
if (necp_socket_should_use_flow_divert(inp)) {
/* Implicit connect */
- return (flow_divert_implicit_data_out(so, flags, m, addr, control, p));
+ return (flow_divert_implicit_data_out(so, flags, m, addr,
+ control, p));
}
#endif /* FLOW_DIVERT */
#endif /* NECP */
else
lr_saved = debug;
- if (refcount)
+ if (refcount) {
+ VERIFY(so->so_usecount > 0);
so->so_usecount--;
-
+ }
if (so->so_pcb == NULL) {
panic("%s: so=%p NO PCB! lr=%p lrh= %s\n", __func__,
so, lr_saved, solockhistory_nr(so));
}
}
lck_rw_done(ipi->ipi_lock);
-
- return;
}
static int
return (0);
}
-extern void
-udp_fill_keepalive_offload_frames(ifnet_t ifp,
- struct ifnet_keepalive_offload_frame *frames_array,
- u_int32_t frames_array_count, size_t frame_data_offset,
- u_int32_t *used_frames_count);
-
void
udp_fill_keepalive_offload_frames(ifnet_t ifp,
struct ifnet_keepalive_offload_frame *frames_array,
continue;
}
if ((inp->inp_vflag & INP_IPV4)) {
- if ((frame_data_offset + sizeof(struct udpiphdr) +
+ if ((frame_data_offset + sizeof(struct udpiphdr) +
inp->inp_keepalive_datalen) >
IFNET_KEEPALIVE_OFFLOAD_FRAME_DATA_SIZE) {
udp_unlock(so, 1, 0);
ip->ip_len = htons(sizeof(struct udpiphdr) +
(u_short)inp->inp_keepalive_datalen);
ip->ip_ttl = inp->inp_ip_ttl;
- ip->ip_tos = inp->inp_ip_tos;
+ ip->ip_tos |= (inp->inp_ip_tos & ~IPTOS_ECN_MASK);
ip->ip_src = inp->inp_laddr;
ip->ip_dst = inp->inp_faddr;
ip->ip_sum = in_cksum_hdr_opt(ip);
}
m->m_pkthdr.len = m->m_len;
ip6->ip6_flow = inp->inp_flow & IPV6_FLOWINFO_MASK;
+ ip6->ip6_flow = ip6->ip6_flow & ~IPV6_FLOW_ECN_MASK;
ip6->ip6_vfc &= ~IPV6_VERSION_MASK;
ip6->ip6_vfc |= IPV6_VERSION;
ip6->ip6_nxt = IPPROTO_UDP;