#include <os/log.h>
#ifndef ROUNDUP64
-#define ROUNDUP64(x) P2ROUNDUP((x), sizeof (u_int64_t))
+#define ROUNDUP64(x) P2ROUNDUP((x), sizeof (u_int64_t))
#endif
#ifndef ADVANCE64
-#define ADVANCE64(p, n) (void*)((char *)(p) + ROUNDUP64(n))
+#define ADVANCE64(p, n) (void*)((char *)(p) + ROUNDUP64(n))
#endif
static void inpcb_to_xinpcb_n(struct inpcb *, struct xinpcb_n *);
__private_extern__ void
sotoxsocket_n(struct socket *so, struct xsocket_n *xso)
{
- xso->xso_len = sizeof (struct xsocket_n);
+ xso->xso_len = sizeof(struct xsocket_n);
xso->xso_kind = XSO_SOCKET;
if (so != NULL) {
__private_extern__ void
sbtoxsockbuf_n(struct sockbuf *sb, struct xsockbuf_n *xsb)
{
- xsb->xsb_len = sizeof (struct xsockbuf_n);
+ xsb->xsb_len = sizeof(struct xsockbuf_n);
xsb->xsb_kind = (sb->sb_flags & SB_RECV) ? XSO_RCVBUF : XSO_SNDBUF;
if (sb != NULL) {
xsb->sb_flags = sb->sb_flags;
xsb->sb_timeo = (short)(sb->sb_timeo.tv_sec * hz) +
sb->sb_timeo.tv_usec / tick;
- if (xsb->sb_timeo == 0 && sb->sb_timeo.tv_usec != 0)
+ if (xsb->sb_timeo == 0 && sb->sb_timeo.tv_usec != 0) {
xsb->sb_timeo = 1;
+ }
}
}
{
int i;
- xst->xst_len = sizeof (struct xsockstat_n);
+ xst->xst_len = sizeof(struct xsockstat_n);
xst->xst_kind = XSO_STATS;
for (i = 0; i < SO_TC_STATS_MAX; i++) {
static void
inpcb_to_xinpcb_n(struct inpcb *inp, struct xinpcb_n *xinp)
{
- xinp->xi_len = sizeof (struct xinpcb_n);
+ xinp->xi_len = sizeof(struct xinpcb_n);
xinp->xi_kind = XSO_INPCB;
xinp->xi_inpp = (uint64_t)VM_KERNEL_ADDRPERM(inp);
xinp->inp_fport = inp->inp_fport;
__private_extern__ void
tcpcb_to_xtcpcb_n(struct tcpcb *tp, struct xtcpcb_n *xt)
{
- xt->xt_len = sizeof (struct xtcpcb_n);
+ xt->xt_len = sizeof(struct xtcpcb_n);
xt->xt_kind = XSO_TCPCB;
xt->t_segq = (uint32_t)VM_KERNEL_ADDRPERM(tp->t_segq.lh_first);
inp_gen_t gencnt;
struct xinpgen xig;
void *buf = NULL;
- size_t item_size = ROUNDUP64(sizeof (struct xinpcb_n)) +
- ROUNDUP64(sizeof (struct xsocket_n)) +
- 2 * ROUNDUP64(sizeof (struct xsockbuf_n)) +
- ROUNDUP64(sizeof (struct xsockstat_n));
+ size_t item_size = ROUNDUP64(sizeof(struct xinpcb_n)) +
+ ROUNDUP64(sizeof(struct xsocket_n)) +
+ 2 * ROUNDUP64(sizeof(struct xsockbuf_n)) +
+ ROUNDUP64(sizeof(struct xsockstat_n));
- if (proto == IPPROTO_TCP)
- item_size += ROUNDUP64(sizeof (struct xtcpcb_n));
+ if (proto == IPPROTO_TCP) {
+ item_size += ROUNDUP64(sizeof(struct xtcpcb_n));
+ }
if (req->oldptr == USER_ADDR_NULL) {
n = pcbinfo->ipi_count;
- req->oldidx = 2 * (sizeof (xig)) + (n + n/8 + 1) * item_size;
+ req->oldidx = 2 * (sizeof(xig)) + (n + n / 8 + 1) * item_size;
return 0;
}
gencnt = pcbinfo->ipi_gencnt;
n = pcbinfo->ipi_count;
- bzero(&xig, sizeof (xig));
- xig.xig_len = sizeof (xig);
+ 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));
+ error = SYSCTL_OUT(req, &xig, sizeof(xig));
if (error) {
goto done;
}
goto done;
}
- inp_list = _MALLOC(n * sizeof (*inp_list), M_TEMP, M_WAITOK);
+ inp_list = _MALLOC(n * sizeof(*inp_list), M_TEMP, M_WAITOK);
if (inp_list == NULL) {
error = ENOMEM;
goto done;
n = get_tcp_inp_list(inp_list, n, gencnt);
} else {
for (inp = pcbinfo->ipi_listhead->lh_first, i = 0; inp && i < n;
- inp = inp->inp_list.le_next) {
+ inp = inp->inp_list.le_next) {
if (inp->inp_gencnt <= gencnt &&
- inp->inp_state != INPCB_STATE_DEAD)
+ inp->inp_state != INPCB_STATE_DEAD) {
inp_list[i++] = inp;
+ }
}
n = i;
}
inp->inp_state != INPCB_STATE_DEAD) {
struct xinpcb_n *xi = (struct xinpcb_n *)buf;
struct xsocket_n *xso = (struct xsocket_n *)
- ADVANCE64(xi, sizeof (*xi));
+ ADVANCE64(xi, sizeof(*xi));
struct xsockbuf_n *xsbrcv = (struct xsockbuf_n *)
- ADVANCE64(xso, sizeof (*xso));
+ ADVANCE64(xso, sizeof(*xso));
struct xsockbuf_n *xsbsnd = (struct xsockbuf_n *)
- ADVANCE64(xsbrcv, sizeof (*xsbrcv));
+ ADVANCE64(xsbrcv, sizeof(*xsbrcv));
struct xsockstat_n *xsostats = (struct xsockstat_n *)
- ADVANCE64(xsbsnd, sizeof (*xsbsnd));
+ ADVANCE64(xsbsnd, sizeof(*xsbsnd));
bzero(buf, item_size);
sbtoxsockstat_n(inp->inp_socket, xsostats);
if (proto == IPPROTO_TCP) {
struct xtcpcb_n *xt = (struct xtcpcb_n *)
- ADVANCE64(xsostats, sizeof (*xsostats));
+ ADVANCE64(xsostats, sizeof(*xsostats));
/*
* inp->inp_ppcb, can only be NULL on
* an initialization race window.
* No need to lock.
*/
- if (inp->inp_ppcb == NULL)
+ if (inp->inp_ppcb == NULL) {
continue;
+ }
tcpcb_to_xtcpcb_n((struct tcpcb *)
inp->inp_ppcb, xt);
* while we were processing this request, and it
* might be necessary to retry.
*/
- bzero(&xig, sizeof (xig));
- xig.xig_len = sizeof (xig);
+ bzero(&xig, sizeof(xig));
+ xig.xig_len = sizeof(xig);
xig.xig_gen = pcbinfo->ipi_gencnt;
xig.xig_sogen = so_gencnt;
xig.xig_count = pcbinfo->ipi_count;
- error = SYSCTL_OUT(req, &xig, sizeof (xig));
+ error = SYSCTL_OUT(req, &xig, sizeof(xig));
}
done:
lck_rw_done(pcbinfo->ipi_lock);
- if (inp_list != NULL)
+ if (inp_list != NULL) {
FREE(inp_list, M_TEMP);
- if (buf != NULL)
+ }
+ if (buf != NULL) {
FREE(buf, M_TEMP);
- return (error);
+ }
+ return error;
}
__private_extern__ void
if (inp->inp_gencnt > gencnt ||
inp->inp_state == INPCB_STATE_DEAD ||
- inp->inp_wantcnt == WNT_STOPUSING)
+ inp->inp_wantcnt == WNT_STOPUSING) {
continue;
+ }
if ((so = inp->inp_socket) == NULL ||
(so->so_state & SS_DEFUNCT) ||
- (so->so_state & SS_ISDISCONNECTED))
+ (so->so_state & SS_ISDISCONNECTED)) {
continue;
+ }
/*
* If protocol is specified, filter out inpcbs that
}
if (SOCK_PROTO(inp->inp_socket) != IPPROTO_UDP &&
- SOCK_PROTO(inp->inp_socket) != IPPROTO_TCP)
+ SOCK_PROTO(inp->inp_socket) != IPPROTO_TCP) {
continue;
+ }
iswildcard = (((inp->inp_vflag & INP_IPV4) &&
inp->inp_laddr.s_addr == INADDR_ANY) ||
((inp->inp_vflag & INP_IPV6) &&
IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)));
- if (!wildcardok && iswildcard)
+ if (!wildcardok && iswildcard) {
continue;
+ }
if ((so->so_options & SO_NOWAKEFROMSLEEP) &&
- !nowakeok)
+ !nowakeok) {
continue;
+ }
if (!(inp->inp_flags & INP_RECV_ANYIF) &&
- recvanyifonly)
+ recvanyifonly) {
continue;
+ }
if (!(so->so_flags1 & SOF1_EXTEND_BK_IDLE_WANTED) &&
- extbgidleok)
+ extbgidleok) {
continue;
+ }
if (!iswildcard &&
!(ifindex == 0 || inp->inp_last_outifp == NULL ||
- ifindex == inp->inp_last_outifp->if_index))
+ ifindex == inp->inp_last_outifp->if_index)) {
continue;
+ }
if (SOCK_PROTO(inp->inp_socket) == IPPROTO_UDP &&
- so->so_state & SS_CANTRCVMORE)
+ so->so_state & SS_CANTRCVMORE) {
continue;
+ }
if (SOCK_PROTO(inp->inp_socket) == IPPROTO_TCP) {
struct tcpcb *tp = sototcpcb(inp->inp_socket);
* Workaround race where inp_ppcb is NULL during
* socket initialization
*/
- if (tp == NULL)
+ if (tp == NULL) {
continue;
+ }
switch (tp->t_state) {
- case TCPS_CLOSED:
- continue;
- /* NOT REACHED */
- case TCPS_LISTEN:
- case TCPS_SYN_SENT:
- case TCPS_SYN_RECEIVED:
- case TCPS_ESTABLISHED:
- case TCPS_FIN_WAIT_1:
- /*
- * Note: FIN_WAIT_1 is an active state
- * because we need our FIN to be
- * acknowledged
- */
- break;
- case TCPS_CLOSE_WAIT:
- case TCPS_CLOSING:
- case TCPS_LAST_ACK:
- case TCPS_FIN_WAIT_2:
- /*
- * In the closing states, the connection
- * is not idle when there is outgoing
- * data having to be acknowledged
- */
- if (activeonly && so->so_snd.sb_cc == 0)
- continue;
- break;
- case TCPS_TIME_WAIT:
+ case TCPS_CLOSED:
+ continue;
+ /* NOT REACHED */
+ case TCPS_LISTEN:
+ case TCPS_SYN_SENT:
+ case TCPS_SYN_RECEIVED:
+ case TCPS_ESTABLISHED:
+ case TCPS_FIN_WAIT_1:
+ /*
+ * Note: FIN_WAIT_1 is an active state
+ * because we need our FIN to be
+ * acknowledged
+ */
+ break;
+ case TCPS_CLOSE_WAIT:
+ case TCPS_CLOSING:
+ case TCPS_LAST_ACK:
+ case TCPS_FIN_WAIT_2:
+ /*
+ * In the closing states, the connection
+ * is not idle when there is outgoing
+ * data having to be acknowledged
+ */
+ if (activeonly && so->so_snd.sb_cc == 0) {
continue;
- /* NOT REACHED */
+ }
+ break;
+ case TCPS_TIME_WAIT:
+ continue;
+ /* NOT REACHED */
}
}
/*
* Final safeguard to exclude unspecified local port
*/
port = ntohs(inp->inp_lport);
- if (port == 0)
+ if (port == 0) {
continue;
+ }
bitstr_set(bitfield, port);
if_ports_used_add_inpcb(ifindex, inp);
lck_rw_done(pcbinfo->ipi_lock);
- return (opportunistic);
+ return opportunistic;
}
__private_extern__ uint32_t
if ((ifa->ifa_addr->sa_family != AF_INET) &&
(ifa->ifa_addr->sa_family != AF_INET6)) {
- return (0);
+ return 0;
}
lck_rw_lock_shared(pcbinfo->ipi_lock);
for (inp = LIST_FIRST(pcbinfo->ipi_listhead);
inp != NULL; inp = LIST_NEXT(inp, inp_list)) {
-
if (inp->inp_gencnt <= gencnt &&
inp->inp_state != INPCB_STATE_DEAD &&
inp->inp_socket != NULL) {
so = inp->inp_socket;
af = SOCK_DOM(so);
- if (af != ifa->ifa_addr->sa_family)
+ if (af != ifa->ifa_addr->sa_family) {
continue;
- if (inp->inp_last_outifp != ifa->ifa_ifp)
+ }
+ if (inp->inp_last_outifp != ifa->ifa_ifp) {
continue;
+ }
if (af == AF_INET) {
if (inp->inp_laddr.s_addr ==
(satosin(ifa->ifa_addr))->sin_addr.s_addr) {
lck_rw_done(pcbinfo->ipi_lock);
- return (1);
+ return 1;
}
}
if (af == AF_INET6) {
if (IN6_ARE_ADDR_EQUAL(IFA_IN6(ifa),
&inp->in6p_laddr)) {
lck_rw_done(pcbinfo->ipi_lock);
- return (1);
+ return 1;
}
}
}
}
lck_rw_done(pcbinfo->ipi_lock);
- return (0);
+ return 0;
}
static int
int i;
struct ifnet *ifp = (struct ifnet *)arg;
- if (ifp == NULL)
- return (PROC_RETURNED);
+ if (ifp == NULL) {
+ return PROC_RETURNED;
+ }
proc_fdlock(p);
fdp = p->p_fd;
for (i = 0; i < fdp->fd_nfiles; i++) {
- struct fileproc *fp = fdp->fd_ofiles[i];
+ struct fileproc *fp = fdp->fd_ofiles[i];
struct fileglob *fg;
struct socket *so;
struct inpcb *inp;
}
fg = fp->f_fglob;
- if (FILEGLOB_DTYPE(fg) != DTYPE_SOCKET)
+ if (FILEGLOB_DTYPE(fg) != DTYPE_SOCKET) {
continue;
+ }
so = (struct socket *)fp->f_fglob->fg_data;
- if (SOCK_DOM(so) != PF_INET && SOCK_DOM(so) != PF_INET6)
+ if (SOCK_DOM(so) != PF_INET && SOCK_DOM(so) != PF_INET6) {
continue;
+ }
inp = (struct inpcb *)so->so_pcb;
- if (in_pcb_checkstate(inp, WNT_ACQUIRE, 0) == WNT_STOPUSING)
+ if (in_pcb_checkstate(inp, WNT_ACQUIRE, 0) == WNT_STOPUSING) {
continue;
+ }
socket_lock(so, 1);
}
proc_fdunlock(p);
- return (PROC_RETURNED);
+ return PROC_RETURNED;
}
void
shutdown_sockets_on_interface(struct ifnet *ifp)
{
proc_iterate(PROC_ALLPROCLIST,
- shutdown_sockets_on_interface_proc_callout,
- ifp, NULL, NULL);
+ shutdown_sockets_on_interface_proc_callout,
+ ifp, NULL, NULL);
}