Lines Matching defs:so

224  * pointer is an invariant, so no lock is required to dereference the so_pcb
295 static void unp_connect2(struct socket *so, struct socket *so2);
297 static void unp_dispose(struct socket *so);
421 uipc_abort(struct socket *so)
425 unp = sotounpcb(so);
440 uipc_attach(struct socket *so, int proto, struct thread *td)
447 KASSERT(so->so_pcb == NULL, ("uipc_attach: so_pcb != NULL"));
448 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
449 switch (so->so_type) {
456 STAILQ_INIT(&so->so_rcv.uxdg_mb);
457 STAILQ_INIT(&so->so_snd.uxdg_mb);
458 TAILQ_INIT(&so->so_rcv.uxdg_conns);
475 error = soreserve(so, sendspace, recvspace);
484 unp->unp_socket = so;
485 so->so_pcb = unp;
495 switch (so->so_type) {
519 uipc_bindat(int fd, struct socket *so, struct sockaddr *nam, struct thread *td)
535 unp = sotounpcb(so);
546 * socket, so flag in-progress operations, and return an error if an
549 * Historically, we have not allowed a socket to be rebound, so this
647 uipc_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
650 return (uipc_bindat(AT_FDCWD, so, nam, td));
654 uipc_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
659 error = unp_connect(so, nam, td);
664 uipc_connectat(int fd, struct socket *so, struct sockaddr *nam,
670 error = unp_connectat(fd, so, nam, td, false);
675 uipc_close(struct socket *so)
681 unp = sotounpcb(so);
709 uipc_chmod(struct socket *so, mode_t mode, struct ucred *cred __unused,
719 unp = sotounpcb(so);
749 uipc_detach(struct socket *so)
756 unp = sotounpcb(so);
762 if (!SOLISTENING(so))
763 unp_dispose(so);
824 switch (so->so_type) {
830 MPASS(so->so_rcv.uxdg_peeked == NULL);
831 MPASS(STAILQ_EMPTY(&so->so_rcv.uxdg_mb));
832 MPASS(TAILQ_EMPTY(&so->so_rcv.uxdg_conns));
833 MPASS(STAILQ_EMPTY(&so->so_snd.uxdg_mb));
838 uipc_disconnect(struct socket *so)
842 unp = sotounpcb(so);
854 uipc_listen(struct socket *so, int backlog, struct thread *td)
859 MPASS(so->so_type != SOCK_DGRAM);
865 unp = sotounpcb(so);
876 SOCK_LOCK(so);
877 error = solisten_proto_check(so);
880 solisten_proto(so, backlog);
882 SOCK_UNLOCK(so);
888 uipc_peeraddr(struct socket *so, struct sockaddr *ret)
893 unp = sotounpcb(so);
914 uipc_rcvd(struct socket *so, int flags)
920 unp = sotounpcb(so);
922 KASSERT(so->so_type == SOCK_STREAM || so->so_type == SOCK_SEQPACKET,
923 ("%s: socktype %d", __func__, so->so_type));
935 SOCKBUF_LOCK(&so->so_rcv);
936 mbcnt = so->so_rcv.sb_mbcnt;
937 sbcc = sbavail(&so->so_rcv);
938 SOCKBUF_UNLOCK(&so->so_rcv);
964 uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
972 unp = sotounpcb(so);
974 KASSERT(so->so_type == SOCK_STREAM || so->so_type == SOCK_SEQPACKET,
975 ("%s: socktype %d", __func__, so->so_type));
987 if ((so->so_state & SS_ISCONNECTED) == 0) {
989 if ((error = unp_connect(so, nam, td)) != 0)
1002 } else if (so->so_snd.sb_state & SBS_CANTSENDMORE) {
1034 switch (so->so_type) {
1065 SOCKBUF_LOCK(&so->so_snd);
1066 if (sbcc >= so->so_snd.sb_hiwat || mbcnt >= so->so_snd.sb_mbmax)
1067 so->so_snd.sb_flags |= SB_STOP;
1068 SOCKBUF_UNLOCK(&so->so_snd);
1077 socantsendmore(so);
1132 uipc_sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio,
1203 unp = sotounpcb(so);
1213 error = SOCK_IO_SEND_LOCK(so, SBLOCKWAIT(flags));
1216 SOCK_SENDBUF_LOCK(so);
1217 if (so->so_snd.sb_state & SBS_CANTSENDMORE) {
1218 SOCK_SENDBUF_UNLOCK(so);
1222 if (so->so_error != 0) {
1223 error = so->so_error;
1224 so->so_error = 0;
1225 SOCK_SENDBUF_UNLOCK(so);
1228 if (((so->so_state & SS_ISCONNECTED) == 0) && addr == NULL) {
1229 SOCK_SENDBUF_UNLOCK(so);
1233 SOCK_SENDBUF_UNLOCK(so);
1236 if ((error = unp_connectat(AT_FDCWD, so, addr, td, true)))
1302 * Unconnected sends, when !(so->so_state & SS_ISCONNECTED) and the
1312 * socket "so". Then, if we just added the very first datagram
1325 sb = (addr == NULL) ? &so->so_snd : &so2->so_rcv;
1329 TAILQ_INSERT_HEAD(&so2->so_rcv.uxdg_conns, &so->so_snd,
1358 SOCK_IO_SEND_UNLOCK(so);
1379 uipc_peek_dgram(struct socket *so, struct mbuf *m, struct sockaddr **psa,
1385 so->so_rcv.uxdg_peeked = m;
1386 so->so_rcv.uxdg_cc += m->m_pkthdr.len;
1387 so->so_rcv.uxdg_ctl += m->m_pkthdr.ctllen;
1388 so->so_rcv.uxdg_mbcnt += m->m_pkthdr.memlen;
1389 SOCK_RECVBUF_UNLOCK(so);
1416 SOCK_IO_RECV_UNLOCK(so);
1422 SOCK_IO_RECV_UNLOCK(so);
1442 uipc_soreceive_dgram(struct socket *so, struct sockaddr **psa, struct uio *uio,
1459 nonblock = (so->so_state & SS_NBIO) ||
1462 error = SOCK_IO_RECV_LOCK(so, SBLOCKWAIT(flags));
1472 SOCK_RECVBUF_LOCK(so);
1473 while ((m = so->so_rcv.uxdg_peeked) == NULL &&
1474 (sb = TAILQ_FIRST(&so->so_rcv.uxdg_conns)) == NULL &&
1475 (m = STAILQ_FIRST(&so->so_rcv.uxdg_mb)) == NULL) {
1476 if (so->so_error) {
1477 error = so->so_error;
1479 so->so_error = 0;
1480 SOCK_RECVBUF_UNLOCK(so);
1481 SOCK_IO_RECV_UNLOCK(so);
1484 if (so->so_rcv.sb_state & SBS_CANTRCVMORE ||
1486 SOCK_RECVBUF_UNLOCK(so);
1487 SOCK_IO_RECV_UNLOCK(so);
1491 SOCK_RECVBUF_UNLOCK(so);
1492 SOCK_IO_RECV_UNLOCK(so);
1495 error = sbwait(so, SO_RCV);
1497 SOCK_RECVBUF_UNLOCK(so);
1498 SOCK_IO_RECV_UNLOCK(so);
1504 sb = &so->so_rcv;
1508 MPASS(m == so->so_rcv.uxdg_peeked);
1517 if (__predict_true(m != so->so_rcv.uxdg_peeked)) {
1519 if (STAILQ_EMPTY(&sb->uxdg_mb) && sb != &so->so_rcv)
1520 TAILQ_REMOVE(&so->so_rcv.uxdg_conns, sb, uxdg_clist);
1522 so->so_rcv.uxdg_peeked = NULL;
1529 return (uipc_peek_dgram(so, m, psa, uio, controlp, flagsp));
1531 so->so_rcv.sb_acc -= m->m_pkthdr.len;
1532 so->so_rcv.sb_ccc -= m->m_pkthdr.len;
1533 so->so_rcv.sb_ctl -= m->m_pkthdr.ctllen;
1534 so->so_rcv.sb_mbcnt -= m->m_pkthdr.memlen;
1535 SOCK_RECVBUF_UNLOCK(so);
1556 * it frees whole chain, so we must disconnect the mbuf.
1561 SOCK_IO_RECV_UNLOCK(so);
1579 SOCK_IO_RECV_UNLOCK(so);
1590 SOCK_IO_RECV_UNLOCK(so);
1608 uipc_ready_scan(struct socket *so, struct mbuf *m, int count, int *errorp)
1613 SOCK_LOCK(so);
1614 if (SOLISTENING(so)) {
1615 SOCK_UNLOCK(so);
1619 sb = &so->so_rcv;
1636 SOCK_UNLOCK(so);
1641 uipc_ready(struct socket *so, struct mbuf *m, int count)
1647 unp = sotounpcb(so);
1649 KASSERT(so->so_type == SOCK_STREAM,
1650 ("%s: unexpected socket type for %p", __func__, so));
1669 * buffer, so perform an exhaustive search before giving up and freeing
1688 uipc_sense(struct socket *so, struct stat *sb)
1692 unp = sotounpcb(so);
1695 sb->st_blksize = so->so_snd.sb_hiwat;
1702 uipc_shutdown(struct socket *so, enum shutdown_how how)
1704 struct unpcb *unp = sotounpcb(so);
1707 SOCK_LOCK(so);
1708 if (SOLISTENING(so)) {
1710 so->so_error = ECONNABORTED;
1711 solisten_wakeup(so); /* unlocks so */
1713 SOCK_UNLOCK(so);
1715 } else if ((so->so_state &
1731 if (so->so_type != SOCK_DGRAM) {
1732 SOCK_UNLOCK(so);
1737 SOCK_UNLOCK(so);
1741 socantrcvmore(so);
1742 unp_dispose(so);
1745 socantrcvmore(so);
1746 unp_dispose(so);
1750 socantsendmore(so);
1754 wakeup(&so->so_timeo);
1760 uipc_sockaddr(struct socket *so, struct sockaddr *ret)
1765 unp = sotounpcb(so);
1779 uipc_ctloutput(struct socket *so, struct sockopt *sopt)
1788 unp = sotounpcb(so);
1799 if (so->so_proto->pr_flags & PR_CONNREQUIRED)
1878 unp_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
1881 return (unp_connectat(AT_FDCWD, so, nam, td, false));
1885 unp_connectat(int fd, struct socket *so, struct sockaddr *nam,
1914 unp = sotounpcb(so);
1929 if (SOLISTENING(so))
1950 connreq = (so->so_proto->pr_flags & PR_CONNREQUIRED) != 0;
1980 unp = sotounpcb(so);
1991 if (so->so_type != so2->so_type) {
2023 mac_socketpeer_set_from_socket(so, so2);
2024 mac_socketpeer_set_from_socket(so2, so);
2032 unp_connect2(so, so2);
2083 unp_connect2(struct socket *so, struct socket *so2)
2088 MPASS(so2->so_type == so->so_type);
2089 unp = sotounpcb(so);
2102 switch (so->so_type) {
2107 soisconnected(so);
2115 soisconnected(so);
2127 struct socket *so, *so2;
2139 so = unp->unp_socket;
2151 if (!STAILQ_EMPTY(&so->so_snd.uxdg_mb)) {
2152 TAILQ_REMOVE(&so2->so_rcv.uxdg_conns, &so->so_snd,
2158 &so->so_snd.uxdg_mb);
2159 so2->so_rcv.uxdg_cc += so->so_snd.uxdg_cc;
2160 so2->so_rcv.uxdg_ctl += so->so_snd.uxdg_ctl;
2161 so2->so_rcv.uxdg_mbcnt += so->so_snd.uxdg_mbcnt;
2163 m = STAILQ_FIRST(&so->so_snd.uxdg_mb);
2164 STAILQ_INIT(&so->so_snd.uxdg_mb);
2165 so2->so_rcv.sb_acc -= so->so_snd.uxdg_cc;
2166 so2->so_rcv.sb_ccc -= so->so_snd.uxdg_cc;
2167 so2->so_rcv.sb_ctl -= so->so_snd.uxdg_ctl;
2168 so2->so_rcv.sb_mbcnt -= so->so_snd.uxdg_mbcnt;
2170 /* Note: so may reconnect. */
2171 so->so_snd.uxdg_cc = 0;
2172 so->so_snd.uxdg_ctl = 0;
2173 so->so_snd.uxdg_mbcnt = 0;
2187 if (so) {
2188 SOCK_LOCK(so);
2189 so->so_state &= ~SS_ISCONNECTED;
2190 SOCK_UNLOCK(so);
2196 if (so)
2197 soisdisconnected(so);
2384 struct socket *so;
2391 so = unp2->unp_socket;
2392 if (so != NULL)
2393 socantrcvmore(so);
2400 struct socket *so;
2410 so = unp->unp_socket;
2411 if (so)
2412 so->so_error = ECONNRESET;
2673 * sizeof int, so we need to check if data fits into
2899 struct socket *so;
2903 if ((so = fp->f_data) == NULL)
2905 if (so->so_proto->pr_domain != &localdomain)
2907 return sotounpcb(so);
3042 unp_scan_socket(struct socket *so, void (*op)(struct filedescent **, int))
3046 SOCK_LOCK_ASSERT(so);
3048 if (sotounpcb(so)->unp_gcflag & UNPGC_IGNORE_RIGHTS)
3051 SOCK_RECVBUF_LOCK(so);
3052 switch (so->so_type) {
3054 unp_scan(STAILQ_FIRST(&so->so_rcv.uxdg_mb), op);
3055 unp_scan(so->so_rcv.uxdg_peeked, op);
3056 TAILQ_FOREACH(sb, &so->so_rcv.uxdg_conns, uxdg_clist)
3061 unp_scan(so->so_rcv.sb_mb, op);
3064 SOCK_RECVBUF_UNLOCK(so);
3070 struct socket *so, *soa;
3072 so = unp->unp_socket;
3073 SOCK_LOCK(so);
3074 if (SOLISTENING(so)) {
3078 TAILQ_FOREACH(soa, &so->sol_comp, so_list)
3084 unp_scan_socket(so, op);
3086 SOCK_UNLOCK(so);
3213 struct socket *so;
3215 so = unref[i]->f_data;
3216 CURVNET_SET(so->so_vnet);
3217 socantrcvmore(so);
3218 unp_dispose(so);
3223 * And finally release the sockets so they can be reclaimed.
3235 unp_dispose(struct socket *so)
3242 MPASS(!SOLISTENING(so));
3244 unp = sotounpcb(so);
3252 error = SOCK_IO_RECV_LOCK(so, SBL_WAIT | SBL_NOINTR);
3254 SOCK_RECVBUF_LOCK(so);
3255 switch (so->so_type) {
3257 while ((sb = TAILQ_FIRST(&so->so_rcv.uxdg_conns)) != NULL) {
3258 STAILQ_CONCAT(&so->so_rcv.uxdg_mb, &sb->uxdg_mb);
3259 TAILQ_REMOVE(&so->so_rcv.uxdg_conns, sb, uxdg_clist);
3263 sb = &so->so_rcv;
3272 (void)chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, 0,
3296 sb = &so->so_rcv;
3301 sbrelease_locked(so, SO_RCV);
3304 SOCK_RECVBUF_UNLOCK(so);
3305 SOCK_IO_RECV_UNLOCK(so);