Lines Matching defs:so
164 soisconnecting(struct socket *so)
167 so->so_state &= ~(SS_ISCONNECTED|SS_ISDISCONNECTING);
168 so->so_state |= SS_ISCONNECTING;
170 sflt_notify(so, sock_evt_connecting, NULL);
174 soisconnected(struct socket *so)
176 struct socket *head = so->so_head;
178 so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING);
179 so->so_state |= SS_ISCONNECTED;
181 sflt_notify(so, sock_evt_connected, NULL);
183 if (head && (so->so_state & SS_INCOMP)) {
184 so->so_state &= ~SS_INCOMP;
185 so->so_state |= SS_COMP;
187 socket_unlock(so, 0);
191 TAILQ_REMOVE(&head->so_incomp, so, so_list);
193 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
198 socket_lock(so, 0);
201 postevent(so, 0, EV_WCONN);
202 wakeup((caddr_t)&so->so_timeo);
203 sorwakeup(so);
204 sowwakeup(so);
205 soevent(so, SO_FILT_HINT_LOCKED);
210 soisdisconnecting(struct socket *so)
212 so->so_state &= ~SS_ISCONNECTING;
213 so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE|SS_CANTSENDMORE);
214 soevent(so, SO_FILT_HINT_LOCKED);
215 sflt_notify(so, sock_evt_disconnecting, NULL);
216 wakeup((caddr_t)&so->so_timeo);
217 sowwakeup(so);
218 sorwakeup(so);
222 soisdisconnected(struct socket *so)
224 so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING);
225 so->so_state |= (SS_CANTRCVMORE|SS_CANTSENDMORE|SS_ISDISCONNECTED);
226 soevent(so, SO_FILT_HINT_LOCKED);
227 sflt_notify(so, sock_evt_disconnected, NULL);
228 wakeup((caddr_t)&so->so_timeo);
229 sowwakeup(so);
230 sorwakeup(so);
238 sodisconnectwakeup(struct socket *so)
240 so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING);
241 so->so_state |= (SS_CANTRCVMORE|SS_CANTSENDMORE|SS_ISDISCONNECTED);
242 soevent(so, SO_FILT_HINT_LOCKED);
243 wakeup((caddr_t)&so->so_timeo);
244 sowwakeup(so);
245 sorwakeup(so);
260 struct socket *so;
282 * as so_qlen so that we fail immediately below.
292 so = soalloc(1, head->so_proto->pr_domain->dom_family,
294 if (so == NULL)
298 sodealloc(so);
302 so->so_type = head->so_type;
303 so->so_options = head->so_options &~ SO_ACCEPTCONN;
304 so->so_linger = head->so_linger;
305 so->so_state = head->so_state | SS_NOFDREF;
306 so->so_proto = head->so_proto;
307 so->so_timeo = head->so_timeo;
308 so->so_pgid = head->so_pgid;
310 so->so_cred = head->so_cred;
311 so->last_pid = head->last_pid;
312 so->last_upid = head->last_upid;
314 so->so_flags = head->so_flags & (SOF_NOSIGPIPE |
324 so->so_usecount = 1;
325 so->next_lock_lr = 0;
326 so->next_unlock_lr = 0;
329 so->so_rcv.sb_flags |= SB_RECV; /* XXX */
330 so->so_rcv.sb_so = so->so_snd.sb_so = so;
331 TAILQ_INIT(&so->so_evlist);
335 mac_socket_label_associate_accept(head, so);
339 so->so_traffic_mgt_flags = head->so_traffic_mgt_flags & (TRAFFIC_MGT_SO_BACKGROUND);
340 so->so_background_thread = head->so_background_thread;
341 so->so_traffic_class = head->so_traffic_class;
343 if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat)) {
344 sodealloc(so);
347 so->so_rcv.sb_flags |= (head->so_rcv.sb_flags & SB_USRSIZE);
348 so->so_snd.sb_flags |= (head->so_snd.sb_flags & SB_USRSIZE);
356 if (((*so->so_proto->pr_usrreqs->pru_attach)(so, 0, NULL) != 0) ||
358 sodealloc(so);
369 so->so_state &= ~SS_NOFDREF;
370 soclose(so);
376 so->so_proto->pr_domain->dom_refs++;
379 so->so_head = head;
387 so->so_flags |= SOF_INCOMP_INPROGRESS;
390 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
391 so->so_state |= SS_COMP;
393 TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list);
394 so->so_state |= SS_INCOMP;
401 sflt_initsock(so);
405 so->so_state |= connstatus;
409 return (so);
435 socantsendmore(struct socket *so)
437 so->so_state |= SS_CANTSENDMORE;
438 soevent(so, SO_FILT_HINT_LOCKED);
439 sflt_notify(so, sock_evt_cantsendmore, NULL);
440 sowwakeup(so);
444 socantrcvmore(struct socket *so)
446 so->so_state |= SS_CANTRCVMORE;
447 soevent(so, SO_FILT_HINT_LOCKED);
448 sflt_notify(so, sock_evt_cantrecvmore, NULL);
449 sorwakeup(so);
464 struct socket *so = sb->sb_so;
470 if (so->so_proto->pr_getlock != NULL)
471 mutex_held = (*so->so_proto->pr_getlock)(so, 0);
473 mutex_held = so->so_proto->pr_domain->dom_mtx;
478 if (so->so_usecount < 1)
479 panic("sbwait: so=%p refcount=%d\n", so, so->so_usecount);
487 if (so->so_usecount < 1)
488 panic("sbwait: so=%p refcount=%d\n", so, so->so_usecount);
490 if ((so->so_state & SS_DRAINING) || (so->so_flags & SOF_DEFUNCT)) {
492 if (so->so_flags & SOF_DEFUNCT) {
493 SODEFUNCTLOG(("%s[%d]: defunct so %p [%d,%d] (%d)\n",
494 __func__, proc_selfpid(), so, INP_SOCKAF(so),
495 INP_SOCKTYPE(so), error));
512 struct socket *so = sb->sb_so;
516 if (so == NULL)
517 panic("sb_lock: null so back pointer sb=%p\n", sb);
522 if (so->so_proto->pr_getlock != NULL)
523 mutex_held = (*so->so_proto->pr_getlock)(so, 0);
525 mutex_held = so->so_proto->pr_domain->dom_mtx;
528 if (so->so_usecount < 1)
529 panic("sb_lock: so=%p refcount=%d\n", so,
530 so->so_usecount);
535 if (so->so_usecount < 1)
536 panic("sb_lock: 2 so=%p refcount=%d\n", so,
537 so->so_usecount);
539 if (error == 0 && (so->so_flags & SOF_DEFUNCT)) {
541 SODEFUNCTLOG(("%s[%d]: defunct so %p [%d,%d] (%d)\n",
542 __func__, proc_selfpid(), so, INP_SOCKAF(so),
543 INP_SOCKTYPE(so), error));
568 sowakeup(struct socket *so, struct sockbuf *sb)
570 if (so->so_flags & SOF_DEFUNCT) {
571 SODEFUNCTLOG(("%s[%d]: defunct so %p [%d,%d] si 0x%x, "
572 "fl 0x%x [%s]\n", __func__, proc_selfpid(), so,
573 INP_SOCKAF(so), INP_SOCKTYPE(so),
581 if (so->so_state & SS_ASYNC) {
582 if (so->so_pgid < 0)
583 gsignal(-so->so_pgid, SIGIO);
584 else if (so->so_pgid > 0)
585 proc_signal(so->so_pgid, SIGIO);
594 so_upcall = so->so_upcall;
595 so_upcallarg = so->so_upcallarg;
597 so->so_upcallusecount++;
599 socket_unlock(so, 0);
600 (*so_upcall)(so, so_upcallarg, M_DONTWAIT);
601 socket_lock(so, 0);
603 so->so_upcallusecount--;
605 if (so->so_flags & SOF_CLOSEWAIT && so->so_upcallusecount == 0)
606 wakeup((caddr_t)&so->so_upcall);
647 soreserve(struct socket *so, u_int32_t sndcc, u_int32_t rcvcc)
650 if (sbreserve(&so->so_snd, sndcc) == 0)
653 so->so_snd.sb_idealsize = sndcc;
655 if (sbreserve(&so->so_rcv, rcvcc) == 0)
658 so->so_rcv.sb_idealsize = rcvcc;
660 if (so->so_rcv.sb_lowat == 0)
661 so->so_rcv.sb_lowat = 1;
662 if (so->so_snd.sb_lowat == 0)
663 so->so_snd.sb_lowat = MCLBYTES;
664 if (so->so_snd.sb_lowat > so->so_snd.sb_hiwat)
665 so->so_snd.sb_lowat = so->so_snd.sb_hiwat;
669 selthreadclear(&so->so_snd.sb_sel);
671 sbrelease(&so->so_snd);
678 * Attempt to scale mbmax so that mbcnt doesn't become limiting
739 struct socket *so = sb->sb_so;
753 int error = sflt_data_in(so, NULL, &m, NULL, 0);
777 struct socket *so = sb->sb_so;
792 int error = sflt_data_in(so, NULL, &m, NULL, 0);
1304 panic("%s: sb %p so %p cc %d mbcnt %d mb %p mbtail %p "
1521 pru_abort_notsupp(__unused struct socket *so)
1527 pru_accept_notsupp(__unused struct socket *so, __unused struct sockaddr **nam)
1533 pru_attach_notsupp(__unused struct socket *so, __unused int proto,
1540 pru_bind_notsupp(__unused struct socket *so, __unused struct sockaddr *nam,
1547 pru_connect_notsupp(__unused struct socket *so, __unused struct sockaddr *nam,
1560 pru_control_notsupp(__unused struct socket *so, __unused u_long cmd,
1567 pru_detach_notsupp(__unused struct socket *so)
1573 pru_disconnect_notsupp(__unused struct socket *so)
1579 pru_listen_notsupp(__unused struct socket *so, __unused struct proc *p)
1585 pru_peeraddr_notsupp(__unused struct socket *so, __unused struct sockaddr **nam)
1591 pru_rcvd_notsupp(__unused struct socket *so, __unused int flags)
1597 pru_rcvoob_notsupp(__unused struct socket *so, __unused struct mbuf *m,
1604 pru_send_notsupp(__unused struct socket *so, __unused int flags,
1618 pru_sense_null(struct socket *so, void *ub, int isstat64)
1624 sb64->st_blksize = so->so_snd.sb_hiwat;
1629 sb->st_blksize = so->so_snd.sb_hiwat;
1637 pru_sosend_notsupp(__unused struct socket *so, __unused struct sockaddr *addr,
1646 pru_soreceive_notsupp(__unused struct socket *so,
1655 pru_shutdown_notsupp(__unused struct socket *so)
1661 pru_sockaddr_notsupp(__unused struct socket *so, __unused struct sockaddr **nam)
1667 pru_sopoll_notsupp(__unused struct socket *so, __unused int events,
1691 * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
1710 sosendallatonce(struct socket *so)
1712 return (so->so_proto->pr_flags & PR_ATOMIC);
1715 /* can we read something from so? */
1717 soreadable(struct socket *so)
1719 return (so->so_rcv.sb_cc >= so->so_rcv.sb_lowat ||
1720 (so->so_state & SS_CANTRCVMORE) ||
1721 so->so_comp.tqh_first || so->so_error);
1724 /* can we write something to so? */
1727 sowriteable(struct socket *so)
1729 return ((!so_wait_for_if_feedback(so) &&
1730 sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat &&
1731 ((so->so_state & SS_ISCONNECTED) ||
1732 (so->so_proto->pr_flags & PR_CONNREQUIRED) == 0)) ||
1733 (so->so_state & SS_CANTSENDMORE) ||
1734 so->so_error);
1802 struct socket *so = sb->sb_so;
1812 if (so->so_usecount < 0) {
1813 panic("sbunlock: b4 wakeup so=%p ref=%d lr=%p "
1814 "sb_flags=%x lrh= %s\n", sb->sb_so, so->so_usecount,
1815 lr_saved, sb->sb_flags, solockhistory_nr(so));
1821 if (so->so_proto->pr_getlock != NULL)
1822 mutex_held = (*so->so_proto->pr_getlock)(so, 0);
1824 mutex_held = so->so_proto->pr_domain->dom_mtx;
1828 so->so_usecount--;
1829 if (so->so_usecount < 0)
1830 panic("sbunlock: unlock on exit so=%p ref=%d lr=%p "
1831 "sb_flags=%x lrh= %s\n", so, so->so_usecount, lr_saved,
1832 sb->sb_flags, solockhistory_nr(so));
1833 so->unlock_lr[so->next_unlock_lr] = lr_saved;
1834 so->next_unlock_lr = (so->next_unlock_lr+1) % SO_LCKDBG_MAX;
1840 sorwakeup(struct socket *so)
1842 if (sb_notify(&so->so_rcv))
1843 sowakeup(so, &so->so_rcv);
1847 sowwakeup(struct socket *so)
1849 if (sb_notify(&so->so_snd))
1850 sowakeup(so, &so->so_snd);
1854 soevent(struct socket *so, long hint)
1856 if (so->so_flags & SOF_KNOTE)
1857 KNOTE(&so->so_klist, hint);
1879 * in the kernel-format socket structure pointed to by so. This is done
1886 sotoxsocket(struct socket *so, struct xsocket *xso)
1889 xso->xso_so = (_XSOCKET_PTR(struct socket *))VM_KERNEL_ADDRPERM(so);
1890 xso->so_type = so->so_type;
1891 xso->so_options = (short)(so->so_options & 0xffff);
1892 xso->so_linger = so->so_linger;
1893 xso->so_state = so->so_state;
1894 xso->so_pcb = (_XSOCKET_PTR(caddr_t))VM_KERNEL_ADDRPERM(so->so_pcb);
1895 if (so->so_proto) {
1896 xso->xso_protocol = so->so_proto->pr_protocol;
1897 xso->xso_family = so->so_proto->pr_domain->dom_family;
1901 xso->so_qlen = so->so_qlen;
1902 xso->so_incqlen = so->so_incqlen;
1903 xso->so_qlimit = so->so_qlimit;
1904 xso->so_timeo = so->so_timeo;
1905 xso->so_error = so->so_error;
1906 xso->so_pgid = so->so_pgid;
1907 xso->so_oobmark = so->so_oobmark;
1908 sbtoxsockbuf(&so->so_snd, &xso->so_snd);
1909 sbtoxsockbuf(&so->so_rcv, &xso->so_rcv);
1910 xso->so_uid = kauth_cred_getuid(so->so_cred);
1917 sotoxsocket64(struct socket *so, struct xsocket64 *xso)
1920 xso->xso_so = (u_int64_t)VM_KERNEL_ADDRPERM(so);
1921 xso->so_type = so->so_type;
1922 xso->so_options = (short)(so->so_options & 0xffff);
1923 xso->so_linger = so->so_linger;
1924 xso->so_state = so->so_state;
1925 xso->so_pcb = (u_int64_t)VM_KERNEL_ADDRPERM(so->so_pcb);
1926 if (so->so_proto) {
1927 xso->xso_protocol = so->so_proto->pr_protocol;
1928 xso->xso_family = so->so_proto->pr_domain->dom_family;
1932 xso->so_qlen = so->so_qlen;
1933 xso->so_incqlen = so->so_incqlen;
1934 xso->so_qlimit = so->so_qlimit;
1935 xso->so_timeo = so->so_timeo;
1936 xso->so_error = so->so_error;
1937 xso->so_pgid = so->so_pgid;
1938 xso->so_oobmark = so->so_oobmark;
1939 sbtoxsockbuf(&so->so_snd, &xso->so_snd);
1940 sbtoxsockbuf(&so->so_rcv, &xso->so_rcv);
1941 xso->so_uid = kauth_cred_getuid(so->so_cred);
1972 soisthrottled(struct socket *so)
1982 (so->so_traffic_mgt_flags & TRAFFIC_MGT_SO_BACKGROUND));
1986 soisprivilegedtraffic(struct socket *so)
1988 return (so->so_flags & SOF_PRIVILEGED_TRAFFIC_CLASS);