/*
- * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2020 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <sys/eventhandler.h>
#endif /* BSD_KERNEL_PRIVATE */
#endif /* KERNEL_PRIVATE */
+#if !KERNEL
+#include <TargetConditionals.h>
+#endif
typedef u_quad_t so_gen_t;
u_int64_t txpackets;
u_int64_t txbytes;
};
-
-#define MSG_PRI_0 0 /* TCP message priority, lowest */
-#define MSG_PRI_1 1
-#define MSG_PRI_2 2
-#define MSG_PRI_3 3 /* TCP message priority, highest */
-#define MSG_PRI_MAX MSG_PRI_3
-#define MSG_PRI_MIN MSG_PRI_0
-#define MSG_PRI_COUNT 4
-#define MSG_PRI_DEFAULT MSG_PRI_1
#endif /* PRIVATE */
#ifdef KERNEL_PRIVATE
-/* State for TCP message send or receive */
-struct msg_priq {
- struct mbuf *msgq_head; /* first mbuf in the queue */
- struct mbuf *msgq_tail; /* last mbuf in the queue */
- struct mbuf *msgq_lastmsg; /* last message in the queue */
- u_int32_t msgq_flags; /* flags per priority queue */
-#define MSGQ_MSG_NOTDONE 0x1 /* set when EOR of a msg is not seen */
- u_int32_t msgq_bytes; /* data bytes in this queue */
-};
-
-struct msg_state {
- struct msg_priq msg_priq[MSG_PRI_COUNT]; /* priority queues */
- u_int32_t msg_serial_bytes; /* bytes moved to serial queue */
- u_int32_t msg_uno_bytes; /* out-of-order chars in rcv buffer */
-};
-
-/* mbuf flag used to indicate out of order data received */
-#define M_UNORDERED_DATA M_PROTO1
-
/*
* Kernel structure per socket.
* Contains send and receive buffer queues,
#define SB_NOCOMPRESS 0x1000 /* do not compress socket buffer */
#define SB_SNDBYTE_CNT 0x2000 /* keep track of snd bytes per interface */
#define SB_UPCALL_LOCK 0x4000 /* Keep socket locked when doing the upcall */
+#define SB_LIMITED 0x8000 /* Socket buffer size limited */
+ /* XXX Note that Unix domain socket's sb_flags is defined as short */
caddr_t so_tpcb; /* Misc. protocol control block, used
* by some kexts */
- void (*so_event)(struct socket *, void *, u_int32_t);
+ void (*so_event)(struct socket *, void *, long);
void *so_eventarg; /* Arg for above */
kauth_cred_t so_cred; /* cred of who opened the socket */
/* NB: generation count must not be first; easiest to make it last. */
so_gen_t so_gencnt; /* generation count */
- TAILQ_HEAD(, eventqelt) so_evlist;
STAILQ_ENTRY(socket) so_cache_ent; /* socache entry */
caddr_t so_saved_pcb; /* Saved pcb when cacheing */
u_int32_t cache_timestamp; /* time socket was cached */
pid_t last_pid; /* pid of most recent accessor */
u_int64_t last_upid; /* upid of most recent accessor */
- struct mbuf *so_temp; /* Holding area for outbound frags */
- /* Plug-in support - make the socket interface overridable */
- struct mbuf *so_tail;
struct socket_filter_entry *so_filt; /* NKE hook */
u_int32_t so_flags; /* Flags */
#define SOF_NOSIGPIPE 0x00000001
#define SOF_NOTSENT_LOWAT 0x00080000 /* A different lowat on not sent
* data has been set */
#define SOF_KNOTE 0x00100000 /* socket is on the EV_SOCK klist */
-#define SOF_USELRO 0x00200000 /* TCP must use LRO on these sockets */
-#define SOF_ENABLE_MSGS 0x00400000 /* TCP must enable message delivery */
#define SOF_FLOW_DIVERT 0x00800000 /* Flow Divert is enabled */
#define SOF_MP_SUBFLOW 0x01000000 /* is a multipath subflow socket */
#define SOF_MP_SEC_SUBFLOW 0x04000000 /* Set up secondary flow */
#define SOF_CONTENT_FILTER 0x20000000 /* Content filter enabled */
uint32_t so_upcallusecount; /* number of upcalls in progress */
- int so_usecount; /* refcounting of socket use */;
+ int so_usecount; /* refcounting of socket use */
int so_retaincnt;
- u_int32_t so_filteruse; /* usecount for the socket filters */
- u_int16_t so_traffic_class;
+ uint32_t so_filteruse; /* usecount for the socket filters */
+ uint16_t so_traffic_class;
int8_t so_netsvctype;
- u_int8_t so_restrictions;
+ uint8_t so_restrictions;
thread_t so_send_filt_thread;
/* for debug pruposes */
struct data_stats so_tc_stats[SO_TC_STATS_MAX];
struct klist so_klist; /* klist for EV_SOCK events */
- struct msg_state *so_msg_state; /* unordered snd/rcv state */
struct flow_divert_pcb *so_fd_pcb; /* Flow Divert control block */
#if CONTENT_FILTER
pid_t e_pid; /* pid of the effective owner */
u_int64_t e_upid; /* upid of the effective owner */
+#if XNU_TARGET_OS_OSX
+ pid_t so_rpid; /* pid of the responsible process */
+#endif /* XNU_TARGET_OS_OSX */
uuid_t last_uuid; /* uuid of most recent accessor */
uuid_t e_uuid; /* uuid of effective owner */
uuid_t so_vuuid; /* UUID of the Voucher originator */
+#if XNU_TARGET_OS_OSX
+ uuid_t so_ruuid; /* UUID of the responsible process */
+#endif /* XNU_TARGET_OS_OSX */
int32_t so_policy_gencnt; /* UUID policy gencnt */
#define SOF1_PRECONNECT_DATA 0x00000020 /* request for preconnect data */
#define SOF1_EXTEND_BK_IDLE_WANTED 0x00000040 /* option set */
#define SOF1_EXTEND_BK_IDLE_INPROG 0x00000080 /* socket */
-#define SOF1_CACHED_IN_SOCK_LAYER 0x00000100 /* bundled with inpcb and
- * tcpcb */
+#define SOF1_CACHED_IN_SOCK_LAYER 0x00000100 /* bundled with inpcb and tcpcb */
#define SOF1_TFO_REWIND 0x00000200 /* rewind mptcp meta data */
#define SOF1_CELLFALLBACK 0x00000400 /* Initiated by cell fallback */
#define SOF1_QOSMARKING_ALLOWED 0x00000800 /* policy allows DSCP map */
#define SOF1_IN_KERNEL_SOCKET 0x00100000 /* Socket created in kernel via KPI */
#define SOF1_CONNECT_COUNTED 0x00200000 /* connect() call was counted */
#define SOF1_DNS_COUNTED 0x00400000 /* socket counted to send DNS queries */
+#define SOF1_MPKL_SEND_INFO 0x00800000 /* SO_MPKL_SEND_INFO option is set */
+#define SOF1_INBOUND 0x01000000 /* Created via a passive listener */
+#define SOF1_WANT_KEV_SOCK_CLOSED 0x02000000 /* Want generation of KEV_SOCKET_CLOSED event */
+#define SOF1_FLOW_DIVERT_SKIP 0x04000000 /* Flow divert already declined to handle the socket */
u_int64_t so_extended_bk_start;
+
+ u_int8_t so_log_seqn; /* Multi-layer Packet Logging rolling sequence number */
+ uuid_t so_mpkl_send_uuid;
+ uint8_t so_mpkl_send_proto;
};
/* Control message accessor in mbufs */
uid_t so_uid; /* XXX */
};
-#if !CONFIG_EMBEDDED
+#if XNU_TARGET_OS_OSX || KERNEL || !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
struct xsocket64 {
u_int32_t xso_len; /* length of this structure */
u_int64_t xso_so; /* makes a convenient handle */
struct xsockbuf so_snd;
uid_t so_uid; /* XXX */
};
-#endif /* !CONFIG_EMBEDDED */
+#endif /* XNU_TARGET_OS_OSX || KERNEL || !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */
#ifdef PRIVATE
#define XSO_SOCKET 0x001
#define SO_FILT_HINT_MUSTRST 0x00020000 /* must send RST and close */
#define SO_FILT_HINT_MPCANTRCVMORE 0x00040000 /* MPTCP DFIN Received */
#define SO_FILT_HINT_NOTIFY_ACK 0x00080000 /* Notify Acknowledgement */
+#define SO_FILT_HINT_MP_SUB_ERROR 0x00100000 /* Error happend on subflow */
#define SO_FILT_HINT_BITS \
"\020\1LOCKED\2CONNRESET\3CANTRCVMORE\4CANTSENDMORE\5TIMEOUT" \
"\6NOSRCADDR\7IFDENIED\10SUSPEND\11RESUME\12KEEPALIVE\13AWTIMO" \
"\14ARTIMO\15CONNECTED\16DISCONNECTED\17CONNINFO_UPDATED" \
- "\20MPFAILOVER\21MPSTATUS\22MUSTRST\23MPCANTRCVMORE\24NOTIFYACK"
+ "\20MPFAILOVER\21MPSTATUS\22MUSTRST\23MPCANTRCVMORE\24NOTIFYACK"\
+ "\25MPSUBERROR"
/* Mask for hints that have corresponding kqueue events */
#define SO_FILT_HINT_EV \
uuid_t spi_uuid;
uuid_t spi_euuid;
int spi_delegated;
+ char spi_proc_name[MAXCOMLEN + 1];
+ char spi_e_proc_name[MAXCOMLEN + 1];
};
extern u_int32_t sb_max;
extern int sorestrictrecv;
extern int sorestrictsend;
extern int somaxconn;
-extern uint32_t tcp_do_autosendbuf;
extern uint32_t tcp_autosndbuf_max;
extern uint32_t tcp_autosndbuf_inc;
extern u_int32_t sotcdb;
extern struct soextbkidlestat soextbkidlestat;
-struct net_qos_dscp_map {
- u_int8_t sotc_to_dscp[SO_TC_MAX];
- u_int8_t netsvctype_to_dscp[_NET_SERVICE_TYPE_COUNT];
-};
-
#endif /* BSD_KERNEL_PRIVATE */
struct mbuf;
struct mbuf *m0, struct mbuf *control, int *error_out);
extern int sbappendchain(struct sockbuf *sb, struct mbuf *m, int space);
extern int sbappendrecord(struct sockbuf *sb, struct mbuf *m0);
+extern int sbappendrecord_nodrop(struct sockbuf *sb, struct mbuf *m0);
extern void sbflush(struct sockbuf *sb);
extern int sbspace(struct sockbuf *sb);
extern int soabort(struct socket *so);
const struct sockaddr *from);
extern int sopoll(struct socket *so, int events, struct ucred *cred, void *wql);
extern int sooptcopyin(struct sockopt *sopt, void *data, size_t len,
- size_t minlen);
-extern int sooptcopyout(struct sockopt *sopt, void *data, size_t len);
-extern int soopt_cred_check(struct socket *so, int priv, boolean_t allow_root);
+ size_t minlen)
+__attribute__ ((warn_unused_result));
+extern int sooptcopyout(struct sockopt *sopt, void *data, size_t len)
+__attribute__ ((warn_unused_result));
+extern int soopt_cred_check(struct socket *so, int priv, boolean_t allow_root,
+ boolean_t ignore_delegate);
extern int soreceive(struct socket *so, struct sockaddr **paddr,
struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
-extern int soreserve(struct socket *so, u_int32_t sndcc, u_int32_t rcvcc);
+extern int soreserve(struct socket *so, uint32_t sndcc, uint32_t rcvcc);
extern void soreserve_preconnect(struct socket *so, unsigned int pre_cc);
extern void sorwakeup(struct socket *so);
extern int sosend(struct socket *so, struct sockaddr *addr, struct uio *uio,
int flags);
extern int soreceive_list(struct socket *so, struct recv_msg_elem *msgarray,
u_int msgcnt, int *flags);
-extern void sonullevent(struct socket *so, void *arg, uint32_t hint);
+extern void sonullevent(struct socket *so, void *arg, long hint);
extern struct mbuf *sbconcat_mbufs(struct sockbuf *sb, struct sockaddr *asa, struct mbuf *m0,
struct mbuf *control);
extern void socketinit(void);
extern struct sockaddr *dup_sockaddr(struct sockaddr *sa, int canwait);
extern int getsock(struct filedesc *fdp, int fd, struct file **fpp);
-extern int sockargs(struct mbuf **mp, user_addr_t data, int buflen, int type);
+extern int sockargs(struct mbuf **mp, user_addr_t data, socklen_t buflen, int type);
extern void get_sockev_state(struct socket *, u_int32_t *);
extern void so_update_last_owner_locked(struct socket *, struct proc *);
extern void so_update_policy(struct socket *);
extern void so_release_accept_list(struct socket *);
extern int sbappend(struct sockbuf *sb, struct mbuf *m);
+extern int sbappend_nodrop(struct sockbuf *sb, struct mbuf *m);
extern int sbappendstream(struct sockbuf *sb, struct mbuf *m);
extern int sbappendcontrol(struct sockbuf *sb, struct mbuf *m0,
struct mbuf *control, int *error_out);
-extern int sbappendmsgstream_rcv(struct sockbuf *sb, struct mbuf *m,
- uint32_t seqnum, int flags);
-extern int sbappendstream_rcvdemux(struct socket *so, struct mbuf *m,
- uint32_t seqnum, int flags);
+extern int sbappendstream_rcvdemux(struct socket *so, struct mbuf *m);
#if MPTCP
extern int sbappendmptcpstream_rcv(struct sockbuf *sb, struct mbuf *m);
#endif /* MPTCP */
-extern int sbappendmsg_snd(struct sockbuf *sb, struct mbuf *m);
-extern void sbpull_unordered_data(struct socket *, int32_t, int32_t);
extern void sbcheck(struct sockbuf *sb);
extern void sblastmbufchk(struct sockbuf *, const char *);
extern void sblastrecordchk(struct sockbuf *, const char *);
int level, struct mbuf **m);
extern void sbdrop(struct sockbuf *sb, int len);
extern void sbdroprecord(struct sockbuf *sb);
-extern int sbinsertoob(struct sockbuf *sb, struct mbuf *m0);
extern void sbrelease(struct sockbuf *sb);
extern int sbreserve(struct sockbuf *sb, u_int32_t cc);
extern void sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb);
sae_connid_t *, uint32_t, void *, u_int32_t, uio_t, user_ssize_t *);
extern int sodisconnectx(struct socket *so, sae_associd_t, sae_connid_t);
extern int sodisconnectxlocked(struct socket *so, sae_associd_t, sae_connid_t);
-extern void soevupcall(struct socket *, u_int32_t);
+extern void soevupcall(struct socket *so, long hint);
/* flags for socreate_internal */
-#define SOCF_ASYNC 0x1 /* non-blocking socket */
+#define SOCF_MPTCP 0x1 /* MPTCP-subflow */
extern int socreate_internal(int dom, struct socket **aso, int type, int proto,
struct proc *, uint32_t, struct proc *);
extern int socreate(int dom, struct socket **aso, int type, int proto);
extern void soclearfastopen(struct socket *so);
extern int solisten(struct socket *so, int backlog);
extern struct socket *sodropablereq(struct socket *head);
+extern lck_mtx_t *socket_getlock(struct socket *so, int flags);
extern void socket_lock(struct socket *so, int refcount);
extern void socket_lock_assert_owned(struct socket *so);
extern int socket_try_lock(struct socket *so);
extern void soevent(struct socket *so, long hint);
extern void sorflush(struct socket *so);
extern void sowflush(struct socket *so);
-extern void sowakeup(struct socket *so, struct sockbuf *sb);
+extern void sowakeup(struct socket *so, struct sockbuf *sb, struct socket *so2);
extern int soioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p);
extern int sogetoptlock(struct socket *so, struct sockopt *sopt, int);
extern int sosetoptlock(struct socket *so, struct sockopt *sopt, int);
extern int soshutdownlock(struct socket *so, int how);
extern int soshutdownlock_final(struct socket *so, int how);
extern void sotoxsocket(struct socket *so, struct xsocket *xso);
-#if !CONFIG_EMBEDDED
+#if XNU_TARGET_OS_OSX
extern void sotoxsocket64(struct socket *so, struct xsocket64 *xso);
-#endif /* !CONFIG_EMBEDDED */
+#endif /* XNU_TARGET_OS_OSX */
extern int sosendallatonce(struct socket *so);
extern int soreadable(struct socket *so);
extern int sowriteable(struct socket *so);
extern void sowwakeup(struct socket *so);
extern int sosendcheck(struct socket *, struct sockaddr *, user_ssize_t,
- int32_t, int32_t, int, int *, struct mbuf *);
+ int32_t, int32_t, int, int *);
extern int soo_ioctl(struct fileproc *, u_long, caddr_t, vfs_context_t);
extern int soo_stat(struct socket *, void *, int);
extern int soo_select(struct fileproc *, int, void *, vfs_context_t);
-extern int soo_kqfilter(struct fileproc *, struct knote *,
- struct kevent_internal_s *kev, vfs_context_t);
+extern int soo_kqfilter(struct fileproc *, struct knote *, struct kevent_qos_s *);
/* Service class flags used for setting service class on a packet */
#define PKT_SCF_IPV6 0x00000001 /* IPv6 packet */
mbuf_svc_class_t, u_int32_t);
extern void so_tc_update_stats(struct mbuf *, struct socket *,
mbuf_svc_class_t);
+extern int so_tos_from_control(struct mbuf *);
extern int so_tc_from_control(struct mbuf *, int *);
extern mbuf_svc_class_t so_tc2msc(int);
extern int so_svc2tc(mbuf_svc_class_t);
extern u_int8_t tcp_cansbgrow(struct sockbuf *sb);
-extern int tcp_get_msg_priority(struct mbuf *, uint32_t *);
extern void set_tcp_stream_priority(struct socket *so);
extern int so_set_net_service_type(struct socket *, int);
extern int so_get_opportunistic(struct socket *);
extern int so_set_recv_anyif(struct socket *, int);
extern int so_get_recv_anyif(struct socket *);
-extern int so_set_effective_pid(struct socket *, int, struct proc *);
-extern int so_set_effective_uuid(struct socket *, uuid_t, struct proc *);
+extern int so_set_effective_pid(struct socket *so, int epid, struct proc *p, boolean_t check_cred);
+extern int so_set_effective_uuid(struct socket *so, uuid_t euuid, struct proc *p, boolean_t check_cred);
extern int so_set_restrictions(struct socket *, uint32_t);
extern uint32_t so_get_restrictions(struct socket *);
extern void socket_tclass_init(void);
extern int so_set_tcdbg(struct socket *, struct so_tcdbg *);
extern int sogetopt_tcdbg(struct socket *, struct sockopt *);
#endif /* (DEVELOPMENT || DEBUG) */
-extern void so_set_lro(struct socket *, int);
extern int so_isdstlocal(struct socket *);
extern void so_recv_data_stat(struct socket *, struct mbuf *, size_t);
extern void so_inc_recv_data_stat(struct socket *, size_t, size_t, uint32_t);
extern int so_wait_for_if_feedback(struct socket *);
-extern int msgq_sbspace(struct socket *so, struct mbuf *control);
extern int soopt_getm(struct sockopt *sopt, struct mbuf **mp);
extern int soopt_mcopyin(struct sockopt *sopt, struct mbuf *m);
extern int soopt_mcopyout(struct sockopt *sopt, struct mbuf *m);
extern void mptcp_preproc_sbdrop(struct socket *, struct mbuf *, unsigned int);
extern void mptcp_postproc_sbdrop(struct mbuf *, u_int64_t, u_int32_t,
u_int32_t);
-extern int mptcp_adj_rmap(struct socket *so, struct mbuf *m, int off,
- uint64_t dsn, uint32_t rseq, uint16_t dlen);
extern void netpolicy_post_msg(uint32_t, struct netpolicy_event_data *,
uint32_t);
-extern void socket_post_kev_msg(uint32_t, struct kev_socket_event_data *,
- uint32_t);
-extern void socket_post_kev_msg_closed(struct socket *);
-/*
- * Socket operation routines.
- * These routines are called by the routines in
- * sys_socket.c or from a system process, and
- * implement the semantics of socket operations by
- * switching out to the protocol specific routines.
- */
-extern void postevent(struct socket *, struct sockbuf *, int);
-extern void evsofree(struct socket *);
extern int tcp_notsent_lowat_check(struct socket *so);