From nobody Mon Jan 03 12:55:59 2022 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 5C4F9191F1C4; Mon, 3 Jan 2022 12:56:00 +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 4JSG2S0SdLz3LcD; Mon, 3 Jan 2022 12:56:00 +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 E028E257F8; Mon, 3 Jan 2022 12:55:59 +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 203Ctx54084435; Mon, 3 Jan 2022 12:55:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 203CtxFO084434; Mon, 3 Jan 2022 12:55:59 GMT (envelope-from git) Date: Mon, 3 Jan 2022 12:55:59 GMT Message-Id: <202201031255.203CtxFO084434@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 9d406e088e95 - main - dnctl: Support reading config from file like ipfw(8) 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9d406e088e95f4245dbeb2b391867621a523401d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641214560; 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=9mr7YM4NQ2mws7dvRNYFxJ1DD43sMeynN44OwvBFKUI=; b=fXTQwi3JwO6Zm3z3UJr8Npw+47duPErsqB/SsnY3kspTfxYZC7hm/3zo7fIhRj/oX76Chg KAZsTEhiEOCL0lBhYCRDL5b2KkRXx3Mld++F0NBYeysz7mwndpEBgvGFuoj+teFja5H4jD SAGHFR2CNK2PHBO11Gwlji9D5IM7/I3BU1sKFLnzhkIy5ucO/qoUn4Kx238O4fSp+C6yAl VpcZBShBGxnKmB1sQtpXWbC5ZJaXsqSuGrTH7UKiT5otcfCzsIHPXQJ/GFmh/TKe9H7DNk LN44VTt6FT+MfX5lZXCLAHMJ3l8usoxGiwu8HcPVz+9ofuU/AmZ3Ya8hJDA/Mw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641214560; a=rsa-sha256; cv=none; b=mVNJRMwu5CpoBFXXwpc9hxDIQfLT6DL2HOIUk/mzuXM1dOhVbutFyic6B9YUq4qUsGs1oz wWe5/oOzUWqtq/YNEppaoE8Nwed+C0XlfldLXimf/NgjM8wJOEDmzwSo5UFybB1mRZAljA BQnmcbZWR7lZiQUi5tnnLaKz1TQalAM/Qk3pcZvHbwyIOdCyGcTLYD+wCaZcp4JdUgCpcR 3JpItBYIIoIviFITwRRxXjbBmH//RBUnONRBRAtGi9IFYh3Id+Z6HvP9FTIMm+5GYfkbfA fKYMCCIn80/gK/70DZcB7Pb/jS7+PRggvSvvl8rQrrlHrKPWclv0gsM1tkXqZQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=9d406e088e95f4245dbeb2b391867621a523401d commit 9d406e088e95f4245dbeb2b391867621a523401d Author: Kristof Provost AuthorDate: 2021-12-23 14:15:44 +0000 Commit: Kristof Provost CommitDate: 2022-01-03 08:50:18 +0000 dnctl: Support reading config from file like ipfw(8) Extend the dnctl (dummynet config) tool to be able to read commands from a file, just like ipfw already does. Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D33627 --- sbin/ipfw/main.c | 121 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 67 insertions(+), 54 deletions(-) diff --git a/sbin/ipfw/main.c b/sbin/ipfw/main.c index f7aa6af5369c..1b9c7f324a9c 100644 --- a/sbin/ipfw/main.c +++ b/sbin/ipfw/main.c @@ -519,62 +519,79 @@ ipfw_readfile(int ac, char *av[]) FILE *f = NULL; pid_t preproc = 0; - while ((c = getopt(ac, av, "cfNnp:qS")) != -1) { - switch(c) { - case 'c': - g_co.do_compact = 1; - break; + if (is_ipfw()) { + while ((c = getopt(ac, av, "cfNnp:qS")) != -1) { + switch(c) { + case 'c': + g_co.do_compact = 1; + break; + + case 'f': + g_co.do_force = 1; + break; - case 'f': - g_co.do_force = 1; - break; + case 'N': + g_co.do_resolv = 1; + break; - case 'N': - g_co.do_resolv = 1; - break; + case 'n': + g_co.test_only = 1; + break; - case 'n': - g_co.test_only = 1; - break; + case 'p': + /* + * ipfw -p cmd [args] filename + * + * We are done with getopt(). All arguments + * except the filename go to the preprocessor, + * so we need to do the following: + * - check that a filename is actually present; + * - advance av by optind-1 to skip arguments + * already processed; + * - decrease ac by optind, to remove the args + * already processed and the final filename; + * - set the last entry in av[] to NULL so + * popen() can detect the end of the array; + * - set optind=ac to let getopt() terminate. + */ + if (optind == ac) + errx(EX_USAGE, "no filename argument"); + cmd = optarg; + av[ac-1] = NULL; + av += optind - 1; + ac -= optind; + optind = ac; + break; - case 'p': - /* - * ipfw -p cmd [args] filename - * - * We are done with getopt(). All arguments - * except the filename go to the preprocessor, - * so we need to do the following: - * - check that a filename is actually present; - * - advance av by optind-1 to skip arguments - * already processed; - * - decrease ac by optind, to remove the args - * already processed and the final filename; - * - set the last entry in av[] to NULL so - * popen() can detect the end of the array; - * - set optind=ac to let getopt() terminate. - */ - if (optind == ac) - errx(EX_USAGE, "no filename argument"); - cmd = optarg; - av[ac-1] = NULL; - av += optind - 1; - ac -= optind; - optind = ac; - break; - - case 'q': - g_co.do_quiet = 1; - break; - - case 'S': - g_co.show_sets = 1; - break; - - default: - errx(EX_USAGE, "bad arguments, for usage" - " summary ``ipfw''"); + case 'q': + g_co.do_quiet = 1; + break; + + case 'S': + g_co.show_sets = 1; + break; + + default: + errx(EX_USAGE, "bad arguments, for usage" + " summary ``ipfw''"); + } } + } else { + while ((c = getopt(ac, av, "nq")) != -1) { + switch(c) { + case 'n': + g_co.test_only = 1; + break; + + case 'q': + g_co.do_quiet = 1; + break; + default: + errx(EX_USAGE, "bad arguments, for usage" + " summary ``dnctl''"); + } + } } if (cmd == NULL && ac != optind + 1) @@ -676,10 +693,6 @@ main(int ac, char *av[]) */ if (ac > 1 && av[ac - 1][0] == '/') { - if (! is_ipfw()) - errx(EX_USAGE, "usage: dnctl [options]\n" - "do \"dnctl -h\" for details"); - if (access(av[ac - 1], R_OK) == 0) ipfw_readfile(ac, av); else