示例#1
0
static bool
tcpdropall(void)
{
	struct xinpgen *head, *xinp;
	struct xtcpcb *xpcb;
	struct tcpcb *tp;
	struct inpcb *inp;
	bool ok;

	ok = true;

	head = getxpcblist("net.inet.tcp.pcblist");

#define	XINP_NEXT(xinp)							\
	((struct xinpgen *)((uintptr_t)(xinp) + (xinp)->xig_len))

	for (xinp = XINP_NEXT(head); xinp->xig_len > sizeof *xinp;
	    xinp = XINP_NEXT(xinp)) {
		xpcb = (struct xtcpcb *)xinp;
		tp = &xpcb->xt_tp;
		inp = &xpcb->xt_inp;

		/*
		 * XXX
		 * Check protocol, support just v4 or v6, etc.
		 */

		/* Ignore PCBs which were freed during copyout.  */
		if (inp->inp_gencnt > head->xig_gen)
			continue;

		/* Skip listening sockets.  */
		if (tp->t_state == TCPS_LISTEN)
			continue;

		if (!tcpdropconn(&inp->inp_inc))
			ok = false;
	}
	free(head);

	return (ok);
}
示例#2
0
static bool
tcpdropall(void)
{
	struct xtcpcb *tcp;
	size_t len;
	bool ok;
	int cnt, i;

	ok = true;

	tcp = tcpcblist("net.inet.tcp.pcblist", &len);
	cnt = len / sizeof(*tcp);

	for (i = 0; i < cnt; ++i) {
		struct xtcpcb *xpcb;
		struct tcpcb *tp;
		struct inpcb *inp;

		xpcb = &tcp[i];
		if (xpcb->xt_len != sizeof(*xpcb))
			break;

		tp = &xpcb->xt_tp;
		inp = &xpcb->xt_inp;

		/*
		 * XXX
		 * Check protocol, support just v4 or v6, etc.
		 */

		/* Skip listening sockets.  */
		if (tp->t_state == TCPS_LISTEN)
			continue;

		if (!tcpdropconn(&inp->inp_inc))
			ok = false;
	}
	free(tcp);

	return (ok);
}