From nobody Fri Dec 10 10:44:50 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 44BBF18D9253; Fri, 10 Dec 2021 10:44:51 +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 4J9SGB6qqbz3GqF; Fri, 10 Dec 2021 10:44:50 +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 CA8FB190F0; Fri, 10 Dec 2021 10:44:50 +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 1BAAiokl019363; Fri, 10 Dec 2021 10:44:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BAAiopJ019362; Fri, 10 Dec 2021 10:44:50 GMT (envelope-from git) Date: Fri, 10 Dec 2021 10:44:50 GMT Message-Id: <202112101044.1BAAiopJ019362@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michael Tuexen Subject: git: cec14fd194f5 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: cec14fd194f5139003ed5ef35334863a2e35579a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639133091; 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=mMJyugitDsBeYu1884+MaC9vrbqYzWFZoSzzQ5gg2dI=; b=PB4XgZ48VmsO6Q/yZ7po/vEJfmQi4P1fO+hsP3PZwhaAyl0gtVQOmi8rTlxR2/QUJvuGbh 6MB6wSspTwSL05B53kU41emr09iFIsY1YX2S5Vah/+QtbQ2iK5pN085He75wMx6hCl+FLQ 0bji7Cgi7vsocETLyUMBniRgpmP2lT94UUkhrV3ifuejEFsiY+bzVPpqZvNXHq8PVLQxpX j+RNLhRJoblz08DqJcaFAE3HBoIrdttdozGzOoPVRVWfV1Z8NBt5AUWJ7G0UUKDDPG7bio jEo1ymNN5QwUnYISutUa/r7UdqEeDVFho8wKXTazTjSu5EZURrKtgsqf3Kt6iA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639133091; a=rsa-sha256; cv=none; b=IAGVJJ8FaZFYnYVwiEG/krHVifL90LkkyYo/mkLsBuSqPZx2rcAZDVkkdSJQZp67wcjE4b Au0BNoHkg05jRNAilPynvgRxYFQROndvcfoQRg+0xkBe7fIxWwv2ITXb8pRSCNkNCTazJy LatS1cAz+kUMpsvAcvDYzTSxsI1eOLrR4EY8RUF723mK3rT9c6U8LfjF9E6LihPV9yvqIe gN8edQ3/CmFLadY4c/aavXr8KkLpNQG9m97xjEVfKyapgKo6AqZjLWz4XNYUnx7x4nQR3R T05sxbtnwWakWLrsCfbgpyibWRtX+rU1ZaFM3hN8soFz3lp+iIkLyJQ+qUqlZA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=cec14fd194f5139003ed5ef35334863a2e35579a commit cec14fd194f5139003ed5ef35334863a2e35579a Author: Michael Tuexen AuthorDate: 2021-12-04 14:00:05 +0000 Commit: Michael Tuexen CommitDate: 2021-12-10 10:44:23 +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. Sponsored by: Netflix, Inc. (cherry picked from commit 31537ea583c0965fe22498d52831ced4b4f4fc5e) --- 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); }