X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/d1ecb069dfe24481e4a83f44cb5217a2b06746d7..db6096698656d32db7df630594bd9617ee54f828:/bsd/sys/socketvar.h diff --git a/bsd/sys/socketvar.h b/bsd/sys/socketvar.h index 804984822..06e6f5c41 100644 --- a/bsd/sys/socketvar.h +++ b/bsd/sys/socketvar.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2009 Apple Inc. All rights reserved. + * Copyright (c) 2000-2012 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -108,6 +108,17 @@ extern char netio[], netcon[], netcls[]; typedef u_quad_t so_gen_t; +#ifdef PRIVATE +#define SO_TC_STATS_MAX 4 + +struct data_stats { + u_int64_t rxpackets; + u_int64_t rxbytes; + u_int64_t txpackets; + u_int64_t txbytes; +}; +#endif /* PRIVATE */ + #ifdef KERNEL_PRIVATE #ifndef __APPLE__ /* We don't support BSD style socket filters */ @@ -117,10 +128,10 @@ struct accept_filter; struct socket { int so_zone; /* zone we were allocated from */ short so_type; /* generic type, see socket.h */ - short so_options; /* from socket call, see socket.h */ + u_int32_t so_options; /* from socket call, see socket.h */ short so_linger; /* time to linger while closing */ short so_state; /* internal state flags SS_*, below */ - void *so_pcb; /* protocol control block */ + void *so_pcb; /* protocol control block */ struct protosw *so_proto; /* protocol handle */ /* * Variables for connection queueing. @@ -168,7 +179,7 @@ struct socket { struct selinfo sb_sel; /* process selecting read/write */ short sb_flags; /* flags, see below */ struct timeval sb_timeo; /* timeout for read/write */ - u_int sb_maxused; /* max char count ever used in sockbuf */ + u_int32_t sb_idealsize; /* Ideal size for the sb based on bandwidth and delay */ void *reserved1[4]; /* for future use */ } so_rcv, so_snd; #define SB_MAX (8192*1024) /* default for max chars in sockbuf */ @@ -188,14 +199,16 @@ struct socket { #define SB_NOTIFY (SB_WAIT|SB_SEL|SB_ASYNC) #define SB_DROP 0x400 /* does not accept any more data */ #define SB_UNIX 0x800 /* UNIX domain socket buffer */ +#define SB_AUTOSIZE 0x1000 /* automatically size socket buffer */ +#define SB_TRIM 0x2000 /* Trim the socket buffer */ #define SB_RECV 0x8000 /* this is rcv sb */ - caddr_t so_tpcb; /* Wisc. protocol control block - XXX unused? */ + caddr_t so_tpcb; /* Wisc. protocol control block, used by some kexts */ #endif void (*so_upcall)(struct socket *so, caddr_t arg, int waitf); caddr_t so_upcallarg; /* Arg for above */ - uid_t so_uid; /* who opened the socket */ + 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 */ #ifndef __APPLE__ @@ -220,9 +233,8 @@ struct socket { #define SOF_NOSIGPIPE 0x1 #define SOF_NOADDRAVAIL 0x2 /* EADDRNOTAVAIL if src addr is gone */ #define SOF_PCBCLEARING 0x4 /* pru_disconnect done; don't call pru_detach */ -#define SOF_DEFUNCT 0x8 /* accepted socket marked as inactive */ +#define SOF_DEFUNCT 0x8 /* socket marked as inactive */ #define SOF_CLOSEWAIT 0x10 /* blocked in close awaiting some events */ -#define SOF_UPCALLINUSE 0x20 /* socket upcall is currently in progress */ #define SOF_REUSESHAREUID 0x40 /* Allows SO_REUSEADDR/SO_REUSEPORT for multiple so_uid */ #define SOF_MULTIPAGES 0x80 /* jumbo clusters may be used for sosend */ #define SOF_ABORTED 0x100 /* soabort was already called once on the socket */ @@ -233,6 +245,15 @@ struct socket { #define SOF_UPCALLCLOSEWAIT 0x800 /* block on close until an upcall returns */ #define SOF_BINDRANDOMPORT 0x1000 /* Request a randomized port number for the bind */ #define SOF_NPX_SETOPTSHUT 0x2000 /* Non POSIX extension to allow setsockopt(2) after shut down */ +#define SOF_RECV_TRAFFIC_CLASS 0x4000 /* Receive traffic class as ancillary data */ +#define SOF_NODEFUNCT 0x8000 /* socket cannot be defunct'd */ +#define SOF_PRIVILEGED_TRAFFIC_CLASS 0x10000 /* traffic class is privileged */ +#define SOF_SUSPENDED 0x20000 /* interface output queue is suspended */ +#define SOF_INCOMP_INPROGRESS 0x40000 /* incomp socket still being processed */ +#define SOF_NOTSENT_LOWAT 0x80000 /* A different lowat on not sent data has been set */ +#define SOF_KNOTE 0x100000 /* socket is on the EV_SOCK klist */ +#define SOF_USELRO 0x200000 /* TCP must use LRO on these sockets */ + uint32_t so_upcallusecount; /* number of upcalls in progress */ int so_usecount; /* refcounting of socket use */; int so_retaincnt; u_int32_t so_filteruse; /* usecount for the socket filters */ @@ -252,7 +273,36 @@ struct socket { struct label *so_label; /* MAC label for socket */ struct label *so_peerlabel; /* cached MAC label for socket peer */ thread_t so_background_thread; /* thread that marked this socket background */ + int so_traffic_class; + + // last process to interact with this socket + u_int64_t last_upid; + pid_t last_pid; + struct data_stats so_tc_stats[SO_TC_STATS_MAX]; + struct klist so_klist; /* klist for EV_SOCK events */ }; + +/* Control message accessor in mbufs */ + +#define _MIN_NXT_CMSGHDR_PTR(cmsg) \ + ((char *)(cmsg) + \ + __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len) + \ + __DARWIN_ALIGN32(sizeof(struct cmsghdr))) + +#define M_FIRST_CMSGHDR(m) \ + ((char *)(m) != (char *)0L && (size_t)(m)->m_len >= sizeof(struct cmsghdr) && \ + (socklen_t)(m)->m_len >= __DARWIN_ALIGN32(((struct cmsghdr *)(void *)(m)->m_data)->cmsg_len) ?\ + (struct cmsghdr *)(void *)(m)->m_data : \ + (struct cmsghdr *)0L) + +#define M_NXT_CMSGHDR(m, cmsg) \ + ((char *)(cmsg) == (char *)0L ? M_FIRST_CMSGHDR(m) : \ + _MIN_NXT_CMSGHDR_PTR(cmsg) > ((char *)(m)->m_data) + (m)->m_len || \ + _MIN_NXT_CMSGHDR_PTR(cmsg) < (char *)(m)->m_data ? \ + (struct cmsghdr *)0L /* NULL */ : \ + (struct cmsghdr *)(void *)((unsigned char *)(cmsg) + \ + __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len))) + #endif /* KERNEL_PRIVATE */ /* @@ -275,6 +325,7 @@ struct socket { #define SS_ISDISCONNECTED 0x2000 /* socket disconnected from peer */ #define SS_DRAINING 0x4000 /* close waiting for blocked system calls to drain */ +#define SS_DEFUNCT 0x8000 /* has been fully defunct'd */ #if defined(__LP64__) #define _XSOCKET_PTR(x) u_int32_t @@ -282,16 +333,22 @@ struct socket { #define _XSOCKET_PTR(x) x #endif +#ifdef PRIVATE +/* Flags returned in data field for EVFILT_SOCK events. */ +#define SOCKEV_CONNECTED 0x00000001 /* connected */ +#define SOCKEV_DISCONNECTED 0x00000002 /* disconnected */ +#endif /* PRIVATE */ + #pragma pack(4) struct xsockbuf { - u_int32_t sb_cc; - u_int32_t sb_hiwat; - u_int32_t sb_mbcnt; - u_int32_t sb_mbmax; - int32_t sb_lowat; - short sb_flags; - short sb_timeo; + u_int32_t sb_cc; + u_int32_t sb_hiwat; + u_int32_t sb_mbcnt; + u_int32_t sb_mbmax; + int32_t sb_lowat; + short sb_flags; + short sb_timeo; }; /* @@ -345,6 +402,56 @@ struct xsocket64 { #endif /* !CONFIG_EMBEDDED */ +#ifdef PRIVATE + +#define XSO_SOCKET 0x001 +#define XSO_RCVBUF 0x002 +#define XSO_SNDBUF 0x004 +#define XSO_STATS 0x008 +#define XSO_INPCB 0x010 +#define XSO_TCPCB 0x020 + +struct xsocket_n { + u_int32_t xso_len; /* length of this structure */ + u_int32_t xso_kind; /* XSO_SOCKET */ + u_int64_t xso_so; /* makes a convenient handle */ + short so_type; + u_int32_t so_options; + short so_linger; + short so_state; + u_int64_t so_pcb; /* another convenient handle */ + int xso_protocol; + int xso_family; + short so_qlen; + short so_incqlen; + short so_qlimit; + short so_timeo; + u_short so_error; + pid_t so_pgid; + u_int32_t so_oobmark; + uid_t so_uid; /* XXX */ +}; + +struct xsockbuf_n { + u_int32_t xsb_len; /* length of this structure */ + u_int32_t xsb_kind; /* XSO_RCVBUF or XSO_SNDBUF */ + u_int32_t sb_cc; + u_int32_t sb_hiwat; + u_int32_t sb_mbcnt; + u_int32_t sb_mbmax; + int32_t sb_lowat; + short sb_flags; + short sb_timeo; +}; + +struct xsockstat_n { + u_int32_t xst_len; /* length of this structure */ + u_int32_t xst_kind; /* XSO_STATS */ + struct data_stats xst_tc_stats[SO_TC_STATS_MAX]; +}; + +#endif /* PRIVATE */ + #pragma pack() #ifdef KERNEL_PRIVATE @@ -393,8 +500,25 @@ struct kextcb { #define sotokextcb(so) (so ? so->so_ext : 0) #ifdef KERNEL - -#define SO_FILT_HINT_LOCKED 0x1 +#include + +/* Hints for socket event processing */ +#define SO_FILT_HINT_LOCKED 0x00000001 /* socket is already locked */ +#define SO_FILT_HINT_CONNRESET 0x00000002 /* Reset is received */ +#define SO_FILT_HINT_CANTRCVMORE 0x00000004 /* No more data to read */ +#define SO_FILT_HINT_CANTSENDMORE 0x00000008 /* Can't write more data */ +#define SO_FILT_HINT_TIMEOUT 0x00000010 /* timeout */ +#define SO_FILT_HINT_NOSRCADDR 0x00000020 /* No src address available */ +#define SO_FILT_HINT_IFDENIED 0x00000040 /* interface denied connection */ +#define SO_FILT_HINT_SUSPEND 0x00000080 /* output queue suspended */ +#define SO_FILT_HINT_RESUME 0x00000100 /* output queue resumed */ +#define SO_FILT_HINT_KEEPALIVE 0x00000200 /* TCP Keepalive received */ + +#define SO_FILT_HINT_EV (SO_FILT_HINT_CONNRESET | \ + SO_FILT_HINT_CANTRCVMORE | SO_FILT_HINT_CANTSENDMORE | \ + SO_FILT_HINT_TIMEOUT | SO_FILT_HINT_NOSRCADDR | \ + SO_FILT_HINT_IFDENIED | SO_FILT_HINT_SUSPEND | \ + SO_FILT_HINT_RESUME | SO_FILT_HINT_KEEPALIVE) /* * Argument structure for sosetopt et seq. This is in the KERNEL @@ -431,6 +555,8 @@ extern so_gen_t so_gencnt; extern int socket_debug; extern int sosendjcl; extern int sosendjcl_ignore_capab; +extern int sodefunctlog; +extern int sothrottlelog; extern int somaxconn; struct file; @@ -441,6 +567,7 @@ struct stat; struct ucred; struct uio; struct knote; +struct so_tcdbg; #define SBLASTRECORDCHK(sb, s) \ if (socket_debug) sblastrecordchk(sb, s); @@ -455,6 +582,33 @@ struct knote; } \ } +#define SB_MB_CHECK(sb) do { \ + if (((sb)->sb_mb != NULL && \ + (sb)->sb_cc == 0) || \ + ((sb)->sb_mb == NULL && \ + (sb)->sb_cc > 0)) \ + panic("corrupt so_rcv: sb_mb %p sb_cc %d\n", \ + (sb)->sb_mb, (sb)->sb_cc); \ +} while(0) + + +#define SODEFUNCTLOG(x) do { if (sodefunctlog) printf x; } while (0) + +#define SOTHROTTLELOG(x) do { if (sothrottlelog) printf x; } while (0) + +/* + * For debugging traffic class behaviors + */ +#define SOTCDB_NO_DSCP 0x01 /* Do not set DSCP code in IP header */ +#define SOTCDB_NO_MTC 0x02 /* Do not set the mbuf traffic class */ +#define SOTCDB_NO_SENDTCPBG 0x04 /* Do not use background TCP CC algorithm for sender */ +#define SOTCDB_NO_LCLTST 0x08 /* Do not test for local destination for setting DSCP */ +#define SOTCDB_NO_DSCPTST 0x10 /* Overwritte any existing DSCP code */ +#define SOTCDB_NO_RECVTCPBG 0x20 /* Do not use throttling on receiver-side of TCP */ +#define SOTCDB_NO_PRIVILEGED 0x40 /* Do not set privileged traffic flag */ + +extern u_int32_t sotcdb; + /* * From uipc_socket and friends */ @@ -478,6 +632,7 @@ extern void sbcheck(struct sockbuf *sb); extern void sblastmbufchk(struct sockbuf *, const char *); extern void sblastrecordchk(struct sockbuf *, const char *); extern struct mbuf *sbcreatecontrol(caddr_t p, int size, int type, int level); +extern struct mbuf **sbcreatecontrol_mbuf(caddr_t p, int size, int type, int level, struct mbuf** m); extern void sbdrop(struct sockbuf *sb, int len); extern void sbdroprecord(struct sockbuf *sb); extern void sbflush(struct sockbuf *sb); @@ -509,13 +664,17 @@ extern void sofree(struct socket *so); extern void soreference(struct socket *so); extern void sodereference(struct socket *so); extern void somultipages(struct socket *, boolean_t); +extern int sosetdefunct(struct proc *, struct socket *, int level, boolean_t); +extern int sodefunct(struct proc *, struct socket *, int level); extern int sogetopt(struct socket *so, struct sockopt *sopt); extern void sohasoutofband(struct socket *so); extern void soisconnected(struct socket *so); extern void soisconnecting(struct socket *so); extern void soisdisconnected(struct socket *so); +extern void sodisconnectwakeup(struct socket *so); extern void soisdisconnecting(struct socket *so); -extern int soisbackground(struct socket *so); +extern int soisthrottled(struct socket *so); +extern int soisprivilegedtraffic(struct socket *so); extern int solisten(struct socket *so, int backlog); extern struct socket *sodropablereq(struct socket *head); extern struct socket *sonewconn(struct socket *head, int connstatus, @@ -528,6 +687,34 @@ extern int socket_unlock(struct socket *so, int refcount); extern void sofreelastref(struct socket *, int); extern int sogetaddr_locked(struct socket *, struct sockaddr **, int); extern const char *solockhistory_nr(struct socket *); +extern void soevent(struct socket *so, long hint); +extern void get_sockev_state(struct socket *, u_int32_t *); + +#ifdef BSD_KERNEL_PRIVATE +/* Service class flags used for setting service class on a packet */ +#define PKT_SCF_IPV6 0x00000001 /* IPv6 packet */ +#define PKT_SCF_TCP_ACK 0x00000002 /* Pure TCP ACK */ + +extern void set_packet_service_class(struct mbuf *, struct socket *, + mbuf_svc_class_t, u_int32_t); +extern void so_tc_update_stats(struct mbuf *, struct socket *, mbuf_svc_class_t ); +extern mbuf_svc_class_t mbuf_service_class_from_control(struct mbuf *); +extern mbuf_svc_class_t so_tc2msc(int); +extern int so_svc2tc(mbuf_svc_class_t); + +extern void set_tcp_stream_priority(struct socket *so); +extern int so_set_traffic_class(struct socket *, int); +extern void so_set_default_traffic_class(struct socket *); +extern int so_set_opportunistic(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 void socket_tclass_init(void); +extern int so_set_tcdbg(struct socket *, struct so_tcdbg *); +extern int sogetopt_tcdbg(struct socket *, struct sockopt *); +extern void so_recv_data_stat(struct socket *, struct mbuf *, size_t); +extern int so_wait_for_if_feedback(struct socket *); +#endif /* BSD_KERNEL_PRIVATE */ /* * XXX; prepare mbuf for (__FreeBSD__ < 3) routines. @@ -552,6 +739,7 @@ extern void sotoxsocket(struct socket *so, struct xsocket *xso); #if !CONFIG_EMBEDDED extern void sotoxsocket64(struct socket *so, struct xsocket64 *xso); #endif +extern void sbwakeup(struct sockbuf *sb); extern void sowakeup(struct socket *so, struct sockbuf *sb); extern int soioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p);