From nobody Sat Dec 04 15:09:49 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C82CC18C88AE; Sat, 4 Dec 2021 15:09:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J5tQj3Rdqz3QXT; Sat, 4 Dec 2021 15:09:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 563DD264AD; Sat, 4 Dec 2021 15:09:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1B4F9nOk019128; Sat, 4 Dec 2021 15:09:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B4F9nkw019127; Sat, 4 Dec 2021 15:09:49 GMT (envelope-from git) Date: Sat, 4 Dec 2021 15:09:49 GMT Message-Id: <202112041509.1B4F9nkw019127@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Michael Tuexen Subject: git: 31537ea583c0 - main - tcpdrop: allow TCP connections to be filtered by cc-algo List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 31537ea583c0965fe22498d52831ced4b4f4fc5e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638630589; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JkPHxURhuEITp05zLacnKwSEoDdKLpUnjvyRIMl9M18=; b=KgbnRSIMHuNvyyyn2Y9EOA+ZAihBLc594tsKO7w03mt3EUPkh+l4QvFU4EOP/r+GcYxenh Q7/VHX/Z7mso9rK+S92MqqLzUkwIHOrrTHUaGJ+yXSeTlg3CwlS2npTsuGUOzuNeqZk3LX VzFN/z+5zq9y2HnLWrO07uceEsX2XwC81AmporCG3FTFy/NgLXZ7YlzgbLe7VJR0Yn5Ixz 241ycL/f/snkLs/7dFLu5bRyqjDEM6mEU2puY30CKZT6dAm6JXEIeHJ/n3pwI8eKZx07B9 UCVZB7YZKKnC9M2wgOH6kcIWACZ0ZpNRS6b17zwCPo6WlmMf1m5hGC4k4p//2w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638630589; a=rsa-sha256; cv=none; b=Z953eDb7AfhN0yF+S0CfdN+6RW9an7IGgdmTMn3Shel+HTiHUAo9IIQjzo+Z9l2fBSKNyw xLxJQ1aQDGvUG+Kq9yJS8HafX8nERR2fEQkM/fQYuqpL5JPIrczDim928A0TaRQ/LemEJU FKWOMeZRxdI0ykLGInnYDCZBn5rJNxRGnPu47gyXMqHPQgwi3/aQrs9wWBXSLbHLMsJGdy zYCl7434sGFbDNCbM1Zs2vzCJz3O9+iROts5TGUkMolwhZL75QbVE4xql0HPUpEj1TClUA BDFjkaOlCWCcHf/IbC/jEed4/eWSrW/koNzjJiJHymtJvF0zaV1e9CzpdVoRcg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=31537ea583c0965fe22498d52831ced4b4f4fc5e commit 31537ea583c0965fe22498d52831ced4b4f4fc5e Author: Michael Tuexen AuthorDate: 2021-12-04 14:00:05 +0000 Commit: Michael Tuexen CommitDate: 2021-12-04 14:02:15 +0000 tcpdrop: allow TCP connections to be filtered by cc-algo In addition to filtering by stack and state, allow filtering by the congestion control module used. Choose the command line options to be consistent with the ones of sockstat. MFC after: 1 week Sponsored by: Netflix, Inc. --- usr.sbin/tcpdrop/tcpdrop.8 | 45 ++++++++++++++++++++++++++++++++++----------- usr.sbin/tcpdrop/tcpdrop.c | 28 +++++++++++++++++++++------- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/usr.sbin/tcpdrop/tcpdrop.8 b/usr.sbin/tcpdrop/tcpdrop.8 index c58388b3eab8..2549a2ec0ad7 100644 --- a/usr.sbin/tcpdrop/tcpdrop.8 +++ b/usr.sbin/tcpdrop/tcpdrop.8 @@ -34,13 +34,18 @@ .Fl a .Nm tcpdrop .Op Fl l -.Fl S Ar stack +.Fl C Ar cc-algo +.Op Fl S Ar stack +.Op Fl s Ar state .Nm tcpdrop .Op Fl l -.Fl s Ar state +.Op Fl C Ar cc-algo +.Fl S Ar stack +.Op Fl s Ar state .Nm tcpdrop .Op Fl l -.Fl S Ar stack +.Op Fl C Ar cc-algo +.Op Fl S Ar stack .Fl s Ar state .Sh DESCRIPTION The @@ -54,6 +59,13 @@ is specified then will attempt to drop all TCP connections. .Pp If +.Fl C Ar cc-algo +is specified then +.Nm +will attempt to drop all connections using the TCP congestion control algorithm +.Ar cc-algo . +.Pp +If .Fl S Ar stack is specified then .Nm @@ -78,16 +90,20 @@ is one of .Dv FIN_WAIT_2 , or .Dv TIME_WAIT . .Pp -If -.Fl S Ar stack +If multiple of +.Fl C Ar cc-algo , +.Fl S Ar stack , and .Fl s Ar state are specified, .Nm -will attempt to drop all TCP connections being in the state -.Ar state +will attempt to drop all TCP connections using the congestion control algorithm +.Ar cc-algo , +being in the state +.Ar state , and using the TCP stack -.Ar stack . +.Ar stack , +if specified. Since TCP connections in the .Dv TIME_WAIT state are not tied to any TCP stack, using the option @@ -102,6 +118,7 @@ The .Fl l flag may be given in addition to the .Fl a , +.Fl C , .Fl S , or .Fl s @@ -110,6 +127,7 @@ connections one at a time. .Pp If none of the .Fl a , +.Fl C , .Fl S , or .Fl s @@ -154,6 +172,11 @@ port 22, the port used by # tcpdrop -l -a | grep -vw 22 | sh .Ed .Pp +To drop all TCP connections using the new-reno congestion control algorithm use: +.Bd -literal -offset indent +# tcpdrop -C new-reno +.Ed +.Pp The following command will drop all connections using the TCP stack rack: .Bd -literal -offset indent @@ -165,10 +188,10 @@ To drop all TCP connections in the LAST_ACK state use: # tcpdrop -s LAST_ACK .Ed .Pp -To drop all TCP connections using the TCP stack rack and being in the -LAST_ACK state use: +To drop all TCP connections using the congestion control algorithm new-reno and +the TCP stack rack and being in the LAST_ACK state use: .Bd -literal -offset indent -# tcpdrop -S rack -s LAST_ACK +# tcpdrop -C new-reno -S rack -s LAST_ACK .Ed .Sh SEE ALSO .Xr netstat 1 , diff --git a/usr.sbin/tcpdrop/tcpdrop.c b/usr.sbin/tcpdrop/tcpdrop.c index f05c027362b8..aa28f494e24d 100644 --- a/usr.sbin/tcpdrop/tcpdrop.c +++ b/usr.sbin/tcpdrop/tcpdrop.c @@ -54,7 +54,7 @@ static char *findport(const char *); static struct xinpgen *getxpcblist(const char *); static void sockinfo(const struct sockaddr *, struct host_service *); static bool tcpdrop(const struct sockaddr *, const struct sockaddr *); -static bool tcpdropall(const char *, int); +static bool tcpdropall(const char *, const char *, int); static bool tcpdropbyname(const char *, const char *, const char *, const char *); static bool tcpdropconn(const struct in_conninfo *); @@ -67,20 +67,26 @@ int main(int argc, char *argv[]) { char stack[TCP_FUNCTION_NAME_LEN_MAX]; + char ca_name[TCP_CA_NAME_MAX]; char *lport, *fport; bool dropall, dropspecific; int ch, state; dropall = false; dropspecific = false; + ca_name[0] = '\0'; stack[0] = '\0'; state = -1; - while ((ch = getopt(argc, argv, "alS:s:")) != -1) { + while ((ch = getopt(argc, argv, "aC:lS:s:")) != -1) { switch (ch) { case 'a': dropall = true; break; + case 'C': + dropspecific = true; + strlcpy(ca_name, optarg, sizeof(ca_name)); + break; case 'l': tcpdrop_list_commands = true; break; @@ -111,7 +117,7 @@ main(int argc, char *argv[]) if (dropall || dropspecific) { if (argc != 0) usage(); - if (!tcpdropall(stack, state)) + if (!tcpdropall(ca_name, stack, state)) exit(1); exit(0); } @@ -223,7 +229,7 @@ tcpdrop(const struct sockaddr *lsa, const struct sockaddr *fsa) } static bool -tcpdropall(const char *stack, int state) +tcpdropall(const char *ca_name, const char *stack, int state) { struct xinpgen *head, *xinp; struct xtcpcb *xtp; @@ -259,6 +265,14 @@ tcpdropall(const char *stack, int state) if ((state != -1) && (xtp->t_state != state)) continue; + /* + * If requested, skip sockets not having the requested + * congestion control algorithm. + */ + if (ca_name[0] != '\0' && + strncmp(xtp->xt_cc, ca_name, TCP_CA_NAME_MAX)) + continue; + /* If requested, skip sockets not having the requested stack. */ if (stack[0] != '\0' && strncmp(xtp->xt_stack, stack, TCP_FUNCTION_NAME_LEN_MAX)) @@ -379,8 +393,8 @@ usage(void) " tcpdrop local-address:local-port foreign-address:foreign-port\n" " tcpdrop local-address.local-port foreign-address.foreign-port\n" " tcpdrop [-l] -a\n" -" tcpdrop [-l] -S stack\n" -" tcpdrop [-l] -s state\n" -" tcpdrop [-l] -S stack -s state\n"); +" tcpdrop [-l] -C cc-algo [-S stack] [-s state]\n" +" tcpdrop [-l] [-C cc-algo] -S stack [-s state]\n" +" tcpdrop [-l] [-C cc-algo] [-S stack] -s state\n"); exit(1); }